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

调整计数器服务基类

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