| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201 |
- var W = Object.defineProperty;
- var b = Object.getOwnPropertySymbols;
- var D = Object.prototype.hasOwnProperty, j = Object.prototype.propertyIsEnumerable;
- var w = (n, i, d) => i in n ? W(n, i, { enumerable: !0, configurable: !0, writable: !0, value: d }) : n[i] = d, p = (n, i) => {
- for (var d in i || (i = {}))
- D.call(i, d) && w(n, d, i[d]);
- if (b)
- for (var d of b(i))
- j.call(i, d) && w(n, d, i[d]);
- return n;
- };
- import { useAttrs as A, ref as y, computed as s, watch as _, onMounted as B, nextTick as E, resolveComponent as I, openBlock as v, createElementBlock as x, normalizeStyle as P, createBlock as S, resolveDynamicComponent as z, toDisplayString as L, createVNode as V, withCtx as N, Fragment as R, renderList as U, mergeProps as q, unref as G } from "vue";
- import { ai as H } from "./index2.js";
- import K from "./SExtendFieldsFormItem.js";
- import { _ as Q } from "./index5.js";
- const oe = {
- __name: "SExtendFieldsForm",
- props: {
- // 扩展字段的列表
- data: {
- type: Array,
- default: () => []
- },
- // 表单类型(add / edit / view)
- type: {
- type: String,
- default: "add"
- },
- // 扩展字段的默认值(编辑时的值)
- defaultValue: {
- type: Array,
- default: () => []
- },
- column: {
- type: Number,
- default: 1
- },
- // label 的宽度,auto 时取表单自身的 labelWidth
- labelWidth: {
- type: String,
- default: "auto"
- },
- lColValue: {
- type: Number,
- default: 8
- },
- wColValue: {
- type: Number,
- default: 8
- },
- layout: {
- type: String,
- default: "vertical"
- },
- marginTop: {
- type: Number,
- default: 0
- }
- },
- setup(n, { expose: i }) {
- const d = A(), f = n, c = y(null), k = y(f.column >= 5 ? 4 : f.column), g = `sapiExtendFieldsForm${Math.floor(Date.now() * Math.random()).toString(16)}`, u = y({}), T = s(() => {
- const l = f.layout, e = (f == null ? void 0 : f.labelWidth) + "";
- return l === "horizontal" ? {
- style: {
- width: e.includes("px") ? e : e + "px"
- }
- } : {};
- }), $ = s(() => `${100 / k.value}%`), F = s(
- () => `div#${g} > form.sapi-form > div.ant-form-item:not(.sapi-form-item_full){ width: ${$.value}; }`
- ), O = s(() => f.labelWidth), C = s(
- () => f.data.map((l) => {
- var a, r;
- const e = p({}, l);
- if (typeof e.fillModeConfig == "string" && e.fillModeConfig)
- try {
- e.fillModeConfig = JSON.parse(e.fillModeConfig);
- } catch (M) {
- e.fillModeConfig = { showType: "input", config: {} };
- }
- const t = ((a = e.fillModeConfig) == null ? void 0 : a.config) || e.fillModeConfig || {}, o = (r = e.fillModeConfig) == null ? void 0 : r.showType;
- return e.isFull = ["textarea", "upload"].includes(o) || o === "select" && t.multiple, e;
- }).sort((l, e) => (l.rowIndex || 0) - (e.rowIndex || 0))
- ), h = s(
- () => f.defaultValue.reduce((l, e) => {
- if (e.value) {
- let t;
- try {
- t = JSON.parse(e.value);
- } catch (M) {
- t = e.value;
- }
- let o = {};
- try {
- o = typeof e.fillModeConfig == "string" ? JSON.parse(e.fillModeConfig) : e.fillModeConfig || {};
- } catch (M) {
- o = {};
- }
- const { showType: a, config: r = {} } = o || {};
- a === "datePicker" ? l[e.fieldCode] = H(new Date(t)) : a === "number" ? l[e.fieldCode] = Number(t) : a === "select" && r.multiple === 1 ? l[e.fieldCode] = String(t).split(",") : l[e.fieldCode] = String(t);
- }
- return l;
- }, {})
- );
- _(
- () => C.value.length,
- () => {
- var e;
- const l = {};
- for (const t of C.value)
- if (f.type === "view") {
- let o = null;
- try {
- o = t.value ? JSON.parse(t.value) : null;
- } catch (a) {
- o = t.value;
- }
- l[t.fieldCode] = o;
- } else {
- const o = h.value[t.fieldCode];
- o ? l[t.fieldCode] = o : (e = t.fillModeConfig) != null && e.defaultValue ? l[t.fieldCode] = t.fillModeConfig.defaultValue : l[t.fieldCode] = null;
- }
- u.value = l, m();
- },
- { immediate: !0 }
- ), _(
- () => f.defaultValue.length,
- () => {
- const l = p({}, u.value);
- for (const e of f.defaultValue)
- l[e.fieldCode] = h.value[e.fieldCode];
- u.value = l, m();
- },
- { immediate: !0 }
- ), B(() => {
- E(() => {
- setTimeout(() => {
- m();
- }, 100);
- });
- });
- const J = () => new Promise((l) => {
- c.value && c.value.validate((e) => {
- l(e);
- });
- });
- function m(l) {
- c.value && c.value.clearValidate(l);
- }
- return i({ validate: J, clearValidate: m, getModel: () => Object.keys(u.value).map((l) => {
- let e = u.value[l];
- return typeof e == "object" && (e = e == null ? null : JSON.stringify(e)), {
- fieldCode: l,
- value: e
- };
- }) }), (l, e) => {
- const t = Q, o = I("s-form");
- return v(), x("div", {
- class: "sapi-extend-fields-form-container",
- id: g,
- style: P({ marginTop: n.marginTop + "px" })
- }, [
- (v(), S(z("style"), {
- textContent: L(F.value)
- }, null, 8, ["textContent"])),
- V(o, {
- ref_key: "formRef",
- ref: c,
- model: u.value,
- "label-width": O.value,
- column: n.column
- }, {
- default: N(() => [
- (v(!0), x(R, null, U(C.value, (a) => (v(), S(t, q({
- key: a.fieldCode,
- label: a.fieldName,
- name: a.fieldCode
- }, { ref_for: !0 }, p(p({}, T.value), G(d)), {
- class: "s-form-item",
- ke: l.$utils.uuid()
- }), {
- default: N(() => [
- V(K, {
- modelValue: u.value[a.fieldCode],
- "onUpdate:modelValue": (r) => u.value[a.fieldCode] = r,
- field: a,
- type: n.type,
- onCallback: (r) => m(a.fieldCode)
- }, null, 8, ["modelValue", "onUpdate:modelValue", "field", "type", "onCallback"])
- ]),
- _: 2
- }, 1040, ["label", "name", "ke"]))), 128))
- ]),
- _: 1
- }, 8, ["model", "label-width", "column"])
- ], 4);
- };
- }
- };
- export {
- oe as default
- };
|