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

调整计数器服务基类

上级 a10577cc
import { Store } from 'vuex';
/** /**
* 计数器服务基类 * 计数器服务基类
* *
* @export * @export
* @class CounterServiceBase * @class CounterService
*/
export class CounterServiceBase {
/**
* 当前计数器数据对象
*
* @memberof CounterServiceBase
*/ */
public counterData: any = {}; export default class CounterService {
/** /**
* 定时器实例 * 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> { public getService(name: string): Promise<any> {
return this.fetchCounterData(); 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 到此讨论。请谨慎行事。
先完成此消息的编辑!
想要评论请 注册