SListLayout.js 15 KB

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