pickup-tree-view-engine.ts 2.3 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
import { Util } from '../utils';
import { TreeViewEngine } from './tree-view-engine';

/**
 * 实体选择树视图(部件视图)界面引擎
 *
 * @export
 * @class PickupTreeViewEngine
 * @extends {TreeViewEngine}
 */
export  class PickupTreeViewEngine extends TreeViewEngine {

    /**
     * 选中处理
     *
     * @param {any[]} args
     * @memberof PickupTreeViewEngine
     */
19
    public selectionChange(args: any[]): void {
20
        if (this.view) {
21 22 23
            const selections = args.map((item: any) => item.curData || item);
            this.view.viewSelections =  [...selections];
            this.emitViewEvent('viewdataschange', selections);
24 25 26 27 28 29 30 31 32 33 34 35
        }
    }

    /**
     * 双击选中激活数据
     *
     * @param {string} ctrlName
     * @param {string} eventName
     * @param {*} args
     * @memberof PickupTreeViewEngine
     */
    public onCtrlEvent(ctrlName: string, eventName: string, args: any): void {
36 37 38 39 40 41
        if (Object.is(ctrlName, 'tree') && Object.is(eventName, 'nodedblclick')) {
            const selections = args.map((item: any) => item.curData || item);
            this.emitViewEvent('viewdatasactivated', selections);
            return;
        }
        super.onCtrlEvent(ctrlName, eventName, args);
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
    }

    /**
     * 父数据参数模式
     *
     * @param {{ tag: string, action: string, viewdata: any }} { tag, action, viewdata }
     * @memberof PickupTreeViewEngine
     */
     public setViewState2({ tag, action, viewdata }: { tag: string, action: string, viewdata: any }): void {
        if (Util.isExistAndNotEmpty(this.view.context.query)) {
            this.view.viewState.next({ tag: tag, action: 'filter', data: { srfnodefilter: this.view.context.query } });
        } else {
            this.view.viewState.next({ tag: tag, action: action, data: viewdata });
        }
    }

    /**
     * 选择全部
     *
     * @param {any[]} [datas=[]]
     * @memberof PickupTreeViewEngine
     */
    public selectAll(datas: any[] = []) {
        const tree = this.getMDCtrl();
        if (tree && tree.$refs[tree.name]) {
            const keys: string[] = [];
            if (datas && datas.length) {
                datas.forEach((data: any) => {
                    keys.push(data.id);
                })
            }
            tree.$refs[tree.name].setCheckedKeys(keys);
        }
    }
}