Commit.vue 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212
  1. <template>
  2. <div class="container">
  3. <el-row class="row-item title">
  4. <h2>commit记录</h2>
  5. </el-row>
  6. <!-- {{currentBranch}}-->
  7. <!-- {{currentAuthors}}-->
  8. <!-- {{displayCommits}}-->
  9. <div>
  10. <div v-if="originCommits.length === 0">
  11. <el-empty description="暂无commit记录!"></el-empty>
  12. </div>
  13. <div v-else>
  14. <el-row :gutter="20">
  15. <el-col :span="6">
  16. <el-select v-model="currentBranch" class="m-2" placeholder="Select" size="large">
  17. <el-option
  18. v-for="(branch, index) in branches"
  19. :key="index"
  20. :label="branch.name"
  21. :value="branch.name"
  22. @change="onSearch"
  23. />
  24. </el-select>
  25. </el-col>
  26. <el-col :span="6">
  27. <el-select
  28. v-model="currentAuthors"
  29. multiple
  30. collapse-tags
  31. placeholder="选择处理人"
  32. >
  33. <el-option
  34. v-for="(author, index) in authors"
  35. :key="index"
  36. :label="author"
  37. :value="author"
  38. />
  39. </el-select>
  40. </el-col>
  41. <el-col :span="10">
  42. <!-- <el-date-picker-->
  43. <!-- v-model="value1"-->
  44. <!-- type="daterange"-->
  45. <!-- range-separator="To"-->
  46. <!-- start-placeholder="Start date"-->
  47. <!-- end-placeholder="End date"-->
  48. <!-- />-->
  49. <!-- <el-date-picker v-model="value1" type="date" placeholder="Pick a day" />-->
  50. <el-input v-model="keyword" placeholder="输入检索message内容或Hash" clearable />
  51. </el-col>
  52. <el-col :span="2">
  53. <el-button type="primary" @click="onSearch">过滤</el-button>
  54. </el-col>
  55. </el-row>
  56. <ElTimeline>
  57. <ElTimelineItem
  58. v-for="(git, index) in displayCommits"
  59. :key="index"
  60. :timestamp="git.timestamp"
  61. placement="top"
  62. :color="git.relatedType === 'bug_id' ? 'chocolate' : (git.relatedType === 'none' ? '#ccc': '#42b983')"
  63. size="large">
  64. <ElCard shadow="hover"
  65. @click="clickCommitCard(git.id)">
  66. <h3 class="view-text">{{git.title}}</h3>
  67. <!-- <h3 class="id">{{git.id}}</h3>-->
  68. <!-- <div class="view-text" style="margin-top: 10px; font-size: 16px; color: #444">{{git.message}}</div>-->
  69. <div style="margin-top: 10px">
  70. <el-row>
  71. <el-col :span="6">
  72. <el-link
  73. target="_blank"
  74. type="info"
  75. @click.stop.prevent="copy(git.id)"
  76. >
  77. <span style="color: #888">{{git.id.substring(0, 8)}}</span>
  78. <i class="el-icon-document-copy"></i>
  79. </el-link>
  80. </el-col>
  81. <el-col :span="12">
  82. 处理人:<span style="font-weight: bold">{{git.gitlabUsername}}</span>
  83. </el-col>
  84. <el-col :span="6">
  85. 类型:
  86. <span v-if="git.relatedType === 'bug_id'" class="node bug">缺陷</span>
  87. <span v-else-if="git.relatedType === 'none'" class="node none">无类型</span>
  88. <span v-else class="node requirement">需求</span></el-col>
  89. </el-row>
  90. </div>
  91. </ElCard>
  92. </ElTimelineItem>
  93. </ElTimeline>
  94. </div>
  95. </div>
  96. </div>
  97. </template>
  98. <script>
  99. import { ProjectAPI } from '@/api';
  100. import { useRouter } from 'vue-router';
  101. import { copy } from '@/utils/clipboard';
  102. import { formatter } from '../../utils/time';
  103. export default {
  104. name: 'Commit.vue',
  105. data() {
  106. return {
  107. branches: [],
  108. originCommits: [],
  109. displayCommits: [],
  110. authors: [],
  111. lastBranch: '',
  112. currentBranch: '',
  113. currentAuthors: [],
  114. keyword: '',
  115. };
  116. },
  117. async mounted() {
  118. this.branches = await ProjectAPI.getAllBranches(this.$store.state.workspace.currentProjectId);
  119. if (this.branches.length !== 0) {
  120. this.currentBranch = this.branches[0].name;
  121. this.lastBranch = this.currentBranch;
  122. await this.loadBranch();
  123. }
  124. },
  125. methods: {
  126. copy,
  127. async loadBranch() {
  128. this.originCommits = await ProjectAPI.getCommitsByBranch(this.$store.state.workspace.currentProjectId, this.currentBranch);
  129. this.authors = [];
  130. for (let i = 0; i < this.originCommits.length; i += 1) {
  131. this.originCommits[i].timestamp = formatter(this.originCommits[i].timestamp);
  132. const author = this.originCommits[i].gitlabUsername;
  133. if (this.authors.indexOf(author) === -1) {
  134. this.authors.push(author);
  135. }
  136. }
  137. this.displayCommits = this.originCommits;
  138. },
  139. clickCommitCard(id) {
  140. console.log(id);
  141. this.$router.push({
  142. path: `/project/${this.$store.state.workspace.currentProjectId}/commit-detail`,
  143. query: {
  144. id,
  145. },
  146. });
  147. },
  148. async onSearch() {
  149. if (this.currentBranch !== this.lastBranch) {
  150. await this.loadBranch();
  151. }
  152. this.displayCommits = this.originCommits
  153. .filter((commit) => (this.currentAuthors.length === 0 || this.currentAuthors.indexOf(commit.gitlabUsername) >= 0)
  154. && (commit.id.startsWith(this.keyword) || commit.title.indexOf(this.keyword) >= 0));
  155. console.log('search');
  156. },
  157. },
  158. };
  159. </script>
  160. <style scoped>
  161. .container {
  162. margin: 50px 100px;
  163. width: 50%;
  164. }
  165. .row-item {
  166. display: flex;
  167. flex-direction: row;
  168. align-items: center;
  169. margin-bottom: 10px;
  170. }
  171. .id {
  172. width: fit-content;
  173. height: 20px;
  174. background-color: #2185d0;
  175. color: #fff;
  176. border: 0 solid transparent;
  177. border-radius: .28571429rem;
  178. }
  179. .node {
  180. width: 15px;
  181. color: #FFFFFF;
  182. border-radius: 3px;
  183. font-size: 14px;
  184. text-align: center;
  185. }
  186. .bug {
  187. background-color: chocolate;
  188. }
  189. .none{
  190. background-color: #ccc;
  191. }
  192. .requirement {
  193. background-color: #42b983;
  194. }
  195. .view-text{
  196. display: inline-block;
  197. white-space: nowrap;
  198. width: 100%;
  199. overflow: hidden;
  200. text-overflow:ellipsis;
  201. }
  202. .el-row{
  203. margin-bottom: 20px;
  204. }
  205. </style>