From 261d5fe5747225c9b24931643835aaa44c2fa7b1 Mon Sep 17 00:00:00 2001 From: fit2cloud-chenyw Date: Thu, 29 Jul 2021 17:59:31 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E6=B6=88=E6=81=AF=E8=B7=B3=E8=BD=AC?= =?UTF-8?q?=E5=88=B0=E6=97=A0=E6=9D=83=E9=99=90=E8=B7=AF=E7=94=B1=EF=BC=8C?= =?UTF-8?q?=E6=98=BE=E7=A4=BA=E7=A9=BA=E7=99=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/components/Notification/index.vue | 19 +++++++++++--- frontend/src/lang/en.js | 1 + frontend/src/lang/tw.js | 1 + frontend/src/lang/zh.js | 1 + frontend/src/views/msg/all.vue | 23 ++++++++++++++-- frontend/src/views/msg/readed.vue | 22 +++++++++++++++- frontend/src/views/msg/unread.vue | 26 ++++++++++++++++--- 7 files changed, 84 insertions(+), 9 deletions(-) diff --git a/frontend/src/components/Notification/index.vue b/frontend/src/components/Notification/index.vue index abb9559ffc..e295018421 100644 --- a/frontend/src/components/Notification/index.vue +++ b/frontend/src/components/Notification/index.vue @@ -120,17 +120,30 @@ export default { if (this.$route && this.$route.name && this.$route.name === row.router) { // 如果当前路由就是目标路由 那么使用router.push页面不会刷新 这时候要使用事件方式 row.callback && bus.$emit(row.callback, param) + row.status || this.setReaded(row.msgId) } else { - this.$router.push({ name: row.router, params: param }) + if (this.hasPermissionRoute(row.router)) { + this.$router.push({ name: row.router, params: param }) + row.status || this.setReaded(row.msgId) + return + } + this.$warning(this.$t('commons.no_target_permission')) } - - row.status || this.setReaded(row.msgId) }, remove(row) { }, msgSetting() { + }, + hasPermissionRoute(name, permission_routes) { + permission_routes = permission_routes || this.permission_routes + for (let index = 0; index < permission_routes.length; index++) { + const route = permission_routes[index] + if (route.name && route.name === name) return true + if (route.children && this.hasPermissionRoute(name, route.children)) return true + } + return false }, showMore() { const routerName = 'sys-msg-web-all' diff --git a/frontend/src/lang/en.js b/frontend/src/lang/en.js index 23a2c11fba..5996642ff1 100644 --- a/frontend/src/lang/en.js +++ b/frontend/src/lang/en.js @@ -129,6 +129,7 @@ export default { password_error: 'The password can not be less than 8 digits' }, commons: { + no_target_permission: 'No permission', success: 'Success', switch_lang: 'Switch Language Success', close: 'Close', diff --git a/frontend/src/lang/tw.js b/frontend/src/lang/tw.js index a7cb619bdc..93bc0a24b7 100644 --- a/frontend/src/lang/tw.js +++ b/frontend/src/lang/tw.js @@ -129,6 +129,7 @@ export default { password_error: '密碼不小於 8 位' }, commons: { + no_target_permission: '沒有權限', success: '成功', switch_lang: '切換語言成功', close: '關閉', diff --git a/frontend/src/lang/zh.js b/frontend/src/lang/zh.js index 7675d9c116..a68698f6a8 100644 --- a/frontend/src/lang/zh.js +++ b/frontend/src/lang/zh.js @@ -129,6 +129,7 @@ export default { password_error: '密码不小于 8 位' }, commons: { + no_target_permission: '没有权限', success: '成功', switch_lang: '切换语言成功', close: '关闭', diff --git a/frontend/src/views/msg/all.vue b/frontend/src/views/msg/all.vue index 51ab3dd58b..6d98a09703 100644 --- a/frontend/src/views/msg/all.vue +++ b/frontend/src/views/msg/all.vue @@ -55,6 +55,7 @@ import { query, updateStatus } from '@/api/system/msg' import { msgTypes, getTypeName, loadMsgTypes } from '@/utils/webMsg' import bus from '@/utils/bus' import { addOrder, formatOrders } from '@/utils/index' +import { mapGetters } from 'vuex' export default { components: { LayoutContent, @@ -82,6 +83,11 @@ export default { orderConditions: [] } }, + computed: { + ...mapGetters([ + 'permission_routes' + ]) + }, mounted() { this.search() }, @@ -120,8 +126,21 @@ export default { }, toDetail(row) { const param = { ...{ msgNotification: true, msgType: row.typeId, sourceParam: row.param }} - this.$router.push({ name: row.router, params: param }) - row.status || this.setReaded(row) + if (this.hasPermissionRoute(row.router)) { + this.$router.push({ name: row.router, params: param }) + row.status || this.setReaded(row) + return + } + this.$warning(this.$t('commons.no_target_permission')) + }, + hasPermissionRoute(name, permission_routes) { + permission_routes = permission_routes || this.permission_routes + for (let index = 0; index < permission_routes.length; index++) { + const route = permission_routes[index] + if (route.name && route.name === name) return true + if (route.children && this.hasPermissionRoute(name, route.children)) return true + } + return false }, // 设置已读 setReaded(row) { diff --git a/frontend/src/views/msg/readed.vue b/frontend/src/views/msg/readed.vue index bddc2e0f89..0866f44f88 100644 --- a/frontend/src/views/msg/readed.vue +++ b/frontend/src/views/msg/readed.vue @@ -60,6 +60,7 @@ import ComplexTable from '@/components/business/complex-table' import { query } from '@/api/system/msg' import { msgTypes, getTypeName, loadMsgTypes } from '@/utils/webMsg' import { addOrder, formatOrders } from '@/utils/index' +import { mapGetters } from 'vuex' export default { components: { LayoutContent, @@ -87,6 +88,11 @@ export default { } } }, + computed: { + ...mapGetters([ + 'permission_routes' + ]) + }, mounted() { this.search() }, @@ -125,7 +131,21 @@ export default { }, toDetail(row) { const param = { ...{ msgNotification: true, msgType: row.typeId, sourceParam: row.param }} - this.$router.push({ name: row.router, params: param }) + // this.$router.push({ name: row.router, params: param }) + if (this.hasPermissionRoute(row.router)) { + this.$router.push({ name: row.router, params: param }) + return + } + this.$warning(this.$t('commons.no_target_permission')) + }, + hasPermissionRoute(name, permission_routes) { + permission_routes = permission_routes || this.permission_routes + for (let index = 0; index < permission_routes.length; index++) { + const route = permission_routes[index] + if (route.name && route.name === name) return true + if (route.children && this.hasPermissionRoute(name, route.children)) return true + } + return false }, sortChange({ column, prop, order }) { this.orderConditions = [] diff --git a/frontend/src/views/msg/unread.vue b/frontend/src/views/msg/unread.vue index 60f0a30eee..60b8c81c54 100644 --- a/frontend/src/views/msg/unread.vue +++ b/frontend/src/views/msg/unread.vue @@ -65,7 +65,7 @@ import { query, updateStatus, batchRead } from '@/api/system/msg' import { msgTypes, getTypeName, loadMsgTypes } from '@/utils/webMsg' import bus from '@/utils/bus' import { addOrder, formatOrders } from '@/utils/index' - +import { mapGetters } from 'vuex' export default { components: { LayoutContent, @@ -98,6 +98,11 @@ export default { orderConditions: [] } }, + computed: { + ...mapGetters([ + 'permission_routes' + ]) + }, mounted() { this.search() }, @@ -136,8 +141,23 @@ export default { }, toDetail(row) { const param = { ...{ msgNotification: true, msgType: row.typeId, sourceParam: row.param }} - this.$router.push({ name: row.router, params: param }) - this.setReaded(row) + // this.$router.push({ name: row.router, params: param }) + // this.setReaded(row) + if (this.hasPermissionRoute(row.router)) { + this.$router.push({ name: row.router, params: param }) + this.setReaded(row) + return + } + this.$warning(this.$t('commons.no_target_permission')) + }, + hasPermissionRoute(name, permission_routes) { + permission_routes = permission_routes || this.permission_routes + for (let index = 0; index < permission_routes.length; index++) { + const route = permission_routes[index] + if (route.name && route.name === name) return true + if (route.children && this.hasPermissionRoute(name, route.children)) return true + } + return false }, // 设置已读 setReaded(row) {