import { Component, ViewChild, Input, EventEmitter, Output, OnInit, OnChanges, ViewEncapsulation, LOCALE_ID, Inject, Injector } from '@angular/core'; import { TreeTableComponent, TreeNode } from '@farris/ui-treetable'; import { FilterExpression, ExpressionItem } from '../filter-expression-entity'; import { VarEntity } from '@gsp-svc/expression'; import { Schema } from '@gsp-svc/expression'; import { GspCommonDataType } from '@gsp-bef/gsp-cm-metadata'; import { InjectedEntity } from '@gsp-svc/expression'; import { ExpressTypeEnum, RelationTypeEnum, CompareTypeEnum } from '../typeinfo'; import { ExpressionService } from '@gsp-svc/expression'; import { FilterProperty, PropertyDataType } from '../property-entity'; import { FieldType } from '../field-type'; import { FilterInjectedEntity } from '../injected-entity'; import { PropertyAdapter } from '../property-adapter'; import { FilterEntitySchema, FilterEntityType } from '../schema'; import { GSPCommonObject } from '@gsp-bef/gsp-cm-metadata'; import { Adapter } from '../adapter'; import { NotifyService } from '@farris/ui-notify'; import { FilterConditionLocalePipe } from '../filter-condition-locale.pipe'; import { NewSchema } from '../NewSchema'; @Component({ selector: 'app-filter-expression', templateUrl: './filter-expression.component.html', styleUrls: ['./filter-expression.component.css'], providers: [ExpressionService, PropertyAdapter, NotifyService], encapsulation: ViewEncapsulation.None }) /** * 过滤条件面板逻辑类 */ export class FilterExpressionComponent implements OnChanges { localePipe: FilterConditionLocalePipe; constructor(private expr: ExpressionService, private propertyAdapter: PropertyAdapter, private notifyservice: NotifyService, private injector: Injector, @Inject(LOCALE_ID) localeId: string) { this.notifyservice = this.expr.getInjector().get(NotifyService); this.localePipe = new FilterConditionLocalePipe(localeId); } treeDataTemp: TreeNode[] //获得树列表组件柄 @ViewChild('tt') tt: TreeTableComponent; //预置计算表达式上下文实体 @Input() contextEntity: VarEntity[] = []; //预置计算默认表达式显示 @Input() expressionText: string = ""; //预置计算表达式中的schema @Input() expressionSchema: Array<{ name: string, schema: Schema }> = []; //预置计算表达式中的NewSchema @Input() expressionNewSchema: Array<{ name: string, schema: NewSchema }> = []; //预置计算表达式中的注入实体 @Input() expressionInjectedEntities: InjectedEntity[] = []; //预置计算表达式cdt集 @Input() expressionCDT: GspCommonDataType[] = []; //预置属性列表 @Input() propertyList: Array<{ text: string, value: string, propertyFieldType: PropertyDataType }> = []; //预置过滤表达式串 @Input() filterExpressionString: string = null; //预置schema名 @Input() schemaName: string; //预置过滤表达式schema @Input() schema: FilterEntitySchema; //===========================分割线之NewSchema=============================== @Input() newSchema: NewSchema; //schema存储结构 filterNewSchemaMap = new Map(); //========================================================================== //过滤表达式注入实体 @Input() injectedEntity: FilterInjectedEntity; //注入CO @Input() gspCommonObject: GSPCommonObject; @Input() disabled: boolean = false; //内部属性列表使用 propertyListInner: Array = []; private NUMBER_PREFIX = "FilterExpression_"; private num: number = 1; //propertyListInner的id //操作比较符集 public operators = []; public stringOperators = []; public NumberOperators = []; //关系集 public relations = []; //表达式类型集 public expressTypes = []; public filterExpression: FilterExpression; //树形结构节点实体集 public nodeTemp: TreeNode[]; defaultSelectGroup: string; defaultSelectItem: string; //操作比较符默认显示值 public defaultOperatorText: string; //表达式类型默认显示值 public defaultExpressTypeText; public displayPopup: boolean = false; // public defaultOperator: { text: string, value: string } = { text: null, value: null }; //表达式类型默认显示值 // public defaultExpressType: { text: string, value: string } = { text: null, value: null }; //预置过滤表达式实体 public filterExpressionPre: FilterExpression; //检查过滤条件实体是否完整正确 public checkFilterStruc: boolean = true; //schema存储结构 filterSchemaMap = new Map(); adapter: Adapter = new Adapter(); treeData: TreeNode[] = []; columnWidth = ["30%", "20%", "20%", "20%", "10%"]; //消息提示 private notifies = {}; //展示添加多个按钮 showAddTypes: boolean = false; cols: any[]; //初始化,复制treeData值,treeDataTemp用于转换为FilterExpression实体 ngOnChanges(): void { //并且树形表绑定的显示的列 this.cols = [ { field: 'item', title: this.localePipe.transform("Item"), width: 240 }, { field: 'operator', title: this.localePipe.transform("Operator"), width: 100 }, { field: 'expressType', title: this.localePipe.transform("ExpressType"), width: 100 }, { field: 'value', title: this.localePipe.transform("Value"), width: 200 }, { field: 'operation', title: this.localePipe.transform("Operation"), width: 200 }]; this.propertyListInner = []; this.treeDataTemp = this.treeData; //=================================分割线之NewSchema==================================== //注入NewSchema if (this.schemaName && this.newSchema) { this.addNewSchema(this.schemaName, this.newSchema); //注入co if (this.gspCommonObject) { let newSchema: NewSchema; //若schemaMap中存在CO的schema if ((this.filterNewSchemaMap.get("CommonObject"))) { newSchema = this.filterNewSchemaMap.get("CommonObject"); } else { newSchema = new NewSchema(); } //将每一个CO转化为schema内部结构中的entityType let entityTypes = this.adapter.convertCOOfNewSchema(this.gspCommonObject); if ((entityTypes) && entityTypes.length != 0) { entityTypes.forEach(entityType => { if (newSchema.entityTypes.find(x => x.code == entityType.code) == null) { newSchema.entityTypes.push(entityType); } }); } //将合并后的schema放入内部上下文实体中 this.addNewSchema("CommonObject", newSchema); } //添加属性列表 this.propertyList.forEach(property => { let propertyInner = { id: this.NUMBER_PREFIX + this.num++, value: property.value, text: property.text, propertyDataType: property.propertyFieldType, parentItem: null }; this.propertyListInner.push(propertyInner); }); if ((this.injectedEntity)) { this.propertyAdapter.adapterOfNewSchema(this.injectedEntity, this.filterNewSchemaMap).forEach(element => { this.propertyListInner.push(element); }); } } else { //===========================================旧Schema========================================== if (this.schemaName != null && (this.schema)) { this.addSchema(this.schemaName, this.schema); } if ((this.gspCommonObject)) { let schema: FilterEntitySchema; //若schemaMap中存在CO的schema if ((this.filterSchemaMap.get("CommonObject"))) { schema = this.filterSchemaMap.get("CommonObject"); } else schema = new FilterEntitySchema(); //将每一个CO转化为schema内部结构中的entityType let entityTypes = this.adapter.convertCO(this.gspCommonObject); if ((entityTypes) && entityTypes.length != 0) { entityTypes.forEach(entityType => { if (schema.entityTypes.find(x => x.name == entityType.name) == null) { schema.entityTypes.push(entityType); } }); } //将合并后的schema放入内部上下文实体中 this.addSchema("CommonObject", schema); } this.propertyList.forEach(property => { let propertyInner = { id: this.NUMBER_PREFIX + this.num++, text: property.text, propertyDataType: property.propertyFieldType, value: property.value, parentItem: null }; this.propertyListInner.push(propertyInner); }); if ((this.injectedEntity)) { this.propertyAdapter.adapter(this.injectedEntity, this.filterSchemaMap).forEach(element => { this.propertyListInner.push(element); }); } } this.defaultExpressTypeText = this.localePipe.transform("Value"); this.defaultSelectGroup = this.localePipe.transform('And'); this.defaultSelectItem = this.localePipe.transform("SelectItem"); this.defaultOperatorText = this.localePipe.transform("GreaterThan"); this.notifies = { 1: { type: 'success', msg: this.localePipe.transform("Success") }, 2: { type: 'warning', msg: this.localePipe.transform("Warning_SelectRelation") }, 3: { type: 'warning', msg: this.localePipe.transform("Warning_ContainsFilters") }, 4: { type: 'warning', msg: this.localePipe.transform("Warning_ConditionsComplete") }, 5: { type: 'warning', msg: this.localePipe.transform("Warning_NumericMatch") }, 6: { type: 'warning', msg: this.localePipe.transform("Warning_DeteleFirst") } }; this.expressTypes = [ { id: this.localePipe.transform("Value") }, { id: this.localePipe.transform("Expression") } ]; this.relations = [ { id: this.localePipe.transform("And") }, { id: this.localePipe.transform("Or") }, ]; this.NumberOperators = [ { id: this.localePipe.transform("GreaterThan") }, { id: this.localePipe.transform("GreaterThanOrEqual") }, { id: this.localePipe.transform("LessThan") }, { id: this.localePipe.transform("LessThanOrEqual") }, { id: this.localePipe.transform("Equal") }, { id: this.localePipe.transform("NotEqual") }, { id: this.localePipe.transform("IsNull") }, { id: this.localePipe.transform("IsNotNull") }, ]; this.stringOperators = [ { id: this.localePipe.transform("Equal") }, { id: this.localePipe.transform("NotEqual") }, { id: this.localePipe.transform("Contains") }, { id: this.localePipe.transform("NotContains") }, { id: this.localePipe.transform("StartsWith") }, { id: this.localePipe.transform("EndsWith") }, { id: this.localePipe.transform("NotStartsWith") }, { id: this.localePipe.transform("NotEndsWith") }, { id: this.localePipe.transform("IsNull") }, { id: this.localePipe.transform("IsNotNull") }, ]; this.operators = [ { id: this.localePipe.transform("GreaterThan") }, { id: this.localePipe.transform("GreaterThanOrEqual") }, { id: this.localePipe.transform("LessThan") }, { id: this.localePipe.transform("LessThanOrEqual") }, { id: this.localePipe.transform("Equal") }, { id: this.localePipe.transform("NotEqual") }, { id: this.localePipe.transform("Contains") }, { id: this.localePipe.transform("NotContains") }, { id: this.localePipe.transform("StartsWith") }, { id: this.localePipe.transform("EndsWith") }, { id: this.localePipe.transform("NotStartsWith") }, { id: this.localePipe.transform("NotEndsWith") }, { id: this.localePipe.transform("IsNull") }, { id: this.localePipe.transform("IsNotNull") }, { id: this.localePipe.transform("In") }, { id: this.localePipe.transform("NotIn") }, ]; this.onCancel(); } //=================添加NewSchema===================== /** * @description 添加NewSchema到Map中 * @param name schema名称 * @param filterNewSchema 注入的统一结构NewSchema */ addNewSchema(name: string, filterNewSchema: NewSchema) { this.filterNewSchemaMap.set(name, filterNewSchema); } //================================================== /** * 添加schema入Map * @param name schema名 * @param filterSchema */ addSchema(name: string, filterSchema: FilterEntitySchema) { this.filterSchemaMap.set(name, filterSchema); } /** * 树形表中节点选择触发函数 * @param $event 所选节点信息 */ nodeSelected($event) { //隐藏掉所有的节点选择编辑框,包括子节点的 this.hideNodeEditor(this.treeData); //将所选节点比较项、表达式类型项、值编辑框显示,并将所选对应数据赋给默认项进行显示 this.defaultOperatorText = $event.node.data.operator; this.defaultExpressTypeText = $event.node.data.expressType; if ($event.node.data.item == this.localePipe.transform('And') || $event.node.data.item == this.localePipe.transform('Or')) { this.defaultSelectGroup = $event.node.data.item; } else if ($event.node.data.item !== this.localePipe.transform("SelectProperty")) { let properties = this.propertyListInner.filter(x => x.text == $event.node.data.item); this.defaultSelectItem = properties[0].id; } else if ($event.node.data.item == this.localePipe.transform("SelectProperty")) { this.defaultSelectItem = $event.node.data.item; } this.treeData = [...this.treeData]; $event.node.data.displayOperator = true; $event.node.data.displayExpressType = true; $event.node.data.displayValue = true; $event.node.data.displaySelect = true; }; /** * 隐藏掉所有的节点选择编辑框,包括子节点的 * @param treeNodes 树形表绑定结构 */ hideNodeEditor(treeNodes: TreeNode[]) { treeNodes.forEach(element => { element.data.displayOperator = false; element.data.displayExpressType = false; element.data.displayValue = false; element.data.displaySelect = false; //若有子节点,则将其子节点的编辑选择框隐藏 if ((element.children) && element.children.length != 0) { this.hideNodeEditor(element.children); } }); }; //节点未选择函数 nodeUnSelect() { console.log("nodeUnselect"); }; /*** * 选择逻辑集时 */ selectGroup($event) { this.propertyNodeOperate($event, this.treeData, FieldType.Group); } /*** * 选择项时 */ selectItem($event) { this.propertyNodeOperate($event, this.treeData, FieldType.Item); } /** * 选择比较操作符时 * @param $event 比较操作项信息 */ selectOperator($event) { this.propertyNodeOperate($event, this.treeData, FieldType.Operation); }; /** * 选择值类型时 * @param $event 值类型项信息 */ selectExpressType($event) { this.propertyNodeOperate($event, this.treeData, FieldType.Valuetype); }; /** * 选择结束后隐藏该字段选择框 * @param treeNodes 树形表绑定结构 * @param fieldType 所选字段 */ hideFieldEditor(treeNodes: TreeNode[], fieldType: FieldType) { //找到所操作的节点,根据所选择的字段将对应选择编辑框隐藏 treeNodes.forEach(treeNode => { if (this.tt.isSelected(treeNode)) { switch (fieldType) { case FieldType.Item: treeNode.data.displaySelect = false; break; case FieldType.Operation: treeNode.data.displayOperator = false; break; case FieldType.Valuetype: treeNode.data.displayExpressType = false; break; } return; } //若未找到所选节点,则找其子节点 else if ((treeNode.children) && treeNode.children.length != 0) { this.hideFieldEditor(treeNode.children, fieldType); } }); } /** * 打开计算表达式编辑器 */ openExpressEditor() { let that = this; //添加预置上下文变量 if (this.contextEntity && this.contextEntity.length != 0) { this.contextEntity.forEach(element => { this.expr.addContext(element); }); } //添加预置表达式文本 let selectNode = this.isSelected(this.treeData); if ((selectNode) && (selectNode.data.value != "") && (selectNode.data.value != null)) { this.expr.addExpressionText(selectNode.data.value); } else this.expr.addExpressionText(this.expressionText); //添加注入实体 this.expressionInjectedEntities.forEach(element => { this.expr.addInjectedEntity(element.name, element.schemaName, element.injectedName, element.injectedType); }); //添加CDT this.expr.addCDT(this.expressionCDT); //添加schema this.expressionSchema.forEach(element => { this.expr.addSchema(element.name, element.schema); }); this.expressionNewSchema.forEach(element => { this.expr.addNewSchema(element.name, element.schema); }); //打开表达式编辑器并返回编辑结果 this.expr.buildExpression().then(info => { let expressInfo: any = info; this.displayExpressResult(that.treeData, expressInfo); }); } /** * 选中节点选择 * @param treeNodes 关系组 */ isSelected(treeNodes: TreeNode[]): any { let treeNode: TreeNode; for (var i = 0; i < treeNodes.length; i++) { if (this.tt.isSelected(treeNodes[i])) { treeNode = treeNodes[i]; break; } //若在该层节点中未找到所选节点,则找其子节点 else if ((treeNodes[i].children) && treeNodes[i].children.length != 0) { treeNode = this.isSelected(treeNodes[i].children); if ((treeNode)) break; } } return treeNode; } /** * 将计算表达式结果展示到对应节点 * @param treeNodes 树表绑定结构 * @param expressInfo 计算表达式得到结果 */ displayExpressResult(treeNodes: TreeNode[], expressInfo: string) { //找到所选节点实体,并将计算表达式所得结果赋给对应属性进行显示 treeNodes.forEach(treeNode => { if (this.tt.isSelected(treeNode)) { treeNode.data.value = expressInfo; return; } //若在该层节点中未找到所选节点,则找其子节点 else if ((treeNode.children) && treeNode.children.length != 0) { this.displayExpressResult(treeNode.children, expressInfo); } //若仍未找到,则不进行任何操作 }); } /** * 选择属性节点操作 * 对新添加的属性节点进行逻辑处理 * @param event 点击事件 * @param treeNodes 树形表绑定结构 * @param fieldType 节点类型 */ propertyNodeOperate(event: any, treeNodes: TreeNode[], fieldType: FieldType) { treeNodes.forEach(treenode => { if (this.tt.isSelected(treenode)) { //对所选节点进行赋值操作 switch (fieldType) { case FieldType.Group: { treenode.data.item = event.data.id; this.defaultSelectGroup = event.data.id; } break; case FieldType.Item: { treenode.data.item = event.data.text; this.defaultSelectItem = event.data.id; treenode.data.parentItem = event.data.parentItem; treenode.data.propertyDataType = event.data.propertyDataType; } break; case FieldType.Operation: { treenode.data.operator = event.data.id; this.defaultOperatorText = event.data.id; } break; case FieldType.Valuetype: { treenode.data.expressType = event.data.id; this.defaultExpressTypeText = event.data.id; } break; } return; } //否则对其子节点进行赋值操作 else if ((treenode.children) && treenode.children.length != 0) { this.propertyNodeOperate(event, treenode.children, fieldType); } }); } /** * 重置(外部调用) * 重置为初始状态 */ onCancel() { if (this.filterExpressionString == null || this.filterExpressionString == "") { this.treeData = [ { data: { "id": 1, //树形结构中每个节点的id "item": this.localePipe.transform('And'), //属性项 "propertyDataType": null, //属性数据类型 "operator": null, //操作比较符 "expressType": null, //表达式类型 "value": null, //值 "displaySelect": false, //选择项显示 "displayOperator": false, //操作符项显示 "displayExpressType": false,//表达式类型显示 "displayValue": false, //值显示 "parentItem": null //父项 }, children: [], //子节点集合 expanded: true //是否展开 } ]; } else { this.filterExpressionPre = JSON.parse(this.filterExpressionString); this.treeData = []; this.treeData.push(this.unConvert(this.filterExpressionPre)); this.treeData[0].data.id = 1; } } /** * 将treeData转化为filetrExpression实体 * @param filterExpression 过滤表达式实体 * @param treeNode 最外层的treeNode */ convert(filterExpression: FilterExpression, treeNode: TreeNode): FilterExpression { //得到最外层的关系符 filterExpression.relationOperator = this.typeMatch(treeNode.data.item); //若其子项不为空 if (treeNode.children.length != 0) { //对其每一个子项进行转化操作 treeNode.children.forEach(treeNodeItem => { //若子项为并且、或者,则新建复杂过滤表达式 if (this.typeMatch(treeNodeItem.data.item) == RelationTypeEnum.And || this.typeMatch(treeNodeItem.data.item) == RelationTypeEnum.Or) { let filterExpressionItem = new FilterExpression(); filterExpression.expressItems.push(this.convert(filterExpressionItem, treeNodeItem)); } //若子项为属性表达式 else { let filterItem = new ExpressionItem(); let properties = this.propertyListInner.filter(x => x.text == treeNodeItem.data.item); filterItem.propertyName = properties[0].value; filterItem.propertyDataType = treeNodeItem.data.propertyDataType; filterItem.operator = this.typeMatch(treeNodeItem.data.operator); filterItem.expressType = this.typeMatch(treeNodeItem.data.expressType); filterItem.value = treeNodeItem.data.value; filterItem.parentItem = treeNodeItem.data.parentItem; //若为数值型比较,则将value值强制转换为数字 if (filterItem.expressType == ExpressTypeEnum.Value && (filterItem.operator == CompareTypeEnum.GreaterThan || filterItem.operator == CompareTypeEnum.GreaterThanOrEqual || filterItem.operator == CompareTypeEnum.LessThan || filterItem.operator == CompareTypeEnum.LessThanOrEqual )) { filterItem.value = Number(treeNodeItem.data.value); } if (filterItem.expressType == ExpressTypeEnum.Value && (filterItem.operator == CompareTypeEnum.Equal || filterItem.operator == CompareTypeEnum.NotEqual)) { if (filterItem.propertyDataType == PropertyDataType.Decimal || filterItem.propertyDataType == PropertyDataType.Double || filterItem.propertyDataType == PropertyDataType.Int16 || filterItem.propertyDataType == PropertyDataType.Int32 || filterItem.propertyDataType == PropertyDataType.Int64) { filterItem.value = Number(treeNodeItem.data.value); } } //将子项放入父项的字段中 filterExpression.expressItems.push(filterItem); } }); } return filterExpression; } /** * filetrExpression反转化为TreeNode * @param filterExpress 待转化的filetrExpression实体 */ unConvert(filterExpress: FilterExpression): TreeNode { let treeData: TreeNode = { data: { "id": Math.random(), //树形结构中每个节点的id "item": this.relationTypeReverseMatch(filterExpress.relationOperator), //属性项 "propertyDataType": null, //属性数据类型 "operator": null, //操作比较符 "expressType": null, //表达式类型 "value": null, //值 "displaySelect": false, //选择项显示 "displayOperator": false, //操作符项显示 "displayExpressType": false,//表达式类型显示 "displayValue": false, //值显示 "parentItem": null //父项 }, children: [], //子节点集合 expanded: true //是否展开 }; //对于每一个子项 filterExpress.expressItems.forEach(expressItem => { let filterExpressItem = expressItem as FilterExpression; //若子项为FilterExpression类型,赋值 if ((filterExpressItem.relationOperator == RelationTypeEnum.And || filterExpressItem.relationOperator == RelationTypeEnum.Or)) { let treeDataChild = this.unConvert(filterExpressItem); treeDataChild.data.parent = treeData;//添加父节点 treeData.children.push(treeDataChild); } else //若子项为ExpressionItem类型,赋值 { let expressionItem = expressItem as ExpressionItem; let properties = this.propertyListInner.filter(x => x.value == expressionItem.propertyName); let treeDataChild: TreeNode = { data: { "id": Math.random(), //树形结构中每个节点的id "item": properties[0].text, //属性项 "propertyDataType": expressionItem.propertyDataType, "operator": this.operatorReverseMatch(expressionItem.operator), //操作比较符 "expressType": this.expressTypeReverseMatch(expressionItem.expressType),//表达式类型 "value": expressionItem.value, //值 "parentItem": expressionItem.parentItem //父项 }, parent: treeData, //添加父节点 children: [], //子节点集合 expanded: true //是否展开 } treeData.children.push(treeDataChild); } }); return treeData; } /** * 类型信息匹配 * @param type 类型 */ typeMatch(type: any): any { switch (type) { case this.localePipe.transform("And"): return RelationTypeEnum.And; case this.localePipe.transform("Or"): return RelationTypeEnum.Or; case this.localePipe.transform("GreaterThan"): return CompareTypeEnum.GreaterThan; case this.localePipe.transform("GreaterThanOrEqual"): return CompareTypeEnum.GreaterThanOrEqual; case this.localePipe.transform("LessThan"): return CompareTypeEnum.LessThan; case this.localePipe.transform("LessThanOrEqual"): return CompareTypeEnum.LessThanOrEqual; case this.localePipe.transform("Equal"): return CompareTypeEnum.Equal; case this.localePipe.transform("NotEqual"): return CompareTypeEnum.NotEqual; case this.localePipe.transform("Contains"): return CompareTypeEnum.Contains; case this.localePipe.transform("NotContains"): return CompareTypeEnum.NotContains; case this.localePipe.transform("StartsWith"): return CompareTypeEnum.StartsWith; case this.localePipe.transform("EndsWith"): return CompareTypeEnum.EndsWith; case this.localePipe.transform("NotStartsWith"): return CompareTypeEnum.NotStartsWith; case this.localePipe.transform("NotEndsWith"): return CompareTypeEnum.NotEndsWith; case this.localePipe.transform("IsNull"): return CompareTypeEnum.IsNull; case this.localePipe.transform("IsNotNull"): return CompareTypeEnum.IsNotNull; case this.localePipe.transform("In"): return CompareTypeEnum.In; case this.localePipe.transform("NotIn"): return CompareTypeEnum.NotIn; case this.localePipe.transform("Value"): return ExpressTypeEnum.Value; case this.localePipe.transform("Expression"): return ExpressTypeEnum.Expression; } } relationTypeReverseMatch(type: RelationTypeEnum): string { switch (type) { case RelationTypeEnum.And: return this.localePipe.transform('And'); case RelationTypeEnum.Or: return this.localePipe.transform('Or'); } } operatorReverseMatch(type: CompareTypeEnum): string { switch (type) { case CompareTypeEnum.GreaterThan: return this.localePipe.transform("GreaterThan"); case CompareTypeEnum.GreaterThanOrEqual: return this.localePipe.transform("GreaterThanOrEqual"); case CompareTypeEnum.LessThan: return this.localePipe.transform("LessThan"); case CompareTypeEnum.LessThanOrEqual: return this.localePipe.transform("LessThanOrEqual"); case CompareTypeEnum.Equal: return this.localePipe.transform("Equal"); case CompareTypeEnum.NotEqual: return this.localePipe.transform("NotEqual"); case CompareTypeEnum.Contains: return this.localePipe.transform("Contains"); case CompareTypeEnum.NotContains: return this.localePipe.transform("NotContains"); case CompareTypeEnum.StartsWith: return this.localePipe.transform("StartsWith"); case CompareTypeEnum.EndsWith: return this.localePipe.transform("EndsWith"); case CompareTypeEnum.NotStartsWith: return this.localePipe.transform("NotStartsWith"); case CompareTypeEnum.NotEndsWith: return this.localePipe.transform("NotEndsWith"); case CompareTypeEnum.IsNull: return this.localePipe.transform("IsNull"); case CompareTypeEnum.IsNotNull: return this.localePipe.transform("IsNotNull"); case CompareTypeEnum.In: return this.localePipe.transform("In"); case CompareTypeEnum.NotIn: return this.localePipe.transform("NotIn"); } } expressTypeReverseMatch(type: ExpressTypeEnum): string { switch (type) { case ExpressTypeEnum.Value: return this.localePipe.transform("Value"); case ExpressTypeEnum.Expression: return this.localePipe.transform('Expression'); } } /** * 过滤表达式获取(外部调用) */ getFilterExpression(): string { this.treeDataTemp = this.treeData; let isNull = true; let isMatch = true; if (this.checkNull(this.treeDataTemp[0].children, isNull) && this.checkMatch(this.treeDataTemp[0].children, isMatch)) { this.filterExpression = new FilterExpression(); //根据树形数据结构转化为过滤表达式实体 this.convert(this.filterExpression, this.treeDataTemp[0]); //若只包含关系项则返回空 if (this.filterExpression.expressItems.length == 0) return null; else { if (this.filterExpression.relationOperator == null) { this.filterExpression.relationOperator = RelationTypeEnum.Or; } return JSON.stringify(this.filterExpression); } } } //递归检查整个过滤表达式是否有漏填的项 public checkNull(treeNodes: TreeNode[], isNull: boolean): boolean { for (var i = 0; i < treeNodes.length; i++) { if (treeNodes[i].data.item == this.localePipe.transform('And') || treeNodes[i].data.item == this.localePipe.transform('Or')) { if (!(treeNodes[i].children) || treeNodes[i].children.length == 0) { this.checkFilterStruc = false; this.notifyservice[this.notifies['3'].type]({ msg: this.notifies['3'].msg }); isNull = false; break; } else if (!this.checkNull(treeNodes[i].children, isNull)) { isNull = false; break; } } else { if (!(treeNodes[i].data.item) || treeNodes[i].data.item == this.localePipe.transform("SelectProperty") || !(treeNodes[i].data.operator) || !(treeNodes[i].data.expressType) || !(treeNodes[i].data.value)) { this.notifyservice[this.notifies['4'].type]({ msg: this.notifies['4'].msg }); this.checkFilterStruc = false; isNull = false; break; } } } return isNull; } onfocus() { this.displayPopup = true; } onblur() { this.displayPopup = false; } checkMatch(treeNodes: TreeNode[], isMatch: boolean) { for (var i = 0; i < treeNodes.length; i++) { if (treeNodes[i].data.item != this.localePipe.transform('And') && treeNodes[i].data.item != this.localePipe.transform('Or')) { if (treeNodes[i].data.expressType == this.localePipe.transform("Value")) { if ((treeNodes[i].data.propertyDataType == PropertyDataType.Int16 || treeNodes[i].data.propertyDataType == PropertyDataType.Int32 || treeNodes[i].data.propertyDataType == PropertyDataType.Int64) && isNaN(treeNodes[i].data.value)) { this.notifyservice[this.notifies['5'].type]({ msg: this.notifies['5'].msg }); isMatch = false; break; } } } else isMatch = this.checkMatch(treeNodes[i].children, isMatch); } return isMatch; } add() { this.showAddTypes = true; } addItem(treeId: number) { this.hideNodeEditor(this.treeData); this.addNode(this.treeData, this.localePipe.transform("SelectProperty"), this.localePipe.transform("Equal"), this.localePipe.transform("Value"), treeId); this.defaultSelectItem = this.localePipe.transform("SelectProperty"); //默认显示 } addGroup(treeId: number) { this.addNode(this.treeData, this.localePipe.transform("And"), null, null, treeId); } /** * 根据所选为关系或者属性对新节点进行初始化 * @param treeNodes 树形表绑定结构 * @param defaultString 新节点显示默认值 */ addNode(treeNodes: TreeNode[], defaultString: any, defaultOperator: string, defalutExpressType: string, treeId: number) { treeNodes.forEach(node => { if (node.data.id == treeId) { //若关系值为空 if (!(node.data.item)) { this.notifyservice[this.notifies['2'].type]({ msg: this.notifies['2'].msg }); return; } //若为所选的关系节点,则在其子项里添加新子节点 let newNode: TreeNode = { data: { "item": defaultString, "propertyDataType": null, //属性数据类型 "operator": defaultOperator, "expressType": defalutExpressType, "value": null, "id": Math.random(), "parentItem": null }, parent: node, children: [], expanded: true }; //向该所选节点的子项添加新节点 node.children.push(newNode); return; } else if ((node.children) && node.children.length != 0) { //若未找到所选节点,且该节点子项不为空,则在其子项中查找所选节点 this.addNode(node.children, defaultString, defaultOperator, defalutExpressType, treeId); } }); this.tt.updateSerializedValue(); } delete($event) { this.onDelete(this.treeData, $event); } /** * 删除节点具体实现类 * @param treeNodes 树形表绑定结构 */ onDelete(treeNodes: TreeNode[], id: number) { treeNodes.forEach(treeNode => { if (treeNode.data.id == id) { if (treeNode.data.id == 1) { this.notifyservice[this.notifies['6'].type]({ msg: this.notifies['6'].msg }); this.treeData = this.baseTree(); return; } //所选节点所在数 let index = treeNodes.indexOf(treeNode); //将所选节点剔除 treeNodes.splice(index, 1); } else if ((treeNode.children) && treeNode.children.length != 0) { treeNode.children = this.onDelete(treeNode.children, id); } }); this.tt.updateSerializedValue(); return treeNodes; } /** * 返回过滤条件树的第一个结点 * @returns id = 1的结点 */ private baseTree(): any { let tree = []; tree.push( { data: { "id": 1, //树形结构中每个节点的id "item": this.localePipe.transform("And"), //属性项(默认为And) "propertyDataType": null, //属性数据类型 "operator": null, //操作比较符 "expressType": null, //表达式类型 "value": null, //值 "displaySelect": false, //选择项显示 "displayOperator": false, //操作符项显示 "displayExpressType": false, //表达式类型显示 "displayValue": false, //值显示 "parentItem": null //父项 }, children: [], //子节点集合 expanded: true //是否展开 } ); return tree; } } // /** // * 根据所选为关系或者属性对新节点进行初始化 // * @param treeNodes 树形表绑定结构 // * @param defaultString 新节点显示默认值 // */ // addNode(treeNodes: TreeNode[], defaultString: any, defaultOperator: string, defalutExpressType: string) { // treeNodes.forEach(treeNode => { // if (this.tt.isSelected(treeNode)) { // //若关系值为空 // if (!(treeNode.data.item)) { // this.notifyservice[this.notifies['2'].type]({ // msg: this.notifies['2'].msg // }); // return; // } // //若为所选的关系节点,则在其子项里添加新子节点 // let newNode: TreeNode = // { // data: // { // "item": defaultString, // "propertyDataType": null, //属性数据类型 // "operator": defaultOperator, // "expressType": defalutExpressType, // "value": null, // "id": Math.random(), // "parentItem": null // }, // parent: treeNode, // children: [], // expanded: true // }; // //向该所选节点的子项添加新节点 // treeNode.children.push(newNode); // return; // } // //若未找到所选节点,且该节点子项不为空,则在其子项中查找所选节点 // else if ((treeNode.children) && treeNode.children.length != 0) { // this.addNode(treeNode.children, defaultString, defaultOperator, defalutExpressType); // } // }); // this.tt.updateSerializedValue(); // } // /** // * 删除节点 // * @param treeNode 要删除的节点 // */ // deleteNode($event) { // this.onDelete(this.treeData, $event); // } // /** // * 删除节点具体实现类 // * @param treeNodes 树形表绑定结构 // */ // onDelete(treeNodes: TreeNode[], id: number) { // treeNodes.forEach(treeNode => { // if (treeNode.data.id == id) { // if (treeNode.data.id == 1) { // this.notifyservice[this.notifies['6'].type]({ // msg: this.notifies['6'].msg // }); // this.treeData = [ // { // data: // { // "id": 1, //树形结构中每个节点的id // "item": this.localePipe.transform('And'), //属性项 // "propertyDataType": null, //属性数据类型 // "operator": null, //操作比较符 // "expressType": null, //表达式类型 // "value": null, //值 // "displaySelect": false, //选择项显示 // "displayOperator": false, //操作符项显示 // "displayExpressType": false,//表达式类型显示 // "displayValue": false, //值显示 // "parentItem": null //父项 // }, // children: [], //子节点集合 // expanded: true //是否展开 // } // ]; // return; // } // //所选节点所在数 // let index = treeNodes.indexOf(treeNode); // //将所选节点剔除 // treeNodes.splice(index, 1); // } // else if ((treeNode.children) && treeNode.children.length != 0) { // treeNode.children = this.onDelete(treeNode.children, id); // } // }); // this.tt.updateSerializedValue(); // return treeNodes; // } // /*** // * 添加条件项 // */ // addItem() { // this.defaultSelectItem = this.localePipe.transform("SelectItem"); // this.hideNodeEditor(this.treeData); // this.addNode(this.treeData, this.localePipe.transform("SelectProperty"), this.localePipe.transform("Equal"), this.localePipe.transform("Value")); // } // /*** // * 添加条件组 // */ // addGroup() { // this.addNode(this.treeData, this.localePipe.transform('And'), null, null); // } // /** // * 关系选择按钮选择事件 // * @param $event 选择按钮所选信息 // */ // itemClick($event) { // //若选择添加关系 // if ($event.value == RelationTypeEnum.AddRelation) { // this.addNode(this.treeData, this.localePipe.transform('And'), null, null); // } // //若选择添加属性 // else if ($event.value == RelationTypeEnum.AddProperty) { // this.addNode(this.treeData, this.localePipe.transform("SelectProperty"), this.localePipe.transform("Equal"), this.localePipe.transform("Value")); // } // else this.propertyNodeOperate($event, this.treeData, FieldType.Item); // }