tab-exp-panel-control-base.tsx 9.2 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 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 124 125 126 127 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 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 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 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 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310
import { IPSControl, IPSTabExpPanel } from '@ibiz/dynamic-model-api';
import { TabExpPanelControlInterface, Util, ViewTool } from 'ibiz-core';
import { Subscription } from 'rxjs';
import { MainControlBase } from './main-control-base';
/**
 * 分页导航面板部件基类
 *
 * @export
 * @class TabExpPanelBase
 * @extends {MainControlBase}
 */
export class TabExpPanelBase extends MainControlBase implements TabExpPanelControlInterface {

    /**
     * 分页导航部件实例对象
     *
     * @type {*}
     * @memberof TabExpPanelBase
     */
    public declare controlInstance: IPSTabExpPanel;

    /**
     * 实体权限服务对象
     *
     * @type 
     * @memberof TabExpPanelBase
     */
    public appAuthService: any;

    /**
     * 是否初始化
     *
     * @returns {any}
     * @memberof TabExpPanelBase
     */
    public isInit: any = {}

    /**
     * 行为参数
     *
     * @public
     * @type {*}
     * @memberof TabExpPanelBase
     */
    public action: any = '';

    /**
     * 当前激活数据
     *
     * @public
     * @type {*}
     * @memberof TabExpPanelBase
     */
    public activeData: any = {};

    /**
     * 分页面板权限标识存储对象
     *
     * @public
     * @type {*}
     * @memberof TabExpPanelBase
     */
    public authResourceObject: any = {};

    /**
     * 被激活的分页面板
     *
     * @type {string}
     * @memberof TabExpPanelBase
     */
    public activiedTabViewPanel: string = '';

    /**
     * 过滤数据
     *
     * @type {*}
     * @memberof TabExpPanelBase
     */
    public filterData: any = {};

    /**
     * @description 分页导航部件事件
     * @type {(Subscription | undefined)}
     * @memberof TabExpPanelBase
     */
    public tabExpControlEvent: Subscription | undefined;

    /**
     * 部件模型数据初始化实例
     *
     * @param {*} [args]
     * @memberof TabExpPanelBase
     */
    public async ctrlModelInit(args?: any) {
        await super.ctrlModelInit();
        const allControls: IPSControl[] = this.controlInstance.getPSControls() as IPSControl[];
        if (allControls.length > 0) {
            this.activiedTabViewPanel = allControls[0].name;
        }
    }

    /**
     * 执行created后的逻辑
     *
     *  @memberof TabExpPanelBase
     */
    public ctrlInit() {
        //设置分页导航srfparentdename和srfparentkey
        if (this.context[this.appDeCodeName.toLowerCase()]) {
            Object.assign(this.context, { srfparentdename: this.appDeCodeName.toLowerCase(), srfparentdemapname: this.deName, srfparentkey: this.context[this.appDeCodeName.toLowerCase()] })
        }
        if (this.viewState) {
            this.tabExpControlEvent = this.viewState.subscribe(({ tag, action, data }: { tag: string, action: string, data: any }) => {
                if (!Object.is(tag, this.name)) {
                    return;
                }
                if (Object.is(action, 'changeActivedTab')) {
                    this.tabPanelClick(data);
                }
                if (Object.is(action, 'search')) {
                    this.action = action;
                    this.filterData = data;
                    this.viewState.next({ tag: this.activiedTabViewPanel, action: 'search', data: data });
                    return;
                }
                if (Object.is(action, 'loadmodel')) {
                    this.activeData = data;
                    this.computedAuthPanel(data);
                } else {
                    this.action = action;
                    this.viewState.next({ tag: this.activiedTabViewPanel, action: action, data: data });
                    this.$forceUpdate();
                }
            });
        }
    }

    /**
     * 部件挂载
     *
     *  @memberof TabExpPanelBase
     */
    public ctrlMounted() {
        super.ctrlMounted();
        if (this.viewparams && (this.viewparams.srftabactivate || this.viewparams.srfnavtag)) {
            const activate = this.viewparams.srftabactivate?.toLowerCase() || this.viewparams.srfnavtag?.toLowerCase();
            if (activate && this.isInit[activate] !== undefined) {
                for (const key in this.isInit) {
                    if (this.isInit.hasOwnProperty(key)) {
                        this.isInit[key] = false;
                    }
                }
                this.$nextTick(() => {
                    this.tabPanelClick(activate);
                });
            }
        }
        this.$nextTick(() => {
            this.ctrlEvent({
                controlname: this.controlInstance.name, action: 'tabexppanelIsMounted', data: {
                    activiedTabViewPanel: this.activiedTabViewPanel,
                    authResourceObject: this.authResourceObject
                }
            })
        })
    }

