菜单找开方式内嵌
This commit is contained in:
parent
1668d7a10b
commit
76c04ec199
@ -27,23 +27,20 @@ export const ErrorPageRoute: AppRouteRecordRaw = {
|
||||
|
||||
|
||||
export const AboutPageRoute: AppRouteRecordRaw ={
|
||||
path: '/about',
|
||||
name: 'about',
|
||||
path: '/monitorJob',
|
||||
name: 'monitorJob',
|
||||
component: Layout,
|
||||
meta: {
|
||||
sort: 12,
|
||||
isRoot: true,
|
||||
activeMenu: 'about_index',
|
||||
alwaysShow: true,
|
||||
icon: renderIcon(ProjectOutlined),
|
||||
},
|
||||
children: [
|
||||
{
|
||||
path: 'index',
|
||||
name: `about_index`,
|
||||
path: 'log',
|
||||
name: `monitorJob`,
|
||||
meta: {
|
||||
title: '关于项目',
|
||||
activeMenu: 'about_index',
|
||||
},
|
||||
component: () => import('@/views/about/index.vue'),
|
||||
},
|
||||
|
@ -20,22 +20,32 @@ LayoutMap.set('IFRAME', Iframe);
|
||||
*/
|
||||
export const routerGenerator = (routerMap, parent?): any[] => {
|
||||
return routerMap.map((item) => {
|
||||
const names = /http(s)?:/.test(item.path)?item.path:item.path.replaceAll('/','')
|
||||
item.meta = {
|
||||
title:item.name,
|
||||
title:item.parentId==0 && item.children.length==0?'':item.name,
|
||||
icon:item.icon,
|
||||
sort:item.sort,
|
||||
permissions:item.permission,
|
||||
hidden: item.hide?true:false,
|
||||
isRoot:item.parentId==0 && item.children.length==0?true:false,
|
||||
alwaysShow: item.parentId==0 && item.children.length==0?true:false,
|
||||
frameSrc: item.target==1?item.component:'',
|
||||
}
|
||||
let components = ''
|
||||
if(item.parentId==0 && item.children.length==0) {
|
||||
components ='LAYOUT'
|
||||
} else if(item.target==0) {
|
||||
components = item.component
|
||||
} else if(item.target==1) {
|
||||
components ='IFRAME'
|
||||
}
|
||||
const components =''
|
||||
const names = /http(s)?:/.test(item.path)?item.path:item.path.replaceAll('/','')
|
||||
const currentRouter: any = {
|
||||
// 路由地址 动态拼接生成如 /dashboard/workplace
|
||||
path: `${item.path}`,
|
||||
path: item.target!=2?item.path:'',
|
||||
// 路由名称,建议唯一
|
||||
name: names,
|
||||
// 该路由对应页面的 组件
|
||||
component: item.component,
|
||||
component: components,
|
||||
// meta: 页面标题, 菜单图标, 页面权限(供指令权限用,可去掉)
|
||||
meta: {
|
||||
...item.meta,
|
||||
@ -44,9 +54,8 @@ export const routerGenerator = (routerMap, parent?): any[] => {
|
||||
permissions: item.meta.permissions || null,
|
||||
},
|
||||
};
|
||||
|
||||
// 为了防止出现后端返回结果不规范,处理有可能出现拼接出两个 反斜杠
|
||||
currentRouter.path = currentRouter.path.replace('//', '/');
|
||||
// currentRouter.path = currentRouter.path.replace('//', '/');
|
||||
// 重定向
|
||||
item.redirect && (currentRouter.redirect = item.redirect);
|
||||
// 是否有子菜单,并递归处理
|
||||
@ -55,6 +64,31 @@ export const routerGenerator = (routerMap, parent?): any[] => {
|
||||
!item.redirect && (currentRouter.redirect = `${item.children[0].path}`);
|
||||
// Recursion
|
||||
currentRouter.children = routerGenerator(item.children, currentRouter);
|
||||
} else {
|
||||
if(item.parentId==0 && item.children.length==0) {
|
||||
currentRouter.children =[]
|
||||
if(item.target==1){
|
||||
currentRouter.children.push({
|
||||
path: item.path,
|
||||
name: names,
|
||||
meta: {
|
||||
title: item.name,
|
||||
frameSrc: item.component,
|
||||
},
|
||||
component: 'IFRAME',
|
||||
})
|
||||
} else {
|
||||
currentRouter.children.push({
|
||||
path: item.path,
|
||||
name: names,
|
||||
meta: {
|
||||
title: item.name,
|
||||
activeMenu: names,
|
||||
},
|
||||
component: item.component,
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
return currentRouter;
|
||||
});
|
||||
@ -69,6 +103,7 @@ export const generatorDynamicRouter = (): Promise<RouteRecordRaw[]> => {
|
||||
adminMenus()
|
||||
.then((result) => {
|
||||
const routeList = routerGenerator(result);
|
||||
console.log(routeList)
|
||||
asyncImportRoute(routeList);
|
||||
resolve(routeList);
|
||||
})
|
||||
|
@ -41,7 +41,7 @@ const setting = {
|
||||
//折叠
|
||||
collapsed: false,
|
||||
//手风琴
|
||||
uniqueOpened: false,
|
||||
uniqueOpened: true,
|
||||
},
|
||||
//面包屑
|
||||
crumbsSetting: {
|
||||
|
@ -55,14 +55,15 @@
|
||||
<IconPicker class="flex-1" v-model="formData.icon"/>
|
||||
</el-form-item>
|
||||
<el-form-item
|
||||
label="是否外链"
|
||||
label="打开方式"
|
||||
prop="target"
|
||||
v-if="formData.type==0"
|
||||
>
|
||||
<div>
|
||||
<el-radio-group v-model="formData.target">
|
||||
<el-radio :label="1">是</el-radio>
|
||||
<el-radio :label="0">否</el-radio>
|
||||
<el-radio :label="0">组件</el-radio>
|
||||
<el-radio :label="1">内链</el-radio>
|
||||
<el-radio :label="2">外链</el-radio>
|
||||
</el-radio-group>
|
||||
<div class="form-tips">
|
||||
选择外链,则新窗口打开页面
|
||||
@ -82,12 +83,12 @@
|
||||
clearable
|
||||
/>
|
||||
<div class="form-tips">
|
||||
访问的路由地址,如:`admin`,如外网地址需内链访问则以`http(s)://`开头
|
||||
访问的路由地址
|
||||
</div>
|
||||
</div>
|
||||
</el-form-item>
|
||||
<el-form-item
|
||||
v-if="formData.type == 0 && formData.target ==0 && formData.parentId!=0"
|
||||
v-if="formData.type == 0 && (formData.target ==0 || formData.target ==1)"
|
||||
label="组件路径"
|
||||
prop="component"
|
||||
:rules="{ required: true, message: '请输入组件路径', trigger: 'blur' }"
|
||||
@ -101,7 +102,7 @@
|
||||
placeholder="请输入组件路径"
|
||||
/>
|
||||
<div class="form-tips">
|
||||
访问的组件路径,如:`permission/admin/index`,默认在`views`目录下
|
||||
访问的组件路径,如:`permission/admin/index`,默认在`views`目录下,如外网地址需内链访问则以`http(s)://`开头
|
||||
</div>
|
||||
</div>
|
||||
</el-form-item>
|
||||
|
Loading…
Reference in New Issue
Block a user