-
Notifications
You must be signed in to change notification settings - Fork 71
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
44 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters