merchant-app/utils/storage.js

33 lines
904 B
JavaScript
Raw Normal View History

2024-09-12 14:10:05 +08:00
import constant from './constant'
// 存储变量名
let storageKey = 'storage_data'
// 存储节点变量名
2024-10-24 11:10:31 +08:00
let storageNodeKeys = [constant.avatar, constant.name, constant.roles, constant.permissions, constant.phone, constant.idCard, constant.nickName, constant.roleType]
2024-09-12 14:10:05 +08:00
const storage = {
set: function(key, value) {
2024-10-24 11:10:31 +08:00
// if (storageNodeKeys.indexOf(key) != -1) {
2024-09-12 14:10:05 +08:00
let tmp = uni.getStorageSync(storageKey)
tmp = tmp ? tmp : {}
tmp[key] = value
uni.setStorageSync(storageKey, tmp)
2024-10-24 11:10:31 +08:00
// }
2024-09-12 14:10:05 +08:00
},
get: function(key) {
let storageData = uni.getStorageSync(storageKey) || {}
return storageData[key] || ""
},
remove: function(key) {
let storageData = uni.getStorageSync(storageKey) || {}
delete storageData[key]
uni.setStorageSync(storageKey, storageData)
},
clean: function() {
uni.removeStorageSync(storageKey)
}
}
export default storage