app-grid-model.ts 4.8 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
import { IPSAppDataEntity, IPSAppDEField, IPSAppDEGridView, IPSAppDERS, IPSDEFormItem, IPSDEGrid, IPSDEGridDataItem, IPSDEGridEditItem, IPSDESearchForm, IPSEditor } from '@ibiz/dynamic-model-api';
import { DataTypes, ModelTool } from 'ibiz-core';

export class AppGridModel {

  /**
  * 表格实例对象
  *
  * @memberof AppGridModel
  */
  public gridInstance !: IPSDEGrid;

  /**
   * Creates an instance of AppGridModel.
   * 
   * @param {*} [opts={}]
   * @memberof AppGridModel
   */
  constructor(opts: any) {
    this.gridInstance = opts;
  }

  /**
* TODO 是否是实体数据导出(暂时未使用)
*
* @returns {any}
* @memberof AppGridModel
*/
  public isDEExport: boolean = false;

  /**
  * 获取数据项集合
  *
  * @returns {any[]}
  * @memberof AppGridModel
  */
  public getDataItems(): any[] {
    let modelArray: any[] = [
      {
        name: 'size',
        prop: 'size',
        dataType: 'QUERYPARAM'
      },
      {
        name: 'offset',
        prop: 'offset',
        dataType: 'QUERYPARAM'
      },
      {
        name: 'query',
        prop: 'query',
        dataType: 'QUERYPARAM'
      },
      {
        name: 'filter',
        prop: 'filter',
        dataType: 'QUERYPARAM'
      },
      {
        name: 'page',
        prop: 'page',
        dataType: 'QUERYPARAM'
      },
      {
        name: 'sort',
        prop: 'sort',
        dataType: 'QUERYPARAM'
      },
      {
        name: 'srfparentdata',
        prop: 'srfparentdata',
        dataType: 'QUERYPARAM'
      },
      // 前端新增修改标识,新增为"0",修改为"1"或未设值
      {
        name: 'srffrontuf',
        prop: 'srffrontuf',
        dataType: 'TEXT',
      },
      // 预置工作流数据字段
      {
        name: 'srfprocessdefinitionkey',
        prop: 'srfprocessdefinitionkey',
        dataType: 'TEXT'
      },
      {
        name: 'srftaskdefinitionkey',
        prop: 'srftaskdefinitionkey',
        dataType: 'TEXT'
      },
      {
        name: 'param09',
        prop: 'param09',
        dataType: 'TEXT'
      },
      {
        name: 'srftaskid',
        prop: 'srftaskid',
        dataType: 'TEXT'
      }
    ]
    const appDataEntity: IPSAppDataEntity = this.gridInstance.getPSAppDataEntity() as IPSAppDataEntity;
    const allDataItems: Array<IPSDEGridDataItem> = this.gridInstance.getPSDEGridDataItems() || [];
    if (allDataItems.length > 0) {
      allDataItems.forEach((item: IPSDEGridDataItem) => {
        let temp: any = {
          name: item.name.toLowerCase()
        };
        if (item.customCode) {
          temp.customCode = true;
          temp.scriptCode = item.scriptCode;
        } else {
          const field: IPSAppDEField | null = item.getPSAppDEField();
          if (field) {
            temp.prop = field.codeName?.toLowerCase();
            temp.dataType = DataTypes.toString(field.stdDataType);
          }
          const editItem: IPSDEGridEditItem = ModelTool.getGridItemByCodeName(item.name, this.gridInstance) as IPSDEGridEditItem;
          if (editItem) {
            temp.isEditable = (editItem.getPSEditor() as IPSEditor).editable;
          }
        }
        modelArray.push(temp);
      })
    }
    //关联主实体的主键
    const minorAppDERSs: Array<IPSAppDERS> = appDataEntity?.getMinorPSAppDERSs() || [];
    if (appDataEntity && appDataEntity.major == false && minorAppDERSs.length > 0) {
      minorAppDERSs.forEach((minorAppDERSs: IPSAppDERS) => {
        const majorAppDataEntity = minorAppDERSs.getMajorPSAppDataEntity();
        if (majorAppDataEntity) {
          let obj: any = {
            name: majorAppDataEntity.codeName?.toLowerCase(),
            dataType: 'FRONTKEY',
          };
          if (minorAppDERSs.getParentPSAppDEField()) {
            obj.prop = minorAppDERSs.getParentPSAppDEField()?.codeName.toLowerCase();
          } else {
            obj.prop = (ModelTool.getAppEntityKeyField(majorAppDataEntity) as IPSAppDEField)?.codeName || '';
          }
          modelArray.push(obj);
        }
      });
    }
145
    const searchFormInstance: IPSDESearchForm = ModelTool.findPSControlByType("SEARCHFORM", (this.gridInstance.getParentPSModelObject() as IPSAppDEGridView)?.getPSControls?.() || []);
146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164
    if (searchFormInstance) {
      (searchFormInstance.getPSDEFormItems?.() || []).forEach((formItem: IPSDEFormItem) => {
        let temp: any = { name: formItem.id, prop: formItem.id };
        if (formItem.getPSAppDEField?.()) {
          temp.dataType = 'QUERYPARAM';
        }
        modelArray.push(temp);
      });
    }

    // 界面主键标识
    const keyField: string = (ModelTool.getAppEntityKeyField(this.gridInstance?.getPSAppDataEntity() as IPSAppDataEntity) as IPSAppDEField)?.codeName || '';
    modelArray.push({
      name: appDataEntity?.codeName.toLowerCase(),
      prop: keyField.toLowerCase(),
    });
    return modelArray;
  }
}