ソースを参照

fix: 添加commit接口

zhaoxingrui 5 年 前
コミット
f45ad8ede3
2 ファイル変更26 行追加37 行削除
  1. 5 1
      src/api/devcloud/project.ts
  2. 21 36
      src/views/Project/Commit.vue

+ 5 - 1
src/api/devcloud/project.ts

@@ -1,6 +1,6 @@
 import axios from '@/utils/axios';
 
-import { PROJECT_PREFIX } from './prefix';
+import { PROJECT_PREFIX, COMMIT_PREFIX } from './prefix';
 
 interface AddProjectMemberPayload {
   phone: string;
@@ -31,3 +31,7 @@ export const generateRelateCode = (projectId: number) => axios.post(`${PROJECT_P
 export const relateProject = (projectId: number, code: string) => axios.post(
   `${PROJECT_PREFIX}/relate?projectId=${projectId}&relateCode=${code}`,
 );
+
+export const getCommits = (projectId: number) => axios.get(
+  `${COMMIT_PREFIX}/list?projectId=${projectId}`,
+);

+ 21 - 36
src/views/Project/Commit.vue

@@ -9,7 +9,9 @@
           v-for="(git, index) in gits"
           :key="index"
           :timestamp="git.timestamp"
-          placement="top">
+          placement="top"
+          :color="git.relatedType === 'bug_id' ? 'chocolate' : '#42b983'"
+          size="large">
           <ElCard>
             <h3 class="id">#{{git.id}}</h3>
             <div style="margin-top: 10px; font-size: 16px">{{git.message}}</div>
@@ -20,7 +22,7 @@
                 </el-col>
                 <el-col :span="12">
                   类型:
-                  <span v-if="git.relatedType === 'BUG_ID'" class="node bug">缺陷</span>
+                  <span v-if="git.relatedType === 'bug_id'" class="node bug">缺陷</span>
                   <span v-else class="node requirement">需求</span></el-col>
               </el-row>
             </div>
@@ -32,46 +34,29 @@
 </template>
 
 <script>
+import { ProjectAPI } from '@/api';
+import { formatter } from '../../utils/time';
+
 export default {
   name: 'Commit.vue',
   data() {
     return {
-      gits: [
-        {
-          id: '010f2a0ccf522fe6c1408bffdd494782880c1ec9',
-          message: 'fix: working on #942#, 处理bug942',
-          timestamp: '2021-07-10 15:09:36',
-          gitlabUsername: 'xiaofei',
-          relatedType: 'BUG_ID',
-          relatedId: 942,
-        },
-        {
-          id: '030a88a98695d83bdd91937783c08323451d5046',
-          message: 'feat: complete #878# ',
-          timestamp: '2021-07-09 23:18:20',
-          gitlabUsername: '17313',
-          relatedType: 'TREE_ID',
-          relatedId: 878,
-        },
-        {
-          id: '07f536fc5d660d8085d360961ab4fd337df9b8f1',
-          message: 'fix: fixing on #17#',
-          timestamp: '2021-07-08 13:45:22',
-          gitlabUsername: 'suyiiis',
-          relatedType: 'BUG_ID',
-          relatedId: 17,
-        },
-        {
-          id: '0c75b8b675291c1f90a56e912befc38341ec3171',
-          message: 'feat: complete #273#',
-          timestamp: '2021-07-08 10:11:23',
-          gitlabUsername: 'YGcatwhite',
-          relatedType: 'TREE_ID',
-          relatedId: 273,
-        },
-      ],
+      gits: [],
     };
   },
+  async mounted() {
+    this.gits = await ProjectAPI.getCommits(this.$store.state.workspace.currentProjectId);
+    for (let i = 0; i < this.gits.length; i += 1) {
+      this.gits[i].timestamp = formatter(this.gits[i].timestamp);
+    }
+    this.gits.sort((a, b) => {
+      const aTimeString = a.timestamp;
+      const bTimeString = b.timestamp;
+      const aTime = new Date(aTimeString).getTime();
+      const bTime = new Date(bTimeString).getTime();
+      return bTime - aTime;
+    });
+  },
 };
 </script>