epic-designer
Version:
基于vue3的设计器,可视化开发页面表单
78 lines (77 loc) • 1.97 kB
JavaScript
import { ref as m, watch as h } from "vue";
/* empty css */
import "vuedraggable";
import { deepClone as g } from "../../../../../utils/src/common/data.js";
import { usePageManager as A } from "../../../../../utils/src/manager/pageManager.js";
import "../../../../../utils/src/manager/pluginManager.js";
function E() {
const i = m(!1), o = A(), e = m({});
function c() {
return new Promise((a) => {
if (i.value)
a();
else {
const t = h(i, () => {
t(), a();
});
}
});
}
async function u(a = "default") {
var n;
await c();
const t = (n = e.value) == null ? void 0 : n[a];
if (!t) throw new Error(`表单 [name=${a}] 不存在`);
return t;
}
async function s(a, t) {
const n = await u(a);
return g(await t(n));
}
async function y(a = "default") {
return await s(a, (t) => t.getData());
}
function l(a, t = "default") {
var r, w, d;
o.setFormData(a, t);
const n = (r = e.value) == null ? void 0 : r[t];
((w = n == null ? void 0 : n.clearValidate) == null ? void 0 : w.call(n)) ?? ((d = n == null ? void 0 : n.restoreValidation) == null || d.call(n));
}
async function p(a = "default") {
return await s(a, async (t) => (await t.validate(), await t.getData()));
}
async function f(a) {
await c();
const t = {};
for (const n in e.value) {
const r = e.value[n];
r && (t[n] = g(await a(r)));
}
return t;
}
async function D() {
return await f((a) => a.getData());
}
function v(a) {
for (const t in a)
l(a[t], t);
}
async function F() {
return await f(async (a) => (await a.validate(), await a.getData()));
}
return {
forms: e,
getData: y,
getFormInstance: u,
getForms: D,
pageManager: o,
ready: i,
setData: l,
setForms: v,
validate: p,
validateAll: F
};
}
export {
E as useBuilder
};