|
4 | 4 | * 弹出层 |
5 | 5 | * */ |
6 | 6 | let popup = { |
| 7 | + animationClass: { |
| 8 | + ANIMATION_ENTER: 't-popup--animation-enter', |
| 9 | + ANIMATION_ENTER_FROM: 't-popup--animation-enter-from', |
| 10 | + ANIMATION_EXITING: 't-popup--animation-exiting', |
| 11 | + ANIMATION_LEAVE_TO: 't-popup--animation-leave-to', |
| 12 | + ANIMATION_ENTER_TO: 't-popup--animation-enter-to', |
| 13 | + ANIMATION_ENTERING: 't-popup--animation-entering', |
| 14 | + ANIMATION_LEAVE_FROM: 't-popup--animation-leave-from', |
| 15 | + ANIMATION_LEAVE: 't-popup--animation-leave', |
| 16 | + ANIMATION_ENTER_ACTIVE: 't-popup--animation-enter-active', |
| 17 | + ANIMATION_LEAVE_ACTIVE: 't-popup--animation-leave-active', |
| 18 | + }, |
| 19 | + popperList: [], |
7 | 20 | /** |
8 | 21 | * 创建一个新的弹出层引用 |
9 | | - * @param objRef 触发对象的引用 |
10 | | - * @param popupRef 弹出提示对象的引用 |
| 22 | + * @param trigerElement 触发对象的引用 |
| 23 | + * @param popupElement 弹出提示对象的引用 |
11 | 24 | * @param options 弹出层配置 |
12 | 25 | * @param optionDotNetHelper options 包装的 DotNetReference 对象 |
13 | 26 | * @returns popper 对象 |
14 | | - * */ |
15 | | - show: function (trigerElement, popupElement, options, optionDotNetReference,dotNetHelper) { |
| 27 | + * */ |
| 28 | + show: function (trigerElement, popupElement, options, dotNetHelper) { |
16 | 29 |
|
| 30 | + let popper; |
17 | 31 | options.onFirstUpdate = state => { |
18 | | - optionDotNetReference.invokeMethodAsync("InvokeOnFirstUpdate", { placement: state.placement }); |
| 32 | + console.debug('placement:' + state.placement); |
| 33 | + //optionDotNetReference.invokeMethodAsync("InvokeOnFirstUpdate", { placement: state.placement }); |
19 | 34 | } |
20 | | - let popper = createPopper(trigerElement, popupElement, options); |
| 35 | + setTimeout(() => { |
| 36 | + popper = createPopper(trigerElement, popupElement, options); |
| 37 | + document.body.appendChild(popupElement); |
21 | 38 |
|
| 39 | + window.addEventListener("click", () => { |
| 40 | + this.hide(popupElement, dotNetHelper); |
| 41 | + }, {once:true}); |
22 | 42 |
|
23 | | - window.addEventListener("click", () => { |
24 | | - dotNetHelper.invokeMethodAsync("Invoke"); |
25 | | - }); |
| 43 | + //popupElement.style.display = ""; |
| 44 | + popupElement.style.display = ""; |
| 45 | + popupElement.classList.remove(this.animationClass.ANIMATION_ENTER, this.animationClass.ANIMATION_LEAVE_ACTIVE); |
| 46 | + popupElement.classList.add(this.animationClass.ANIMATION_ENTER_ACTIVE, this.animationClass.ANIMATION_LEAVE); |
| 47 | + dotNetHelper.invokeMethodAsync('onShown'); |
26 | 48 |
|
27 | | - document.body.appendChild(popupElement); |
28 | | - popupElement.style.display = ""; |
29 | | - return popper; |
| 49 | + this.popperList[popupElement] = popper; |
| 50 | + }, 400); |
| 51 | + //return popper; |
30 | 52 | }, |
31 | | - hide: function (popper, popupElement, options) { |
32 | | - if (popper) { |
33 | | - popper.destroy(); |
| 53 | + hide: function (popupElement, dotNetHelper) { |
| 54 | + if (popupElement) { |
| 55 | + |
| 56 | + const popper = this.popperList[popupElement]; |
| 57 | + if (!popper) { |
| 58 | + return; |
| 59 | + } |
| 60 | + popupElement.classList.remove(this.animationClass.ANIMATION_LEAVE, this.animationClass.ANIMATION_ENTER_ACTIVE); |
| 61 | + popupElement.classList.add(this.animationClass.ANIMATION_LEAVE_ACTIVE, this.animationClass.ANIMATION_ENTER); |
| 62 | + |
| 63 | + setTimeout(() => { |
| 64 | + popper.destroy(); |
| 65 | + popupElement.style.display = 'none'; |
| 66 | + dotNetHelper.invokeMethodAsync('onHidden'); |
| 67 | + },400) |
34 | 68 | } |
| 69 | + }, |
| 70 | + clear: () => { |
| 71 | + this.popperList.clear(); |
35 | 72 | } |
36 | 73 | } |
37 | 74 |
|
|
0 commit comments