| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899 |
- import PopupWindow from "./PopupWindow.vue";
- import Vue from "vue";
- import { mergeDeep } from "@vci/helper/src/object";
- import { getElementBody } from "@vci/helper/src/element";
- const PopupWindowExt = Vue.extend({
- data() {
- return {
- props: {
- title: "窗口",
- left: "center",
- top: "middle",
- defaultWidth: "600px",
- defaultHeight: "300px",
- widthMin: 300,
- heightMin: 150,
- customStyle: {},
- visibleHead: true,
- visibleTool: true,
- enableResize: true,
- url: null
- },
- on: {
- beforeOpen: null,
- afterOpen: null,
- beforeClose: null,
- close: 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);
- },
- close() {
- getElementBody().removeChild(this.$el);
- this.on.close && this.on.close(this.$children[0]);
- this.$destroy();
- }
- },
- render(h) {
- const on = {
- close: vm => {
- this.on.close && this.on.close(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(
- PopupWindow,
- {
- props: this.props,
- on,
- scopedSlots: {
- default: props => {
- const component = this.component || "div";
- return h(
- component,
- {
- props: {
- ...this.propsComponent,
- ...props
- }
- }
- );
- }
- }
- }
- );
- }
- });
- function open(option) {
- const popupWindow = new PopupWindowExt();
- popupWindow.$mount();
- getElementBody().appendChild(popupWindow.$el);
- popupWindow.open(option || {});
- return popupWindow;
- }
- function close(popupWindow) {
- popupWindow && popupWindow.close();
- }
- const PluginPopupWindow = {
- open,
- close,
- install: Vue => {
- Vue.prototype.$popupWindow = { open, close };
- }
- };
- export {
- PluginPopupWindow
- };
|