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