composition: update LogViewer

This commit is contained in:
Matthias 2022-04-15 19:44:16 +02:00
parent 80f01ed91a
commit 2738d03363

View File

@ -6,33 +6,34 @@
</template> </template>
<script lang="ts"> <script lang="ts">
import { Component, Vue } from 'vue-property-decorator';
import { namespace } from 'vuex-class';
import { LogLine } from '@/types';
import { BotStoreGetters } from '@/store/modules/ftbot'; import { BotStoreGetters } from '@/store/modules/ftbot';
import StoreModules from '@/store/storeSubModules'; import StoreModules from '@/store/storeSubModules';
import { defineComponent, onMounted, computed } from '@vue/composition-api';
import { useNamespacedActions, useNamespacedGetters } from 'vuex-composition-helpers';
const ftbot = namespace(StoreModules.ftbot); export default defineComponent({
name: 'LogViewer',
setup() {
const { lastLogs } = useNamespacedGetters(StoreModules.ftbot, [BotStoreGetters.lastLogs]);
const { getLogs } = useNamespacedActions(StoreModules.ftbot, ['getLogs']);
@Component({}) onMounted(() => getLogs());
export default class LogViewer extends Vue { const formattedLogs = computed(() => {
@ftbot.Getter [BotStoreGetters.lastLogs]!: LogLine[]; let result = '';
for (let i = 0, len = lastLogs.value.length; i < len; i += 1) {
const log = lastLogs.value[i];
result += `${log[0]} - ${log[2]} - ${log[3]} - ${log[4]}\n`;
}
return result;
});
@ftbot.Action getLogs; return {
getLogs,
mounted() { lastLogs,
this.getLogs(); formattedLogs,
} };
},
get formattedLogs() { });
let result = '';
for (let i = 0, len = this.lastLogs.length; i < len; i += 1) {
const log = this.lastLogs[i];
result += `${log[0]} - ${log[2]} - ${log[3]} - ${log[4]}\n`;
}
return result;
}
}
</script> </script>
<style lang="scss" scoped> <style lang="scss" scoped>