update 优化 loadView 预建 Map 查找表,路由组件解析从 O(n) 降为 O(1)
update 优化 generateRoutes 三次 JSON 序列化改为 structuredClone fix 修复 layout watchEffect 改为 watch(width) 消除循环依赖 fix 修复 useDict 返回 reactive 对象保持响应式,增加并发请求去重 fix 修复 FileUpload/ImageUpload headers 改为 computed 避免 token 过期 update 优化 debounce 箭头函数改为 function 声明修复 this 绑定丢失 fix 修复 duplicateRouteChecker 修复 route.name 为空时的空指针崩溃 fix 修复 AppMain 动画随机选择 Math.round 改为 Math.floor 防止越界 fix 修复 TagsView 关闭页签时始终清除缓存,修复动态路由内存泄漏
This commit is contained in:
@@ -1,31 +1,39 @@
|
||||
import { getDicts } from '@/api/system/dict/data';
|
||||
import { useDictStore } from '@/store/modules/dict';
|
||||
|
||||
const pendingRequests = new Map<string, Promise<DictDataOption[]>>();
|
||||
|
||||
/**
|
||||
* 获取字典数据
|
||||
*/
|
||||
export const useDict = (...args: string[]): { [key: string]: DictDataOption[] } => {
|
||||
const res = ref<{
|
||||
[key: string]: DictDataOption[];
|
||||
}>({});
|
||||
const res = reactive<{ [key: string]: DictDataOption[] }>({});
|
||||
|
||||
args.forEach(async dictType => {
|
||||
res.value[dictType] = [];
|
||||
res[dictType] = [];
|
||||
const dicts = useDictStore().getDict(dictType);
|
||||
if (dicts) {
|
||||
res.value[dictType] = dicts;
|
||||
res[dictType] = dicts;
|
||||
} else {
|
||||
await getDicts(dictType).then(resp => {
|
||||
res.value[dictType] = resp.data.map(
|
||||
(p): DictDataOption => ({
|
||||
label: p.dictLabel,
|
||||
value: p.dictValue,
|
||||
elTagType: p.listClass,
|
||||
elTagClass: p.cssClass
|
||||
if (!pendingRequests.has(dictType)) {
|
||||
const request = getDicts(dictType)
|
||||
.then(resp => {
|
||||
const data = resp.data.map(
|
||||
(p): DictDataOption => ({
|
||||
label: p.dictLabel,
|
||||
value: p.dictValue,
|
||||
elTagType: p.listClass,
|
||||
elTagClass: p.cssClass
|
||||
})
|
||||
);
|
||||
useDictStore().setDict(dictType, data);
|
||||
return data;
|
||||
})
|
||||
);
|
||||
useDictStore().setDict(dictType, res.value[dictType]);
|
||||
});
|
||||
.finally(() => pendingRequests.delete(dictType));
|
||||
pendingRequests.set(dictType, request);
|
||||
}
|
||||
res[dictType] = await pendingRequests.get(dictType)!;
|
||||
}
|
||||
});
|
||||
return res.value;
|
||||
return res;
|
||||
};
|
||||
|
||||
@@ -204,39 +204,40 @@ export const getTime = (type: string) => {
|
||||
* @param {boolean} immediate
|
||||
* @return {*}
|
||||
*/
|
||||
export const debounce = (func: any, wait: number, immediate: boolean) => {
|
||||
let timeout: any, args: any, context: any, timestamp: any, result: any;
|
||||
export function debounce(func: (...args: any[]) => any, wait: number, immediate: boolean) {
|
||||
let timeout: ReturnType<typeof setTimeout> | null = null;
|
||||
let lastArgs: any[] | null = null;
|
||||
let lastContext: any = null;
|
||||
let timestamp = 0;
|
||||
let result: any;
|
||||
|
||||
const later = function () {
|
||||
// 据上一次触发时间间隔
|
||||
const last = +new Date() - timestamp;
|
||||
function later() {
|
||||
const last = Date.now() - timestamp;
|
||||
|
||||
// 上次被包装函数被调用时间间隔 last 小于设定时间间隔 wait
|
||||
if (last < wait && last > 0) {
|
||||
timeout = setTimeout(later, wait - last);
|
||||
} else {
|
||||
timeout = null;
|
||||
// 如果设定为immediate===true,因为开始边界已经调用过了此处无需调用
|
||||
if (!immediate) {
|
||||
result = func.apply(context, args);
|
||||
if (!timeout) context = args = null;
|
||||
result = func.apply(lastContext, lastArgs!);
|
||||
if (!timeout) lastContext = lastArgs = null;
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
return (...args: any) => {
|
||||
context = this;
|
||||
timestamp = +new Date();
|
||||
return function (this: any, ...args: any[]) {
|
||||
lastContext = this;
|
||||
lastArgs = args;
|
||||
timestamp = Date.now();
|
||||
const callNow = immediate && !timeout;
|
||||
// 如果延时不存在,重新设定延时
|
||||
if (!timeout) timeout = setTimeout(later, wait);
|
||||
if (callNow) {
|
||||
result = func.apply(context, args);
|
||||
context = args = null;
|
||||
result = func.apply(lastContext, lastArgs);
|
||||
lastContext = lastArgs = null;
|
||||
}
|
||||
return result;
|
||||
};
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* This is just a simple version of deep copy
|
||||
|
||||
Reference in New Issue
Block a user