2021-10-20 14:32:09 +08:00
|
|
|
|
<template>
|
|
|
|
|
<div :class="prefixCls">
|
2022-03-10 09:47:29 +08:00
|
|
|
|
<Popover v-model:visible="popoverVisible" title="" trigger="click" :overlayClassName="`${prefixCls}__overlay`">
|
|
|
|
|
<Badge :count="count" :overflowCount="9" :offset="[-4, 10]" :numberStyle="numberStyle">
|
2021-10-20 14:32:09 +08:00
|
|
|
|
<BellOutlined />
|
|
|
|
|
</Badge>
|
|
|
|
|
<template #content>
|
|
|
|
|
<Tabs>
|
|
|
|
|
<template v-for="item in listData" :key="item.key">
|
|
|
|
|
<TabPane>
|
|
|
|
|
<template #tab>
|
|
|
|
|
{{ item.name }}
|
2022-03-10 09:47:29 +08:00
|
|
|
|
<span v-if="item.list.length !== 0">({{ item.count }})</span>
|
2021-10-20 14:32:09 +08:00
|
|
|
|
</template>
|
|
|
|
|
<!-- 绑定title-click事件的通知列表中标题是“可点击”的-->
|
2022-03-10 09:47:29 +08:00
|
|
|
|
<NoticeList :list="item.list" @title-click="onNoticeClick" />
|
2021-10-20 14:32:09 +08:00
|
|
|
|
</TabPane>
|
|
|
|
|
</template>
|
|
|
|
|
</Tabs>
|
2022-03-10 09:47:29 +08:00
|
|
|
|
<a-row class="bottom-buttons">
|
|
|
|
|
<a-col :span="count === 0 ? 0 : 12">
|
|
|
|
|
<a-button @click="onEmptyNotify" type="dashed" block>清空消息</a-button>
|
|
|
|
|
</a-col>
|
|
|
|
|
<a-col :span="count === 0 ? 24 : 12">
|
|
|
|
|
<a-button @click="popoverVisible=false" type="dashed" block>
|
|
|
|
|
<router-link to="/monitor/mynews">查看更多</router-link>
|
|
|
|
|
</a-button>
|
|
|
|
|
</a-col>
|
|
|
|
|
</a-row>
|
2021-10-20 14:32:09 +08:00
|
|
|
|
</template>
|
|
|
|
|
</Popover>
|
2022-03-10 09:47:29 +08:00
|
|
|
|
<DynamicNotice ref="dynamicNoticeRef" v-bind="dynamicNoticeProps"/>
|
|
|
|
|
<DetailModal @register="registerDetail"/>
|
2021-10-20 14:32:09 +08:00
|
|
|
|
</div>
|
|
|
|
|
</template>
|
|
|
|
|
<script lang="ts">
|
2022-03-10 09:47:29 +08:00
|
|
|
|
import { computed, defineComponent, ref, unref, reactive, onMounted, getCurrentInstance } from 'vue'
|
2021-10-20 14:32:09 +08:00
|
|
|
|
import { Popover, Tabs, Badge } from 'ant-design-vue';
|
|
|
|
|
import { BellOutlined } from '@ant-design/icons-vue';
|
2022-03-10 09:47:29 +08:00
|
|
|
|
import { tabListData } from './data'
|
|
|
|
|
import { listCementByUser, editCementSend } from './notify.api';
|
2021-10-20 14:32:09 +08:00
|
|
|
|
import NoticeList from './NoticeList.vue';
|
2022-03-10 09:47:29 +08:00
|
|
|
|
import DetailModal from '/@/views/monitor/mynews/DetailModal.vue';
|
|
|
|
|
import DynamicNotice from '/@/views/monitor/mynews/DynamicNotice.vue';
|
|
|
|
|
import { useModal } from '/@/components/Modal'
|
2021-10-20 14:32:09 +08:00
|
|
|
|
import { useDesign } from '/@/hooks/web/useDesign';
|
2022-03-10 09:47:29 +08:00
|
|
|
|
import { useGlobSetting } from '/@/hooks/setting'
|
|
|
|
|
import { useUserStore } from '/@/store/modules/user';
|
|
|
|
|
import { connectWebSocket, onWebSocket } from '/@/hooks/web/useWebSocket'
|
|
|
|
|
import { readAllMsg } from '/@/views/monitor/mynews/mynews.api'
|
|
|
|
|
import { getToken } from '/@/utils/auth';
|
2021-10-20 14:32:09 +08:00
|
|
|
|
export default defineComponent({
|
2022-03-10 09:47:29 +08:00
|
|
|
|
components: { Popover, BellOutlined, Tabs, TabPane: Tabs.TabPane, Badge, NoticeList, DetailModal, DynamicNotice },
|
2021-10-20 14:32:09 +08:00
|
|
|
|
setup() {
|
|
|
|
|
const { prefixCls } = useDesign('header-notify');
|
2022-03-10 09:47:29 +08:00
|
|
|
|
const instance: any = getCurrentInstance()
|
|
|
|
|
const userStore = useUserStore();
|
|
|
|
|
const glob = useGlobSetting();
|
|
|
|
|
const dynamicNoticeProps = reactive({ path: '', formData: {} })
|
|
|
|
|
const [registerDetail, detailModal] = useModal();
|
|
|
|
|
const popoverVisible = ref<boolean>(false);
|
2021-10-20 14:32:09 +08:00
|
|
|
|
const listData = ref(tabListData);
|
2022-03-10 09:47:29 +08:00
|
|
|
|
listData.value[0].list = []
|
|
|
|
|
listData.value[1].list = []
|
|
|
|
|
listData.value[0].count = 0
|
|
|
|
|
listData.value[1].count = 0
|
|
|
|
|
|
|
|
|
|
onMounted(() => {
|
|
|
|
|
initWebSocket()
|
|
|
|
|
})
|
2021-10-20 14:32:09 +08:00
|
|
|
|
|
|
|
|
|
const count = computed(() => {
|
|
|
|
|
let count = 0;
|
2022-03-10 09:47:29 +08:00
|
|
|
|
for (let i = 0; i < listData.value.length; i++) {
|
|
|
|
|
count += listData.value[i].count;
|
2021-10-20 14:32:09 +08:00
|
|
|
|
}
|
|
|
|
|
return count;
|
|
|
|
|
});
|
|
|
|
|
|
2022-03-10 09:47:29 +08:00
|
|
|
|
function mapAnnouncement(item) {
|
|
|
|
|
return {
|
|
|
|
|
...item,
|
|
|
|
|
title: item.titile,
|
|
|
|
|
description: item.msgAbstract,
|
|
|
|
|
datetime: item.sendTime,
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 获取系统消息
|
|
|
|
|
async function loadData() {
|
|
|
|
|
try {
|
|
|
|
|
let { anntMsgList, sysMsgList, anntMsgTotal, sysMsgTotal } = await listCementByUser({ pageSize: 5 })
|
|
|
|
|
listData.value[0].list = anntMsgList.map(mapAnnouncement)
|
|
|
|
|
listData.value[1].list = sysMsgList.map(mapAnnouncement)
|
|
|
|
|
listData.value[0].count = anntMsgTotal
|
|
|
|
|
listData.value[1].count = sysMsgTotal
|
|
|
|
|
} catch (e) {
|
|
|
|
|
console.warn('系统消息通知异常:', e)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
loadData()
|
|
|
|
|
|
|
|
|
|
function onNoticeClick(record) {
|
|
|
|
|
try {
|
|
|
|
|
editCementSend(record.id)
|
|
|
|
|
loadData()
|
|
|
|
|
} catch (e) {
|
|
|
|
|
console.error(e)
|
|
|
|
|
}
|
|
|
|
|
if (record.openType === 'component') {
|
|
|
|
|
dynamicNoticeProps.path = record.openPage
|
|
|
|
|
dynamicNoticeProps.formData = { id: record.busId }
|
|
|
|
|
instance.refs.dynamicNoticeRef?.detail(record.openPage)
|
|
|
|
|
} else {
|
|
|
|
|
detailModal.openModal(true, {
|
|
|
|
|
record,
|
|
|
|
|
isUpdate: true,
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
popoverVisible.value = false
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 初始化 WebSocket
|
|
|
|
|
function initWebSocket() {
|
|
|
|
|
let userId = unref(userStore.getUserInfo).id
|
|
|
|
|
let token=getToken();
|
|
|
|
|
// WebSocket与普通的请求所用协议有所不同,ws等同于http,wss等同于https
|
|
|
|
|
let url = glob.domainUrl?.replace('https://', 'wss://').replace('http://', 'ws://') + '/websocket/' + userId
|
|
|
|
|
connectWebSocket(url)
|
|
|
|
|
onWebSocket(onWebSocketMessage)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function onWebSocketMessage(data) {
|
|
|
|
|
if (data.cmd === 'topic' || data.cmd === 'user') {
|
|
|
|
|
loadData()
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 清空消息
|
|
|
|
|
function onEmptyNotify() {
|
|
|
|
|
popoverVisible.value = false
|
|
|
|
|
readAllMsg({}, loadData)
|
2021-10-20 14:32:09 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return {
|
|
|
|
|
prefixCls,
|
|
|
|
|
listData,
|
|
|
|
|
count,
|
|
|
|
|
onNoticeClick,
|
2022-03-10 09:47:29 +08:00
|
|
|
|
onEmptyNotify,
|
2021-10-20 14:32:09 +08:00
|
|
|
|
numberStyle: {},
|
2022-03-10 09:47:29 +08:00
|
|
|
|
popoverVisible,
|
|
|
|
|
registerDetail,
|
|
|
|
|
dynamicNoticeProps,
|
2021-10-20 14:32:09 +08:00
|
|
|
|
};
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
</script>
|
|
|
|
|
<style lang="less">
|
2022-03-10 09:47:29 +08:00
|
|
|
|
//noinspection LessUnresolvedVariable
|
2021-10-20 14:32:09 +08:00
|
|
|
|
@prefix-cls: ~'@{namespace}-header-notify';
|
|
|
|
|
|
|
|
|
|
.@{prefix-cls} {
|
|
|
|
|
padding-top: 2px;
|
|
|
|
|
|
|
|
|
|
&__overlay {
|
2022-03-10 09:47:29 +08:00
|
|
|
|
max-width: 340px;
|
|
|
|
|
|
|
|
|
|
.ant-popover-inner-content {
|
|
|
|
|
padding: 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.ant-tabs-bar {
|
|
|
|
|
margin-bottom: 12px;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.ant-list-item {
|
|
|
|
|
padding: 12px 24px;
|
|
|
|
|
transition: background-color 300ms;
|
|
|
|
|
|
|
|
|
|
&:hover {
|
|
|
|
|
background-color: #e6f7ff;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.bottom-buttons {
|
|
|
|
|
text-align: center;
|
|
|
|
|
border-top: 1px solid #f0f0f0;
|
|
|
|
|
height: 42px;
|
|
|
|
|
|
|
|
|
|
.ant-btn {
|
|
|
|
|
border: 0;
|
|
|
|
|
height: 100%;
|
|
|
|
|
|
|
|
|
|
&:first-child {
|
|
|
|
|
border-right: 1px solid #f0f0f0;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2021-10-20 14:32:09 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.ant-tabs-content {
|
|
|
|
|
width: 300px;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.ant-badge {
|
|
|
|
|
font-size: 18px;
|
|
|
|
|
|
2022-03-10 09:47:29 +08:00
|
|
|
|
.ant-badge-count {
|
|
|
|
|
@badget-size: 16px;
|
|
|
|
|
width: @badget-size;
|
|
|
|
|
height: @badget-size;
|
|
|
|
|
min-width: @badget-size;
|
|
|
|
|
line-height: @badget-size;
|
|
|
|
|
padding: 0;
|
|
|
|
|
|
|
|
|
|
.ant-scroll-number-only > p.ant-scroll-number-only-unit {
|
|
|
|
|
font-size: 14px;
|
|
|
|
|
height: @badget-size;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-10-20 14:32:09 +08:00
|
|
|
|
.ant-badge-multiple-words {
|
2022-03-10 09:47:29 +08:00
|
|
|
|
padding: 0 0 0 2px;
|
|
|
|
|
font-size: 12px;
|
2021-10-20 14:32:09 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
svg {
|
|
|
|
|
width: 0.9em;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2022-03-10 09:47:29 +08:00
|
|
|
|
|
|
|
|
|
// 兼容黑暗模式
|
|
|
|
|
[data-theme='dark'] .@{prefix-cls} {
|
|
|
|
|
&__overlay {
|
|
|
|
|
.ant-list-item {
|
|
|
|
|
&:hover {
|
|
|
|
|
background-color: #111b26;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.bottom-buttons {
|
|
|
|
|
border-top: 1px solid #303030;
|
|
|
|
|
|
|
|
|
|
.ant-btn {
|
|
|
|
|
&:first-child {
|
|
|
|
|
border-right: 1px solid #303030;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2021-10-20 14:32:09 +08:00
|
|
|
|
</style>
|