mirror of
https://github.com/CzBiX/qb-web.git
synced 2026-12-01 08:16:04 +08:00
Auto update logs
This commit is contained in:
10
src/Api.ts
10
src/Api.ts
@@ -63,8 +63,14 @@ class Api {
|
||||
return this.axios.post('/app/setPreferences', data);
|
||||
}
|
||||
|
||||
public getLogs() {
|
||||
return this.axios.get('/log/main').then(this.handleResponse);
|
||||
public getLogs(lastId?: number) {
|
||||
const params = {
|
||||
last_known_id: lastId,
|
||||
};
|
||||
|
||||
return this.axios.get('/log/main', {
|
||||
params,
|
||||
}).then(this.handleResponse);
|
||||
}
|
||||
|
||||
public toggleSpeedLimitsMode() {
|
||||
|
||||
@@ -30,13 +30,16 @@
|
||||
<script lang="ts">
|
||||
import Vue from 'vue'
|
||||
import { api } from '../Api';
|
||||
import { sleep } from '../utils';
|
||||
export default Vue.extend({
|
||||
props: {
|
||||
value: Boolean,
|
||||
},
|
||||
data() {
|
||||
return {
|
||||
logs: null,
|
||||
logs: [],
|
||||
task: 0,
|
||||
destory: false,
|
||||
};
|
||||
},
|
||||
filters: {
|
||||
@@ -69,15 +72,33 @@ export default Vue.extend({
|
||||
this.$emit('input', false);
|
||||
},
|
||||
async getLogs() {
|
||||
this.logs = await api.getLogs();
|
||||
const lastId = this.logs.length ? this.logs[this.logs.length - 1]['id'] : -1;
|
||||
const logs = await api.getLogs(lastId);
|
||||
|
||||
await this.$nextTick();
|
||||
this.$refs.end.scrollIntoView();
|
||||
if (this.destory) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (logs.length) {
|
||||
this.logs = this.logs.concat(logs);
|
||||
|
||||
await this.$nextTick();
|
||||
|
||||
this.$refs.end.scrollIntoView();
|
||||
}
|
||||
|
||||
this.task = setTimeout(this.getLogs, 2000);
|
||||
},
|
||||
},
|
||||
async created() {
|
||||
await this.getLogs();
|
||||
},
|
||||
beforeDestroy() {
|
||||
this.destory = true;
|
||||
if (this.task) {
|
||||
clearTimeout(this.task);
|
||||
}
|
||||
},
|
||||
});
|
||||
</script>
|
||||
|
||||
|
||||
@@ -42,3 +42,7 @@ export function torrentIsState(type: StateType, state: string) {
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
export function sleep(ms: number) {
|
||||
return new Promise((resolve) => setTimeout(resolve, ms));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user