SListLayout.js 15 KB

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