snowy-designer
Version:
基于Epic-Designer-Pro版本的设计器,可视化开发页面表单
94 lines (93 loc) • 2.54 kB
JavaScript
import { ref as d, watch as S } from "vue";
/* empty css */
import "radix-vue";
import "clsx";
import "tailwind-merge";
import "lucide-vue-next";
import "../../../../../ui-kit/base-ui/src/shadch-ui/button/index.js";
import "@vueuse/core";
import "../../../../../ui-kit/base-ui/src/shadch-ui/toast/index.js";
import "vuedraggable";
import { findSchemas as A, deepClone as g } from "../../../../../utils/src/common/data.js";
import { usePageManager as M } from "../../../../../utils/src/manager/pageManager.js";
import "../../../../../utils/src/manager/pluginManager.js";
import "monaco-editor";
import "../../../../../utils/src/request/index.js";
function G() {
const i = d(!1), o = M(), r = d({});
function c() {
return new Promise((t) => {
if (i.value)
t();
else {
const a = S(i, () => {
a(), t();
});
}
});
}
async function s(t = "default") {
var n;
await c();
const a = Object.keys(r.value || {});
if (a.length === 1)
return r.value[a[0]];
const e = (n = r.value) == null ? void 0 : n[t];
if (!e) throw new Error(`表单 [name=${t}] 不存在`);
return e;
}
async function u(t, a) {
const e = await s(t);
return g(await a(e));
}
async function y(t = "default") {
return await u(t, (a) => a.getData());
}
function l(t, a = "default") {
var f, p, w;
const e = A(
o.pageSchema.schemas,
(P) => P.type === "form"
);
e && e.length === 1 && (a = e[0].componentProps.name), o.setFormData(t, a);
const n = (f = r.value) == null ? void 0 : f[a];
((p = n == null ? void 0 : n.clearValidate) == null ? void 0 : p.call(n)) ?? ((w = n == null ? void 0 : n.restoreValidation) == null || w.call(n));
}
async function h(t = "default") {
return await u(t, async (a) => (await a.validate(), await a.getData()));
}
async function m(t) {
await c();
const a = {};
for (const e in r.value) {
const n = r.value[e];
n && (a[e] = g(await t(n)));
}
return a;
}
async function v() {
return await m((t) => t.getData());
}
function D(t) {
for (const a in t)
l(t[a], a);
}
async function F() {
return await m(async (t) => (await t.validate(), await t.getData()));
}
return {
forms: r,
getData: y,
getFormInstance: s,
getForms: v,
pageManager: o,
ready: i,
setData: l,
setForms: D,
validate: h,
validateAll: F
};
}
export {
G as useBuilder
};