columns.tsx 988 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. import Print from "@/utils/print";
  2. import { ref, type Ref } from "vue";
  3. import { tableDataEdit } from "../data";
  4. import { clone } from "@pureadmin/utils";
  5. export function useColumns(printRef: Ref) {
  6. const dataList = ref(clone(tableDataEdit, true));
  7. const columns: TableColumnList = [
  8. {
  9. label: "ID",
  10. prop: "id"
  11. },
  12. {
  13. label: "日期",
  14. prop: "date"
  15. },
  16. {
  17. label: "姓名",
  18. prop: "name"
  19. },
  20. {
  21. label: "地址",
  22. prop: "address"
  23. }
  24. ];
  25. const print = () => {
  26. Print(printRef.value.getTableRef().$refs.tableWrapper).toPrint;
  27. };
  28. function headerCellStyle({ columnIndex }) {
  29. return columnIndex === 0
  30. ? { background: "#f3b2d0" }
  31. : { background: "#fafafa" };
  32. }
  33. function rowStyle({ rowIndex }) {
  34. return rowIndex % 2 === 1
  35. ? { background: "#ffa39e" }
  36. : { background: "#91d5ff" };
  37. }
  38. return {
  39. columns,
  40. dataList,
  41. print,
  42. headerCellStyle,
  43. rowStyle
  44. };
  45. }