1234567891011121314151617181920212223242526272829303132333435363738394041424344454647 |
- class Storage {
- // token
- static getToken() {
- let token = uni.getStorageSync('access_token')
- return token || '';
- }
- static setCache(key, value) {
- return uni.setStorageSync(key, value)
- }
- static getCache(key) {
- return uni.getStorageSync(key)
- }
- static setToken(token = null) {
- uni.setStorageSync('access_token', token)
- }
- static removeCache(key) {
- uni.removeStorageSync(key)
- }
- static removeToken() {
- uni.removeStorageSync('access_token')
- }
- // 清除
- static clear() {
- uni.clearStorageSync()
- uni.clearStorage()
- }
- static isLogin() {
- const token = uni.getStorageSync('access_token')
- const user = uni.getStorageSync('userInfo')
- if (token && user) {
- return true;
- } else {
- return false;
- }
- }
- static resetToken() {
- // const token = this.getToken()
- // const str = cryptojs.Decrypt(token);
- // const tokens = str.split(',');
- // const tokenStr = tokens[0] + ',' + ((new Date()).valueOf());
- // // const res = cryptojs.Encrypt(tokenStr)
- return this.getToken();
- }
- }
- export default Storage
|