| import { Types } from '@business/enum/types.enum'; | 
|   | 
|   | 
| export interface Column { | 
|    text?: string; | 
|    name?: string; | 
|    width?: string; | 
|    sort?: string; | 
|    isSort?: boolean; | 
|    type?: DataType; | 
|    format?: (value: any, col: Column, row: any) => string; | 
| } | 
| export interface DataType { | 
|     name: Types; | 
|     format?: any; | 
| } | 
| // 作为http来回传递参数 | 
| export interface PageBean { | 
|     pageIndex?: number ; // 页码 | 
|     pageSize?: number ; // 一页多少条 | 
|     total?: number; | 
|     data?: any[]; | 
|     queryParams?: string; | 
|     orderByClause?: string; | 
|     getOrderByClause ?(): string; | 
| } | 
| export class Grid<T> implements PageBean { | 
|     getOrderByClause(): string { | 
|         const orderby = this.sorts.map( (fn) => { | 
|           return this.columns.find( (col: Column) => { | 
|                  return fn === col.name; | 
|            } ); | 
|         }).map( (col: Column) => { | 
|             const sort = col.sort.startsWith('asc') ? 'asc' : 'desc' ; | 
|             return col.name + '||' + sort; | 
|         }).join('|||'); | 
|         return  encodeURI(orderby); | 
|     } | 
|     title = ''; | 
|     pageIndex = 0; // 页码 | 
|     pageSize = 10; // 每页几行数据 | 
|     data: T[] = []; | 
|     total = 0; | 
|     queryParams = '';    | 
|     pages = 0; // 总页数 | 
|     size  = 0;  // 当前页数据条数 | 
|     sorts?: any[] = []; | 
|     loading = false; | 
|     indeterminate = false; | 
|     allChecked = false; | 
|     selectedIndexs?: number[] = []; // 被选中序列号 | 
|     columns?: Column[] = [];     | 
|   | 
|     checkAll(value: boolean) { | 
|         this.data.forEach( | 
|             row => {row['checked'] = value; } | 
|         );  | 
|         this.refreshStatus(); | 
|     } | 
|     getData(): any [] { | 
|         return this.data; | 
|     } | 
|     initData(pageData: {data?: any[], total?: number}) { | 
|         if ( pageData != null && pageData.data != null) { | 
|             let index = 0; | 
|             this.data = pageData.data.map(row => { | 
|                 row['index'] = index++; | 
|                 return row; | 
|             }); | 
|             this.total = pageData.total; | 
|         } | 
|     } | 
|     refreshStatus() { | 
|         const data = this.data; | 
|         const allChecked =   data.every(value => value['checked']); | 
|         const allUnChecked = data.every(value => !value['checked']); | 
|         this.allChecked = allChecked; | 
|         this.indeterminate = (!allChecked) && (!allUnChecked); | 
|         this.selectedIndexs = data.filter(value => value['checked']).map( | 
|             row => { | 
|                return row['index'] != null ? row['index'] : 0; | 
|             } | 
|         ); | 
|         this.selectedIndexs = this.selectedIndexs == null ? [] : this.selectedIndexs; | 
|       } | 
|     constructor(config: object) { | 
|         if (config != null) { | 
|             const keys = Object.getOwnPropertyNames(config); | 
|             for (const index in keys) { | 
|                 const key = keys[index]; | 
|                 if (this[key] != null) { | 
|                     this[key] = config[key]; | 
|                 }             | 
|             } | 
|         } | 
|     } | 
|     public setColumns(obj: Object) { | 
|         this.columns = this.objectToArray(obj); | 
|     } | 
|     private objectToArray(obj: Object): any[] { | 
|         const arr = []; | 
|         const keys = Object.getOwnPropertyNames(obj); | 
|         for (const index in keys) { | 
|             const key = keys[index]; | 
|             const item = obj[key]; | 
|             if ( item['name'] == null) { | 
|               item['name'] = key; | 
|             } | 
|             arr.push(item); | 
|         } | 
|         return arr; | 
|     } | 
| } | 
| export interface ResultBean<T>{ | 
|   code?: number; | 
|   data?: T; | 
|   message?: string; | 
| } |