FileReviewAddDrawer.vue 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  1. <template>
  2. <el-drawer v-model="showDrawer" :size="650" :before-close="handleDrawerClose">
  3. <template #title>
  4. <h3>创建新的文件评审任务</h3>
  5. </template>
  6. <div class="drawer-content">
  7. <el-select v-model="fileReviewForm.branch" placeholder="请选择需要评审的分支" @change="changeBranch">
  8. <el-option v-for="item in branchOptions" :key="item" :value="item" :label="item"/>
  9. </el-select>
  10. <div>选择需要评审的文件</div>
  11. <el-tree :load="loadNode" :props="fileListProps" lazy show-checkbox ref="fileTree" node-key="path"></el-tree>
  12. <el-select v-model="fileReviewForm.reviewerList" multiple placeholder="请选择评审人,可以通过手机号邀请">
  13. <el-option v-for="item in reviewerOption" :key="item.id" :label="item.label" :value="item.value"/>
  14. </el-select>
  15. <el-popover width="230" trigger="click">
  16. <div class="popoverContent">
  17. <el-input v-model="phoneNumber" placeholder="请输入手机号码"></el-input>
  18. <el-button icon="el-icon-search" circle size="mini" @click="inviteUser"></el-button>
  19. </div>
  20. <template #reference><el-button type="primary" style="margin-left: 20px">邀请用户</el-button></template>
  21. </el-popover>
  22. <el-input v-model="fileReviewForm.title" placeholder="请输入标题" minlength="1" maxlength="20" show-word-limit></el-input>
  23. <el-button @click="createFileReview" type="success" style="display:block">创建</el-button>
  24. </div>
  25. </el-drawer>
  26. </template>
  27. <script>
  28. import { CodeReviewAPI } from '../api';
  29. export default {
  30. name: 'FileReviewAddDrawer',
  31. data() {
  32. return {
  33. showDrawer: false,
  34. fileReviewForm: {
  35. projectId: -1,
  36. creatorId: -1,
  37. reviewerList: [],
  38. fileList: [],
  39. branch: '',
  40. title: '',
  41. },
  42. phoneNumber: '',
  43. branchOptions: [],
  44. fileListProps: {
  45. label: 'name',
  46. children: 'children',
  47. isLeaf: 'leaf',
  48. },
  49. fileList: [{
  50. label: 'file1',
  51. path: '',
  52. }],
  53. reviewerOption: [{
  54. label: '',
  55. value: -1,
  56. }],
  57. nodeTreeConfig: {
  58. nodeLevel0: {},
  59. resolveLevel0: {},
  60. },
  61. };
  62. },
  63. computed: {
  64. currentProjectInfo() {
  65. return this.$store.getters.currentProjectInfo;
  66. },
  67. currentUser() {
  68. return this.$store.state.user;
  69. },
  70. projectMemberList() {
  71. return this.$store.getters.userOptions;
  72. },
  73. },
  74. methods: {
  75. show() {
  76. this.showDrawer = true;
  77. },
  78. async changeBranch() {
  79. this.fileList = await CodeReviewAPI.getRepositoryTree(this.fileReviewForm.projectId, this.fileReviewForm.branch);
  80. this.nodeTreeConfig.nodeLevel0.childNodes = [];
  81. this.loadNode(this.nodeTreeConfig.nodeLevel0, this.nodeTreeConfig.resolveLevel0);
  82. },
  83. async loadNode(node, resolve) {
  84. if (node.level === 0) {
  85. this.nodeTreeConfig.nodeLevel0 = node;
  86. this.nodeTreeConfig.resolveLevel0 = resolve;
  87. return resolve(this.fileList);
  88. }
  89. if (node.level > 0) {
  90. const subTree = await CodeReviewAPI.getSubTree(this.fileReviewForm.projectId, this.fileReviewForm.branch, node.data.path);
  91. return resolve(subTree);
  92. }
  93. return resolve([]);
  94. },
  95. createFileReview() {
  96. this.fileReviewForm.fileList = this.$refs.fileTree.getCheckedKeys();
  97. console.log(this.fileReviewForm);
  98. CodeReviewAPI.createFileReview(this.fileReviewForm).then(
  99. (res) => {
  100. this.showDrawer = false;
  101. this.handleDrawerClose(
  102. () => {
  103. console.log('finishAdd');
  104. },
  105. );
  106. },
  107. );
  108. },
  109. async inviteUser() {
  110. const user = await CodeReviewAPI.inviteUser(this.phoneNumber);
  111. if (user !== undefined) {
  112. this.reviewerOption.push({
  113. label: user.username,
  114. value: user.id,
  115. });
  116. this.fileReviewForm.reviewerList.push(user.id);
  117. }
  118. this.phoneNumber = '';
  119. },
  120. handleDrawerClose(done) {
  121. this.fileReviewForm.reviewerList = [];
  122. this.fileReviewForm.fileList = [];
  123. this.title = '';
  124. this.branch = 'master';
  125. done();
  126. },
  127. },
  128. async mounted() {
  129. this.fileReviewForm.projectId = this.currentProjectInfo.id;
  130. this.fileReviewForm.creatorId = this.currentUser.id;
  131. this.reviewerOption = this.projectMemberList;
  132. const branches = await CodeReviewAPI.getProjectBranches(this.currentProjectInfo.id);
  133. Object.keys(branches).forEach(
  134. (key) => {
  135. this.branchOptions.push(branches[key].name);
  136. },
  137. );
  138. [this.fileReviewForm.branch] = this.branchOptions;
  139. this.fileList = await CodeReviewAPI.getRepositoryTree(this.fileReviewForm.projectId, this.fileReviewForm.branch);
  140. },
  141. };
  142. </script>
  143. <style lang="scss" scoped>
  144. .drawer-content {
  145. width: 100%;
  146. padding: 10px;
  147. > * {
  148. margin-top: 10px;
  149. }
  150. }
  151. .el-tree {
  152. border-style: solid;
  153. border-width: 1px;
  154. border-color: gainsboro;
  155. border-radius: 5px;
  156. }
  157. .el-select {
  158. width: 60%;
  159. }
  160. .popoverContent {
  161. > * {
  162. display: inline-block;
  163. }
  164. }
  165. ::v-deep {
  166. .el-tree {
  167. .el-tree-node__content {
  168. height: 35px;
  169. }
  170. }
  171. }
  172. </style>