Commit b95c8f8d authored by 李苏's avatar 李苏 💬

删除common

parent de9dd04e
common @ 8143dba1
Subproject commit 8143dba1dce0de34c96363bacd7cb7e3ac0446ce
import auth from '@/plugins/auth'
import router, { constantRoutes, dynamicRoutes,powerRoutes } from '@/router'
import { getRouters } from '@/api/menu'
import Layout from '@/layout/index'
import ParentView from '@/components/ParentView'
import InnerLink from '@/layout/components/InnerLink'
import views from 'common'
import vue from 'vue'
const permission = {
state: {
routes: [],
addRoutes: [],
defaultRoutes: [],
topbarRouters: [],
sidebarRouters: [],
appName:'',
},
mutations: {
SET_APPNAME:(state,appName)=>{
state.appName=appName
},
SET_SIDEBAR_SHOW:(state, menusBizType)=>{
state.sidebarRouters.forEach((e,index)=>{
if(menusBizType!='root'&&e.menusBizType&&e.menusBizType==menusBizType){
console.log(e)
state.sidebarRouters[index].hidden=false
}else{
state.sidebarRouters[index].hidden=true
}
if(menusBizType=='root'&&e.mkid){
state.sidebarRouters[index].hidden=false
}
if(e.redirect=='index'){
e.hidden=false
}
})
},
SET_ROUTES: (state, routes) => {
state.addRoutes = routes
state.routes = constantRoutes.concat(routes)
},
SET_DEFAULT_ROUTES: (state, routes) => {
state.defaultRoutes = constantRoutes.concat(routes)
},
SET_TOPBAR_ROUTES: (state, routes) => {
state.topbarRouters = routes
},
SET_SIDEBAR_ROUTERS: (state, routes) => {
state.sidebarRouters = routes
},
},
actions: {
// 生成路由
GenerateRoutes({ commit }) {
return new Promise(resolve => {
// 向后端请求路由数据
getRouters({}).then(res => {
let appName=res.data.appName||''
commit('SET_APPNAME', appName)
localStorage.setItem('appName',appName)
let menus=res.data.menu
let asymenus=JSON.parse(JSON.stringify(res.data.menu))
/* 权限路由*/
/* */
function filter (data) {
var newData = data.filter(
(item)=>{
let hasMkid=false
asymenus.forEach(e=>{
if((e.mkid==item.meta.mkid)||(item.meta.mkid=='test')){
console.log(item,e)
item.meta.icon=e.icon
if(item.meta.mkid!='test'){
item.meta.title=e.mkmc
}
/* 额外参数*/
e.mkid&&(item.mkid=e.mkid)
e.menusBizType&&(item.menusBizType=e.menusBizType)
e.mkid&&(item.menusBizTypeName=e.menusBizTypeName)
hasMkid=true
}
})
return hasMkid
}
)
newData.forEach(x => x.children && (x.children = filter(x.children)))
return newData
}
let newPowerRoutes=filter(powerRoutes)
console.log(newPowerRoutes,'icon')
/* 转化菜单格式*/
let delArr=[]
menus.forEach((item,index)=>{
let routeInfo=routing(item.mkid)
routeInfo.menusBizType=item.menusBizType||false
if(routeInfo&&routeInfo.meta){
routeInfo.meta.url=menus[index].url
routeInfo.meta.icon=menus[index].icon||''
}
menus[index]={...menus[index],...routeInfo}
if(menus[index].component==undefined){
menus[index]={}
}
})
let newmenus=[]
menus.forEach((mi,i)=>{
let length= Object.keys(mi)
if(length!=0){
newmenus.push(mi)
}
})
res.data=[...dgmk(newmenus,0),...newPowerRoutes]
const sdata = JSON.parse(JSON.stringify(res.data))
const rdata = JSON.parse(JSON.stringify(res.data))
const sidebarRoutes = filterAsyncRouter(sdata)
const rewriteRoutes = filterAsyncRouter(rdata, false, true)
const asyncRoutes = filterDynamicRoutes(dynamicRoutes);
rewriteRoutes.push({ path: '*', redirect: '/404', hidden: true })
router.addRoutes(asyncRoutes);
// router.addRoutes(powerRoutes1)
commit('SET_ROUTES', rewriteRoutes)
commit('SET_SIDEBAR_ROUTERS', constantRoutes.concat(sidebarRoutes))
commit('SET_DEFAULT_ROUTES', sidebarRoutes)
commit('SET_TOPBAR_ROUTES', sidebarRoutes)
resolve(rewriteRoutes)
})
})
}
}
}
// 遍历后台传来的路由字符串,转换为组件对象
function filterAsyncRouter(asyncRouterMap, lastRouter = false, type = false) {
return asyncRouterMap.filter(route => {
if (type && route.children) {
route.children = filterChildren(route.children)
}
if (route.component) {
// Layout ParentView 组件特殊处理
if (route.component === 'Layout') {
route.component = Layout
} else if (route.component === 'ParentView') {
route.component = ParentView
} else if (route.component === 'InnerLink') {
route.component = InnerLink
} else {
if(route.commonComponent){
let a=views[route.commonComponent]
route.component=views[route.commonComponent]
}else{
route.component = loadView(route.component)
}
}
}
if (route.children != null && route.children && route.children.length) {
route.children = filterAsyncRouter(route.children, route, type)
} else {
delete route['children']
delete route['redirect']
}
return true
})
}
/* 递归整理*/
function dgmk(arr,pid){
let oldarr = JSON.parse(JSON.stringify(arr))
let outarr = []
oldarr.forEach((e,index)=>{
if(e.fmkid==pid){
outarr.push(e)
e.children=dgmk(oldarr,e.mkid)
}
})
return outarr
}
function routing(mkid){
let componentInfo={}
if(mkid=="101001300"){
componentInfo={
commonComponent:'appVersion',
component: "system/appVersion/index",
hidden:false,
meta:{
"title": "移动端版本",
"icon": "user",
"noCache": false,
"link": null,
"mkid":101001300,
},
name:'AppVersion',
path:"appVersion"
}
}
/* 工作任务*/
else if(mkid=='120130000'){
componentInfo={
commonComponent:'workTask',
component: "development/workTask/index",
hidden:false,
meta:{
"title": "工作任务",
"icon": "user",
"noCache": false,
"link": null,
"mkid":120130000,
},
name:'workTask',
path:"workTask"
}
}
else if(mkid=='120140000'){
componentInfo={
commonComponent:'taskLog',
component: "development/taskLog/index",
hidden:false,
meta:{
"title": "任务日志",
"icon": "user",
"noCache": false,
"link": null,
"mkid":120140000,
},
name:'taskLog',
path:"taskLog"
}
}
else if(mkid=='101000200'){
componentInfo={
commonComponent:'roleManagement',
component: "system/roleManagement/index",
hidden:false,
meta:{
"title": "角色管理",
"icon": "user",
"noCache": false,
"link": null,
"mkid":101000200,
},
name:'roleManagement',
path:"roleManagement"
}
}
/* 应用组件注册*/
else if(mkid=='101000900'){
componentInfo={
commonComponent:'appComponents',
component: "system/appComponents/index",
hidden:false,
meta:{
"title": "应用组件",
"icon": "user",
"noCache": false,
"link": null,
"mkid":101000900,
},
name:'appComponents',
path:"appComponents"
}
}
else if(mkid=='101000100'){
componentInfo={
commonComponent:'userManagement',
component: "system/userManagement/index",
hidden:false,
meta:{
"title": "用户管理",
"icon": "user",
"noCache": false,
"link": null,
"mkid":101000100,
},
name:'userManagement',
path:"userManagement"
}
}
else if(mkid=='101000300'){
componentInfo={
commonComponent:'departmentManagement',
component: "system/departmentManagement/index",
hidden:false,
meta:{
"title": "部门维护",
"icon": "user",
"noCache": false,
"link": null,
"mkid":101000300,
},
name:'departmentManagement',
path:"departmentManagement"
}
}
else if(mkid=='101000400'){
componentInfo={
commonComponent:'parameterSetting',
component: "system/parameterSetting/index",
hidden:false,
meta:{
"title": "参数设置",
"icon": "user",
"noCache": false,
"link": null,
"mkid":101000400,
},
name:'parameterSetting',
path:"parameterSetting"
}
}
else if(mkid=='101000800'){
componentInfo={
commonComponent:'menuManage',
component: "system/menuManage/index",
hidden:false,
meta:{
"title": "菜单管理",
"icon": "user",
"noCache": false,
"link": null,
"mkid":101000800,
},
name:'menuManage',
path:"menuManage"
}
}
else if(mkid=='101000820'){
componentInfo={
commonComponent:'appmenuManage',
component: "system/appmenuManage/index",
hidden:false,
meta:{
"title": "APP菜单管理",
"icon": "user",
"noCache": false,
"link": null,
"mkid":101000820,
},
name:'appmenuManage',
path:"appmenuManage"
}
}
else if(mkid=='101009800'){
componentInfo={
commonComponent:'cache',
component: "system/cache/index",
hidden:false,
meta:{
"title": "缓存",
"icon": "user",
"noCache": false,
"link": null,
"mkid":101009800,
},
name:'cache',
path:"cache"
}
}
/* 系统注册*/
else if(mkid=='101001200'){
componentInfo={
commonComponent:'registration',
component: "system/registration/index",
hidden:false,
meta:{
"title": "系统注册",
"icon": "user",
"noCache": false,
"link": null,
"mkid":101001200,
},
name:'registration',
path:"registration"
}
}
else if(mkid=='101001000'){
componentInfo={
commonComponent:'moduleManage',
component: "system/moduleManage/index",
hidden:false,
meta:{
"title": "模块管理",
"icon": "user",
"noCache": false,
"link": null,
"mkid":101001000,
},
name:'moduleManage',
path:"moduleManage"
}
}
/* 菜单管理*/
else if(mkid=='101000500'){
componentInfo={
commonComponent:'auxiliaryInput',
component: "system/auxiliaryInput/index",
hidden:false,
meta:{
"title": "辅助输入",
"icon": "user",
"noCache": false,
"link": null,
"mkid":101000300,
},
name:'auxiliaryInput',
path:"auxiliaryInput"
}
}
/* 打印模板*/
else if(mkid=='101000700'){
componentInfo={
commonComponent:'printTemplate',
component: "system/printTemplate/index",
hidden:false,
meta:{
"title": "打印模板",
"icon": "user",
"noCache": false,
"link": null,
"mkid":101000700,
},
name:'printTemplate',
path:"printTemplate"
}
}
else if(mkid=='101000000'){
componentInfo={
component: "Layout",
alwaysShow: true,
hidden: false,
name: "System",
path: "/system",
redirect: "noRedirect",
meta: {title: "系统管理", icon: "system", noCache: false, link: null,mkid:101000000}
}
}
/* 我的事务*/
else if(mkid=='105002100'){
componentInfo={
commonComponent:'mytodo',
component: "workflow/mytodo/index",
hidden:false,
meta:{
"title": "我的待办",
"icon": "user",
"noCache": false,
"link": null,
"mkid":105002100,
},
name:'mytodo',
path:"mytodo"
}
}
else if(mkid=='105000900'){
componentInfo={
commonComponent:'todoItems',
component: "workflow/todoItems/index",
hidden:false,
meta:{
"title": "查询待办事务",
"icon": "user",
"noCache": false,
"link": null,
"mkid":105000900,
},
name:'todoItems',
path:"todoItems"
}
}
else if(mkid=='105000100'){
componentInfo={
commonComponent:'workflowDefinition',
component: "workflow/workflowDefinition/index",
hidden:false,
meta:{
"title": "工作流定义",
"icon": "user",
"noCache": false,
"link": null,
"mkid":105000100,
},
name:'workflowDefinition',
path:"workflowDefinition"
}
}
/* 工作流程*/
else if(mkid=='105000000'){
componentInfo={
component: "Layout",
alwaysShow: true,
hidden: false,
name: "workflow",
path: "/workflow",
redirect: "noRedirect",
meta: {title: "工作流", icon: "system", noCache: false, link: null,mkid:105000000}
}
}
else if(mkid=='120100601'){
componentInfo={
commonComponent:'dataTableIndex',
component: "system/parameterSetting/dataTableIndex/index",
hidden:false,
meta:{
"title": "数据表索引",
"noCache": false,
"link": null,
"mkid":120100601,
},
name:'dataTableIndex',
path:"dataTableIndex"
}
}
else if(mkid=='120100501'){
componentInfo={
commonComponent:'triggerVersion',
component: "system/parameterSetting/triggerVersion/index",
hidden:false,
meta:{
"title": "N触发器版本",
"noCache": false,
"link": null,
"mkid":120100501,
},
name:'triggerVersion',
path:"triggerVersion"
}
}
else if(mkid=='120100401'){
componentInfo={
commonComponent:'trigger',
component: "system/parameterSetting/trigger/index",
hidden:false,
meta:{
"title": "触发器",
"noCache": false,
"link": null,
"mkid":120100401,
},
name:'trigger',
path:"trigger"
}
}
/* 120100201 数据表版本*/
else if(mkid=='120100201'){
componentInfo={
commonComponent:'dataTableVersion',
component: "system/parameterSetting/dataTableVersion/index",
hidden:false,
meta:{
"title": "数据表版本",
"noCache": false,
"link": null,
"mkid":120100201,
},
name:'dataTableVersion',
path:"dataTableVersion"
}
}
/* 120100201 数据表版本*/
else if(mkid=='120100701'){
componentInfo={
commonComponent:'dataTableIndexVersion',
component: "development/dictionary/dataTableIndexVersion/index",
hidden:false,
meta:{
"title": "N数据表索引版本",
"noCache": false,
"link": null,
"mkid":120100701,
},
name:'dataTableIndexVersion',
path:"dataTableIndexVersion"
}
}
/* 120100201 数据表*/
else if(mkid=='120100101'){
componentInfo={
commonComponent:'dataTable',
component: "system/parameterSetting/dataTable/index",
hidden:false,
meta:{
"title": "数据表",
"noCache": false,
"link": null,
"mkid":120100101,
},
name:'dataTable',
path:"dataTable"
}
}
/* 初始数据版本*/
else if(mkid=='120100301'){
componentInfo={
commonComponent:'initTableVersion',
component: "system/parameterSetting/initTableVersion/index",
hidden:false,
meta:{
"title": "初始化数据表版本",
"noCache": false,
"link": null,
"mkid":120100301,
},
name:'initTableVersion',
path:"initTableVersion"
}
}
/* 研发数据字典*/
else if(mkid=='120100000'){
componentInfo={
commonComponent:'dictionary',
component: "development/dictionary/index",
alwaysShow: true,
hidden: false,
name: "dictionary",
path: "/development/dictionary",
redirect: "noRedirect",
meta: {title: "数据字典", icon: "system", noCache: false, link: null,mkid:120100000}
}
}
/* 组件维护*/
else if(mkid=='120120101'){
componentInfo={
commonComponent:'componentMaintenance',
component: "development/functionManagement/componentMaintenance/index",
hidden:false,
meta:{
/* 下载数据表程序未完成*/
"title": "组件维护",
"noCache": false,
"link": null,
"mkid":120120101,
},
name:'componentMaintenance',
path:"componentMaintenance"
}
}
/* 模块维护*/
else if(mkid=='120120102'){
componentInfo={
commonComponent:'moduleMaintenance',
component: "development/functionManagement/moduleMaintenance/index",
hidden:false,
meta:{
/* 下载数据表程序未完成*/
"title": "模块维护",
"noCache": false,
"link": null,
"mkid":120120102,
},
name:'moduleMaintenance',
path:"moduleMaintenance"
}
}
/* 产品维护*/
else if(mkid=='120110101'){
componentInfo={
commonComponent:'productMaintenance',
component: "development/productManagement/productMaintenance/index",
hidden:false,
meta:{
/* 下载数据表程序未完成*/
"title": "N产品维护",
"noCache": false,
"link": null,
"mkid":120110101,
},
name:'productMaintenance',
path:"productMaintenance"
}
} /* 发布计划*/
else if(mkid=='120111001'){
componentInfo={
commonComponent:'releasePlan',
component: "development/productManagement/releasePlan/index",
hidden:false,
meta:{
/* 下载数据表程序未完成*/
"title": "N发布计划",
"noCache": false,
"link": null,
"mkid":120111001,
},
name:'releasePlan',
path:"releasePlan"
}
}
else if(mkid=='120111101'){
componentInfo={
commonComponent:'regCode',
component: "regCode",
hidden:false,
meta:{
/* 下载数据表程序未完成*/
"title": "(未写)注册码",
"noCache": false,
"link": null,
"mkid":120111101,
},
name:'regCode',
path:"regCode"
}
}
/* 产品管理*/
else if(mkid=='120110000'){
componentInfo={
commonComponent:'productManagement',
component: "development/productManagement/index",
alwaysShow: true,
hidden: false,
name: "productManagement",
path: "/development/productManagement",
redirect: "noRedirect",
meta: {title: "产品管理", icon: "system", noCache: false, link: null,mkid:120110000}
}
}
/* 功能管理*/
else if(mkid=='120120000'){
componentInfo={
commonComponent:'functionManagement',
component: "development/functionManagement/index",
alwaysShow: true,
hidden: false,
name: "functionManagement",
path: "/development/functionManagement",
redirect: "noRedirect",
meta: {title: "功能管理", icon: "system", noCache: false, link: null,mkid:120120000}
}
}
else if(mkid=='120000000'){
componentInfo={
component: "Layout",
alwaysShow: true,
hidden: false,
name: "Development",
path: "/development",
redirect: "noRedirect",
meta: {title: "研发工作", icon: "system", noCache: false, link: null,mkid:120000000}
}
}
return componentInfo
}
function filterChildren(childrenMap, lastRouter = false) {
var children = []
childrenMap.forEach((el, index) => {
if (el.children && el.children.length) {
if (el.component === 'ParentView' && !lastRouter) {
el.children.forEach(c => {
c.path = el.path + '/' + c.path
if (c.children && c.children.length) {
children = children.concat(filterChildren(c.children, c))
return
}
children.push(c)
})
return
}
}
if (lastRouter) {
el.path = lastRouter.path + '/' + el.path
}
children = children.concat(el)
})
return children
}
// 动态路由遍历,验证是否具备权限
export function filterDynamicRoutes(routes) {
const res = []
routes.forEach(route => {
if (route.permissions) {
if (auth.hasPermiOr(route.permissions)) {
res.push(route)
}
} else if (route.roles) {
if (auth.hasRoleOr(route.roles)) {
res.push(route)
}
}
})
return res
}
export const loadView = (view) => {
/* 改为common路由*/
if (process.env.NODE_ENV === 'development') {
return (resolve) => require([`@/views/${view}`], resolve)
} else {
// 使用 import 实现生产环境的路由懒加载
// return () => import(`@/views/${view}`)
return (resolve) => require([`@/views/${view}`], resolve)
}
}
export default permission
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment