From 3517e796f650b8aed52165c1a5905456f54033ef Mon Sep 17 00:00:00 2001 From: fengxiang <110431245@qq.com> Date: Wed, 10 Jan 2018 14:31:40 +0800 Subject: [PATCH] 项目路径 配置,以适应可能的框架更新 --- src/app/routes/sensors/basic-info/basic-info.component.ts | 162 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 161 insertions(+), 1 deletions(-) diff --git a/src/app/routes/sensors/basic-info/basic-info.component.ts b/src/app/routes/sensors/basic-info/basic-info.component.ts index 434f272..e53d4f6 100644 --- a/src/app/routes/sensors/basic-info/basic-info.component.ts +++ b/src/app/routes/sensors/basic-info/basic-info.component.ts @@ -1,4 +1,14 @@ +import { NzModalService, NzMessageService } from 'ng-zorro-antd'; +import { PageBean } from '@business/entity/grid'; +import { Sensor } from '@business/entity/data'; +import { ModalHelper } from '@delon/theme'; +import { SensorsService } from '@business/services/http/sensors.service'; +import { Column, Grid } from '@business/entity/grid'; import { Component, OnInit } from '@angular/core'; +import { Subject } from 'rxjs/Subject'; +import { SensorEditComponent } from './sensor-edit/sensor-edit.component'; + + @Component({ selector: 'app-basic-info', @@ -7,9 +17,159 @@ }) export class BasicInfoComponent implements OnInit { - constructor() { } + + grid: Grid<Sensor> = new Grid(null); + queryMap = { text: '���������������', value: ''}; + queryTextStream: Subject<string> = new Subject<string>(); + private initPage() { + const sensor: Sensor = { + name: { + text: '������', + width: '200px' + }, + key: { + text: '������', + width: '60px' + }, + lower: { + text: '���������', + width: '90px' + }, + upper: { + text: '���������', + width: '90px' + }, + unit: { + text: '������', + width: '100px' + }, + description: { + text: '������' + } + }; + this.grid.title = '���������'; + this.grid.setColumns(sensor); + this.grid.pageSize = 10; + } + constructor( + private sensorsService: SensorsService, + + private confirmServ: NzModalService, + public msgSrv: NzMessageService, + private modalHelper: ModalHelper, + ) {} ngOnInit() { + this.initPage(); + this.queryTextStream + .debounceTime(500) + .distinctUntilChanged() + .subscribe(queryText => { + this.load(); + }); + } + queryTextChanged($event) { + this.queryTextStream.next(this.queryMap.value); + } + load(reload: boolean = false) { + if (reload) { + this.grid.pageIndex = 1 ; + } + // ������������������ExpressionChangedAfterItHasBeenCheckedError + setTimeout(() => { + this.grid.loading = true; + }, 1); + this.sensorsService.getPagingList(this.grid, this.queryMap.value).subscribe( + (res: PageBean) => { + this.grid.loading = true; + if (res != null && res.data != null) { + this.grid.initData(res); + this.grid.refreshStatus(); + setTimeout(() => { + this.grid.loading = false; + }, 1); + } + } + ); + } + +// rowData���null��������������� + addOrModify(d) { + const data = {}; + if ( d != null) { + Object.assign(data, d); + } + this.modalHelper.static(SensorEditComponent, { data }).subscribe( + ( ret: { data: any, close: Function} ) => { + // ������������ + if (ret.data['index'] != null ) { + const index: number = ret.data['index'] ; + const origData = this.grid.getData()[index]; + const isModified = Object.keys(origData).some( + (key: string) => { + return ret.data[key] !== origData[key]; + } + ); + // ������������ + if (!isModified) { + ret.close(); + this.msgSrv.success(this.grid.title + '���������������������'); + return; + } + } + this.sensorsService.save(ret.data).subscribe( + ( res: any) => { + if (res.code === 1) { + this.load(); + ret.close(); + this.msgSrv.success(this.grid.title + '���������������'); + } + } + ); + }); + } + + delete(...id: number[]) { + this.sensorsService.delete( ...id ).subscribe( + ( res: any) => { + if (res.code === 1) { + this.load(); + this.msgSrv.success(this.grid.title + '���������������'); + } + } + ); + } + + 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) => { + const id = this.grid.data[index].id; + return Number.parseInt(id); + } + ); + this.delete( ...ids ); + } + }); + } + sort(field: string, value: string) { + // ������������field + this.grid.sorts = this.grid.sorts.filter( + (fn: string) => { + return fn !== field; + } + ); + // ������value������null������������������������������filed + if ( value != null ) { + this.grid.sorts.push(field); + } + this.load(); } } -- Gitblit v1.8.0