/* eslint-disable no-empty */ export class Searchs { saveKey = 'searchs' initSearch = { form: {}, page: {}, } searchs = {} constructor(key) { this.key = key this.searchs = this.parse() } save() { sessionStorage.setItem(this.saveKey, JSON.stringify(this.searchs)) } parse() { let json = {} try { const val = sessionStorage.getItem(this.saveKey) json = JSON.parse(val) || initSearch } catch (error) {} return json } get(key) { const k = (key || this.key) if (!this.searchs[k]) { this.searchs[k] = {...initSearch} } return this.searchs[k] } remove(type) { if (this.searchs && this.searchs[this.key]) { type ? this.searchs[this.key][type] : this.searchs[this.key] this.save() } return this.searchs } getSearchs() { return this.searchs } removeByKey(key) { delete this.searchs[key] this.save() return this.searchs } removeAll() { this.searchs = {} sessionStorage.setItem(this.saveKey, JSON.stringify(this.searchs)) return this.searchs } update(data, key, type) { const k = (key || this.key) if (type) { this.searchs[k][type] = data } else { this.searchs[k] = data } this.save() return this.searchs } } const initSearch = { form: {}, page: {}, }