storage.js 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. import { useStores } from "@/store/modules/index";
  2. // 存储变量名
  3. let storageKey = 'storage_data'
  4. const storage = {
  5. set: function (key, value) {
  6. let tmp = uni.getStorageSync(storageKey)
  7. tmp = tmp ? tmp : {}
  8. tmp[key] = value
  9. uni.setStorageSync(storageKey, tmp)
  10. },
  11. get: function (key) {
  12. return uni.getStorageSync(storageKey)[key] || ""
  13. },
  14. remove: function (key) {
  15. delete uni.getStorageSync(storageKey)[key]
  16. uni.setStorageSync(storageKey, uni.getStorageSync(storageKey))
  17. },
  18. clean: function () {
  19. uni.removeStorageSync(storageKey)
  20. }
  21. }
  22. const storageSystem = {
  23. init: function (key) { },
  24. set: function (key, value) {
  25. let tmp = uni.getStorageSync(useStores().userId + "_storage_System")
  26. tmp = tmp ? tmp : {}
  27. tmp[key] = value
  28. uni.setStorageSync(useStores().userId + "_storage_System", tmp)
  29. },
  30. get: function (key) {
  31. return uni.getStorageSync(useStores().userId + "_storage_System")[key] || ""
  32. },
  33. remove: function (key) {
  34. delete uni.getStorageSync(useStores().userId + "_storage_System")[key]
  35. uni.setStorageSync(useStores().userId + "_storage_System", uni.getStorageSync(useStores().userId + "_storage_System"))
  36. },
  37. clean: function () {
  38. uni.removeStorageSync(useStores().userId + "_storage_System")
  39. }
  40. }
  41. export { storage, storageSystem }