You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
35 lines
815 B
35 lines
815 B
import constant from './constant'
|
|
|
|
// 存储变量名
|
|
let storageKey = 'storage_data'
|
|
|
|
// 存储节点变量名
|
|
let storageNodeKeys = [
|
|
constant.avatar, constant.name,
|
|
constant.userInfo, constant.loginInfo
|
|
]
|
|
|
|
const storage = {
|
|
set: (key, value) => {
|
|
if (storageNodeKeys.indexOf(key) != -1) {
|
|
let tmp = uni.getStorageSync(storageKey)
|
|
tmp = tmp ? tmp : {}
|
|
tmp[key] = value
|
|
uni.setStorageSync(storageKey, tmp)
|
|
}
|
|
},
|
|
get: (key) => {
|
|
let storageData = uni.getStorageSync(storageKey) || {}
|
|
return storageData[key] || ""
|
|
},
|
|
remove: (key) => {
|
|
let storageData = uni.getStorageSync(storageKey) || {}
|
|
delete storageData[key]
|
|
uni.setStorageSync(storageKey, storageData)
|
|
},
|
|
clean: () => {
|
|
uni.removeStorageSync(storageKey)
|
|
}
|
|
}
|
|
|
|
export default storage
|