From 70670c3efedcecf10b9dacd9233a6d6e744f5cd4 Mon Sep 17 00:00:00 2001 From: x_ying <2438792676@qq.com> Date: Wed, 24 Aug 2022 16:42:03 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8F=B3=E4=B8=8A=E8=A7=92=E6=88=91=E7=9A=84?= =?UTF-8?q?=E6=B6=88=E6=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/assets/styles/yxk-admin.scss | 2 +- src/layout/components/Navbar.vue | 82 ++++++++++++++++++++++++++++---- src/views/system/user/center.vue | 7 +++ 3 files changed, 80 insertions(+), 11 deletions(-) diff --git a/src/assets/styles/yxk-admin.scss b/src/assets/styles/yxk-admin.scss index 7b48f46..1dd7e2f 100644 --- a/src/assets/styles/yxk-admin.scss +++ b/src/assets/styles/yxk-admin.scss @@ -1103,7 +1103,7 @@ input[type='number'] { line-height: 40px; } p{ - width: 230px; + width: 220px; overflow: hidden; text-overflow: ellipsis; display: -webkit-box; diff --git a/src/layout/components/Navbar.vue b/src/layout/components/Navbar.vue index e2aad52..6660fc9 100644 --- a/src/layout/components/Navbar.vue +++ b/src/layout/components/Navbar.vue @@ -29,19 +29,22 @@
- 6 + {{ msgList.length }}
- 全部标记为已读 + 全部标记为已读 去查看
- - -

这是一条系统通知系统通知这是一条系统通知系统通知

- 2022-5-23 13:30 + +
暂无最新消息
+
+ + +

{{ item.noticeContent }}

+ {{ item.create_time | parseTime }}
@@ -104,6 +107,7 @@ import Logo from '@/layout/components/Sidebar/Logo' // import SizeSelect from '@/components/SizeSelect' // import Search from '@/components/HeaderSearch' import Avatar from '@/assets/images/avatar.png' +import { getUserNotice, isread } from '@/api/system/logs' export default { components: { @@ -120,9 +124,10 @@ export default { Avatar: Avatar, defaultImg: 'this.src="' + require('@/assets/images/avatar.png') + '"', logoutVisible: false, - readMsg: null + msgList: [] } }, + computed: { ...mapGetters([ 'sidebar', @@ -148,10 +153,67 @@ export default { return !this.sidebar.opened } }, + created() { + this.getMsgList() + }, methods: { - // 未读消息 - getReadMsg() { - + // 获取未读消息 + async getMsgList() { + const params = { + page: 0, + size: 10, + // createTime: [], + sort: 'createTime,desc' + } + const list = [] + const allList = await this.getAllNoRead(params, list) + console.log(allList, 'allList') + allList.forEach(item => { + item.pushUserName = item.noticeUsers[0].pushUserName + item.isRead = item.noticeUsers[0].isRead + }) + const arr = allList.filter(item => { return !item.isRead }) + console.log(arr, 'msg') + if (arr.length > 20) { + this.msgList = arr.slice(0, 20) + } else { + this.msgList = arr + } + }, + // 全部已读 + async handleAllRead() { + const params = { + page: 0, + size: 10, + // createTime: [], + sort: 'createTime,desc' + } + const list = [] + const ids = [] + const allList = await this.getAllNoRead(params, list) + allList.forEach(item => { + item.noticeUsers.forEach(i => { + ids.push(i.id) + }) + }) + isread(ids).then(res => { + if (res) { + this.msgList = [] + } + }) + }, + // 递归获取所有消息列表 + async getAllNoRead(params, list) { + const allList = await getUserNotice(params).then(res => { + list = list.concat(res.content) + if ((list.length) < res.totalElements) { + params.page++ + return this.getAllNoRead(params, list) + } else { + return list + } + }) + return allList }, toggleSideBar() { this.$store.dispatch('app/toggleSideBar') diff --git a/src/views/system/user/center.vue b/src/views/system/user/center.vue index 2cfb2c7..d7948f5 100644 --- a/src/views/system/user/center.vue +++ b/src/views/system/user/center.vue @@ -164,6 +164,13 @@ export default { 'baseApi' ]) }, + watch: { + '$route'(val, from) { // 监听到路由(参数)改变 + if (this.$route.query) { + this.activeIndex = this.$route.query.activeIndex + } + } + }, created() { this.form = { id: this.user.id, nickName: this.user.nickName, gender: this.user.gender, phone: this.user.phone } store.dispatch('GetInfo').then(() => {})