util.js 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. "use strict";
  2. const common_vendor = require("../common/vendor.js");
  3. const config_config = require("../config/config.js");
  4. const framework_log = require("./log.js");
  5. const framework_tools = require("./tools.js");
  6. class util {
  7. /**
  8. * 获取本地数据
  9. */
  10. static getStorage(key) {
  11. let d = common_vendor.index.getStorageSync(key);
  12. if (util.isNull(d)) {
  13. return null;
  14. }
  15. return d;
  16. }
  17. /**
  18. * 设置本地数据
  19. */
  20. static setStorage(key, value) {
  21. common_vendor.index.setStorageSync(key, value);
  22. }
  23. /**
  24. * 清除本地key数据
  25. */
  26. static clearStorageForKey(key) {
  27. let d = util.getStorage(key);
  28. if (util.isNull(d)) {
  29. framework_log.log.Error(`${key} is null!`);
  30. } else {
  31. util.setStorage(key, null);
  32. }
  33. }
  34. /**
  35. * 清除本地数据
  36. */
  37. static clearAllStorage() {
  38. common_vendor.index.clearStorageSync();
  39. }
  40. static isNull(v) {
  41. if (v == null || v == void 0 || v == "") {
  42. return true;
  43. }
  44. return false;
  45. }
  46. static alert(v) {
  47. let Platform = framework_tools.tools.getCurPlatform();
  48. if (Platform == config_config.config.Platform.H5) {
  49. alert(v);
  50. } else if (Platform == config_config.config.Platform.TOUTIAO) {
  51. framework_log.log.Debug("TOUTIAO", v);
  52. } else if (Platform == config_config.config.Platform.WEIXIN) {
  53. framework_log.log.Debug("WEIXIN", v);
  54. }
  55. }
  56. }
  57. exports.util = util;