feat: 添加防抖指令和任务管理功能
feat(anchor): 新增主播管理模块 feat(account): 完善客服账号管理功能 feat(knowledge): 添加任务列表查看和重新执行功能 feat(router): 增强路由组件动态导入逻辑 refactor: 优化多个视图的按钮防抖处理 style: 统一代码格式和样式 fix: 修复客服账号状态切换逻辑
This commit is contained in:
@@ -141,17 +141,51 @@ export function setBackEndControlRefreshRoutes() {
|
||||
export function backEndComponent(routes: any) {
|
||||
if (!routes) return [];
|
||||
return routes.map((item: any) => {
|
||||
// 递归处理子路由
|
||||
if (item.children && item.children.length > 0) {
|
||||
item.children.some((ci: any) => {
|
||||
if (!ci.meta.isHide) {
|
||||
item.redirect = ci;
|
||||
return true;
|
||||
item.children = backEndComponent(item.children);
|
||||
// 找到第一个非隐藏的子路由作为重定向
|
||||
const firstVisibleChild = item.children.find((ci: any) => !ci.meta?.isHide);
|
||||
if (firstVisibleChild) {
|
||||
item.redirect = firstVisibleChild.path;
|
||||
}
|
||||
// 确保父级路由有component
|
||||
if (!item.component || item.component === false) {
|
||||
item.component = dynamicViewsModules['../layout/routerView/parent.vue'];
|
||||
}
|
||||
} else {
|
||||
// 确保叶子路由有component
|
||||
let componentFound = false;
|
||||
if (item.component && item.component !== false) {
|
||||
const comp = dynamicImport(dynamicViewsModules, item.component as string);
|
||||
if (comp) {
|
||||
item.component = comp;
|
||||
componentFound = true;
|
||||
}
|
||||
return false;
|
||||
});
|
||||
}
|
||||
if (!componentFound) {
|
||||
// 尝试根据path生成component路径
|
||||
const path = item.path.replace(/^\//, '');
|
||||
let comp = dynamicImport(dynamicViewsModules, path);
|
||||
if (!comp) {
|
||||
comp = dynamicImport(dynamicViewsModules, path + '/index');
|
||||
}
|
||||
if (!comp) {
|
||||
// 尝试直接拼接views路径
|
||||
const viewsPath = 'views/' + path + '/index.vue';
|
||||
const directKey = Object.keys(dynamicViewsModules).find((key) => key.includes(viewsPath));
|
||||
if (directKey) {
|
||||
comp = dynamicViewsModules[directKey];
|
||||
}
|
||||
}
|
||||
if (comp) {
|
||||
item.component = comp;
|
||||
} else {
|
||||
// 如果还是找不到,使用一个默认组件
|
||||
item.component = dynamicViewsModules['../layout/routerView/parent.vue'];
|
||||
}
|
||||
}
|
||||
}
|
||||
if (item.component) item.component = dynamicImport(dynamicViewsModules, item.component as string);
|
||||
item.children && backEndComponent(item.children);
|
||||
return item;
|
||||
});
|
||||
}
|
||||
@@ -164,10 +198,35 @@ export function backEndComponent(routes: any) {
|
||||
*/
|
||||
export function dynamicImport(dynamicViewsModules: Record<string, Function>, component: string) {
|
||||
const keys = Object.keys(dynamicViewsModules);
|
||||
const matchKeys = keys.filter((key) => {
|
||||
|
||||
// 尝试多种匹配方式
|
||||
let matchKeys = keys.filter((key) => {
|
||||
const k = key.replace(/..\/views|../, '');
|
||||
return k.startsWith(`${component}`) || k.startsWith(`/${component}`);
|
||||
});
|
||||
|
||||
// 如果没有匹配到,尝试带index的路径
|
||||
if (matchKeys?.length === 0) {
|
||||
matchKeys = keys.filter((key) => {
|
||||
const k = key.replace(/..\/views|../, '');
|
||||
return k.startsWith(`${component}/index`) || k.startsWith(`/${component}/index`);
|
||||
});
|
||||
}
|
||||
|
||||
// 尝试直接匹配完整路径
|
||||
if (matchKeys?.length === 0) {
|
||||
matchKeys = keys.filter((key) => {
|
||||
return key.includes(component);
|
||||
});
|
||||
}
|
||||
|
||||
// 尝试更宽松的匹配方式
|
||||
if (matchKeys?.length === 0) {
|
||||
matchKeys = keys.filter((key) => {
|
||||
return key.replace(/..\/views\//, '').includes(component.replace(/\//g, ''));
|
||||
});
|
||||
}
|
||||
|
||||
if (matchKeys?.length === 1) {
|
||||
const matchKey = matchKeys[0];
|
||||
return dynamicViewsModules[matchKey];
|
||||
@@ -175,4 +234,6 @@ export function dynamicImport(dynamicViewsModules: Record<string, Function>, com
|
||||
if (matchKeys?.length > 1) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user