blob: 4856bce86f8e5028cc57d3417b52925c48e893f3 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
|
<template>
<v-app>
<v-container>
<v-file-input label="选择日志文件" v-model="selectedFile"></v-file-input>
<v-btn color="primary" @click="uploadFile">上传</v-btn>
<v-card>
<v-card-text>
<pre v-html="formattedLog"></pre>
</v-card-text>
</v-card>
</v-container>
</v-app>
</template>
<script>
export default {
data() {
return {
selectedFile: null,
logContent: '',
}
},
computed: {
formattedLog() {
return this.logContent.replace(/\[(.*?)\]/g, '<span class="log-tag">$1</span>');
},
},
methods: {
async uploadFile() {
if (!this.selectedFile) {
alert('请先选择日志文件!');
return;
}
const formData = new FormData();
formData.append('file', this.selectedFile);
try {
const response = await fetch('/api/upload', { method: 'POST', body: formData });
const data = await response.json();
if (data.success) {
this.logContent = data.logContent;
} else {
alert('上传出错!');
}
} catch (error) {
console.error(error);
alert('发生错误,请稍后重试!');
}
},
},
}
</script>
<style>
.log-tag {
color: green;
}
</style>
|