storage.js 955 B

12345678910111213141516171819202122232425262728
  1. "use strict";
  2. const common_vendor = require("../common/vendor.js");
  3. const utils_constant = require("./constant.js");
  4. let storageKey = "storage_data";
  5. let storageNodeKeys = [utils_constant.constant.avatar, utils_constant.constant.name, utils_constant.constant.roles, utils_constant.constant.permissions];
  6. let storageData = common_vendor.index.getStorageSync(storageKey) || {};
  7. const storage = {
  8. set: function(key, value) {
  9. if (storageNodeKeys.indexOf(key) != -1) {
  10. let tmp = common_vendor.index.getStorageSync(storageKey);
  11. tmp = tmp ? tmp : {};
  12. tmp[key] = value;
  13. common_vendor.index.setStorageSync(storageKey, tmp);
  14. }
  15. },
  16. get: function(key) {
  17. return storageData[key] || "";
  18. },
  19. remove: function(key) {
  20. delete storageData[key];
  21. common_vendor.index.setStorageSync(storageKey, storageData);
  22. },
  23. clean: function() {
  24. common_vendor.index.removeStorageSync(storageKey);
  25. }
  26. };
  27. exports.storage = storage;