综合办公系统
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

storage.js 931B

123456789101112131415161718192021222324252627282930313233343536373839
  1. /*
  2. * @Author: ysh
  3. * @Date: 2025-01-16 11:17:24
  4. * @LastEditors:
  5. * @LastEditTime: 2025-02-17 14:39:22
  6. */
  7. import constant from './constant'
  8. // 存储变量名
  9. let storageKey = 'storage_data'
  10. // 存储节点变量名
  11. let storageNodeKeys = [constant.avatar, constant.name, constant.roles, constant.permissions, constant.userId, constant.deptId]
  12. // 存储的数据
  13. let storageData = uni.getStorageSync(storageKey) || {}
  14. const storage = {
  15. set: function (key, value) {
  16. if (storageNodeKeys.indexOf(key) != -1) {
  17. let tmp = uni.getStorageSync(storageKey)
  18. tmp = tmp ? tmp : {}
  19. tmp[key] = value
  20. uni.setStorageSync(storageKey, tmp)
  21. }
  22. },
  23. get: function (key) {
  24. return storageData[key] || ""
  25. },
  26. remove: function (key) {
  27. delete storageData[key]
  28. uni.setStorageSync(storageKey, storageData)
  29. },
  30. clean: function () {
  31. uni.removeStorageSync(storageKey)
  32. }
  33. }
  34. export default storage