SSuperListLayout.js 16 KB

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