From 8ac3a87733b421c1f1cb3b691f946c05bdae02df Mon Sep 17 00:00:00 2001 From: fengxiang <110431245@qq.com> Date: Fri, 06 Jul 2018 13:54:14 +0800 Subject: [PATCH] 设备,监控点维护 完善 --- src/app/routes/map/coordinates-picker/coordinates-picker.component.html | 4 src/app/routes/devices/basic-info/basic-info.component.ts | 56 ++++++++++++- yarn.lock | 8 + src/app/business/entity/grid.ts | 4 src/app/core/net/default.interceptor.ts | 30 ++++--- package.json | 2 src/app/business/services/http/device.service.ts | 29 ------- src/app/routes/devices/monitor-point/monitor-point-edit/monitor-point-edit.component.ts | 2 src/app/routes/devices/basic-info/device-edit/device-edit.component.html | 7 - src/app/routes/map/coordinates-picker/coordinates-picker.component.ts | 70 ++++++++++++++--- src/app/routes/devices/basic-info/device-edit/device-edit.component.ts | 9 +- 11 files changed, 143 insertions(+), 78 deletions(-) diff --git a/package.json b/package.json index 18af71a..0ca5c08 100644 --- a/package.json +++ b/package.json @@ -54,7 +54,7 @@ "angular-qq-maps": "^1.0.1", "angular-split": "^1.0.0-rc.0", "angular-tree-component": "^7.0.1", - "angular2-baidu-map": "^4.1.0", + "angular2-baidu-map": "^4.3.2", "core-js": "^2.5.1", "echarts": "^4.0.4", "file-saver": "^1.3.3", diff --git a/src/app/business/entity/grid.ts b/src/app/business/entity/grid.ts index 5992378..b6f908c 100644 --- a/src/app/business/entity/grid.ts +++ b/src/app/business/entity/grid.ts @@ -66,8 +66,10 @@ this.data = pageData.data.map(row => { row['index'] = index++; return row; - }); + }); this.total = pageData.total; + const pages = Math.ceil(this.total / this.pageSize); + this.pageIndex = this.pageIndex > pages ? pages : this.pageIndex; } } refreshStatus() { diff --git a/src/app/business/services/http/device.service.ts b/src/app/business/services/http/device.service.ts index 83c70d2..31de514 100644 --- a/src/app/business/services/http/device.service.ts +++ b/src/app/business/services/http/device.service.ts @@ -17,34 +17,7 @@ public getListUrl () { return this.urls.list; } - public getSqlParams(queryMap: {[key: string]: number|string}) { - const example = new ExampleService(); - const orgId = !!queryMap.orgId ? queryMap.orgId : null; - const mpointId = !!queryMap.mpointId ? queryMap.mpointId : null; - const devMacOrName = !!queryMap.devMacOrName && !!(<string>queryMap.devMacOrName).trim() ? queryMap.devMacOrName : null; - let criWithMac: Criteria = null; - let criWithName: Criteria = null; - if (!!devMacOrName) { - criWithName = example.or().andLike({name: 'name', value: '%' + devMacOrName + '%'}); - criWithMac = example.or().andLike({name: 'mac', value: '%' + devMacOrName + '%'}); - } - if (!!mpointId) { - if (!!devMacOrName) { - criWithName.andEqualTo({name: 'monitorPointId', value: mpointId}); - criWithMac.andEqualTo({name: 'monitorPointId', value: mpointId}); - }else { - example.or().andEqualTo({name: 'monitorPointId', value: mpointId}); - } - } else if (!!orgId) { - if (!!devMacOrName) { - criWithName.andCondition(`monitor_point_id in (select id from monitor_point where organization_id = ${orgId})`); - criWithMac.andCondition(`monitor_point_id in (select id from monitor_point where organization_id = ${orgId})`); - }else { - example.or().andCondition(`monitor_point_id in (select id from monitor_point where organization_id = ${orgId})`); - } - } - return example.getSqlParam(); - } + constructor(private http: _HttpClient) { } delete(...ids: number[]): Observable< ResultBean<any> > { return this.http.post(this.urls.delete, ids); diff --git a/src/app/core/net/default.interceptor.ts b/src/app/core/net/default.interceptor.ts index 2a3a6dc..982d562 100644 --- a/src/app/core/net/default.interceptor.ts +++ b/src/app/core/net/default.interceptor.ts @@ -29,27 +29,29 @@ () => !isExpireModelShow ).subscribe( (event: HttpErrorResponse) => { isExpireModelShow = true; - if (!!event.error) { - let errorMsg = ''; + let errorMsg = ''; + if (!!event && !!event.error) { const erroCode = !!event.error['errorCode'] ? Number.parseInt(event.error['errorCode']) : 0; switch (erroCode) { case 10: errorMsg = '���������,���������'; break; case 11: errorMsg = '������������,���������������'; break; case 12: errorMsg = '������������,������������������'; break; - case 0: errorMsg = '���������������������������'; break; + case 0: errorMsg = '���������������������������'; break; default: errorMsg = '������������,���������������'; break; } - // ������refresh��������������������� - this.loginService.clearRefreshToken(); - this.model.info({ - maskClosable: false, - title: errorMsg, - onOk: () => { - isExpireModelShow = false; - this.goTo('/passport/login'); - } - }); - } + }else { + errorMsg = '���������������������������'; + } + // ������refresh��������������������� + this.loginService.clearRefreshToken(); + this.model.info({ + maskClosable: false, + title: errorMsg, + onOk: () => { + isExpireModelShow = false; + this.goTo('/passport/login'); + } + }); }); } get loginService(): LoginService { diff --git a/src/app/routes/devices/basic-info/basic-info.component.ts b/src/app/routes/devices/basic-info/basic-info.component.ts index 43c8723..6dabdca 100644 --- a/src/app/routes/devices/basic-info/basic-info.component.ts +++ b/src/app/routes/devices/basic-info/basic-info.component.ts @@ -2,17 +2,17 @@ import { CoorPicker, Device } from '@business/entity/data'; import { AdjustConfigComponent } from './adjust-config/adjust-config.component'; import { DeviceEditComponent } from './device-edit/device-edit.component'; -import { ModalHelper } from '@delon/theme'; +import { ModalHelper, _HttpClient } from '@delon/theme'; import { NzModalService, NzMessageService } from 'ng-zorro-antd'; import { PageBean, ResultBean } from '@business/entity/grid'; import { DeviceService } from '@business/services/http/device.service'; import { Component, OnInit, ElementRef, ViewChild } from '@angular/core'; -import { SimpleTableColumn } from '@delon/abc'; +import { SimpleTableColumn, SimpleTableComponent } from '@delon/abc'; import { Subject } from 'rxjs/Subject'; import { CoordinatesPickerComponent } from 'app/routes/map/coordinates-picker/coordinates-picker.component'; import { CoorPickerService } from 'app/routes/map/coordinates-picker/coordinates-picker.service'; import { OrganizationService } from '@business/services/http/organization.service'; -import { ExampleService } from '@business/services/util/example.service'; +import { ExampleService, Criteria } from '@business/services/util/example.service'; @Component({ selector: 'app-basic-info', @@ -75,7 +75,8 @@ public msgSrv: NzMessageService, private modalHelper: ModalHelper, private coorPickerService: CoorPickerService, - private organizationService: OrganizationService + private organizationService: OrganizationService, + private http: _HttpClient ) { } ngOnInit() { @@ -115,9 +116,50 @@ }); } load() { - this.extraParams.queryParams = this.deviceService.getSqlParams(this.queryMap); + const example = this.initQueryExample(); + this.extraParams.queryParams = example.getSqlParam(); this.selectedRows = []; - this.simpleTable.load(); + this.deviceService.countByExample(example).subscribe( + res => { + if (!!res && !!res.code) { + setTimeout(() => { + const count = res.data; + const pages = Math.ceil(count / this.simpleTable.ps); + const pi = this.simpleTable.pi > pages ? pages : this.simpleTable.pi; + this.simpleTable.load(pi); + }, 1); + } + } + ); + + } + private initQueryExample() { + const example = new ExampleService(); + const orgId = !!this.queryMap.orgId ? this.queryMap.orgId : null; + const mpointId = !!this.queryMap.mpointId ? this.queryMap.mpointId : null; + const devMacOrName = !!this.queryMap.devMacOrName && !!(<string>this.queryMap.devMacOrName).trim() ? this.queryMap.devMacOrName : null; + let criWithMac: Criteria = null; + let criWithName: Criteria = null; + if (!!devMacOrName) { + criWithName = example.or().andLike({name: 'name', value: '%' + devMacOrName + '%'}); + criWithMac = example.or().andLike({name: 'mac', value: '%' + devMacOrName + '%'}); + } + if (!!mpointId) { + if (!!devMacOrName) { + criWithName.andEqualTo({name: 'monitorPointId', value: mpointId}); + criWithMac.andEqualTo({name: 'monitorPointId', value: mpointId}); + }else { + example.or().andEqualTo({name: 'monitorPointId', value: mpointId}); + } + } else if (!!orgId) { + if (!!devMacOrName) { + criWithName.andCondition(`monitor_point_id in (select id from monitor_point where organization_id = ${orgId})`); + criWithMac.andCondition(`monitor_point_id in (select id from monitor_point where organization_id = ${orgId})`); + }else { + example.or().andCondition(`monitor_point_id in (select id from monitor_point where organization_id = ${orgId})`); + } + } + return example; } delete(...id: number[]) { this.deviceService.delete(...id).subscribe( @@ -129,7 +171,7 @@ } ); } - @ViewChild('simpleTable') simpleTable: { load: Function }; + @ViewChild('simpleTable') simpleTable: SimpleTableComponent; queryTextChanged(event) { this.queryTextStream.next(this.queryText); } diff --git a/src/app/routes/devices/basic-info/device-edit/device-edit.component.html b/src/app/routes/devices/basic-info/device-edit/device-edit.component.html index e9400e4..fa89a42 100644 --- a/src/app/routes/devices/basic-info/device-edit/device-edit.component.html +++ b/src/app/routes/devices/basic-info/device-edit/device-edit.component.html @@ -38,7 +38,7 @@ </div> <div nz-form-item nz-row class="mb-sm"> <div nz-form-label nz-col [nzSm]="4" [nzXs]="24"> - <label>������������</label> + <label nz-form-item-required>������������</label> </div> <div nz-form-control nz-col [nzSpan]="7" nzHasFeedback> <nz-select formControlName="deviceVersionId" [nzPlaceHolder]="'������ ������(������������������)'" @@ -76,11 +76,10 @@ </div> <div nz-form-item nz-row class="mb-sm"> <div nz-form-label nz-col [nzSm]="4" [nzXs]="24"> - <label>������������</label> + <label nz-form-item-required>������������</label> </div> <div nz-form-control nz-col [nzSpan]="7" nzHasFeedback> - <nz-select formControlName="monitorPointId" [nzPlaceHolder]="'������ ������������(������������������)'" - nzAllowClear [nzFilter]="false" nzShowSearch (nzSearchChange)="monitorPointChange($event)" [nzNotFoundContent]="'������������'" > + <nz-select formControlName="monitorPointId" [nzPlaceHolder]="'������ ������������(������������������)'" nzAllowClear [nzFilter]="false" nzShowSearch (nzSearchChange)="monitorPointChange($event)" [nzNotFoundContent]="'������������'" > <nz-option *ngFor="let option of monitorPoints" [nzLabel]="option.name" [nzValue]="option.id" [nzDisabled]="option.disabled"> </nz-option> </nz-select> diff --git a/src/app/routes/devices/basic-info/device-edit/device-edit.component.ts b/src/app/routes/devices/basic-info/device-edit/device-edit.component.ts index fe4d7da..f6f821c 100644 --- a/src/app/routes/devices/basic-info/device-edit/device-edit.component.ts +++ b/src/app/routes/devices/basic-info/device-edit/device-edit.component.ts @@ -7,7 +7,6 @@ import { DeviceService } from '@business/services/http/device.service'; import { Component, OnInit } from '@angular/core'; import { Device, MonitorPoint} from '@business/entity/data'; -import { _Validators } from '@delon/abc'; import { PageBean, ResultBean } from '@business/entity/grid'; import { _HttpClient } from '@delon/theme'; import { environment } from '@env/environment'; @@ -67,8 +66,8 @@ const validates: Device = { name: [data.name, [Validators.required]], mac: [data.mac, [Validators.required], [this.macAsyncValidator]], - deviceVersionId: [data.deviceVersionId], - monitorPointId: [data.monitorPointId], + deviceVersionId: [data.deviceVersionId, [Validators.required]], + monitorPointId: [data.monitorPointId, [Validators.required]], professionId: [data.professionId], operateUserId: [data.operateUserId], address: [data.address], @@ -137,10 +136,10 @@ const pageBean: PageBean = {pageIndex: 0, pageSize: 100}; const orgId = this.configMap.orgId; const example = new ExampleService(); - text = !!text && !!text.trim() ? text : null; + text = !!text && !!text.trim() ? '%' + text + '%' : null; example.or() .andEqualTo({name: 'organizationId', value: this.configMap.orgId}) - .andEqualTo({name: 'name', value: text}); + .andLike({name: 'name', value: text}); this.monitorPointService.getPageByExample(pageBean, example).subscribe( (res: PageBean) => { if (res != null && res.data != null) { diff --git a/src/app/routes/devices/monitor-point/monitor-point-edit/monitor-point-edit.component.ts b/src/app/routes/devices/monitor-point/monitor-point-edit/monitor-point-edit.component.ts index 8fafe6e..669a144 100644 --- a/src/app/routes/devices/monitor-point/monitor-point-edit/monitor-point-edit.component.ts +++ b/src/app/routes/devices/monitor-point/monitor-point-edit/monitor-point-edit.component.ts @@ -32,7 +32,7 @@ let _areas = null; if (areaNames != null) { _areas = { - label: Object.values(areaNames).filter(d=>d).join('/'), + label: Object.values(areaNames).filter(d => d).join('/'), value: data.areaCode }; } diff --git a/src/app/routes/map/coordinates-picker/coordinates-picker.component.html b/src/app/routes/map/coordinates-picker/coordinates-picker.component.html index c9470b5..1619375 100644 --- a/src/app/routes/map/coordinates-picker/coordinates-picker.component.html +++ b/src/app/routes/map/coordinates-picker/coordinates-picker.component.html @@ -6,11 +6,11 @@ <span></span> </div> <div nz-col [nzSpan]="7"> - <nz-input maxlength="20" [(ngModel)]="queryTest" [nzPlaceHolder]="'���������������(��� ��� ��� ��� ���������)'"> + <nz-input #queryText maxlength="20" [nzPlaceHolder]="'���������������(��� ��� ��� ��� ���������)'"> </nz-input> </div> <div nz-col [nzSpan]="1"> - <button nz-button [nzType]="'primary'" (click)="mapSearch($event)" class="mr-sm"> + <button nz-button [nzType]="'primary'" (click)="mapSearch(queryText._value,true)" class="mr-sm"> <i class="anticon anticon-search"></i><span>������</span> </button> </div> diff --git a/src/app/routes/map/coordinates-picker/coordinates-picker.component.ts b/src/app/routes/map/coordinates-picker/coordinates-picker.component.ts index 726a069..1a787bd 100644 --- a/src/app/routes/map/coordinates-picker/coordinates-picker.component.ts +++ b/src/app/routes/map/coordinates-picker/coordinates-picker.component.ts @@ -16,6 +16,7 @@ export class CoordinatesPickerComponent implements OnInit { Default_LNG = 121; Default_LAT = 31.4; + showZoom = 19; isSaving = false; markerOption: { point: Point, @@ -35,19 +36,19 @@ ngOnInit(): void { this.data = this.coorPickerService.data; let lng = this.data.longitude; - lng = lng === 0 || lng == null ? this.Default_LNG : lng; + lng = !lng ? this.Default_LNG : lng; this.data.longitude = lng; let lat = this.data.latitude; - lat = lat === 0 || lat == null ? this.Default_LAT : lat; + lat = !lat ? this.Default_LAT : lat; this.data.latitude = lat; this.options = { minZoom: 3, maxZoom: 19, cursor: 'default', - centerAndZoom: { - lng: lng, - lat: lat, - zoom: 19 + centerAndZoom: { + lng: this.data.longitude, + lat: this.data.latitude, + zoom: this.showZoom }, enableKeyboard: true }; @@ -98,14 +99,59 @@ && this.data.longitude === this.Default_LNG && !!this.data.address && !!this.data.address.trim()) { - this._localSearch.search(this.data.address); + this.mapSearch(this.data.address); } } - queryTest: string; - mapSearch(param: any) { - let text = this.queryTest; - text = text == null || text.trim() === '' ? '���������' : text; - this._localSearch.search(text); + city: string; + // queryText: string; + mapSearch(queryText: string, isSearch?: boolean) { + + if (!!queryText && !!queryText.trim()) { + this.city = !!this.city ? this.city : '���������'; + const end = queryText.indexOf('���') + 1; + if (end > 0) { + let start = queryText.indexOf('���') + 1; + start = start > 0 ? start : queryText.indexOf('���') + 1; + start = start > end ? 0 : start; + if (start < end) { + this.city = queryText.slice(start, end).trim(); + if (!!this.city) { + this._map.setCurrentCity(this.city); + } + } + } + console.log(this.city); + const myGeo = new this._BMap.Geocoder(); + const that = this; + that._map.setCurrentCity(that.city); + myGeo.getPoint(queryText, function(point){ + let getPoint = false; + if (point) { + that.data.latitude = point.lat; + that.data.longitude = point.lng; + getPoint = true; + }else { + console.log('������������������������������������!'); + } + that.markerOption.point = { + lng: that.data.longitude, + lat: that.data.latitude + }; + that.options.centerAndZoom = { + lng: that.data.longitude, + lat: that.data.latitude, + zoom: that.showZoom + }; + // setTimeout(() => { + if (getPoint && !isSearch) { + that._map.centerAndZoom(point, that.showZoom); + + } else { + that._localSearch.search(queryText); + } + // }, 3000); + }, that.city); + } } clickMap(e: any) { this.markerOption.point = { diff --git a/yarn.lock b/yarn.lock index 7a61b2b..bd91a1a 100644 --- a/yarn.lock +++ b/yarn.lock @@ -463,9 +463,11 @@ mobx ">=3" mobx-angular ">=1" -angular2-baidu-map@^4.1.0: - version "4.1.0" - resolved "https://registry.yarnpkg.com/angular2-baidu-map/-/angular2-baidu-map-4.1.0.tgz#9992840349a78e3d3c3eaf3b3857fd85e59ccb32" +angular2-baidu-map@^4.3.2: + version "4.3.2" + resolved "http://registry.npm.taobao.org/angular2-baidu-map/download/angular2-baidu-map-4.3.2.tgz#bd85d10692e863f97479b640071ef59fe5b1e001" + dependencies: + tslib "^1.7.1" angular2-cookie@^1.2.6: version "1.2.6" -- Gitblit v1.8.0