columns.tsx 2.6 KB

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