¶Ô±ÈÐÂÎļþ |
| | |
| | | import constant from './constant' |
| | | |
| | | // åå¨åéå |
| | | let storageKey = 'storage_data' |
| | | |
| | | // åå¨èç¹åéå |
| | | let storageNodeKeys = [constant.avatar, constant.name, constant.roles, constant.permissions] |
| | | |
| | | // åå¨çæ°æ® |
| | | let storageData = uni.getStorageSync(storageKey) || {} |
| | | |
| | | const storage = { |
| | | set: function(key:string, value:any) { |
| | | if (storageNodeKeys.indexOf(key) != -1) { |
| | | let tmp = uni.getStorageSync(storageKey) |
| | | tmp = tmp ? tmp : {} |
| | | tmp[key] = value |
| | | uni.setStorageSync(storageKey, tmp) |
| | | } |
| | | }, |
| | | get: function(key:string) { |
| | | return storageData[key] || "" |
| | | }, |
| | | remove: function(key:string) { |
| | | delete storageData[key] |
| | | uni.setStorageSync(storageKey, storageData) |
| | | }, |
| | | clean: function() { |
| | | uni.removeStorageSync(storageKey) |
| | | } |
| | | } |
| | | |
| | | export default storage |