diff --git a/src/hooks/modules/useComponentPaths.ts b/src/hooks/modules/useComponentPaths.ts new file mode 100644 index 00000000..ca7a4d39 --- /dev/null +++ b/src/hooks/modules/useComponentPaths.ts @@ -0,0 +1,36 @@ +import { onMounted, ref } from 'vue' +import { Message } from '@arco-design/web-vue' + +interface ComponentOption { + label: string + value: string +} + +export const useComponentPaths = () => { + const componentOptions = ref([]) + + const loadComponentPaths = async () => { + try { + const modules = import.meta.glob('@/views/**/index.vue') + const paths = Object.keys(modules) + componentOptions.value = paths.map((path) => { + // 格式转化 + path = path.replace('/src/views/', '') + const label = `@view/${path}` + const value = path.split('.vue')[0] + return { label, value } + }) + } catch (error) { + Message.error('加载组件路径失败') + console.error('加载组件路径失败:', error) + } + } + + onMounted(async () => { + await loadComponentPaths() + }) + + return { + componentOptions, + } +} diff --git a/src/views/system/menu/MenuAddModal.vue b/src/views/system/menu/MenuAddModal.vue index d24a8c51..bf19d580 100644 --- a/src/views/system/menu/MenuAddModal.vue +++ b/src/views/system/menu/MenuAddModal.vue @@ -51,10 +51,11 @@ - - - - + + + @@ -121,6 +122,7 @@ import { mapTree } from 'xe-utils' import { type MenuResp, addMenu, getMenu, updateMenu } from '@/apis/system/menu' import { useResetReactive } from '@/hooks' import { filterTree, transformPathToName } from '@/utils' +import { useComponentPaths } from '@/hooks/modules/useComponentPaths' interface Props { menus: MenuResp[] @@ -152,6 +154,8 @@ const [form, resetForm] = useResetReactive({ const componentName = computed(() => transformPathToName(form.path)) +const { componentOptions } = useComponentPaths() + const rules: FormInstance['rules'] = { parentId: [{ required: true, message: '请选择上级菜单' }], title: [{ required: true, message: '请输入菜单标题' }],