talk_appAmin/utils/storage.js

66 lines
1.4 KiB
JavaScript
Raw Normal View History

2024-04-23 23:01:35 +08:00
import constant from './constant'
// 存储变量名
let storageKey = 'storage_data'
// 存储节点变量名
2024-06-09 15:37:59 +08:00
let storageNodeKeys = [
constant.avatar,
2024-06-27 08:57:50 +08:00
constant.deptManageName,
constant.deptManage,
2024-06-09 15:37:59 +08:00
constant.nickName,
constant.sex,
constant.QNDomain,
constant.phoneType,
// userInfo
constant.birthday,
2024-06-15 15:19:23 +08:00
constant.newUser,
2024-06-09 15:37:59 +08:00
constant.doingsStatus,
constant.infoName,
constant.infoSchool,
constant.infoDepartment,
2024-06-15 15:19:23 +08:00
constant.codeInfo,
constant.codeDocument,
2024-06-09 15:37:59 +08:00
constant.infoGrade,
constant.infoCode,
constant.infoDocument,
constant.auditInfo,
constant.infoRank,
constant.infoCoin,
constant.infoActive,
constant.infoAssist,
constant.followCount,
constant.fanCount,
constant.remark,
2024-06-15 15:19:23 +08:00
constant.area,
constant.backgroundImage,
2024-06-09 15:37:59 +08:00
constant.name, constant.roles, constant.permissions]
2024-04-23 23:01:35 +08:00
const storage = {
set: function(key, value) {
if (storageNodeKeys.indexOf(key) != -1) {
let tmp = uni.getStorageSync(storageKey)
tmp = tmp ? tmp : {}
tmp[key] = value
uni.setStorageSync(storageKey, tmp)
}
},
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