Skip to content

Commit

Permalink
feat(ui): buffering task log records
Browse files Browse the repository at this point in the history
  • Loading branch information
fiftin committed Jan 5, 2025
1 parent d2c63b6 commit f5746b2
Showing 1 changed file with 27 additions and 6 deletions.
33 changes: 27 additions & 6 deletions web/src/components/TaskLogView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,7 @@ export default {
itemComponent: TaskLogViewRecord,
item: {},
output: [],
outputBuffer: [],
user: {},
};
},
Expand Down Expand Up @@ -232,10 +233,28 @@ export default {
},
async created() {
this.outputInterval = setInterval(() => {
this.$nextTick(() => {
const len = this.outputBuffer.length;
if (len === 0) {
return;
}
this.output.push(...this.outputBuffer.splice(0, len));
if (this.$refs.records) {
this.$refs.records.scrollToBottom();
}
});
}, 500);
socket.addListener((data) => this.onWebsocketDataReceived(data));
await this.loadData();
},
beforeDestroy() {
clearInterval(this.outputInterval);
},
methods: {
async confirmTask() {
await axios({
Expand Down Expand Up @@ -269,6 +288,8 @@ export default {
reset() {
this.item = {};
this.output = [];
this.outputBuffer = [];
this.outputInterval = null;
this.user = {};
},
Expand All @@ -285,16 +306,16 @@ export default {
});
break;
case 'log':
this.output.push({
this.outputBuffer.push({
...data,
id: data.time + data.output,
});
this.$nextTick(() => {
if (this.$refs.records) {
this.$refs.records.scrollToBottom();
}
});
// this.$nextTick(() => {
// if (this.$refs.records) {
// this.$refs.records.scrollToBottom();
// }
// });
break;
default:
Expand Down

0 comments on commit f5746b2

Please sign in to comment.