SNewestDataListLayout.js 18 KB

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