This commit is contained in:
qsh
2026-02-05 11:59:53 +08:00
parent e63e95525d
commit 5c5d3d8598
5 changed files with 48 additions and 29 deletions

View File

@@ -1,32 +1,32 @@
import constant from './constant'
import constant from './constant';
// 存储变量名
let storageKey = 'storage_data'
let storageKey = 'storage_data';
// 存储节点变量名
let storageNodeKeys = [constant.avatar, constant.id, constant.name, constant.roles, constant.permissions]
let storageNodeKeys = [constant.avatar, constant.id, constant.name, constant.roles, constant.permissions, constant.instanceId, constant.tenantId];
const storage = {
set: function(key, value) {
set: function (key, value) {
if (storageNodeKeys.indexOf(key) != -1) {
let tmp = uni.getStorageSync(storageKey)
tmp = tmp ? tmp : {}
tmp[key] = value
uni.setStorageSync(storageKey, tmp)
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] || ""
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)
remove: function (key) {
let storageData = uni.getStorageSync(storageKey) || {};
delete storageData[key];
uni.setStorageSync(storageKey, storageData);
},
clean: function() {
uni.removeStorageSync(storageKey)
clean: function () {
uni.removeStorageSync(storageKey);
}
}
};
export default storage
export default storage;