PopupQuick.vue 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246
  1. <template>
  2. <div
  3. v-if="visible"
  4. :class="[`pq-${animation}`, vmClass]"
  5. :style="[vmStyle, popupStyle]"
  6. class="PopupQuick vci-flex-rcm"
  7. >
  8. <i
  9. v-if="enableMask"
  10. :style="maskStyle"
  11. class="pq-mask"
  12. @pointerup="closeByMask"
  13. ></i>
  14. <div
  15. :style="{overflow}"
  16. class="pq-slot vci-flex-rcm"
  17. >
  18. <slot v-bind="slotProps"></slot>
  19. </div>
  20. </div>
  21. </template>
  22. <script>
  23. import MixinClearScheduleTasks from "../../../mixins/MixinClearScheduledTasks";
  24. import { addCss, getElementBody, getElementMaxZIndex, getElementProperty } from "@vci/helper/src/element";
  25. import { isEmpty } from "@vci/helper/src/other";
  26. export default {
  27. name: "PopupQuick",
  28. mixins: [MixinClearScheduleTasks],
  29. inheritAttrs: false,
  30. props: {
  31. visible: {
  32. type: Boolean,
  33. default: false
  34. },
  35. zIndex: {
  36. type: [String, Number],
  37. default: null
  38. },
  39. popupStyle: {
  40. type: Object,
  41. default: null
  42. },
  43. maskStyle: {
  44. type: Object,
  45. default: null
  46. },
  47. enableMask: {
  48. type: Boolean,
  49. default: true
  50. },
  51. enableMaskClose: {
  52. type: Boolean,
  53. default: false
  54. },
  55. enableLockScroll: {
  56. type: Boolean,
  57. default: false
  58. },
  59. animation: {
  60. type: String,
  61. default: "fade-up"
  62. },
  63. overflow: {
  64. type: String,
  65. default: "visible"
  66. }
  67. },
  68. data() {
  69. return {
  70. vmClass: null,
  71. vmStyle: {
  72. zIndex: 8
  73. },
  74. inter: -1
  75. };
  76. },
  77. computed: {
  78. slotProps() {
  79. return {
  80. close: this.close
  81. };
  82. }
  83. },
  84. watch: {
  85. visible: {
  86. immediate: true,
  87. handler(value, oldValue) {
  88. if(value) {
  89. this.$emit("beforeOpen", this);
  90. if(!isEmpty(this.zIndex)) this.vmStyle.zIndex = this.zIndex;
  91. else this.toppingPopup();
  92. clearTimeout(this.inter);
  93. this.inter = setTimeout(() => {
  94. this.vmClass = "pq-show pq-show-" + this.animation;
  95. this.inter = setTimeout(() => this.$emit("afterOpen", this), 350);
  96. }, 50);
  97. } else !isEmpty(oldValue) && this.close();
  98. }
  99. },
  100. enableLockScroll: {
  101. immediate: true,
  102. handler: "lockScrollHandle"
  103. }
  104. },
  105. methods: {
  106. toppingPopup() {
  107. this.vmStyle.zIndex = getElementMaxZIndex();
  108. },
  109. lockScrollHandle() {
  110. const body = getElementBody();
  111. if(this.enableLockScroll) {
  112. this._oldScroll = getElementProperty(body, "overflow");
  113. addCss(body, { overflow: "hidden" });
  114. } else {
  115. if(this._oldScroll) addCss(body, { overflow: this._oldScroll });
  116. }
  117. },
  118. closeByMask() {
  119. this.enableMaskClose && this.close();
  120. },
  121. close() {
  122. if(!this.visible) return false;
  123. this.$emit("beforeClose", this);
  124. this.vmClass = "pq-hide pq-hide-" + this.animation;
  125. clearTimeout(this.inter);
  126. this.inter = setTimeout(() => this.$emit("afterClose", this), 350);
  127. }
  128. }
  129. };
  130. </script>
  131. <style lang="scss" scoped>
  132. @use "@vci/style/src/var" as va;
  133. .PopupQuick {
  134. position: fixed;
  135. left: 0;
  136. top: 0;
  137. width: 100%;
  138. height: 100%;
  139. .pq-mask {
  140. position: absolute;
  141. left: 0;
  142. top: 0;
  143. z-index: 1;
  144. display: block;
  145. width: 100%;
  146. height: 100%;
  147. opacity: 0;
  148. transition: va.$transition;
  149. background-color: rgba(0, 0, 0, .05);
  150. backdrop-filter: blur(0);
  151. }
  152. .pq-slot {
  153. position: relative;
  154. z-index: 2;
  155. transition: va.$transition-slow;
  156. opacity: 0;
  157. max-height: calc(100% - 32px);
  158. max-width: calc(100% - 32px);
  159. pointer-events: none;
  160. > * {
  161. pointer-events: auto;
  162. }
  163. }
  164. &.pq-show {
  165. .pq-mask {
  166. opacity: 1;
  167. backdrop-filter: blur(12px);
  168. }
  169. .pq-slot {
  170. opacity: 1;
  171. }
  172. }
  173. &.pq-hide {
  174. .pq-mask {
  175. transition: va.$transition-slow;
  176. }
  177. .pq-slot {
  178. transition: va.$transition;
  179. }
  180. }
  181. &.pq-fade-down {
  182. .pq-slot {
  183. transform: translateY(-32px);
  184. }
  185. }
  186. &.pq-show-fade-down {
  187. .pq-slot {
  188. transform: translateY(0);
  189. }
  190. }
  191. &.pq-hide-fade-down {
  192. .pq-slot {
  193. transform: translateY(-32px);
  194. }
  195. }
  196. &.pq-fade-up {
  197. .pq-slot {
  198. transform: translateY(32px);
  199. }
  200. }
  201. &.pq-show-fade-up {
  202. .pq-slot {
  203. transform: translateY(0);
  204. }
  205. }
  206. &.pq-hide-fade-up {
  207. .pq-slot {
  208. transform: translateY(32px);
  209. }
  210. }
  211. &.pq-zoom-out {
  212. .pq-slot {
  213. transform: scale(.8);
  214. }
  215. }
  216. &.pq-show-zoom-out {
  217. .pq-slot {
  218. transform: scale(1);
  219. }
  220. }
  221. &.pq-hide-zoom-out {
  222. .pq-slot {
  223. transform: scale(.8);
  224. }
  225. }
  226. &.pq-zoom-in {
  227. .pq-slot {
  228. transform: scale(1.2);
  229. }
  230. }
  231. &.pq-show-zoom-in {
  232. .pq-slot {
  233. transform: scale(1);
  234. }
  235. }
  236. &.pq-hide-zoom-in {
  237. .pq-slot {
  238. transform: scale(1.2);
  239. }
  240. }
  241. }
  242. </style>