gitLog.vue 5.03 KB
<template>
  <div class="gitlog">
    <div class="branch">
      <a-select
        :defaultValue="currentBranch"
        style="width: 120px"
        @change="handleChange"
      >
        <a-select-option
          v-for="(item, index) in branchs"
          :key="index + 'branch'"
          :value="item.name"
        >
          {{ item.name }}
        </a-select-option>
      </a-select>
      <span class="current">当前分支:{{ currentBranch }}</span>
    </div>
    <a-list item-layout="horizontal" :data-source="data">
      <a-list-item slot="renderItem" slot-scope="item">
        <a-list-item-meta :description="item.message">
          <span slot="title"
            >{{ item.title }}---{{ item.created_at | dateTime }} by author:
            {{ item.author }}
            <span class="author">{{ item.author_name }}</span></span
          >
          <a-avatar
            slot="avatar"
            src="https://zos.alipayobjects.com/rmsportal/ODTLcjxAfvqbxHnVXCYX.png"
          />
        </a-list-item-meta>
      </a-list-item>
    </a-list>
    <a-back-top />
  </div>
</template>

<script>
import moment from "moment";
export default {
  name: "gitlog",
  props: {},
  data() {
    return {
      data: [
        {
          id: "98285ed4f3df5ef58a01607651f61592248dd101",
          short_id: "98285ed4",
          title: "add:主题色加深色值调整",
          created_at: "2022-02-10T14:00:54.000+08:00",
          parent_ids: ["37efaa1ece09035aafd490a8e4d94931b23fedd2"],
          message: "add:主题色加深色值调整\n",
          author_name: "luyt",
          author_email: "q9OUYzI2",
          authored_date: "2022-02-10T14:00:54.000+08:00",
          committer_name: "luyt",
          committer_email: "q9OUYzI2",
          committed_date: "2022-02-10T14:00:54.000+08:00",
        },
      ],
      branchs: [
        // {
        //   name: "SCRM-V1.0.2",
        //   commit: {
        //     id: "266eb49b58dbc3dfdf12e52395fb5de9edcbf47a",
        //     short_id: "266eb49b",
        //     title: "1.3.7",
        //     created_at: "2022-01-17T14:26:31.000+08:00",
        //     parent_ids: ["aa7f2e56c33073428325efb7deff5f25e1da9c80"],
        //     message: "1.3.7\n",
        //     author_name: "limin",
        //     author_email: "17653212@qq.com",
        //     authored_date: "2022-01-17T14:26:31.000+08:00",
        //     committer_name: "limin",
        //     committer_email: "17653212@qq.com",
        //     committed_date: "2022-01-17T14:26:31.000+08:00",
        //   },
        //   merged: true,
        //   protected: false,
        //   developers_can_push: false,
        //   developers_can_merge: false,
        // },
        // {
        //   name: "dev",
        //   commit: {
        //     id: "d51cb098bf2eae3295c336c9cf8000776e8e2a3a",
        //     short_id: "d51cb098",
        //     title: "add:修改table左对齐,金额右对齐",
        //     created_at: "2022-02-16T15:39:30.000+08:00",
        //     parent_ids: ["a423fa7e0afb347a2854ac03069dd19167d3acbb"],
        //     message: "add:修改table左对齐,金额右对齐\n",
        //     author_name: "luyt",
        //     author_email: "q9OUYzI2",
        //     authored_date: "2022-02-16T15:39:30.000+08:00",
        //     committer_name: "luyt",
        //     committer_email: "q9OUYzI2",
        //     committed_date: "2022-02-16T15:39:30.000+08:00",
        //   },
        //   merged: false,
        //   protected: false,
        //   developers_can_push: false,
        //   developers_can_merge: false,
        // },
      ],
      currentBranch: "master",
      projectId: 173,
    };
  },
  filters: {
    dateTime(value) {
      if (!value) return;
      return moment(value).format("YYYY-MM-DD HH:MM:ss");
    },
  },
  created() {
    this.getProjectId();
  },
  mounted() {},
  methods: {
    //获取项目id
    getProjectId() {
      // console.log('this.$route.query.projectId',this.$route.query.projectId)
      if (this.$route.query.projectId) {
        this.projectId = this.$route.query.projectId;
        this.getBranches();
        this.getCommitList();
      }
    },
    handleChange(value) {
      // console.log('value: ', value);
      this.currentBranch = value;
      this.getCommitList();
    },
    //获取所有分支
    async getBranches() {
      const res = await this.api.gitLog.getBranches(this.projectId);
      if (res.length > 0) {
        this.branchs = res;
      }
    },
    //获取某个分支下的所有commit
    async getCommitList() {
      const res = await this.api.gitLog.getCommitList(
        this.projectId,
        this.currentBranch
      );
      if (res.length > 0) {
        this.data = res;
      }
    },
  },
  components: {},
  computed: {},
};
</script>
<style lang='scss'>
.gitlog {
  .branch {
    margin-bottom: 30px;
    .current {
      margin-left: 20px;
    }
  }
  .author {
    color: #008dff;
  }
  .ant-list-split .ant-list-item {
    transition: all 0.3s;
  }
  .ant-list-split .ant-list-item:hover {
    border-color: rgba(0, 0, 0, 0.09);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.09);
  }
}
</style>