src/app/business/entity/data.ts
@@ -83,6 +83,7 @@ export interface AlarmSensorLevel { enable: boolean|any []; increment: number []|any[]; degressEnable:boolean|any []; degression: number []|any []; } export interface Device { src/app/business/services/http/alarm-config.service.ts
@@ -29,6 +29,7 @@ { enable: false, increment: [0,0,0], degressEnable: false, degression: [0,0,0] } : alarmLevels[key]; } src/app/business/services/http/sensors.service.ts
@@ -12,7 +12,8 @@ private urls = { list: environment.SERVER_BASH_URL + '/sensor/page-list', save: environment.SERVER_BASH_URL + '/sensor/add-or-modify', delete: environment.SERVER_BASH_URL + '/sensor/delete-by-ids' delete: environment.SERVER_BASH_URL + '/sensor/delete-by-ids', listByVersionId:environment.SERVER_BASH_URL + '/sensor/list-by-vid', }; constructor(private http: _HttpClient) { } public getPagingList(page: PageBean, queryText: string): Observable<PageBean> { @@ -29,6 +30,9 @@ queryParams: example.getSqlParam(), orderByClause: orderByClause}; return this.http.get(this.urls.list, param); } public getPageByVersionId(versionId:number): Observable<PageBean> { return this.http.get(this.urls.listByVersionId,{versionId:versionId}); } public save(data: any): Observable<any> { return this.http.post(this.urls.save, data); } src/app/business/services/util/tools.service.ts
@@ -15,4 +15,17 @@ } ) } public static removePrivate(obj:object){ Object.keys(obj).forEach( (key:string) => { if(key.startsWith('_')){ delete obj[key]; }else{ if(obj[key] instanceof Object){ ToolsService.removePrivate(obj[key]); } } } ); } } src/app/routes/devices/basic-info/adjust-config/adjust-config.component.ts
@@ -5,6 +5,8 @@ import { Component, OnInit } from '@angular/core'; import { DeviceAdjustValue, Sensor, Device } from '@business/entity/data'; import { Grid, PageBean, ResultBean } from '@business/entity/grid'; import { ContentChild } from '@angular/core/src/metadata/di'; import swal, { SweetAlertType } from 'sweetalert2'; @Component({ selector: 'app-adjust-config', @@ -56,6 +58,10 @@ ) { } ngOnInit() { if(this.record.deviceVersionId==null){ swal(`请先选择设备型号`, '设备校准值到传感器类型由所属设备型号决定', 'info'); this.subject.destroy(); } this.initPage(); this.load(); } @@ -66,22 +72,23 @@ }, 1); zip( this.adjustValueService.getByDid(this.record.id), this.sensorsService.getPagingList(this.grid, null) this.sensorsService.getPageByVersionId(this.record.deviceVersionId) ).subscribe( ([adjustRes,sensorsRes]) => { if(adjustRes!=null && adjustRes.code==1 && sensorsRes != null && sensorsRes.data != null){ this.data = adjustRes.data; if(this.data == null||this.data.deviceId== null){ this.data = {}; this.data.value = {}; this.data['deviceId'] = this.record.id; } // 存储修改前到值 Object.assign(this._dataValue,this.data.value); this.data = { deviceId:this.record.id, value:{} }; if(adjustRes.data!=null){ // 存储修改前到值 Object.assign(this._dataValue,adjustRes.data.value); this.data['id'] =adjustRes.data.id; } this.grid.initData(sensorsRes); sensorsRes.data.forEach( (item:Sensor) => { this.data.value[item.sensorKey] = this.data.value[item.sensorKey] == null?0:this.data.value[item.sensorKey]; this.data.value[item.sensorKey] = this._dataValue[item.sensorKey] == null?0:this._dataValue[item.sensorKey]; } ); this.grid.refreshStatus(); @@ -97,11 +104,14 @@ } save($event) { // $event.preventDefault(); let isModify = Object.keys(this.data.value).some( let isModify = Object.keys(this._dataValue).length != Object.keys(this.data.value).length; if(!isModify){ isModify = Object.keys(this.data.value).some( key => { return this.data.value[key] !== this._dataValue[key]; } ); ); } debugger; if(isModify){ this.adjustValueService.save(this.data).subscribe( src/app/routes/systems/organization/organization-config/organization-config.component.html
@@ -19,14 +19,17 @@ <th nz-th> 三级 </th> <th nz-th> 反向一级 <th nz-th [ngStyle]="{'width': '72px'}"> 启用反向 </th> <th nz-th> 反向二级 <span *ngIf="hasDegression">反向一级</span> </th> <th nz-th> 反向三级 <span *ngIf="hasDegression">反向二级</span> </th> <th nz-th> <span *ngIf="hasDegression">反向三级</span> </th> </tr> </thead> @@ -36,59 +39,65 @@ <td nz-td [nzCheckbox]="true"> <label nz-checkbox formControlName="enable"></label> </td> <td> <td nz-td> <span> {{ row.name }}({{ row.unit }}) </span> </td> <td formArrayName="increment" *ngFor="let in of validateForm.get('alarmLevels.'+row.sensorKey+'.increment').controls; index as i"> <div nz-form-item> <div nz-form-control nzHasFeedback> <nz-input [formControlName]="i" maxlength="20" nzDisabled="{{ !f.value['alarmLevels'][row.sensorKey]['enable'] }}"></nz-input> </div> </div> </td> <td formArrayName="degression" *ngFor="let in of validateForm.get('alarmLevels.'+row.sensorKey+'.degression').controls; index as i"> <td nz-td formArrayName="increment" *ngFor="let in of validateForm.get('alarmLevels.'+row.sensorKey+'.increment').controls; index as i"> <div nz-form-item> <div nz-form-control nzHasFeedback> <nz-input [formControlName]="i" maxlength="20" nzDisabled="{{ !f.value['alarmLevels'][row.sensorKey]['enable'] }}"></nz-input> </div> </div> </td> </td> <td nz-td style="padding-top:0px;"> <div nz-form-control> <nz-switch formControlName="degressEnable" (click)="refreshHasDegression(f.value['alarmLevels'][row.sensorKey]['degressEnable'])" nzDisabled="{{ !f.value['alarmLevels'][row.sensorKey]['enable'] }}"></nz-switch> </div> </td> <td nz-td formArrayName="degression" *ngFor="let in of validateForm.get('alarmLevels.'+row.sensorKey+'.degression').controls; index as i"> <div *ngIf="f.value['alarmLevels'][row.sensorKey]['degressEnable']" nz-form-item> <div nz-form-control nzHasFeedback> <nz-input [formControlName]="i" maxlength="20" nzDisabled="{{ !f.value['alarmLevels'][row.sensorKey]['enable'] }}"></nz-input> </div> </div> </td> </tr> </tbody> </nz-table> </nz-card> <div [ngStyle]="{'background-color':'#f5f7fa','width':'110%','left':'-5%','height':'20px','position':'relative'}"></div> <nz-card [nzBordered]="false" nzTitle="报警方式" formGroupName="alarmMode"> <label nz-checkbox formControlName="enable"> <span>启用报警</span> </label> <div [ngStyle]="{'margin-left': '20%'}"> <br/> <br/> <br/> <div *ngFor="let i of [1,2,3]" nz-form-item nz-row class="mb-sm"> <div nz-form-label nz-col [nzSm]="3" [nzXs]="24"> <span [ngSwitch]="i"> <label *ngSwitchCase="1">一级报警方式:</label> <label *ngSwitchCase="2">二级报警方式:</label> <label *ngSwitchCase="3">三级报警方式:</label> </span> </div> <div nz-form-control nz-col [nzSpan]="12" nzHasFeedback> <nz-select formControlName="{{ 'level'+i }}" [nzMode]="'multiple'" [nzPlaceHolder]="'选择 报警方式'" [nzNotFoundContent]="'无法找到'" nzDisabled="{{ !f.value['alarmMode']['enable'] }}"> <nz-option *ngFor="let option of alarmModes" [nzLabel]="option.label" [nzValue]="option.value" [nzDisabled]="option.disabled"> </nz-option> </nz-select> </div> <br/> <br/> <br/> <nz-card [nzBordered]="false" nzTitle="报警方式" formGroupName="alarmMode"> <label nz-checkbox formControlName="enable"> <span>启用报警</span> </label> <div [ngStyle]="{'margin-left': '20%'}"> <br/> <br/> <br/> <div *ngFor="let i of [1,2,3]" nz-form-item nz-row class="mb-sm"> <div nz-form-label nz-col [nzSm]="3" [nzXs]="24"> <span [ngSwitch]="i"> <label *ngSwitchCase="1">一级报警方式:</label> <label *ngSwitchCase="2">二级报警方式:</label> <label *ngSwitchCase="3">三级报警方式:</label> </span> </div> <div nz-form-control nz-col [nzSpan]="12" nzHasFeedback> <nz-select formControlName="{{ 'level'+i }}" [nzMode]="'multiple'" [nzPlaceHolder]="'选择 报警方式'" [nzNotFoundContent]="'无法找到'" nzDisabled="{{ !f.value['alarmMode']['enable'] }}"> <nz-option *ngFor="let option of alarmModes" [nzLabel]="option.label" [nzValue]="option.value" [nzDisabled]="option.disabled"> </nz-option> </nz-select> </div> <br/> <br/> <br/> </div> </nz-card> </div> </nz-card> <footer-toolbar errorCollect> <span [ngStyle]="{'color':'red','width':'300px','margin-right':'40px'}">{{ errorMessage }}</span> <label>组织名称:</label> @@ -100,5 +109,5 @@ <span *ngIf="isSaving">中</span> </span> </button> </footer-toolbar> </footer-toolbar> </form> src/app/routes/systems/organization/organization-config/organization-config.component.ts
@@ -1,7 +1,7 @@ import { NzMessageService } from 'ng-zorro-antd'; import { filter } from 'rxjs/operators'; import { HttpClient } from '@angular/common/http'; import { FormGroup, FormBuilder, FormControl, Validators, FormArray } from '@angular/forms'; import { FormGroup, FormBuilder, FormControl, Validators, FormArray, AbstractControl } from '@angular/forms'; import { SensorsService } from '@business/services/http/sensors.service'; import { Grid, PageBean } from '@business/entity/grid'; import { Organization, AlarmConfig, AlarmSensorLevel, AlarmConfigValue } from '@business/entity/data'; @@ -11,6 +11,7 @@ import { AlarmConfigService } from '@business/services/http/alarm-config.service'; import { AlarmStyle } from '@business/enum/types.enum'; import { patterns } from '@business/enum/patterns.enum'; import { ToolsService } from '@business/services/util/tools.service'; @Component({ selector: 'app-organization-config', @@ -81,8 +82,12 @@ [degression[1], Validators.pattern(patterns.num)], [degression[2], Validators.pattern(patterns.num)] ]); //判断逆向是否启用 // let _degressionEnable = degression[0] != 0 || degression[1] != 0 || degression[2] != 0; const alarmSensorGroup = this.formBuilder.group( { degressEnable:[alarmLevels[key].degressEnable], enable: [alarmLevels[key].enable], increment: incrementArray, degression: degressionArray, @@ -126,6 +131,7 @@ ) this.refreshIndeterminate(); } this.refreshHasDegression(false); // 延时加载避免ExpressionChangedAfterItHasBeenCheckedError setTimeout(() => { this.grid.loading = false; @@ -173,6 +179,7 @@ organizationId:this.organization.id, value:value } // ToolsService.removePrivate(data.value); this.alarmConfigService.save(data).subscribe( result => { if(result!=null&&result.code==1){ @@ -182,6 +189,7 @@ } ); } debugger; } setErrorMessage(){ @@ -198,53 +206,55 @@ } } errorMessage:string = ''; private removeError(error:'increment'|'degression',...controls:AbstractControl[]){ controls.forEach( item => { if(item.hasError(error)&&Object.keys(item.errors).length==1){ item.setErrors(null); } } ); } private addError(error:'increment'|'degression',...controls:AbstractControl[]){ controls.forEach( item => { let errs = {}; errs[error] = true; item.setErrors(errs); item.markAsDirty(); } ); } private alarmLevelValidator = (control: FormControl): { [s: string]: boolean } => { let result = {}; const i0 = control.get("increment.0"); const i1 = control.get("increment.1"); const i2 = control.get("increment.2"); if ((i0.value != 0 || i1.value != 0 || i2.value != 0)&&(i0.value >= i1.value||i1.value >= i2.value)) { i0.setErrors({ increment: true }); i0.markAsDirty(); i1.setErrors({ increment: true }); i1.markAsDirty(); i2.setErrors({ increment: true }); i2.markAsDirty(); result["increment"] = true; }else{ if(i0.hasError('increment')&&Object.keys(i0.errors).length==1){ i0.setErrors(null); const enable = control.get("enable").value; const degressEnable = control.get("degressEnable").value; const i0 = control.get("increment.0"); const i1 = control.get("increment.1"); const i2 = control.get("increment.2"); const d0 = control.get("degression.0"); const d1 = control.get("degression.1"); const d2 = control.get("degression.2"); // 如果未启用 删除错误信息,不验证 if(!enable){ this.removeError('increment',i0,i1,i2); this.removeError('degression',d0,d1,d2); return null; } if(i1.hasError('increment')&&Object.keys(i1.errors).length==1){ i1.setErrors(null); } if(i2.hasError('increment')&&Object.keys(i2.errors).length==1){ i2.setErrors(null); } } const d0 = control.get("degression.0"); const d1 = control.get("degression.1"); const d2 = control.get("degression.2"); if ((d0.value != 0 || d1.value != 0 || d2.value != 0)&&(d1.value >= d0.value||d2.value >= d1.value)) { d0.setErrors({ degression: true }); d0.markAsDirty(); d1.setErrors({ degression: true }); d1.markAsDirty(); d2.setErrors({ degression: true }); d2.markAsDirty(); result["degression"] = true; }else{ if(d0.hasError('degression')&&Object.keys(d0.errors).length==1){ d0.setErrors(null); } if(d1.hasError('degression')&&Object.keys(d1.errors).length==1){ d1.setErrors(null); } if(d2.hasError('degression')&&Object.keys(d2.errors).length==1){ d2.setErrors(null); } } return Object.keys(result).length == 0?null:result; let result = {}; if ((i0.value != 0 || i1.value != 0 || i2.value != 0)&&(i0.value >= i1.value||i1.value >= i2.value)) { this.addError('increment',i0,i1,i2); result["increment"] = true; }else{ this.removeError('increment',i0,i1,i2); } debugger; if(degressEnable&&(d0.value != 0 || d1.value != 0 || d2.value != 0)&&(d1.value >= d0.value||d2.value >= d1.value)) { this.addError('degression',d0,d1,d2); result["degression"] = true; }else{ this.removeError('degression',d0,d1,d2); } return Object.keys(result).length == 0?null:result; }; getLastError(control:FormGroup|FormArray){ if(control.errors!=null){ @@ -264,4 +274,16 @@ } } } private hasDegression = false; refreshHasDegression(value){ if(value){ this.hasDegression = true; }else{ this.hasDegression = Object.values(this.validateForm.value['alarmLevels']).some( ( item:any) => { return item['degressEnable']; } ) } } }