miao-plugin/models/Base.js

47 lines
947 B
JavaScript
Raw Normal View History

2022-08-18 10:13:42 +00:00
import { Data } from '../components/index.js'
2022-03-26 08:21:44 +00:00
let cacheMap = {}
let reFn = {}
2022-03-26 08:21:44 +00:00
export default class Base {
toString () {
2022-08-18 10:13:42 +00:00
return this?.name || ''
2022-03-26 08:21:44 +00:00
}
getData (arrList = '', cfg = {}) {
2022-08-18 10:13:42 +00:00
arrList = arrList || this._dataKey || ''
return Data.getData(this, arrList, cfg)
2022-03-26 08:21:44 +00:00
}
// 获取指定值数据,支持通过
getVal (key, defaultValue) {
return Data.getVal(this, key, defaultValue)
2022-03-26 08:21:44 +00:00
}
_getCache (uuid = '', time = 10 * 60) {
if (uuid && cacheMap[uuid]) {
return cacheMap[uuid]._setCache(time)
}
this._uuid = uuid
}
_setCache (time = 10 * 60) {
let id = this._uuid
if (id) {
reFn[id] && clearTimeout(reFn[id])
delete reFn[id]
reFn[id] = setTimeout(() => {
reFn[id] && clearTimeout(reFn[id])
delete reFn[id]
delete cacheMap[id]
}, time * 1000)
cacheMap[id] = this
}
return this
}
}
Base.get = (id, time = 10 * 60) => {
}