| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109 |
- import Vue from "vue";
- import VpPopupQuick from "./PopupQuick.vue";
- import { hexToRgba } from "@vci/helper/src/color";
- import { getElementBody } from "@vci/helper/src/element";
- import { mergeDeep } from "@vci/helper/src/object";
- const PopupQuickExt = Vue.extend({
- data() {
- return {
- props: {
- visible: false,
- zIndex: null,
- popupStyle: {},
- maskStyle: {
- backgroundColor: hexToRgba("#000", 0.6),
- backdropFilter: "blur(6px)"
- },
- enableMask: true,
- enableMaskClose: false,
- enableLockScroll: true,
- animation: "fade-up",
- overflow: "visible"
- },
- on: {
- beforeOpen: null,
- afterOpen: null,
- beforeClose: null,
- afterClose: null
- },
- component: null,
- propsComponent: {}
- };
- },
- methods: {
- open(option) {
- const { props, on, component, propsComponent } = option;
- this.props = mergeDeep(this.props, props);
- this.on = mergeDeep(this.on, on);
- this.component = component;
- this.propsComponent = mergeDeep(this.propsComponent, propsComponent);
- this.props.visible = true;
- },
- close() {
- this.props.visible = false;
- getElementBody().removeChild(this.$el);
- this.$destroy();
- },
- closeAmt() {
- if(this._isClosing) return false;
- this._isClosing = true;
- const targetVm = this.$children[0];
- if(!targetVm) return false;
- targetVm["close"]();
- }
- },
- render(h) {
- const on = {
- afterClose: vm => {
- this.on.afterClose && this.on.afterClose(vm);
- this.close();
- }
- };
- if(this.on.beforeOpen) on.beforeOpen = this.on.beforeOpen;
- if(this.on.afterOpen) on.afterOpen = this.on.afterOpen;
- if(this.on.beforeClose) on.beforeClose = this.on.beforeClose;
- return h(
- VpPopupQuick,
- {
- props: this.props,
- on,
- scopedSlots: {
- default: props => {
- const component = this.component || "div";
- return h(
- component,
- {
- props: {
- ...this.propsComponent,
- ...props
- }
- }
- );
- }
- }
- }
- );
- }
- });
- function open(option) {
- const popupQuick = new PopupQuickExt();
- popupQuick.$mount();
- getElementBody().appendChild(popupQuick.$el);
- popupQuick.open(option || {});
- return popupQuick;
- }
- function close(popupQuick) {
- popupQuick && popupQuick.close();
- }
- const PluginPopupQuick = {
- open,
- close,
- install: Vue => {
- Vue.prototype.$popupQuick = { open, close };
- }
- };
- export {
- PluginPopupQuick
- };
|