exp-view-engine.ts 5.5 KB
Newer Older
1 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
import ViewEngine from "./view-engine";

/**
 * 导航视图引擎
 *
 * @export
 * @class ExpViewEngine
 * @extends {ViewEngine}
 */
export class ExpViewEngine extends ViewEngine {
    /**
     * 导航栏部件
     *
     * @protected
     * @type {*}
     * @memberof ExpViewEngine
     */
    protected expBar: any = null;

    /**
     * 是否真正选中
     *
     * @protected
     * @type {boolean}
     * @memberof ExpViewEngine
     */
    protected isRealSelected: boolean = false;

    /**
     * 是否关闭导航视图
     *
     * @protected
     * @type {boolean}
     * @memberof ExpViewEngine
     */
    protected isCloseNavView: boolean = false;

    /**
     * 引擎加载
     *
Mosher's avatar
Mosher committed
41
     * @memberof ExpViewEngine
42 43 44 45 46
     */
    public load() {
        super.load();
        if (this.getExpBar() && this.isLoadDefault) {
            const tag = this.getExpBar().name;
Mosher's avatar
Mosher committed
47
            this.setViewState2({ tag: tag, action: "load", viewdata: this.view.viewparams });
48 49 50 51 52 53 54 55 56 57 58 59 60 61
        } else {
            this.isLoadDefault = true;
        }
    }

    /**
     * 搜索
     *
     * @param {*} data
     * @memberof ExpViewEngine
     */
    public search(data: any) {
        const expBar = this.getExpBar();
        if (expBar) {
Mosher's avatar
Mosher committed
62
            this.setViewState2({ tag: expBar.name, action: "load", viewdata: null });
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79
        }
    }

    /**
     * 关闭导航视图
     *
     * @memberof ExpViewEngine
     */
    public closeNavView() {
        this.view.backSplit = this.view.split;
        this.view.split = 1;
        this.view.navItem = null;
        this.isCloseNavView = true;
    }

    /**
     * 处理导航视图重绘(有选中项,且导航视图需要刷新则通知嵌入导航视图执行刷新逻辑)
Mosher's avatar
Mosher committed
80
     *
81 82 83 84
     * @memberof ExpViewEngine
     */
    public handleNavViewRefresh(tag: string) {
        if (this.view && this.view.viewState && this.isRealSelected) {
Mosher's avatar
Mosher committed
85
            this.setViewState2({ tag, action: "load", viewdata: this.view.viewparams });
86 87 88 89 90 91 92
        }
    }

    /**
     * 事件处理
     *
     * @param {string} ctrlName 事件标识
Mosher's avatar
Mosher committed
93
     * @param {string} eventName
94 95 96 97 98
     * @param {*} args
     * @memberof ExpViewEngine
     */
    public onCtrlEvent(ctrlName: string, eventName: string, args: any) {
        const expBar = this.getExpBar();
Mosher's avatar
Mosher committed
99
        if (expBar && ctrlName === expBar.name) {
100 101
            this.handleExpBarEvents(eventName, args);
        }
Mosher's avatar
Mosher committed
102
        if (expBar && ctrlName === expBar.xDataControlName) {
103 104 105 106 107 108 109 110 111 112 113 114 115
            this.handleXDataControlEvents(eventName, args);
        }
    }

    /**
     * 处理导航栏事件
     *
     * @protected
     * @param {string} eventName
     * @param {*} args
     * @memberof ExpViewEngine
     */
    protected handleExpBarEvents(eventName: string, args: any) {
Mosher's avatar
Mosher committed
116 117
        if (Object.is(eventName, "load")) {
            this.view.$emit("viewload", args);
118
        }
Mosher's avatar
Mosher committed
119
        if (Object.is(eventName, "selectionchange")) {
120 121 122 123
            if (this.isCloseNavView) {
                this.isCloseNavView = false;
                return;
            }
Mosher's avatar
Mosher committed
124
            if (this.view && args && args.srfnavdata && args.srfnavdata.context) {
125
                this.view.navItem = args;
Mosher's avatar
Mosher committed
126
                this.setNavPosData(args);
127 128 129 130 131 132 133
                if (this.view.backSplit !== 0) {
                    this.view.split = this.view.backSplit;
                }
                // 计算真实选中值
                if (args && args.data && args.data[0]) {
                    const selectedData = args.data[0];
                    const result = Object.keys(selectedData).find((key: string) => {
Mosher's avatar
Mosher committed
134 135 136
                        return selectedData[key] !== null && key !== "srfchecked";
                    });
                    if (result) {
137
                        this.isRealSelected = true;
Mosher's avatar
Mosher committed
138
                    } else {
139 140 141
                        this.isRealSelected = false;
                    }
                }
Mosher's avatar
Mosher committed
142
                this.view.$forceUpdate();
143
            }
Mosher's avatar
Mosher committed
144
            this.view.$emit("viewdataschange", args && args.data ? args.data : []);
145
        }
Mosher's avatar
Mosher committed
146 147
        if (Object.is(eventName, "activated")) {
            this.view.$emit("viewdatasactivated", args);
148 149 150
        }
    }

Mosher's avatar
Mosher committed
151 152 153 154 155 156 157 158 159 160 161 162 163 164 165
    /**
     * 设置导航数据
     *
     * @protected
     * @param {*} data
     * @return {*} 
     * @memberof ExpViewEngine
     */
    protected setNavPosData(data: any) {
        if (!this.view.layoutModelDetails) {
            return;
        }
        const navPos: any = Object.values(this.view.layoutModelDetails).find((item: any) => {
            return item.predefinedType === "NAV_POS";
        });
Mosher's avatar
Mosher committed
166 167 168
        if (navPos) {
            navPos.navData = data;
        }
Mosher's avatar
Mosher committed
169 170
    }

171 172 173 174 175 176 177 178 179
    /**
     * 处理导航栏数据部件事件
     *
     * @protected
     * @param {string} eventName
     * @param {*} args
     * @memberof ExpViewEngine
     */
    protected handleXDataControlEvents(eventName: string, args: any) {
Mosher's avatar
Mosher committed
180
        if (Object.is(eventName, "beforeload")) {
181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200
            this.handleBeforeLoad(args);
        }
    }

    /**
     * 导航栏数据部件加载之前
     *
     * @protected
     * @param {*} args
     * @memberof ExpViewEngine
     */
    protected handleBeforeLoad(args: any) {
        if (this.view && this.view.quickGroupData) {
            Object.assign(args, { viewparams: this.view.quickGroupData });
        }
    }

    /**
     * 获取导航栏
     *
Mosher's avatar
Mosher committed
201
     * @return {*}
202 203 204 205 206 207 208 209 210 211 212 213 214
     * @memberof ExpViewEngine
     */
    public getExpBar() {
        return this.expBar;
    }

    /**
     * @description 视图销毁
     * @memberof ExpViewEngine
     */
    public destroyed() {
        this.expBar = null;
    }
Mosher's avatar
Mosher committed
215
}