fix: 消息跳转到无权限路由,显示空白

This commit is contained in:
fit2cloud-chenyw 2021-07-29 17:59:31 +08:00
parent 4a5f868090
commit 261d5fe574
7 changed files with 84 additions and 9 deletions

View File

@ -120,17 +120,30 @@ export default {
if (this.$route && this.$route.name && this.$route.name === row.router) { if (this.$route && this.$route.name && this.$route.name === row.router) {
// 使router.push 使 // 使router.push 使
row.callback && bus.$emit(row.callback, param) row.callback && bus.$emit(row.callback, param)
row.status || this.setReaded(row.msgId)
} else { } 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) { remove(row) {
}, },
msgSetting() { 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() { showMore() {
const routerName = 'sys-msg-web-all' const routerName = 'sys-msg-web-all'

View File

@ -129,6 +129,7 @@ export default {
password_error: 'The password can not be less than 8 digits' password_error: 'The password can not be less than 8 digits'
}, },
commons: { commons: {
no_target_permission: 'No permission',
success: 'Success', success: 'Success',
switch_lang: 'Switch Language Success', switch_lang: 'Switch Language Success',
close: 'Close', close: 'Close',

View File

@ -129,6 +129,7 @@ export default {
password_error: '密碼不小於 8 位' password_error: '密碼不小於 8 位'
}, },
commons: { commons: {
no_target_permission: '沒有權限',
success: '成功', success: '成功',
switch_lang: '切換語言成功', switch_lang: '切換語言成功',
close: '關閉', close: '關閉',

View File

@ -129,6 +129,7 @@ export default {
password_error: '密码不小于 8 位' password_error: '密码不小于 8 位'
}, },
commons: { commons: {
no_target_permission: '没有权限',
success: '成功', success: '成功',
switch_lang: '切换语言成功', switch_lang: '切换语言成功',
close: '关闭', close: '关闭',

View File

@ -55,6 +55,7 @@ import { query, updateStatus } from '@/api/system/msg'
import { msgTypes, getTypeName, loadMsgTypes } from '@/utils/webMsg' import { msgTypes, getTypeName, loadMsgTypes } from '@/utils/webMsg'
import bus from '@/utils/bus' import bus from '@/utils/bus'
import { addOrder, formatOrders } from '@/utils/index' import { addOrder, formatOrders } from '@/utils/index'
import { mapGetters } from 'vuex'
export default { export default {
components: { components: {
LayoutContent, LayoutContent,
@ -82,6 +83,11 @@ export default {
orderConditions: [] orderConditions: []
} }
}, },
computed: {
...mapGetters([
'permission_routes'
])
},
mounted() { mounted() {
this.search() this.search()
}, },
@ -120,8 +126,21 @@ export default {
}, },
toDetail(row) { toDetail(row) {
const param = { ...{ msgNotification: true, msgType: row.typeId, sourceParam: row.param }} const param = { ...{ msgNotification: true, msgType: row.typeId, sourceParam: row.param }}
this.$router.push({ name: row.router, params: param }) if (this.hasPermissionRoute(row.router)) {
row.status || this.setReaded(row) 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) { setReaded(row) {

View File

@ -60,6 +60,7 @@ import ComplexTable from '@/components/business/complex-table'
import { query } from '@/api/system/msg' import { query } from '@/api/system/msg'
import { msgTypes, getTypeName, loadMsgTypes } from '@/utils/webMsg' import { msgTypes, getTypeName, loadMsgTypes } from '@/utils/webMsg'
import { addOrder, formatOrders } from '@/utils/index' import { addOrder, formatOrders } from '@/utils/index'
import { mapGetters } from 'vuex'
export default { export default {
components: { components: {
LayoutContent, LayoutContent,
@ -87,6 +88,11 @@ export default {
} }
} }
}, },
computed: {
...mapGetters([
'permission_routes'
])
},
mounted() { mounted() {
this.search() this.search()
}, },
@ -125,7 +131,21 @@ export default {
}, },
toDetail(row) { toDetail(row) {
const param = { ...{ msgNotification: true, msgType: row.typeId, sourceParam: row.param }} 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 }) { sortChange({ column, prop, order }) {
this.orderConditions = [] this.orderConditions = []

View File

@ -65,7 +65,7 @@ import { query, updateStatus, batchRead } from '@/api/system/msg'
import { msgTypes, getTypeName, loadMsgTypes } from '@/utils/webMsg' import { msgTypes, getTypeName, loadMsgTypes } from '@/utils/webMsg'
import bus from '@/utils/bus' import bus from '@/utils/bus'
import { addOrder, formatOrders } from '@/utils/index' import { addOrder, formatOrders } from '@/utils/index'
import { mapGetters } from 'vuex'
export default { export default {
components: { components: {
LayoutContent, LayoutContent,
@ -98,6 +98,11 @@ export default {
orderConditions: [] orderConditions: []
} }
}, },
computed: {
...mapGetters([
'permission_routes'
])
},
mounted() { mounted() {
this.search() this.search()
}, },
@ -136,8 +141,23 @@ export default {
}, },
toDetail(row) { toDetail(row) {
const param = { ...{ msgNotification: true, msgType: row.typeId, sourceParam: row.param }} 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 })
this.setReaded(row) // 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) { setReaded(row) {