%APP_COUNTER%-counter-base.ts.ftl 2.2 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
import CounterService from '../counter-service';
<#ibiztemplate>
TARGET=PSAPPCOUNTER
</#ibiztemplate>
/**
 * ${item.getName()}计数器服务对象基类
 *
 * @export
 * @class ${item.getCodeName()}CounterServiceBase
 */
export default class ${srfclassname('${item.getCodeName()}')}CounterServiceBase extends CounterService {

    /**
     * 当前计数器数据对象
     * 
     * @param {*} [opts={}]
     * @memberof  ${srfclassname('${item.getCodeName()}')}CounterServiceBase
     */
19
    public counterData:any ={};
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40

    /**
     * Creates an instance of  ${srfclassname('${item.getCodeName()}')}CounterServiceBase.
     * 
     * @param {*} [opts={}]
     * @memberof  ${srfclassname('${item.getCodeName()}')}CounterServiceBase
     */
    constructor(opts: any = {}) {
        super(opts);
        this.initCounterData();
        setInterval(() => {
            this.fetchCounterData();
        }, <#if item.getTimer()??>${item.getTimer()?c}<#else>6000</#if>);
    }

    /**
     * 初始化当前计数器数据对象
     * 
     * @param {*} [opts={}]
     * @memberof  ${srfclassname('${item.getCodeName()}')}CounterServiceBase
     */
41
    public initCounterData(){
42 43 44 45 46 47 48 49 50
        this.fetchCounterData();
    }

    /**
     * 查询数据
     * 
     * @param {*} [opts={}]
     * @memberof  ${srfclassname('${item.getCodeName()}')}CounterServiceBase
     */
51
    public async fetchCounterData(){
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70
        this.counterData = {
            item1:parseInt((Math.random()*10)+''),
            item2:parseInt((Math.random()*100)+''),
            item3:parseInt((Math.random()*100)+''),
            item4:parseInt((Math.random()*100)+''),
            item5:parseInt((Math.random()*100)+''),
            item6:parseInt((Math.random()*100)+''),
            item7:parseInt((Math.random()*100)+''),
            item8:parseInt((Math.random()*100)+''),
            item9:parseInt((Math.random()*100)+''),
            item10:parseInt((Math.random()*100)+'')
        }
    }

    /**
     * 刷新数据
     *
     * @memberof ${srfclassname('${item.getCodeName()}')}CounterServiceBase
     */
71
    public async refreshData(){
72 73 74 75 76
        const res = await this.fetchCounterData();
        return res;
    }

}