| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960 | import {isAllNull} from "js-fast-way"import website from '@/config/index'//获取缓存export const getStorage = (key, debug = false) => {    let obj = uni.getStorageSync(website.key + '-' + key), content;    if (isAllNull(obj)) {        return '';    }    try {        obj = JSON.parse(obj);    } catch {        return obj;    }    if (debug) {        return obj;    }    if (obj.dataType === 'string') {        content = obj.content;    } else if (obj.dataType === 'number') {        content = Number(obj.content);    } else if (obj.dataType === 'boolean') {        content = Boolean(obj.content);    } else if (obj.dataType === 'object') {        content = obj.content;    }    return content ?? '';}//保存缓存export const setStorage = (key, value) => {    try {        uni.setStorageSync(website.key + '-' + key, JSON.stringify({            dataType: typeof (value),            content: value ?? '',            datetime: new Date().getTime()        }));    } catch (e) {        uni.showToast({            title: '本地数据缓存失败',            icon: 'none'        });    }}//删除缓存export const delStorage = (key) => {    try {        uni.removeStorageSync(website.key + '-' + key);    } catch {    }}//清理缓存export const clearStorage = () => {    try {        uni.clearStorageSync();    } catch {}}
 |