SListLayout.js 15 KB

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