From 7fbb4b87c7faf3e6a153afe49796def8a9c97014 Mon Sep 17 00:00:00 2001 From: zhaoxu <493734247@qq.com> Date: Fri, 25 Jun 2021 22:59:07 +0800 Subject: [PATCH] =?UTF-8?q?demo=20=E6=89=8B=E5=86=99=E9=AB=98=E5=BE=B7?= =?UTF-8?q?=E7=9A=84=E6=90=9C=E7=B4=A2=E6=A1=86=E9=80=BB=E8=BE=91.?= =?UTF-8?q?=E6=96=B9=E4=BE=BF=E7=A7=BB=E6=A4=8D=E8=87=B3=E7=A7=91=E8=BE=BE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/app/app.component.ts | 90 +++--- src/app/app.module.ts | 62 +++-- src/app/pages/login/login.component.ts | 257 +++++++++--------- src/app/searchComponent.service.ts | 23 +- src/global.d.ts | 5 - .../SearchDownListPlugins/SearchDownList.ts | 22 +- src/modules/map/declare/gaode-map.ts | 89 +++--- src/modules/map/declare/keda-map.ts | 9 +- 8 files changed, 292 insertions(+), 265 deletions(-) delete mode 100644 src/global.d.ts diff --git a/src/app/app.component.ts b/src/app/app.component.ts index f2c071e..7e1f764 100644 --- a/src/app/app.component.ts +++ b/src/app/app.component.ts @@ -1,60 +1,60 @@ import { Component, Inject, Injector } from '@angular/core'; import { HttpClient } from '@angular/common/http' import { Data } from './interface' -import { Router,ActivatedRoute } from '@angular/router' -import {CacheTokenService} from './http-interceptors/cache-token.service'//引入服务 +import { Router, ActivatedRoute } from '@angular/router' +import { CacheTokenService } from './http-interceptors/cache-token.service'//引入服务 import { MaskLayerService } from './mask-layer.service'; - +import * as global from 'globals'; @Component({ - selector: 'app-root', - templateUrl: './app.component.html', - styleUrls: ['./app.component.scss'] + selector: 'app-root', + templateUrl: './app.component.html', + styleUrls: ['./app.component.scss'] }) export class AppComponent { - constructor(private maskLayerService:MaskLayerService,private http:HttpClient,private router:Router,public token:CacheTokenService,private injector:Injector) { - window.injector = injector; - } - - isMaskLayerShow:boolean = false - - ngOnInit(): void { - - //监听遮罩层 - this.maskLayerService.getMessage().subscribe((message: any)=>{ - this.isMaskLayerShow = message - }); - var token = sessionStorage.getItem("token"); - var refreshToken = sessionStorage.getItem("refreshToken"); - if(token && refreshToken) { - this.http.post('/api/Account/RefreshToken', { - token: token, - refreshToken: refreshToken - }).subscribe((data: Data) => { - sessionStorage.setItem("level",data.level); - sessionStorage.setItem("token",data.token); - sessionStorage.setItem("refreshToken",data.refreshToken); - this.token.startUp() - }) - } - // console.log(1234,document.documentElement.clientWidth) - function addMeta(name,content){//手动添加mate标签 - - let meta = document.createElement('meta'); - -     meta.content=content; - -     meta.name=name; - -     document.getElementsByTagName('head')[0].appendChild(meta); - + constructor(private maskLayerService: MaskLayerService, private http: HttpClient, private router: Router, public token: CacheTokenService, private injector: Injector) { + global.injector = injector; } - if(document.documentElement.clientWidth < 800){ - addMeta('viewport','initial-scale=0.5, maximum-scale=0.5, minimum-scale=0.5, user-scalable=no,uc-fitscreen=yes,viewport-fit=cover') + + isMaskLayerShow: boolean = false + + ngOnInit(): void { + + //监听遮罩层 + this.maskLayerService.getMessage().subscribe((message: any) => { + this.isMaskLayerShow = message + }); + var token = sessionStorage.getItem("token"); + var refreshToken = sessionStorage.getItem("refreshToken"); + if (token && refreshToken) { + this.http.post('/api/Account/RefreshToken', { + token: token, + refreshToken: refreshToken + }).subscribe((data: Data) => { + sessionStorage.setItem("level", data.level); + sessionStorage.setItem("token", data.token); + sessionStorage.setItem("refreshToken", data.refreshToken); + this.token.startUp() + }) + } + // console.log(1234,document.documentElement.clientWidth) + function addMeta(name, content) {//手动添加mate标签 + + let meta = document.createElement('meta'); + + meta.content = content; + + meta.name = name; + + document.getElementsByTagName('head')[0].appendChild(meta); + + } + if (document.documentElement.clientWidth < 800) { + addMeta('viewport', 'initial-scale=0.5, maximum-scale=0.5, minimum-scale=0.5, user-scalable=no,uc-fitscreen=yes,viewport-fit=cover') + } } - } diff --git a/src/app/app.module.ts b/src/app/app.module.ts index 673c961..ddd0fc8 100644 --- a/src/app/app.module.ts +++ b/src/app/app.module.ts @@ -2,7 +2,7 @@ import { BrowserModule } from '@angular/platform-browser'; import { NgModule } from '@angular/core'; import { AppRoutingModule } from './app-routing.module'; import { AppComponent } from './app.component'; -import {BrowserAnimationsModule} from '@angular/platform-browser/animations'; +import { BrowserAnimationsModule } from '@angular/platform-browser/animations'; import { MatButtonModule } from '@angular/material/button'; import { MatCheckboxModule } from '@angular/material/checkbox'; import { MatIconModule } from '@angular/material/icon'; @@ -15,8 +15,8 @@ import { FormsModule } from '@angular/forms'; import { UiModule } from './ui/ui.module'; import { HttpClientModule } from '@angular/common/http'; import { httpInterceptorProviders } from './http-interceptors/index' -import {CacheTokenService} from './http-interceptors/cache-token.service' -import { TreeService } from'./http-interceptors/tree.service'; +import { CacheTokenService } from './http-interceptors/cache-token.service' +import { TreeService } from './http-interceptors/tree.service'; import { MTokenK1Component } from './m-token-k1/m-token-k1.component' //K1秘钥 import { CountdownModule } from 'ngx-countdown'; //倒计时插件 import { GISManagementModule } from './gis-management/gis-management.module'; @@ -24,34 +24,36 @@ import { DataCollectionModule } from './data-collection/data-collection.module'; import { MatProgressSpinnerModule } from '@angular/material/progress-spinner'; import { TestComponent } from './test/test.component'; import { ExternalLinksPlanComponent } from './external-links-plan/external-links-plan.component'; +import { SearchDownList } from '../modules/map/declare/component/SearchDownListPlugins/SearchDownList'; @NgModule({ - declarations: [ - AppComponent, - HomeComponent, - MTokenK1Component, - TestComponent, - ExternalLinksPlanComponent - ], - imports: [ - BrowserModule, - AppRoutingModule, - BrowserAnimationsModule, - MatButtonModule, - MatCheckboxModule, - MatSidenavModule, - NavigationModule, - MatIconModule, - PagesModule, - FormsModule, - HttpClientModule, - CountdownModule, - GISManagementModule, - DataCollectionModule, - MatProgressSpinnerModule, - UiModule - ], - providers: [httpInterceptorProviders, CacheTokenService,TreeService], - bootstrap: [AppComponent] + declarations: [ + AppComponent, + HomeComponent, + MTokenK1Component, + TestComponent, + ExternalLinksPlanComponent, + SearchDownList + ], + imports: [ + BrowserModule, + AppRoutingModule, + BrowserAnimationsModule, + MatButtonModule, + MatCheckboxModule, + MatSidenavModule, + NavigationModule, + MatIconModule, + PagesModule, + FormsModule, + HttpClientModule, + CountdownModule, + GISManagementModule, + DataCollectionModule, + MatProgressSpinnerModule, + UiModule + ], + providers: [httpInterceptorProviders, CacheTokenService, TreeService], + bootstrap: [AppComponent] }) export class AppModule { } diff --git a/src/app/pages/login/login.component.ts b/src/app/pages/login/login.component.ts index 96ca249..b11f432 100644 --- a/src/app/pages/login/login.component.ts +++ b/src/app/pages/login/login.component.ts @@ -1,153 +1,154 @@ import { ApplicationRef, Component, ComponentFactoryResolver, Injector, OnInit } from '@angular/core'; import { HttpClient } from '@angular/common/http' import { Data } from '../../interface' -import { Router,ActivatedRoute } from '@angular/router' -import {CacheTokenService} from '../../http-interceptors/cache-token.service'//引入服务 -import { MatSnackBar,MatSnackBarConfig } from '@angular/material/snack-bar'; -import { MatDialog,MatDialogRef } from '@angular/material/dialog'; +import { Router, ActivatedRoute } from '@angular/router' +import { CacheTokenService } from '../../http-interceptors/cache-token.service'//引入服务 +import { MatSnackBar, MatSnackBarConfig } from '@angular/material/snack-bar'; +import { MatDialog, MatDialogRef } from '@angular/material/dialog'; import { SearchService } from '@src/app/searchComponent.service'; import { SearchDownList } from '@src/modules/map/declare/component/SearchDownListPlugins/SearchDownList'; - +import * as global from 'globals'; @Component({ - selector: 'app-login', - templateUrl: './login.component.html', - styleUrls: ['./login.component.scss'], + selector: 'app-login', + templateUrl: './login.component.html', + styleUrls: ['./login.component.scss'], }) export class LoginComponent implements OnInit { - constructor(private http:HttpClient,private router:Router,private route:ActivatedRoute,public token:CacheTokenService,public snackBar: MatSnackBar, public dialog: MatDialog) { - - window.injector.get(SearchService).appendComponentToBody(SearchDownList); - } - - ngOnInit() { - this.automaticLogin() - } - - errmsg :string = '' - - onSubmit(e){ - this.http.post('/api/Account/SignIn',{ - name: e.name, - password: e.password}).subscribe( (data: Data) => { - sessionStorage.setItem("level",data.level); - sessionStorage.setItem("token",data.token); - sessionStorage.setItem("refreshToken",data.refreshToken); - sessionStorage.setItem("isDefaultPassword",data.isDefaultPassword);//是否需要修改默认密码 - this.http.get('/api/Account/NavMenus').subscribe((data:any)=>{ - let isHave = data.find(item=>{ return item.url == "/statisticanalysis/home"}) - let isHaveGis = data.find(item=>{ return item.url == "/gis"}) - if (isHave) { - this.router.navigate([`/statisticanalysis/home`]) - this.dialogChangePassword() - return - } else if(isHaveGis){ - this.router.navigate([`/gis`]) - this.dialogChangePassword() - return - } else if(data.length != 0){ - this.router.navigate([`/keyUnit`]) - this.dialogChangePassword() - return - data.forEach(item => { - if(item.url){ - - } - }); - }else{ - this.snackBar.open('该用户角色未分配任何菜单', '确定', { - duration: 3000 + constructor(private http: HttpClient, private router: Router, private route: ActivatedRoute, public token: CacheTokenService, public snackBar: MatSnackBar, public dialog: MatDialog) { + + } + + ngOnInit() { + this.automaticLogin() + } + + errmsg: string = '' + + onSubmit(e) { + this.http.post('/api/Account/SignIn', { + name: e.name, + password: e.password + }).subscribe((data: Data) => { + sessionStorage.setItem("level", data.level); + sessionStorage.setItem("token", data.token); + sessionStorage.setItem("refreshToken", data.refreshToken); + sessionStorage.setItem("isDefaultPassword", data.isDefaultPassword);//是否需要修改默认密码 + this.http.get('/api/Account/NavMenus').subscribe((data: any) => { + let isHave = data.find(item => { return item.url == "/statisticanalysis/home" }) + let isHaveGis = data.find(item => { return item.url == "/gis" }) + if (isHave) { + this.router.navigate([`/statisticanalysis/home`]) + this.dialogChangePassword() + return + } else if (isHaveGis) { + this.router.navigate([`/gis`]) + this.dialogChangePassword() + return + } else if (data.length != 0) { + this.router.navigate([`/keyUnit`]) + this.dialogChangePassword() + return + data.forEach(item => { + if (item.url) { + + } + }); + } else { + this.snackBar.open('该用户角色未分配任何菜单', '确定', { + duration: 3000 + }); + } + + }) + if (e.notlogin) { //7天免登录时 + localStorage.setItem("isnologin", "true") + localStorage.setItem("token", data.token) + localStorage.setItem("refreshToken", data.refreshToken) + } + //调用服务中的function刷新token + this.token.startUp() + }, + (err) => { this.errmsg = err } + ) + } + + + dialogChangePassword() { + if (sessionStorage.getItem('isDefaultPassword') == 'true') { + let dialogRef = this.dialog.open(ChangepasswordComponent2, + { width: '348px' }); + + dialogRef.afterClosed().subscribe((data) => { + sessionStorage.setItem('isDefaultPassword', 'false') }); - } - - }) - if(e.notlogin){ //7天免登录时 - localStorage.setItem("isnologin","true") - localStorage.setItem("token",data.token) - localStorage.setItem("refreshToken",data.refreshToken) } - //调用服务中的function刷新token - this.token.startUp() - }, - (err) => {this.errmsg = err} - ) - } - - - dialogChangePassword(){ - if(sessionStorage.getItem('isDefaultPassword') == 'true'){ - let dialogRef = this.dialog.open(ChangepasswordComponent2, - {width:'348px'}); - - dialogRef.afterClosed().subscribe((data)=>{ - sessionStorage.setItem('isDefaultPassword','false') - }); + } + } + //7天免登录自动登录 + automaticLogin() { + let isNoLogin = localStorage.getItem("isnologin") + if (isNoLogin) { //7天免登录时 + let token = localStorage.getItem("token"); + let refreshToken = localStorage.getItem("refreshToken"); + this.http.post('/api/Account/RefreshToken', { + token: token, + refreshToken: refreshToken + }).subscribe((data: any) => { + sessionStorage.setItem("level", data.level); + sessionStorage.setItem("token", data.token); + sessionStorage.setItem("refreshToken", data.refreshToken); + this.token.startUp() + this.router.navigate(['/keyUnit']) + this.snackBar.open('已自动登录', '确定', { duration: 3000 }); + }) + } //if + + } + + //打开弹窗 + open() { + this.snackBar.open('请联系管理员', '确定', { + duration: 3000 + }); } - } - //7天免登录自动登录 - automaticLogin () { - let isNoLogin = localStorage.getItem("isnologin") - if (isNoLogin) { //7天免登录时 - let token = localStorage.getItem("token"); - let refreshToken = localStorage.getItem("refreshToken"); - this.http.post('/api/Account/RefreshToken', { - token: token, - refreshToken: refreshToken}).subscribe((data:any)=>{ - sessionStorage.setItem("level",data.level); - sessionStorage.setItem("token",data.token); - sessionStorage.setItem("refreshToken",data.refreshToken); - this.token.startUp() - this.router.navigate(['/keyUnit']) - this.snackBar.open('已自动登录', '确定', {duration: 3000}); - }) - } //if - - } - - //打开弹窗 - open () { - this.snackBar.open('请联系管理员', '确定', { - duration: 3000 - }); - } } @Component({ - selector: 'app-changepassword', - templateUrl: './changePassword.html', - styleUrls: ['./changepassword.scss'] + selector: 'app-changepassword', + templateUrl: './changePassword.html', + styleUrls: ['./changepassword.scss'] }) export class ChangepasswordComponent2 implements OnInit { - - constructor(private http:HttpClient,public snackBar: MatSnackBar, - public dialogRef: MatDialogRef) { } - - ngOnInit() { - } - errmsg :string = '' - - onSubmit(e){ - this.http.put( - '/api/Account/Password', - { - newPassword: e.newPassword, - password: 'SHya119!@' - } - ).subscribe(data=> { - this.dialogRef.close(data); - const config = new MatSnackBarConfig(); - config.verticalPosition = 'top'; - config.duration = 3000 - this.snackBar.open('密码修改成功','确定',config); - },(err) => - {this.errmsg = err} - ) - } + + constructor(private http: HttpClient, public snackBar: MatSnackBar, + public dialogRef: MatDialogRef) { } + + ngOnInit() { + } + errmsg: string = '' + + onSubmit(e) { + this.http.put( + '/api/Account/Password', + { + newPassword: e.newPassword, + password: 'SHya119!@' + } + ).subscribe(data => { + this.dialogRef.close(data); + const config = new MatSnackBarConfig(); + config.verticalPosition = 'top'; + config.duration = 3000 + this.snackBar.open('密码修改成功', '确定', config); + }, (err) => { this.errmsg = err } + ) + } diff --git a/src/app/searchComponent.service.ts b/src/app/searchComponent.service.ts index 6c00787..6e34d11 100644 --- a/src/app/searchComponent.service.ts +++ b/src/app/searchComponent.service.ts @@ -1,30 +1,29 @@ import { ApplicationRef, ComponentFactoryResolver, ComponentRef, EmbeddedViewRef, Injectable, Injector } from '@angular/core'; @Injectable({ - providedIn: 'root' + providedIn: 'root' }) export class SearchService { - constructor(private componentFactoryResolver: ComponentFactoryResolver,private applicationRef: ApplicationRef,private injector: Injector,) {} + constructor(private componentFactoryResolver: ComponentFactoryResolver, private applicationRef: ApplicationRef, private injector: Injector,) { } //angular 动态组件 - appendComponentToBody(component: any) { + appendComponentToBody(component: any): ComponentRef { //create a component reference const componentRef = this.componentFactoryResolver.resolveComponentFactory(component).create(this.injector); - // attach component to the appRef so that so that it will be dirty checked. this.applicationRef.attachView(componentRef.hostView); - + // get DOM element from component - const domElem = (componentRef.hostView as EmbeddedViewRef < any > ).rootNodes[0] as HTMLElement; - + const domElem = (componentRef.hostView as EmbeddedViewRef).rootNodes[0] as HTMLElement; + document.body.appendChild(domElem); - - return componentRef; - } - removeComponentFromBody(componentRef: ComponentRef < any > ) { + return componentRef as ComponentRef; + } + + removeComponentFromBody(componentRef: ComponentRef) { this.applicationRef.detachView(componentRef.hostView); componentRef.destroy(); - } + } } \ No newline at end of file diff --git a/src/global.d.ts b/src/global.d.ts deleted file mode 100644 index 420e434..0000000 --- a/src/global.d.ts +++ /dev/null @@ -1,5 +0,0 @@ -import { Injector } from "@angular/core"; - -export declare interface Window { - injector: Injector - } \ No newline at end of file diff --git a/src/modules/map/declare/component/SearchDownListPlugins/SearchDownList.ts b/src/modules/map/declare/component/SearchDownListPlugins/SearchDownList.ts index 815b30d..5e4585c 100644 --- a/src/modules/map/declare/component/SearchDownListPlugins/SearchDownList.ts +++ b/src/modules/map/declare/component/SearchDownListPlugins/SearchDownList.ts @@ -2,7 +2,7 @@ import { Component, OnInit, Inject } from '@angular/core'; import { AutocompleteSelect } from '../../map'; -type ClickHandler = (data:AutocompleteSelect)=>void; +type ClickHandler = (data: AutocompleteSelect) => void; @Component({ selector: 'SearchDownList', @@ -17,13 +17,17 @@ export class SearchDownList implements OnInit { public leftCss: string = '0px'; public topCss: string = '0px'; public minWidthCss: string = '0px'; - private clickHandler:ClickHandler; + private clickHandler: ClickHandler; ngOnInit(): void { } - - init(elementId:string,clickCallback:ClickHandler):void{ + setClickHander(handler: ClickHandler) { + this.clickHandler = handler; + } + clearClickHander() { + this.clearClickHander = null; + } + init(elementId: string): void { this.$input = document.getElementById(elementId); - this.clickHandler = clickCallback; //this.addDOMEvent(); } // input 添加监听事件 @@ -35,11 +39,17 @@ export class SearchDownList implements OnInit { } select(e) { - this.clickHandler(e); + this.clearClickHander && this.clickHandler(e); this.searchList = []; } watch() { //TODO:修改leftCss ,topCss } + + testAddData() { + this.searchList.push({ + name: "asfasdfasdf" + } as AutocompleteSelect); + } } \ No newline at end of file diff --git a/src/modules/map/declare/gaode-map.ts b/src/modules/map/declare/gaode-map.ts index 6b5da0c..ff02a4f 100644 --- a/src/modules/map/declare/gaode-map.ts +++ b/src/modules/map/declare/gaode-map.ts @@ -1,5 +1,8 @@ -import { HtmlRender, ICircle, IIcon, IIconOptions, ILayer, ILngLat, IMap, IMapOptions, IMarker, IMarkerCluster, IMarkOptions, IMouseTool, IInfoWindow, IPixel, IRenderClusterMarker, ISelf, ISize, PixelRender, ITileLayer, IDriving, IDrivingOptions, IAutocomplete, IPlaceSearch, AutocompleteSearchCallback, AutocompleteSelectCallback, PlaceSearchCallback } from './map' +import { HtmlRender, ICircle, IIcon, IIconOptions, ILayer, ILngLat, IMap, IMapOptions, IMarker, IMarkerCluster, IMarkOptions, IMouseTool, IInfoWindow, IPixel, IRenderClusterMarker, ISelf, ISize, PixelRender, ITileLayer, IDriving, IDrivingOptions, IAutocomplete, IPlaceSearch, AutocompleteSearchCallback, AutocompleteSelectCallback, PlaceSearchCallback, AutocompleteSearch } from './map' import MapTools from './map-tools'; +import * as global from 'globals'; +import { SearchService } from '@src/app/searchComponent.service'; +import { SearchDownList } from './component/SearchDownListPlugins/SearchDownList'; declare var AMap: any; declare var AMapUI: any; @@ -10,13 +13,13 @@ class GaodeBasic implements ISelf { export class GaoDeMap extends GaodeBasic implements IMap { /// plugins:同步加载插件 - constructor(container: string, options: IMapOptions,plugins?:string[]) { + constructor(container: string, options: IMapOptions, plugins?: string[]) { super(); this.self = new AMap.Map(container, options); - if(!!plugins && plugins.length){ - for(var i in plugins){ + if (!!plugins && plugins.length) { + for (var i in plugins) { let name = plugins[i]; - if(name.indexOf('AMap.')==-1)continue; + if (name.indexOf('AMap.') == -1) continue; let pObj = eval(`new ${plugins[i]}()`); this.self.plugin(pObj); } @@ -38,7 +41,7 @@ export class GaoDeMap extends GaodeBasic implements IMap { return this.self.setZoomAndCenter(zoom, pos) } plugin(pluginNames: string[], callback: Function) { - let names = pluginNames.filter(s=>s.indexOf("AMap.")==0); + let names = pluginNames.filter(s => s.indexOf("AMap.") == 0); return this.self.plugin(names, callback) } getBounds() { @@ -59,9 +62,9 @@ export class GaoDeMap extends GaodeBasic implements IMap { setCenter(pos: any) { return this.self.setCenter(pos) } - getCenter():ILngLat { + getCenter(): ILngLat { let d = this.self.getCenter(); - return new GaoDeLngLat(0,0,d); + return new GaoDeLngLat(0, 0, d); } getZoom() { return this.self.getZoom(); @@ -238,9 +241,9 @@ export class GaoDePixel extends GaodeBasic implements IPixel { this.self = new AMap.Pixel(x, y); } getArray(): number[] { - return [this.x,this.y]; + return [this.x, this.y]; } - + x: number; y: number; } @@ -255,8 +258,8 @@ export class GaoDeMarker extends GaodeBasic implements IMarker { setContent(html: string) { return this.self.setContent(html) } - setPosition(x: ILngLat|number[]) { - x = (x as ILngLat).getArray == undefined ? x:(x as ILngLat).getArray(); + setPosition(x: ILngLat | number[]) { + x = (x as ILngLat).getArray == undefined ? x : (x as ILngLat).getArray(); return this.self.setPosition(x) } _position: number[] @@ -279,7 +282,7 @@ export class GaoDeMarkerCluster extends GaodeBasic implements IMarkerCluster { super(); let conf = MapTools.ExplicitConvert(options); - AMap.plugin('AMap.MarkerClusterer',()=>{ + AMap.plugin('AMap.MarkerClusterer', () => { this.self = new AMap.MarkerCluster(map.self, list, conf) }); } @@ -292,23 +295,23 @@ export class GaoDeMarkerCluster extends GaodeBasic implements IMarkerCluster { } export class GaoDeLngLat extends GaodeBasic implements ILngLat { - constructor(x: number, y: number,me?:any) { + constructor(x: number, y: number, me?: any) { super(); - if(me==undefined) + if (me == undefined) this.self = new AMap.LngLat(x, y); else this.self = me; } - typeName="LngLat"; - get KL():number{ + typeName = "LngLat"; + get KL(): number { return this.lng; } - get kT():number{ + get kT(): number { return this.lat; } getArray(): number[] { - return [this.lng,this.lat]; + return [this.lng, this.lat]; } get lng(): number { return this.self.lng; @@ -316,7 +319,7 @@ export class GaoDeLngLat extends GaodeBasic implements ILngLat { get lat(): number { return this.self.lat; } - offset(x: number, y: number):ILngLat { + offset(x: number, y: number): ILngLat { return this.self.offset(x, y) } } @@ -362,12 +365,12 @@ export class GaodeDriving extends GaodeBasic implements IDriving { constructor(options: IDrivingOptions) { super(); options.map = options.map.self - AMap.plugin('AMap.Driving',()=>{ + AMap.plugin('AMap.Driving', () => { this.self = new AMap.Driving(options) }) } search(posStart?: ILngLat, posEnd?: ILngLat, callback?: Function) { - return this.self.search(posStart.getArray(),posEnd.getArray(),callback) + return this.self.search(posStart.getArray(), posEnd.getArray(), callback) } clear() { return this.self.clear() @@ -375,38 +378,54 @@ export class GaodeDriving extends GaodeBasic implements IDriving { } export class GaodeAutocomplete extends GaodeBasic implements IAutocomplete { - private component:any - constructor(options: any,component: any) { + private component: any + private searchDownList: SearchDownList + constructor(options: any, component: any) { super(); this.component = component - AMap.plugin('AMap.AutoComplete',()=>{ + AMap.plugin('AMap.AutoComplete', () => { this.self = new AMap.Autocomplete(options) }) + + this.searchDownList = global.injector.get(SearchService).appendComponentToBody(SearchDownList).instance; + this.searchDownList.init(options.input); + + this.self.on('complete', (e) => { + console.log('search complete', e); + this.searchDownList.searchList = e.tips || []; + }) } on(eventName: string, callback: AutocompleteSelectCallback) { - return this.self.on(eventName, (event)=>{ - callback.call(this.component,event) - }) + this.searchDownList.setClickHander(e => { + alert(e.name); + callback(e); + }); + //$().addEventListener + // return this.self.on(eventName, (event) => { + // console.log('on event', event) + // callback.call(this.component, event) + // }) } search(address: string, callback: AutocompleteSearchCallback) { - return this.self.search(address,(status,result)=>{ - callback.call(this.component,status,result) + return this.self.search(address, (status, result: AutocompleteSearch) => { + this.searchDownList.searchList = result.tips || []; + callback.call(this.component, status, result) }) } } export class GaodePlaceSearch extends GaodeBasic implements IPlaceSearch { - private component:any + private component: any constructor(component: any) { super(); this.component = component - AMap.plugin('AMap.PlaceSearch',()=>{ + AMap.plugin('AMap.PlaceSearch', () => { this.self = new AMap.PlaceSearch() }) } search(text: string, callback: PlaceSearchCallback) { - return this.self.search(text,(status,result)=>{ - callback.call(this.component,status,result) + return this.self.search(text, (status, result) => { + callback.call(this.component, status, result) }) } } @@ -414,7 +433,7 @@ export class GaodePlaceSearch extends GaodeBasic implements IPlaceSearch { export class GaodeMouseTool extends GaodeBasic implements IMouseTool { constructor(map: IMap) { super(); - AMap.plugin(["AMap.RangingTool", "AMap.MouseTool"],()=>{ + AMap.plugin(["AMap.RangingTool", "AMap.MouseTool"], () => { this.self = new AMap.MouseTool(map.self); }) } diff --git a/src/modules/map/declare/keda-map.ts b/src/modules/map/declare/keda-map.ts index f642293..0dc2c5e 100644 --- a/src/modules/map/declare/keda-map.ts +++ b/src/modules/map/declare/keda-map.ts @@ -3,6 +3,7 @@ import * as ObjectID from 'bson-objectid'; import { SearchDownList } from './component/SearchDownListPlugins/SearchDownList'; import { ApplicationRef, ComponentFactoryResolver, Injector, ReflectiveInjector } from '@angular/core'; import { SearchService } from '@src/app/searchComponent.service'; +import * as global from 'globals'; declare var KMap: any; class KedaBasic implements ISelf { @@ -319,9 +320,9 @@ export class KedaAutocomplete extends KedaBasic implements IAutocomplete { //Aut this.component = component const injector = Injector.create({ providers: - [{provide: SearchService, deps: [ComponentFactoryResolver,ApplicationRef,Injector]}] - }); - injector.get(SearchService).appendComponentToBody(SearchDownList); + [{ provide: SearchService, deps: [ComponentFactoryResolver, ApplicationRef, Injector] }] + }); + injector.get(SearchService).appendComponentToBody(SearchDownList); if (options && options.input != undefined) { //绑定input框搜索事件 this.inputListen(options.input); } @@ -329,7 +330,7 @@ export class KedaAutocomplete extends KedaBasic implements IAutocomplete { //Aut on(eventName: string, callback: AutocompleteSelectCallback) { } - inputListen(elementId:string){ + inputListen(elementId: string) { } search(address: string, callback: AutocompleteSearchCallback) {