SListLayout.js 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493
  1. import { ref as l, computed as Z, watch as K, onMounted as Oe, onActivated as ze, nextTick as L, onBeforeUnmount as Re, resolveComponent as E, resolveDirective as Ae, openBlock as n, createElementBlock as s, createElementVNode as c, toDisplayString as g, createVNode as C, withCtx as p, Fragment as ee, renderList as De, withDirectives as U, createBlock as S, createTextVNode as te, resolveDynamicComponent as Ie, createCommentVNode as a, vShow as oe, renderSlot as u, normalizeStyle as Be, unref as Te, h as xe } from "vue";
  2. import { n as Me, B as Pe, y as Ke, d0 as Le } from "./index2.js";
  3. import { S as Ee } from "./index9.js";
  4. const Ue = { class: "tools" }, Fe = { class: "title" }, Ve = { class: "btns" }, qe = { class: "list-layout-main" }, Ne = {
  5. key: 1,
  6. class: "side-bar s-theme-bg"
  7. }, We = {
  8. key: 2,
  9. class: "layout-list-content"
  10. }, je = {
  11. key: 0,
  12. class: "desc-wrap"
  13. }, He = {
  14. key: 0,
  15. class: "filter-content"
  16. }, Xe = { class: "filter" }, Ge = {
  17. key: 1,
  18. class: "reset-wrap"
  19. }, Je = {
  20. key: 1,
  21. class: "filter-more-content"
  22. }, Qe = { class: "table-content" }, Ye = { class: "table-container" }, Ze = ["onClick"], et = {
  23. key: 3,
  24. class: "layout-list-content"
  25. }, tt = { class: "other" }, ot = /* @__PURE__ */ Object.assign({ name: "SListLayout" }, {
  26. __name: "SListLayout",
  27. props: {
  28. // 页面标题
  29. title: {
  30. type: String,
  31. required: !0
  32. },
  33. buttons: {
  34. type: Array,
  35. default: () => [
  36. {
  37. name: window.$l("添加"),
  38. key: "add",
  39. show: !0,
  40. type: "primary",
  41. icon: !0,
  42. api: null
  43. },
  44. {
  45. name: window.$l("批量删除"),
  46. key: "remove",
  47. action: "remove",
  48. show: !0,
  49. icon: !0,
  50. api: null
  51. },
  52. {
  53. name: window.$l("导入"),
  54. key: "import",
  55. show: !0,
  56. icon: !0,
  57. importColumns: [],
  58. // 预览的表头信息
  59. importUploadUrl: null,
  60. // 上传url
  61. importApis: {
  62. templateDownload: null,
  63. importPreview: null,
  64. importData: null,
  65. exportExceptionData: null
  66. }
  67. },
  68. {
  69. name: window.$l("导出"),
  70. key: "export",
  71. show: !0,
  72. icon: !0,
  73. api: null
  74. }
  75. ]
  76. },
  77. // 列表checkbox列
  78. isSelection: {
  79. type: Boolean,
  80. default: !1
  81. },
  82. showPagination: {
  83. type: Boolean,
  84. default: !0
  85. },
  86. columns: {
  87. type: Array,
  88. default: () => []
  89. },
  90. rowKey: {
  91. type: [Function, String],
  92. default: "id"
  93. },
  94. loadData: {
  95. type: Function,
  96. required: !0
  97. },
  98. pSize: {
  99. type: [String, Number],
  100. default: 20
  101. },
  102. // 初始勾选的表格行 key(选择表格弹窗等场景由外部带入)
  103. selectedRowKeysArr: {
  104. type: Array,
  105. default: () => []
  106. }
  107. },
  108. emits: ["reset", "btnCallback", "tableColCallback"],
  109. setup(y, { expose: ne, emit: le }) {
  110. const h = y, v = le, R = l(null), se = l(null), ae = l(null), w = l(null), ie = l(8), _ = l(!1), $ = l(!1), F = l(300), m = l(!1), V = l(20), O = l(232), q = l(!1), d = l([]), N = l([]), A = l([]), k = l([]), re = {
  111. add: "PlusCircleOutlined",
  112. edit: "FormOutlined",
  113. delete: "DeleteOutlined",
  114. remove: "DeleteOutlined",
  115. import: "UploadOutlined",
  116. export: "DownloadOutlined",
  117. assign: "ClusterOutlined",
  118. execute: "PlayCircleOutlined",
  119. pause: "PauseCircleOutlined",
  120. resume: "PoweroffOutlined",
  121. approve: "HighlightOutlined",
  122. setting: "SettingOutlined",
  123. TopOfType: "VerticalAlignTopOutlined",
  124. TOP: "VerticalAlignTopOutlined",
  125. synchronize: "SyncOutlined"
  126. }, W = Z(() => k.value.map((e) => e.key).includes("import")), D = Z(() => k.value.find((e) => e.key === "import") || {});
  127. K(
  128. () => h.buttons,
  129. (e) => {
  130. e && e.length && ue(e);
  131. },
  132. { immediate: !0, deep: !0 }
  133. ), K(
  134. () => h.columns,
  135. () => X()
  136. ), K(
  137. () => h.selectedRowKeysArr,
  138. (e) => {
  139. d.value = e || [];
  140. },
  141. { immediate: !0 }
  142. );
  143. function j(e, t = "") {
  144. return !!(e && typeof e == "function");
  145. }
  146. function H(e) {
  147. return typeof e.icon == "string" ? e.icon : typeof e.icon == "boolean" && e.icon && re[e.key] || "";
  148. }
  149. function ue(e) {
  150. k.value = e.map((t) => (t.key === "remove" && (q.value = !0), t));
  151. }
  152. function de() {
  153. L(() => {
  154. Y(), V.value = h.pSize, A.value = h.columns.map((e) => ((e.template || e.isClick || e.dataIndex === "action" && !e.customRender) && !e.scopedSlots && (e.scopedSlots = { customRender: e.dataIndex }), e));
  155. }), setTimeout(() => {
  156. const e = document.querySelector(".ant-table-cell.ant-table-cell-scrollbar"), t = document.querySelector(".ant-table-thead tr");
  157. e && t && t.removeChild(e);
  158. }, 100);
  159. }
  160. function X() {
  161. de();
  162. }
  163. function I() {
  164. $.value = !$.value, Y();
  165. }
  166. function B() {
  167. v("reset");
  168. }
  169. function T() {
  170. w.value && w.value.refresh(!0);
  171. }
  172. function G(e) {
  173. v("btnCallback", e.key, d.value);
  174. const t = $e[e.key];
  175. typeof t == "function" ? t(e) : x(e);
  176. }
  177. function x(e) {
  178. if (e.selection !== !1 && !d.value.length) {
  179. window.$message.warn(`${window.$l("请选择要")}${window.$l(e.name)}${window.$l("的数据")}`);
  180. return;
  181. }
  182. if (j(e.api, e.name, e.key)) {
  183. if (e.confirm) {
  184. window.$confirm({
  185. title: `${e.name}`,
  186. content: () => xe(
  187. "div",
  188. { style: "color:var(--s-color-error)" },
  189. `${window.$l("确认要")}{${window.$l(e.name)}}${window.$l("数据吗?")}`
  190. ),
  191. onOk: () => {
  192. m.value = !0, e.api(d.value).then(() => {
  193. window.$message.success(`${window.$l(e.name)}${window.$l("成功")}`), v("reset");
  194. }).finally(() => {
  195. m.value = !1;
  196. });
  197. }
  198. });
  199. return;
  200. }
  201. m.value = !0, e.api(d.value).then(() => {
  202. window.$message.success(`${window.$l(e.name)}${window.$l("成功")}`), v("reset");
  203. }).finally(() => {
  204. m.value = !1;
  205. });
  206. }
  207. }
  208. function J(e, t) {
  209. typeof e == "string" ? Q(e, t) : e.forEach((i) => {
  210. Q(i, t);
  211. });
  212. }
  213. function Q(e, t) {
  214. const i = k.value.find((r) => r.key === e);
  215. if (!i) {
  216. console.error(`按钮(${e})未定义, 请确认该变更状态按钮是否设置正确`);
  217. return;
  218. }
  219. Object.keys(t).forEach((r) => {
  220. i[r] = t[r];
  221. });
  222. }
  223. function ce() {
  224. }
  225. function me(e) {
  226. x(e);
  227. }
  228. function fe() {
  229. if (!W.value) {
  230. v("btnCallback", "import");
  231. return;
  232. }
  233. _.value = !0;
  234. }
  235. function pe(e) {
  236. j(e.api, e.name, e.key) && (m.value = !0, e.api().then(() => {
  237. m.value = !1;
  238. }));
  239. }
  240. function ye(e, t) {
  241. v("tableColCallback", e, t);
  242. }
  243. function M(e) {
  244. return A.value.find((t) => t.dataIndex === e);
  245. }
  246. function ve(e) {
  247. const t = M(e);
  248. return !!(t && t.template);
  249. }
  250. function we(e) {
  251. const t = M(e);
  252. return !!(t && t.isClick);
  253. }
  254. function ke(e) {
  255. return e == null ? "" : typeof e == "object" ? e.name === void 0 ? "" : e.name : e;
  256. }
  257. function he(e) {
  258. d.value = e;
  259. }
  260. function Y() {
  261. L(P);
  262. }
  263. function P() {
  264. const e = w.value && w.value.$el, t = e && e.querySelector(".ant-table-body"), i = t && t.clientHeight;
  265. i && (F.value = Math.max(i - 8, 0));
  266. }
  267. const $e = {
  268. add: ce,
  269. delete: me,
  270. import: fe,
  271. export: pe,
  272. reload: T,
  273. filterReset: B,
  274. toggleFilter: I,
  275. setStateBtn: J,
  276. handAction: x
  277. }, be = {
  278. mounted(e) {
  279. e.style.cursor = "e-resize", document.addEventListener("selectstart", (t) => {
  280. t.preventDefault();
  281. }), e.onmousedown = (t) => {
  282. const i = t.clientX, r = O.value;
  283. document.onmousemove = (z) => {
  284. const f = z.clientX - i;
  285. if (f < 0) {
  286. if (r + f <= 232) return;
  287. O.value = r + f;
  288. } else {
  289. if (r + f >= 500) return;
  290. O.value = r + f;
  291. }
  292. }, document.onmouseup = () => {
  293. document.onmousemove = document.onmousedown = null;
  294. };
  295. };
  296. }
  297. };
  298. let b = null;
  299. return Oe(() => {
  300. X(), window.ResizeObserver && R.value && (b = new ResizeObserver(() => P()), b.observe(R.value));
  301. }), ze(() => {
  302. L(P);
  303. }), Re(() => {
  304. b && (b.disconnect(), b = null);
  305. }), ne({
  306. reload: T,
  307. spinning: m,
  308. selectedRowKeys: d,
  309. renderButtons: k,
  310. setStateBtn: J,
  311. btnCallback: G,
  312. filterReset: B,
  313. toggleFilter: I,
  314. table: w,
  315. importVisible: _
  316. }), (e, t) => {
  317. const i = Pe, r = Ee, z = E("double-right-outlined"), f = E("sync-outlined"), ge = Ke, Ce = E("s-import-modal"), Se = Ae("action");
  318. return n(), s("div", {
  319. class: "list-layout",
  320. ref_key: "layoutRef",
  321. ref: R
  322. }, [
  323. c("div", Ue, [
  324. c("div", Fe, g(y.title), 1),
  325. c("div", Ve, [
  326. C(r, { size: ie.value }, {
  327. default: p(() => [
  328. (n(!0), s(ee, null, De(k.value, (o) => (n(), s("span", {
  329. class: "item-btn",
  330. key: o.key
  331. }, [
  332. U((n(), S(i, {
  333. class: "btn",
  334. disabled: !!o.disabled,
  335. type: o.type || o.key === "add" ? "primary" : "default",
  336. onClick: (_e) => G(o)
  337. }, {
  338. icon: p(() => [
  339. H(o) ? (n(), S(Ie(H(o)), { key: 0 })) : a("", !0)
  340. ]),
  341. default: p(() => [
  342. te(" " + g(e.$l(o.name)), 1)
  343. ]),
  344. _: 2
  345. }, 1032, ["disabled", "type", "onClick"])), [
  346. [Se, o.action || o.key],
  347. [oe, o.show !== !1]
  348. ])
  349. ]))), 128)),
  350. u(e.$slots, "otherBtns", { selections: d.value }, void 0, !0)
  351. ]),
  352. _: 3
  353. }, 8, ["size"])
  354. ])
  355. ]),
  356. c("div", qe, [
  357. e.$slots.tree ? (n(), s("div", {
  358. key: 0,
  359. class: "side s-side-tree",
  360. ref: "side",
  361. style: Be([{ width: O.value + "px" }, { "overflow-y": "auto" }])
  362. }, [
  363. u(e.$slots, "tree", {}, void 0, !0)
  364. ], 4)) : a("", !0),
  365. e.$slots.tree ? U((n(), s("div", Ne, null, 512)), [
  366. [be]
  367. ]) : a("", !0),
  368. e.$slots.empty ? (n(), s("div", et, [
  369. u(e.$slots, "empty", {}, void 0, !0)
  370. ])) : (n(), s("div", We, [
  371. e.$slots.desc ? (n(), s("div", je, [
  372. u(e.$slots, "desc", {}, void 0, !0)
  373. ])) : a("", !0),
  374. e.$slots.filter || e.$slots.filterMore ? (n(), s("div", {
  375. key: 1,
  376. class: "list-filter-wrap",
  377. ref_key: "filters",
  378. ref: se
  379. }, [
  380. e.$slots.filter ? (n(), s("div", He, [
  381. c("div", Xe, [
  382. u(e.$slots, "filter", {}, void 0, !0)
  383. ]),
  384. e.$slots.filterMore ? (n(), s("a", {
  385. key: 0,
  386. class: "filter-more-btn",
  387. onClick: I
  388. }, [
  389. te(g($.value ? e.$l("收起") : e.$l("更多")) + " ", 1),
  390. $.value ? (n(), S(z, {
  391. key: 1,
  392. style: { "font-size": "12px", transform: "rotate(-90deg)" }
  393. })) : (n(), S(z, {
  394. key: 0,
  395. style: { "font-size": "12px", transform: "rotate(90deg)" }
  396. }))
  397. ])) : a("", !0),
  398. e.$slots.filter ? (n(), s("div", Ge, [
  399. C(ge, {
  400. placement: "top",
  401. overlayStyle: { maxWidth: "500px" },
  402. mouseEnterDelay: 1.5,
  403. mouseLeaveDelay: 0.5
  404. }, {
  405. title: p(() => [
  406. c("span", null, g(e.$l("条件重置")), 1)
  407. ]),
  408. default: p(() => [
  409. C(i, {
  410. style: { "padding-bottom": "2px" },
  411. onClick: B
  412. }, {
  413. icon: p(() => [
  414. C(f)
  415. ]),
  416. _: 1
  417. })
  418. ]),
  419. _: 1
  420. })
  421. ])) : a("", !0)
  422. ])) : a("", !0),
  423. e.$slots.filterMore ? U((n(), s("div", Je, [
  424. u(e.$slots, "filterMore", {}, void 0, !0)
  425. ], 512)), [
  426. [oe, $.value]
  427. ]) : a("", !0)
  428. ], 512)) : a("", !0),
  429. c("div", Qe, [
  430. e.$slots.tabs ? (n(), s("div", {
  431. key: 0,
  432. class: "tabs-wrap",
  433. ref_key: "tabs",
  434. ref: ae
  435. }, [
  436. u(e.$slots, "tabs", {}, void 0, !0)
  437. ], 512)) : a("", !0),
  438. c("div", Ye, [
  439. C(Te(Le), {
  440. ref_key: "table",
  441. ref: w,
  442. size: "middle",
  443. scroll: { y: F.value, x: "100%" },
  444. pageSize: V.value,
  445. rowKey: y.rowKey,
  446. columns: A.value,
  447. data: y.loadData,
  448. "expanded-row-keys": N.value,
  449. "onUpdate:expandedRowKeys": t[0] || (t[0] = (o) => N.value = o),
  450. rowSelection: q.value || y.isSelection ? { selectedRowKeys: d.value, onChange: he } : null,
  451. showPagination: y.showPagination
  452. }, {
  453. bodyCell: p((o) => [
  454. o.column ? (n(), s(ee, { key: 0 }, [
  455. ve(o.column.dataIndex) ? u(e.$slots, o.column.dataIndex, {
  456. text: o.text,
  457. record: o.record,
  458. index: o.index,
  459. item: M(o.column.dataIndex)
  460. }, void 0, !0, 0) : we(o.column.dataIndex) ? (n(), s("a", {
  461. key: 1,
  462. onClick: (_e) => ye(o.column.dataIndex, o.record)
  463. }, g(ke(o.text)), 9, Ze)) : o.column.dataIndex === "action" ? u(e.$slots, "action", {
  464. record: o.record
  465. }, void 0, !0, 2) : a("", !0)
  466. ], 64)) : a("", !0)
  467. ]),
  468. _: 3
  469. }, 8, ["scroll", "pageSize", "rowKey", "columns", "data", "expanded-row-keys", "rowSelection", "showPagination"])
  470. ])
  471. ])
  472. ]))
  473. ]),
  474. c("div", tt, [
  475. u(e.$slots, "other", {}, void 0, !0)
  476. ]),
  477. W.value ? (n(), S(Ce, {
  478. key: 0,
  479. ref: "importModalRef",
  480. "upload-url": D.value.importUploadUrl,
  481. value: _.value,
  482. "onUpdate:value": t[1] || (t[1] = (o) => _.value = o),
  483. columns: D.value.importColumns,
  484. apis: D.value.importApis,
  485. onReload: T
  486. }, null, 8, ["upload-url", "value", "columns", "apis"])) : a("", !0)
  487. ], 512);
  488. };
  489. }
  490. }), at = /* @__PURE__ */ Me(ot, [["__scopeId", "data-v-db45cf7b"]]);
  491. export {
  492. at as default
  493. };