新版打包监控,不再用前端轮询

This commit is contained in:
aixianling
2023-01-19 10:47:51 +08:00
parent e419339c10
commit 34e23beaeb
3 changed files with 31 additions and 39 deletions

View File

@@ -23,8 +23,8 @@ const app = new Vue({
render: h => h(App) render: h => h(App)
}); });
let theme = null let theme = null
store.dispatch('getSystem').then(({colorScheme}) => { store.dispatch('getSystem').then(res => {
theme = JSON.parse(colorScheme || null) theme = JSON.parse(res?.colorScheme || null)
Vue.prototype.$theme = theme?.web || "blue" Vue.prototype.$theme = theme?.web || "blue"
return import(`dui/lib/styles/theme.${theme?.web}.scss`).catch(() => 0) return import(`dui/lib/styles/theme.${theme?.web}.scss`).catch(() => 0)
}).finally(() => { }).finally(() => {

View File

@@ -57,7 +57,7 @@ export default {
{prop: "dist", label: "更新路径"}, {prop: "dist", label: "更新路径"},
{slot: 'process'}, {slot: 'process'},
], ],
timer: {} ws: {}
} }
}, },
methods: { methods: {
@@ -107,34 +107,32 @@ export default {
}) })
}, },
handleUpdate(row) { handleUpdate(row) {
let {id} = row, {timer} = this let {id} = row
this.instance.post("/node/custom/getZip", null, { if (!this.ws[id]) {
params: {id} this.ws[id] = new WebSocket(`ws://192.168.1.87:12525/custom/getZip?id=${id}`)
}).then(res => { this.ws[id].onmessage = res => {
if (res?.code == 0) { if (res?.data) {
row.count = 1 const data = JSON.parse(res.data)
timer[id] = setInterval(() => { if (data.code == '0') {
if (row.count >= 100) { row.count = data.progress
clearInterval(timer[id]) if (row.count == 100) {
row.count = 0
this.$message.success("打包成功!")
this.refreshRow(row, data.remark)
}
} else if (data.code == 1) {
row.count = 0 row.count = 0
this.$message.error("打包失败!") this.$message.error("打包失败!")
} else if (row.count % 2 == 0 && row.target) { this.refreshRow(row, data.row)
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.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) { refreshRow(row, v) {
row.error = v.error row.error = v.error
@@ -148,15 +146,9 @@ export default {
}, },
handleCancelUpdate(row) { handleCancelUpdate(row) {
let {id} = row let {id} = row
return this.instance.post("/node/custom/cancelZip", null, { this.ws[id].send(JSON.stringify({
params: {id} cid: id
}).then(res => { }))
if (res?.code == 0) {
clearInterval(this.timer[id])
row.count = 0
this.getRowById(row.id).then(v => this.refreshRow(row, v))
}
})
}, },
getRowById(id) { getRowById(id) {
return this.instance.post("/node/custom/detail", null, { return this.instance.post("/node/custom/detail", null, {
@@ -179,7 +171,7 @@ export default {
this.getTableData() this.getTableData()
}, },
beforeDestroy() { beforeDestroy() {
Object.values(this.timer).map(t => clearInterval(t)) Object.values(this.ws).map(t => t.close())
} }
} }
</script> </script>

View File

@@ -97,7 +97,7 @@ module.exports = {
} }
}, },
'/lns': { '/lns': {
target: 'http://dvcp.sinocare.net', target: 'http://localhost:12525',
changeOrigin: true, changeOrigin: true,
pathRewrite: { pathRewrite: {
//地址重写 //地址重写