index19.js 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269
  1. var u = Object.defineProperty, d = Object.defineProperties;
  2. var f = Object.getOwnPropertyDescriptors;
  3. var h = Object.getOwnPropertySymbols;
  4. var S = Object.prototype.hasOwnProperty, w = Object.prototype.propertyIsEnumerable;
  5. var c = (e, a, t) => a in e ? u(e, a, { enumerable: !0, configurable: !0, writable: !0, value: t }) : e[a] = t, l = (e, a) => {
  6. for (var t in a || (a = {}))
  7. S.call(a, t) && c(e, t, a[t]);
  8. if (h)
  9. for (var t of h(a))
  10. w.call(a, t) && c(e, t, a[t]);
  11. return e;
  12. }, n = (e, a) => d(e, f(a));
  13. import { h as g } from "vue";
  14. import { t as p, T as y } from "./Table.js";
  15. import { a_ as m } from "./index2.js";
  16. const O = {
  17. data() {
  18. return {
  19. needTotalList: [],
  20. selectedRows: [],
  21. selectedRowKeys: [],
  22. localLoading: !1,
  23. localDataSource: [],
  24. localPagination: Object.assign({}, this.pagination),
  25. pageSizeOptions: ["10", "20", "50", "100", "500"]
  26. };
  27. },
  28. props: Object.assign({}, p(), {
  29. rowKey: {
  30. type: [String, Function],
  31. default: "key"
  32. },
  33. data: {
  34. type: Function,
  35. required: !0
  36. },
  37. loading: {
  38. type: Boolean,
  39. default: !1
  40. },
  41. pageNo: {
  42. type: Number,
  43. default: 1
  44. },
  45. pageSize: {
  46. type: Number,
  47. default: 10
  48. },
  49. showSizeChanger: {
  50. type: Boolean,
  51. default: !0
  52. },
  53. size: {
  54. type: String,
  55. default: "default"
  56. },
  57. /**
  58. * alert: {
  59. * show: true,
  60. * clear: Function
  61. * }
  62. */
  63. alert: {
  64. type: [Object, Boolean],
  65. default: null
  66. },
  67. rowSelection: {
  68. type: Object,
  69. default: null
  70. },
  71. /** @Deprecated */
  72. showAlertInfo: {
  73. type: Boolean,
  74. default: !1
  75. },
  76. showPagination: {
  77. type: [String, Boolean],
  78. default: "auto"
  79. },
  80. /**
  81. * enable page URI mode
  82. *
  83. * e.g:
  84. * /users/1
  85. * /users/2
  86. * /users/3?queryParam=test
  87. * ...
  88. */
  89. pageURI: {
  90. type: Boolean,
  91. default: !1
  92. }
  93. }),
  94. watch: {
  95. "localPagination.current"(e) {
  96. this.pageURI && this.router.push(n(l({}, this.$route), {
  97. name: this.$route.name,
  98. params: Object.assign({}, this.$route.params, {
  99. pageNo: e
  100. })
  101. }));
  102. },
  103. pageNo(e) {
  104. Object.assign(this.localPagination, {
  105. current: e
  106. });
  107. },
  108. pageSize(e) {
  109. Object.assign(this.localPagination, {
  110. pageSize: e
  111. });
  112. },
  113. showSizeChanger(e) {
  114. Object.assign(this.localPagination, {
  115. showSizeChanger: e
  116. });
  117. }
  118. },
  119. created() {
  120. const { pageNo: e } = this.$route.params, a = this.pageURI && e && parseInt(e) || this.pageNo;
  121. this.localPagination = ["auto", !0].includes(this.showPagination) && Object.assign({}, this.localPagination, {
  122. current: a,
  123. pageSize: this.pageSize,
  124. pageSizeOptions: this.pageSizeOptions,
  125. showSizeChanger: this.showSizeChanger,
  126. showQuickJumper: !0,
  127. showTotal: (t) => `共${t}条`
  128. }) || !1, this.needTotalList = this.initTotalList(this.columns), this.loadData();
  129. },
  130. methods: {
  131. getTableHeight() {
  132. return "500px";
  133. },
  134. /**
  135. * 表格重新加载方法
  136. * 如果参数为 true, 则强制刷新到第一页
  137. * @param Boolean bool
  138. */
  139. refresh(e = !1) {
  140. e && (this.localPagination = Object.assign(
  141. {},
  142. {
  143. current: 1,
  144. pageSize: this.pageSize
  145. }
  146. )), this.loadData();
  147. },
  148. /**
  149. * 加载数据方法
  150. * @param {Object} pagination 分页选项器
  151. * @param {Object} filters 过滤条件
  152. * @param {Object} sorter 排序条件
  153. */
  154. loadData(e, a, t) {
  155. const i = Object.assign(
  156. {
  157. pageNo: e && e.current || this.showPagination && this.localPagination.current || this.pageNo,
  158. pageSize: e && e.pageSize || this.showPagination && this.localPagination.pageSize || this.pageSize
  159. },
  160. t && t.field && {
  161. sortField: t.field
  162. } || {},
  163. t && t.order && {
  164. sortOrder: t.order
  165. } || {},
  166. l({}, a)
  167. ), s = this.data(i);
  168. (typeof s == "object" || typeof s == "function") && typeof s.then == "function" && (this.localLoading = !0, s.then((o) => {
  169. if (this.localPagination = this.showPagination && Object.assign({}, this.localPagination, {
  170. current: o.pageNo,
  171. // 返回结果中的当前分页数
  172. total: o.total,
  173. // 返回结果中的总记录数
  174. showSizeChanger: this.showSizeChanger,
  175. pageSize: e && e.pageSize || this.localPagination.pageSize
  176. }) || !1, o.list.length === 0 && this.showPagination && this.localPagination.current > 1) {
  177. this.localPagination.current--, this.loadData();
  178. return;
  179. }
  180. this.localDataSource = o.list, this.localLoading = !1;
  181. }));
  182. },
  183. initTotalList(e) {
  184. const a = [];
  185. return e && e instanceof Array && e.forEach((t) => {
  186. t.needTotal && a.push(n(l({}, t), {
  187. total: 0
  188. }));
  189. }), a;
  190. },
  191. /**
  192. * 用于更新已选中的列表数据 total 统计
  193. * @param selectedRowKeys
  194. * @param selectedRows
  195. */
  196. updateSelect(e, a) {
  197. this.selectedRows = a, this.selectedRowKeys = e;
  198. const t = this.needTotalList;
  199. this.needTotalList = t.map((i) => n(l({}, i), {
  200. total: a.reduce((s, o) => {
  201. const r = s + parseInt(m(o, i.dataIndex));
  202. return isNaN(r) ? 0 : r;
  203. }, 0)
  204. }));
  205. },
  206. /**
  207. * 清空 table 已选中项
  208. */
  209. clearSelected() {
  210. this.rowSelection && (this.rowSelection.onChange([], []), this.updateSelect([], []));
  211. },
  212. /**
  213. * 处理交给 table 使用者去处理 clear 事件时,内部选中统计同时调用
  214. * @param callback
  215. * @returns {*}
  216. */
  217. renderClear(e) {
  218. return this.selectedRowKeys.length <= 0 ? null : /* @__PURE__ */ React.createElement(
  219. "a",
  220. {
  221. style: "margin-left: 24px",
  222. onClick: () => {
  223. e(), this.clearSelected();
  224. }
  225. },
  226. "清空"
  227. );
  228. },
  229. renderAlert() {
  230. const e = this.needTotalList.map((t) => /* @__PURE__ */ React.createElement("span", { style: "margin-right: 12px" }, t.title, "总计", " ", /* @__PURE__ */ React.createElement("a", { style: "font-weight: 600" }, t.customRender ? t.customRender(t.total) : t.total))), a = typeof this.alert.clear == "boolean" && this.alert.clear ? this.renderClear(this.clearSelected) : this.alert !== null && typeof this.alert.clear == "function" ? this.renderClear(this.alert.clear) : null;
  231. return /* @__PURE__ */ React.createElement("a-alert", { showIcon: !0, style: "margin-bottom: 16px" }, /* @__PURE__ */ React.createElement("template", { "v-slot:message": !0 }, /* @__PURE__ */ React.createElement("span", { style: "margin-right: 12px" }, "已选择: ", /* @__PURE__ */ React.createElement("a", { style: "font-weight: 600" }, this.selectedRows.length)), e, a));
  232. }
  233. },
  234. render() {
  235. const e = {}, a = Object.keys(this.$data), t = typeof this.alert == "object" && this.alert !== null && this.alert.show && typeof this.rowSelection.selectedRowKeys != "undefined" || this.alert;
  236. return Object.keys(p()).forEach((i) => {
  237. const s = `local${i.substring(0, 1).toUpperCase()}${i.substring(1)}`;
  238. if (a.includes(s))
  239. return e[i] = this[s], e[i];
  240. if (i === "rowSelection") {
  241. if (t && this.rowSelection)
  242. return e[i] = n(l({}, this.rowSelection), {
  243. selectedRows: this.selectedRows,
  244. selectedRowKeys: this.selectedRowKeys,
  245. onChange: (o, r) => {
  246. this.updateSelect(o, r), typeof this[i].onChange != "undefined" && this[i].onChange(o, r);
  247. }
  248. }), e[i];
  249. if (!this.rowSelection)
  250. return e[i] = null, e[i];
  251. } else i === "scroll" && (this.scroll || (e[i] = { y: getTableHeight() }));
  252. return this[i] && (e[i] = this[i]), e[i];
  253. }), g("div", { class: "table-wrapper" }, t ? this.renderAlert() : null, [
  254. g(
  255. y,
  256. n(l({}, e), {
  257. onChange: this.loadData,
  258. onExpand: (i, s) => {
  259. this.$emit("expand", i, s);
  260. }
  261. }),
  262. l({}, this.$slots)
  263. )
  264. ]);
  265. }
  266. };
  267. export {
  268. O as S
  269. };