SListCardLayout.js 18 KB

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