feat:初始化 -融骅

This commit is contained in:
2023-10-17 09:15:30 +08:00
parent c9ff84e6a2
commit 405e152b38
1190 changed files with 138344 additions and 455 deletions

View File

@@ -0,0 +1,52 @@
export default (storage) => {
if (!storage) return
const skey = (key) => '' + key
return {
/**
* 获取
* @param {string} key key
* @param {any} defaultValue defaultValue
*/
get (key, defaultValue) {
try {
return JSON.parse(storage.getItem(skey(key))) || defaultValue
} catch (error) {
return defaultValue
}
},
/**
* 保存
* @param {string} key key
* @param {any} val 值
*/
save (key, val) {
if (val === undefined || val === null) return this.remove(key)
storage.setItem(skey(key), JSON.stringify(val))
},
/**
* 获取 所有key
*/
keys () {
return Object.keys(storage)
},
/**
* 删除
* @param {string} key key
*/
remove (key) {
storage.removeItem(skey(key))
},
/**
* 清空
*/
clear () {
storage.clear()
}
}
}