更改路径方式
This commit is contained in:
@@ -1,15 +1,47 @@
|
|||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import Index from '@/views/index/tenantIndex.vue';
|
import Index from '@/views/index/tenantIndex.vue';
|
||||||
import { getConfigKey } from '@/api/system/config';
|
import { getConfigKey } from '@/api/system/config';
|
||||||
import { defineAsyncComponent, onMounted, shallowRef } from 'vue';
|
import {
|
||||||
|
defineAsyncComponent,
|
||||||
|
onMounted,
|
||||||
|
shallowRef,
|
||||||
|
type Component,
|
||||||
|
} from 'vue';
|
||||||
import { RESULT_CODE_SUCCESS } from '@/constants/result-constants';
|
import { RESULT_CODE_SUCCESS } from '@/constants/result-constants';
|
||||||
import useUserStore from '@/store/modules/user';
|
import useUserStore from '@/store/modules/user';
|
||||||
import useLayoutStore from '@/store/modules/layout';
|
import useLayoutStore from '@/store/modules/layout';
|
||||||
|
|
||||||
const currentComponent = shallowRef(
|
const currentComponent = shallowRef<Component | null>(
|
||||||
defineAsyncComponent(() => import('@/views/configManage/neOverview/index.vue'))
|
defineAsyncComponent(
|
||||||
|
() => import('@/views/configManage/neOverview/index.vue')
|
||||||
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
/**匹配views里面所有的.vue或.tsx文件 */
|
||||||
|
const views = import.meta.glob('../views/**/*.{vue,tsx}') as Record<
|
||||||
|
string,
|
||||||
|
() => Promise<Component>
|
||||||
|
>;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 查找页面模块
|
||||||
|
* @param dirName 组件路径
|
||||||
|
* @returns 路由懒加载函数
|
||||||
|
*/
|
||||||
|
function findView(dirName: string): () => Promise<Component> {
|
||||||
|
for (const dir in views) {
|
||||||
|
let viewDirName = '';
|
||||||
|
const component = dir.match(/\/(.+)\.(vue|tsx)/);
|
||||||
|
if (component && component.length === 3) {
|
||||||
|
viewDirName = component[1];
|
||||||
|
}
|
||||||
|
if (viewDirName === dirName) {
|
||||||
|
return views[dir];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return () => import('@/views/error/404.vue');
|
||||||
|
}
|
||||||
|
|
||||||
onMounted(() => {
|
onMounted(() => {
|
||||||
if (useUserStore().roles.includes('tenant')) {
|
if (useUserStore().roles.includes('tenant')) {
|
||||||
//租户
|
//租户
|
||||||
@@ -22,11 +54,9 @@ onMounted(() => {
|
|||||||
//获取当前系统设置的首页路径
|
//获取当前系统设置的首页路径
|
||||||
getConfigKey('sys.homePage').then(res => {
|
getConfigKey('sys.homePage').then(res => {
|
||||||
if (res.code === RESULT_CODE_SUCCESS && res.data) {
|
if (res.code === RESULT_CODE_SUCCESS && res.data) {
|
||||||
console.log(res.data);
|
|
||||||
if (res.data) {
|
if (res.data) {
|
||||||
currentComponent.value = defineAsyncComponent(
|
const asyncComponent = findView(`${res.data}`);
|
||||||
() => import(`./${res.data}.vue`)
|
currentComponent.value = defineAsyncComponent(asyncComponent);
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user