vexModal.vue
<template>
<vxe-modal
ref="vxeModal"
:title="title"
type="confirm"
:status="statusData"
:className="className"
:cancel-button-text="cancelButtonText"
:confirm-button-text="confirmButtonText"
:showFooter="showFooter"
:lock-view="lockView"
:lock-scroll="lockScroll"
:mask="mask"
:mask-closable="maskClosable"
:esc-closable="escClosable"
:zIndex="zIndex"
:transfer="transfer"
:destroy-on-close="destroyOnClose"
@confirm="confirm"
@cancel="cancel"
@close="cancel"
>
{{ content }}
<template #footer>
<vxe-button
size="mini"
:content="cancelButtonText"
@click="cancel"
v-if="cancelButtonTextBoolean"
></vxe-button>
<vxe-button
size="mini"
status="primary"
:content="confirmButtonText"
@click="confirm"
></vxe-button
></template>
</vxe-modal>
</template>
<script>
export default {
name: "vexModal",
data() {
return {};
},
created() {},
methods: {
open() {
this.$refs.vxeModal.open();
},
close() {
this.$refs.vxeModal.close();
},
confirm({ type, $event }) {
let { onOk } = this;
onOk && onOk(type, $event);
this.close();
},
cancel({ type, $event }) {
let { onCancel } = this;
onCancel && onCancel(type, $event);
this.close();
},
},
};
</script>
<style>
.modalContent {
width: 100%;
height: 100%;
text-align: center;
}
</style>
index.js
import Vue from "vue";
import vexModal from "./vexModal";
const modalVue = Vue.extend(vexModal);
let returnData = {
type: "confirm",
title: "",
statusData: "warning",
content: "",
className: "",
cancelButtonText: "取消",
cancelButtonTextBoolean: false,
confirmButtonText: "确认",
showFooter: true,
lockView: true,
lockScroll: true,
mask: true,
maskClosable: false,
escClosable: true,
zIndex: 9999,
transfer: false,
destroyOnClose: false,
onOk: null,
onCancel: null,
};
const getModal = () => { };
getModal.warning = (configurationItem) => {
modelInit(configurationItem);
};
getModal.confirm = (configurationItem) => {
configurationItem.cancelButtonTextBoolean = true
modelInit(configurationItem);
}
function modelInit(data) {
let modal = new modalVue({
data() {
return {
...returnData,
...data
};
},
});
modal.$mount()
document.body.appendChild(modal.$el);
modal.open()
}
export default {
install() {
Vue.prototype.$Modal = getModal;
},
};