SListLayout.js 15 KB

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