SNewestDataListLayout.js 18 KB

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