SSuperListLayout.js 18 KB

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