SForm.js 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  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 "./index5.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({
  75. validate: (e, t) => {
  76. const l = typeof e == "function" ? e : typeof t == "function" ? t : null, r = typeof e == "function" ? void 0 : e;
  77. return new Promise((s, a) => {
  78. (r && r.length ? n.value.validateFields(r) : n.value.validate()).then((c) => {
  79. l && l(!0), s(c);
  80. }).catch((c) => {
  81. if (l) {
  82. l(!1, c), s(void 0);
  83. return;
  84. }
  85. a(c);
  86. });
  87. });
  88. },
  89. validateField: (e, t) => {
  90. const l = typeof t == "function" ? t : null;
  91. return new Promise((r, s) => {
  92. if (!n.value) {
  93. r(void 0);
  94. return;
  95. }
  96. n.value.validateFields(e).then((a) => {
  97. l && l(!0), r(a);
  98. }).catch((a) => {
  99. if (l) {
  100. l(!1, a), r(void 0);
  101. return;
  102. }
  103. s(a);
  104. });
  105. });
  106. },
  107. clearValidate: (e) => {
  108. n.value && n.value.clearValidate(e);
  109. },
  110. resetFields: (e) => {
  111. n.value && n.value.resetFields(e);
  112. },
  113. getFieldsValue: (e) => n.value ? n.value.getFieldsValue(e) : {},
  114. setFieldsValue: (e) => {
  115. n.value && n.value.setFieldsValue(e);
  116. }
  117. }), (e, t) => {
  118. const l = B;
  119. return S(), w("div", A, [
  120. V(l, _({
  121. labelCol: b.value.labelCol,
  122. model: u.model,
  123. rules: u.rules,
  124. layout: u.layout
  125. }, F.value, {
  126. ref_key: "form",
  127. ref: n,
  128. style: {
  129. display: "grid",
  130. gridTemplateColumns: `repeat(${p.value}, 1fr)`,
  131. gap: "20px"
  132. }
  133. }), {
  134. default: C(() => [
  135. x(e.$slots, "default", {}, void 0, !0)
  136. ]),
  137. _: 3
  138. }, 16, ["labelCol", "model", "rules", "layout", "style"])
  139. ]);
  140. };
  141. }
  142. }, M = /* @__PURE__ */ O(j, [["__scopeId", "data-v-2925f82d"]]);
  143. export {
  144. M as default
  145. };