import Tool from "./Tool"; import UserInfoMgr from "./user/UserInfoMgr"; class LocalStorageMgr{ constructor() { console.log('LocalStorageMgr初始化'); } getDailyNum(key){ let jsonStr = cc.sys.localStorage.getItem(key); if(jsonStr){ let jsonObj = JSON.parse(jsonStr); let tempKey = key + UserInfoMgr.getUserId() + (new Date()).getDate(); return jsonObj[tempKey] || 0; }else{ return 0; } } setDailyNum(key, num){ let jsonStr = cc.sys.localStorage.getItem(key); let jsonObj = {}; if(jsonStr){ jsonObj = JSON.parse(jsonStr); } let tempKey = key + UserInfoMgr.getUserId() + (new Date()).getDate(); jsonObj[tempKey] = jsonObj[tempKey] || 0; jsonObj[tempKey] = num; let newJsonObj = {}; newJsonObj[tempKey] = jsonObj[tempKey]; cc.sys.localStorage.setItem(key,JSON.stringify(newJsonObj)); } getLocalValue(key, defValue=0){ let vaule = cc.sys.localStorage.getItem(key); if(Tool.IsEmpty(vaule)) { return defValue; } return vaule; } setLocalValue(key, data){ cc.sys.localStorage.setItem(key, data); } } let instance = null; LocalStorageMgr.getInstance = function(){ if(!instance){ instance = new LocalStorageMgr(); } return instance; } export default LocalStorageMgr.getInstance();