From 55da782025f5728051fea9fff49f9e6b6f602a1e Mon Sep 17 00:00:00 2001 From: fengxiang <110431245@qq.com> Date: Thu, 28 Dec 2017 17:31:15 +0800 Subject: [PATCH] 设备信息模块 --- src/app/routes/devices/devices.module.ts | 8 src/app/app.module.ts | 1 src/app/shared/shared.module.ts | 10 ++ src/app/core/i18n/i18n.service.ts | 4 src/app/routes/devices/version/version.component.ts | 97 ++++++++++++------ /dev/null | 15 --- src/app/routes/devices/version/version.service.ts | 20 ++-- src/app/routes/devices/version/add-or-edit/add-or-edit.component.html | 48 +++++++++ src/app/core/entity/grid.ts | 15 +- src/app/core/services/example.service.ts | 9 - src/app/routes/devices/version/add-or-edit/add-or-edit.component.ts | 48 +++++++++ src/app/routes/devices/version/version.component.html | 14 ++ src/app/core/pipe/tyep-handle.pipe.ts | 10 +- 13 files changed, 208 insertions(+), 91 deletions(-) diff --git a/src/app/app.module.ts b/src/app/app.module.ts index 2d1fc5b..5aeeadf 100644 --- a/src/app/app.module.ts +++ b/src/app/app.module.ts @@ -4,7 +4,6 @@ import { TranslateModule, TranslateLoader, TranslateService } from '@ngx-translate/core'; import { TranslateHttpLoader } from '@ngx-translate/http-loader'; import { HttpClient, HTTP_INTERCEPTORS } from '@angular/common/http'; - import { CoreModule } from './core/core.module'; import { SharedModule } from './shared/shared.module'; import { AppComponent } from './app.component'; diff --git a/src/app/core/entity/grid.ts b/src/app/core/entity/grid.ts index b96a8dd..a66711d 100644 --- a/src/app/core/entity/grid.ts +++ b/src/app/core/entity/grid.ts @@ -3,7 +3,6 @@ export interface Column { text?: string; name?: string; - value?: any; width?: string; sort?: boolean; type?: DataType; @@ -18,13 +17,13 @@ pageSize?: number ; // ��������������� total?: number; data?: any[]; - queryParams?: string; + queryParams?: string; } -export class Grid implements PageBean { +export class Grid<T> implements PageBean { title = ''; pageIndex = 0; // ������ pageSize = 10; // ������������������ - data: any[] = []; + data: T[] = []; total = 0; queryParams = ''; pages = 0; // ��������� @@ -38,7 +37,7 @@ checkAll(value: boolean) { this.data.forEach( - row => {row.checked = value; } + row => {row['checked'] = value; } ); this.refreshStatus(); } @@ -57,11 +56,11 @@ } refreshStatus() { const data = this.data; - const allChecked = data.every(value => value.checked); - const allUnChecked = data.every(value => !value.checked); + 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( + this.selectedIndexs = data.filter(value => value['checked']).map( row => { return row['index'] != null ? row['index'] : 0; } diff --git a/src/app/core/i18n/i18n.service.ts b/src/app/core/i18n/i18n.service.ts index e046d53..9e8fc05 100644 --- a/src/app/core/i18n/i18n.service.ts +++ b/src/app/core/i18n/i18n.service.ts @@ -11,8 +11,8 @@ private _default = 'en'; private _langs = [ - { code: 'en', text: 'English' }, - { code: 'zh-CN', text: '������' } + { code: 'zh-CN', text: '������' }, + { code: 'en', text: 'English' } ]; constructor(settings: SettingsService, diff --git a/src/app/core/pipe/tyep-handle.pipe.ts b/src/app/core/pipe/tyep-handle.pipe.ts index 876b401..a9a8ab3 100644 --- a/src/app/core/pipe/tyep-handle.pipe.ts +++ b/src/app/core/pipe/tyep-handle.pipe.ts @@ -19,15 +19,15 @@ transform(value: any, col?: Column): any { const t = Types.Date; const type = col.type; - if(type!=null&&type.name!=null){ - value = this.transformHandle(value,type.name,type.format); + if (type != null && type.name != null) { + value = this.transformHandle(value, type.name, type.format); } return value; } - private transformHandle(value:any,type: Types,format:any):any{ - switch(type){ + private transformHandle(value: any, type: Types, format: any): any{ + switch (type) { case Types.Date: - return this.dateService.date_format(value,format); + return this.dateService.date_format(value, format); } } } \ No newline at end of file diff --git a/src/app/core/services/example.service.ts b/src/app/core/services/example.service.ts index 823a581..9d32660 100644 --- a/src/app/core/services/example.service.ts +++ b/src/app/core/services/example.service.ts @@ -1,23 +1,22 @@ import { Injectable } from '@angular/core'; -import { Column } from '@core/entity/grid'; export class Criteria{ - private static CONDITION_SPLIT = "||"; + private static CONDITION_SPLIT = '||'; private conditions: string[] = []; public getConditions(): string[]{ return this.conditions; } public addCondition(condition: string,colName:string,...values: any[]){ - const split = Criteria.CONDITION_SPLIT;//'||' + const split = Criteria.CONDITION_SPLIT; // '||' this.conditions.push(condition+split+colName+split+ values.join(split)); } - public andLike(col:Column): Criteria{ + public andLike(col: { name: string, value: any}): Criteria{ this.addCondition('andLike',col.name,col.value); return this; } - public andEqualTo(col:Column): Criteria{ + public andEqualTo(col: { name: string, value: any}): Criteria{ this.addCondition('andEqualTo',col.name,col.value); return this; } diff --git a/src/app/routes/devices/devices.module.ts b/src/app/routes/devices/devices.module.ts index efa7913..3e17229 100644 --- a/src/app/routes/devices/devices.module.ts +++ b/src/app/routes/devices/devices.module.ts @@ -12,6 +12,7 @@ import { _HttpClient } from '@delon/theme/services/http/http.client'; import { AddOrEditComponent } from './version/add-or-edit/add-or-edit.component'; import { PipeModule } from '@core/pipe/pipe.module'; +import { FormBuilder } from '@angular/forms'; const COMPONENTS_NOROUNT = [ AddOrEditComponent ]; @@ -28,7 +29,7 @@ @NgModule({ imports: [ - //������������������������������������ + // ������������������������������������ PipeModule, CommonModule, SharedModule, @@ -38,10 +39,9 @@ BasicInfoComponent, VersionComponent, MonitorPointComponent, - ...COMPONENTS_NOROUNT, - AddOrEditComponent + ...COMPONENTS_NOROUNT ], - providers: [ToolsService, VersionService, _HttpClient], + providers: [ToolsService, VersionService, _HttpClient, FormBuilder], entryComponents: COMPONENTS_NOROUNT }) export class DevicesModule { } diff --git a/src/app/routes/devices/version/add-or-edit/add-or-edit.component.html b/src/app/routes/devices/version/add-or-edit/add-or-edit.component.html index 3ded8dc..fb9bb87 100644 --- a/src/app/routes/devices/version/add-or-edit/add-or-edit.component.html +++ b/src/app/routes/devices/version/add-or-edit/add-or-edit.component.html @@ -1,3 +1,45 @@ -<p> - add-or-edit works! -</p> +<div class="modal-header"> + <div class="modal-title">{{ data.id != null ? '������' : '������'}} - ������������</div> +</div> +<form [formGroup]="validateForm" (ngSubmit)="save($event,validateForm.value,validateForm.valid)" nz-form [nzType]="'horizontal'"> + <div nz-form-item nz-row class="mb-sm"> + <div nz-form-label nz-col [nzSm]="4" [nzXs]="24"> + <label nz-form-item-required>{{ cols.name.text }}</label> + </div> + <div nz-form-control nz-col [nzSpan]="6" nzHasFeedback> + <input nz-input formControlName="{{ cols.name.name }}" maxlength="20" /> + </div> + <div nz-form-label nz-col [nzSpan]="4"> + <label nz-form-item-required> + {{ cols.version.text }} + </label> + </div> + <div nz-form-control nz-col [nzSpan]="3" nzHasFeedback> + <nz-input-number formControlName="{{ cols.version.name }}" [nzMin]="1" [nzMax]="100" [nzStep]="1"> + </nz-input-number> + </div> + </div> + <div nz-form-item nz-row class="mb-sm"> + <div nz-form-label nz-col [nzSm]="4" [nzXs]="24"> + <label nz-form-item-required>{{ cols.createTime.text }}</label> + </div> + <div nz-form-control nz-col [nzSpan]="6" nzHasFeedback> + <nz-datepicker formControlName="{{ cols.createTime.name }}" nzShowTime [nzPlaceHolder]="'������������'" + [nzFormat]="'YYYY-MM-DD HH:mm:ss'" ></nz-datepicker> + </div> + <div nz-form-label nz-col [nzSpan]="4"> + <label>{{ cols.description.text }}</label> + </div> + <div nz-form-control nz-col [nzSpan]="8" nzHasFeedback> + <input nz-input formControlName="{{ cols.description.name }}" maxlength="20" /> + </div> + </div> + <div class="modal-footer"> + <button nz-button type="button" (click)="close()">������</button> + <button nz-button [nzType]="'primary'" [nzLoading]="isSaving"> + <span > + ������<span *ngIf="isSaving" >���</span> + </span> + </button> + </div> +</form> \ No newline at end of file diff --git a/src/app/routes/devices/version/add-or-edit/add-or-edit.component.ts b/src/app/routes/devices/version/add-or-edit/add-or-edit.component.ts index ca244f8..b875876 100644 --- a/src/app/routes/devices/version/add-or-edit/add-or-edit.component.ts +++ b/src/app/routes/devices/version/add-or-edit/add-or-edit.component.ts @@ -1,4 +1,9 @@ +import { DeviceVersion } from './../version.component'; import { Component, OnInit } from '@angular/core'; +import { HttpClient } from '@angular/common/http'; +import { NzMessageService, NzModalSubject } from 'ng-zorro-antd'; +import { DateService } from '@core/services/date.service'; +import { FormGroup, FormBuilder, Validators } from '@angular/forms'; @Component({ selector: 'app-add-or-edit', @@ -6,10 +11,49 @@ styles: [] }) export class AddOrEditComponent implements OnInit { + + cols: DeviceVersion; - constructor() { } + data: DeviceVersion; + isSaving = false; + validateForm: FormGroup; + constructor( + private subject: NzModalSubject, + private formBuilder: FormBuilder + ) { } ngOnInit() { + const validates: DeviceVersion = { + name: [this.data.name, [Validators.required] ], + version: [this.data.version == null ? 1 : this.data.version, [Validators.required] ], + createTime: [this.data.createTime, [Validators.required] ], + description: [this.data.description, [Validators.required] ] + }; + this.validateForm = this.formBuilder.group( + validates + ); } - + close() { + this.subject.destroy(); + } + save($event, value, valid) { + $event.preventDefault(); + if (valid) { + for (const i in this.validateForm.controls) { + this.validateForm.controls[ i ].disable(); + } + this.isSaving = true; + this.data = value; + this.subject.next( this ); + }else { + for (const i in this.validateForm.controls) { + this.validateForm.controls[ i ].markAsDirty(); + } + } + } + validate() { + for (const i in this.validateForm.controls) { + this.validateForm.controls[ i ].markAsDirty(); + } + } } diff --git a/src/app/routes/devices/version/version.component.html b/src/app/routes/devices/version/version.component.html index 9dc93f3..69d1282 100644 --- a/src/app/routes/devices/version/version.component.html +++ b/src/app/routes/devices/version/version.component.html @@ -1,11 +1,11 @@ <pro-header [title]="grid.title"></pro-header> <nz-card [nzBordered]="false"> <div class="mb-md"> - <button nz-button (click)="add()" [nzType]="'primary'" [nzSize]="'large'"> + <button nz-button (click)="addOrModify()" [nzType]="'primary'" [nzSize]="'large'"> <i class="anticon anticon-plus"></i><span>������</span> </button> <ng-container *ngIf="grid.selectedIndexs.length > 0"> - <button nz-button [nzSize]="'large'" (click)="remove()">������������</button> + <button nz-button [nzSize]="'large'" (click)="deleteSelected()">������������</button> </ng-container> <nz-input [ngStyle]="{'width': '280px','float':'right'}" [(ngModel)]="queryMap.value" name="" [nzPlaceHolder]="queryMap.text" (keyup)="queryTextChanged($event)" (change)="queryTextChanged($event)" ></nz-input> @@ -22,7 +22,7 @@ [nzTotal]="grid.total" [(nzPageIndex)]="grid.pageIndex" [(nzPageSize)]="grid.pageSize" - [nzLoading]="http.loading" + [nzLoading]="versionService.loading" [nzShowTotal]="true" (nzPageIndexChange)="load()" (nzDataChange)="dataChange($event)"> @@ -35,6 +35,7 @@ [ngStyle]="{'width':col.width,'text-align':col['align'] === undefined?'left':col.align}" > <span>{{ col.text }}</span> </th> + <th nz-th><span>������</span></th> </tr> </thead> <tbody nz-tbody> @@ -50,6 +51,13 @@ <!-- ������������������������������������ --> </span> </td> + <td nz-td> + <a (click)="addOrModify(row)">������</a> + <span nz-table-divider></span> + <nz-popconfirm [nzTitle]="'���������������������������?'" [nzOkText]="'Yes'" [nzCancelText]="'No'" (nzOnConfirm)="delete(row.id)" > + <a nz-popconfirm>������</a> + </nz-popconfirm> + </td> </tr> </tbody> </nz-table> diff --git a/src/app/routes/devices/version/version.component.ts b/src/app/routes/devices/version/version.component.ts index 72fddc4..b6f9849 100644 --- a/src/app/routes/devices/version/version.component.ts +++ b/src/app/routes/devices/version/version.component.ts @@ -1,8 +1,10 @@ +import { DataType } from './../../../core/entity/grid'; +import { AddOrEditComponent } from './add-or-edit/add-or-edit.component'; +import { Version } from '@angular/compiler/src/util'; import { Subject } from 'rxjs/Subject'; -import '../../../rxjs-operators'; import { ToolsService } from '@core/services/tools.service'; import { Component, OnInit } from '@angular/core'; -import { NzMessageService } from 'ng-zorro-antd'; +import { NzMessageService, NzModalService } from 'ng-zorro-antd'; import { ModalHelper } from '@delon/theme'; import { HttpClient } from '@angular/common/http'; import { environment } from '../../../../environments/environment'; @@ -11,12 +13,12 @@ import { Types } from '@core/enum/types.enum'; import { Column, Grid, PageBean } from '@core/entity/grid'; -interface DeviceVersion { - createTime: Column; - description: Column; - id?: Column; - name: Column; - version: Column; +export interface DeviceVersion { + createTime?: Column|any; + description?: Column|any; + id?: Column|any; + name?: Column|any; + version?: Column|any; } @Component({ selector: 'app-version', @@ -24,23 +26,23 @@ styles: [] }) export class VersionComponent implements OnInit { - - grid: Grid = new Grid(null); + private version: DeviceVersion; + grid: Grid<DeviceVersion> = new Grid(null); queryMap = { text: '������������������������', value: ''}; queryTextStream: Subject<string> = new Subject<string>(); private initPage() { - const columns: DeviceVersion = { + this.version = { name: { text: '������', - width: '22%' + width: '18%' }, version: { text: '������', - width: '22%' + width: '18%' }, createTime: { text: '������������', - width: '22%', + width: '18%', type: { name: Types.Date, format: 'YYYY-MM-DD HH:mm:ss' @@ -48,20 +50,20 @@ }, description: { text: '������', - width: '22%' + width: '18%' } }; this.grid.title = '������������'; - this.grid.setColumns(columns); + this.grid.setColumns(this.version); this.grid.pageSize = 10; } constructor( - public http: HttpClient, private versionService: VersionService, - public dateSrv: DateService, + + private confirmServ: NzModalService, public msgSrv: NzMessageService, private modalHelper: ModalHelper, - private toolsService: ToolsService) {} + ) {} ngOnInit() { this.initPage(); @@ -95,24 +97,53 @@ // this.msgSrv.success('���������������������������'); // }); } - - add() { - // const user = {}; - // this.modalHelper.static(VersionEditComponent, { user }).subscribe(() => { - // this.load(true); - // this.msgSrv.success('���������������������������'); - // }); - } - - delete(user) { - this.http.delete(environment.SERVER_BASH_URL + '/user/operate_user/' + user.id).subscribe((res: any) => { - this.msgSrv.success('���������������������������'); - this.load(true); +// rowData���null��������������� + addOrModify(data) { + if ( data == null) { + data = {}; + } + const cols = this.version; + this.modalHelper.static(AddOrEditComponent, { cols , data }).subscribe( + ( ret: { data: any, close: Function} ) => { + this.versionService.save(ret.data).subscribe( + ( res: any) => { + if (res.code === 1) { + this.load(true); + ret.close(); + this.msgSrv.success('���������������������������'); + } + } + ); }); } - remove() { + delete(...id: number[]) { + this.versionService.delete( ...id ).subscribe( + ( res: any) => { + if (res.code === 1) { + this.load(true); + this.msgSrv.success('���������������������������'); + } + } + ); + } + deleteSelected() { + this.confirmServ.confirm({ + title: '������������', + content: '������������������������������������������������', + okText: '������', + cancelText: '������' + }).on('onOk', () => { + if (this.grid.selectedIndexs != null && this.grid.selectedIndexs.length > 0) { + const ids = this.grid.selectedIndexs.map( + (index: number) => { + return Number.parseInt(this.grid.data[index].id); + } + ); + this.delete( ...ids ); + } + }); } diff --git a/src/app/routes/devices/version/version.service.ts b/src/app/routes/devices/version/version.service.ts index 43988c2..4b14382 100644 --- a/src/app/routes/devices/version/version.service.ts +++ b/src/app/routes/devices/version/version.service.ts @@ -1,4 +1,3 @@ -import { DeviceVersion } from './version.service'; import { ExampleService } from './../../../core/services/example.service'; import { _HttpClient } from '@delon/theme'; import { environment } from './../../../../environments/environment.prod'; @@ -9,19 +8,14 @@ import { PageBean } from '@core/entity/grid'; -export interface DeviceVersion { - createTime?: any; - description?: string; - id?: number; - name?: string; - version?: number; -} - @Injectable() export class VersionService { private urls = { - edit: environment.SERVER_BASH_URL + '/device-version/page-list' + edit: environment.SERVER_BASH_URL + '/device-version/page-list', + save: environment.SERVER_BASH_URL + '/device-version/add-or-modify', + delete: environment.SERVER_BASH_URL + '/device-version/delete-by-ids' }; + public loading = this.http.loading; constructor(private http: _HttpClient) { } public getPagingList(page: PageBean, queryText: string): Observable<PageBean> { const example = new ExampleService(); @@ -32,4 +26,10 @@ const param: PageBean = {pageSize: page.pageSize, pageIndex: page.pageIndex, queryParams: example.getSqlParam()}; return this.http.get(this.urls.edit, param); } + public save(data: any): Observable<any> { + return this.http.post(this.urls.save, data); + } + public delete(...ids: number[]): Observable<any> { + return this.http.post(this.urls.delete, ids); + } } diff --git a/src/app/rxjs-operators.ts b/src/app/rxjs-operators.ts deleted file mode 100644 index b1105b7..0000000 --- a/src/app/rxjs-operators.ts +++ /dev/null @@ -1,15 +0,0 @@ -// import 'rxjs/Rx'; // adds ALL RxJS statics & operators to Observable - -// See node_module/rxjs/Rxjs.js -// Import just the rxjs statics and operators we need for THIS app. - -// 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'; diff --git a/src/app/shared/shared.module.ts b/src/app/shared/shared.module.ts index 532f5c9..d2f88eb 100644 --- a/src/app/shared/shared.module.ts +++ b/src/app/shared/shared.module.ts @@ -17,6 +17,16 @@ import { I18NService } from '@core/i18n/i18n.service'; // region: zorro modules +// 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 { // LoggerModule, -- Gitblit v1.8.0