SListCardLayout.js 17 KB

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