From 32b4841505be90edd81eaf2309a04d02fa401a4c Mon Sep 17 00:00:00 2001 From: Stanislav Popov Date: Fri, 25 Dec 2020 00:16:07 +0500 Subject: [PATCH] fix: persistent scan log --- pages/scan.vue | 25 +++++++++++++++++-------- plugins/localStorage.js | 3 ++- store/index.js | 4 ++++ 3 files changed, 23 insertions(+), 9 deletions(-) diff --git a/pages/scan.vue b/pages/scan.vue index 552400b..df0b544 100644 --- a/pages/scan.vue +++ b/pages/scan.vue @@ -114,7 +114,6 @@ export default { data() { return { routerProcess: false, - log: [], running: '', available: '', pending: '', @@ -125,6 +124,10 @@ export default { }, computed: { + log(){ + return this.$store.state.log; + }, + url: { get() { return this.$store.state.url; @@ -160,6 +163,12 @@ export default { }, methods: { + logPush(msg) { + const log = [...this.log, ...[msg]]; + if (log.length > 10000) log.shift(); + this.$store.commit('log', log); + }, + // form state to GET params updateUrlQuery(push = false) { if (this.routerProcess) return; @@ -193,7 +202,7 @@ export default { }, async sendTask() { - this.log.splice(0, this.log.length); + this.$store.commit('log', []); // clear log const opts = { url: this.url, args: this.args @@ -220,11 +229,11 @@ export default { // log to "terminal" this.socket.on("status" + key, (msg, cb) => { console.log(`msg ${key}: ${msg}`); - this.log.push(msg); + this.logPush(msg); }); this.socket.on("status", (msg, cb) => { console.log('msg: ', msg); - this.log.push(msg); + this.logPush(msg); }); // server queue info @@ -241,7 +250,7 @@ export default { const viewerUrl = window.location.origin + this.$router.options.base; if (data.json) { const url = viewerUrl + '?url=' + data.json; - this.log.push(`result: ${url}`); + this.logPush(`result: ${url}`); this.$store.commit('itemsJsonUrl', data.json); } if (data.name) { @@ -252,7 +261,7 @@ export default { } const jsonUrl = `${baseUrl}/${data.name}`; const url = `${viewerUrl}?url=${jsonUrl}`; - this.log.push(`result: ${url}`); + this.logPush(`result: ${url}`); this.$store.commit('itemsJsonUrl', jsonUrl); } }); @@ -274,13 +283,13 @@ export default { }); this.socket.on("disconnect", () => { - this.log.push('server disconnected'); + this.logPush('server disconnected'); this.isNeedAuth = true; this.running = ''; }); this.socket.on("reconnect_attempt", () => { - this.log.push('try to connect ' + this.serverUrl + '...'); + this.logPush('try to connect ' + this.serverUrl + '...'); }); firebase.auth().onAuthStateChanged(user => { diff --git a/plugins/localStorage.js b/plugins/localStorage.js index 4fce7ca..8beb93f 100644 --- a/plugins/localStorage.js +++ b/plugins/localStorage.js @@ -13,6 +13,7 @@ export default ({store}) => { 'uid', 'url', 'args', - 'serverUrl'], + 'serverUrl', + 'log'], })(store); }; diff --git a/store/index.js b/store/index.js index 2f675f1..fc52de5 100644 --- a/store/index.js +++ b/store/index.js @@ -99,6 +99,7 @@ export const state = () => ({ url: 'https://blog.popstas.ru', args: '-m 50', serverUrl: process.env.SERVER_URL || false, + log: [], introTourSteps: [ // tolang /* { @@ -442,6 +443,9 @@ export const mutations = { serverUrl(state, newValue) { state.serverUrl = newValue; }, + log(state, newValue) { + state.log = newValue; + }, }; export const actions = {