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