feat(menu): 路由菜单组件路径新增下拉选择

This commit is contained in:
KAI
2024-12-13 07:06:22 +00:00
committed by Charles7c
parent f157130b23
commit 438c2af4a6
2 changed files with 44 additions and 4 deletions

View File

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