From 34e23beaeb5ebaedacf184a64132cae364770814 Mon Sep 17 00:00:00 2001 From: aixianling Date: Thu, 19 Jan 2023 10:47:51 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E7=89=88=E6=89=93=E5=8C=85=E7=9B=91?= =?UTF-8?q?=E6=8E=A7,=E4=B8=8D=E5=86=8D=E7=94=A8=E5=89=8D=E7=AB=AF?= =?UTF-8?q?=E8=BD=AE=E8=AF=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- examples/main.js | 4 +- .../oms/apps/develop/AppDeployCustom/list.vue | 64 ++++++++----------- vue.config.js | 2 +- 3 files changed, 31 insertions(+), 39 deletions(-) diff --git a/examples/main.js b/examples/main.js index 5266f8e9..cf168901 100644 --- a/examples/main.js +++ b/examples/main.js @@ -23,8 +23,8 @@ const app = new Vue({ render: h => h(App) }); let theme = null -store.dispatch('getSystem').then(({colorScheme}) => { - theme = JSON.parse(colorScheme || null) +store.dispatch('getSystem').then(res => { + theme = JSON.parse(res?.colorScheme || null) Vue.prototype.$theme = theme?.web || "blue" return import(`dui/lib/styles/theme.${theme?.web}.scss`).catch(() => 0) }).finally(() => { diff --git a/project/oms/apps/develop/AppDeployCustom/list.vue b/project/oms/apps/develop/AppDeployCustom/list.vue index 4c75628c..e7793204 100644 --- a/project/oms/apps/develop/AppDeployCustom/list.vue +++ b/project/oms/apps/develop/AppDeployCustom/list.vue @@ -57,7 +57,7 @@ export default { {prop: "dist", label: "更新路径"}, {slot: 'process'}, ], - timer: {} + ws: {} } }, methods: { @@ -107,34 +107,32 @@ export default { }) }, handleUpdate(row) { - let {id} = row, {timer} = this - this.instance.post("/node/custom/getZip", null, { - params: {id} - }).then(res => { - if (res?.code == 0) { - row.count = 1 - timer[id] = setInterval(() => { - if (row.count >= 100) { - clearInterval(timer[id]) + let {id} = row + if (!this.ws[id]) { + this.ws[id] = new WebSocket(`ws://192.168.1.87:12525/custom/getZip?id=${id}`) + this.ws[id].onmessage = res => { + if (res?.data) { + const data = JSON.parse(res.data) + if (data.code == '0') { + row.count = data.progress + if (row.count == 100) { + row.count = 0 + this.$message.success("打包成功!") + this.refreshRow(row, data.remark) + } + } else if (data.code == 1) { row.count = 0 this.$message.error("打包失败!") - } else if (row.count % 2 == 0 && row.target) { - row.count++ - } else this.getRowById(row.id).then(v => { - if (v.error) { - clearInterval(timer[id]) - this.$message.error("打包失败!") - this.refreshRow(row, v) - row.count = 0 - } else if (v.download) { - clearInterval(timer[id]) - this.refreshRow(row, v) - row.count = 0 - } else row.count++ - }) - }, 6000) + this.refreshRow(row, data.row) + } + } } - }) + this.ws[id].onclose = () => { + row.count = 0 + this.ws[id].close() + delete this.ws[id] + } + } else this.ws[id]?.send(JSON.stringify({id})) }, refreshRow(row, v) { row.error = v.error @@ -148,15 +146,9 @@ export default { }, handleCancelUpdate(row) { let {id} = row - return this.instance.post("/node/custom/cancelZip", null, { - params: {id} - }).then(res => { - if (res?.code == 0) { - clearInterval(this.timer[id]) - row.count = 0 - this.getRowById(row.id).then(v => this.refreshRow(row, v)) - } - }) + this.ws[id].send(JSON.stringify({ + cid: id + })) }, getRowById(id) { return this.instance.post("/node/custom/detail", null, { @@ -179,7 +171,7 @@ export default { this.getTableData() }, beforeDestroy() { - Object.values(this.timer).map(t => clearInterval(t)) + Object.values(this.ws).map(t => t.close()) } } diff --git a/vue.config.js b/vue.config.js index 3638bf84..bbbc319b 100644 --- a/vue.config.js +++ b/vue.config.js @@ -97,7 +97,7 @@ module.exports = { } }, '/lns': { - target: 'http://dvcp.sinocare.net', + target: 'http://localhost:12525', changeOrigin: true, pathRewrite: { //地址重写