expview-base.tsx 8.0 KB
Newer Older
1
import { IPSExpBar } from '@ibiz/dynamic-model-api';
2
import { IParams, Util } from 'ibiz-core';
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
import { ExpViewInterface } from 'ibiz-core/src/interface/view/exp-view';
import { MainViewBase } from './mainview-base';

/**
 * 导航视图基类
 *
 * @export
 * @class ExpViewBase
 * @extends {MainViewBase}
 * @implements {ExpViewInterface}
 */
export class ExpViewBase extends MainViewBase implements ExpViewInterface {
    /**
     * 视图唯一标识
     *
     * @type {string}
     * @memberof ExpViewBase
     */
    public viewUID: string = '';

    /**
     * 导航栏实例
     * 
     * @memberof ExpViewBase
     */
    public expBarInstance!: IPSExpBar;

    /**
     * 导航项
     *
     * @type {*}
     * @memberof ExpViewBase
     */
    public navItem: any;

    /**
     * 分隔占位比例
     *
     * @type {number}
     * @memberof ExpViewBase
     */
    public split: number = 0.15;

    /**
     * 分隔占位比例(备份)
     *
     * @description 当导航视图关闭时备份比例
     * @type {number}
     * @memberof ExpViewBase
     */
    public backSplit: number = 0;

    /**
     * 快速分组数据
     *
     * @type {*}
     * @memberof ExpViewBase
     */
    public quickGroupData: any;

    /**
     * 是否提交快速分组值
     *
     * @protected
     * @type {boolean}
     * @memberof ExpViewBase
     */
    protected isEmitQuickGroupValue: boolean = false;

72 73 74 75 76 77 78 79 80
    /**
     * 导航视图key属性模式
     *
     * @protected
     * @type {('DEFAULT' | 'VIEWPATH')}
     * @memberof ExpViewBase
     */
    protected keyMode: 'DEFAULT' | 'VIEWPATH' = 'DEFAULT';

81 82 83 84 85 86 87 88
    /**
     * 容器挂载完成
     *
     * @memberof ExpViewBase
     */
    public containerMounted() {
        super.containerMounted();
        this.initSplit();
89 90 91 92 93 94
        if (this.expBarInstance) {
            const ctrlParams = this.expBarInstance.getPSControlParam()?.ctrlParams;
            if (ctrlParams && ctrlParams.KEYMODE) {
                this.keyMode = ctrlParams.KEYMODE.toUpperCase();
            }
        }
95 96 97 98 99 100 101 102 103 104
    }

    /**
     * 初始化分隔值
     *
     * @protected
     * @memberof ExpViewBase
     */
    protected initSplit() {
        const tempSplit = this.$store.getters.getViewSplit(`${this.viewInstance?.codeName}_${this.expBarInstance?.codeName}`);
105
        let split: number = this.split;
106
        if (tempSplit) {
107
            split = Number(tempSplit);
108
        } else {
109 110
            //  上下
            if (this.viewInstance.sideBarLayout === 'TOP') {
111 112
                const height = this.expBarInstance?.height;
                if (height && height > 0) {
113 114 115 116 117 118
                    split = height / (this.$el as any).offsetHeight;
                }
            } else {
                const width = this.expBarInstance?.width;
                if (width && width > 0) {
                    split = width / (this.$el as any).offsetWidth;
119 120
                }
            }
121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139
            this.$store.commit("setViewSplit", { viewUID: `${this.viewInstance?.codeName}_${this.expBarInstance?.codeName}`, viewSplit: split });
        }
        // IVIEW 分隔面板组件监听value为 0.5 时不执行计算逻辑
        this.split = split === 0.5 ? split + 0.0000001 : split;
    }

    /**
     * 获取导航视图key
     *
     * @protected
     * @param {IParams} navContext
     * @return {*} 
     * @memberof ExpViewBase
     */
    protected getNavViewKey(navContext: IParams) {
        if (this.keyMode === 'VIEWPATH') {
            return navContext.viewpath;
        } else {
            return navContext.viewpath + navContext.srfparentkey;
140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197
        }
    }

    /**
     * 处理占位比例变化
     *
     * @protected
     * @memberof ExpViewBase
     */
    protected handleSplitChange() {
        if (this.split) {
            this.$store.commit("setViewSplit", { viewUID: `${this.viewInstance?.codeName}_${this.expBarInstance?.codeName}`, viewSplit: this.split });
        }
    }

