GeneralTable.vue 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. <template>
  2. <div class="table-prefix">
  3. <div class="right">
  4. <ElButton class="prefix-right-button" size="small" type="text" @click="clearFilter">清除过滤器</ElButton>
  5. <ElButton class="prefix-right-button" v-if="showAdd" size="small" type="primary" @click="add">新建</ElButton>
  6. </div>
  7. </div>
  8. <ElTable
  9. ref="tableRef"
  10. :data="data"
  11. v-loading="loading"
  12. @row-click="rowClick"
  13. >
  14. <ElTableColumn
  15. prop="id"
  16. label="ID"
  17. align="center"
  18. width="80"
  19. ></ElTableColumn>
  20. <ElTableColumn
  21. label="优先级"
  22. align="center"
  23. width="80"
  24. :filters="[{ text: '紧急', value: '紧急' }, { text: '一般', value: '一般' }, { text: '宽松', value: '宽松' }]"
  25. :filter-method="(value, row) => {
  26. return row.priority === value;
  27. }"
  28. filter-placement="bottom-end"
  29. >
  30. <template #default="scope">
  31. <PriorityTag :priority="scope.row.priority" />
  32. </template>
  33. </ElTableColumn>
  34. <ElTableColumn
  35. prop="title"
  36. label="名称"
  37. align="center"
  38. width="180"
  39. ></ElTableColumn>
  40. <ElTableColumn
  41. prop="processorName"
  42. label="负责人"
  43. align="center"
  44. width="120"
  45. :filters="[{ text: '我', value: me }]"
  46. :filter-method="(value, row) => {
  47. return row.processorName === value;
  48. }"
  49. ></ElTableColumn>
  50. <ElTableColumn
  51. prop="timeToTake"
  52. label="预期耗时"
  53. align="center"
  54. width="100"
  55. ></ElTableColumn>
  56. <ElTableColumn
  57. label="开始时间"
  58. :formatter="(row) => formatter(row.startTime)"
  59. align="center"
  60. ></ElTableColumn>
  61. <ElTableColumn
  62. label="结束时间"
  63. :formatter="(row) => formatter(row.endTime)"
  64. align="center"
  65. ></ElTableColumn>
  66. <ElTableColumn
  67. prop="state"
  68. label="状态"
  69. align="center"
  70. width="120"
  71. :filters="[{ text: '已创建', value: '已创建' }, { text: '进行中', value: '进行中' }, { text: '已完成', value: '已完成' }]"
  72. :filter-method="(value, row) => {
  73. return row.state === value;
  74. }"
  75. >
  76. <template #default="scope">
  77. <StateTag :state="scope.row.state" />
  78. </template>
  79. </ElTableColumn>
  80. </ElTable>
  81. </template>
  82. <script lang="ts">
  83. import { defineComponent, PropType, ref } from 'vue';
  84. import { useStore } from '@/store';
  85. import StateTag from '@/components/StateTag.vue';
  86. import PriorityTag from '@/components/PriorityTag.vue';
  87. import { ElTable } from 'element-plus';
  88. import { formatter } from '@/utils/time';
  89. interface Record {
  90. commits: Array<CommitRecord>;
  91. description: string;
  92. endTime: string;
  93. id: number;
  94. priority: RecordPriority;
  95. processorId: number;
  96. processorName: string;
  97. startTime: string;
  98. state: RecordState;
  99. timeToTake: 0;
  100. title: string;
  101. }
  102. export default defineComponent({
  103. name: 'GeneralTable',
  104. components: { StateTag, PriorityTag },
  105. props: {
  106. data: Array as PropType<Record[]>,
  107. showAdd: {
  108. type: Boolean,
  109. default: false,
  110. },
  111. loading: {
  112. type: Boolean,
  113. default: false,
  114. },
  115. },
  116. emits: ['row-click', 'add'],
  117. setup(props, { emit }) {
  118. const store = useStore();
  119. const rowClick = (...args: any[]) => {
  120. emit('row-click', ...args);
  121. };
  122. const tableRef = ref<typeof ElTable|null>(null);
  123. const clearFilter = () => {
  124. console.log(tableRef);
  125. tableRef.value!.clearFilter();
  126. };
  127. const add = () => {
  128. emit('add');
  129. };
  130. return {
  131. me: store.state.user.username,
  132. rowClick,
  133. tableRef,
  134. clearFilter,
  135. add,
  136. formatter,
  137. };
  138. },
  139. });
  140. </script>
  141. <style lang="scss" scoped>
  142. .table-prefix {
  143. width: 90%;
  144. margin: 0 auto;
  145. & .right {
  146. float: right;
  147. & .prefix-right-button {
  148. margin-left: 20px;
  149. }
  150. }
  151. }
  152. </style>