DeployDetail.vue 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357
  1. <template>
  2. <div class="data-table">
  3. <section>
  4. <div class="mirror-subtitle" v-if="deployStatus != 'RUNNING'">
  5. 选择镜像
  6. </div>
  7. <div class="select-mirror" v-if="deployStatus != 'RUNNING'">
  8. <div class="latest-build">
  9. <div
  10. class="test-item"
  11. :key="`b${item.id}`"
  12. v-for="item in latestBuildList"
  13. >
  14. <div>
  15. <b-radio v-model="radio" :native-value="`b${item.id}`"> </b-radio>
  16. <strong>构建ID: #</strong> {{ item.id }}
  17. <b-tag type="is-success">success</b-tag>
  18. <span style="padding-left: 10px">
  19. <strong>镜像ID: #</strong> {{ item.mirrorId }}
  20. </span>
  21. </div>
  22. </div>
  23. <div
  24. class="test-item"
  25. :key="`d${item.id}`"
  26. v-for="item in latestDeployList"
  27. >
  28. <div>
  29. <b-radio v-model="radio" :native-value="`d${item.id}`"> </b-radio>
  30. <strong>部署ID: #</strong> {{ item.id }}
  31. <b-tag type="is-success">success</b-tag>
  32. <span style="padding-left: 10px">
  33. <strong>镜像ID: #</strong> {{ item.mirrorId }}
  34. </span>
  35. </div>
  36. </div>
  37. </div>
  38. </div>
  39. <button
  40. :class="['button', 'block', 'is-link', { 'is-loading': isRunning }]"
  41. @click="startDeploy"
  42. style="margin-top: 20px;"
  43. >
  44. 开始部署
  45. </button>
  46. <b-message
  47. title="部署进行中..."
  48. :active.sync="isRunning"
  49. type="is-warning"
  50. >
  51. 部署已经开始,一次部署需要大约5-10分钟,请5-10分钟后刷新页面获取部署结果
  52. </b-message>
  53. </section>
  54. <!--部署记录-->
  55. <div class="deploy-list" v-if="deployInfo">
  56. <div class="subtitle">
  57. {{ isRunning ? "当前部署情况" : "上次部署结果" }}
  58. </div>
  59. <div class="deploy-item">本次部署ID: #{{ deployInfo.id }}</div>
  60. <div class="deploy-item">本次部署镜像ID: #{{ deployInfo.mirrorId }}</div>
  61. <div class="deploy-item">
  62. 本次部署创建时间: {{ handleTime(deployInfo.createdAt) }}
  63. </div>
  64. <div class="deploy-item" v-if="deployInfo.endAt">
  65. 本次部署结束时间: {{ handleTime(deployInfo.endAt) }}
  66. </div>
  67. <div class="deploy-item">
  68. 部署结果:
  69. <div :class="['tag', type(deployInfo.status)]">
  70. {{ deployInfo.status }}
  71. </div>
  72. </div>
  73. <div class="subtitle">项目部署地址</div>
  74. <div class="deploy-item">{{ deployInfo.url }}</div>
  75. <div class="deploy-item">
  76. <div class="subtitle">部署输出信息</div>
  77. <a
  78. :class="[
  79. 'button',
  80. 'is-small',
  81. 'is-info',
  82. { 'is-loading': isfetchLog }
  83. ]"
  84. @click="getDeployLogInfo"
  85. >
  86. {{ unfoldDeployLogInfo ? "收起部署详细信息" : "查看部署详细信息" }}</a
  87. >
  88. <div class="code-section" v-show="unfoldDeployLogInfo">
  89. <div class="code-content" v-html="deployLog"></div>
  90. </div>
  91. </div>
  92. </div>
  93. </div>
  94. </template>
  95. <script>
  96. import {
  97. getDeployDetail,
  98. getDeployLogInfo,
  99. getLatestBuildInfoList,
  100. makeDeploy,
  101. getLatestDeployInfoList
  102. } from "@/api/codehw";
  103. export default {
  104. data() {
  105. return {
  106. isActive: false,
  107. isRunning: false,
  108. deployStatus: "",
  109. deployInfo: {},
  110. haveDeployRecord: false,
  111. deployLog: "",
  112. unfoldDeployLogInfo: false,
  113. latestBuildList: [],
  114. latestDeployList: [],
  115. latestMirrorIdList: [],
  116. radio: -1,
  117. isfetchLog: false
  118. };
  119. },
  120. props: {
  121. projectDetail: {
  122. type: Object,
  123. default: () => {}
  124. },
  125. detailLoading: {
  126. type: Boolean,
  127. default: false
  128. }
  129. },
  130. watch: {
  131. projectDetail: function(newVal) {
  132. console.log(newVal);
  133. //获取最新一次部署详细信息
  134. if (newVal.latestDeploy && newVal.latestDeploy.id) {
  135. this.haveDeployRecord = true;
  136. this.getLatestDeployInfo(newVal.latestDeploy.id);
  137. // this.getDeployLogInfo(this.projectDetail.latestDeploy.id);
  138. }
  139. this.getLatestBuildInfo(this.projectDetail && this.projectDetail.id, 5);
  140. this.getLastNDeployInfoList(
  141. this.projectDetail && this.projectDetail.id,
  142. 5
  143. );
  144. }
  145. },
  146. mounted() {
  147. if (this.projectDetail.latestDeploy) {
  148. this.getLatestDeployInfo(this.projectDetail.latestDeploy.id);
  149. // this.getDeployLogInfo(this.projectDetail.latestDeploy.id);
  150. }
  151. if (this.projectDetail.id) {
  152. this.getLatestBuildInfo(this.projectDetail.id, 5);
  153. this.getLastNDeployInfoList(this.projectDetail.id, 5);
  154. }
  155. },
  156. methods: {
  157. //获取部署日志
  158. // checkDeployLog(){
  159. // if(this.projectDetail.latestDeploy){
  160. // this.getDeployLogInfo(this.projectDetail.latestDeploy.id);
  161. // }
  162. // },
  163. //获取最新一次部署详细信息
  164. getLatestDeployInfo(deployId) {
  165. getDeployDetail(deployId)
  166. .then(res => {
  167. this.deployInfo = res.data;
  168. this.deployStatus = res.data.status;
  169. let isRunning = this.deployStatus == "RUNNING" ? true : false;
  170. this.isRunning = isRunning;
  171. })
  172. .catch(e => {
  173. this.$toast.open({
  174. message: e.message || "服务器未知错误",
  175. type: "is-danger"
  176. });
  177. });
  178. },
  179. //处理时间格式
  180. handleTime(time) {
  181. if (!time) {
  182. return "";
  183. }
  184. return time.replace("T", " ") + "ms";
  185. },
  186. //开始部署
  187. startDeploy() {
  188. if (this.radio == -1) {
  189. this.$toast.open({
  190. message: "请先选择镜像",
  191. type: "is-danger"
  192. });
  193. return;
  194. } else {
  195. let mirrorId = this.getSelectedMirrorId();
  196. //触发部署
  197. makeDeploy({
  198. projectId: this.projectDetail.id,
  199. mirrorId: mirrorId,
  200. replicas: 1
  201. })
  202. .then(res => {
  203. console.log(res);
  204. this.$toast.open({
  205. message: "开始部署",
  206. type: "is-success"
  207. });
  208. this.isRunning = true;
  209. // setTimeout(() => {
  210. // this.getLatestDeployInfo(this.projectDetail.latestDeploy.id);
  211. // }, 1000);
  212. })
  213. .catch(e => {
  214. this.$toast.open({
  215. message: e.message || "服务器未知错误",
  216. type: "is-danger"
  217. });
  218. });
  219. }
  220. },
  221. //获取最近n次部署成功记录
  222. getLastNDeployInfoList(projectId, limit) {
  223. getLatestDeployInfoList(projectId, limit)
  224. .then(res => {
  225. this.latestDeployList = res.data;
  226. // this.latestMirrorIdList = this.latestMirrorIdList.concat(res.data);
  227. })
  228. .catch(e => {
  229. this.$toast.open({
  230. message: e.message || " 服务器未知错误",
  231. type: "is-danger"
  232. });
  233. });
  234. },
  235. //获取最近n个构建的信息
  236. getLatestBuildInfo(projectId, limit) {
  237. getLatestBuildInfoList(projectId, limit)
  238. .then(res => {
  239. this.latestBuildList = res.data;
  240. // this.latestMirrorIdList = this.latestMirrorIdList.concat(res.data);
  241. })
  242. .catch(e => {
  243. this.$toast.open({
  244. message: e.message || "服务器未知错误",
  245. type: "is-danger"
  246. });
  247. });
  248. },
  249. //获取部署日志
  250. getDeployLogInfo() {
  251. if (this.unfoldDeployLogInfo) {
  252. this.unfoldDeployLogInfo = false;
  253. } else {
  254. let deployId = this.projectDetail.latestDeploy.id;
  255. this.isfetchLog = true;
  256. getDeployLogInfo(deployId)
  257. .then(res => {
  258. this.deployLog = res.data;
  259. this.unfoldDeployLogInfo = true;
  260. this.isfetchLog = false;
  261. })
  262. .catch(e => {
  263. this.isfetchLog = false;
  264. this.$toast.open({
  265. message: e.message || "服务器未知错误",
  266. type: "is-danger"
  267. });
  268. });
  269. }
  270. },
  271. //部署类型
  272. type(value) {
  273. if (value == "FAILURE") {
  274. return "is-danger";
  275. } else if (value == "RUNNING") {
  276. return "is-warning";
  277. } else if (value == "SUCCESS") {
  278. return "is-success";
  279. } else {
  280. return "";
  281. }
  282. },
  283. //选择镜像ID
  284. getSelectedMirrorId() {
  285. let list =
  286. this.radio[0] == "b" ? this.latestBuildList : this.latestDeployList;
  287. let id = this.radio.substring(1);
  288. for (let item of list) {
  289. if (item.id == id) {
  290. return item.mirrorId;
  291. }
  292. }
  293. }
  294. }
  295. };
  296. </script>
  297. <style lang="scss" scoped>
  298. @import "../../../../assets/scss/app";
  299. .mirror-subtitle {
  300. font-size: 1.25rem;
  301. width: 100%;
  302. font-weight: bold;
  303. padding-bottom: 10px;
  304. border-bottom: 1px solid #dbdbdb;
  305. }
  306. .select-mirror {
  307. width: 100%;
  308. display: flex;
  309. .latest-build {
  310. width: 100%;
  311. }
  312. }
  313. .test-item {
  314. width: 100%;
  315. padding: $default-margin $default-margin-between;
  316. margin: 0 -#{$default-margin-between};
  317. cursor: pointer;
  318. }
  319. /*.test-item:hover,*/
  320. /*.test-item:nth-child(even):hover {*/
  321. /*background-color: #dde3ef;*/
  322. /*}*/
  323. .test-item:nth-child(even) {
  324. background-color: rgba(244, 247, 252, 0.6);
  325. }
  326. .deploy-list {
  327. margin-top: 1.5rem;
  328. .deploy-item {
  329. margin-top: 10px;
  330. font-weight: bold;
  331. .tag {
  332. margin-left: 10px;
  333. margin-right: 10px;
  334. }
  335. a {
  336. margin-bottom: 10px;
  337. }
  338. }
  339. .subtitle {
  340. margin-top: 1.5rem;
  341. width: 100%;
  342. font-weight: bold;
  343. padding-bottom: 10px;
  344. border-bottom: 1px solid #dbdbdb;
  345. }
  346. }
  347. .code-section {
  348. background-color: #2d3044;
  349. padding: 20px 20px 20px 20px;
  350. white-space: pre-line;
  351. .code-content {
  352. color: #cacff1;
  353. }
  354. }
  355. </style>