|
|
@@ -1,40 +1,5 @@
|
|
|
-import { asyncRoutes, constantRoutes } from '@/router'
|
|
|
import Layout from '@/layout'
|
|
|
|
|
|
-/**
|
|
|
- * Use meta.role to determine if the current user has permission
|
|
|
- * @param roles
|
|
|
- * @param route
|
|
|
- */
|
|
|
-function hasPermission(roles, route) {
|
|
|
- if (route.meta && route.meta.roles) {
|
|
|
- return roles.some(role => route.meta.roles.includes(role))
|
|
|
- } else {
|
|
|
- return true
|
|
|
- }
|
|
|
-}
|
|
|
-
|
|
|
-/**
|
|
|
- * Filter asynchronous routing tables by recursion
|
|
|
- * @param routes asyncRoutes
|
|
|
- * @param roles
|
|
|
- */
|
|
|
-export function filterAsyncRoutes(routes, roles) {
|
|
|
- const res = []
|
|
|
-
|
|
|
- routes.forEach(route => {
|
|
|
- const tmp = { ...route }
|
|
|
- if (hasPermission(roles, tmp)) {
|
|
|
- if (tmp.children) {
|
|
|
- tmp.children = filterAsyncRoutes(tmp.children, roles)
|
|
|
- }
|
|
|
- res.push(tmp)
|
|
|
- }
|
|
|
- })
|
|
|
-
|
|
|
- return res
|
|
|
-}
|
|
|
-
|
|
|
const state = {
|
|
|
routes: [],
|
|
|
addRoutes: []
|
|
|
@@ -56,7 +21,6 @@ const mutations = {
|
|
|
*/
|
|
|
export function generaMenu(routes, data) {
|
|
|
data.forEach(item => {
|
|
|
-
|
|
|
const menu = {
|
|
|
path: '/' + item.routePath,
|
|
|
component: Layout,
|
|
|
@@ -65,7 +29,8 @@ const mutations = {
|
|
|
children: [],
|
|
|
name: item.name,
|
|
|
meta: {
|
|
|
- title: item.metaTitle,
|
|
|
+ // 接口需要新返回一个字段,标记语言标签 使用 item.routeLangFlag
|
|
|
+ title: testBackLangTitle(item.name),
|
|
|
icon: item.icon
|
|
|
}
|
|
|
}
|
|
|
@@ -73,82 +38,44 @@ const mutations = {
|
|
|
if (item.child) {
|
|
|
generaMenu(menu.children, item.child)
|
|
|
}
|
|
|
- // if (item.routePath != 'dashboard/index') {
|
|
|
- routes.push(menu)
|
|
|
- // }
|
|
|
+
|
|
|
+ routes.push(menu)
|
|
|
})
|
|
|
return routes
|
|
|
}
|
|
|
|
|
|
+export function testBackLangTitle(name) {
|
|
|
+ let ret = name
|
|
|
+ if (name == '控制台' || name == 'Dashboard') {
|
|
|
+ ret = 'dashboard'
|
|
|
+ } else if (name == '商城管理' || name == 'Shopping Mall') {
|
|
|
+ ret = 'shop'
|
|
|
+ } else if (name == '商品列表' || name == 'Products list') {
|
|
|
+ ret = 'indexShop'
|
|
|
+ } else if (name == '复消商品') {
|
|
|
+ ret = 'shopReconsume'
|
|
|
+ } else if (name == '会员管理' || name == 'Member management') {
|
|
|
+ ret = 'memberManagement'
|
|
|
+ } else if (name == 'Personal info' || name == '个人资料') {
|
|
|
+ ret = 'personalInfo'
|
|
|
+ }
|
|
|
+
|
|
|
+ return ret
|
|
|
+}
|
|
|
|
|
|
-// 系统使用版
|
|
|
const actions = {
|
|
|
generateRoutes({ commit }, roles) {
|
|
|
return new Promise(resolve => {
|
|
|
- let accessedRoutes
|
|
|
roles = ['admin']
|
|
|
let baseInfo = JSON.parse(localStorage.getItem('baseInfo'))
|
|
|
- // let apiMenu = baseInfo.menu---调试先写固定
|
|
|
- let apiMenu = [
|
|
|
- {
|
|
|
- "name":"控制台",
|
|
|
- "class":"",
|
|
|
- "icon":"el-icon-guide",
|
|
|
- "controller":"dashboard",
|
|
|
- "action":"index",
|
|
|
- "routePath":"dashboard/index",
|
|
|
- "show":1,
|
|
|
- "metaTitle": 'dashboard',
|
|
|
- "child":[
|
|
|
-
|
|
|
- ]
|
|
|
- },
|
|
|
- {
|
|
|
- "name":"商城管理",
|
|
|
- "class":"",
|
|
|
- "icon":"el-icon-goods",
|
|
|
- "controller":"shop",
|
|
|
- "action":"",
|
|
|
- "routePath":"shop",
|
|
|
- "metaTitle":'shop',
|
|
|
- "show":1,
|
|
|
- "child":[
|
|
|
- {
|
|
|
- "name":"商品列表",
|
|
|
- "class":"",
|
|
|
- "icon":"",
|
|
|
- "controller":"shop",
|
|
|
- "action":"index",
|
|
|
- "routePath":"shop/index",
|
|
|
- "show":1,
|
|
|
- "metaTitle": 'indexShop'
|
|
|
- }
|
|
|
- ]
|
|
|
- }
|
|
|
- ]
|
|
|
+ let apiMenu = baseInfo.menu//---调试先写固定 metaTitle 为新增字段,代表语言对应标记字符串
|
|
|
let formatMenu = generaMenu([], apiMenu)
|
|
|
- accessedRoutes = formatMenu //filterAsyncRoutes(asyncRoutes, roles)
|
|
|
- commit('SET_ROUTES', accessedRoutes)
|
|
|
- resolve(accessedRoutes)
|
|
|
+ commit('SET_ROUTES', formatMenu)
|
|
|
+ resolve(formatMenu)
|
|
|
})
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-// const actions = {
|
|
|
-// generateRoutes({ commit }, roles) {
|
|
|
-// return new Promise(resolve => {
|
|
|
-// let accessedRoutes
|
|
|
-// if (roles.includes('admin')) {
|
|
|
-// accessedRoutes = asyncRoutes || []
|
|
|
-// } else {
|
|
|
-// accessedRoutes = filterAsyncRoutes(asyncRoutes, roles)
|
|
|
-// }
|
|
|
-// commit('SET_ROUTES', accessedRoutes)
|
|
|
-// resolve(accessedRoutes)
|
|
|
-// })
|
|
|
-// }
|
|
|
-// }
|
|
|
-
|
|
|
export default {
|
|
|
namespaced: true,
|
|
|
state,
|