lb #1
@ -91,6 +91,7 @@ router.beforeEach((to, from, next) => {
|
|||||||
if (window.SITE_CONFIG['dynamicMenuRoutesHasAdded'] || fnCurrentRouteIsPageRoute(to, pageRoutes)) {
|
if (window.SITE_CONFIG['dynamicMenuRoutesHasAdded'] || fnCurrentRouteIsPageRoute(to, pageRoutes)) {
|
||||||
return next()
|
return next()
|
||||||
}
|
}
|
||||||
|
|
||||||
// 获取字典列表, 添加并全局变量保存
|
// 获取字典列表, 添加并全局变量保存
|
||||||
http.get(http.adornUrl('/sys/dict/type/all')).then(({ data: res }) => {
|
http.get(http.adornUrl('/sys/dict/type/all')).then(({ data: res }) => {
|
||||||
if (res.code !== 0) {
|
if (res.code !== 0) {
|
||||||
@ -98,20 +99,15 @@ router.beforeEach((to, from, next) => {
|
|||||||
}
|
}
|
||||||
window.SITE_CONFIG['dictList'] = res.data
|
window.SITE_CONFIG['dictList'] = res.data
|
||||||
}).catch((err) => {
|
}).catch((err) => {
|
||||||
// console.log("catch /sys/dict/type/all", err)
|
|
||||||
})
|
})
|
||||||
// 获取菜单列表, 添加并全局变量保存
|
// 获取菜单列表, 添加并全局变量保存
|
||||||
http.get(http.adornUrl('/sys/menu/nav')).then(({ data: res }) => {
|
http.get(http.adornUrl('/sys/menu/nav')).then(({ data: res }) => {
|
||||||
if (res.code !== 0) {
|
/** axios 的拦截器已经拦截出错情况,此处只考虑正确情况即可 */
|
||||||
Vue.prototype.$message.error(res.msg)
|
|
||||||
return next({ name: 'login' })
|
|
||||||
}
|
|
||||||
console.log('menulist: ', res.data)
|
|
||||||
window.SITE_CONFIG['menuList'] = res.data
|
window.SITE_CONFIG['menuList'] = res.data
|
||||||
fnAddDynamicMenuRoutes(window.SITE_CONFIG['menuList'])
|
fnAddDynamicMenuRoutes(window.SITE_CONFIG['menuList'])
|
||||||
next({ ...to, replace: true })
|
next({ ...to, replace: true })
|
||||||
}).catch((err) => {
|
}).catch((err) => {
|
||||||
next({ name: 'login' })
|
// Vue.prototype.$message.error(err)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
@ -140,6 +136,7 @@ function fnCurrentRouteIsPageRoute(route, pageRoutes = []) {
|
|||||||
*/
|
*/
|
||||||
function fnAddDynamicMenuRoutes(menuList = [], routes = []) {
|
function fnAddDynamicMenuRoutes(menuList = [], routes = []) {
|
||||||
var temp = []
|
var temp = []
|
||||||
|
|
||||||
for (var i = 0; i < menuList.length; i++) {
|
for (var i = 0; i < menuList.length; i++) {
|
||||||
if (menuList[i].children && menuList[i].children.length >= 1) {
|
if (menuList[i].children && menuList[i].children.length >= 1) {
|
||||||
temp = temp.concat(menuList[i].children)
|
temp = temp.concat(menuList[i].children)
|
||||||
@ -168,9 +165,11 @@ function fnAddDynamicMenuRoutes(menuList = [], routes = []) {
|
|||||||
}
|
}
|
||||||
routes.push(route)
|
routes.push(route)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (temp.length >= 1) {
|
if (temp.length >= 1) {
|
||||||
return fnAddDynamicMenuRoutes(temp, routes)
|
return fnAddDynamicMenuRoutes(temp, routes)
|
||||||
}
|
}
|
||||||
|
|
||||||
// 添加路由
|
// 添加路由
|
||||||
router.addRoutes([
|
router.addRoutes([
|
||||||
{
|
{
|
||||||
|
@ -48,6 +48,7 @@ export function clearLoginInfo () {
|
|||||||
store.commit('resetStore')
|
store.commit('resetStore')
|
||||||
Cookies.remove('token')
|
Cookies.remove('token')
|
||||||
window.SITE_CONFIG['dynamicMenuRoutesHasAdded'] = false
|
window.SITE_CONFIG['dynamicMenuRoutesHasAdded'] = false
|
||||||
|
window.SITE_CONFIG['dynamicMenuRoutes'] = []
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -8,7 +8,7 @@
|
|||||||
:collapseTransition="false"
|
:collapseTransition="false"
|
||||||
class="aui-sidebar__menu"
|
class="aui-sidebar__menu"
|
||||||
>
|
>
|
||||||
<sub-menu v-for="menu in $store.state.sidebarMenuList" :key="menu.id" :menu="menu" />
|
<sub-menu v-for="menu in unhiddenMenuList" :key="menu.id" :menu="menu" />
|
||||||
</el-menu>
|
</el-menu>
|
||||||
</div>
|
</div>
|
||||||
</aside>
|
</aside>
|
||||||
@ -18,13 +18,40 @@
|
|||||||
import SubMenu from './main-sidebar-sub-menu'
|
import SubMenu from './main-sidebar-sub-menu'
|
||||||
export default {
|
export default {
|
||||||
data() {
|
data() {
|
||||||
return {}
|
return {
|
||||||
|
unhiddenMenuList: []
|
||||||
|
}
|
||||||
},
|
},
|
||||||
components: {
|
components: {
|
||||||
SubMenu
|
SubMenu
|
||||||
},
|
},
|
||||||
created() {
|
mounted() {
|
||||||
this.$store.state.sidebarMenuList = window.SITE_CONFIG['menuList']
|
// this.$store.state.sidebarMenuList = window.SITE_CONFIG['menuList']
|
||||||
|
this.$nextTick(() => {
|
||||||
|
this.unhiddenMenuList = this.getUnhiddenRoutesListFrom(window.SITE_CONFIG['menuList'])
|
||||||
|
/** 本地保存一份,store保存一份,感觉 store 都不需要保存... */
|
||||||
|
this.$store.state.sidebarMenuList = this.unhiddenMenuList
|
||||||
|
})
|
||||||
|
},
|
||||||
|
methods: {
|
||||||
|
getUnhiddenRoutesListFrom(fullList) {
|
||||||
|
const list = []
|
||||||
|
if (fullList.length) {
|
||||||
|
fullList.forEach(menu => {
|
||||||
|
if (menu.sort !== 99) {
|
||||||
|
/** 前后端约定,路由排序值为 99 时不在前端的侧边栏展示该路由 */
|
||||||
|
const newRouteItem = JSON.parse(JSON.stringify(menu))
|
||||||
|
if (menu.children) {
|
||||||
|
newRouteItem.children = this.getUnhiddenRoutesListFrom(menu.children)
|
||||||
|
}
|
||||||
|
list.push(newRouteItem)
|
||||||
|
} else {
|
||||||
|
console.log(menu.name, '是应该被隐藏的路由')
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
return list
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
@ -105,7 +105,8 @@ export default {
|
|||||||
confirmPassword: [{ validator: validateConfirmPassword, trigger: 'blur' }],
|
confirmPassword: [{ validator: validateConfirmPassword, trigger: 'blur' }],
|
||||||
realName: [{ required: true, message: this.$t('validate.required'), trigger: 'blur' }],
|
realName: [{ required: true, message: this.$t('validate.required'), trigger: 'blur' }],
|
||||||
email: [{ validator: validateEmail, trigger: 'blur' }],
|
email: [{ validator: validateEmail, trigger: 'blur' }],
|
||||||
mobile: [{ validator: validateMobile, trigger: 'blur' }]
|
mobile: [{ validator: validateMobile, trigger: 'blur' }],
|
||||||
|
roleIdList: [{ required: true, message: '至少选择一个角色', trigger: 'change' }]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
Loading…
Reference in New Issue
Block a user