import {updateUserNotice, workshopNoticeList} from "@/api/system/notice"; import {parseTime} from "@/utils/ruoyi"; export const noticeData = { data() { return { showTableDialog: false, //用户下的通知公告List noticeList: [], //当前显示的通知公告 noticeListData: {}, notificationInstance: null // 保存通知实例 }; }, mounted() { setInterval(() => this.workshopNoticeTasks(), 60 * 1000) }, methods: { workshopNoticeTasks() { if (this.notificationInstance) { this.notificationInstance.close(); // 手动关闭通知 } workshopNoticeList({noticeType: '1', checkStatus: '0'}).then(res => { this.noticeList = res.rows; if (this.noticeList.length > 0) { this.notificationInstance = this.$notify.info({ title: '通知', position: 'bottom-right', duration: 0, message: this.$createElement( "div", { on: { click: () => { this.handleNotificationClick(); }, }, }, [this.$createElement("el-button", {}, ["点击查看"])] ), }); } }); }, //点击查看弹窗逻辑 handleNotificationClick() { this.noticeListData = this.noticeList[0]; let userNotice = this.noticeListData.sysUserNoticeList[0]; userNotice.checkStatus = '1' userNotice.checkTime = parseTime(new Date()); //更新用户公告查看状态 updateUserNotice(userNotice).then(res => { this.showTableDialog = true; }) if (this.notificationInstance) { this.notificationInstance.close(); // 手动关闭通知 } }, }, };