/** * 用户缓存操作 */ 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(); } } })();