GeneralTable.vue 3.9 KB

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