app-panel-model.ts 1.3 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
/**
 * AppPanelModel 部件模型
 *
 * @export
 * @class AppPanelModel
 */
export class AppPanelModel {

    /**
    * 面板实例对象
    *
    * @memberof AppPanelModel
    */
   public PanelInstance:any;

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


  /**
    * 获取name找到对应field
    *
    * @returns {any[]}
    * @memberof AppPanelModel
    */
   public findField(arr:Array<any>, name:string):any {
    let _result = null;
    for (let i = 0; i < arr.length; i++) {
      if (arr[i].name == name) return arr[i];
      if (arr[i].getPSPanelItems) _result = this.findField(arr[i].getPSPanelItems, name)
      if (_result != null) return _result;
    }
    return _result
  }

  /**
    * 获取数据项集合
    *
    * @returns {any[]}
    * @memberof AppPanelModel
    */
  public getDataItems(): any[] {
    let arr:any = [];
    this.PanelInstance.getAllPSPanelFields.forEach((datafield:any) => {
      let field:any = this.findField(this.PanelInstance.getRootPSPanelItems,datafield.id);
      let obj:any = {};
      obj.name = field?.name.toLowerCase();
      obj.prop = field?.viewFieldName?.toLowerCase();
      arr.push(obj);
    });
    return arr
  }
}