SForm.js 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. import { useAttrs as m, ref as n, computed as f, watchEffect as i, createElementBlock as p, openBlock as y, createVNode as h, mergeProps as _, unref as b, withCtx as v, renderSlot as g } from "vue";
  2. import { k as x } from "./index2.js";
  3. import { F as S } from "./index5.js";
  4. const w = { class: "s-form" }, C = {
  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 "horizontal";
  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(r, { expose: u }) {
  39. const c = m(), e = r, a = n(), s = n(e.column >= 5 ? 4 : e.column), d = f(() => {
  40. const o = e.layout, t = (e == null ? void 0 : e.labelWidth) + "";
  41. return o === "horizontal" ? {
  42. style: {
  43. width: t.includes("px") ? t : t + "px"
  44. }
  45. } : {};
  46. });
  47. return i(() => {
  48. e.column > 4 && console.warn(`当前设置表单列column【${e.column}】最多显示为4列,已默认为最多4列`);
  49. }), u({ validate: () => new Promise((o, t) => {
  50. a.value.validate().then((l) => {
  51. o(l);
  52. }).catch((l) => {
  53. t(l);
  54. });
  55. }) }), (o, t) => {
  56. const l = S;
  57. return y(), p("div", w, [
  58. h(l, _({
  59. labelCol: d.value.labelCol,
  60. model: r.model,
  61. rules: r.rules,
  62. layout: r.layout
  63. }, b(c), {
  64. ref_key: "form",
  65. ref: a,
  66. style: {
  67. display: "grid",
  68. gridTemplateColumns: `repeat(${s.value}, 1fr)`,
  69. gap: "20px"
  70. }
  71. }), {
  72. default: v(() => [
  73. g(o.$slots, "default", {}, void 0, !0)
  74. ]),
  75. _: 3
  76. }, 16, ["labelCol", "model", "rules", "layout", "style"])
  77. ]);
  78. };
  79. }
  80. }, j = /* @__PURE__ */ x(C, [["__scopeId", "data-v-cad3adca"]]);
  81. export {
  82. j as default
  83. };