SListTableTreeLayout.js 17 KB

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