+ 炽灼残渣新增保存功能
+ 格式化代码
This commit is contained in:
34
modules/tools.js
Normal file
34
modules/tools.js
Normal file
@@ -0,0 +1,34 @@
|
||||
class IO {
|
||||
constructor(scope) {
|
||||
this.scope = scope
|
||||
}
|
||||
|
||||
read(id) {
|
||||
let key = `${this.scope}/${id}`
|
||||
return localStorage.getItem(key)
|
||||
}
|
||||
|
||||
write(id, data) {
|
||||
let key = `${this.scope}/${id}`
|
||||
localStorage.setItem(key, data)
|
||||
}
|
||||
|
||||
remove(id) {
|
||||
let key = `${this.scope}/${id}`
|
||||
localStorage.removeItem(key)
|
||||
}
|
||||
|
||||
listKeys() {
|
||||
let keys = []
|
||||
for (const key in localStorage) {
|
||||
if (Object.hasOwnProperty.call(localStorage, key) &&
|
||||
key.startsWith(this.scope)) {
|
||||
let i = key.indexOf('/') + 1
|
||||
keys.push(key.slice(i))
|
||||
}
|
||||
}
|
||||
return keys
|
||||
}
|
||||
}
|
||||
|
||||
export { IO }
|
||||
Reference in New Issue
Block a user