columns.tsx 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. import { ref } from "vue";
  2. import dayjs from "dayjs";
  3. import { message } from "@/utils/message";
  4. import { ElMessageBox } from "element-plus";
  5. export function useColumns() {
  6. const switchLoadMap = ref({});
  7. const columns: TableColumnList = [
  8. {
  9. type: "selection",
  10. width: 55,
  11. align: "left",
  12. hide: ({ checkList }) => !checkList.includes("勾选列")
  13. },
  14. {
  15. label: "序号",
  16. type: "index",
  17. width: 70,
  18. hide: ({ checkList }) => !checkList.includes("序号列")
  19. },
  20. {
  21. label: "用户编号",
  22. prop: "id"
  23. },
  24. {
  25. label: "用户名称",
  26. prop: "username"
  27. },
  28. {
  29. label: "用户昵称",
  30. prop: "nickname"
  31. },
  32. {
  33. label: "性别",
  34. prop: "sex",
  35. cellRenderer: ({ row, props }) => (
  36. <el-tag
  37. size={props.size}
  38. type={row.sex === 1 ? "danger" : ""}
  39. effect="plain"
  40. >
  41. {row.sex === 1 ? "女" : "男"}
  42. </el-tag>
  43. )
  44. },
  45. {
  46. label: "部门",
  47. prop: "dept",
  48. formatter: ({ dept }) => dept.name
  49. },
  50. {
  51. label: "手机号码",
  52. prop: "mobile"
  53. },
  54. {
  55. label: "状态",
  56. prop: "status",
  57. width: 130,
  58. cellRenderer: scope => (
  59. <el-switch
  60. size={scope.props.size === "small" ? "small" : "default"}
  61. loading={switchLoadMap.value[scope.index]?.loading}
  62. v-model={scope.row.status}
  63. active-value={1}
  64. inactive-value={0}
  65. active-text="已开启"
  66. inactive-text="已关闭"
  67. inline-prompt
  68. onChange={() => onChange(scope as any)}
  69. />
  70. )
  71. },
  72. {
  73. label: "创建时间",
  74. width: 180,
  75. prop: "createTime",
  76. formatter: ({ createTime }) =>
  77. dayjs(createTime).format("YYYY-MM-DD HH:mm:ss")
  78. },
  79. {
  80. label: "操作",
  81. fixed: "right",
  82. width: 180,
  83. slot: "operation"
  84. }
  85. ];
  86. function onChange({ row, index }) {
  87. ElMessageBox.confirm(
  88. `确认要<strong>${
  89. row.status === 0 ? "停用" : "启用"
  90. }</strong><strong style='color:var(--el-color-primary)'>${
  91. row.username
  92. }</strong>用户吗?`,
  93. "系统提示",
  94. {
  95. confirmButtonText: "确定",
  96. cancelButtonText: "取消",
  97. type: "warning",
  98. dangerouslyUseHTMLString: true,
  99. draggable: true
  100. }
  101. )
  102. .then(() => {
  103. switchLoadMap.value[index] = Object.assign(
  104. {},
  105. switchLoadMap.value[index],
  106. {
  107. loading: true
  108. }
  109. );
  110. setTimeout(() => {
  111. switchLoadMap.value[index] = Object.assign(
  112. {},
  113. switchLoadMap.value[index],
  114. {
  115. loading: false
  116. }
  117. );
  118. message("已成功修改用户状态", "success");
  119. }, 300);
  120. })
  121. .catch(() => {
  122. row.status === 0 ? (row.status = 1) : (row.status = 0);
  123. });
  124. }
  125. return {
  126. columns
  127. };
  128. }