Browse Source

菜单工厂权限

dev
常熟吴彦祖 4 weeks ago
parent
commit
c02c3f1d6e
  1. 25
      src/router/index.js
  2. 3
      src/store/modules/user.js
  3. 2
      src/views/common/login.vue

25
src/router/index.js

@ -10,6 +10,7 @@ import http from '@/utils/httpRequest'
import { isURL } from '@/utils/validate'
import { clearLoginInfo } from '@/utils'
import i18n from '@/i18n/i18n'
import store from '@/store'
Vue.use(Router)
@ -70,6 +71,20 @@ const router = new Router({
routes: globalRoutes.concat(mainRoutes)
})
/**
* 菜单拉取前统一解析当前工厂并兜底回写到store.user.site - rqrq
*/
function resolveCurrentMenuSite () {
const storeSiteRaw = store.state.user.site
const storeSite = (storeSiteRaw === null || storeSiteRaw === undefined) ? '' : String(storeSiteRaw).trim()
const cacheSite = (localStorage.getItem('site') || '').trim()
const currentSite = (storeSite && storeSite !== '0') ? storeSite : cacheSite
if (currentSite) {
store.commit('user/updateSite', currentSite)
}
return currentSite
}
router.beforeEach((to, from, next) => {
// 检查登录状态(除了登录页和404页)
if (to.name !== 'login' && to.name !== '404' && !to.path.startsWith('/dashboard-')) {
@ -87,12 +102,20 @@ router.beforeEach((to, from, next) => {
if (router.options.isAddDynamicMenuRoutes || fnCurrentRouteType(to, globalRoutes) === 'global') {
next()
} else {
const currentSite = resolveCurrentMenuSite()
if (!currentSite) {
console.log('当前登录工厂为空,跳转至登录页')
clearLoginInfo()
next({ name: 'login' })
return
}
http({
url: http.adornUrl('/sys/menu/nav'),
method: 'get',
params: {
'l': i18n.locale, //i18n.locale
menuType: "pc"
menuType: "pc",
site: currentSite
}
}).then(({data}) => {
if (data && data.code === 0) {

3
src/store/modules/user.js

@ -3,7 +3,8 @@ export default {
state: {
id: 0,
name: '',
site: 0,
// 当前登录工厂编码,默认空字符串避免数值0与真实site混淆 - rqrq
site: '',
languageDefault: '',
userDisplay: '',
userDev: false,

2
src/views/common/login.vue

@ -239,6 +239,8 @@
localStorage.setItem('refresh', "0")
localStorage.setItem('userName', this.dataForm.userName)
localStorage.setItem('site', this.selectedSite) //
// store.user.site - rqrq
this.$store.commit('user/updateSite', this.selectedSite)
this.getConfigParams()
this.cacheUserAuthorizedSubSiteCodes(this.dataForm.userName, this.selectedSite).finally(() => {

Loading…
Cancel
Save