flat: 优化

This commit is contained in:
Apcallover
2025-11-30 16:47:06 +08:00
parent 8cf55d3925
commit 9a38bbd298
15 changed files with 167 additions and 122 deletions

View File

@@ -26,6 +26,10 @@ const needToEncrypt = [
*/
export async function createRequestWithCache(url, data = {}, method = 'GET', loading = false, headers = {},
onCacheLoad = null) {
// 是分页接口的话, 只缓存第一页的数据
if (data.current && data.current > 1) {
return createRequest(url, data, method, loading, headers);
}
const cacheKey = `${method.toUpperCase()}:${url}:${JSON.stringify(data)}`;
baseDB.getDB().then(async (dbHelper) => {
@@ -77,13 +81,16 @@ export function createRequest(url, data = {}, method = 'GET', loading = false, h
mask: true
})
}
let Authorization = ''
if (useUserStore().token) {
Authorization = `${useUserStore().token}`
}
let header = {
...headers
};
const userStore = useUserStore();
const token = userStore.token;
const header = headers || {};
header["Authorization"] = encodeURIComponent(Authorization);
if (token) {
// 确保 Authorization 不会被覆盖,且进行编码
header["Authorization"] = encodeURIComponent(token);
}
// ------------------------------------------------------------------
// 检查当前请求是否需要加密