BugEditDrawer.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312
  1. <template>
  2. <el-drawer
  3. v-model="showDrawer"
  4. :size="650"
  5. :before-close="(done) => {
  6. isEditing = false;
  7. done();
  8. }">
  9. <template #title>
  10. <el-row class="entry-row">
  11. <el-col :span="2">
  12. <div class="node-type">Bug</div>
  13. </el-col>
  14. <el-col :span="4">
  15. <template class="entry-row">
  16. <span>#{{id}}</span>
  17. </template>
  18. </el-col>
  19. <el-col :span="8">
  20. <template class="entry-row" v-if="isEditing">
  21. <el-input placeholder="请输入标题" size="mini" style="width: 200px;display: inline;" v-model="editedBugRecord.title"/>
  22. </template>
  23. <template v-else><h3>{{title}}</h3></template>
  24. </el-col>
  25. <el-col :span="6" :offset="2">
  26. <el-switch
  27. id="bugEditSwitch"
  28. v-if="activeTab ==='basic_info'"
  29. style="float: right; padding: 5px"
  30. v-model="isEditing"
  31. active-text="编辑"
  32. @change="(isEditing) => {
  33. isEditing && fillDefaultValue();
  34. }">
  35. </el-switch>
  36. </el-col>
  37. </el-row>
  38. </template>
  39. <template #default>
  40. <el-row type="flex" justify="center">
  41. <el-col :span="20">
  42. <el-tabs
  43. class="tabs"
  44. v-model="activeTab"
  45. @tab-click="(tab) => {
  46. if(tab.panename !== 'basic_info')
  47. isEditing = false;
  48. }"
  49. >
  50. <el-tab-pane label="基本信息" name="basic_info">
  51. <el-row class="entry-row" style="margin-top: 15px">
  52. <h4>缺陷描述</h4>
  53. </el-row>
  54. <el-row class="entry-row">
  55. <div v-if="isEditing">
  56. <el-input placeholder="请输入描述"
  57. type="textarea"
  58. maxlength="120"
  59. show-word-limit
  60. :rows="3" style="width: 300px;" v-model="editedBugRecord.description" />
  61. <br/>
  62. </div>
  63. <p v-else>{{description}}</p>
  64. </el-row>
  65. <!-- 状态、优先级等 -->
  66. <el-row class="entry-row" style="margin-top: 15px">
  67. <h4>详情</h4>
  68. </el-row>
  69. <el-row style="margin: 3px 20px;width: 100%">
  70. <el-col :span="12">
  71. <RowItem :label="'状态:'">
  72. <div v-if="!isEditing" class="detail-value">
  73. <StateTag :state="state"></StateTag>
  74. </div>
  75. <div v-else>
  76. <el-select style="width: 160px" size="mini" v-model="editedBugRecord.state">
  77. <el-option
  78. v-for="item in stateOptions"
  79. :key="item.value"
  80. :value="item.value"
  81. :label="item.value" />
  82. </el-select>
  83. </div>
  84. </RowItem>
  85. <RowItem :label="'优先级:'">
  86. <div class="detail-value" v-if="!isEditing">
  87. <PriorityTag :priority="priority"></PriorityTag>
  88. </div>
  89. <div v-else>
  90. <el-select style="width: 160px" size="mini" v-model="editedBugRecord.priority">
  91. <el-option
  92. v-for="item in priorityOptions"
  93. :key="item.value"
  94. :value="item.value"
  95. :label="item.label" />
  96. </el-select>
  97. </div>
  98. </RowItem>
  99. <RowItem :label="'经办人:'">
  100. <div class="detail-value" v-if="!isEditing">
  101. <el-tag>{{processorName}}</el-tag>
  102. </div>
  103. <div v-else>
  104. <el-select style="width: 160px" size="mini" v-model="editedBugRecord.processorId" >
  105. <el-option
  106. v-for="item in userOptions"
  107. :key="item.value"
  108. :value="item.value"
  109. :label="item.label" />
  110. </el-select>
  111. </div>
  112. </RowItem>
  113. </el-col>
  114. <el-col :span="12">
  115. <RowItem :label="'工作量:'">
  116. <div class="detail-value" v-if="!isEditing">
  117. <span>{{timeToTake}}人日</span>
  118. </div>
  119. <div v-else>
  120. <el-input-number size="mini" v-model="editedBugRecord.timeToTake" :min="1" :max="200">
  121. </el-input-number>
  122. </div>
  123. </RowItem>
  124. <RowItem :label="'开始时间:'"><span>{{formatter(startTime)}}</span></RowItem>
  125. <RowItem :label="'完成时间:'"><span>{{formatter(endTime)}}</span></RowItem>
  126. </el-col>
  127. </el-row>
  128. <el-row v-if="isEditing" class="entry-row" style="margin-top: 15px">
  129. <el-button @click="submitEdit" size="mini" v-loading="confirmLoading" type="primary">提交</el-button>
  130. <el-button @click="cancelEdit" size="mini">取消</el-button>
  131. </el-row>
  132. </el-tab-pane>
  133. <el-tab-pane label="历史提交" name="commit_history">
  134. <!-- 相关提交 -->
  135. <el-row class="entry-row" style="margin-top: 15px">
  136. <el-table :data="commits">
  137. <el-table-column type="expand">
  138. <template #default="scope">
  139. <RowItem :label="'ID:'" :label-span="5" :value-span="19">{{scope.row.id}}</RowItem>
  140. <RowItem :label="'信息:'" :label-span="5" :value-span="19">{{scope.row.message}}</RowItem>
  141. <RowItem :label="'时间:'" :label-span="5" :value-span="19">{{formatter(scope.row.timestamp)}}</RowItem>
  142. <RowItem :label="'操作:'" :label-span="5" :value-span="19">
  143. <el-button
  144. v-if="!deletedCommitIndex.has(scope.$index)"
  145. size="small"
  146. type="danger"
  147. @click="handleDelete(scope.$index,scope.row.id)"
  148. >删除</el-button
  149. >
  150. <el-button
  151. v-else
  152. size="small"
  153. type="info"
  154. @click="handleRestore(scope.$index, scope.row.id)"
  155. >撤销</el-button>
  156. </RowItem>
  157. </template>
  158. </el-table-column>
  159. <el-table-column
  160. label="ID"
  161. align="center"
  162. :formatter="(row)=>row.id.substr(0,7)"
  163. >
  164. </el-table-column>
  165. <el-table-column
  166. prop="gitlabUsername"
  167. label="用户"
  168. align="center"
  169. >
  170. </el-table-column>
  171. </el-table>
  172. </el-row>
  173. </el-tab-pane>
  174. </el-tabs>
  175. </el-col>
  176. </el-row>
  177. </template>
  178. </el-drawer>
  179. </template>
  180. <script>
  181. import { BugListAPI, ProjectAPI } from '@/api';
  182. import PriorityTag from '@/components/PriorityTag.vue';
  183. import StateTag from '@/components/StateTag.vue';
  184. import { priorityOptions, stateOptions } from '@/utils/constants';
  185. import { formatter } from '@/utils/time';
  186. import RowItem from './RowItem.vue';
  187. export default {
  188. name: 'BugEditDrawer',
  189. components: { RowItem, PriorityTag, StateTag },
  190. emits: ['bug-record-update'],
  191. props: {
  192. id: Number,
  193. title: String,
  194. description: String,
  195. state: String,
  196. priority: String,
  197. processorId: Number,
  198. processorName: String,
  199. timeToTake: Number,
  200. startTime: String,
  201. endTime: String,
  202. commits: Array,
  203. },
  204. data() {
  205. return {
  206. activeTab: 'basic_info',
  207. showDrawer: false,
  208. isEditing: false,
  209. editedBugRecord: {
  210. title: null,
  211. description: null,
  212. state: null,
  213. timeToTake: null,
  214. priority: null,
  215. processorId: null,
  216. processorName: null,
  217. },
  218. confirmLoading: false,
  219. stateOptions,
  220. priorityOptions,
  221. deletedCommitIndex: new Set(),
  222. };
  223. },
  224. computed: {
  225. userOptions() {
  226. return this.$store.getters.userOptions;
  227. },
  228. },
  229. methods: {
  230. formatter,
  231. show() {
  232. this.showDrawer = true;
  233. },
  234. fillDefaultValue() {
  235. this.editedBugRecord.title = this.title;
  236. this.editedBugRecord.description = this.description;
  237. this.editedBugRecord.state = this.state;
  238. this.editedBugRecord.timeToTake = this.timeToTake;
  239. this.editedBugRecord.priority = this.priority;
  240. this.editedBugRecord.processorId = this.processorId;
  241. this.editedBugRecord.processorName = this.processorName;
  242. },
  243. submitEdit() {
  244. this.confirmLoading = true;
  245. const param = { id: this.id, ...this.editedBugRecord };
  246. BugListAPI.updateBugRecord(param).then((res) => {
  247. this.isEditing = false;
  248. this.$emit('bug-record-update');
  249. this.showDrawer = false;
  250. });
  251. this.confirmLoading = false;
  252. },
  253. cancelEdit() {
  254. this.isEditing = false;
  255. this.fillDefaultValue();
  256. },
  257. async handleDelete(index, commitId) {
  258. await ProjectAPI.linkCommit(this.$store.state.workspace.currentProjectId, commitId, 'NONE', this.id);
  259. this.deletedCommitIndex.add(index);
  260. },
  261. async handleRestore(index, commitId) {
  262. console.log(commitId);
  263. console.log(index);
  264. await ProjectAPI.linkCommit(this.$store.state.workspace.currentProjectId, commitId, 'BUG_ID', this.id);
  265. this.deletedCommitIndex.delete(index);
  266. },
  267. },
  268. };
  269. </script>
  270. <style lang="scss" scoped>
  271. .entry-row{
  272. width: 100%;
  273. margin: 3px 20px;
  274. display: flex;
  275. flex-direction: row;
  276. align-items: center;
  277. justify-content: flex-start;
  278. h3, h4{
  279. color: #172b4d
  280. }
  281. }
  282. .detail-row{
  283. display: flex;
  284. flex-direction: row;
  285. align-items: center;
  286. line-height: 24px;
  287. margin: 3px 0;
  288. }
  289. .detail-value{
  290. display: flex;
  291. flex-direction: row;
  292. align-items: center;
  293. }
  294. .node-type{
  295. color: #FFFFFF;
  296. border-radius: 3px;
  297. font-size: 14px;
  298. background-color: #42b983;
  299. text-align: center;
  300. }
  301. .state-entry{
  302. border-radius: 5px;
  303. background-color: cornflowerblue;
  304. font-size: 12px;
  305. color: #FFFFFF;
  306. padding: 0px 4px;
  307. cursor: pointer
  308. }
  309. </style>