SListTableTreeLayout.js 17 KB

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