| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150 |
- import { useAttrs as g, ref as d, computed as f, watchEffect as v, openBlock as S, createElementBlock as w, createVNode as V, mergeProps as _, withCtx as C, renderSlot as x } from "vue";
- import { n as O } from "./index2.js";
- import { F as B } from "./index5.js";
- const A = { class: "s-form" }, j = {
- __name: "SForm",
- props: {
- // 表单数据对象
- model: {
- type: Object,
- default() {
- return {};
- }
- },
- // 校验规则
- rules: {
- type: Object,
- default() {
- return {};
- }
- },
- // 排列方向:horizontal / vertical
- layout: {
- type: String,
- default() {
- return "vertical";
- }
- },
- // 每行列数
- column: {
- type: [Number, String],
- default() {
- return 1;
- }
- },
- // 标签宽度,单位 px
- labelWidth: {
- type: [Number, String],
- default() {
- return 80;
- }
- }
- },
- setup(u, { expose: m }) {
- const i = g(), o = u, n = d(), p = d(o.column >= 5 ? 4 : o.column), h = /* @__PURE__ */ new Set([
- "disabled",
- "allowClear",
- "clearable",
- "showSearch",
- "multiple",
- "readonly",
- "autofocus",
- "bordered",
- "checked",
- "open",
- "autoClearSearchValue",
- "noDrag",
- "isManual",
- "expandAll",
- "recursionChildren",
- "treeCheckable",
- "showOnlyOrganization",
- "isDataScopeFilter"
- ]), y = (e) => typeof e == "boolean" ? e : e === "" || e === null || e === void 0 ? e === "" ? !0 : e : typeof e == "string" ? !(e === "false" || e === "0") : !!e, F = f(() => {
- const e = {};
- return Object.keys(i || {}).forEach((t) => {
- const l = i[t];
- e[t] = h.has(t) ? y(l) : l;
- }), e;
- }), b = f(() => {
- const e = o.layout, t = (o == null ? void 0 : o.labelWidth) + "";
- return e === "horizontal" ? {
- style: {
- width: t.includes("px") ? t : t + "px"
- }
- } : {};
- });
- return v(() => {
- o.column > 4 && console.warn(`当前设置表单列column【${o.column}】最多显示为4列,已默认为最多4列`);
- }), m({
- validate: (e, t) => {
- const l = typeof e == "function" ? e : typeof t == "function" ? t : null, r = typeof e == "function" ? void 0 : e;
- return new Promise((s, a) => {
- (r && r.length ? n.value.validateFields(r) : n.value.validate()).then((c) => {
- l && l(!0), s(c);
- }).catch((c) => {
- if (l) {
- l(!1, c), s(void 0);
- return;
- }
- a(c);
- });
- });
- },
- validateField: (e, t) => {
- const l = typeof t == "function" ? t : null;
- return new Promise((r, s) => {
- if (!n.value) {
- r(void 0);
- return;
- }
- n.value.validateFields(e).then((a) => {
- l && l(!0), r(a);
- }).catch((a) => {
- if (l) {
- l(!1, a), r(void 0);
- return;
- }
- s(a);
- });
- });
- },
- clearValidate: (e) => {
- n.value && n.value.clearValidate(e);
- },
- resetFields: (e) => {
- n.value && n.value.resetFields(e);
- },
- getFieldsValue: (e) => n.value ? n.value.getFieldsValue(e) : {},
- setFieldsValue: (e) => {
- n.value && n.value.setFieldsValue(e);
- }
- }), (e, t) => {
- const l = B;
- return S(), w("div", A, [
- V(l, _({
- labelCol: b.value.labelCol,
- model: u.model,
- rules: u.rules,
- layout: u.layout
- }, F.value, {
- ref_key: "form",
- ref: n,
- style: {
- display: "grid",
- gridTemplateColumns: `repeat(${p.value}, 1fr)`,
- gap: "20px"
- }
- }), {
- default: C(() => [
- x(e.$slots, "default", {}, void 0, !0)
- ]),
- _: 3
- }, 16, ["labelCol", "model", "rules", "layout", "style"])
- ]);
- };
- }
- }, M = /* @__PURE__ */ O(j, [["__scopeId", "data-v-678f5a2b"]]);
- export {
- M as default
- };
|