SFormLayout.js 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354
  1. import { useSlots as ue, ref as o, computed as I, watch as j, nextTick as re, onMounted as de, onUnmounted as fe, resolveComponent as p, openBlock as l, createElementBlock as f, createVNode as i, withCtx as c, createElementVNode as u, toDisplayString as h, createBlock as m, createTextVNode as w, createCommentVNode as r, renderSlot as g, Fragment as M, renderList as q, normalizeStyle as S, normalizeClass as me } from "vue";
  2. import { n as ve, aB as ye, y as pe, B as he } from "./index2.js";
  3. import { S as be } from "./index9.js";
  4. import { _ as _e, S as ke } from "./index12.js";
  5. import { T as we, _ as ge } from "./index13.js";
  6. const Se = { class: "title" }, Be = { style: { "margin-right": "10px" } }, $e = { class: "btns" }, Ce = { class: "form-layout-main-content" }, Te = {
  7. key: 1,
  8. class: "collapses-content-wrap"
  9. }, Ae = { class: "collapese-container" }, ze = { class: "modal" }, Re = { class: "form-fixed-footer" }, Ve = /* @__PURE__ */ Object.assign({ name: "SFormLayout" }, {
  10. __name: "SFormLayout",
  11. props: {
  12. // 手动指定内容高度,单位 px;0 表示自动撑满
  13. viewHeight: {
  14. type: Number,
  15. default: 0
  16. },
  17. // 是否显示右侧锚点导航
  18. showAnchor: {
  19. type: Boolean,
  20. default: !0
  21. },
  22. // 表单 loading 遮罩
  23. loading: {
  24. type: Boolean,
  25. default: !1
  26. },
  27. // 页面标题
  28. title: {
  29. type: String,
  30. required: !0
  31. },
  32. // 标题右侧副标题
  33. subTitle: {
  34. type: String,
  35. default: ""
  36. },
  37. // 底部按钮是否显示图标
  38. showBtnIcon: {
  39. type: Boolean,
  40. default: !0
  41. },
  42. // 步骤条配置,传了才显示步骤区
  43. steps: {
  44. type: Array,
  45. default: () => []
  46. },
  47. // 步骤条默认选中下标
  48. stepDefaultActive: {
  49. type: Number,
  50. default: 0
  51. },
  52. // 切换步骤前的校验函数,返回 false 停在当前步
  53. stepValid: {
  54. type: Function,
  55. default: void 0
  56. },
  57. // 页签配置,传了才显示页签区
  58. tabs: {
  59. type: Array,
  60. default: () => []
  61. },
  62. // 页签字段映射:{ label, value }
  63. tabKey: {
  64. type: Object,
  65. default: () => ({
  66. label: "label",
  67. value: "value"
  68. })
  69. },
  70. // 表单区自定义样式
  71. formStyle: {
  72. type: Object,
  73. default: () => ({})
  74. },
  75. // 是否显示返回按钮
  76. goBack: {
  77. type: Boolean,
  78. default: !0
  79. },
  80. // 是否显示保存按钮
  81. isShowSave: {
  82. type: Boolean,
  83. default: !0
  84. },
  85. // 保存按钮文案
  86. saveBtnText: {
  87. type: String,
  88. default: window.$l("保存")
  89. },
  90. // 表单内容区宽度,默认 1000px
  91. width: {
  92. type: String,
  93. default: "1000px"
  94. }
  95. },
  96. emits: ["footer-callback", "tabsChange"],
  97. setup(t, { expose: H, emit: P }) {
  98. const n = t, v = P, U = ue(), T = o(null), R = o(null), G = o(null), J = o(null), Q = o(null), V = o(null), F = o(null), N = o(8), W = o({}), B = o("100%"), D = o(0), a = o(0), A = I(() => n.tabKey && n.tabKey.value || "value"), b = o("");
  99. j(() => n.tabs, () => {
  100. const e = n.tabs || [];
  101. if (!e.length) {
  102. b.value = "";
  103. return;
  104. }
  105. const s = A.value;
  106. e.some((d) => d && d[s] === b.value) || (b.value = e[0][s]);
  107. }, { immediate: !0, deep: !0 });
  108. const X = I(() => n.showAnchor && n.width);
  109. j(X, () => z(), { immediate: !0, deep: !0 });
  110. function K() {
  111. z();
  112. }
  113. function L() {
  114. v("footer-callback", "cancel");
  115. }
  116. function O() {
  117. a.value--, v("footer-callback", "prev", a.value);
  118. }
  119. function E() {
  120. if (!window.$utils.isFunction(n.stepValid)) {
  121. a.value++, v("footer-callback", "next", a.value);
  122. return;
  123. }
  124. n.stepValid(a.value).then((e) => {
  125. e && (a.value++, v("footer-callback", "next", a.value));
  126. });
  127. }
  128. function x() {
  129. v("footer-callback", "save");
  130. }
  131. function Y(e) {
  132. b.value = e;
  133. const s = n.tabs.find((d) => d[A.value] === e);
  134. v("tabsChange", s);
  135. }
  136. function z() {
  137. re(() => {
  138. var $, _;
  139. const e = {}, s = (($ = R.value) == null ? void 0 : $.offsetWidth) || 0, d = ((_ = F.value) == null ? void 0 : _.offsetWidth) || 0;
  140. d + 200 > s ? e.right = "0px" : e.left = n.width, W.value = e, n.showAnchor && U.collapses ? B.value = d + 200 > s ? `${s - 200}px` : n.width : B.value = d > s ? `${s}px` : n.width, D.value = V.value.offsetWidth - 10 + "px";
  141. });
  142. }
  143. let y = null;
  144. return de(() => {
  145. K(), a.value = n.stepDefaultActive, window.ResizeObserver && T.value && (y = new ResizeObserver(() => {
  146. K(), z();
  147. }), y.observe(T.value));
  148. }), fe(() => {
  149. y == null || y.disconnect(), y = null;
  150. }), H({
  151. save: x,
  152. rollback: L,
  153. handNext: E,
  154. handPrev: O,
  155. stepActive: a,
  156. formWidth: B
  157. }), (e, s) => {
  158. const d = p("InfoCircleOutlined"), $ = pe, _ = be, Z = ke, ee = _e, te = ge, le = we, ne = p("s-anchor"), oe = p("close-outlined"), C = he, ae = p("arrow-left-outlined"), se = p("arrow-right-outlined"), ie = p("save-outlined"), ce = ye;
  159. return l(), f("div", {
  160. class: "form-layout",
  161. ref_key: "layout",
  162. ref: T
  163. }, [
  164. i(ce, { spinning: t.loading }, {
  165. default: c(() => [
  166. t.title || t.subTitle || e.$slots.otherBtns ? (l(), f("div", {
  167. key: 0,
  168. class: "tools",
  169. ref_key: "toolsRef",
  170. ref: G
  171. }, [
  172. u("div", Se, [
  173. u("span", Be, h(t.title), 1),
  174. t.subTitle ? (l(), m($, {
  175. key: 0,
  176. placement: "topLeft",
  177. mouseEnterDelay: 0.5,
  178. mouseLeaveDelay: 0.5
  179. }, {
  180. title: c(() => [
  181. w(h(t.subTitle), 1)
  182. ]),
  183. default: c(() => [
  184. i(d)
  185. ]),
  186. _: 1
  187. })) : r("", !0)
  188. ]),
  189. u("div", $e, [
  190. i(_, { size: N.value }, {
  191. default: c(() => [
  192. g(e.$slots, "otherBtns", {}, void 0, !0)
  193. ]),
  194. _: 3
  195. }, 8, ["size"])
  196. ])
  197. ], 512)) : r("", !0),
  198. t.steps && t.steps.length ? (l(), f("div", {
  199. key: 1,
  200. class: "step-wrap",
  201. ref_key: "stepRef",
  202. ref: J
  203. }, [
  204. i(ee, {
  205. current: a.value,
  206. type: "navigation",
  207. size: "small"
  208. }, {
  209. default: c(() => [
  210. (l(!0), f(M, null, q(t.steps, (k) => (l(), m(Z, {
  211. title: k,
  212. key: k,
  213. disabled: !0
  214. }, null, 8, ["title"]))), 128))
  215. ]),
  216. _: 1
  217. }, 8, ["current"])
  218. ], 512)) : r("", !0),
  219. t.tabs && t.tabs.length ? (l(), f("div", {
  220. key: 2,
  221. class: "tabs-wrap",
  222. ref_key: "tabsRef",
  223. ref: Q
  224. }, [
  225. i(le, {
  226. "active-key": b.value,
  227. onChange: Y
  228. }, {
  229. default: c(() => [
  230. (l(!0), f(M, null, q(t.tabs, (k) => (l(), m(te, {
  231. tab: k[t.tabKey.label],
  232. key: k[A.value]
  233. }, null, 8, ["tab"]))), 128))
  234. ]),
  235. _: 1
  236. }, 8, ["active-key"])
  237. ], 512)) : r("", !0),
  238. u("div", Ce, [
  239. u("div", {
  240. class: "border-top",
  241. style: S({
  242. width: D.value
  243. })
  244. }, null, 4),
  245. u("div", {
  246. class: "form-layout-main-scroll",
  247. ref_key: "mainScroll",
  248. ref: R
  249. }, [
  250. u("div", {
  251. class: me(["form-layout-main", { whiteBg: !!e.$slots.form || !!e.$slots.collapses }]),
  252. ref_key: "formMain",
  253. ref: V,
  254. style: S({
  255. width: B.value
  256. }),
  257. id: "form-container"
  258. }, [
  259. e.$slots.form ? (l(), f("div", {
  260. key: 0,
  261. class: "form-container-wrap",
  262. style: S(t.formStyle)
  263. }, [
  264. g(e.$slots, "form", {}, void 0, !0)
  265. ], 4)) : r("", !0),
  266. e.$slots.collapses ? (l(), f("div", Te, [
  267. u("div", Ae, [
  268. g(e.$slots, "collapses", {}, void 0, !0)
  269. ])
  270. ])) : r("", !0)
  271. ], 6)
  272. ], 512),
  273. t.showAnchor && e.$slots.collapses ? (l(), f("div", {
  274. key: 0,
  275. class: "collapses-nav",
  276. style: S(W.value)
  277. }, [
  278. i(ne, { el: "form-layout-main-scroll" })
  279. ], 4)) : r("", !0)
  280. ]),
  281. u("div", ze, [
  282. g(e.$slots, "other", {}, void 0, !0)
  283. ]),
  284. u("div", Re, [
  285. i(_, { size: N.value }, {
  286. default: c(() => [
  287. t.goBack ? (l(), m(C, {
  288. key: 0,
  289. onClick: L,
  290. class: "btn"
  291. }, {
  292. default: c(() => [
  293. i(oe),
  294. w(h(e.$l("取消")), 1)
  295. ]),
  296. _: 1
  297. })) : r("", !0),
  298. t.steps.length ? (l(), m(C, {
  299. key: 1,
  300. class: "btn",
  301. disabled: a.value === t.stepDefaultActive,
  302. onClick: O
  303. }, {
  304. default: c(() => [
  305. i(ae),
  306. w(h(e.$l("上一步")), 1)
  307. ]),
  308. _: 1
  309. }, 8, ["disabled"])) : r("", !0),
  310. t.steps.length ? (l(), m(C, {
  311. key: 2,
  312. class: "btn",
  313. type: "primary",
  314. disabled: a.value === t.steps.length - 1,
  315. onClick: E
  316. }, {
  317. default: c(() => [
  318. i(se),
  319. w(h(e.$l("下一步")), 1)
  320. ]),
  321. _: 1
  322. }, 8, ["disabled"])) : r("", !0),
  323. t.isShowSave ? (l(), m(C, {
  324. key: 3,
  325. type: "primary",
  326. onClick: x
  327. }, {
  328. default: c(() => [
  329. i(ie),
  330. w(" " + h(e.$l(t.saveBtnText)), 1)
  331. ]),
  332. _: 1
  333. })) : r("", !0),
  334. g(e.$slots, "footer", {}, void 0, !0)
  335. ]),
  336. _: 3
  337. }, 8, ["size"])
  338. ]),
  339. u("div", {
  340. class: "calc-width",
  341. ref_key: "caclWidth",
  342. ref: F,
  343. style: S({ width: t.width })
  344. }, null, 4)
  345. ]),
  346. _: 3
  347. }, 8, ["spinning"])
  348. ], 512);
  349. };
  350. }
  351. }), Oe = /* @__PURE__ */ ve(Ve, [["__scopeId", "data-v-8f9a50f4"]]);
  352. export {
  353. Oe as default
  354. };