From df32ffda541b2b01514ad1fdbf1998f40d366a16 Mon Sep 17 00:00:00 2001 From: xingyu Date: Thu, 4 May 2023 15:58:27 +0800 Subject: [PATCH] fix: route --- .../Form/src/components/ApiTreeSelect.vue | 8 ++++-- src/router/helper/routeHelper.ts | 10 +++++++ src/router/types.ts | 1 + src/views/system/menu/menu.data.ts | 28 ++++++++----------- 4 files changed, 28 insertions(+), 19 deletions(-) diff --git a/src/components/Form/src/components/ApiTreeSelect.vue b/src/components/Form/src/components/ApiTreeSelect.vue index d0293725..7cbe5a1e 100644 --- a/src/components/Form/src/components/ApiTreeSelect.vue +++ b/src/components/Form/src/components/ApiTreeSelect.vue @@ -23,7 +23,8 @@ const props = defineProps({ immediate: { type: Boolean, default: true }, resultField: propTypes.string.def(''), handleTree: { type: String, default: '' }, - parent: { type: String, default: '' } + parent: { type: String, default: '' }, + parentId: { type: Number, default: 0 } }) const emit = defineEmits(['options-change', 'change']) const attrs = useAttrs() @@ -81,8 +82,9 @@ async function fetch() { result = handleTree(result, props.handleTree) } if (props.parent) { - treeData.value = [{ id: 0, name: props.parent, children: [] }] - treeData.value[0].children = (result as Recordable[]) || [] + let tree: any = { id: props.parentId, name: props.parent, children: [] } + tree.children = (result as Recordable[]) || [] + treeData.value.push(tree) } else { treeData.value = (result as Recordable[]) || [] } diff --git a/src/router/helper/routeHelper.ts b/src/router/helper/routeHelper.ts index 83f7af0d..82b0deca 100644 --- a/src/router/helper/routeHelper.ts +++ b/src/router/helper/routeHelper.ts @@ -100,6 +100,7 @@ export function transformObjToRoute(routeList: AppRouteModul path: path, name: route.name, component: 'IFRAME', + sort: route.sort, meta: { title: route.name, icon: route.icon @@ -113,12 +114,18 @@ export function transformObjToRoute(routeList: AppRouteModul if (component.toUpperCase() === 'LAYOUT') { route.component = LayoutMap.get('LAYOUT'.toUpperCase()) const meta = route.meta || {} + meta.hideMenu = !route.visible + meta.orderNo = route.sort + meta.ignoreKeepAlive = !route.keepAlive meta.title = route.name meta.icon = route.icon route.meta = meta } else if (component.toUpperCase() === 'IFRAME') { route.component = LayoutMap.get('IFRAME'.toUpperCase()) const meta = route.meta || {} + meta.hideMenu = !route.visible + meta.orderNo = route.sort + meta.ignoreKeepAlive = !route.keepAlive meta.title = route.name meta.icon = route.icon meta.frameSrc = route.path @@ -127,6 +134,9 @@ export function transformObjToRoute(routeList: AppRouteModul } else { //处理顶级非目录路由 const meta = route.meta || {} + meta.hideMenu = !route.visible + meta.orderNo = route.sort + meta.ignoreKeepAlive = !route.keepAlive meta.title = route.name meta.icon = route.icon meta.single = true diff --git a/src/router/types.ts b/src/router/types.ts index d8eadf23..d73841eb 100644 --- a/src/router/types.ts +++ b/src/router/types.ts @@ -10,6 +10,7 @@ export interface AppRouteRecordRaw extends Omit { visible?: boolean icon?: string name: string + sort: number parentId?: number meta: RouteMeta component?: Component | string diff --git a/src/views/system/menu/menu.data.ts b/src/views/system/menu/menu.data.ts index 457e1112..a6c16732 100644 --- a/src/views/system/menu/menu.data.ts +++ b/src/views/system/menu/menu.data.ts @@ -80,6 +80,7 @@ export const formSchema: FormSchema[] = [ label: '上级菜单', field: 'parentId', required: true, + defaultValue: 0, component: 'ApiTreeSelect', componentProps: { api: () => listSimpleMenus(), @@ -119,7 +120,8 @@ export const formSchema: FormSchema[] = [ label: '显示排序', field: 'sort', required: true, - component: 'Input' + component: 'InputNumber', + defaultValue: 0 }, { label: '路由地址', @@ -164,12 +166,10 @@ export const formSchema: FormSchema[] = [ { label: '显示状态', field: 'visible', - component: 'RadioButtonGroup', + component: 'Switch', componentProps: { - options: [ - { label: '显示', key: true, value: true }, - { label: '隐藏', key: false, value: false } - ] + checkedChildren: '显示', + unCheckedChildren: '隐藏' }, helpMessage: '选择隐藏时,路由将不会出现在侧边栏,但仍然可以访问', ifShow: ({ values }) => values.type !== SystemMenuTypeEnum.BUTTON @@ -177,12 +177,10 @@ export const formSchema: FormSchema[] = [ { label: '总是显示', field: 'alwaysShow', - component: 'RadioButtonGroup', + component: 'Switch', componentProps: { - options: [ - { label: '显示', key: true, value: true }, - { label: '隐藏', key: false, value: false } - ] + checkedChildren: '显示', + unCheckedChildren: '隐藏' }, helpMessage: '选择不是时,当该菜单只有一个子菜单时,不展示自己,直接展示子菜单', ifShow: ({ values }) => values.type !== SystemMenuTypeEnum.BUTTON @@ -190,12 +188,10 @@ export const formSchema: FormSchema[] = [ { label: '是否缓存', field: 'keepAlive', - component: 'RadioButtonGroup', + component: 'Switch', componentProps: { - options: [ - { label: '缓存', key: true, value: true }, - { label: '不缓存', key: false, value: false } - ] + checkedChildren: '缓存', + unCheckedChildren: '不缓存' }, helpMessage: '选择缓存时,则会被 `keep-alive` 缓存,必须填写「组件名称」字段', ifShow: ({ values }) => values.type === SystemMenuTypeEnum.MENU