fzq #31

Closed
fanzhiqin wants to merge 215 commits from fzq into test
4 changed files with 41 additions and 13 deletions
Showing only changes of commit 38afe6cbb9 - Show all commits

View File

@ -91,6 +91,7 @@ router.beforeEach((to, from, next) => {
if (window.SITE_CONFIG['dynamicMenuRoutesHasAdded'] || fnCurrentRouteIsPageRoute(to, pageRoutes)) {
return next()
}
// 获取字典列表, 添加并全局变量保存
http.get(http.adornUrl('/sys/dict/type/all')).then(({ data: res }) => {
if (res.code !== 0) {
@ -98,20 +99,15 @@ router.beforeEach((to, from, next) => {
}
window.SITE_CONFIG['dictList'] = res.data
}).catch((err) => {
// console.log("catch /sys/dict/type/all", err)
})
// 获取菜单列表, 添加并全局变量保存
http.get(http.adornUrl('/sys/menu/nav')).then(({ data: res }) => {
if (res.code !== 0) {
Vue.prototype.$message.error(res.msg)
return next({ name: 'login' })
}
console.log('menulist: ', res.data)
/** axios 的拦截器已经拦截出错情况,此处只考虑正确情况即可 */
window.SITE_CONFIG['menuList'] = res.data
fnAddDynamicMenuRoutes(window.SITE_CONFIG['menuList'])
next({ ...to, replace: true })
}).catch((err) => {
next({ name: 'login' })
// Vue.prototype.$message.error(err)
})
})
@ -140,6 +136,7 @@ function fnCurrentRouteIsPageRoute(route, pageRoutes = []) {
*/
function fnAddDynamicMenuRoutes(menuList = [], routes = []) {
var temp = []
for (var i = 0; i < menuList.length; i++) {
if (menuList[i].children && menuList[i].children.length >= 1) {
temp = temp.concat(menuList[i].children)
@ -168,9 +165,11 @@ function fnAddDynamicMenuRoutes(menuList = [], routes = []) {
}
routes.push(route)
}
if (temp.length >= 1) {
return fnAddDynamicMenuRoutes(temp, routes)
}
// 添加路由
router.addRoutes([
{

View File

@ -48,6 +48,7 @@ export function clearLoginInfo () {
store.commit('resetStore')
Cookies.remove('token')
window.SITE_CONFIG['dynamicMenuRoutesHasAdded'] = false
window.SITE_CONFIG['dynamicMenuRoutes'] = []
}
/**

View File

@ -8,7 +8,7 @@
:collapseTransition="false"
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>
</div>
</aside>
@ -18,13 +18,40 @@
import SubMenu from './main-sidebar-sub-menu'
export default {
data() {
return {}
return {
unhiddenMenuList: []
}
},
components: {
SubMenu
},
created() {
this.$store.state.sidebarMenuList = window.SITE_CONFIG['menuList']
mounted() {
// 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>

View File

@ -105,7 +105,8 @@ export default {
confirmPassword: [{ validator: validateConfirmPassword, trigger: 'blur' }],
realName: [{ required: true, message: this.$t('validate.required'), trigger: 'blur' }],
email: [{ validator: validateEmail, trigger: 'blur' }],
mobile: [{ validator: validateMobile, trigger: 'blur' }]
mobile: [{ validator: validateMobile, trigger: 'blur' }],
roleIdList: [{ required: true, message: '至少选择一个角色', trigger: 'change' }]
}
}
},