snowy-designer
Version:
基于Epic-Designer-Pro版本的设计器,可视化开发页面表单
98 lines (97 loc) • 3.65 kB
JavaScript
import { defineComponent as V, inject as v, ref as B, provide as M, watchEffect as T, computed as g, createElementBlock as y, openBlock as F, createVNode as W, unref as S, mergeProps as j, withCtx as k, renderSlot as l, Fragment as R, renderList as N } 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 "lodash";
import "../../../utils/src/manager/pluginManager.js";
import "monaco-editor";
import "../../../utils/src/request/index.js";
import "../../../hooks/src/store/index.js";
import { useFormLogic as O } from "../../../hooks/src/logic/form.js";
import { Form as q } from "ant-design-vue";
const z = {
class: "form-main",
style: { height: "100%" }
}, le = /* @__PURE__ */ V({
__name: "form",
props: {
componentSchema: { default: () => ({ type: "" }) },
scrollToFirstError: { type: Boolean, default: !1 }
},
setup(b, { expose: x }) {
var s, u;
const n = b, D = v("pageManager", {}), r = B(null), m = v("forms", {}), { formData: a, setLogicRules: P } = O(w);
D.addFormData(a, (u = (s = n.componentSchema) == null ? void 0 : s.componentProps) == null ? void 0 : u.name), M("formData", a), T(() => {
P(n.componentSchema.componentProps.logicRules);
});
function c() {
return a;
}
async function i() {
var e, t;
try {
return await ((e = r.value) == null ? void 0 : e.validateFields());
} catch (o) {
throw n.scrollToFirstError && ((t = r.value) == null || t.scrollToField(o.errorFields[0].name.toString())), o;
}
}
function w() {
var e;
return (e = r.value) == null ? void 0 : e.clearValidate();
}
function p(e) {
Object.assign(a, e);
}
const C = (e) => {
var t, o, d, f, h;
if (r.value = (t = e.component) == null ? void 0 : t.exposed, ((o = n.componentSchema) == null ? void 0 : o.type) === "form" && m.value && r.value) {
const E = ((f = (d = n.componentSchema) == null ? void 0 : d.componentProps) == null ? void 0 : f.name) ?? ((h = n.componentSchema) == null ? void 0 : h.name) ?? "default";
return r.value.validate = i, m.value[E] = r.value, r.value.getData = c, r.value.setData = p, !1;
}
}, _ = g(() => {
const e = n.componentSchema.componentProps ?? {};
let t = e.labelCol, o = e.wrapperCol;
return e.layout === "vertical" ? t = o = { span: 24 } : e.layout === "inline" && e.labelLayout === "fixed" ? (t = {}, o = { flex: 1 }) : e.labelLayout === "fixed" && (t = {
flex: `${typeof e.labelWidth == "number" ? `${e.labelWidth}px` : e.labelWidth}`
}, o = { flex: 1 }), {
...e,
labelCol: t,
wrapperCol: o
};
});
function L(e) {
console.log(e);
}
const $ = g(() => n.componentSchema.children ?? []);
return x({
form: r,
getData: c,
setData: p,
validate: i
}), (e, t) => (F(), y("div", z, [
W(S(q), j({ model: S(a) }, _.value, {
style: { height: "100%" },
onFinish: L,
onVnodeMounted: C
}), {
default: k(() => [
l(e.$slots, "default", {}, () => [
l(e.$slots, "edit-node", {}, () => [
(F(!0), y(R, null, N($.value, (o) => l(e.$slots, "node", { componentSchema: o })), 256))
])
])
]),
_: 3
}, 16, ["model"])
]));
}
});
export {
le as default
};