SExtendFieldsForm.js 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  1. var W = Object.defineProperty;
  2. var b = Object.getOwnPropertySymbols;
  3. var D = Object.prototype.hasOwnProperty, j = Object.prototype.propertyIsEnumerable;
  4. 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) => {
  5. for (var d in i || (i = {}))
  6. D.call(i, d) && w(n, d, i[d]);
  7. if (b)
  8. for (var d of b(i))
  9. j.call(i, d) && w(n, d, i[d]);
  10. return n;
  11. };
  12. 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";
  13. import { ai as H } from "./index2.js";
  14. import K from "./SExtendFieldsFormItem.js";
  15. import { _ as Q } from "./index5.js";
  16. const oe = {
  17. __name: "SExtendFieldsForm",
  18. props: {
  19. // 扩展字段的列表
  20. data: {
  21. type: Array,
  22. default: () => []
  23. },
  24. // 表单类型(add / edit / view)
  25. type: {
  26. type: String,
  27. default: "add"
  28. },
  29. // 扩展字段的默认值(编辑时的值)
  30. defaultValue: {
  31. type: Array,
  32. default: () => []
  33. },
  34. column: {
  35. type: Number,
  36. default: 1
  37. },
  38. // label 的宽度,auto 时取表单自身的 labelWidth
  39. labelWidth: {
  40. type: String,
  41. default: "auto"
  42. },
  43. lColValue: {
  44. type: Number,
  45. default: 8
  46. },
  47. wColValue: {
  48. type: Number,
  49. default: 8
  50. },
  51. layout: {
  52. type: String,
  53. default: "vertical"
  54. },
  55. marginTop: {
  56. type: Number,
  57. default: 0
  58. }
  59. },
  60. setup(n, { expose: i }) {
  61. 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(() => {
  62. const l = f.layout, e = (f == null ? void 0 : f.labelWidth) + "";
  63. return l === "horizontal" ? {
  64. style: {
  65. width: e.includes("px") ? e : e + "px"
  66. }
  67. } : {};
  68. }), $ = s(() => `${100 / k.value}%`), F = s(
  69. () => `div#${g} > form.sapi-form > div.ant-form-item:not(.sapi-form-item_full){ width: ${$.value}; }`
  70. ), O = s(() => f.labelWidth), C = s(
  71. () => f.data.map((l) => {
  72. var a, r;
  73. const e = p({}, l);
  74. if (typeof e.fillModeConfig == "string" && e.fillModeConfig)
  75. try {
  76. e.fillModeConfig = JSON.parse(e.fillModeConfig);
  77. } catch (M) {
  78. e.fillModeConfig = { showType: "input", config: {} };
  79. }
  80. const t = ((a = e.fillModeConfig) == null ? void 0 : a.config) || e.fillModeConfig || {}, o = (r = e.fillModeConfig) == null ? void 0 : r.showType;
  81. return e.isFull = ["textarea", "upload"].includes(o) || o === "select" && t.multiple, e;
  82. }).sort((l, e) => (l.rowIndex || 0) - (e.rowIndex || 0))
  83. ), h = s(
  84. () => f.defaultValue.reduce((l, e) => {
  85. if (e.value) {
  86. let t;
  87. try {
  88. t = JSON.parse(e.value);
  89. } catch (M) {
  90. t = e.value;
  91. }
  92. let o = {};
  93. try {
  94. o = typeof e.fillModeConfig == "string" ? JSON.parse(e.fillModeConfig) : e.fillModeConfig || {};
  95. } catch (M) {
  96. o = {};
  97. }
  98. const { showType: a, config: r = {} } = o || {};
  99. 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);
  100. }
  101. return l;
  102. }, {})
  103. );
  104. _(
  105. () => C.value.length,
  106. () => {
  107. var e;
  108. const l = {};
  109. for (const t of C.value)
  110. if (f.type === "view") {
  111. let o = null;
  112. try {
  113. o = t.value ? JSON.parse(t.value) : null;
  114. } catch (a) {
  115. o = t.value;
  116. }
  117. l[t.fieldCode] = o;
  118. } else {
  119. const o = h.value[t.fieldCode];
  120. o ? l[t.fieldCode] = o : (e = t.fillModeConfig) != null && e.defaultValue ? l[t.fieldCode] = t.fillModeConfig.defaultValue : l[t.fieldCode] = null;
  121. }
  122. u.value = l, m();
  123. },
  124. { immediate: !0 }
  125. ), _(
  126. () => f.defaultValue.length,
  127. () => {
  128. const l = p({}, u.value);
  129. for (const e of f.defaultValue)
  130. l[e.fieldCode] = h.value[e.fieldCode];
  131. u.value = l, m();
  132. },
  133. { immediate: !0 }
  134. ), B(() => {
  135. E(() => {
  136. setTimeout(() => {
  137. m();
  138. }, 100);
  139. });
  140. });
  141. const J = () => new Promise((l) => {
  142. c.value && c.value.validate((e) => {
  143. l(e);
  144. });
  145. });
  146. function m(l) {
  147. c.value && c.value.clearValidate(l);
  148. }
  149. return i({ validate: J, clearValidate: m, getModel: () => Object.keys(u.value).map((l) => {
  150. let e = u.value[l];
  151. return typeof e == "object" && (e = e == null ? null : JSON.stringify(e)), {
  152. fieldCode: l,
  153. value: e
  154. };
  155. }) }), (l, e) => {
  156. const t = Q, o = I("s-form");
  157. return v(), x("div", {
  158. class: "sapi-extend-fields-form-container",
  159. id: g,
  160. style: P({ marginTop: n.marginTop + "px" })
  161. }, [
  162. (v(), S(z("style"), {
  163. textContent: L(F.value)
  164. }, null, 8, ["textContent"])),
  165. V(o, {
  166. ref_key: "formRef",
  167. ref: c,
  168. model: u.value,
  169. "label-width": O.value,
  170. column: n.column
  171. }, {
  172. default: N(() => [
  173. (v(!0), x(R, null, U(C.value, (a) => (v(), S(t, q({
  174. key: a.fieldCode,
  175. label: a.fieldName,
  176. name: a.fieldCode
  177. }, { ref_for: !0 }, p(p({}, T.value), G(d)), {
  178. class: "s-form-item",
  179. ke: l.$utils.uuid()
  180. }), {
  181. default: N(() => [
  182. V(K, {
  183. modelValue: u.value[a.fieldCode],
  184. "onUpdate:modelValue": (r) => u.value[a.fieldCode] = r,
  185. field: a,
  186. type: n.type,
  187. onCallback: (r) => m(a.fieldCode)
  188. }, null, 8, ["modelValue", "onUpdate:modelValue", "field", "type", "onCallback"])
  189. ]),
  190. _: 2
  191. }, 1040, ["label", "name", "ke"]))), 128))
  192. ]),
  193. _: 1
  194. }, 8, ["model", "label-width", "column"])
  195. ], 4);
  196. };
  197. }
  198. };
  199. export {
  200. oe as default
  201. };