store.js 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. import {Global} from "../common/Global.js";
  2. class Store {
  3. static login = 'isLogin'
  4. static save(key, value) {
  5. uni.setStorageSync(key,value)
  6. }
  7. static saveUserInfo (value) {
  8. uni.setStorageSync(Global.userKey,value);
  9. }
  10. static saveToken( value) {
  11. this.setIsLogin(true)
  12. uni.setStorageSync(Global.tokenKey,value)
  13. }
  14. static saveType( value) {
  15. // this.setIsLogin(true)
  16. uni.setStorageSync(Global.typeKey,value)
  17. }
  18. static removeType( value) {
  19. // this.setIsLogin(false)
  20. uni.removeStorageSync(Global.typeKey)
  21. }
  22. static removeUser( value) {
  23. // this.setIsLogin(false)
  24. uni.removeStorageSync(Global.userKey)
  25. }
  26. static removeToken( value) {
  27. // this.setIsLogin(false)
  28. uni.removeStorageSync(Global.tokenKey)
  29. }
  30. static isLogin() {
  31. return this.get(this.login)
  32. }
  33. static get(key) {
  34. return uni.getStorageSync(key)
  35. }
  36. static getToken() {
  37. return this.get(Global.tokenKey)
  38. }
  39. static getUser() {
  40. return this.get(Global.userKey)
  41. }
  42. static getType() {
  43. return this.get(Global.typeKey)
  44. }
  45. static setIsLogin(isLogin) {
  46. uni.$emit('isLogin',{ isLogin:isLogin })
  47. Store.save(Store.login, isLogin)
  48. }
  49. static isExist (key) {
  50. const value = this.get(key)
  51. return value !== null && value !==undefined && value !==''
  52. }
  53. }
  54. export {
  55. Store
  56. }