SListLayout.js 16 KB

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