SNewestDataListLayout.js 18 KB

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