Browse Source

消息数量和转载调整

dev-V1.10.2-temp
wangmingyong 4 months ago
parent
commit
99fc540df2
  1. 9
      zdxt-web-client/zdxt-efcode-enforcement-app/src/components/FooterBar.vue
  2. 17
      zdxt-web-client/zdxt-efcode-enforcement-app/src/store/messageState.js
  3. 88
      zdxt-web-client/zdxt-efcode-enforcement-app/src/views/enforcement/law/lawServiceDetail.vue
  4. 97
      zdxt-web-client/zdxt-efcode-enforcement-app/src/views/enforcement/message/messageCenter.vue

9
zdxt-web-client/zdxt-efcode-enforcement-app/src/components/FooterBar.vue

@ -20,6 +20,7 @@ import { onMounted } from 'vue';
import { getMessageUnreadCount } from '@/api/enforcement/index'; import { getMessageUnreadCount } from '@/api/enforcement/index';
import nosIcon from '@/assets/images/nos/off_site_bottom_icon.png'; import nosIcon from '@/assets/images/nos/off_site_bottom_icon.png';
import tabBarBg from '@/assets/images/nos/tab_bar_bg.png'; import tabBarBg from '@/assets/images/nos/tab_bar_bg.png';
import { messageUnread, setMessageStats } from '@/store/messageState';
const props = defineProps({ const props = defineProps({
active: { active: {
@ -30,8 +31,6 @@ const props = defineProps({
const router = useRouter(); const router = useRouter();
const messageUnread = ref(0);
const tabs = [ const tabs = [
{ {
key: 'home', label: '首页', route: '/enforcement/enforcementHome', key: 'home', label: '首页', route: '/enforcement/enforcementHome',
@ -65,15 +64,15 @@ const onTabClick = (item) => {
if (router.currentRoute.value.path !== item.route) { if (router.currentRoute.value.path !== item.route) {
router.replace(item.route); router.replace(item.route);
} }
fetchMessageUnreadCount(); // console.log('获取消息未读数量2222');
// fetchMessageUnreadCount();
}; };
// ========== 获取消息未读数量 ========== // ========== 获取消息未读数量 ==========
const fetchMessageUnreadCount = () => { const fetchMessageUnreadCount = () => {
getMessageUnreadCount({}, (res) => { getMessageUnreadCount({}, (res) => {
if (res && res.code === 200 && res.data) { if (res && res.code === 200 && res.data) {
const totalCount = Number(res.data.totalCount) || 0; setMessageStats(res.data);
messageUnread.value = totalCount;
} }
}, () => { }, () => {
// 接口调用失败不处理 // 接口调用失败不处理

17
zdxt-web-client/zdxt-efcode-enforcement-app/src/store/messageState.js

@ -6,6 +6,12 @@ import { ref, computed } from 'vue';
* - 消息中心页面负责写入;其他页面仅读取用于 footer-bar 角标展示 * - 消息中心页面负责写入;其他页面仅读取用于 footer-bar 角标展示
*/ */
export const messageUnread = ref(0); export const messageUnread = ref(0);
export const pffwCount = ref(0); // 普法服务未读数量
export const zfpjcount = ref(0); // 执法评价未读数量
export const zfygCount = ref(0); // 执法预告未读数量
export const jhtzcount = ref(0); // 计划通知未读数量
export const zfywCount = ref(0); // 执法任务未读数量
export const zfyyCount = ref(0); // 执法预约未读数量
/** 格式化为角标展示值(0 显示空) */ /** 格式化为角标展示值(0 显示空) */
export const messageUnreadBadge = computed(() => (messageUnread.value > 0 ? messageUnread.value : '')); export const messageUnreadBadge = computed(() => (messageUnread.value > 0 ? messageUnread.value : ''));
@ -15,6 +21,17 @@ export const setMessageUnread = (count) => {
messageUnread.value = Number(count) || 0; messageUnread.value = Number(count) || 0;
}; };
/** 设置所有消息数量 */
export const setMessageStats = (data) => {
pffwCount.value = Number(data.pffwCount) || 0;
zfpjcount.value = Number(data.zfpjcount) || 0;
zfygCount.value = Number(data.zfygCount) || 0;
jhtzcount.value = Number(data.jhtzcount) || 0;
zfywCount.value = Number(data.zfywCount) || 0;
zfyyCount.value = Number(data.zfyyCount) || 0;
messageUnread.value = Number(data.totalCount) || 0;
};
// 占位 default 导出:src/store 目录会被 globalStore.js 通过 import.meta.glob // 占位 default 导出:src/store 目录会被 globalStore.js 通过 import.meta.glob
// 以 { import: 'default' } 的方式扫描,缺少 default 会触发 // 以 { import: 'default' } 的方式扫描,缺少 default 会触发
// "does not provide an export named 'default'" 错误。 // "does not provide an export named 'default'" 错误。

88
zdxt-web-client/zdxt-efcode-enforcement-app/src/views/enforcement/law/lawServiceDetail.vue

@ -24,8 +24,8 @@
<span class="detail-time">{{ detail.time }}</span> <span class="detail-time">{{ detail.time }}</span>
</div> </div>
<!-- 文本内容 (contentType == 1) --> <!-- 文本内容 (sourceType == 1) -->
<template v-if="detail.contentType !== 2"> <template v-if="detail.sourceType== 1">
<!-- 正文 --> <!-- 正文 -->
<div class="detail-body" v-html="detail.content"></div> <div class="detail-body" v-html="detail.content"></div>
@ -41,15 +41,21 @@
</div> </div>
</template> </template>
<!-- 链接内容 (contentType == 2) --> <!-- 链接内容 (sourceType == 2) -->
<template v-else> <template v-else>
<div class="detail-iframe-wrap"> <div class="detail-iframe-wrap">
<iframe <iframe
:src="detail.content" :src="detail.forwardUrl"
class="detail-iframe" class="detail-iframe"
frameborder="0" frameborder="0"
sandbox="allow-scripts allow-same-origin allow-forms" sandbox="allow-scripts allow-same-origin allow-forms"
@load="onIframeLoad"
@error="onIframeError"
></iframe> ></iframe>
<div class="copy-link-btn" @click="copyLink">
<van-icon name="link-o" size="16" />
<span>复制链接</span>
</div>
</div> </div>
</template> </template>
</div> </div>
@ -62,7 +68,8 @@ import { useRouter, useRoute } from 'vue-router';
import { showToast, showImagePreview } from 'vant'; import { showToast, showImagePreview } from 'vant';
import 'vant/es/toast/style'; import 'vant/es/toast/style';
import 'vant/es/image-preview/style'; import 'vant/es/image-preview/style';
import { getEducationServicesDetail } from '@/api/enforcement'; import { getEducationServicesDetail, getMessageUnreadCount } from '@/api/enforcement';
import { setMessageStats } from '@/store/messageState';
const router = useRouter(); const router = useRouter();
const route = useRoute(); const route = useRoute();
@ -76,6 +83,7 @@ const detail = ref({
contentType: 1, // 1: 文本详情, 2: 超链接 contentType: 1, // 1: 文本详情, 2: 超链接
content: [], content: [],
images: [], images: [],
forwardUrl: '',
}); });
const loading = ref(false); const loading = ref(false);
@ -101,9 +109,12 @@ const fetchDetail = () => {
source: res.data.source || '', source: res.data.source || '',
time: res.data.time || '', time: res.data.time || '',
contentType: res.data.contentType || 1, // 1: 文本详情, 2: 超链接 contentType: res.data.contentType || 1, // 1: 文本详情, 2: 超链接
sourceType: res.data.sourceType || 1,
content: res.data.content || '', content: res.data.content || '',
images: res.data.images || [], images: res.data.images || [],
forwardUrl: res.data.forwardUrl || res.data.content || '',
}; };
fetchMessageUnreadCount();
} else { } else {
showToast(res.message || '获取详情失败'); showToast(res.message || '获取详情失败');
} }
@ -135,6 +146,48 @@ const onSearchClick = () => {
showToast('搜索功能开发中'); showToast('搜索功能开发中');
}; };
// ========== 获取消息未读数量 ==========
const fetchMessageUnreadCount = () => {
getMessageUnreadCount({}, (res) => {
if (res && res.code === 200 && res.data) {
setMessageStats(res.data);
}
}, () => {
// 接口调用失败不处理
});
};
// ========== iframe加载成功 ==========
const onIframeLoad = () => {
console.log('iframe加载成功');
};
// ========== iframe加载失败 ==========
const onIframeError = () => {
showToast('页面加载失败,可复制链接到浏览器打开');
};
// ========== 复制链接 ==========
const copyLink = async () => {
const url = detail.value.forwardUrl || '';
if (!url) {
showToast('暂无链接');
return;
}
try {
await navigator.clipboard.writeText(url);
showToast('复制成功');
} catch (err) {
const textarea = document.createElement('textarea');
textarea.value = url;
document.body.appendChild(textarea);
textarea.select();
document.execCommand('copy');
document.body.removeChild(textarea);
showToast('复制成功');
}
};
// ========== 预览图片 ========== // ========== 预览图片 ==========
const previewImage = (index) => { const previewImage = (index) => {
showImagePreview({ showImagePreview({
@ -274,6 +327,7 @@ const previewImage = (index) => {
border-radius: 0.15rem; border-radius: 0.15rem;
overflow: hidden; overflow: hidden;
background: #f5f5f5; background: #f5f5f5;
position: relative;
} }
.detail-iframe { .detail-iframe {
@ -281,4 +335,28 @@ const previewImage = (index) => {
height: 500px; height: 500px;
background: #fff; background: #fff;
} }
.copy-link-btn {
position: absolute;
bottom: 0.3rem;
right: 0.3rem;
display: flex;
align-items: center;
gap: 0.1rem;
padding: 0.15rem 0.3rem;
background: rgba(0, 0, 0, 0.6);
color: #fff;
font-size: 0.28rem;
border-radius: 0.2rem;
cursor: pointer;
z-index: 10;
:deep(.van-icon) {
color: #fff;
}
&:active {
background: rgba(0, 0, 0, 0.8);
}
}
</style> </style>

97
zdxt-web-client/zdxt-efcode-enforcement-app/src/views/enforcement/message/messageCenter.vue

@ -71,12 +71,13 @@
</template> </template>
<script setup name="messageCenter"> <script setup name="messageCenter">
import { ref, computed, onMounted } from 'vue'; import { ref, computed, onMounted, watch } from 'vue';
import { useRouter, useRoute } from 'vue-router'; import { useRouter, useRoute } from 'vue-router';
import { showToast } from 'vant'; import { showToast } from 'vant';
import 'vant/es/toast/style'; import 'vant/es/toast/style';
import FooterBar from '@/components/FooterBar.vue'; import FooterBar from '@/components/FooterBar.vue';
import { getMessageUnreadCount } from '@/api/enforcement/index'; import { getMessageUnreadCount } from '@/api/enforcement/index';
import { pffwCount, zfpjcount, zfygCount, jhtzcount, zfywCount, zfyyCount, setMessageStats } from '@/store/messageState';
const router = useRouter(); const router = useRouter();
const route = useRoute(); const route = useRoute();
@ -100,31 +101,11 @@ const todoRefreshing = ref(false);
const todoPageNum = ref(1); const todoPageNum = ref(1);
const todoPageSize = ref(10); const todoPageSize = ref(10);
// ========== 消息统计数据 ==========
const messageStats = ref({
pffwCount: 0, // 普法服务未读数量
zfpjcount: 0, // 执法评价未读数量
zfygCount: 0, // 执法预告未读数量
totalCount: 0, // 未读总数
});
// 未读总数(tabbar 角标)
const totalUnread = computed(() => {
const messageUnread = messageList.value.reduce((sum, item) => sum + (item.unreadCount || 0), 0);
const todoUnread = todoList.value.reduce((sum, item) => sum + (item.unreadCount || 0), 0);
return messageUnread + todoUnread;
});
// ========== 获取消息未读数量 ========== // ========== 获取消息未读数量 ==========
const fetchMessageStats = () => { const fetchMessageStats = () => {
getMessageUnreadCount({}, (res) => { getMessageUnreadCount({}, (res) => {
if (res && res.code === 200 && res.data) { if (res && res.code === 200 && res.data) {
messageStats.value = { setMessageStats(res.data);
pffwCount: Number(res.data.pffwCount) || 0, // 普法服务未读数量
zfpjcount: Number(res.data.zfpjcount) || 0, // 执法评价未读数量
zfygCount: Number(res.data.zfygCount) || 0, // 执法预告未读数量
totalCount: Number(res.data.totalCount) || 0, // 总未读数量
};
initMessageList(); initMessageList();
initTodoList(); initTodoList();
} }
@ -143,7 +124,7 @@ const initMessageList = () => {
time: '', time: '',
icon: 'law', icon: 'law',
iconBg: 'icon-blue', iconBg: 'icon-blue',
unreadCount: messageStats.value.pffwCount, unreadCount: pffwCount.value,
},{ },{
id: 3, id: 3,
title: '执法评价', title: '执法评价',
@ -151,7 +132,7 @@ const initMessageList = () => {
time: '', time: '',
icon: 'law', icon: 'law',
iconBg: 'icon-blue', iconBg: 'icon-blue',
unreadCount: messageStats.value.zfpjcount, unreadCount: zfpjcount.value,
},{ },{
id: 4, id: 4,
title: '非现场执法评价', title: '非现场执法评价',
@ -159,7 +140,7 @@ const initMessageList = () => {
time: '', time: '',
icon: 'law', icon: 'law',
iconBg: 'icon-blue', iconBg: 'icon-blue',
unreadCount: messageStats.value.zfpjcount, unreadCount: zfpjcount.value,
},{ },{
id: 2, id: 2,
title: '计划通知', title: '计划通知',
@ -167,7 +148,7 @@ const initMessageList = () => {
time: '', time: '',
icon: 'law', icon: 'law',
iconBg: 'icon-blue', iconBg: 'icon-blue',
unreadCount: messageStats.value.jhtzcount, unreadCount: jhtzcount.value,
}, },
]; ];
}; };
@ -182,7 +163,7 @@ const initTodoList = () => {
time: '', time: '',
icon: 'check', icon: 'check',
iconBg: 'icon-red', iconBg: 'icon-red',
unreadCount: messageStats.value.zfygCount, unreadCount: zfygCount.value,
}, },
{ {
id: 102, id: 102,
@ -191,7 +172,7 @@ const initTodoList = () => {
time: '', time: '',
icon: 'check', icon: 'check',
iconBg: 'icon-red', iconBg: 'icon-red',
unreadCount: messageStats.value.zfygCount, unreadCount: zfywCount.value,
}, },
{ {
id: 103, id: 103,
@ -200,7 +181,7 @@ const initTodoList = () => {
time: '', time: '',
icon: 'check', icon: 'check',
iconBg: 'icon-red', iconBg: 'icon-red',
unreadCount: messageStats.value.zfygCount, unreadCount: zfyyCount.value,
}, },
]; ];
}; };
@ -217,7 +198,34 @@ const fetchMessageList = () => {
time: '2026-04-15 10:07', time: '2026-04-15 10:07',
icon: 'law', icon: 'law',
iconBg: 'icon-blue', iconBg: 'icon-blue',
unreadCount: messageStats.value.pffwCount, unreadCount: pffwCount.value,
},
{
id: 3,
title: '执法评价',
desc: zfpjcount.value > 0 ? `您有${zfpjcount.value}条执法评价,请及时查看` : '暂无执法评价',
time: '2026-04-15 10:07',
icon: 'law',
iconBg: 'icon-blue',
unreadCount: zfpjcount.value,
},
{
id: 4,
title: '非现场执法评价',
desc: zfpjcount.value > 0 ? `您有${zfpjcount.value}条非现场执法评价,请及时查看` : '暂无非现场执法评价',
time: '2026-04-15 10:07',
icon: 'law',
iconBg: 'icon-blue',
unreadCount: zfpjcount.value,
},
{
id: 2,
title: '计划通知',
desc: jhtzcount.value > 0 ? `您有${jhtzcount.value}条计划通知,请及时查看` : '暂无计划通知',
time: '2026-04-15 10:07',
icon: 'law',
iconBg: 'icon-blue',
unreadCount: jhtzcount.value,
}, },
]; ];
messageRefreshing.value = false; messageRefreshing.value = false;
@ -235,11 +243,29 @@ const fetchTodoList = () => {
{ {
id: 101, id: 101,
title: '执法预告', title: '执法预告',
desc: messageStats.value.zfygCount > 0 ? `您有${messageStats.value.zfygCount}条执法预告,请及时查看` : '暂无执法预告', desc: zfygCount.value > 0 ? `您有${zfygCount.value}条执法预告,请及时查看` : '暂无执法预告',
time: '2026-04-15 09:30', time: '2026-04-15 09:30',
icon: 'check', icon: 'check',
iconBg: 'icon-red', iconBg: 'icon-red',
unreadCount: messageStats.value.zfygCount, unreadCount: zfygCount.value,
},
{
id: 102,
title: '执法任务',
desc: zfywCount.value > 0 ? `您有${zfywCount.value}条执法任务,请及时查看` : '暂无执法任务',
time: '2026-04-15 09:30',
icon: 'check',
iconBg: 'icon-red',
unreadCount: zfywCount.value,
},
{
id: 103,
title: '执法预约',
desc: zfyyCount.value > 0 ? `您有${zfyyCount.value}条执法预约,请及时查看` : '暂无执法预约',
time: '2026-04-15 09:30',
icon: 'check',
iconBg: 'icon-red',
unreadCount: zfyyCount.value,
}, },
]; ];
todoRefreshing.value = false; todoRefreshing.value = false;
@ -335,6 +361,11 @@ const onTodoClick = (item) => {
} }
}; };
watch([pffwCount, zfpjcount, zfygCount, jhtzcount, zfywCount, zfyyCount], () => {
initMessageList();
initTodoList();
});
onMounted(() => { onMounted(() => {
const returnTab = sessionStorage.getItem('messageReturnTab'); const returnTab = sessionStorage.getItem('messageReturnTab');
if (returnTab === '1') { if (returnTab === '1') {
@ -351,8 +382,6 @@ onMounted(() => {
activeTab.value = 0; activeTab.value = 0;
} }
} }
initMessageList();
initTodoList();
fetchMessageStats(); fetchMessageStats();
}); });
</script> </script>

Loading…
Cancel
Save