fix: route

pull/6/MERGE
xingyu 2023-05-04 15:58:27 +08:00
parent cf1d3d30e6
commit df32ffda54
4 changed files with 28 additions and 19 deletions

View File

@ -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[]) || []
}

View File

@ -100,6 +100,7 @@ export function transformObjToRoute<T = AppRouteModule>(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<T = AppRouteModule>(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<T = AppRouteModule>(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

View File

@ -10,6 +10,7 @@ export interface AppRouteRecordRaw extends Omit<RouteRecordRaw, 'meta'> {
visible?: boolean
icon?: string
name: string
sort: number
parentId?: number
meta: RouteMeta
component?: Component | string

View File

@ -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