Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
B
basic-vue-admin
概览
概览
详情
活动
周期分析
版本库
存储库
文件
提交
分支
标签
贡献者
分支图
比较
统计图
问题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程表
图表
维基
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
Basic
basic-vue-admin
Commits
9b61e82d
提交
9b61e82d
authored
11月 09, 2020
作者:
vben
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
refactor: route Module structural transformation
上级
dc42d434
隐藏空白字符变更
内嵌
并排
正在显示
9 个修改的文件
包含
57 行增加
和
60 行删除
+57
-60
.env
.env
+2
-3
CHANGELOG.zh_CN.md
CHANGELOG.zh_CN.md
+1
-0
index.ts
build/vite/plugin/dynamicImport/index.ts
+3
-2
menu.ts
mock/sys/menu.ts
+24
-32
types.d.ts
src/router/types.d.ts
+3
-1
projectSetting.ts
src/settings/projectSetting.ts
+3
-3
env.ts
src/utils/env.ts
+0
-12
menuHelper.ts
src/utils/helper/menuHelper.ts
+3
-3
routeHelper.ts
src/utils/helper/routeHelper.ts
+18
-4
没有找到文件。
.env
浏览文件 @
9b61e82d
...
@@ -7,6 +7,5 @@ VITE_GLOB_APP_TITLE = Vben Admin
...
@@ -7,6 +7,5 @@ VITE_GLOB_APP_TITLE = Vben Admin
# spa shortname
# spa shortname
VITE_GLOB_APP_SHORT_NAME = vue_vben_admin_2x
VITE_GLOB_APP_SHORT_NAME = vue_vben_admin_2x
# Menu generation mode BACK|ROLE
# Whether to dynamically load all files in `src/views`
# Need to delete LocalStorage after modification
VITE_DYNAMIC_IMPORT = true
VITE_GEN_MENU_MODE=ROLE
CHANGELOG.zh_CN.md
浏览文件 @
9b61e82d
...
@@ -11,6 +11,7 @@
...
@@ -11,6 +11,7 @@
### ✨ Refactor
### ✨ Refactor
-
重构由后台生成菜单的逻辑
-
重构由后台生成菜单的逻辑
-
Route Module 结构改造
### ⚡ Performance Improvements
### ⚡ Performance Improvements
...
...
build/vite/plugin/dynamicImport/index.ts
浏览文件 @
9b61e82d
...
@@ -20,10 +20,11 @@ const dynamicImportTransform = function (env: any = {}): Transform {
...
@@ -20,10 +20,11 @@ const dynamicImportTransform = function (env: any = {}): Transform {
return
path
.
includes
(
'/src/utils/helper/dynamicImport.ts'
);
return
path
.
includes
(
'/src/utils/helper/dynamicImport.ts'
);
},
},
transform
({
code
})
{
transform
({
code
})
{
const
{
VITE_
GEN_MENU_MODE
=
''
}
=
env
;
const
{
VITE_
DYNAMIC_IMPORT
}
=
env
;
if
(
VITE_GEN_MENU_MODE
!==
'BACK'
)
{
if
(
!
VITE_DYNAMIC_IMPORT
)
{
return
code
;
return
code
;
}
}
// if (!isBuild) return code;
// if (!isBuild) return code;
// Only convert the dir
// Only convert the dir
try
{
try
{
...
...
mock/sys/menu.ts
浏览文件 @
9b61e82d
...
@@ -2,17 +2,15 @@ import { resultSuccess } from '../_util';
...
@@ -2,17 +2,15 @@ import { resultSuccess } from '../_util';
import
{
MockMethod
}
from
'vite-plugin-mock'
;
import
{
MockMethod
}
from
'vite-plugin-mock'
;
const
dashboardRoute
=
{
const
dashboardRoute
=
{
layout
:
{
path
:
'/dashboard'
,
path
:
'/dashboard'
,
name
:
'Dashboard'
,
name
:
'Dashboard'
,
component
:
'PAGE_LAYOUT'
,
component
:
'PAGE_LAYOUT'
,
redirect
:
'/dashboard/welcome'
,
redirect
:
'/dashboard/welcome'
,
meta
:
{
meta
:
{
icon
:
'ant-design:home-outlined'
,
icon
:
'ant-design:home-outlined'
,
title
:
'Dashboard'
,
title
:
'Dashboard'
,
},
},
},
routes
:
[
children
:
[
{
{
path
:
'/welcome'
,
path
:
'/welcome'
,
name
:
'Welcome'
,
name
:
'Welcome'
,
...
@@ -86,33 +84,27 @@ const backRoute = {
...
@@ -86,33 +84,27 @@ const backRoute = {
],
],
};
};
const
authRoute
=
{
const
authRoute
=
{
layout
:
{
path
:
'/permission'
,
path
:
'/permission'
,
name
:
'Permission'
,
name
:
'Permission'
,
component
:
'PAGE_LAYOUT'
,
component
:
'PAGE_LAYOUT'
,
redirect
:
'/permission/front/page'
,
redirect
:
'/permission/front/page'
,
meta
:
{
meta
:
{
icon
:
'ant-design:home-outlined'
,
icon
:
'ant-design:home-outlined'
,
title
:
'权限管理'
,
title
:
'权限管理'
,
},
},
},
children
:
[
frontRoute
,
backRoute
],
routes
:
[
frontRoute
,
backRoute
],
};
};
const
authRoute1
=
{
const
authRoute1
=
{
layout
:
{
path
:
'/permission'
,
path
:
'/permission'
,
name
:
'Permission'
,
name
:
'Permission'
,
component
:
'PAGE_LAYOUT'
,
component
:
'PAGE_LAYOUT'
,
redirect
:
'/permission/front/page'
,
redirect
:
'/permission/front/page'
,
meta
:
{
meta
:
{
icon
:
'ant-design:home-outlined'
,
icon
:
'ant-design:home-outlined'
,
title
:
'权限管理'
,
title
:
'权限管理'
,
},
},
},
children
:
[
backRoute
],
routes
:
[
backRoute
],
};
};
export
default
[
export
default
[
{
{
...
...
src/router/types.d.ts
浏览文件 @
9b61e82d
...
@@ -68,5 +68,7 @@ export interface MenuModule {
...
@@ -68,5 +68,7 @@ export interface MenuModule {
export
interface
AppRouteModule
{
export
interface
AppRouteModule
{
layout
?:
AppRouteRecordRaw
;
layout
?:
AppRouteRecordRaw
;
routes
:
AppRouteRecordRaw
[];
routes
?:
AppRouteRecordRaw
[];
children
?:
AppRouteRecordRaw
[];
component
?:
any
;
}
}
src/settings/projectSetting.ts
浏览文件 @
9b61e82d
import
type
{
ProjectConfig
}
from
'/@/types/config'
;
import
type
{
ProjectConfig
}
from
'/@/types/config'
;
import
{
MenuTypeEnum
,
MenuThemeEnum
,
MenuModeEnum
,
TriggerEnum
}
from
'/@/enums/menuEnum'
;
import
{
MenuTypeEnum
,
MenuThemeEnum
,
MenuModeEnum
,
TriggerEnum
}
from
'/@/enums/menuEnum'
;
import
{
ContentEnum
,
RouterTransitionEnum
}
from
'/@/enums/appEnum'
;
import
{
ContentEnum
,
PermissionModeEnum
,
RouterTransitionEnum
}
from
'/@/enums/appEnum'
;
import
{
primaryColor
}
from
'../../build/config/lessModifyVars'
;
import
{
primaryColor
}
from
'../../build/config/lessModifyVars'
;
import
{
isProdMode
,
getRoleMode
}
from
'/@/utils/env'
;
import
{
isProdMode
}
from
'/@/utils/env'
;
// ! You need to clear the browser cache after the change
// ! You need to clear the browser cache after the change
const
setting
:
ProjectConfig
=
{
const
setting
:
ProjectConfig
=
{
// Whether to show the configuration button
// Whether to show the configuration button
showSettingButton
:
true
,
showSettingButton
:
true
,
// 权限模式
// 权限模式
permissionMode
:
getRoleMode
()
,
permissionMode
:
PermissionModeEnum
.
ROLE
,
// 网站灰色模式,用于可能悼念的日期开启
// 网站灰色模式,用于可能悼念的日期开启
grayMode
:
false
,
grayMode
:
false
,
// 色弱模式
// 色弱模式
...
...
src/utils/env.ts
浏览文件 @
9b61e82d
import
{
PermissionModeEnum
}
from
'../enums/appEnum'
;
import
type
{
GlobEnvConfig
}
from
'/@/types/config'
;
import
type
{
GlobEnvConfig
}
from
'/@/types/config'
;
export
const
getGlobEnvConfig
=
():
GlobEnvConfig
=>
{
export
const
getGlobEnvConfig
=
():
GlobEnvConfig
=>
{
...
@@ -47,14 +46,3 @@ export const isProdMode = (): boolean => import.meta.env.PROD;
...
@@ -47,14 +46,3 @@ export const isProdMode = (): boolean => import.meta.env.PROD;
* @example:
* @example:
*/
*/
export
const
isUseMock
=
():
boolean
=>
import
.
meta
.
env
.
VITE_USE_MOCK
===
'true'
;
export
const
isUseMock
=
():
boolean
=>
import
.
meta
.
env
.
VITE_USE_MOCK
===
'true'
;
/**
* @description: 获取菜单生成方式
* @param {type}
* @returns:
* @example:
*/
export
const
getRoleMode
=
():
PermissionModeEnum
=>
import
.
meta
.
env
.
VITE_GEN_MENU_MODE
===
PermissionModeEnum
.
ROLE
?
PermissionModeEnum
.
ROLE
:
PermissionModeEnum
.
BACK
;
src/utils/helper/menuHelper.ts
浏览文件 @
9b61e82d
...
@@ -48,12 +48,12 @@ export function transformRouteToMenu(routeModList: AppRouteModule[]) {
...
@@ -48,12 +48,12 @@ export function transformRouteToMenu(routeModList: AppRouteModule[]) {
const
cloneRouteModList
=
cloneDeep
(
routeModList
);
const
cloneRouteModList
=
cloneDeep
(
routeModList
);
const
routeList
:
AppRouteRecordRaw
[]
=
[];
const
routeList
:
AppRouteRecordRaw
[]
=
[];
cloneRouteModList
.
forEach
((
item
)
=>
{
cloneRouteModList
.
forEach
((
item
)
=>
{
const
{
layout
,
routes
}
=
item
;
const
{
layout
,
routes
,
children
}
=
item
;
if
(
layout
)
{
if
(
layout
)
{
layout
.
children
=
routes
;
layout
.
children
=
routes
||
children
;
routeList
.
push
(
layout
);
routeList
.
push
(
layout
);
}
else
{
}
else
{
routeList
.
push
(...
routes
);
route
s
&&
route
List
.
push
(...
routes
);
}
}
});
});
return
treeMap
(
routeList
,
{
return
treeMap
(
routeList
,
{
...
...
src/utils/helper/routeHelper.ts
浏览文件 @
9b61e82d
...
@@ -8,6 +8,7 @@ import { toRaw } from 'vue';
...
@@ -8,6 +8,7 @@ import { toRaw } from 'vue';
import
{
PAGE_LAYOUT_COMPONENT
}
from
'/@/router/constant'
;
import
{
PAGE_LAYOUT_COMPONENT
}
from
'/@/router/constant'
;
// import { isDevMode } from '/@/utils/env';
// import { isDevMode } from '/@/utils/env';
import
dynamicImport
from
'./dynamicImport'
;
import
dynamicImport
from
'./dynamicImport'
;
import
{
omit
}
from
'lodash-es'
;
let
currentTo
:
RouteLocationNormalized
|
null
=
null
;
let
currentTo
:
RouteLocationNormalized
|
null
=
null
;
...
@@ -23,8 +24,16 @@ export function setCurrentTo(to: RouteLocationNormalized) {
...
@@ -23,8 +24,16 @@ export function setCurrentTo(to: RouteLocationNormalized) {
export
function
genRouteModule
(
moduleList
:
AppRouteModule
[])
{
export
function
genRouteModule
(
moduleList
:
AppRouteModule
[])
{
const
ret
:
AppRouteRecordRaw
[]
=
[];
const
ret
:
AppRouteRecordRaw
[]
=
[];
for
(
const
routeMod
of
moduleList
)
{
for
(
const
routeMod
of
moduleList
)
{
const
routes
=
routeMod
.
routes
as
any
;
let
routes
=
[];
const
layout
=
routeMod
.
layout
;
let
layout
:
AppRouteRecordRaw
|
undefined
;
if
(
Reflect
.
has
(
routeMod
,
'routes'
))
{
routes
=
routeMod
.
routes
as
any
;
layout
=
routeMod
.
layout
;
}
else
if
(
Reflect
.
has
(
routeMod
,
'path'
))
{
layout
=
omit
(
routeMod
,
'children'
)
as
any
;
routes
=
routeMod
.
children
||
[];
}
const
router
=
createRouter
({
routes
,
history
:
createWebHashHistory
()
});
const
router
=
createRouter
({
routes
,
history
:
createWebHashHistory
()
});
const
flatList
=
(
toRaw
(
router
.
getRoutes
()).
filter
(
const
flatList
=
(
toRaw
(
router
.
getRoutes
()).
filter
(
...
@@ -45,7 +54,8 @@ export function genRouteModule(moduleList: AppRouteModule[]) {
...
@@ -45,7 +54,8 @@ export function genRouteModule(moduleList: AppRouteModule[]) {
// 动态引入
// 动态引入
// TODO 错误写法
// TODO 错误写法
function
asyncImportRoute
(
routes
:
AppRouteRecordRaw
[])
{
function
asyncImportRoute
(
routes
:
AppRouteRecordRaw
[]
|
undefined
)
{
if
(
!
routes
)
return
;
routes
.
forEach
((
item
)
=>
{
routes
.
forEach
((
item
)
=>
{
const
{
component
}
=
item
;
const
{
component
}
=
item
;
const
{
children
}
=
item
;
const
{
children
}
=
item
;
...
@@ -60,10 +70,14 @@ function asyncImportRoute(routes: AppRouteRecordRaw[]) {
...
@@ -60,10 +70,14 @@ function asyncImportRoute(routes: AppRouteRecordRaw[]) {
// 将后台对象转成路由对象
// 将后台对象转成路由对象
export
function
transformObjToRoute
(
routeList
:
AppRouteModule
[])
{
export
function
transformObjToRoute
(
routeList
:
AppRouteModule
[])
{
routeList
.
forEach
((
route
)
=>
{
routeList
.
forEach
((
route
)
=>
{
asyncImportRoute
(
route
.
routes
);
asyncImportRoute
(
Reflect
.
has
(
route
,
'routes'
)
?
route
.
routes
:
route
.
children
||
[]
);
if
(
route
.
layout
)
{
if
(
route
.
layout
)
{
route
.
layout
.
component
=
route
.
layout
.
component
=
route
.
layout
.
component
===
'PAGE_LAYOUT'
?
PAGE_LAYOUT_COMPONENT
:
''
;
route
.
layout
.
component
===
'PAGE_LAYOUT'
?
PAGE_LAYOUT_COMPONENT
:
''
;
}
else
{
route
.
component
=
route
.
component
===
'PAGE_LAYOUT'
?
PAGE_LAYOUT_COMPONENT
:
''
;
const
_layout
=
omit
(
route
,
'children'
)
as
any
;
route
.
layout
=
_layout
;
}
}
});
});
return
routeList
;
return
routeList
;
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论