|
|
@@ -0,0 +1,261 @@
|
|
|
+<template>
|
|
|
+ <el-drawer v-model="showDrawer" :size="650" :before-close="handleDrawerClose">
|
|
|
+ <template #title>
|
|
|
+ <h3 v-if="showSelectBranch">选择分支</h3>
|
|
|
+ <h3 v-if="showCreateCodeReview">创建代码评审任务</h3>
|
|
|
+ </template>
|
|
|
+ <div class="drawer-content" v-if="showSelectBranch">
|
|
|
+ <div class="branch-table">
|
|
|
+ <div class="branch-row" style="background-color: #F5F5F5;">Source Branch</div>
|
|
|
+ <div class="branch-row" >
|
|
|
+ <el-select v-model="sourceProject" placeholder="请选择源项目" class="inline-selector left" style="margin-right:1%">
|
|
|
+ <el-option v-for="item in projectOptions" :key="item" :value="item" :label="item"/>
|
|
|
+ </el-select>
|
|
|
+ <el-select v-model="sourceBranch" placeholder="请选择源分支" class="inline-selector right" style="margin-left:1%">
|
|
|
+ <el-option v-for="item in branchOptions" :key="item" :value="item" :label="item"/>
|
|
|
+ </el-select>
|
|
|
+ </div>
|
|
|
+ <div class="branch-row" style="background-color: #F5F5F5; border-bottom-width: 0px" v-if="sourceBranch !== ''">
|
|
|
+ <div style="display: inline-block">
|
|
|
+ <div>{{branches[branchOptions.indexOf(sourceBranch)].commit.title}}</div>
|
|
|
+ <div style="font-weight:200; font-size: 0.875em; color: #585858">
|
|
|
+ {{getAuthorName(sourceBranch)}} commited at {{getCreateTime(sourceBranch)}}
|
|
|
+ </div>
|
|
|
+ </div>
|
|
|
+ <div class="short-id-block">
|
|
|
+ <div class="short-id-line">{{branches[branchOptions.indexOf(sourceBranch)].commit.short_id}}</div>
|
|
|
+ <div class="copy-button"><i class="el-icon-document-copy"/></div>
|
|
|
+ </div>
|
|
|
+ </div>
|
|
|
+ </div>
|
|
|
+ <div class="branch-table" style="margin-top: 15px">
|
|
|
+ <div class="branch-row" style="background-color: #F5F5F5;">Target Branch</div>
|
|
|
+ <div class="branch-row" >
|
|
|
+ <el-select v-model="targetProject" placeholder="请选择目标项目" class="inline-selector left" style="margin-right:1%">
|
|
|
+ <el-option v-for="item in projectOptions" :key="item" :value="item" :label="item"/>
|
|
|
+ </el-select>
|
|
|
+ <el-select v-model="targetBranch" placeholder="请选择目标分支" class="inline-selector right" style="margin-left:1%">
|
|
|
+ <el-option v-for="item in branchOptions" :key="item" :value="item" :label="item"/>
|
|
|
+ </el-select>
|
|
|
+ </div>
|
|
|
+ <div class="branch-row" style="background-color: #F5F5F5; border-bottom-width: 0px" v-if="targetBranch !== ''">
|
|
|
+ <div style="display: inline-block">
|
|
|
+ <div>{{branches[branchOptions.indexOf(targetBranch)].commit.title}}</div>
|
|
|
+ <div style="font-weight:200; font-size: 0.875em; color: #585858">
|
|
|
+ {{getAuthorName(targetBranch)}} commited at {{getCreateTime(targetBranch)}}
|
|
|
+ </div>
|
|
|
+ </div>
|
|
|
+ <div class="short-id-block">
|
|
|
+ <div class="short-id-line">{{branches[branchOptions.indexOf(targetBranch)].commit.short_id}}</div>
|
|
|
+ <div class="copy-button"><i class="el-icon-document-copy"/></div>
|
|
|
+ </div>
|
|
|
+ </div>
|
|
|
+ </div>
|
|
|
+ <el-button type="success" style="margin-top: 7px" @click="compareBranch()" size="medium">继续</el-button>
|
|
|
+ </div>
|
|
|
+ <div class="drawer-content" v-if="showCreateCodeReview">
|
|
|
+ <el-form ref="createForm" label-position="right" label-width="80px" :model="codeReviewCreateForm" :rules="formRules">
|
|
|
+ <el-form-item label="标题" prop="title">
|
|
|
+ <el-input v-model="codeReviewCreateForm.title"/>
|
|
|
+ </el-form-item>
|
|
|
+ <el-form-item label="详细描述" prop="description">
|
|
|
+ <el-input type="textarea" v-model="codeReviewCreateForm.description"/>
|
|
|
+ </el-form-item>
|
|
|
+ <el-form-item label="评审人" prop="reviewerId">
|
|
|
+ <el-select v-model="codeReviewCreateForm.reviewerId" placeholder="请选择评审人">
|
|
|
+ <el-option v-for=" member in projectMemberList" :label="member.label" :key="member.id" :value="member.value"/>
|
|
|
+ </el-select>
|
|
|
+ </el-form-item>
|
|
|
+ <el-form-item prop="deleteSourceBranch">
|
|
|
+ <el-switch v-model="codeReviewCreateForm.deleteSourceBranch"
|
|
|
+ active-text="合并后删除源分支"
|
|
|
+ active-color="#13ce66"/>
|
|
|
+ </el-form-item>
|
|
|
+ <el-form-item>
|
|
|
+ <el-button type="success" v-loading="submitLoading" size="medium" @click="submitForm">立即创建</el-button>
|
|
|
+ <el-button type="text" size="medium" @click="backToSelectBranch">重新选择分支</el-button>
|
|
|
+ </el-form-item>
|
|
|
+ </el-form>
|
|
|
+ <CodeDifferencePlate :data="diffMsg.res"/>
|
|
|
+ </div>
|
|
|
+ </el-drawer>
|
|
|
+</template>
|
|
|
+<script>
|
|
|
+import CodeDifferencePlate from './CodeDifferencePlate.vue';
|
|
|
+import { CodeReviewAPI } from '../api';
|
|
|
+
|
|
|
+export default {
|
|
|
+ name: 'CodeReviewAddDrawer',
|
|
|
+ components: { CodeDifferencePlate },
|
|
|
+ data() {
|
|
|
+ return {
|
|
|
+ sourceProject: '',
|
|
|
+ targetProject: '',
|
|
|
+ projectOptions: [''],
|
|
|
+ sourceBranch: '',
|
|
|
+ targetBranch: 'master',
|
|
|
+ branchOptions: [],
|
|
|
+ showDrawer: false,
|
|
|
+ showSelectBranch: true,
|
|
|
+ showCreateCodeReview: false,
|
|
|
+ branches: [],
|
|
|
+ codeReviewCreateForm: {
|
|
|
+ projectId: -1,
|
|
|
+ sourceBranch: '',
|
|
|
+ targetBranch: '',
|
|
|
+ creatorId: '',
|
|
|
+ reviewerId: undefined,
|
|
|
+ title: '',
|
|
|
+ description: '',
|
|
|
+ deleteSourceBranch: false,
|
|
|
+ },
|
|
|
+ formRules: {
|
|
|
+ title: [{required: true, message: '请输入代码评审任务标题', trigger: 'blur',}],
|
|
|
+ reviewerId: [{required: true, message: '请选择一位评审人', trigger: 'blur'}],
|
|
|
+ },
|
|
|
+ submitLoading: false,
|
|
|
+ diffMsg: [],
|
|
|
+ };
|
|
|
+ },
|
|
|
+ computed: {
|
|
|
+ projectMemberList() {
|
|
|
+ return this.$store.getters.userOptions;
|
|
|
+ },
|
|
|
+ currentProjectInfo() {
|
|
|
+ return this.$store.getters.currentProjectInfo;
|
|
|
+ },
|
|
|
+ currentUser() {
|
|
|
+ return this.$store.state.user;
|
|
|
+ }
|
|
|
+ },
|
|
|
+ methods: {
|
|
|
+ show() {
|
|
|
+ this.showDrawer = true;
|
|
|
+ },
|
|
|
+ getAuthorName(branchName) {
|
|
|
+ return this.branches[this.branchOptions.indexOf(branchName)].commit.author_name;
|
|
|
+ },
|
|
|
+ getCreateTime(branchName) {
|
|
|
+ return this.branches[this.branchOptions.indexOf(branchName)].commit.created_at.split('T')[0];
|
|
|
+ },
|
|
|
+ getBranchBash(branchName) {
|
|
|
+ return this.branches[this.branchOptions.indexOf(branchName)].commit.id;
|
|
|
+ },
|
|
|
+ getProjectNameFromUrl(url) {
|
|
|
+ let addList = url.split('/');
|
|
|
+ return addList[addList.length - 2] + '/' + addList[addList.length - 1];
|
|
|
+ },
|
|
|
+ async compareBranch() {
|
|
|
+ if(this.sourceBranch === '')this.$message.error('源分支不能为空!');
|
|
|
+ else if (this.sourceBranch === this.targetBranch)this.$message.error('源分支与目标分支相同,请重新选择!')
|
|
|
+ else {
|
|
|
+ this.codeReviewCreateForm.sourceBranch = this.sourceBranch;
|
|
|
+ this.codeReviewCreateForm.targetBranch = this.targetBranch;
|
|
|
+ this.diffMsg = await CodeReviewAPI.compareBranch(this.codeReviewCreateForm.projectId, this.targetBranch, this.sourceBranch);
|
|
|
+ this.showSelectBranch = false;
|
|
|
+ this.showCreateCodeReview = true;
|
|
|
+ }
|
|
|
+ },
|
|
|
+ handleDrawerClose(done) {
|
|
|
+ this.showSelectBranch = true;
|
|
|
+ this.showCreateCodeReview = false;
|
|
|
+ this.sourceBranch = '';
|
|
|
+ this.targetBranch = 'master';
|
|
|
+ this.resetForm();
|
|
|
+ done();
|
|
|
+ },
|
|
|
+ backToSelectBranch() {
|
|
|
+ this.showSelectBranch = true;
|
|
|
+ this.showCreateCodeReview = false;
|
|
|
+ this.codeReviewCreateForm.reviewerId = undefined;
|
|
|
+ this.codeReviewCreateForm.title = '';
|
|
|
+ this.codeReviewCreateForm.description = '';
|
|
|
+ this.codeReviewCreateForm.deleteSourceBranch = false;
|
|
|
+ },
|
|
|
+ submitForm() {
|
|
|
+ this.$refs.createForm.validate((valid) => {
|
|
|
+ if(valid) {
|
|
|
+ this.submitLoading = true;
|
|
|
+ CodeReviewAPI.createCodeReview(this.codeReviewCreateForm).then(
|
|
|
+ (res) => {
|
|
|
+ this.showDrawer = false;
|
|
|
+ this.handleDrawerClose(() => {});
|
|
|
+ }
|
|
|
+ );
|
|
|
+ this.submitLoading = false;
|
|
|
+ }
|
|
|
+ });
|
|
|
+ },
|
|
|
+ resetForm() {
|
|
|
+ this.codeReviewCreateForm = {
|
|
|
+ projectId: this.currentProjectInfo.id,
|
|
|
+ sourceBranch: '',
|
|
|
+ targetBranch: '',
|
|
|
+ creatorId: this.currentUser.id,
|
|
|
+ reviewerId: undefined,
|
|
|
+ title: '',
|
|
|
+ description: '',
|
|
|
+ deleteSourceBranch: false,
|
|
|
+ };
|
|
|
+ },
|
|
|
+ },
|
|
|
+ async mounted(){
|
|
|
+ //更新项目名称,项目Id,创建者Id
|
|
|
+ this.projectOptions[0] = this.sourceProject = this.targetProject = this.getProjectNameFromUrl(this.currentProjectInfo.gitRemoteUrl);
|
|
|
+ this.codeReviewCreateForm.projectId = this.currentProjectInfo.id;
|
|
|
+ this.codeReviewCreateForm.creatorId = this.currentUser.id;
|
|
|
+ //获取项目的分支信息
|
|
|
+ this.branches = await CodeReviewAPI.getProjectBranches(this.currentProjectInfo.id);
|
|
|
+ for(let item in this.branches) {
|
|
|
+ this.branchOptions.push(this.branches[item].name);
|
|
|
+ }
|
|
|
+ },
|
|
|
+};
|
|
|
+</script>
|
|
|
+<style scoped>
|
|
|
+.drawer-content {
|
|
|
+ width: 100%;
|
|
|
+ padding: 10px;
|
|
|
+}
|
|
|
+.branch-table {
|
|
|
+ border-style: solid;
|
|
|
+ border-width: 1px;
|
|
|
+ border-color: gainsboro;
|
|
|
+}
|
|
|
+.branch-row {
|
|
|
+ padding: 10px 2%;
|
|
|
+}
|
|
|
+.inline-selector {
|
|
|
+ display: inline-block;
|
|
|
+ width: 49%;
|
|
|
+}
|
|
|
+.short-id-block {
|
|
|
+ float: right;
|
|
|
+ border: 2px solid gainsboro;
|
|
|
+ border-radius: 5px;
|
|
|
+}
|
|
|
+.short-id-line {
|
|
|
+ display: inline-block;
|
|
|
+ font-family: 'Courier New', Courier, monospace;
|
|
|
+ font-weight: 600;
|
|
|
+ padding: 7px;
|
|
|
+ border-right: 2px solid gainsboro;
|
|
|
+}
|
|
|
+.copy-button {
|
|
|
+ display: inline-block;
|
|
|
+ padding: 7px;
|
|
|
+ background-color: white;
|
|
|
+ cursor: pointer;
|
|
|
+}
|
|
|
+.copy-button:hover {
|
|
|
+ background-color: whitesmoke;
|
|
|
+}
|
|
|
+</style>
|
|
|
+<style>
|
|
|
+.el-drawer__body {
|
|
|
+ overflow: auto;
|
|
|
+}
|
|
|
+.el-drawer__container ::-webkit-scrollbar{
|
|
|
+ display: none;
|
|
|
+}
|
|
|
+</style>
|