2026-02-05 11:59:53 +08:00
|
|
|
import constant from './constant';
|
2026-01-26 15:36:37 +08:00
|
|
|
|
|
|
|
|
// 存储变量名
|
2026-02-05 11:59:53 +08:00
|
|
|
let storageKey = 'storage_data';
|
2026-01-26 15:36:37 +08:00
|
|
|
|
|
|
|
|
// 存储节点变量名
|
2026-02-05 11:59:53 +08:00
|
|
|
let storageNodeKeys = [constant.avatar, constant.id, constant.name, constant.roles, constant.permissions, constant.instanceId, constant.tenantId];
|
2026-01-26 15:36:37 +08:00
|
|
|
|
|
|
|
|
const storage = {
|
2026-02-05 11:59:53 +08:00
|
|
|
set: function (key, value) {
|
2026-01-26 15:36:37 +08:00
|
|
|
if (storageNodeKeys.indexOf(key) != -1) {
|
2026-02-05 11:59:53 +08:00
|
|
|
let tmp = uni.getStorageSync(storageKey);
|
|
|
|
|
tmp = tmp ? tmp : {};
|
|
|
|
|
tmp[key] = value;
|
|
|
|
|
uni.setStorageSync(storageKey, tmp);
|
2026-01-26 15:36:37 +08:00
|
|
|
}
|
|
|
|
|
},
|
2026-02-05 11:59:53 +08:00
|
|
|
get: function (key) {
|
|
|
|
|
let storageData = uni.getStorageSync(storageKey) || {};
|
|
|
|
|
return storageData[key] || '';
|
2026-01-26 15:36:37 +08:00
|
|
|
},
|
2026-02-05 11:59:53 +08:00
|
|
|
remove: function (key) {
|
|
|
|
|
let storageData = uni.getStorageSync(storageKey) || {};
|
|
|
|
|
delete storageData[key];
|
|
|
|
|
uni.setStorageSync(storageKey, storageData);
|
2026-01-26 15:36:37 +08:00
|
|
|
},
|
2026-02-05 11:59:53 +08:00
|
|
|
clean: function () {
|
|
|
|
|
uni.removeStorageSync(storageKey);
|
2026-01-26 15:36:37 +08:00
|
|
|
}
|
2026-02-05 11:59:53 +08:00
|
|
|
};
|
2026-01-26 15:36:37 +08:00
|
|
|
|
2026-02-05 11:59:53 +08:00
|
|
|
export default storage;
|