SNewestDataListLayout.js 19 KB

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