    /**
     * 快速分组值变化
     *
     * @param {*} event
     * @memberof ExpViewBase
     */
    public quickGroupValueChange(event: any) {
        if (event) {
            this.quickGroupData = event.data;
            if (this.isEmitQuickGroupValue && this.engine) {
                this.engine.search(event);
            }
        }
        this.isEmitQuickGroupValue = true;
    }

    /**
     * 渲染快速分组
     *
     * @return {*}  {*}
     * @memberof ExpViewBase
     */
    public renderQuickGroup(): any {
        if (!this.viewInstance.enableQuickGroup) {
            return;
        }
        let counterService: any;
        if (this.viewInstance?.getPSAppCounterRef?.()?.id) {
            counterService = Util.findElementByField(this.counterServiceArray, 'id', this.viewInstance?.getPSAppCounterRef?.()?.id)?.service;
        }
        const codeList = this.viewInstance.getQuickGroupPSCodeList?.();
        return <div class="quick-group-container" slot="quickGroupSearch">
            <app-quick-group context={this.context} viewparams={this.viewparams} codeList={codeList} on-valuechange={this.quickGroupValueChange.bind(this)} counterService={counterService}></app-quick-group>
        </div>;
    }

    /**
     * 渲染导航视图
     *
     * @return {*} 
     * @memberof ExpViewBase
     */
    public renderNavView() {
198
        if (this.navItem && this.navItem.data[0] && Object.keys(this.navItem.data[0]).length > 0) {
199 200
            const navContext = this.navItem.srfnavdata ? this.navItem.srfnavdata.context : {};
            const navViewParam = this.navItem.srfnavdata ? this.navItem.srfnavdata.viewparams : {};
201 202 203
            if(this.navItem.srfnavdata && this.navItem.srfnavdata.data){
                Object.assign(navViewParam,{srfnav: this.navItem.srfnavdata.data});
            }
204 205 206 207 208 209 210 211 212 213 214 215 216
            const targetCtrlParam: any = {
                staticProps: {
                    viewDefaultUsage: false,
                    inputState: this.viewState,
                    isNavView: true
                },
                dynamicProps: {
                    viewdata: JSON.stringify(navContext),
                    viewparam: JSON.stringify(navViewParam)
                }
            }
            return this.$createElement('app-view-shell', {
                class: "view-container2",
217
                key: this.getNavViewKey(navContext),
218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268
                props: targetCtrlParam,
                on: {
                    close: (data: any) => {
                        if (this.engine) {
                            this.engine.closeNavView();
                        }
                    },
                    viewNeedRefresh: (data: any, tag: string) => {
                        if (this.engine) {
                            this.engine.handleNavViewRefresh(tag);
                        }
                    }
                }
            });
        }
        return null;
    }

    /**
     * 渲染导航栏
     *
     * @return {*} 
     * @memberof ExpViewBase
     */
    public renderExpBar() {
        let { targetCtrlName, targetCtrlParam, targetCtrlEvent } = this.computeTargetCtrlData(this.expBarInstance);
        return this.$createElement(targetCtrlName, { key: this.expBarInstance.name, props: targetCtrlParam, ref: this.expBarInstance?.name, on: targetCtrlEvent }, [this.renderQuickGroup()]);
    }

    /**
     * 渲染视图主体内容区
     * 
     * @memberof ExpViewBase
     */
    public renderMainContent() {
        return (
            <split
                v-model={this.split}
                class="app-vc-expbar"
                mode={this.viewInstance.sideBarLayout === 'TOP' ? 'vertical' : 'horizontal'}
                on-on-move-end={() => this.handleSplitChange()}>
                <div class={`app-vc-expbar__${this.viewInstance.sideBarLayout === 'TOP' ? 'top' : 'left'}`} slot={this.viewInstance.sideBarLayout === 'TOP' ? 'top' : 'left'}>
                    {this.renderExpBar()}
                </div>
                <div class='app-vc-expbar__body' slot={this.viewInstance.sideBarLayout === 'TOP' ? 'bottom' : 'right'}>
                    {this.renderNavView()}
                </div>
            </split>
        )
    }
}