You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

44 lines
1.2 KiB

1 year ago
/**
* 用户缓存操作
*/
export default (function () {
let userCacheKey = "user";
let extCacheKey = "userExtends";
function set(key, info, obj){
uni.setStorageSync(key, info);
return obj;
}
function get(cacheKey, key, defaultValue){
let info = uni.getStorageSync(cacheKey);
return key !== null
? (info[key] ? info[key] : defaultValue)
: info;
}
function remove(cacheKey){
uni.removeStorageSync(cacheKey);
}
return {
set:(info) => set(userCacheKey, info),
setAndReturn(info){
this.set(info);
return this.get();
},
get:(key = null, defaultValue = null) => get(userCacheKey, key, defaultValue),
extSet:(info) => set(extCacheKey, info),
extSetAndReturn(info){
this.extSet(info);
return this.extGet();
},
extGet:(key = null, defaultValue = null) => get(extCacheKey, key, defaultValue),
clearUser:()=> remove(userCacheKey),
clearUserExt:() => remove(extCacheKey),
clearAll(){
this.clearUser();
this.clearUserExt();
}
}
})();