| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246 |
- <template>
- <div
- v-if="visible"
- :class="[`pq-${animation}`, vmClass]"
- :style="[vmStyle, popupStyle]"
- class="PopupQuick vci-flex-rcm"
- >
- <i
- v-if="enableMask"
- :style="maskStyle"
- class="pq-mask"
- @pointerup="closeByMask"
- ></i>
- <div
- :style="{overflow}"
- class="pq-slot vci-flex-rcm"
- >
- <slot v-bind="slotProps"></slot>
- </div>
- </div>
- </template>
- <script>
- import MixinClearScheduleTasks from "../../../mixins/MixinClearScheduledTasks";
- import { addCss, getElementBody, getElementMaxZIndex, getElementProperty } from "@vci/helper/src/element";
- import { isEmpty } from "@vci/helper/src/other";
- export default {
- name: "PopupQuick",
- mixins: [MixinClearScheduleTasks],
- inheritAttrs: false,
- props: {
- visible: {
- type: Boolean,
- default: false
- },
- zIndex: {
- type: [String, Number],
- default: null
- },
- popupStyle: {
- type: Object,
- default: null
- },
- maskStyle: {
- type: Object,
- default: null
- },
- enableMask: {
- type: Boolean,
- default: true
- },
- enableMaskClose: {
- type: Boolean,
- default: false
- },
- enableLockScroll: {
- type: Boolean,
- default: false
- },
- animation: {
- type: String,
- default: "fade-up"
- },
- overflow: {
- type: String,
- default: "visible"
- }
- },
- data() {
- return {
- vmClass: null,
- vmStyle: {
- zIndex: 8
- },
- inter: -1
- };
- },
- computed: {
- slotProps() {
- return {
- close: this.close
- };
- }
- },
- watch: {
- visible: {
- immediate: true,
- handler(value, oldValue) {
- if(value) {
- this.$emit("beforeOpen", this);
- if(!isEmpty(this.zIndex)) this.vmStyle.zIndex = this.zIndex;
- else this.toppingPopup();
- clearTimeout(this.inter);
- this.inter = setTimeout(() => {
- this.vmClass = "pq-show pq-show-" + this.animation;
- this.inter = setTimeout(() => this.$emit("afterOpen", this), 350);
- }, 50);
- } else !isEmpty(oldValue) && this.close();
- }
- },
- enableLockScroll: {
- immediate: true,
- handler: "lockScrollHandle"
- }
- },
- methods: {
- toppingPopup() {
- this.vmStyle.zIndex = getElementMaxZIndex();
- },
- lockScrollHandle() {
- const body = getElementBody();
- if(this.enableLockScroll) {
- this._oldScroll = getElementProperty(body, "overflow");
- addCss(body, { overflow: "hidden" });
- } else {
- if(this._oldScroll) addCss(body, { overflow: this._oldScroll });
- }
- },
- closeByMask() {
- this.enableMaskClose && this.close();
- },
- close() {
- if(!this.visible) return false;
- this.$emit("beforeClose", this);
- this.vmClass = "pq-hide pq-hide-" + this.animation;
- clearTimeout(this.inter);
- this.inter = setTimeout(() => this.$emit("afterClose", this), 350);
- }
- }
- };
- </script>
- <style lang="scss" scoped>
- @use "@vci/style/src/var" as va;
- .PopupQuick {
- position: fixed;
- left: 0;
- top: 0;
- width: 100%;
- height: 100%;
- .pq-mask {
- position: absolute;
- left: 0;
- top: 0;
- z-index: 1;
- display: block;
- width: 100%;
- height: 100%;
- opacity: 0;
- transition: va.$transition;
- background-color: rgba(0, 0, 0, .05);
- backdrop-filter: blur(0);
- }
- .pq-slot {
- position: relative;
- z-index: 2;
- transition: va.$transition-slow;
- opacity: 0;
- max-height: calc(100% - 32px);
- max-width: calc(100% - 32px);
- pointer-events: none;
- > * {
- pointer-events: auto;
- }
- }
- &.pq-show {
- .pq-mask {
- opacity: 1;
- backdrop-filter: blur(12px);
- }
- .pq-slot {
- opacity: 1;
- }
- }
- &.pq-hide {
- .pq-mask {
- transition: va.$transition-slow;
- }
- .pq-slot {
- transition: va.$transition;
- }
- }
- &.pq-fade-down {
- .pq-slot {
- transform: translateY(-32px);
- }
- }
- &.pq-show-fade-down {
- .pq-slot {
- transform: translateY(0);
- }
- }
- &.pq-hide-fade-down {
- .pq-slot {
- transform: translateY(-32px);
- }
- }
- &.pq-fade-up {
- .pq-slot {
- transform: translateY(32px);
- }
- }
- &.pq-show-fade-up {
- .pq-slot {
- transform: translateY(0);
- }
- }
- &.pq-hide-fade-up {
- .pq-slot {
- transform: translateY(32px);
- }
- }
- &.pq-zoom-out {
- .pq-slot {
- transform: scale(.8);
- }
- }
- &.pq-show-zoom-out {
- .pq-slot {
- transform: scale(1);
- }
- }
- &.pq-hide-zoom-out {
- .pq-slot {
- transform: scale(.8);
- }
- }
- &.pq-zoom-in {
- .pq-slot {
- transform: scale(1.2);
- }
- }
- &.pq-show-zoom-in {
- .pq-slot {
- transform: scale(1);
- }
- }
- &.pq-hide-zoom-in {
- .pq-slot {
- transform: scale(1.2);
- }
- }
- }
- </style>
|