SFormBasicLayout.js 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280
  1. import { ref as l, computed as U, watch as X, onMounted as Y, resolveComponent as w, openBlock as a, createElementBlock as c, createVNode as d, withCtx as v, createElementVNode as s, toDisplayString as m, renderSlot as g, createCommentVNode as i, Fragment as O, renderList as W, createBlock as b, normalizeStyle as A, normalizeClass as Z, createTextVNode as T, nextTick as ee } from "vue";
  2. import { n as te, ao as ae, B as oe } from "./index2.js";
  3. import { _ as le, S as ne } from "./index10.js";
  4. import { T as se, _ as ie } from "./index11.js";
  5. const ue = { class: "row" }, ce = { class: "title" }, re = { class: "btns" }, fe = {
  6. key: 0,
  7. class: "row sub-title-wrap"
  8. }, de = { class: "sub-title" }, ve = ["id"], ye = {
  9. key: 1,
  10. class: "collapses-content-wrap"
  11. }, me = { class: "modal" }, be = /* @__PURE__ */ Object.assign({ name: "SFormBasicLayout" }, {
  12. __name: "SFormBasicLayout",
  13. props: {
  14. loading: {
  15. type: Boolean,
  16. default: !1
  17. },
  18. // 表单主体容器的 id(锚点/表单定位用)
  19. commonId: {
  20. type: String,
  21. default: "form-container"
  22. },
  23. // 页面标题
  24. title: {
  25. type: String,
  26. required: !0
  27. },
  28. subTitle: {
  29. type: String,
  30. default: ""
  31. },
  32. showBtnIcon: {
  33. type: Boolean,
  34. default: !0
  35. },
  36. steps: {
  37. type: Array,
  38. default: () => []
  39. },
  40. stepDefaultActive: {
  41. type: Number,
  42. default: 0
  43. },
  44. // 上一步校验:返回 Promise<boolean>,resolve(false) 时停在当前步
  45. stepValid: {
  46. type: Function,
  47. default: void 0
  48. },
  49. tabs: {
  50. type: Array,
  51. default: () => []
  52. },
  53. tabKey: {
  54. type: Object,
  55. default: () => ({
  56. label: "label",
  57. value: "value"
  58. })
  59. },
  60. formStyle: {
  61. type: Object,
  62. default: () => ({})
  63. },
  64. goBack: {
  65. type: Boolean,
  66. default: !0
  67. },
  68. isShowSave: {
  69. type: Boolean,
  70. default: !0
  71. },
  72. saveBtnText: {
  73. type: String,
  74. default: "保存"
  75. }
  76. },
  77. emits: ["footer-callback", "tabsChange"],
  78. setup(t, { expose: z, emit: E }) {
  79. const n = t, y = E, R = l(null), q = l(null), V = l(null), K = l(null), N = l(null), x = l(null), F = l("0px"), D = l("100%"), o = l(0), C = U(() => n.tabKey && n.tabKey.value || "value"), p = l("");
  80. X(() => n.tabs, () => {
  81. const e = n.tabs || [];
  82. if (!e.length) {
  83. p.value = "";
  84. return;
  85. }
  86. const r = C.value;
  87. e.some((u) => u && u[r] === p.value) || (p.value = e[0][r]);
  88. }, { immediate: !0, deep: !0 });
  89. function P() {
  90. ee(() => {
  91. var k, _, f, S, B;
  92. const e = ((k = V.value) == null ? void 0 : k.offsetHeight) || 0, r = ((_ = K.value) == null ? void 0 : _.offsetHeight) || 0, u = ((f = x.value) == null ? void 0 : f.offsetHeight) || 0, $ = n.subTitle ? 34 : 0;
  93. F.value = (((S = R.value) == null ? void 0 : S.offsetHeight) || 0) - u - e - r - $ - 20 + "px";
  94. const H = 0;
  95. D.value = (((B = N.value) == null ? void 0 : B.offsetWidth) || 0) - H + "px";
  96. });
  97. }
  98. function I() {
  99. y("footer-callback", "cancel");
  100. }
  101. function L() {
  102. o.value--, y("footer-callback", "prev", o.value);
  103. }
  104. function j() {
  105. if (typeof n.stepValid != "function") {
  106. o.value++, y("footer-callback", "next", o.value);
  107. return;
  108. }
  109. n.stepValid(o.value).then((e) => {
  110. e && (o.value++, y("footer-callback", "next", o.value));
  111. });
  112. }
  113. function M() {
  114. y("footer-callback", "save");
  115. }
  116. function G(e) {
  117. p.value = e;
  118. const r = n.tabs.find((u) => u[C.value] === e);
  119. y("tabsChange", r);
  120. }
  121. return Y(() => {
  122. P(), o.value = n.stepDefaultActive;
  123. }), z({
  124. save: M,
  125. rollback: I,
  126. handNext: j,
  127. handPrev: L,
  128. stepActive: o
  129. }), (e, r) => {
  130. const u = ne, $ = le, H = ie, k = se, _ = w("close-outlined"), f = oe, S = w("arrow-left-outlined"), B = w("arrow-right-outlined"), J = w("save-outlined"), Q = ae;
  131. return a(), c("div", {
  132. class: "s-form-basic-layout",
  133. ref_key: "layoutRef",
  134. ref: R
  135. }, [
  136. d(Q, { spinning: t.loading }, {
  137. default: v(() => [
  138. s("div", {
  139. class: "tools",
  140. ref_key: "toolsRef",
  141. ref: q
  142. }, [
  143. s("div", ue, [
  144. s("div", ce, [
  145. s("span", null, m(t.title), 1)
  146. ]),
  147. s("div", re, [
  148. g(e.$slots, "otherBtns", {}, void 0, !0)
  149. ])
  150. ]),
  151. t.subTitle ? (a(), c("div", fe, [
  152. s("div", de, m(t.subTitle), 1)
  153. ])) : i("", !0)
  154. ], 512),
  155. t.steps && t.steps.length ? (a(), c("div", {
  156. key: 0,
  157. class: "step-wrap",
  158. ref_key: "stepRef",
  159. ref: V
  160. }, [
  161. d($, {
  162. current: o.value,
  163. type: "navigation"
  164. }, {
  165. default: v(() => [
  166. (a(!0), c(O, null, W(t.steps, (h) => (a(), b(u, {
  167. title: h,
  168. key: h,
  169. disabled: ""
  170. }, null, 8, ["title"]))), 128))
  171. ]),
  172. _: 1
  173. }, 8, ["current"])
  174. ], 512)) : i("", !0),
  175. t.tabs && t.tabs.length ? (a(), c("div", {
  176. key: 1,
  177. class: "tabs-wrap",
  178. ref_key: "tabsRef",
  179. ref: K
  180. }, [
  181. d(k, {
  182. "active-key": p.value,
  183. onChange: G
  184. }, {
  185. default: v(() => [
  186. (a(!0), c(O, null, W(t.tabs, (h) => (a(), b(H, {
  187. tab: h[t.tabKey.label],
  188. key: h[C.value]
  189. }, null, 8, ["tab"]))), 128))
  190. ]),
  191. _: 1
  192. }, 8, ["active-key"])
  193. ], 512)) : i("", !0),
  194. s("div", {
  195. class: Z(["form-layout-main", { whiteBg: !!e.$slots.form }]),
  196. id: t.commonId,
  197. ref_key: "formMain",
  198. ref: N,
  199. style: A({ height: F.value })
  200. }, [
  201. e.$slots.form ? (a(), c("div", {
  202. key: 0,
  203. class: "form-container-wrap",
  204. style: A(t.formStyle)
  205. }, [
  206. g(e.$slots, "form", {}, void 0, !0)
  207. ], 4)) : i("", !0),
  208. e.$slots.collapses ? (a(), c("div", ye, [
  209. g(e.$slots, "collapses", {}, void 0, !0)
  210. ])) : i("", !0)
  211. ], 14, ve),
  212. s("div", me, [
  213. g(e.$slots, "other", {}, void 0, !0)
  214. ]),
  215. s("div", {
  216. class: "s-form-basic-fixed-footer",
  217. ref_key: "footer",
  218. ref: x,
  219. style: A({ width: D.value })
  220. }, [
  221. t.goBack ? (a(), b(f, {
  222. key: 0,
  223. class: "btn",
  224. onClick: I
  225. }, {
  226. default: v(() => [
  227. d(_),
  228. T(m(e.$l("取消")), 1)
  229. ]),
  230. _: 1
  231. })) : i("", !0),
  232. t.steps.length ? (a(), b(f, {
  233. key: 1,
  234. class: "btn",
  235. disabled: o.value === t.stepDefaultActive,
  236. onClick: L
  237. }, {
  238. default: v(() => [
  239. d(S),
  240. T(m(e.$l("上一步")), 1)
  241. ]),
  242. _: 1
  243. }, 8, ["disabled"])) : i("", !0),
  244. t.steps.length ? (a(), b(f, {
  245. key: 2,
  246. class: "btn",
  247. type: "primary",
  248. disabled: o.value === t.steps.length - 1,
  249. onClick: j
  250. }, {
  251. default: v(() => [
  252. d(B),
  253. T(m(e.$l("下一步")), 1)
  254. ]),
  255. _: 1
  256. }, 8, ["disabled"])) : i("", !0),
  257. t.isShowSave ? (a(), b(f, {
  258. key: 3,
  259. style: { "margin-right": "8px" },
  260. type: "primary",
  261. onClick: M
  262. }, {
  263. default: v(() => [
  264. d(J),
  265. T(" " + m(e.$l(t.saveBtnText)), 1)
  266. ]),
  267. _: 1
  268. })) : i("", !0),
  269. g(e.$slots, "footer", {}, void 0, !0)
  270. ], 4)
  271. ]),
  272. _: 3
  273. }, 8, ["spinning"])
  274. ], 512);
  275. };
  276. }
  277. }), Se = /* @__PURE__ */ te(be, [["__scopeId", "data-v-ec389f6b"]]);
  278. export {
  279. Se as default
  280. };