8b8b926d-2f0d-42e9-a81a-dc10184e8ffd.js 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  1. "use strict";
  2. cc._RF.push(module, '8b8b9JtLw1C6aga3BAYTo/9', 'LocalStorageUtil');
  3. // Script/Framework/Utils/LocalStorageUtil.ts
  4. "use strict";
  5. var __extends = (this && this.__extends) || (function () {
  6. var extendStatics = function (d, b) {
  7. extendStatics = Object.setPrototypeOf ||
  8. ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
  9. function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
  10. return extendStatics(d, b);
  11. };
  12. return function (d, b) {
  13. extendStatics(d, b);
  14. function __() { this.constructor = d; }
  15. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  16. };
  17. })();
  18. Object.defineProperty(exports, "__esModule", { value: true });
  19. exports.LocalStorageUtil = void 0;
  20. var Singleton_1 = require("./Singleton");
  21. var LocalStorageUtil = /** @class */ (function (_super) {
  22. __extends(LocalStorageUtil, _super);
  23. function LocalStorageUtil() {
  24. var _this = _super !== null && _super.apply(this, arguments) || this;
  25. /**音乐 */
  26. _this.lst_music = "Bird_music";
  27. /**音效 */
  28. _this.lst_effect = "Bird_effect";
  29. /**倒计时时间*/
  30. _this.lst_CountTime = "BirdCountTime";
  31. /**倒计时秒数*/
  32. _this.lst_CountSecond = "BirdCountSecond";
  33. /**体力 */
  34. _this.lst_Tili = "BirdTili";
  35. /** 最后进入关卡*/
  36. _this.lst_playLevel = "Bird_playLevel";
  37. /** 通关进度*/
  38. _this.lst_passProgress = "Bird_passProgress";
  39. _this.list_foodLevel = "list_foodLevel";
  40. _this.list_kitchenLevel = "list_kitchenLevel";
  41. _this.list_missionComplete = "list_missionComplete";
  42. _this.list_missionReceive = "list_missionReceive";
  43. // 通关场景进度
  44. _this.Bird_passScene = "Bird_passScene";
  45. /** 通关进度*/
  46. _this.lst_InfiniteLevelDate = "Bird_infiniteLevelDate";
  47. _this.str_guideStep = "str_guideStep";
  48. /** 道具数量*/
  49. _this.lst_PropNum = "lst_PropNum";
  50. /** 金币*/
  51. _this.lst_Coin = "lst_UserCoin";
  52. _this.lst_UserDiamond = "lst_UserDiamond";
  53. /** 用户皮肤组*/
  54. _this.lst_getSkin = "Bird_getSkin";
  55. /** 用户当前使用皮肤*/
  56. _this.lst_dressOnSkin = "Bird_dressOnSkin";
  57. /** 新手引导标志*/
  58. _this.lst_guide = "Bird_guide";
  59. // /** 免费视频次数 */
  60. // public lst_free_watch_times: string = "sausage_free_watch_times";
  61. // /** 每日签到数据 */
  62. // public lst_daily_signin: string = "sausage_daily_signin";
  63. _this.secretkey = 'ccxh_ws111'; // 加密密钥
  64. _this.isSecret = false;
  65. return _this;
  66. }
  67. LocalStorageUtil.prototype.set = function (key, value) {
  68. try {
  69. if (key) {
  70. if (this.isSecret) {
  71. var dataString = JSON.stringify(value);
  72. value = window["encryptjs"].encrypt(dataString, this.secretkey, 256);
  73. }
  74. cc.sys.localStorage.setItem(key, value);
  75. }
  76. }
  77. catch (e) {
  78. console.error("设置数据出错!!!");
  79. }
  80. };
  81. //不存在key时返回null
  82. LocalStorageUtil.prototype.get = function (key) {
  83. try {
  84. if (key) {
  85. var value = cc.sys.localStorage.getItem(key);
  86. if (value) {
  87. if (this.isSecret)
  88. return JSON.parse(window["encryptjs"].decrypt(value, this.secretkey, 256));
  89. else
  90. return value;
  91. }
  92. }
  93. return null;
  94. }
  95. catch (e) {
  96. console.error("获取数据出错!!!");
  97. return null;
  98. }
  99. };
  100. /**存string */
  101. LocalStorageUtil.prototype.setString = function (key, value) {
  102. this.set(key, value);
  103. };
  104. /**取string */
  105. LocalStorageUtil.prototype.getString = function (key) {
  106. var value = this.get(key);
  107. return value;
  108. };
  109. /**存boolean */
  110. LocalStorageUtil.prototype.setBoolean = function (key, value) {
  111. var temp = value ? "1" : "0";
  112. this.set(key, temp);
  113. };
  114. /**取boolean */
  115. LocalStorageUtil.prototype.getBoolean = function (key) {
  116. var value = this.get(key);
  117. if (value) {
  118. if (value == "1")
  119. return true;
  120. else
  121. return false;
  122. }
  123. return null;
  124. };
  125. /**存number */
  126. LocalStorageUtil.prototype.setNumber = function (key, value, encode) {
  127. if (value != null && value != undefined) {
  128. // if (value == Math.floor(value) && encode) { //整数
  129. // value = EncryptUtil.enValue(value);
  130. // }
  131. this.set(key, value.toString());
  132. }
  133. };
  134. /**取number */
  135. LocalStorageUtil.prototype.getNumber = function (key, decode) {
  136. var temp = this.get(key);
  137. if (temp) {
  138. if (temp.indexOf(".") >= 0) {
  139. return parseFloat(temp);
  140. }
  141. else {
  142. var value = parseInt(temp);
  143. // return EncryptUtil.desValue(value);
  144. }
  145. }
  146. return temp;
  147. };
  148. /**存json */
  149. LocalStorageUtil.prototype.setJsonObj = function (key, value) {
  150. if (value != null && value != undefined) {
  151. this.set(key, JSON.stringify(value));
  152. }
  153. };
  154. /**取json */
  155. LocalStorageUtil.prototype.getJsonObj = function (key) {
  156. var temp = this.get(key);
  157. if (temp != null) {
  158. return JSON.parse(temp);
  159. }
  160. return temp;
  161. };
  162. /**清空本地存在数据 */
  163. LocalStorageUtil.prototype.clearAll = function () {
  164. cc.sys.localStorage.clear();
  165. };
  166. /**删除数据key */
  167. LocalStorageUtil.prototype.deleteKey = function (key) {
  168. var temp = this.get(key);
  169. if (temp != null) {
  170. cc.sys.localStorage.removeItem(key);
  171. }
  172. };
  173. return LocalStorageUtil;
  174. }(Singleton_1.Singleton));
  175. exports.LocalStorageUtil = LocalStorageUtil;
  176. cc._RF.pop();