columns.tsx 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. import { tableData } from "../data";
  2. import { clone, delay } from "@pureadmin/utils";
  3. import { ref, onMounted, reactive, watchEffect } from "vue";
  4. import type { PaginationProps, LoadingConfig, Align } from "@pureadmin/table";
  5. export function useColumns() {
  6. const dataList = ref([]);
  7. const loading = ref(true);
  8. const hideVal = ref("nohide");
  9. const tableSize = ref("default");
  10. const paginationSmall = ref(false);
  11. const paginationAlign = ref("right");
  12. const columns: TableColumnList = [
  13. {
  14. label: "日期",
  15. prop: "date",
  16. hide: () => (hideVal.value === "hideDate" ? true : false)
  17. },
  18. {
  19. label: "姓名",
  20. prop: "name",
  21. hide: () => (hideVal.value === "hideName" ? true : false)
  22. },
  23. {
  24. label: "地址",
  25. prop: "address",
  26. hide: () => (hideVal.value === "hideAddress" ? true : false)
  27. }
  28. ];
  29. /** 分页配置 */
  30. const pagination = reactive<PaginationProps>({
  31. pageSize: 10,
  32. currentPage: 1,
  33. pageSizes: [10, 15, 20],
  34. total: 0,
  35. align: "right",
  36. background: true,
  37. small: false
  38. });
  39. /** 加载动画配置 */
  40. const loadingConfig = reactive<LoadingConfig>({
  41. text: "正在加载第一页...",
  42. viewBox: "-10, -10, 50, 50",
  43. spinner: `
  44. <path class="path" d="
  45. M 30 15
  46. L 28 17
  47. M 25.61 25.61
  48. A 15 15, 0, 0, 1, 15 30
  49. A 15 15, 0, 1, 1, 27.99 7.5
  50. L 15 15
  51. " style="stroke-width: 4px; fill: rgba(0, 0, 0, 0)"/>
  52. `
  53. // svg: "",
  54. // background: rgba()
  55. });
  56. function onChange(val) {
  57. pagination.small = val;
  58. }
  59. function onSizeChange(val) {
  60. console.log("onSizeChange", val);
  61. }
  62. function onCurrentChange(val) {
  63. loadingConfig.text = `正在加载第${val}页...`;
  64. loading.value = true;
  65. delay(600).then(() => {
  66. loading.value = false;
  67. });
  68. }
  69. watchEffect(() => {
  70. pagination.align = paginationAlign.value as Align;
  71. });
  72. onMounted(() => {
  73. delay(600).then(() => {
  74. const newList = [];
  75. Array.from({ length: 6 }).forEach(() => {
  76. newList.push(clone(tableData, true));
  77. });
  78. dataList.value = newList.flat(Infinity);
  79. pagination.total = dataList.value.length;
  80. loading.value = false;
  81. });
  82. });
  83. return {
  84. loading,
  85. columns,
  86. dataList,
  87. hideVal,
  88. tableSize,
  89. pagination,
  90. loadingConfig,
  91. paginationAlign,
  92. paginationSmall,
  93. onChange,
  94. onSizeChange,
  95. onCurrentChange
  96. };
  97. }