storage.js 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. class Storage {
  2. // token
  3. static getToken() {
  4. let token = uni.getStorageSync('access_token')
  5. return token || '';
  6. }
  7. static setCache(key, value) {
  8. return uni.setStorageSync(key, value)
  9. }
  10. static getCache(key) {
  11. return uni.getStorageSync(key)
  12. }
  13. static setToken(token = null) {
  14. uni.setStorageSync('access_token', token)
  15. }
  16. static removeCache(key) {
  17. uni.removeStorageSync(key)
  18. }
  19. static removeToken() {
  20. uni.removeStorageSync('access_token')
  21. }
  22. // 清除
  23. static clear() {
  24. uni.clearStorageSync()
  25. uni.clearStorage()
  26. }
  27. static isLogin() {
  28. const token = uni.getStorageSync('access_token')
  29. const user = uni.getStorageSync('userInfo')
  30. if (token && user) {
  31. return true;
  32. } else {
  33. return false;
  34. }
  35. }
  36. static resetToken() {
  37. // const token = this.getToken()
  38. // const str = cryptojs.Decrypt(token);
  39. // const tokens = str.split(',');
  40. // const tokenStr = tokens[0] + ',' + ((new Date()).valueOf());
  41. // // const res = cryptojs.Encrypt(tokenStr)
  42. return this.getToken();
  43. }
  44. }
  45. export default Storage