Files
CompanyProject/衣莎项目/源码/YiShaXiYi/model/getSetting.js
2024-09-27 01:32:49 +08:00

62 lines
1.5 KiB
JavaScript

const app = getApp();
const config = app.loadConfig()
// 对StorageSync进行二次封装
export class StorageSync {
/**
* 存储本地信息
* @param {String} key 存储名称
* @param {String} value 存储内容
*/
setStorage(key, value) {
wx.setStorage({
key: `${config.prefix}${key}`,
data: value
})
}
/**
* 获取本地存储数据
* @param {String} key 需要获取的存储对象名称
*/
getSetting(key) {
return new Promise(function (resolve, reject) {
wx.getStorage({
key: `${config.prefix}${key}`,
success(res) {
resolve(res.data)
},
fail() {
resolve()
console.log("获取本地信息失败获取的key为:", key);
}
})
})
}
deleteStorage(key){
if(typeof key !== 'string') return console.error('类型错误');
wx.removeStorageSync(`${config.prefix}${key}`)
}
}
// 获取本地信息未完成
export class GetSetting extends StorageSync {
constructor() {
super()
}
// 判断本地是否授权
isAuthorization() {
if (!!this.getSetting('token')) {
return true
}
return false
}
// 获取本地授权信息
getAuthorization() {
}
// 更新本地授权信息
updateAuthorization() {
}
}