    /**
     * 分页视图面板数据变更
     *
     * @memberof TabExpPanelBase
     */
    public tabViewPanelDatasChange() {
        this.counterRefresh();
    }

    /**
     * 分页面板选中
     *
     * @param {*} $event 选中分页
     * @returns
     * @memberof TabExpPanelBase
     */
    public tabPanelClick($event: any) {
        if (!$event || Object.is(this.activiedTabViewPanel, $event)) {
            return;
        }
        this.isInit = [];
        this.isInit[$event] = true;
        if (!this.viewState) {
            return;
        }
        this.handleCtrlEvents('onselectionchange', { action: 'viewPanelIsChange', data: $event }).then((res: boolean) => {
            if (res) {
                this.activiedTabViewPanel = $event;
                this.ctrlEvent({ controlname: this.controlInstance.name, action: 'viewPanelIsChange', data: this.activiedTabViewPanel });
                this.viewState.next({ tag: this.activiedTabViewPanel, action: this.action, data: this.activeData });
            }
        })
    }

    /**
     * 部件事件
     * @param ctrl 部件 
     * @param action  行为
     * @param data 数据
     * 
     * @memberof TabExpPanelBase
     */
    public onCtrlEvent(controlname: string, action: string, data: any) {
        if (Object.is(controlname, 'tabviewpanel') && action == 'viewpanelDatasChange') {
            this.tabViewPanelDatasChange();
        } else {
            super.onCtrlEvent(controlname, action, data);
        }
    }

    /**
     * 初始化解析分页导航面板绘制参数
     *
     * @memberof TabExpPanelBase
     */
    public initRenderOptions() {
        super.initRenderOptions();
        const allControls: IPSControl[] = this.controlInstance.getPSControls() as IPSControl[];
        this.authResourceObject = [];
        allControls.forEach((item: any, index: number) => {
            this.authResourceObject[item.name] = {
                resourcetag: "",
                visabled: true,
                disabled: false
            }
            this.isInit[item.name] = index === 0 ? true : false;
        });
    }

    /**
     * 获取多项数据
     *
     * @returns {any[]}
     * @memberof TabExpPanelBase
     */
    public getDatas(): any[] {
        return [];
    }

    /**
     * 获取单项数据
     *
     * @returns {*}
     * @memberof TabExpPanelBase
     */
    public getData(): any {
        return null;
    }

    /**
     * 计算分页面板权限
     *
     * @memberof TabExpPanelBase
     */
    public computedAuthPanel(data: any) {
        const _this: any = this;
        if (!data || Object.keys(data).length === 0) {
            return;
        }
        if (this.authResourceObject && Object.keys(this.authResourceObject).length > 0) {
            Object.keys(this.authResourceObject).forEach((key: string) => {
                if (this.authResourceObject[key] && this.authResourceObject[key]['dataaccaction']) {
                    let tempUIAction: any = Util.deepCopy(this.authResourceObject[key]);
                    ViewTool.calcActionItemAuthState(data, [tempUIAction], _this.appUIService);
                    this.authResourceObject[key].visabled = this.computedPanelWithResource(key, tempUIAction.visabled);
                    this.authResourceObject[key].disabled = this.computedPanelWithResource(key, tempUIAction.disabled);
                }
            })
            const keys: any = Object.keys(this.authResourceObject);
            for (let i = 0; i < keys.length; i++) {
                if (this.authResourceObject[keys[i]].visabled) {
                    // this.tabPanelClick(keys[i]);
                    return;
                }
            }
        }
    }

    /**
     * 合入统一资源权限
     *
     * @memberof TabExpPanelBase
     */
    public computedPanelWithResource(name: string, mainState: boolean) {
        if (!this.$store.getters['authresource/getEnablePermissionValid'])
            return mainState === false ? false : true;
        if (!this.authResourceObject[name])
            return mainState === false ? false : true;
        const resourceAuth: boolean = this.appAuthService.getResourcePermission(this.authResourceObject[name]['resourcetag']);
        return !resourceAuth ? false : mainState ? true : false;
    }

    /**
     * @description 部件销毁
     * @memberof TabExpPanelBase
     */
    public ctrlDestroyed(){
        super.ctrlDestroyed()
        if(this.tabExpControlEvent){
            this.tabExpControlEvent.unsubscribe();
        }
    }
}