35 lines
1.2 KiB
JavaScript
35 lines
1.2 KiB
JavaScript
import Vue from "vue";
|
|
import FEEDBACKCOMP from "./index.vue";
|
|
const FBConstructor = Vue.extend(FEEDBACKCOMP);
|
|
let FBCTABLEINSTANCELIST = [];
|
|
const FBT = (options = {}) => {
|
|
const { data = {}, callBack } = options;
|
|
// if (!UserId) throw `UserId is requred.but ${UserId}`
|
|
const id = `FB${new Date().getTime()}`;
|
|
const instance = new FBConstructor();
|
|
FBCTABLEINSTANCELIST.push(instance);
|
|
instance.id = id;
|
|
instance.vm = instance.$mount();
|
|
if (instance.vm.visible) return;
|
|
document.body.appendChild(instance.vm.$el);
|
|
instance.vm.open({ ...data });
|
|
instance.vm.$on("success", (Id) => {
|
|
if (callBack) callBack();
|
|
});
|
|
instance.vm.$on("closed", () => {
|
|
document.body.removeChild(instance.vm.$el);
|
|
instance.vm.$destroy();
|
|
let index = FBCTABLEINSTANCELIST.findIndex(item => item.id === id);
|
|
FBCTABLEINSTANCELIST.splice(index, 1)
|
|
});
|
|
return instance.vm;
|
|
}
|
|
FBT.close = () => {
|
|
if (FBCTABLEINSTANCELIST.length <= 0) return;
|
|
FBCTABLEINSTANCELIST.forEach(item => {
|
|
document.body.removeChild(item.vm.$el);
|
|
item.vm.$destroy();
|
|
})
|
|
FBCTABLEINSTANCELIST = [];
|
|
}
|
|
export default FBT; |