123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155 |
- import Plat from "../utils/Palt";
- import GameUtil from "../utils/util/GameUtil";
- const { ccclass, property } = cc._decorator;
- @ccclass("LocalManager")
- export default class LocalData {
- //#region 基本函数
- public static str_datas: { [key: string]: string } = {};
- public static getItemToStr(key, val?: string): string {
- if (this.str_datas[key] == null) {
- let str = cc.sys.localStorage.getItem(key);
- if (str == null || str == "") {
- str = "";
- if (val) {
- str = val;
- }
- this.str_datas[key] = str;
- }
- else {
- this.str_datas[key] = str;
- }
- }
- return this.str_datas[key];
- }
- public static setItemToStr(key: string, val: string) {
- this.str_datas[key] = val;
- cc.sys.localStorage.setItem(key, val);
- }
- public static int_datas: { [key: string]: number } = {};
- public static getItemToNumber(key, val?: number): number {
- if (this.int_datas[key] == null) {
- let str = cc.sys.localStorage.getItem(key);
- if (str == null || str == "") {
- let v = 0;
- if (val) {
- v = val;
- }
- this.int_datas[key] = v;
- }
- else {
- this.int_datas[key] = parseInt(str);
- }
- }
- return this.int_datas[key];
- }
- public static setItemToNumber(key: string, val: number): any {
- this.int_datas[key] = val;
- cc.sys.localStorage.setItem(key, val + "");
- }
- //#endregion
- public static yx: boolean = true;
- public static yy: boolean = true;
- public static set lv(curLevel) {
- Plat.setRank(curLevel)
- this.setItemToNumber("curLevel", curLevel)
- }
- public static get lv() {
- return this.getItemToNumber("curLevel", 1);
- }
- public static set openid(id) {
- this.setItemToStr("openid", id);
- }
- public static get openid() {
- return this.getItemToStr("openid");
- }
- private static _userinfo: any = null;
- public static set userinfo(info) {
- this._userinfo = info;
- this.setItemToStr("userinfo", JSON.stringify(info));
- }
- public static get userinfo() {
- if (this._userinfo == null) {
- let str = this.getItemToStr("userinfo");
- if (str == "") {
- this._userinfo = null;
- }
- else {
- this._userinfo = JSON.parse(str);
- }
- }
- return this._userinfo;
- }
- public static set userid(id) {
- this.setItemToStr("userid", id);
- }
- public static get userid() {
- let str = this.getItemToStr("userid");
- if (str == "") {
- str = "" + Date.now() + GameUtil.randomRange(0, 10000000);
- this.setItemToStr("userid", str);
- }
- return str;
- }
- public static get catSkinList(): number[] {
- let skinListStr = localStorage.getItem("local_data_list");
- if (!skinListStr) {
- skinListStr = "{}"
- }
- const skinList = JSON.parse(skinListStr)
- return skinList
- }
- public static set catSkinList(v: number[]) {
- }
-
- }
|