插槽

  1. <template #status="{ text: status }">
  2. <span>
  3. <a-tag :color="status == '0' ? 'blue' : 'red'">{{ status == '0' ? '启用' : '停用' }}</a-tag>
  4. </span>
  5. </template>

table 组件使用

  1. <template>
  2. <a-table :data-source="userInfoData" :pagination="false" :columns="columns">
  3. <template #status="{ text: status }">
  4. <span>
  5. <a-tag :color="status == '0' ? 'blue' : 'red'">{{ status == '0' ? '启用' : '停用' }}</a-tag>
  6. </span>
  7. </template>
  8. <template #action="{ record }">
  9. <span>
  10. <a-button type="primary" danger>删除</a-button>
  11. <a-button type="primary" @click="onEdit">编辑</a-button>
  12. <a-button type="primary" danger>密码重置</a-button>
  13. <a-button :type="record.status == '0' ? 'success' : 'danger'">{{
  14. record.status == '0' ? '启用' : '停用'
  15. }}</a-button>
  16. </span>
  17. </template>
  18. </a-table>
  19. </template>
  20. <script lang="ts" setup>
  21. import { storeToRefs } from 'pinia';
  22. import { onBeforeMount } from 'vue';
  23. import usePermissionManagementStore from '/@/store/modules/management';
  24. const managementStore = usePermissionManagementStore();
  25. const { userInfoData } = storeToRefs(managementStore);
  26. const { onEdit, getUserInfoData } = managementStore;
  27. /**
  28. *table 属性类型定义
  29. */
  30. type ColumnType = {
  31. title: string;
  32. dataIndex: string;
  33. key: string;
  34. class?: string;
  35. slots?: Object;
  36. width?: number;
  37. align?: 'center' | 'left' | 'right';
  38. fixed?: 'left' | 'right';
  39. slots?: Object;
  40. filters?: {
  41. text: string;
  42. value: string;
  43. children?: {
  44. text: string;
  45. value: string;
  46. }[];
  47. }[];
  48. onFilter?: (value: string, record: ConceptData) => boolean;
  49. sortDirections?: string[];
  50. defaultSortOrder?: string;
  51. filterMultiple?: string[] | boolean;
  52. filterDropdownVisible?: boolean;
  53. };
  54. const columns: ColumnType[] = [
  55. {
  56. key: 'userid',
  57. title: '序号',
  58. dataIndex: 'userid',
  59. width: 60,
  60. fixed: 'right',
  61. },
  62. {
  63. key: 'username',
  64. title: '用户名',
  65. dataIndex: 'username',
  66. width: 60,
  67. },
  68. {
  69. key: 'realname',
  70. title: '真实姓名',
  71. dataIndex: 'realname',
  72. width: 60,
  73. },
  74. {
  75. key: 'telephone',
  76. title: '电话',
  77. dataIndex: 'telephone',
  78. width: 60,
  79. },
  80. {
  81. key: 'status',
  82. title: '状态',
  83. dataIndex: 'status',
  84. width: 60,
  85. slots: { customRender: 'status' },
  86. },
  87. {
  88. key: 'last_ip',
  89. title: '最后登录IP',
  90. dataIndex: 'last_ip',
  91. width: 60,
  92. },
  93. {
  94. key: 'last_login_time',
  95. title: '最后登陆时间',
  96. dataIndex: 'last_login_time',
  97. width: 60,
  98. },
  99. {
  100. key: 'action',
  101. title: '操作',
  102. dataIndex: 'action',
  103. align: 'center',
  104. width: 100,
  105. slots: { customRender: 'action' },
  106. },
  107. ];
  108. onBeforeMount(async () => {
  109. await getUserInfoData();
  110. });
  111. </script>

参考

【1】https://2x.antdv.com/docs/vue/introduce-cn