SListCardLayout.js 17 KB

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