Files
JayuCloud/FD-WeChat-Fronted/utils/storage.js
T
2026-06-15 15:53:55 +08:00

49 lines
1.6 KiB
JavaScript

/**
* Purpose: STORAGE_KEYS supports storage.js by holding or executing the storage keys page or API role.
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
*/
const STORAGE_KEYS = {
ACCESS_TOKEN: 'accessToken',
REFRESH_TOKEN: 'refreshToken',
USER_INFO: 'userInfo',
NEED_SET_PASSWORD: 'needSetPassword',
PREFERRED_MINI_LOGIN_SHOP_ID: 'preferredMiniLoginShopId',
DEVICE_ID: 'miniDeviceId'
}
/**
* Purpose: getStorage supports storage.js by holding or executing the get storage page or API role.
* Usage: import, call, read, or update this function from the owning page/module while preserving the surrounding loading and permission flow.
*/
function getStorage(key, defaultValue) {
try {
const value = wx.getStorageSync(key)
return value === '' || value === undefined ? defaultValue : value
} catch (error) {
return defaultValue
}
}
/**
* Purpose: setStorage supports storage.js by holding or executing the set storage page or API role.
* Usage: import, call, read, or update this function from the owning page/module while preserving the surrounding loading and permission flow.
*/
function setStorage(key, value) {
wx.setStorageSync(key, value)
}
/**
* Purpose: removeStorage supports storage.js by holding or executing the remove storage page or API role.
* Usage: import, call, read, or update this function from the owning page/module while preserving the surrounding loading and permission flow.
*/
function removeStorage(key) {
wx.removeStorageSync(key)
}
module.exports = {
STORAGE_KEYS,
getStorage,
setStorage,
removeStorage
}