CaiYuanYiTiHua/src/layouts/default/header/components/notify/index.vue

197 lines
5.2 KiB
Vue
Raw Normal View History

2024-05-11 09:53:05 +08:00
<template>
<div :class="prefixCls">
<Popover title="" trigger="click" :overlayClassName="`${prefixCls}__overlay`">
<Badge :count="count" dot :numberStyle="numberStyle">
<BellOutlined />
</Badge>
<template #content>
<Tabs>
<template v-for="item in listData" :key="item.key">
<Tabs.TabPane>
<template #tab>
{{ item.name }}
<span v-if="item.list.length !== 0">({{ item.list.length }})</span>
</template>
<!-- 绑定title-click事件的通知列表中标题是可点击-->
<NoticeList :list="item.list" v-if="item.key === '1'" @title-click="onNoticeClick" />
<NoticeList :list="item.list" v-else />
</Tabs.TabPane>
</template>
</Tabs>
</template>
</Popover>
<a-modal
width="100%"
wrap-class-name="full-modal"
v-model:open="auditOpen"
title="详情"
:destroyOnClose="true"
>
<template #footer> </template>
<Look ref="posRef" :processId="processId" />
</a-modal>
<Message @register="register" />
2024-05-11 09:53:05 +08:00
</div>
</template>
<script lang="ts" setup>
import { computed, onMounted, ref, h } from 'vue';
2024-05-11 09:53:05 +08:00
import { Popover, Tabs, Badge } from 'ant-design-vue';
import { BellOutlined } from '@ant-design/icons-vue';
import { tabListData } from './data';
2024-05-11 09:53:05 +08:00
import { useDesign } from '@/hooks/web/useDesign';
import { useMessage } from '@/hooks/web/useMessage';
import { getLastList, loadSysImMsgList, readMsg } from '@/api/demo/message';
import { useUserStore } from '@/store/modules/user';
import { Look } from '@/views/demo/workflow/task/process/page';
import { useModal } from '@/components/Modal';
import NoticeList from './NoticeList.vue';
import Message from './message.vue';
import { signal } from '@/utils/signalR';
const [register, { openModal }] = useModal();
const userStore = useUserStore();
const userInfo: any = userStore.getUserInfo;
2024-05-11 09:53:05 +08:00
const { prefixCls } = useDesign('header-notify');
const { createMessage, notification } = useMessage();
2024-05-11 09:53:05 +08:00
const listData = ref(tabListData);
const numberStyle = {};
const auditOpen = ref(false);
const processId = ref('');
2024-05-11 09:53:05 +08:00
const count = computed(() => {
let count = 0;
for (let i = 0; i < listData.value.length; i++) {
count += listData.value[i].list.length;
2024-05-11 09:53:05 +08:00
}
return count;
});
async function onNoticeClick(record) {
console.log(record);
// createMessage.success('你点击了通知ID=' + record.id);
// // 可以直接将其标记为已读(为标题添加删除线),此处演示的代码会切换删除线状态
// record.titleDelete = !record.titleDelete;
const index = listData.value[0].list.findIndex((item: any) => item.id === record.id);
if (index !== -1) {
listData.value[0].list.splice(index, 1);
}
if (record.contentId) {
auditOpen.value = true;
processId.value = record.contentId;
}
const data = await readMsg({
id: record.msgId,
});
}
async function getList() {
const data = await getLastList({
userId: userInfo.id,
});
// const data = await loadSysImMsgList({
// page: 1,
// limit: 10,
// });
console.log(data);
let arr: any = [];
2024-07-10 13:58:51 +08:00
if (data && data.length > 0) {
data.forEach((item: any) => {
arr.push({
id: item.msgId,
title: item.content,
datetime: item.createDate,
contentId: item.contentId,
});
});
listData.value[0].list = arr;
}
2024-05-11 09:53:05 +08:00
}
// 连接
async function start() {
try {
await signal.start().then(() => {
signal
.invoke('SendInfo', userInfo.id.toString())
.catch((err) => console.error(err.toString()));
});
console.log('userInfo.id', userInfo.id);
console.log('SignalR Connected.连接成功');
} catch (err) {
console.log(err);
// setTimeout(start, 5000);
}
}
signal.onclose(async () => {
await start();
});
//接口推送
signal.on('RevMsg', (user, message, time, id, issystem) => {
console.log('报警', user, message, time, id, issystem); //拿到后台推送的数据
notification.info({
message: '您有一条新消息',
description: () => {
const res = message + '\n' + time;
return h('pre', {}, res);
},
duration: 3,
});
getList();
// openModal(true, {
// user: user,
// message: message,
// time: time,
// id: id,
// issystem: issystem,
// });
});
onMounted(() => {
getList();
start();
});
2024-05-11 09:53:05 +08:00
</script>
<style lang="less">
@prefix-cls: ~'@{namespace}-header-notify';
.@{prefix-cls} {
padding-bottom: 1px;
&__overlay {
max-width: 360px;
}
.ant-tabs-content {
width: 300px;
}
.ant-badge {
display: flex;
align-items: center;
font-size: 18px;
.ant-badge-multiple-words {
padding: 0 4px;
}
svg {
width: 0.9em;
}
}
}
.full-modal {
.ant-modal {
max-width: 100%;
top: 0;
}
.ant-modal-content {
height: calc(100vh);
}
.ant-modal-body {
height: 85%;
}
}
2024-05-11 09:53:05 +08:00
</style>