@wetspace/pro-components
Version:
::: tip 基本介绍
161 lines (160 loc) • 4.98 kB
JavaScript
import { defineComponent as q, shallowRef as G, computed as m, ref as C, watch as H, provide as J, openBlock as d, createElementBlock as K, normalizeClass as r, unref as s, createVNode as b, withCtx as i, renderSlot as f, createBlock as g, createElementVNode as L, createCommentVNode as E, mergeProps as Q } from "vue";
import { useNamespace as U, ElRow as _, ElCol as X, ElFormItem as Y, ElForm as Z } from "element-plus";
import { wetProFormProps as x } from "./types.mjs";
import { SymbolState as ee } from "./symbol.mjs";
import te from "./base/item.vue.mjs";
import h from "../../node_modules/.pnpm/lodash-es@4.17.21/node_modules/lodash-es/cloneDeep.mjs";
import $ from "../../node_modules/.pnpm/lodash-es@4.17.21/node_modules/lodash-es/get.mjs";
import I from "../../node_modules/.pnpm/lodash-es@4.17.21/node_modules/lodash-es/set.mjs";
import { useDebounceFn as le } from "../../node_modules/.pnpm/@vueuse_shared@10.11.1_vue@3.5.12_typescript@5.4.2_/node_modules/@vueuse/shared/index.mjs";
const fe = /* @__PURE__ */ q({
name: "ProForm",
__name: "index",
props: x,
emits: ["change", "update:modelValue"],
setup(S, { expose: N, emit: B }) {
const a = U("pro-form"), j = B, n = G(), l = S, A = m(() => ({
span: l.span,
...l.colProps
})), o = C({}), p = C({}), D = (e) => {
const t = e.join(".");
p.value[t] = e;
}, c = (e) => {
const t = l.valueEmptyModel === "filter" ? void 0 : null;
if (e) {
const u = (Array.isArray(e), e);
return $(o.value, u, t);
} else {
const u = {};
return Object.values(p.value).forEach((w) => {
const O = $(o.value, w, t);
I(u, w, O);
}), u;
}
}, V = (e, t) => {
I(o.value, e, t);
}, R = (e) => {
j("change", e, c());
}, T = (e) => {
var t;
(t = n.value) == null || t.validateField(e);
}, F = (e) => {
var t;
(t = n.value) == null || t.clearValidate(e);
}, W = (e) => {
var t;
(t = n.value) == null || t.scrollToField(e);
}, P = async () => {
var e;
return await ((e = n.value) == null ? void 0 : e.validate()), c();
}, z = (e) => {
o.value = h(e);
}, y = le(() => {
F();
}, 50), v = (e = !1) => (e ? o.value = {} : o.value = h(l.initialValues || {}), y(), c());
H(() => l.initialValues, (e) => {
e ? o.value = h(e) : o.value = {}, l.notInitClearValidate || y();
}, {
immediate: !0,
deep: !0
});
const M = m(() => l.labelWidth || "100px");
J(ee, {
registerFiledsPaths: p,
formState: o,
setFormStateValue: D,
registerChangeEmit: R,
globalColProps: A,
labelWidth: M,
clearable: m(() => l.clearable),
setFieldsValue: V,
getFieldsValue: c,
labelPosition: m(() => l.labelPosition)
});
const k = () => v(!0);
return N({
submit: P,
reset: v,
clear: k,
validateField: T,
clearValidate: F,
getFieldsValue: c,
setFieldsValue: V,
scrollToField: W,
setValue: z
}), (e, t) => l.isFormItem ? (d(), K("div", {
key: 0,
class: r([s(a).b()])
}, [
b(s(_), {
gutter: l.gutter,
class: r([s(a).e("row")])
}, {
default: i(() => [
f(e.$slots, "default"),
e.$slots.actions ? (d(), g(s(X), {
key: 0,
class: r([s(a).e("actions")])
}, {
default: i(() => [
b(s(Y), null, {
default: i(() => [
L("div", {
class: r([s(a).e("actions-slot")])
}, [
f(e.$slots, "actions")
], 2)
]),
_: 3
})
]),
_: 3
}, 8, ["class"])) : E("", !0)
]),
_: 3
}, 8, ["gutter", "class"])
], 2)) : (d(), g(s(Z), Q({
key: 1,
ref_key: "formIns",
ref: n,
class: [s(a).b()],
model: o.value,
"scroll-to-error": "",
"scroll-into-view-options": {
behavior: "smooth",
block: "center"
},
disabled: l.disabled
}, e.$attrs), {
default: i(() => [
b(s(_), {
gutter: l.gutter,
class: r([s(a).e("row")])
}, {
default: i(() => [
f(e.$slots, "default"),
e.$slots.actions ? (d(), g(te, {
key: 0,
"is-action": "",
class: r([s(a).e("actions")])
}, {
default: i(() => [
f(e.$slots, "actions", {
submit: P,
reset: v,
clear: k
})
]),
_: 3
}, 8, ["class"])) : E("", !0)
]),
_: 3
}, 8, ["gutter", "class"])
]),
_: 3
}, 16, ["class", "model", "disabled"]));
}
});
export {
fe as default
};