SSuperListLayout.js 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445
  1. import { h as B, resolveComponent as f, resolveDirective as I, openBlock as o, createElementBlock as l, createElementVNode as r, toDisplayString as y, Fragment as R, renderList as S, withDirectives as H, createBlock as b, withCtx as m, resolveDynamicComponent as K, createCommentVNode as d, createTextVNode as k, vShow as P, renderSlot as u, createVNode as c, normalizeStyle as w, createSlots as L } from "vue";
  2. import { S as T } from "./index7.js";
  3. import { l as A, U as F } from "./index2.js";
  4. const V = {
  5. name: "SListLayout",
  6. components: {
  7. STable: T
  8. // ImportModal
  9. },
  10. data() {
  11. return {
  12. _: this,
  13. filterVisible: !1,
  14. drawerVisible: !1,
  15. importLoading: !1,
  16. exportLoading: !1,
  17. importVisible: !1,
  18. isFilter: !1,
  19. layoutHeight: 0,
  20. tableScrollPx: 0,
  21. spinning: !1,
  22. pageSize: 20,
  23. sideWidth: 232,
  24. showSelection: !1,
  25. selectedRowKeys: [],
  26. expandedRowKeys: [],
  27. renderColumns: [],
  28. startX: 0,
  29. dragWidth: 0,
  30. renderButtons: [],
  31. iconMap: {
  32. add: "PlusCircleOutlined",
  33. edit: "FormOutlined",
  34. delete: "DeleteOutlined",
  35. remove: "DeleteOutlined",
  36. import: "UploadOutlined",
  37. export: "DownloadOutlined",
  38. assign: "ClusterOutlined",
  39. execute: "PlayOircleOutlined",
  40. pause: "PauseOircleOutlined",
  41. resume: "PoweroffOutlined",
  42. approve: "HighlightOutlined",
  43. setting: "SettingOutlined",
  44. TopOfType: "VerticalAlignTopOutlined",
  45. TOP: "VerticalAlignTopOutlined",
  46. synchronize: "SyncOutlined"
  47. }
  48. };
  49. },
  50. props: {
  51. // 页面标题
  52. title: {
  53. type: String,
  54. required: !0
  55. },
  56. buttons: {
  57. type: Array,
  58. default() {
  59. return [
  60. {
  61. name: "添加",
  62. key: "add",
  63. show: !0,
  64. type: "primary",
  65. icon: !0,
  66. api: null
  67. },
  68. {
  69. name: "批量删除",
  70. key: "remove",
  71. action: "remove",
  72. show: !0,
  73. icon: !0,
  74. api: null
  75. },
  76. {
  77. name: "导入",
  78. key: "import",
  79. show: !0,
  80. icon: !0,
  81. api: null,
  82. templateApi: null
  83. },
  84. {
  85. name: "导出",
  86. key: "export",
  87. show: !0,
  88. icon: !0,
  89. api: null
  90. }
  91. ];
  92. }
  93. },
  94. // 列表checkbox列
  95. isSelection: {
  96. type: Boolean,
  97. default: !1
  98. },
  99. showPagination: {
  100. type: Boolean,
  101. default: !0
  102. },
  103. /**
  104. title = String:列标题
  105. * @dataIndex = String:列数据字段名
  106. * @align = String:left || right || center
  107. * @ellipsis = true:是否自动换行
  108. * @isClick = true:是否支持点击跳转
  109. * @template = true:是否使用自定义模板
  110. * @customRender = Function:自定义jsx模板
  111. * @fixed = null:是否固定列 left || right || null 默认null
  112. * @isFixed = false:是否固定列 Boolean fixed存在时无效
  113. * @width = null:列宽 不要写百分比 组件内强制转换成Number
  114. * @filterConfig = 默认null | Object: 自定义筛选配置 {
  115. @filterType = String: SINGLE_SELECT:单选/ MULTIPLE_SELECT:多选/ GANDER:性别/ IS:是否/ USER:用户/ OFFICE:组织机构/ DATE:日期/ DATETIME:时间/ INPUT:输入框 INT:整数/ FLOAT:浮点数/
  116. @filterApi = null:自定义接口 Function => filterType = SINGLE_SELECT || MULTIPLE_SELECT || GANDER || IS 时生效
  117. @filterData = []:自定义数据 Array => filterType = SINGLE_SELECT || MULTIPLE_SELECT || GANDER || IS 时生效 优先级大于 filterApi
  118. @props = Object:自定义属性 使用filterApi时 处理 结果集中的 key、value 键值对映射内容使用
  119. @precision = 0:小数点后保留位数 filterType = FLOAT 时生效
  120. @step = 1:步长 filterType = INT || FLOAT 时生效
  121. @minValue = 0:最小值 filterType = INT || FLOAT 时生效
  122. @maxValue = 0:最大值 filterType = INT || FLOAT 时生效
  123. @length = 200:长度 filterType = INPUT 时生效
  124. @startDate = null :开始可选时间 filterType = DATE || DATETIME 时生效
  125. @endDate = null :结束可选时间 filterType = DATE || DATETIME 时生效
  126. * }
  127. */
  128. columns: {
  129. type: Array,
  130. default() {
  131. return [];
  132. }
  133. },
  134. rowKey: {
  135. type: [Function, String],
  136. default: "id"
  137. },
  138. loadData: {
  139. type: Function,
  140. required: !0
  141. },
  142. pSize: {
  143. type: [String, Number],
  144. default: 20
  145. }
  146. },
  147. watch: {
  148. buttons: {
  149. handler(e) {
  150. e.length && this.initRenderButtons(e);
  151. },
  152. immediate: !0,
  153. deep: !0
  154. },
  155. columns: {
  156. handler(e) {
  157. this.initComponent(e);
  158. },
  159. deep: !0,
  160. immediate: !0
  161. }
  162. },
  163. methods: {
  164. isFunction(e, t = "") {
  165. return !!(e && typeof e == "function");
  166. },
  167. renderIcon(e) {
  168. return typeof e.icon == "string" ? e.icon : typeof e.icon == "boolean" && e.icon ? this.iconMap[e.key] : "";
  169. },
  170. initRenderButtons(e) {
  171. this.renderButtons = e.map((t) => (t.key === "remove" && (this.showSelection = !0), t));
  172. },
  173. initTable(e) {
  174. this.$nextTick(() => {
  175. this.layoutHeight = this.$refs.layout.offsetHeight - 50, this.setLayoutHeight(), this.pageSize = this.pSize, this.renderColumns = e.map((t) => ((t.template || t.isClick || t.dataIndex === "action" && !t.customRender) && !t.scopedSlots && (t.scopedSlots = { customRender: t.dataIndex }), (t.dataIndex === "action" || t.title === "操作") && (t.fixed = "right"), t));
  176. });
  177. },
  178. initComponent(e = []) {
  179. this.initTable(e);
  180. },
  181. reload() {
  182. this.$refs.table.refresh(!0);
  183. },
  184. // 树列表 - 新增/编辑/详情 时 不刷新
  185. setFilterParams() {
  186. },
  187. // 设置列表路由地址
  188. setHistoryPath() {
  189. const e = this.$route;
  190. sessionStorage.setItem("backPath", e.path);
  191. },
  192. // 按钮回调
  193. btnCallback(e) {
  194. this.$emit("btnCallback", e.key, this.selectedRowKeys), this[e.key] ? this[e.key](e) : this.handAction(e);
  195. },
  196. // 其他未定义按钮方法生成
  197. handAction(e) {
  198. if (e.selection !== !1 && !this.selectedRowKeys.length) {
  199. this.$message.warn(`请选择要${e.name}的数据`);
  200. return;
  201. }
  202. if (this.isFunction(e.api, e.name, e.key)) {
  203. if (e.confirm) {
  204. this.$confirm({
  205. title: `${e.name}`,
  206. content: () => B("div", { style: "color:red" }, `确认要{${e.name}}数据吗?`),
  207. onOk: () => {
  208. this.spinning = !0, e.api(this.selectedRowKeys).then(() => {
  209. this.$message.success(`${e.name}成功`), this.$emit("reset");
  210. }).finally(() => {
  211. this.spinning = !1;
  212. });
  213. }
  214. });
  215. return;
  216. }
  217. this.spinning = !0, e.api(this.selectedRowKeys).then(() => {
  218. this.$message.success(`${e.name}成功`), this.$emit("reset");
  219. }).finally(() => {
  220. this.spinning = !1;
  221. });
  222. }
  223. },
  224. // 变更按钮状态
  225. setStateBtn(e, t) {
  226. typeof e == "string" ? this.setStateBtnItem(e, t) : e.forEach((i) => {
  227. this.setStateBtnItem(i, t);
  228. });
  229. },
  230. setStateBtnItem(e, t) {
  231. const i = this.renderButtons.find((h) => h.key === e);
  232. if (!i) {
  233. console.error(`按钮(${e})未定义, 请确认该变更状态按钮是否设置正确`);
  234. return;
  235. }
  236. Object.keys(t).forEach((h) => {
  237. i[h] = t[h];
  238. });
  239. },
  240. // 添加方法
  241. add() {
  242. },
  243. // 删除方法
  244. delete(e) {
  245. this.handAction(e);
  246. },
  247. // 导入方法
  248. import() {
  249. this.importVisible = !0;
  250. },
  251. // 导出方法
  252. export(e) {
  253. this.isFunction(e.api, e.name, e.key) && (this.spinning = !0, this.exportApi().then(() => {
  254. this.spinning = !1;
  255. }));
  256. },
  257. // 导入回调
  258. importExcel(e) {
  259. this.importLoading = !0;
  260. const t = this.renderButtons.find((i) => i.key === "import");
  261. this.isFunction(t.api, t.name, t.key) && t.api(e).then(() => {
  262. this.importLoading = !1, this.$message.success("导入成功"), this.importVisible = !1, this.$emit("reset");
  263. });
  264. },
  265. // 模板下载回调
  266. exportExcelTemplate() {
  267. const e = this.renderButtons.find((t) => t.key === "import");
  268. this.isFunction(e.templateApi, e.name, e.key) && (this.exportLoading = !0, e.templateApi().finally(() => {
  269. this.exportLoading = !1;
  270. }));
  271. },
  272. // 表格可点击列事件回调
  273. tableColCallback(e, t) {
  274. this.$emit("tableColCallback", e, t);
  275. },
  276. onSelectChange(e) {
  277. this.selectedRowKeys = e;
  278. },
  279. // 设置表格滚动条高度
  280. setLayoutHeight() {
  281. this.$nextTick(() => {
  282. const t = this.$refs.filters && this.$refs.filters.offsetHeight || 0, i = this.$refs.tabs && this.$refs.tabs.offsetHeight || 0;
  283. this.tableScrollPx = this.layoutHeight - t - 103 - i;
  284. });
  285. }
  286. },
  287. mounted() {
  288. }
  289. }, z = {
  290. class: "list-layout",
  291. ref: "layout"
  292. }, D = { class: "tools" }, E = { class: "title" }, N = { class: "btn-list" }, U = {
  293. key: 0,
  294. style: { "margin-left": "8px" }
  295. }, q = {
  296. key: 0,
  297. class: "list-filter-wrap",
  298. ref: "filters"
  299. }, M = { class: "filter-content" }, W = { class: "filter" }, j = {
  300. key: 0,
  301. class: "desc-wrap"
  302. }, X = { class: "table-content" }, G = {
  303. key: 0,
  304. class: "tabs-wrap",
  305. ref: "tabs"
  306. }, J = { class: "table-container" }, Q = ["onClick"], Y = { class: "other" };
  307. function Z(e, t, i, h, n, p) {
  308. const g = F, C = f("SearchOutlined"), v = f("SettingOutlined"), _ = f("s-table"), x = f("setting-filter"), O = f("setting-columns"), $ = I("action");
  309. return o(), l("div", z, [
  310. r("div", D, [
  311. r("div", E, y(i.title), 1),
  312. r("div", N, [
  313. (o(!0), l(R, null, S(n.renderButtons, (s) => (o(), l("span", {
  314. class: "item-btn",
  315. key: s.key
  316. }, [
  317. H((o(), b(g, {
  318. class: "btn",
  319. disabled: !!s.disabled,
  320. type: s.type || s.key === "add" ? "primary" : "default",
  321. onClick: (a) => p.btnCallback(s)
  322. }, {
  323. icon: m(() => [
  324. p.renderIcon(s) ? (o(), b(K(p.renderIcon(s)), { key: 0 })) : d("", !0)
  325. ]),
  326. default: m(() => [
  327. k(" " + y(s.name), 1)
  328. ]),
  329. _: 2
  330. }, 1032, ["disabled", "type", "onClick"])), [
  331. [$, s.action || s.key],
  332. [P, s.show !== !1]
  333. ])
  334. ]))), 128)),
  335. e.$slots.otherBtns ? (o(), l("span", U, [
  336. u(e.$slots, "otherBtns", { selections: n.selectedRowKeys }, void 0, !0)
  337. ])) : d("", !0),
  338. r("span", null, [
  339. c(g, {
  340. class: "btn",
  341. onClick: t[0] || (t[0] = (s) => e.$refs.filter.show(n.renderColumns))
  342. }, {
  343. default: m(() => [
  344. c(C),
  345. k(" " + y(e.$l("高级搜索")), 1)
  346. ]),
  347. _: 1
  348. }),
  349. c(g, {
  350. class: "btn",
  351. onClick: t[1] || (t[1] = (s) => e.$refs.columns.show(n.renderColumns))
  352. }, {
  353. default: m(() => [
  354. c(v),
  355. k(" " + y(e.$l("高级表格")), 1)
  356. ]),
  357. _: 1
  358. })
  359. ])
  360. ])
  361. ]),
  362. r("div", {
  363. class: "list-layout-main",
  364. style: w({ height: n.layoutHeight + "px" })
  365. }, [
  366. e.$slots.empty ? (o(), l("div", {
  367. key: 1,
  368. class: "layout-list-content",
  369. style: w({ height: n.layoutHeight + "px" })
  370. }, [
  371. u(e.$slots, "empty", {}, void 0, !0)
  372. ], 4)) : (o(), l("div", {
  373. key: 0,
  374. class: "layout-list-content",
  375. style: w({ height: n.layoutHeight + "px" })
  376. }, [
  377. e.$slots.filter || e.$slots.desc ? (o(), l("div", q, [
  378. r("div", M, [
  379. r("div", W, [
  380. u(e.$slots, "filter", {}, void 0, !0)
  381. ])
  382. ]),
  383. e.$slots.desc ? (o(), l("div", j, [
  384. u(e.$slots, "desc", {}, void 0, !0)
  385. ])) : d("", !0)
  386. ], 512)) : d("", !0),
  387. r("div", X, [
  388. e.$slots.tabs ? (o(), l("div", G, [
  389. u(e.$slots, "tabs", {}, void 0, !0)
  390. ], 512)) : d("", !0),
  391. r("div", J, [
  392. c(_, {
  393. ref: "table",
  394. size: "middle",
  395. scroll: { y: n.tableScrollPx, x: "100%" },
  396. pageSize: n.pageSize,
  397. rowKey: i.rowKey,
  398. columns: n.renderColumns,
  399. data: i.loadData,
  400. "expanded-row-keys": n.expandedRowKeys,
  401. "onUpdate:expandedRowKeys": t[2] || (t[2] = (s) => n.expandedRowKeys = s),
  402. rowSelection: n.showSelection || i.isSelection ? { selectedRowKeys: n.selectedRowKeys, onChange: p.onSelectChange } : null,
  403. showPagination: i.showPagination
  404. }, L({ _: 2 }, [
  405. S(n.renderColumns, (s) => ({
  406. name: "bodyCell",
  407. fn: m((a) => [
  408. s.template && a.column.dataIndex === s.dataIndex ? u(e.$slots, s.dataIndex, {
  409. key: 0,
  410. text: a.text,
  411. record: a.record,
  412. item: s
  413. }, void 0, !0) : d("", !0),
  414. s.isClick && a.column.dataIndex === s.dataIndex ? (o(), l("a", {
  415. key: s.dataIndex,
  416. onClick: (ee) => p.tableColCallback(s.dataIndex, a.record)
  417. }, y(a.text.name), 9, Q)) : d("", !0),
  418. a.column.dataIndex === "action" ? u(e.$slots, "action", {
  419. key: 2,
  420. record: a.record
  421. }, void 0, !0) : d("", !0)
  422. ])
  423. }))
  424. ]), 1032, ["scroll", "pageSize", "rowKey", "columns", "data", "expanded-row-keys", "rowSelection", "showPagination"])
  425. ])
  426. ])
  427. ], 4))
  428. ], 4),
  429. c(x, { ref: "filter" }, null, 512),
  430. c(O, {
  431. ref: "columns",
  432. pageCode: "demo",
  433. onReset: t[3] || (t[3] = (s = null) => {
  434. s && s(n.renderColumns);
  435. })
  436. }, null, 512),
  437. r("div", Y, [
  438. u(e.$slots, "other", {}, void 0, !0)
  439. ])
  440. ], 512);
  441. }
  442. const ie = /* @__PURE__ */ A(V, [["render", Z], ["__scopeId", "data-v-c0bcfa3f"]]);
  443. export {
  444. ie as default
  445. };