提交 20de8d9e 编写于 作者: tony001's avatar tony001

调整计数器服务基类

上级 a10577cc
import { Store } from 'vuex';
/** /**
* 计数器服务基类 * 计数器服务基类
* *
* @export * @export
* @class CounterServiceBase * @class CounterService
*/ */
export class CounterServiceBase { export default class CounterService {
/**
* 当前计数器数据对象
*
* @memberof CounterServiceBase
*/
public counterData: any = {};
/** /**
* 定时器实例 * Vue 状态管理器
* *
* @type {*} * @private
* @memberof CounterServiceBase * @type {(any | null)}
* @memberof CounterService
*/ */
public timer: any; private $store: Store<any> | null = null;
/**
* Creates an instance of CounterServiceBase.
* @memberof CounterServiceBase
*/
constructor() {
this.initCounterData();
this.timer = setInterval(() => {
this.fetchCounterData();
}, 60000);
}
/** /**
* 初始化计数器 * Creates an instance of CounterService.
* *
* @protected * @param {*} [opts={}]
* @memberof CounterServiceBase * @memberof CounterService
*/ */
protected initCounterData(): void { constructor(opts: any = {}) {
this.fetchCounterData(); this.$store = opts.$store;
} }
/** /**
* 查询数据 * 获取状态管理器
* *
* @protected * @returns {(any | null)}
* @returns {Promise<any>} * @memberof CounterService
* @memberof CounterServiceBase
*/ */
protected async fetchCounterData(): Promise<any> { public getStore(): Store<any> | null {
for (let i: number = 0; i < 10; i++) { return this.$store;
this.counterData['item' + i] = Math.floor(Math.random() * 10);
}
} }
/** /**
* 刷新数据 * 获取计数器服务
* *
* @protected * @protected
* @param {string} name 实体名称
* @returns {Promise<any>} * @returns {Promise<any>}
* @memberof CounterServiceBase * @memberof CounterService
*/
protected refreshData(): Promise<any> {
return this.fetchCounterData();
}
/**
* 定时器销毁
*
* @memberof CounterServiceBase
*/ */
public destroy(): void { public getService(name: string): Promise<any> {
if (this.timer) { return (window as any)['counterServiceRegister'].getService(name);
clearInterval(this.timer);
}
} }
} }
\ No newline at end of file
Markdown 格式
0% or
您添加了 0 到此讨论。请谨慎行事。
先完成此消息的编辑!
想要评论请 注册