From f0b742d34e95811b6874bcaedbc7a06451d39da1 Mon Sep 17 00:00:00 2001 From: fengxiang <110431245@qq.com> Date: Fri, 12 Jan 2018 21:07:08 +0800 Subject: [PATCH] 组织配置 --- src/app/routes/systems/organization/organization-list/organization-list.component.ts | 20 ++ src/app/routes/routes.module.ts | 2 src/app/business/business.module.ts | 20 ++ src/app/business/entity/grid.ts | 5 src/app/business/services/http/organization.service.ts | 6 src/app/routes/systems/organization/organization-config/organization-config.component.html | 188 +++++++++++++++------- src/app/routes/systems/organization/organization.component.html | 4 src/app/business/enum/types.enum.ts | 5 src/app/business/entity/data.ts | 9 + src/app/business/services/http/areacode.service.ts | 5 src/app/routes/systems/systems.module.ts | 8 src/app/routes/systems/organization/organization-config/organization-config.component.ts | 151 ++++++++++++++++++ src/app/routes/devices/version/version-sensor-config/version-sensor-config.component.html | 2 src/app/business/services/http/alarm-config.service.ts | 19 ++ 14 files changed, 361 insertions(+), 83 deletions(-) diff --git a/src/app/business/business.module.ts b/src/app/business/business.module.ts new file mode 100644 index 0000000..5f8177b --- /dev/null +++ b/src/app/business/business.module.ts @@ -0,0 +1,20 @@ +import { NgModule } from '@angular/core'; +import { CommonModule } from '@angular/common'; +// Statics +import 'rxjs/add/observable/throw'; + +// Operators +import 'rxjs/add/operator/catch'; +import 'rxjs/add/operator/debounceTime'; +import 'rxjs/add/operator/distinctUntilChanged'; +import 'rxjs/add/operator/map'; +import 'rxjs/add/operator/switchMap'; +import 'rxjs/add/operator/toPromise'; +import 'rxjs/add/operator/filter'; + +@NgModule({ + imports: [ + CommonModule + ] +}) +export class BusinessModule { } diff --git a/src/app/business/entity/data.ts b/src/app/business/entity/data.ts index 2ea1eba..d6f454c 100644 --- a/src/app/business/entity/data.ts +++ b/src/app/business/entity/data.ts @@ -61,3 +61,12 @@ areaNames?: AreaNames|any ; organization?: Organization; } + + // ������������ + export interface AlarmConfig { + createTime?: number; + id?: number; + organizationId?: number; + updateTime?: number; + value?: object; +} diff --git a/src/app/business/entity/grid.ts b/src/app/business/entity/grid.ts index 628fea5..f4f5501 100644 --- a/src/app/business/entity/grid.ts +++ b/src/app/business/entity/grid.ts @@ -111,3 +111,8 @@ return arr; } } +export interface ResultBean<T>{ + code?: number; + data?: T; + message?: string; +} \ No newline at end of file diff --git a/src/app/business/enum/types.enum.ts b/src/app/business/enum/types.enum.ts index 3fc5a08..b1a5157 100644 --- a/src/app/business/enum/types.enum.ts +++ b/src/app/business/enum/types.enum.ts @@ -1,3 +1,8 @@ export enum Types { Date, Json } + +export enum AlarmStyle { + //��������������������������������� + weixin='weixin',email='email',sms='sms',voice='voice' +} diff --git a/src/app/business/services/http/alarm-config.service.ts b/src/app/business/services/http/alarm-config.service.ts new file mode 100644 index 0000000..6db6cbf --- /dev/null +++ b/src/app/business/services/http/alarm-config.service.ts @@ -0,0 +1,19 @@ +import { _HttpClient } from '@delon/theme'; +import { Injectable } from '@angular/core'; +import { environment } from '@env/environment'; +import { Observable } from 'rxjs/Observable'; +import { ResultBean } from '@business/entity/grid'; +import { AlarmConfig } from '@business/entity/data'; + +@Injectable() +export class AlarmConfigService { + private urls = { + getByOid: environment.SERVER_BASH_URL + 'alarm-config/get-by-oid' + }; + constructor( private http: _HttpClient) { + + } + public getByOid(oid:number):Observable<ResultBean<AlarmConfig>>{ + return this.http.get(this.urls.getByOid,{organizationId:oid}); + } +} diff --git a/src/app/business/services/http/areacode.service.ts b/src/app/business/services/http/areacode.service.ts index 51254b2..80801af 100644 --- a/src/app/business/services/http/areacode.service.ts +++ b/src/app/business/services/http/areacode.service.ts @@ -1,10 +1,5 @@ import { Injectable } from '@angular/core'; import { _HttpClient } from '@delon/theme/services/http/http.client'; -// Statics -import 'rxjs/add/observable/throw'; -// Operators -import 'rxjs/add/operator/catch'; -import 'rxjs/add/operator/map'; import { Observable } from 'rxjs/Observable'; import { environment } from 'environments/environment'; diff --git a/src/app/business/services/http/organization.service.ts b/src/app/business/services/http/organization.service.ts index da161a8..0284ab9 100644 --- a/src/app/business/services/http/organization.service.ts +++ b/src/app/business/services/http/organization.service.ts @@ -1,4 +1,4 @@ -import { Organization } from '@business/entity/data'; +import { Organization, AlarmConfig } from '@business/entity/data'; import { ExampleService } from '@business/services/util/example.service'; import { _HttpClient } from '@delon/theme'; import { environment } from 'environments/environment'; @@ -6,13 +6,13 @@ import { Injectable } from '@angular/core'; import { equal } from 'assert'; import { Observable } from 'rxjs/Observable'; -import { PageBean } from '@business/entity/grid'; +import { PageBean, ResultBean } from '@business/entity/grid'; @Injectable() export class OrganizationService { handle: 'list'|'config' = 'list'; - + config: {pageBean: PageBean,resultBean: ResultBean<AlarmConfig>}; data: Organization; title: '������������'|'������������' = '������������'; private urls = { diff --git a/src/app/routes/devices/version/version-sensor-config/version-sensor-config.component.html b/src/app/routes/devices/version/version-sensor-config/version-sensor-config.component.html index 8ad08af..86c2a1a 100644 --- a/src/app/routes/devices/version/version-sensor-config/version-sensor-config.component.html +++ b/src/app/routes/devices/version/version-sensor-config/version-sensor-config.component.html @@ -2,7 +2,7 @@ <div class="modal-title">���������������</div> </div> <nz-table #nzTable [nzDataSource]="grid.data" [nzPageSize]="8" - [nzLoading]="grid.loading" [nzShowTotal]="true" > + [nzLoading]="grid.loading" [nzShowTotal]="true"> <thead nz-thead> <tr> <th nz-th [nzCheckbox]="true"> diff --git a/src/app/routes/routes.module.ts b/src/app/routes/routes.module.ts index 67e88d4..4afdeaf 100644 --- a/src/app/routes/routes.module.ts +++ b/src/app/routes/routes.module.ts @@ -29,7 +29,7 @@ DashboardV1Component, DashboardAnalysisComponent, DashboardMonitorComponent, - DashboardWorkplaceComponent, + DashboardWorkplaceComponent ], providers: [ _HttpClient, diff --git a/src/app/routes/systems/organization/organization-config/organization-config.component.html b/src/app/routes/systems/organization/organization-config/organization-config.component.html index a4c3222..b5a2a48 100644 --- a/src/app/routes/systems/organization/organization-config/organization-config.component.html +++ b/src/app/routes/systems/organization/organization-config/organization-config.component.html @@ -1,67 +1,131 @@ -<form> - <p>111111111111111111111111111<br/> - 222222222222222222222222222<br/> - 333333333333333333333333333<br/> - </p> - <p>111111111111111111111111111<br/> - 222222222222222222222222222<br/> - 333333333333333333333333333<br/> - </p> - <p>111111111111111111111111111<br/> - 222222222222222222222222222<br/> - 333333333333333333333333333<br/> - </p> - <p>111111111111111111111111111<br/> - 222222222222222222222222222<br/> - 333333333333333333333333333<br/> - </p> - <p>111111111111111111111111111<br/> - 222222222222222222222222222<br/> - 333333333333333333333333333<br/> - </p> - <p>111111111111111111111111111<br/> - 222222222222222222222222222<br/> - 333333333333333333333333333<br/> - </p> - <p>111111111111111111111111111<br/> - 222222222222222222222222222<br/> - 333333333333333333333333333<br/> - </p> - <p>111111111111111111111111111<br/> - 222222222222222222222222222<br/> - 333333333333333333333333333<br/> - </p> - <p>111111111111111111111111111<br/> - 222222222222222222222222222<br/> - 333333333333333333333333333<br/> - </p> - <p>111111111111111111111111111<br/> - 222222222222222222222222222<br/> - 333333333333333333333333333<br/> - </p> - <p>111111111111111111111111111<br/> - 222222222222222222222222222<br/> - 333333333333333333333333333<br/> - </p> - <p>111111111111111111111111111<br/> - 222222222222222222222222222<br/> - 333333333333333333333333333<br/> - </p> - <p>111111111111111111111111111<br/> - 222222222222222222222222222<br/> - 333333333333333333333333333<br/> - </p> - <p>111111111111111111111111111<br/> - 222222222222222222222222222<br/> - 333333333333333333333333333<br/> - </p> - <footer-toolbar errorCollect> +<form nz-form [formGroup]="validateForm" (ngSubmit)="save($event,validateForm.value,validateForm.valid)" [nzLayout]="'vertical'" + #f="ngForm"> + <nz-card [nzBordered]="false" nzTitle="��������������������������������������������� ������������ ������������������������)"> + <nz-table #nzTable [nzDataSource]="grid.data" [nzPageSize]="10" [nzLoading]="grid.loading" [nzShowTotal]="true"> + <thead nz-thead> + <tr> + <th nz-th [nzCheckbox]="true"> + <label nz-checkbox formControlName="_allChecked" [nzIndeterminate]="indeterminate" (ngModelChange)="checkAll($event)"></label> + </th> + <th nz-th> + ��������������� + </th> + <th nz-th> + ������ + </th> + <th nz-th> + ������ + </th> + <th nz-th> + ������ + </th> + <th nz-th> + ������������ + </th> + <th nz-th> + ������������ + </th> + <th nz-th> + ������������ + </th> + </tr> + </thead> + <tbody nz-tbody> + <tr nz-tbody-tr *ngFor="let row of nzTable.data"> + <td nz-td [nzCheckbox]="true"> + <label nz-checkbox formControlName="{{row.key}}_enable"></label> + </td> + <td> + <span> + {{ row.name }} + </span> + </td> + <td> + <div nz-form-item> + <div nz-form-control nzHasFeedback> + <nz-input formControlName="{{row.key}}_level_increment_1" maxlength="20" nzDisabled="{{ !f.value[row.key+'_enable'] }}"></nz-input> + </div> + </div> + </td> + <td> + <div nz-form-item> + <div nz-form-control nzHasFeedback> + <nz-input formControlName="{{row.key}}_level_increment_2" maxlength="20" nzDisabled="{{ !f.value[row.key+'_enable'] }}" + validateGreater></nz-input> + </div> + </div> + </td> + <td> + <div nz-form-item> + <div nz-form-control nzHasFeedback> + <nz-input formControlName="{{row.key}}_level_increment_3" maxlength="20" nzDisabled="{{ !f.value[row.key+'_enable'] }}"></nz-input> + </div> + </div> + </td> + <td> + <div nz-form-item> + <div nz-form-control nzHasFeedback> + <nz-input formControlName="{{row.key}}_level_degression_1" maxlength="20" nzDisabled="{{ !f.value[row.key+'_enable'] }}"></nz-input> + </div> + </div> + </td> + <td> + <div nz-form-item> + <div nz-form-control nzHasFeedback> + <nz-input formControlName="{{row.key}}_level_degression_2" maxlength="20" nzDisabled="{{ !f.value[row.key+'_enable'] }}"></nz-input> + </div> + </div> + </td> + <td> + <div nz-form-item> + <div nz-form-control nzHasFeedback> + <nz-input formControlName="{{row.key}}_level_degression_3" maxlength="20" nzDisabled="{{ !f.value[row.key+'_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="������������"> + <label nz-checkbox formControlName="mode_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="mode_level{{i}}" [nzMode]="'multiple'" [nzPlaceHolder]="'������ ������������'" [nzNotFoundContent]="'������������'" + nzDisabled="{{ !f.value['mode_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> + </div> + </nz-card> + <footer-toolbar ng-content = '������������' errorCollect> + <label>���������������</label> + <span [ngStyle]="{'font-size': '16px','font-weight': 'bold','margin-right':'30px'}">{{ organization.name }}</span> <button nz-button type="button" (click)="backToList()">������</button> <button nz-button [nzType]="'primary'" [nzLoading]="isSaving"> - <span> - ������ - <span *ngIf="isSaving">���</span> - </span> + <span> + ������ + <span *ngIf="isSaving">���</span> + </span> </button> </footer-toolbar> </form> diff --git a/src/app/routes/systems/organization/organization-config/organization-config.component.ts b/src/app/routes/systems/organization/organization-config/organization-config.component.ts index f9fdffa..100d3a0 100644 --- a/src/app/routes/systems/organization/organization-config/organization-config.component.ts +++ b/src/app/routes/systems/organization/organization-config/organization-config.component.ts @@ -1,24 +1,161 @@ +import { filter } from 'rxjs/operators'; +import { HttpClient } from '@angular/common/http'; +import { FormGroup, FormBuilder, FormControl, Validators } from '@angular/forms'; +import { SensorsService } from '@business/services/http/sensors.service'; +import { Grid, PageBean } from '@business/entity/grid'; import { Organization } from '@business/entity/data'; -import { Component, OnInit } from '@angular/core'; +import { Component, OnInit, OnDestroy } from '@angular/core'; import { OrganizationService } from '@business/services/http/organization.service'; +import { _HttpClient } from '@delon/theme'; +import { AlarmConfigService } from '@business/services/http/alarm-config.service'; +import { AlarmStyle } from '@business/enum/types.enum'; @Component({ selector: 'app-organization-config', templateUrl: './organization-config.component.html', - styles: [] + styles: [], + providers: [AlarmConfigService] }) -export class OrganizationConfigComponent implements OnInit { - organization: Organization; +export class OrganizationConfigComponent implements OnInit, OnDestroy { + ngOnDestroy(): void { + this.backToList(); + } + private organization:Organization; + grid: Grid<object> = new Grid<object>(null); + validateForm: FormGroup; constructor( - private organizationService: OrganizationService - ) { - console.log(this.organizationService.data); + private organizationService: OrganizationService, + private sensorsService: SensorsService, + private alarmConfigService:AlarmConfigService, + private formBuilder: FormBuilder, + private http: _HttpClient + ) { + this.organization = this.organizationService.data; } ngOnInit() { + this.load(); } + load(reload: boolean = false) { + if (reload) { + this.grid.pageIndex = 1 ; + } + // TODO + // ������������������ExpressionChangedAfterItHasBeenCheckedError + // setTimeout(() => { + // this.grid.loading = true; + // }, 1); + let pageBean = this.organizationService.config.pageBean;// + let resultBean = this.organizationService.config.resultBean; + resultBean = resultBean == null?{} : resultBean; + if (pageBean != null && pageBean.data != null) { + this.grid.initData(pageBean); + this.grid.refreshStatus(); + setTimeout(() => { + this.grid.loading = false; + }, 1); + let validates = {}; + let data = resultBean.data == null ?{}:resultBean.data; + const value = data['value'] == null ? {} : data['value']; + let alarmLevels = value['alarmLevels']; + alarmLevels = alarmLevels==null ? {} : alarmLevels; + // ������������ + const level_num = 3; + this.grid.data.forEach( + (sensor: object) => { + const sensorLevel = alarmLevels[sensor['key']] == null ?{}:alarmLevels[sensor['key']]; + const enable_key = sensor['key'] + '_enable'; + const enable_value = sensorLevel['enable'] == null ? false : sensorLevel['enable'] == 1; + validates[enable_key] = enable_value; + const increments:number[] = sensorLevel['increment']; + const degression:number[] = sensorLevel['degression']; + for(let i=0;i<level_num;i++){ + const increment_key = sensor['key']+'_level_increment_'+(i+1); + if( increments == null || increments.length == 0 ){ + validates[increment_key] = [null,[Validators.pattern('^\\d+(\\.\\d+)?$')]]; + }else{ + const increment_value = increments.length>i ? increments[i]:null ; + validates[increment_key] = [increment_value,[Validators.pattern('^\\d+(\\.\\d+)?$')]]; + } + const degression_key = sensor['key']+'_level_degression_'+(i+1); + if( degression == null || degression.length == 0 ){ + validates[degression_key] = [null,[Validators.pattern('^\\d+(\\.\\d+)?$')]]; + }else{ + const degression_value = degression.length>i ? degression[i]:null ; + validates[degression_key] = [degression_value,[Validators.pattern('^\\d+(\\.\\d+)?$')]]; + } + } + + } + ); + validates['_allChecked'] = [this.grid.allChecked]; + //������������������ + let alarmMode = value['alarmMode']; + alarmMode = alarmMode==null ? {}: alarmMode; + this.alarmModes.push( + {label:'������',value:AlarmStyle.email, disabled: false}, + {label:'������',value:AlarmStyle.sms, disabled: false}, + {label:'������',value:AlarmStyle.voice, disabled: false}, + {label:'������',value:AlarmStyle.weixin, disabled: false} + ); + validates['mode_enable'] = [alarmMode['enable']]; + for(let i = 0; i<level_num; i++){ + const n = i+1; + validates['mode_level'+n] = [AlarmStyle[alarmMode['level'+n]]]; + } + this.validateForm = this.formBuilder.group(validates); + this.grid.loading = false; + this.enableKeys = Object.keys(this.validateForm.value).filter( + (key: string) => { + return key.endsWith('_enable'); + } + ); + this.enableKeys.forEach( + (key: string) => { + this.validateForm.controls[key].valueChanges.subscribe( + (value: any) => { + if(this._allCheckTriggers <= 0){ + this.refreshIndeterminate(); + } else { + this._allCheckTriggers--; + } + } + ); + } + ); + this.refreshIndeterminate(); + } + + } + alarmModes: {label:string,value:AlarmStyle,disabled: boolean} [] = []; + backToList() { this.organizationService.handle = 'list'; this.organizationService.title = '������������'; } + enableKeys: string []; + indeterminate: boolean; + checkAll(param){ + this._allCheckTriggers = 0; + this.enableKeys.forEach( + (key: string) => { + this._allCheckTriggers++; + this.validateForm.controls[key].setValue(param); + } + ); + this.refreshIndeterminate(); + } + private _allCheckTriggers: number = 0; + refreshIndeterminate(){ + const allChecked = this.enableKeys.every(key => this.validateForm.controls[key].value); + const allUnChecked = this.enableKeys.every(key => !this.validateForm.controls[key].value); + this.indeterminate = (!allChecked) && (!allUnChecked); + } + save($event, value, valid) { + $event.preventDefault(); + if (valid) { + + + } + } } diff --git a/src/app/routes/systems/organization/organization-list/organization-list.component.ts b/src/app/routes/systems/organization/organization-list/organization-list.component.ts index 24e80c5..eb79a20 100644 --- a/src/app/routes/systems/organization/organization-list/organization-list.component.ts +++ b/src/app/routes/systems/organization/organization-list/organization-list.component.ts @@ -1,3 +1,5 @@ +import { AlarmConfigService } from '@business/services/http/alarm-config.service'; +import { SensorsService } from '@business/services/http/sensors.service'; import { Router } from '@angular/router'; import { ModalHelper } from '@delon/theme'; import { NzModalService, NzMessageService } from 'ng-zorro-antd'; @@ -8,11 +10,13 @@ import { Subject } from 'rxjs/Subject'; import { Types } from '@business/enum/types.enum'; import { OrganizationEditComponent } from 'app/routes/systems/organization/organization-edit/organization-edit.component'; +import { zip } from 'rxjs/observable/zip'; @Component({ selector: 'app-organization-list', templateUrl: './organization-list.component.html', - styles: [] + styles: [], + providers: [AlarmConfigService] }) export class OrganizationListComponent implements OnInit { private organization: Organization; @@ -89,6 +93,8 @@ public msgSrv: NzMessageService, private modalHelper: ModalHelper, private router: Router, + private sensorsService:SensorsService, + private alarmConfigService:AlarmConfigService, ) {} ngOnInit() { @@ -205,8 +211,20 @@ this.load(); } config(row) { + // ������������������ExpressionChangedAfterItHasBeenCheckedError + setTimeout(() => { + this.grid.loading = true; + }, 1); + zip( + this.sensorsService.getPagingList({pageIndex:0,pageSize:0}, null), + this.alarmConfigService.getByOid( row.id ) + ).subscribe(([pageBean, resultBean]) => { + console.log(pageBean); + this.grid.loading = false; this.organizationService.handle = 'config' ; this.organizationService.data = row; + this.organizationService.config = {pageBean,resultBean}; this.organizationService.title = '������������'; + }); } } diff --git a/src/app/routes/systems/organization/organization.component.html b/src/app/routes/systems/organization/organization.component.html index bee33d6..eb4b3db 100644 --- a/src/app/routes/systems/organization/organization.component.html +++ b/src/app/routes/systems/organization/organization.component.html @@ -1,4 +1,6 @@ -<pro-header [title]="organizationService.title"></pro-header> +<pro-header [title]="organizationService.title"> + +</pro-header> <nz-card [nzBordered]="false" [nzNoHovering]="true"> <ng-template #body> <app-organization-list *ngIf="organizationService.handle=='list'"></app-organization-list> diff --git a/src/app/routes/systems/systems.module.ts b/src/app/routes/systems/systems.module.ts index 7404c54..257790b 100644 --- a/src/app/routes/systems/systems.module.ts +++ b/src/app/routes/systems/systems.module.ts @@ -1,3 +1,4 @@ +import { EqualValidator } from '@business/validators/equal-validator.directive'; import { FormBuilder } from '@angular/forms'; import { _HttpClient } from '@delon/theme'; import { Component, OnInit } from '@angular/core'; @@ -15,6 +16,8 @@ import { AreacodeService } from '@business/services/http/areacode.service'; import { OrganizationConfigComponent } from './organization/organization-config/organization-config.component'; import { OrganizationListComponent } from './organization/organization-list/organization-list.component'; +import { SensorsService } from '@business/services/http/sensors.service'; +import { BusinessModule } from '@business/business.module'; const routes: Routes = [ { @@ -34,7 +37,8 @@ PipeModule, CommonModule, SharedModule, - RouterModule.forChild(routes) + RouterModule.forChild(routes), + BusinessModule ], declarations: [ ...COMPONENTS_NOROUNT, @@ -44,7 +48,7 @@ OrganizationConfigComponent, OrganizationListComponent ], - providers: [ToolsService, OrganizationService, _HttpClient, FormBuilder, AreacodeService], + providers: [ToolsService, SensorsService,OrganizationService, _HttpClient, FormBuilder, AreacodeService], entryComponents: COMPONENTS_NOROUNT }) export class SystemsModule { } -- Gitblit v1.8.0