SListCardLayout.js 17 KB

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