9 changed files with 102 additions and 80 deletions
@ -1,4 +1,3 @@ |
|||||||
<div class="content" [ngStyle]="{'left': leftCss,'top': topCss,'min-width': minWidthCss}" *ngIf="searchList.length"> |
<div class="content" [ngStyle]="{'left': leftCss,'top': topCss,'min-width': minWidthCss}" *ngIf="searchList.length"> |
||||||
<h1>I'm loaded</h1> |
|
||||||
<div *ngFor="let item of searchList" (click)="select(item)" class="item">{{item.name}}</div> |
<div *ngFor="let item of searchList" (click)="select(item)" class="item">{{item.name}}</div> |
||||||
</div> |
</div> |
@ -1,55 +1,53 @@ |
|||||||
import { Component, OnInit, Inject } from '@angular/core'; |
import { Component, OnInit, Inject } from '@angular/core'; |
||||||
import { AutocompleteSelect } from '../../map'; |
import { AutocompleteSelect, HtmlRender } from '../../map'; |
||||||
|
|
||||||
|
|
||||||
type ClickHandler = (data: AutocompleteSelect) => void; |
type ClickHandler = (data: AutocompleteSelect) => void; |
||||||
|
|
||||||
@Component({ |
@Component({ |
||||||
selector: 'SearchDownList', |
selector: 'SearchDownList', |
||||||
templateUrl: './SearchDownList.html', |
templateUrl: './SearchDownList.html', |
||||||
styleUrls: ['./SearchDownList.scss'] |
styleUrls: ['./SearchDownList.scss'] |
||||||
}) |
}) |
||||||
export class SearchDownList implements OnInit { |
export class SearchDownList implements OnInit { |
||||||
private $input; |
constructor() {} |
||||||
constructor() { |
|
||||||
} |
public $input; //input
|
||||||
public searchList: AutocompleteSelect[] = []; //list
|
public searchList: AutocompleteSelect[] = []; //list
|
||||||
public leftCss: string = '0px'; |
public leftCss: string = '0px'; |
||||||
public topCss: string = '0px'; |
public topCss: string = '0px'; |
||||||
public minWidthCss: string = '0px'; |
public minWidthCss: string = '0px'; |
||||||
private clickHandler: ClickHandler; |
private clickHandler: ClickHandler; |
||||||
|
|
||||||
ngOnInit(): void { |
ngOnInit(): void { |
||||||
|
window.onresize = () => { |
||||||
|
if (this.$input) { |
||||||
|
let Dom = this.$input.getBoundingClientRect() |
||||||
|
this.leftCss = `${Dom.left + 3}px` |
||||||
|
this.topCss = `${Dom.top + Dom.height + 3}px` |
||||||
|
this.minWidthCss = `${Dom.width}px` |
||||||
|
} |
||||||
|
} |
||||||
} |
} |
||||||
|
|
||||||
setClickHander(handler: ClickHandler) { |
setClickHander(handler: ClickHandler) { |
||||||
this.clickHandler = handler; |
this.clickHandler = handler; |
||||||
} |
} |
||||||
|
|
||||||
clearClickHander() { |
clearClickHander() { |
||||||
this.clearClickHander = null; |
this.clearClickHander = null; |
||||||
} |
} |
||||||
init(elementId: string): void { |
|
||||||
this.$input = document.getElementById(elementId); |
|
||||||
//this.addDOMEvent();
|
|
||||||
} |
|
||||||
// input 添加监听事件
|
|
||||||
addDOMEvent() { |
|
||||||
|
|
||||||
// this.left = DOM.left
|
init(inputElement: HtmlRender): void { |
||||||
// this.top = DOM.top + DOM.height + 2
|
this.$input = inputElement |
||||||
// this.minWidth = DOM.width
|
let Dom = this.$input.getBoundingClientRect() |
||||||
|
this.leftCss = `${Dom.left + 3}px` |
||||||
|
this.topCss = `${Dom.top + Dom.height + 3}px` |
||||||
|
this.minWidthCss = `${Dom.width}px` |
||||||
} |
} |
||||||
|
|
||||||
|
// 触发 select
|
||||||
select(e) { |
select(e) { |
||||||
this.clearClickHander && this.clickHandler(e); |
this.clearClickHander && this.clickHandler(e); |
||||||
this.searchList = []; |
this.searchList = []; |
||||||
} |
} |
||||||
|
|
||||||
watch() { |
|
||||||
//TODO:修改leftCss ,topCss
|
|
||||||
} |
|
||||||
|
|
||||||
testAddData() { |
|
||||||
this.searchList.push({ |
|
||||||
name: "asfasdfasdf" |
|
||||||
} as AutocompleteSelect); |
|
||||||
} |
|
||||||
} |
} |
Loading…
Reference in new issue