From 04e64c5a21816c348af8f7fb48709bd6066eaf8a Mon Sep 17 00:00:00 2001 From: air <30444667+sszdot@users.noreply.github.com> Date: Thu, 12 Jun 2025 19:31:17 +0800 Subject: [PATCH] =?UTF-8?q?=E3=80=90=E7=B1=BB=20=20=E5=9E=8B=E3=80=91?= =?UTF-8?q?=EF=BC=9Afeat=20=E3=80=90=E5=8E=9F=20=20=E5=9B=A0=E3=80=91?= =?UTF-8?q?=EF=BC=9A=E9=9C=80=E8=A6=81=E7=AE=A1=E7=90=86=E5=91=98=E8=83=BD?= =?UTF-8?q?=E5=A4=9F=E5=8F=91=E5=B8=83=E5=85=AC=E5=91=8A=E4=BF=A1=E6=81=AF?= =?UTF-8?q?=EF=BC=8C=E6=96=B9=E4=BE=BF=E5=90=91=E7=AE=A1=E7=90=86=E5=91=98?= =?UTF-8?q?=E5=8F=8A=E6=97=B6=E4=BC=A0=E8=BE=BE=E9=87=8D=E8=A6=81=E9=80=9A?= =?UTF-8?q?=E7=9F=A5=E3=80=82=20=E3=80=90=E8=BF=87=20=20=E7=A8=8B=E3=80=91?= =?UTF-8?q?=EF=BC=9A=E5=A2=9E=E5=8A=A0=E5=85=AC=E5=91=8A=E7=AE=A1=E7=90=86?= =?UTF-8?q?=E6=A8=A1=E5=9D=97=EF=BC=8C=E6=94=AF=E6=8C=81=E6=8C=87=E5=AE=9A?= =?UTF-8?q?=E7=AE=A1=E7=90=86=E5=91=98=E7=94=A8=E6=88=B7=E5=8F=91=E5=B8=83?= =?UTF-8?q?=E5=85=AC=E5=91=8A=E3=80=82=E7=AE=A1=E7=90=86=E5=91=98=E7=99=BB?= =?UTF-8?q?=E5=BD=95=E6=97=B6=E8=87=AA=E5=8A=A8=E5=BC=B9=E5=87=BA=E5=85=AC?= =?UTF-8?q?=E5=91=8A=E5=88=97=E8=A1=A8=E6=A1=86=E3=80=82=20=E3=80=90?= =?UTF-8?q?=E5=BD=B1=20=20=E5=93=8D=E3=80=91=EF=BC=9A=E6=96=B0=E5=A2=9E?= =?UTF-8?q?=E5=85=AC=E5=91=8A=E5=8A=9F=E8=83=BD=E6=A8=A1=E5=9D=97=EF=BC=8C?= =?UTF-8?q?=E6=B6=89=E5=8F=8A=E7=AE=A1=E7=90=86=E5=91=98=E7=95=8C=E9=9D=A2?= =?UTF-8?q?=E5=92=8C=E9=80=9A=E7=9F=A5=E5=BC=B9=E7=AA=97=E9=80=BB=E8=BE=91?= =?UTF-8?q?=EF=BC=8C=E4=B8=8D=E5=BD=B1=E5=93=8D=E5=85=B6=E4=BB=96=E4=B8=9A?= =?UTF-8?q?=E5=8A=A1=E5=8A=9F=E8=83=BD=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/router/index.js | 11 +++ src/store/index.js | 38 ++++++++- src/store/modules/app.js | 10 ++- src/utils/api/table.js | 18 +++++ .../layout/components/main/admin/index.vue | 15 +++- .../layout/components/main/admin/message.vue | 81 +++++++++---------- src/views/layout/index.vue | 1 + 7 files changed, 128 insertions(+), 46 deletions(-) diff --git a/src/router/index.js b/src/router/index.js index adaba67..9a73165 100644 --- a/src/router/index.js +++ b/src/router/index.js @@ -310,6 +310,17 @@ const routes = [ tapName: 'admin', hidden: true } + }, + { + path: '/admin/message', + component: () => import('@/views/layout/components/main/admin/message'), + meta: { + title: '发布公告', + icon: 'el-icon-microphone', + roles: ['admin', 'editor'], + tapName: 'admin', + hidden: true + } } ] }, diff --git a/src/store/index.js b/src/store/index.js index ffd5060..b5c4dc1 100644 --- a/src/store/index.js +++ b/src/store/index.js @@ -5,7 +5,7 @@ import app from './modules/app' import settings from './modules/settings' import user from './modules/user' import api from '@/utils/api' -import { Message, MessageBox } from 'element-ui' +import { Message, MessageBox, Notification } from 'element-ui' // 把vuex作为插件引入到Vue示例中 ps:注册 Vue.use(Vuex) @@ -23,6 +23,7 @@ const store = new Vuex.Store({ skuList: [], // 商品sku列表 paidOrderList: [], // 已付款 和已退款但是发货状态为 已发货 订单列表 logList: [], // 操作日志列表 + messageList: [], // 管理员公告列表 crosFrequency: null// 对频macadd }, mutations: { @@ -102,6 +103,13 @@ const store = new Vuex.Store({ insertNewLog (state, logData) { state.logList.push(logData) }, + /** + * @description: 向管理员公告列表最后插入新的信息 + * @param {*} list + */ + setMessageList (state, list) { + state.messageList = list + }, /** * @description: 登记对频信息 */ @@ -980,6 +988,34 @@ const store = new Vuex.Store({ } return res }, + /** + * @description: 异步获取管理员消息列表 成功获取之后 弹出通知框 显示列表 + */ + async fetchMessageList ({ commit }) { + const res = await api.get('getMessageList', 'Admin') + + if (res.data.status === 1) { + const list = res.data.messageList || [] + commit('setMessageList', list) + + // 每条通知之间延迟 800ms,显示时间为 8000ms + list.forEach((item, index) => { + setTimeout(() => { + Notification({ + title: item.tit || '通知', + message: item.message || '', + duration: 8000, // 显示时间 8 秒 + type: 'info' // 可选类型: success / warning / error / info + }) + }, index * 800) + }) + } else { + Message.error(res.data.msg || '获取消息失败') + commit('setMessageList', []) + } + + return res + }, /** * @description: 向操作日志插入信息 并在积攒多条之后 向服务器提交 * @param {logData} content 日志内容 logData.color 时间 diff --git a/src/store/modules/app.js b/src/store/modules/app.js index 50c55f4..e6d0297 100644 --- a/src/store/modules/app.js +++ b/src/store/modules/app.js @@ -5,7 +5,10 @@ const state = { isWideScreen: window.innerWidth < 480, // 屏幕宽度是否小于480 defaultLonLat: null, // 地图默认经纬度 defaultZoom: null, // 地图默认缩放 - orderSerch: null// 订单列表页搜索条件 + orderSerch: null, // 订单列表页搜索条件 + + /* 页面临时传参 */ + toMessageIdArr: [] // 用户管理 发布公告页面 id临时传参 } const mutations = { @@ -50,6 +53,11 @@ const mutations = { // 存储到 localStorage localStorage.setItem('orderSerch', JSON.stringify(state.orderSerch)) + }, + + /* 临时传参 */ + setToMessageIdArr (state, idArr) { + state.toMessageIdArr = idArr } } diff --git a/src/utils/api/table.js b/src/utils/api/table.js index e3e9aae..7c15488 100644 --- a/src/utils/api/table.js +++ b/src/utils/api/table.js @@ -143,3 +143,21 @@ export async function addLog (log) { const res = await api.post('addLog', params) return res } + +/** + * @description: 向管理员用户发布公告 + * @param {*} tit 公告标题 + * @param {*} message 公告内容 + * @param {*} idArr 接收公告的管理员ID数组 + * @param {*} endTime 公告截至时间(时间戳) + */ +export async function pubMessage (tit, message, idArr, endTime) { + const params = new URLSearchParams() + params.append('tit', tit) + params.append('message', message) + params.append('idArr', idArr.join(',')) // 后端只收字符串 + params.append('endTime', endTime) + + const res = await api.post('pubMessage', params, 'Admin') // 模块名根据你实际配置来 + return res +} diff --git a/src/views/layout/components/main/admin/index.vue b/src/views/layout/components/main/admin/index.vue index 77195f8..14e29b6 100644 --- a/src/views/layout/components/main/admin/index.vue +++ b/src/views/layout/components/main/admin/index.vue @@ -6,6 +6,7 @@ 删除 编辑 + 发布公告 @@ -32,12 +33,13 @@ {{ scope.row.addtime | parseTime('{y}-{m}-{d}') }} - + @@ -101,6 +103,17 @@ export default { this.$message.error('只能选择一条记录') } }, + /** + * @description: 跳转到发布公告页面 + */ + toMessagePage (selIdArr) { + if (selIdArr.length === 0) { + this.$message.error('请选择至少一个用户') + } else { + this.$store.commit('app/setToMessageIdArr', selIdArr)// 传参 + this.$router.push('/admin/message/') + } + }, /** * @description: 删除用户 */ diff --git a/src/views/layout/components/main/admin/message.vue b/src/views/layout/components/main/admin/message.vue index 40bccbc..392215f 100644 --- a/src/views/layout/components/main/admin/message.vue +++ b/src/views/layout/components/main/admin/message.vue @@ -11,30 +11,19 @@ - - + + + + + - + - + 发布公告 @@ -55,7 +44,8 @@ export default { return { form: { date: '', - message: '' + message: '', + tit: '' }, loading: false } @@ -66,37 +56,42 @@ export default { return this.$store.state.app.toMessageIdArr } }, + created () { + }, methods: { async pubMessage () { - // 校验内容 - if (!this.form.message.trim()) { + // 判断 idArr 是否为空 + if (!this.idArr || this.idArr.length === 0) { + this.$message.warning('接收用户为空,请重新操作') + this.$router.push('/admin/index') + return + } + if (!this.form.tit) { + this.$message.error('请输入公告标题') + return + } + if (!this.form.message) { this.$message.error('请输入公告内容') return } if (!this.form.date) { - this.$message.error('请选择显示截止日期') - return - } - if (!this.ids.length) { - this.$message.error('接收用户为空,请重新操作') + this.$message.error('请选择截止日期') return } - this.loading = true - try { - const res = await pubMessage(this.form.message, this.ids, this.form.date) - if (res.status === 1) { - this.$message.success(res.msg || '公告发布成功') - this.form.message = '' - this.form.date = '' - } else { - this.$message.error(res.msg || '公告发布失败') - } - } catch (error) { - this.$message.error('接口请求失败') - console.error(error) - } finally { - this.loading = false + const endTime = Math.floor(new Date(this.form.date).getTime() / 1000 + 86400) + + const res = await pubMessage(this.form.tit, this.form.message, this.idArr, endTime) + + if (res.data.status === 1) { + this.$message.success(res.data.msg) + this.form.message = '' + this.form.date = '' + this.form.tit = '' + // 跳转到首页 + this.$router.push('/admin/index') + } else { + this.$message.error(res.data.msg || '公告发布失败') } } } diff --git a/src/views/layout/index.vue b/src/views/layout/index.vue index 4168012..8076ad6 100644 --- a/src/views/layout/index.vue +++ b/src/views/layout/index.vue @@ -69,6 +69,7 @@ export default { this.$store.dispatch('fetchSpuList')// 获取商品spu列表 this.$store.dispatch('fetchSkuList')// 获取商品sku列表 this.$store.dispatch('fetchPaidOrderList')// 获取订单列表 + this.$store.dispatch('fetchMessageList')// 获取管理员公告列表 }, watch: { /**