map-exp-bar-control-base.ts 6.9 KB
Newer Older
1
import { IPSDERBase, IPSMapExpBar, IPSSysMap, IPSSysMapItem, 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 87 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
import { IPSAppDataEntity } from '@ibiz/dynamic-model-api';
import { MapExpBarControlInterface, Util } from 'ibiz-core';
import { ExpBarControlBase } from './expbar-control-base';
/**
 * 地图导航部件基类
 * 
 * 
 */
export class MapExpBarControlBase extends ExpBarControlBase implements MapExpBarControlInterface {

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

    /**
     * 数据部件
     *
     * @memberof MapExpBarControlBase
     */
    public declare $xDataControl: IPSSysMap;

    /**
     * 导航过滤项
     *
     * @type {*}
     * @memberof MapExpBarControlBase
     */
    public navFilter: any = {};

    /**
     * 导航关系
     *
     * @type {*}
     * @memberof MapExpBarControlBase
     */
    public navPSDer: any = {};

    /**
     * 初始化地图导航部件实例
     *
     * @memberof MapExpBarControlBase
     */
    public async ctrlModelInit() {
        await super.ctrlModelInit();
        this.initNavView();
    }

    /**
     * 初始化导航视图参数
     * 
     * @memberof MapExpBarControlBase
     */
    public initNavView() {
        const mapItems: IPSSysMapItem[] | null = this.$xDataControl?.getPSSysMapItems();
        let navViewName = {};
        let navParam = {};
        let navFilter = {};
        let navPSDer = {};
        if (mapItems && mapItems.length > 0) {
            mapItems.forEach((item: IPSSysMapItem) => {
                const viewName = {
                    [item.itemType]: item.getNavPSAppView() ? item.getNavPSAppView()?.modelPath : "",
                };
                Object.assign(navViewName, viewName);
                const param = {
                    [item.itemType]: {
                        navigateContext: this.initNavParam(item.getPSNavigateContexts()),
                        navigateParams: this.initNavParam(item.getPSNavigateParams()),
                    }
                }
                Object.assign(navParam, param);
                const filter = {
                    [item.itemType]: item.navFilter ? item.navFilter : "",
                }
                Object.assign(navFilter, filter);
                const psDer = {
                    [item.itemType]: item.getNavPSDER() ? "n_" + (item.getNavPSDER() as IPSDERBase).minorCodeName?.toLowerCase() + "_eq" : "",
                }
                Object.assign(navPSDer, psDer);
            })
        }
        this.navViewName = navViewName;
        this.navParam = navParam;
        this.navFilter = navFilter;
        this.navPSDer = navPSDer;
    }

    /**
     * 执行搜索
     *
     * @memberof GridExpBarControlBase
     */
    public onSearch() {
        if (this.Environment && this.Environment.isPreviewMode) {
            return;
        }
        let map: any = (this.$refs[`${this.xDataControlName}`] as any).ctrl;
        if (map) {
            map.load({ query: this.searchText });
        }
    }

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

    /**
     * 地图部件的选中数据事件
     * 
     *
     * @param {any[]} args 选中数据
124
     * @return {*}  {Promise<void>}
125 126
     * @memberof MapExpBarControlBase
     */
127
    public async onSelectionChange(args: any[]): Promise<void> {
128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158
        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 mapItem: IPSSysMapItem | null | undefined = ((this.$xDataControl as IPSSysMap).getPSSysMapItems() || []).find((item: IPSSysMapItem) => {
            return item.itemType === arg.itemType;
        });
        const mapItemEntity: IPSAppDataEntity | null | undefined = mapItem?.getPSAppDataEntity();
        if (mapItem && mapItemEntity) {
            Object.assign(tempContext, { [mapItemEntity.codeName?.toLowerCase()]: arg[mapItemEntity.codeName?.toLowerCase()] });
            Object.assign(tempContext, { srfparentdename: mapItemEntity.codeName, srfparentdemapname: (mapItemEntity as any)?.getPSDEName(), srfparentkey: arg[mapItemEntity.codeName?.toLowerCase()] });
            if (this.navFilter && this.navFilter[arg.itemType] && !Object.is(this.navFilter[arg.itemType], "")) {
                Object.assign(tempViewParam, { [this.navFilter[arg.itemType]]: arg[mapItemEntity.codeName?.toLowerCase()] });
            }
            if (this.navPSDer && this.navFilter[arg.itemType] && !Object.is(this.navPSDer[arg.itemType], "")) {
                Object.assign(tempViewParam, { [this.navPSDer[arg.itemType]]: arg[mapItemEntity.codeName?.toLowerCase()] });
            }
            if (this.navParam && this.navParam[arg.itemType] && this.navParam[arg.itemType].navigateContext && Object.keys(this.navParam[arg.itemType].navigateContext).length > 0) {
                let _context: any = Util.computedNavData(arg.curdata, tempContext, tempViewParam, this.navParam[arg.itemType].navigateContext);
                Object.assign(tempContext, _context);
            }
            if (this.navParam && this.navParam[arg.itemType] && this.navParam[arg.itemType].navigateParams && Object.keys(this.navParam[arg.itemType].navigateParams).length > 0) {
                let _params: any = Util.computedNavData(arg.curdata, tempContext, tempViewParam, this.navParam[arg.itemType].navigateParams);
                Object.assign(tempViewParam, _params);
            }
159 160 161 162 163 164 165 166
            const navViewModel = mapItem.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 });
                }
167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184
            }
        }
        this.handleCtrlEvents('onselectionchange', { action: 'selectionchange', data: args }).then((res: boolean) => {
            if (res) {
                const param = {
                    data: args,
                    srfnavdata: {
                        context: tempContext,
                        viewparams: tempViewParam
                    }
                }
                this.calcNavigationToolbarState(false, arg);
                this.$emit("ctrl-event", { controlname: this.controlInstance.name, action: "selectionchange", data: param });
            }
        })
    }

}