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

    /**
     * Creates an instance of  ${srfclassname('${item.getCodeName()}')}CounterServiceBase.
     * 
     * @param {*} [opts={}]
     * @memberof  ${srfclassname('${item.getCodeName()}')}CounterServiceBase
     */
    constructor(opts: any = {}) {
        super(opts);
        this.initCounterData();
22 23
        this.timer = setInterval(() => {
            this.fetchCounterData(this.context,this.viewparams);
24 25 26 27 28 29 30 31 32
        }, <#if item.getTimer()??>${item.getTimer()?c}<#else>6000</#if>);
    }

    /**
     * 初始化当前计数器数据对象
     * 
     * @param {*} [opts={}]
     * @memberof  ${srfclassname('${item.getCodeName()}')}CounterServiceBase
     */
33
    public initCounterData(){
34
        this.fetchCounterData(this.context,this.viewparams);
35 36 37 38 39 40 41 42
    }

    /**
     * 查询数据
     * 
     * @param {*} [opts={}]
     * @memberof  ${srfclassname('${item.getCodeName()}')}CounterServiceBase
     */
43 44 45 46
    public async fetchCounterData(context:any,data:any){
        <#if item.getPSAppDataEntity?? && item.getPSAppDataEntity()?? && item.getGetPSAppDEAction?? && item.getGetPSAppDEAction()??>
        let _appEntityService:any = await this.appEntityService.getService('${item.getPSAppDataEntity().getCodeName()?lower_case}');
        if (_appEntityService['${item.getGetPSAppDEAction().getCodeName()}'] && _appEntityService['${item.getGetPSAppDEAction().getCodeName()}'] instanceof Function) {
47
            let result = await _appEntityService['${item.getGetPSAppDEAction().getCodeName()}'](context,data, false);
48
            this.counterData = result.data;
49
        }
50
        </#if>
51 52 53 54 55 56 57
    }

    /**
     * 刷新数据
     *
     * @memberof ${srfclassname('${item.getCodeName()}')}CounterServiceBase
     */
58
    public async refreshData(){
59 60 61
        if (this['fetchCounterData'] && this['fetchCounterData'] instanceof Function) {
            await this.fetchCounterData(this.context,this.viewparams);
        }
62 63 64
    }

}