wujingjing
2024-11-05 fa315dbe5e37b6c8cf9f68df71f79978ad027c7d
缓存带过期时间
已修改2个文件
36 ■■■■■ 文件已修改
src/components/chat/chatComponents/summaryCom/components/recordSetTable/RecordSetTable.vue 6 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/utils/storage.ts 30 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/components/chat/chatComponents/summaryCom/components/recordSetTable/RecordSetTable.vue
@@ -113,7 +113,7 @@
import { PATH_ICON } from '../../../common';
import { ChartTypeEnum } from '../../../types';
import { axisLabelFormatter } from '/@/utils/chart';
import { Local } from '/@/utils/storage';
import { LocalPlus } from '/@/utils/storage';
const props = defineProps({
    data: {
@@ -223,14 +223,14 @@
const storeCols = (colList: any[]) => {
    const key = colList.map((item) => item.label).join(',');
    if (!key) return;
    Local.set(key, colList);
    LocalPlus.set(key, colList, 7);
};
const colList = ref([]);
const getStoreCols = (colList: any[]) => {
    if (colList.length === 0) return colList;
    const key = colList.map((item) => item.label).join(',');
    if (!key) return colList;
    const storeValue = Local.get(key);
    const storeValue = LocalPlus.get(key);
    if (!storeValue) {
        return colList;
src/utils/storage.ts
@@ -32,6 +32,36 @@
    },
};
//#region ====================== 缓存带时间 ======================
type CacheValue<T> = {
    // 过期时间,时间戳
    expiredTime: number;
    value: T;
};
export const LocalPlus = {
    // 设置
    set<T>(key: string, val: T, expireDay: number) {
        const expireMs = expireDay * 24 * 60 * 60 * 1000;
        const cacheValue: CacheValue<T> = {
            expiredTime: new Date().getTime() + expireMs,
            value: val,
        };
        Local.set(key, cacheValue);
    },
    // 获取,过期则清除
    get(key: string) {
        const cacheValue: CacheValue<any> = Local.get(key);
        if (new Date().getTime() > cacheValue.expiredTime) {
            Local.remove(key);
            return null;
        }
        return cacheValue.value;
    },
};
//#endregion
/**
 * window.sessionStorage 浏览器临时缓存
 * @method set 设置临时缓存