chart-exp-bar-control-base.tsx 6.8 KB
Newer Older
1
import { IPSAppDataEntity, IPSChartExpBar, IPSDEChart, IPSDEChartSeries, IPSDERBase, IPSAppDERedirectView } from '@ibiz/dynamic-model-api';
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86
import { ModelTool, Util } from 'ibiz-core';
import { ExpBarControlBase } from './expbar-control-base';

export class ChartExpBarControlBase extends ExpBarControlBase {

    /**
     * 导航栏部件模型对象
     * 
     * @memberof ChartExpBarControlBase
     */
    public declare controlInstance: IPSChartExpBar;

    /**
     * 数据部件
     *
     * @memberof ChartExpBarControlBase
     */
    public declare $xDataControl: IPSDEChart;

    /**
     * 部件模型初始化
     * 
     * @memberof ChartExpBarControlBase
     */
    public async ctrlModelInit() {
        await super.ctrlModelInit();
        this.initNavView();
    }

    /**
     * 初始化导航视图
     * 
     * @memberof ChartExpBarControlBase
     */
    public initNavView() {
        if (!this.$xDataControl) {
            return;
        }
        let navViewName: any = {};
        let navParam: any = {};
        let navFilter: any = {};
        let navPSDer: any = {};
        const series: Array<IPSDEChartSeries> = this.$xDataControl.getPSDEChartSerieses() || [];
        series.forEach((item: IPSDEChartSeries) => {
            Object.assign(navViewName, {
                [item.name]: item.getNavPSAppView?.()?.modelPath || ""
            });
            Object.assign(navParam, {
                [item.name.toLowerCase()]: {
                    navigateContext: this.initNavParam(item.getPSNavigateContexts?.()),
                    navigateParams: this.initNavParam(item.getPSNavigateParams?.())
                }
            });
            if (item.navFilter) {
                Object.assign(navFilter, {
                    [item.name]: item.navFilter || ""
                });
            }
            Object.assign(navPSDer, {
                [item.name]: item.getNavPSDER() ? "n_" + (item.getNavPSDER() as IPSDERBase).minorCodeName?.toLowerCase() + "_eq" : ""
            });
        })
        this.navViewName = navViewName;
        this.navParam = navParam;
        this.navFilter = navFilter;
        this.navPSDer = navPSDer;
    }

    /**
     * 刷新
     *
     * @memberof ChartExpBarControlBase
     */
    public refresh(): void {
        let chart: any = (this.$refs[`${this.xDataControlName}`] as any)?.ctrl;
        if (chart) {
            chart.load({ query: this.searchText });
        }
    }

    /**
     * 图表部件选中数据变化
     * 
     * @memberof ChartExpBarControlBase
     */
87
    public async onSelectionChange(args: any[]): Promise<void> {
88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129
        let tempContext: any = {};
        let tempViewParam: any = {};
        if (args.length === 0) {
            this.calcNavigationToolbarState(true);
            return;
        }
        const arg: any = args[0];
        if (this.context) {
            Object.assign(tempContext, Util.deepCopy(this.context));
        }
        const seriesItem: IPSDEChartSeries | null | undefined = (this.$xDataControl.getPSDEChartSerieses() || []).find((item: IPSDEChartSeries) => {
            return item.name.toLowerCase() === arg._chartName.toLowerCase();
        });
        const appDataEntity: IPSAppDataEntity | null = this.$xDataControl?.getPSAppDataEntity();
        if (seriesItem && appDataEntity) {
            Object.assign(tempContext, { [appDataEntity.codeName?.toLowerCase()]: arg[(ModelTool.getAppEntityKeyField(appDataEntity) as any)?.codeName?.toLowerCase()] });
            Object.assign(tempContext, { srfparentdename: appDataEntity.codeName, srfparentdemapname: (appDataEntity as any)?.getPSDEName(), srfparentkey: arg[appDataEntity.codeName?.toLowerCase()] });
            //  分类属性
            if (seriesItem.catalogField) {
                Object.assign(tempContext, { [seriesItem.catalogField]: arg[seriesItem.catalogField] });
                Object.assign(tempViewParam, { [seriesItem.catalogField]: arg[seriesItem.catalogField] });
                Object.assign(tempViewParam, { [`n_${seriesItem.catalogField}_eq`]: arg[`${seriesItem.catalogField}_srfvalue`] ? arg[`${seriesItem.catalogField}_srfvalue`] : arg[seriesItem.catalogField] });
            }
            //  数据属性
            if (seriesItem.valueField) {
                Object.assign(tempContext, { [seriesItem.valueField]: arg[seriesItem.valueField] });
                Object.assign(tempViewParam, { [seriesItem.valueField]: arg[seriesItem.valueField] });
            }
            if (this.navFilter && this.navFilter[arg._chartName] && !Object.is(this.navFilter[arg._chartName], "")) {
                Object.assign(tempViewParam, { [this.navFilter[arg._chartName]]: arg[appDataEntity.codeName?.toLowerCase()] });
            }
            if (this.navPSDer && this.navFilter[arg._chartName] && !Object.is(this.navPSDer[arg._chartName], "")) {
                Object.assign(tempViewParam, { [this.navPSDer[arg._chartName]]: arg[appDataEntity.codeName?.toLowerCase()] });
            }
            if (this.navParam && this.navParam[arg._chartName] && this.navParam[arg._chartName].navigateContext && Object.keys(this.navParam[arg._chartName].navigateContext).length > 0) {
                let _context: any = Util.computedNavData(arg, tempContext, tempViewParam, this.navParam[arg._chartName].navigateContext);
                Object.assign(tempContext, _context);
            }
            if (this.navParam && this.navParam[arg._chartName] && this.navParam[arg._chartName].navigateParams && Object.keys(this.navParam[arg._chartName].navigateParams).length > 0) {
                let _params: any = Util.computedNavData(arg, tempContext, tempViewParam, this.navParam[arg._chartName].navigateParams);
                Object.assign(tempViewParam, _params);
            }
130 131 132 133 134 135 136 137
            const navViewModel = seriesItem.getNavPSAppView();
            if (navViewModel) {
                if (Object.is(navViewModel.viewType, 'DEREDIRECTVIEW')) {
                    const { modelPath } = await this.getRedirectViewModelPath(tempContext, tempViewParam, navViewModel as IPSAppDERedirectView);
                    Object.assign(tempContext, { viewpath: modelPath });
                } else {
                    Object.assign(tempContext, { viewpath: navViewModel.modelPath });
                }
138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155
            }
        }
        this.handleCtrlEvents('onselectionchange', { action: 'selectionchange', data: args }).then((res: boolean) => {
            if (res) {
                const params = {
                    data: args,
                    srfnavdata: {
                        context: tempContext,
                        viewparams: tempViewParam
                    }
                }
                this.calcNavigationToolbarState(false, arg);
                this.$emit("ctrl-event", { controlname: this.controlInstance.name, action: "selectionchange", data: params });
            }
        })
    }

}