diff --git a/src/components/deployment-info.vue b/src/components/deployment-info.vue new file mode 100644 index 0000000000000000000000000000000000000000..343fcb85a320382a15733468f8c0c8baab482976 --- /dev/null +++ b/src/components/deployment-info.vue @@ -0,0 +1,148 @@ + + + + + diff --git a/src/pages/workbench/yygl/deployment.vue b/src/pages/workbench/yygl/deployment.vue index 37a905be6d76eef754c094150e532acc0b3475f1..a7e1e41739b8785ac86c7a320cfab4fb3f1e7142 100644 --- a/src/pages/workbench/yygl/deployment.vue +++ b/src/pages/workbench/yygl/deployment.vue @@ -5,7 +5,9 @@ 我的应用 - + 应用仓库 @@ -65,7 +67,10 @@ :step="2" :active-icon="require('@/assets/imgs/progress_ic_bushudata.png')" > - +
前往查看 @@ -90,12 +95,14 @@ import appBuildSteps from "@/components/app-build-steps/app-build-steps"; import appBuildStep from "@/components/app-build-steps/app-build-step"; import apassDialog from "@/components/apass-dialog"; +import deploymentInfo from "@/components/deployment-info"; export default { components: { appBuildSteps, appBuildStep, apassDialog, + deploymentInfo, }, data: () => ({ step: 0, @@ -116,6 +123,39 @@ export default { tag: [{ required: true, message: "请输入版本号", trigger: "blur" }], file: [{ required: true, message: "请选择镜像文件", trigger: "change" }], }, + evtUuid: "", + evtSource: null, + listStatus: [], + state: "", + text: "", + url: "", + act: 0, + stateList: [ + { + name: "获取部署参数", + value: "values", + content: "获取部署参数", + state: 1, + }, + { + name: "拉取部署文件", + value: "pull-chart", + content: "拉取部署文件", + state: 1, + }, + { + name: "开始部署", + value: "install", + content: "开始部署", + state: 1, + }, + { + name: "部署状态", + value: "deploy-status", + content: "部署状态", + state: 2, + }, + ], }), methods: { preStep() { @@ -124,9 +164,87 @@ export default { nextStep() { this.step++; }, + getStatus() { + let evtUuid = Math.random() + .toString(16) + .substr(3); + let evtSource = new EventSource( + `/apaas/hubApi/event/subscribe/deploy/${evtUuid}` + ); + + this.evtUuid = evtUuid; + this.evtSource = evtSource; + + evtSource.addEventListener("message", function(e) { + if (this.listStatus.map((o) => o.status).indexOf(e.lastEventId) == -1) { + if (this.listStatus.length) { + this.listStatus[this.listStatus.length - 1].success = "success"; + } + + this.listStatus.push({ + status: e.lastEventId, + success: JSON.parse(e.data).state, + data: JSON.parse(e.data).data, + }); + + this.text = this.listStatus[this.listStatus.length - 1].data; + this.text = "" + this.text; + this.text = this.text.replace( + /\n/g, + "\n" + ); + this.text = this.text.replace(/>==>/g, ">>"); + this.act = this.listStatus.length - 1; + } else { + let i = this.listStatus.map((o) => o.status).indexOf(e.lastEventId); + let item = this.listStatus[i].data; + + item = item + "\n" + JSON.parse(e.data).data; + + this.listStatus[i].data = item; + this.text = this.listStatus[this.listStatus.length - 1].data; + this.text = "" + this.text; + this.text = this.text.replace( + /\n/g, + "\n" + ); + this.text = this.text.replace(/>==>/g, ">>"); + this.act = this.listStatus.length - 1; + + if (JSON.parse(e.data).state != "notes") { + this.listStatus[i].success = JSON.parse(e.data).state; + } + } + + if (JSON.parse(e.data).state == "success") { + this.state = "部署成功!"; + this.url = `https://${window.location.host}/apaas/ui/#/pods?namespace=${this.baseInfoForm.namespace}`; + } + + for (let i = 0; i < this.listStatus.length; i++) { + switch (this.listStatus[i].status) { + case "values": + this.listStatus[i].statusHan = "获取部署参数"; + break; + case "pull-chart": + this.listStatus[i].statusHan = "拉取部署文件"; + break; + case "install": + this.listStatus[i].statusHan = "开始部署"; + break; + case "deploy-status": + this.listStatus[i].statusHan = "部署状态"; + break; + default: + this.listStatus[i].statusHan = "其他"; + break; + } + } + }); + }, }, mounted() { - + this.getStatus(); }, };