SForm.js 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. import { useAttrs as h, ref as u, computed as s, watchEffect as y, openBlock as b, createElementBlock as F, createVNode as g, mergeProps as S, withCtx as V, renderSlot as _ } from "vue";
  2. import { n as w } from "./index2.js";
  3. import { F as v } from "./index4.js";
  4. const C = { class: "s-form" }, x = {
  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(a, { expose: c }) {
  39. const n = h(), o = a, t = u(), d = u(o.column >= 5 ? 4 : o.column), i = /* @__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. ]), f = (e) => typeof e == "boolean" ? e : e === "" || e === null || e === void 0 ? e === "" ? !0 : e : typeof e == "string" ? !(e === "false" || e === "0") : !!e, m = s(() => {
  59. const e = {};
  60. return Object.keys(n || {}).forEach((l) => {
  61. const r = n[l];
  62. e[l] = i.has(l) ? f(r) : r;
  63. }), e;
  64. }), p = s(() => {
  65. const e = o.layout, l = (o == null ? void 0 : o.labelWidth) + "";
  66. return e === "horizontal" ? {
  67. style: {
  68. width: l.includes("px") ? l : l + "px"
  69. }
  70. } : {};
  71. });
  72. return y(() => {
  73. o.column > 4 && console.warn(`当前设置表单列column【${o.column}】最多显示为4列,已默认为最多4列`);
  74. }), c({ validate: () => new Promise((e, l) => {
  75. t.value.validate().then((r) => {
  76. e(r);
  77. }).catch((r) => {
  78. l(r);
  79. });
  80. }), clearValidate: (e) => {
  81. t.value && t.value.clearValidate(e);
  82. }, resetFields: (e) => {
  83. t.value && t.value.resetFields(e);
  84. }, getFieldsValue: (e) => t.value ? t.value.getFieldsValue(e) : {}, setFieldsValue: (e) => {
  85. t.value && t.value.setFieldsValue(e);
  86. } }), (e, l) => {
  87. const r = v;
  88. return b(), F("div", C, [
  89. g(r, S({
  90. labelCol: p.value.labelCol,
  91. model: a.model,
  92. rules: a.rules,
  93. layout: a.layout
  94. }, m.value, {
  95. ref_key: "form",
  96. ref: t,
  97. style: {
  98. display: "grid",
  99. gridTemplateColumns: `repeat(${d.value}, 1fr)`,
  100. gap: "20px"
  101. }
  102. }), {
  103. default: V(() => [
  104. _(e.$slots, "default", {}, void 0, !0)
  105. ]),
  106. _: 3
  107. }, 16, ["labelCol", "model", "rules", "layout", "style"])
  108. ]);
  109. };
  110. }
  111. }, $ = /* @__PURE__ */ w(x, [["__scopeId", "data-v-4775fdd2"]]);
  112. export {
  113. $ as default
  114. };