SListLayout.js 16 KB

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