storageUtil.ts 922 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. const storageKey = {
  2. userId: 'userId'
  3. }
  4. function saveStorage(key: any, value: any) {
  5. let promise = new Promise((resolve, reject) => {
  6. wx.setStorage({
  7. key: key,
  8. data: value,
  9. success(res) {
  10. resolve(res)
  11. },
  12. fail(res) {
  13. reject(res)
  14. }
  15. })
  16. })
  17. return promise;
  18. }
  19. function getStorage(key: any) {
  20. let promise = new Promise((resolve, reject) => {
  21. wx.getStorage({
  22. key: key,
  23. success(res) {
  24. resolve(res)
  25. },
  26. fail(res) {
  27. reject(res)
  28. }
  29. })
  30. })
  31. return promise;
  32. }
  33. export const storage = {
  34. storageKey,
  35. saveStorage: function (key: any, value: any) {
  36. return saveStorage(key, value);
  37. },
  38. getStorage: function (key: any) {
  39. return getStorage(key)
  40. }
  41. }