perf: fix table setting error

This commit is contained in:
ibuler
2025-02-25 18:16:22 +08:00
committed by 老广
parent 8e461e8aed
commit e361bcbf42
4 changed files with 25 additions and 34 deletions

View File

@@ -388,21 +388,27 @@ export class ObjectLocalStorage {
} catch (e) {
console.warn('localStorage value is not a valid JSON: ', this.key)
}
if (typeof value !== 'object') {
if (!value || typeof value !== 'object') {
value = {}
}
return value
}
get(attr) {
get(attr, defaults) {
const obj = this.getObject(this.key)
const attrSafe = this.b64(attr)
return obj[attrSafe]
const val = obj[attrSafe]
if (val === undefined) {
return defaults
}
return val
}
set(attr, value) {
const obj = this.getObject(this.key)
const attrSafe = this.b64(attr)
console.log('Obj: ', obj)
console.log('Set to: ', attr, value)
obj[attrSafe] = value
window.localStorage.setItem(this.key, JSON.stringify(obj))
}