SForm.js 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. 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";
  2. import { n as O } from "./index2.js";
  3. import { F as B } from "./index4.js";
  4. const A = { class: "s-form" }, j = {
  5. __name: "SForm",
  6. props: {
  7. model: {
  8. type: Object,
  9. default() {
  10. return {};
  11. }
  12. },
  13. rules: {
  14. type: Object,
  15. default() {
  16. return {};
  17. }
  18. },
  19. layout: {
  20. type: String,
  21. default() {
  22. return "vertical";
  23. }
  24. },
  25. column: {
  26. type: [Number, String],
  27. default() {
  28. return 1;
  29. }
  30. },
  31. labelWidth: {
  32. type: [Number, String],
  33. default() {
  34. return 80;
  35. }
  36. }
  37. },
  38. setup(u, { expose: m }) {
  39. const i = g(), o = u, n = d(), p = d(o.column >= 5 ? 4 : o.column), h = /* @__PURE__ */ new Set([
  40. "disabled",
  41. "allowClear",
  42. "clearable",
  43. "showSearch",
  44. "multiple",
  45. "readonly",
  46. "autofocus",
  47. "bordered",
  48. "checked",
  49. "open",
  50. "autoClearSearchValue",
  51. "noDrag",
  52. "isManual",
  53. "expandAll",
  54. "recursionChildren",
  55. "treeCheckable",
  56. "showOnlyOrganization",
  57. "isDataScopeFilter"
  58. ]), 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(() => {
  59. const e = {};
  60. return Object.keys(i || {}).forEach((t) => {
  61. const l = i[t];
  62. e[t] = h.has(t) ? y(l) : l;
  63. }), e;
  64. }), b = f(() => {
  65. const e = o.layout, t = (o == null ? void 0 : o.labelWidth) + "";
  66. return e === "horizontal" ? {
  67. style: {
  68. width: t.includes("px") ? t : t + "px"
  69. }
  70. } : {};
  71. });
  72. return v(() => {
  73. o.column > 4 && console.warn(`当前设置表单列column【${o.column}】最多显示为4列,已默认为最多4列`);
  74. }), m({ validate: (e, t) => {
  75. const l = typeof e == "function" ? e : typeof t == "function" ? t : null, r = typeof e == "function" ? void 0 : e;
  76. return new Promise((s, a) => {
  77. (r && r.length ? n.value.validateFields(r) : n.value.validate()).then((c) => {
  78. l && l(!0), s(c);
  79. }).catch((c) => {
  80. if (l) {
  81. l(!1, c), s(void 0);
  82. return;
  83. }
  84. a(c);
  85. });
  86. });
  87. }, validateField: (e, t) => {
  88. const l = typeof t == "function" ? t : null;
  89. return new Promise((r, s) => {
  90. if (!n.value) {
  91. r(void 0);
  92. return;
  93. }
  94. n.value.validateFields(e).then((a) => {
  95. l && l(!0), r(a);
  96. }).catch((a) => {
  97. if (l) {
  98. l(!1, a), r(void 0);
  99. return;
  100. }
  101. s(a);
  102. });
  103. });
  104. }, clearValidate: (e) => {
  105. n.value && n.value.clearValidate(e);
  106. }, resetFields: (e) => {
  107. n.value && n.value.resetFields(e);
  108. }, getFieldsValue: (e) => n.value ? n.value.getFieldsValue(e) : {}, setFieldsValue: (e) => {
  109. n.value && n.value.setFieldsValue(e);
  110. } }), (e, t) => {
  111. const l = B;
  112. return S(), w("div", A, [
  113. V(l, _({
  114. labelCol: b.value.labelCol,
  115. model: u.model,
  116. rules: u.rules,
  117. layout: u.layout
  118. }, F.value, {
  119. ref_key: "form",
  120. ref: n,
  121. style: {
  122. display: "grid",
  123. gridTemplateColumns: `repeat(${p.value}, 1fr)`,
  124. gap: "20px"
  125. }
  126. }), {
  127. default: C(() => [
  128. x(e.$slots, "default", {}, void 0, !0)
  129. ]),
  130. _: 3
  131. }, 16, ["labelCol", "model", "rules", "layout", "style"])
  132. ]);
  133. };
  134. }
  135. }, M = /* @__PURE__ */ O(j, [["__scopeId", "data-v-633f4395"]]);
  136. export {
  137. M as default
  138. };