src/app/core/entity/grid.ts
@@ -13,7 +13,7 @@ sort?: string; isSort?: boolean; type?: DataType; format?: Function; format?: (value: any, col: Column, row: any) => string; } export interface DataType { name: Types; src/app/routes/devices/devices.module.ts
@@ -1,3 +1,4 @@ import { MonitorPointService } from 'app/routes/devices/monitor-point/monitor-point.service'; import { ToolsService } from './../../core/services/tools.service'; import { NgModule } from '@angular/core'; @@ -13,8 +14,9 @@ import { PipeModule } from '@core/pipe/pipe.module'; import { FormBuilder } from '@angular/forms'; import { VersionEditComponent } from './version/version-edit/version-edit.component'; import { MonitorPointEditComponent } from './monitor-point/monitor-point-edit/monitor-point-edit.component'; const COMPONENTS_NOROUNT = [ VersionEditComponent ]; const COMPONENTS_NOROUNT = [ VersionEditComponent, MonitorPointEditComponent ]; const routes: Routes = [ { @@ -39,9 +41,9 @@ BasicInfoComponent, VersionComponent, MonitorPointComponent, ...COMPONENTS_NOROUNT ...COMPONENTS_NOROUNT ], providers: [ToolsService, VersionService, _HttpClient, FormBuilder], providers: [ToolsService, VersionService, MonitorPointService, _HttpClient, FormBuilder], entryComponents: COMPONENTS_NOROUNT }) export class DevicesModule { } src/app/routes/devices/monitor-point/monitor-point-edit/monitor-point-edit.component.html
New file @@ -0,0 +1,3 @@ <p> monitor-point-edit works! </p> src/app/routes/devices/monitor-point/monitor-point-edit/monitor-point-edit.component.ts
New file @@ -0,0 +1,15 @@ import { Component, OnInit } from '@angular/core'; @Component({ selector: 'app-monitor-point-edit', templateUrl: './monitor-point-edit.component.html', styles: [] }) export class MonitorPointEditComponent implements OnInit { constructor() { } ngOnInit() { } } src/app/routes/devices/monitor-point/monitor-point.component.html
@@ -1,3 +1,66 @@ <p> monitor-point works! </p> <pro-header [title]="grid.title"></pro-header> <nz-card [nzBordered]="false"> <div class="mb-md"> <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)="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> </div> <div class="mb-md"> <nz-alert *ngIf="grid.selectedIndexs.length > 0" [nzType]="'info'" [nzShowIcon]="true"> <span alert-body> 已选择<strong class="text-primary">{{grid.selectedIndexs.length}}</strong>项 </span> </nz-alert> </div> <nz-table #nzTable [nzAjaxData]="grid.data" [nzTotal]="grid.total" [(nzPageIndex)]="grid.pageIndex" [(nzPageSize)]="grid.pageSize" [nzLoading]="grid.loading" [nzShowTotal]="true" (nzPageIndexChange)="load()"> <thead nz-thead> <tr> <th nz-th [nzCheckbox]="true"> <label nz-checkbox [(ngModel)]="grid.allChecked" [nzIndeterminate]="grid.indeterminate" (ngModelChange)="grid.checkAll($event)"></label> </th> <th nz-th *ngFor="let col of grid.columns" [ngStyle]="{'width':col.width,'text-align':col['align'] === undefined?'left':col.align}" > <span>{{ col.text }}</span> <nz-table-sort *ngIf="col.isSort" [(nzValue)]="col.sort" (nzValueChange)="sort(col.name,$event)"></nz-table-sort> </th> <th nz-th><span>操作</span></th> </tr> </thead> <tbody nz-tbody> <tr nz-tbody-tr *ngFor="let row of nzTable.data"> <td nz-td [nzCheckbox]="true"> <label nz-checkbox [(ngModel)]="row.checked" (ngModelChange)="grid.refreshStatus($event)"></label> </td> <td nz-td *ngFor="let col of grid.columns" [ngStyle]="{'width':col.width,'text-align':col['align'] === undefined?'left':col.align}"> <span [ngSwitch]="col.type"> <!-- 要使用管道,无法自动生成 --> <span *ngSwitchDefault> {{ row[col.name]|tyepHandle:col:row }} </span> <!-- 要使用管道,无法自动生成 --> </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> </nz-card> src/app/routes/devices/monitor-point/monitor-point.component.ts
@@ -1,5 +1,33 @@ import { DataType, AreaNames } from './../../../core/entity/grid'; import { Version, ValueTransformer } from '@angular/compiler/src/util'; import { Subject } from 'rxjs/Subject'; import { ToolsService } from '@core/services/tools.service'; import { Component, OnInit } from '@angular/core'; import { NzMessageService, NzModalService } from 'ng-zorro-antd'; import { ModalHelper } from '@delon/theme'; import { HttpClient } from '@angular/common/http'; import { environment } from '../../../../environments/environment'; import { DateService } from '@core/services/date.service'; import { VersionService } from 'app/routes/devices/version/version.service'; import { Types } from '@core/enum/types.enum'; import { Column, Grid, PageBean } from '@core/entity/grid'; import { filter } from 'rxjs/operators/filter'; import { MonitorPointEditComponent } from 'app/routes/devices/monitor-point/monitor-point-edit/monitor-point-edit.component'; import { MonitorPointService } from 'app/routes/devices/monitor-point/monitor-point.service'; interface MonitorPoint { address?: any|Column; areaCode?: any|Column; cityCode?: any|Column; description?: any|Column; id?: any|Column; isDelete?: any|Column; latitude?: any|Column; longitude?: any|Column; name?: any|Column; organizationId?: any|Column; provinceCode?: any|Column; } @Component({ selector: 'app-monitor-point', templateUrl: './monitor-point.component.html', @@ -7,9 +35,147 @@ }) export class MonitorPointComponent implements OnInit { constructor() { } private organization: MonitorPoint; grid: Grid<MonitorPoint> = new Grid(null); queryMap = { text: '请输入名称', value: ''}; queryTextStream: Subject<string> = new Subject<string>(); private initPage() { this.organization = { name: { text: '名称', width: '120px' } }; this.grid.title = '设备型号'; this.grid.setColumns(this.organization); this.grid.pageSize = 10; } constructor( private monitorPointService: MonitorPointService, 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.monitorPointService.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); } const cols = this.organization; this.modalHelper.static(MonitorPointEditComponent, { cols , 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('组织未作任何修改!'); return; } } this.monitorPointService.save(ret.data).subscribe( ( res: any) => { if (res.code === 1) { this.load(); ret.close(); this.msgSrv.success('组织保存成功!'); } } ); }); } delete(...id: number[]) { this.monitorPointService.delete( ...id ).subscribe( ( res: any) => { if (res.code === 1) { this.load(); 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) => { 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(); } reset(ls: any[]) { for (const item of ls) item.value = false; this.load(true); } } src/app/routes/devices/monitor-point/monitor-point.service.ts
New file @@ -0,0 +1,35 @@ import { ExampleService } from './../../../core/services/example.service'; import { _HttpClient } from '@delon/theme'; import { environment } from './../../../../environments/environment.prod'; import { RouteConfigLoadStart } from '@angular/router'; import { Injectable } from '@angular/core'; import { equal } from 'assert'; import { Observable } from 'rxjs/Observable'; import { PageBean } from '@core/entity/grid'; @Injectable() export class MonitorPointService { private urls = { edit: environment.SERVER_BASH_URL + '/monitor-point/page-list', save: environment.SERVER_BASH_URL + '/monitor-point/add-or-modify', delete: environment.SERVER_BASH_URL + '/monitor-point/delete-by-ids' }; constructor(private http: _HttpClient) { } public getPagingList(page: PageBean, queryText: string): Observable<PageBean> { const example = new ExampleService(); if (queryText != null && queryText !== '') { example.or().andLike({name: 'name', value: '%' + queryText + '%'}); } const param: PageBean = {pageSize: page.pageSize, pageIndex: page.pageIndex, queryParams: example.getSqlParam(), orderByClause: page.getOrderByClause()}; 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); } } src/app/routes/devices/version/version.service.ts
@@ -1,6 +1,6 @@ import { ExampleService } from './../../../core/services/example.service'; import { _HttpClient } from '@delon/theme'; import { environment } from './../../../../environments/environment.prod'; import { environment } from './../../../../environments/environment'; import { RouteConfigLoadStart } from '@angular/router'; import { Injectable } from '@angular/core'; import { equal } from 'assert'; @@ -20,6 +20,7 @@ const example = new ExampleService(); if (queryText != null && queryText !== '') { example.or().andLike({name: 'name', value: '%' + queryText + '%'}); example.or().andEqualTo({name: 'version', value: queryText}); } const param: PageBean = {pageSize: page.pageSize, pageIndex: page.pageIndex, queryParams: example.getSqlParam(), orderByClause: page.getOrderByClause()}; src/app/routes/systems/organization/organization.component.ts
@@ -51,7 +51,20 @@ }, rank: { text: '级别', width: '60px' width: '80px', format: (value: any, col: Column, row: any) => { const item = [ { value: 0, label: '企业' }, { value: 1, label: '乡镇科级' }, { value: 2, label: '县处级' }, { value: 3, label: '司厅局级' }, { value: 4, label: '省部级' }, { value: 5, label: '国家级' } ].filter( (rankItem: {value: number, label: string }) => { return rankItem.value === value; }); return item != null && item.length === 1 ? item[0].label : ''; } }, telephone: { text: '电话', src/app/routes/systems/organization/organization.service.ts
@@ -1,6 +1,6 @@ import { ExampleService } from './../../../core/services/example.service'; import { _HttpClient } from '@delon/theme'; import { environment } from './../../../../environments/environment.prod'; import { environment } from './../../../../environments/environment'; import { RouteConfigLoadStart } from '@angular/router'; import { Injectable } from '@angular/core'; import { equal } from 'assert'; @@ -20,7 +20,6 @@ const example = new ExampleService(); if (queryText != null && queryText !== '') { example.or().andLike({name: 'name', value: '%' + queryText + '%'}); example.or().andEqualTo({name: 'version', value: queryText}); } const param: PageBean = {pageSize: page.pageSize, pageIndex: page.pageIndex, queryParams: example.getSqlParam(), orderByClause: page.getOrderByClause()};