refactor: ♻️ 系统配置刷新防抖和支持patch请求
系统配置刷新防抖和支持patch请求
This commit is contained in:
@@ -62,7 +62,7 @@ const ConfigAPI = {
|
|||||||
refreshCache() {
|
refreshCache() {
|
||||||
return request({
|
return request({
|
||||||
url: `${CONFIG_BASE_URL}/refresh`,
|
url: `${CONFIG_BASE_URL}/refresh`,
|
||||||
method: "PUT",
|
method: "PATCH",
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -39,3 +39,32 @@ export function isExternal(path: string) {
|
|||||||
const isExternal = /^(https?:|http?:|mailto:|tel:)/.test(path);
|
const isExternal = /^(https?:|http?:|mailto:|tel:)/.test(path);
|
||||||
return isExternal;
|
return isExternal;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 防抖函数
|
||||||
|
*
|
||||||
|
* @param {Function} fn 需要防抖的函数
|
||||||
|
* @param {number} delay 防抖时间
|
||||||
|
* @returns {Function}
|
||||||
|
*/
|
||||||
|
export const debounce = <T extends (...args: any[]) => any>(
|
||||||
|
fn: T,
|
||||||
|
delay: number,
|
||||||
|
immediate = false
|
||||||
|
) => {
|
||||||
|
let timer: NodeJS.Timeout | null = null;
|
||||||
|
return function (this: any, ...args: Parameters<T>) {
|
||||||
|
if (timer) clearTimeout(timer);
|
||||||
|
|
||||||
|
if (immediate && !timer) {
|
||||||
|
fn.apply(this, args);
|
||||||
|
}
|
||||||
|
|
||||||
|
timer = setTimeout(() => {
|
||||||
|
if (!immediate) {
|
||||||
|
fn.apply(this, args);
|
||||||
|
}
|
||||||
|
timer = null;
|
||||||
|
}, delay);
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|||||||
@@ -136,6 +136,7 @@ defineOptions({
|
|||||||
});
|
});
|
||||||
|
|
||||||
import ConfigAPI, { ConfigPageVO, ConfigForm, ConfigPageQuery } from "@/api/system/config";
|
import ConfigAPI, { ConfigPageVO, ConfigForm, ConfigPageQuery } from "@/api/system/config";
|
||||||
|
import { debounce } from "@/utils";
|
||||||
|
|
||||||
const queryFormRef = ref(ElForm);
|
const queryFormRef = ref(ElForm);
|
||||||
const dataFormRef = ref(ElForm);
|
const dataFormRef = ref(ElForm);
|
||||||
@@ -211,11 +212,16 @@ function handleOpenDialog(id?: number) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 刷新缓存
|
// 防抖刷新缓存
|
||||||
function handleRefreshCache() {
|
const debouncedRefresh = debounce(() => {
|
||||||
ConfigAPI.refreshCache().then(() => {
|
ConfigAPI.refreshCache().then(() => {
|
||||||
ElMessage.success("刷新成功");
|
ElMessage.success("刷新成功");
|
||||||
});
|
});
|
||||||
|
}, 1000);
|
||||||
|
|
||||||
|
// 刷新缓存
|
||||||
|
function handleRefreshCache() {
|
||||||
|
debouncedRefresh();
|
||||||
}
|
}
|
||||||
|
|
||||||
// 系统配置表单提交
|
// 系统配置表单提交
|
||||||
|
|||||||
Reference in New Issue
Block a user