Files
woer_management/src/components/index.js
T
2026-07-29 16:30:04 +08:00

81 lines
2.0 KiB
JavaScript

import Vue from "vue";
import SearchDialog from "./SearchDialog";
import FormDialog from "./FormDialog";
import Table from "./Table";
import SelectTree from "./SelectTree";
import ImageDialog from "./ImageDialog";
import importFailedDialog from "./importFailedDialog";
const SearchConstructor = Vue.extend(SearchDialog);
const ImageConstructor = Vue.extend(ImageDialog);
const FailedDialog = Vue.extend(importFailedDialog);
Vue.component("Table", Table);
Vue.component("FormDialog", FormDialog);
Vue.component("SelectTree", SelectTree);
const components = {
SearchDialog,
FormDialog,
Table,
SelectTree
};
Vue.use({
install: function(vue) {
vue.prototype.$search = async function(query, rules) {
const search = new SearchConstructor({
propsData: {
query,
rules
}
});
search.$mount();
document.body.appendChild(search.$el);
return new Promise((resolve, reject) => {
search.$on("done", function(e) {
if (e) {
resolve(e);
} else {
reject(new Error("cancel"));
}
});
});
};
vue.prototype.$ImageDialog = async function(src, width, title) {
const Image = new ImageConstructor({
propsData: { src, width, title }
});
Image.$mount();
document.body.appendChild(Image.$el);
return new Promise((resolve, reject) => {
Image.$on("done", function(e) {
if (e) {
resolve(e);
} else {
reject(new Error("cancel"));
}
});
});
};
vue.prototype.$FailedDialog = async function(message) {
const dialog = new FailedDialog({
propsData: { message }
});
dialog.$mount();
document.body.appendChild(dialog.$el);
return new Promise((resolve, reject) => {
dialog.$on("done", function(e) {
if (e) {
resolve(e);
} else {
reject(new Error("cancel"));
}
});
});
};
}
});
export default components;