epic-designer
Version:
基于vue3的设计器,可视化开发页面表单
98 lines (97 loc) • 2.74 kB
JavaScript
import { ref as d, watch as I } from "vue";
import { createPageManager as M } from "../../../../../manager/src/pageManager.js";
import "../../../../../manager/src/pluginManager.js";
/* empty css */
/* empty css */
/* empty css */
import "@vueuse/core";
import "../../../../../hooks/src/store/index.js";
/* empty css */
import "vue-draggable-plus";
import { findSchemas as P, deepClone as g } from "../../../../../utils/src/common/data.js";
import "../../../../../git/epic/epic-designer/node_modules/.pnpm/jsep@1.4.0/node_modules/jsep/dist/jsep.js";
function q() {
const i = d(!1), o = M(), r = d({});
function c() {
return new Promise((t) => {
if (i.value)
t();
else {
const a = I(i, () => {
a(), t();
});
}
});
}
async function s(t = "default") {
var e;
await c();
const a = Object.keys(r.value || {});
if (a.length === 1)
return r.value[a[0]];
const n = (e = r.value) == null ? void 0 : e[t];
if (!n) throw new Error(`表单 [name=${t}] 不存在`);
return n;
}
async function u(t, a) {
const n = await s(t);
return g(await a(n));
}
async function y(t = "default") {
return await u(t, (a) => a.getData());
}
function l(t, a = "default") {
var m, p, w;
const n = P(
o.pageSchema.schemas,
(A) => A.type === "form"
);
n && n.length === 1 && (a = n[0].props.name), o.setFormData(t, a);
const e = (m = r.value) == null ? void 0 : m[a];
((p = e == null ? void 0 : e.clearValidate) == null ? void 0 : p.call(e)) ?? ((w = e == null ? void 0 : e.restoreValidation) == null || w.call(e));
}
async function v(t = "default") {
return await u(t, async (a) => (await a.validate(), await a.getData()));
}
async function f(t) {
await c();
const a = {};
for (const n in r.value) {
const e = r.value[n];
e && (a[n] = g(await t(e)));
}
return a;
}
async function h() {
return await f((t) => t.getData());
}
function D(t) {
for (const a in t)
l(t[a], a);
}
async function F() {
return await f(async (t) => (await t.validate(), await t.getData()));
}
function S() {
for (const t in r.value) {
const a = r.value[t];
a && a.resetData();
}
}
return {
formInstances: r,
getData: y,
getFormInstance: s,
getForms: h,
pageManager: o,
ready: i,
resetData: S,
setData: l,
setForms: D,
validate: v,
validateAll: F
};
}
export {
q as useBuilder
};