GeneralTable.vue 3.9 KB

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