columns.tsx 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. import type {
  2. LoadingConfig,
  3. AdaptiveConfig,
  4. PaginationProps
  5. } from "@pureadmin/table";
  6. import { tableData } from "../data";
  7. import { ref, onMounted, reactive } from "vue";
  8. import { clone, delay } from "@pureadmin/utils";
  9. export function useColumns() {
  10. const dataList = ref([]);
  11. const loading = ref(true);
  12. const columns: TableColumnList = [
  13. {
  14. label: "日期",
  15. prop: "date"
  16. },
  17. {
  18. label: "姓名",
  19. prop: "name"
  20. },
  21. {
  22. label: "地址",
  23. prop: "address"
  24. }
  25. ];
  26. /** 分页配置 */
  27. const pagination = reactive<PaginationProps>({
  28. pageSize: 20,
  29. currentPage: 1,
  30. pageSizes: [20, 40, 60],
  31. total: 0,
  32. align: "right",
  33. background: true,
  34. size: "default"
  35. });
  36. /** 加载动画配置 */
  37. const loadingConfig = reactive<LoadingConfig>({
  38. text: "正在加载第一页...",
  39. viewBox: "-10, -10, 50, 50",
  40. spinner: `
  41. <path class="path" d="
  42. M 30 15
  43. L 28 17
  44. M 25.61 25.61
  45. A 15 15, 0, 0, 1, 15 30
  46. A 15 15, 0, 1, 1, 27.99 7.5
  47. L 15 15
  48. " style="stroke-width: 4px; fill: rgba(0, 0, 0, 0)"/>
  49. `
  50. // svg: "",
  51. // background: rgba()
  52. });
  53. /** 撑满内容区自适应高度相关配置 */
  54. const adaptiveConfig: AdaptiveConfig = {
  55. /** 表格距离页面底部的偏移量,默认值为 `96` */
  56. offsetBottom: 110
  57. /** 是否固定表头,默认值为 `true`(如果不想固定表头,fixHeader设置为false并且表格要设置table-layout="auto") */
  58. // fixHeader: true
  59. /** 页面 `resize` 时的防抖时间,默认值为 `60` ms */
  60. // timeout: 60
  61. /** 表头的 `z-index`,默认值为 `100` */
  62. // zIndex: 100
  63. };
  64. function onSizeChange(val) {
  65. console.log("onSizeChange", val);
  66. }
  67. function onCurrentChange(val) {
  68. loadingConfig.text = `正在加载第${val}页...`;
  69. loading.value = true;
  70. delay(600).then(() => {
  71. loading.value = false;
  72. });
  73. }
  74. onMounted(() => {
  75. delay(600).then(() => {
  76. const newList = [];
  77. Array.from({ length: 6 }).forEach(() => {
  78. newList.push(clone(tableData, true));
  79. });
  80. newList.flat(Infinity).forEach((item, index) => {
  81. dataList.value.push({ id: index, ...item });
  82. });
  83. pagination.total = dataList.value.length;
  84. loading.value = false;
  85. });
  86. });
  87. return {
  88. loading,
  89. columns,
  90. dataList,
  91. pagination,
  92. loadingConfig,
  93. adaptiveConfig,
  94. onSizeChange,
  95. onCurrentChange
  96. };
  97. }