LogFile.vue
2.41 KB
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
66
67
68
69
70
71
72
<!--
* @Author: 前端 qianduan01@didihu.com.cn
* @Date: 2024-09-04 21:13:18
* @LastEditors: 前端 qianduan01@didihu.com.cn
* @LastEditTime: 2024-11-07 16:37:29
* @FilePath: \Apper-Admin-master\src\views\log\dictionary\components\Dailog.vue
* @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
-->
<template>
<el-dialog :before-close="handleClose" v-model="showLog" width="50%" title="日志文件列表">
<el-table class="table-box" :data="tableData" style="width: 100%">
<el-table-column prop="filename" label="文件名" />
<el-table-column prop="created_at" label="日期" width="160">
<template #default="scope"> {{ new Date(scope.row.created_at).toLocaleString() }} </template>
</el-table-column>
<el-table-column fixed="right" label="操作" width="120">
<template #default="scope">
<el-button link type="primary" size="small" @click="handleClick(scope.row)"> 详情 </el-button>
</template>
</el-table-column>
</el-table>
<Detail :detail-visible="detailVisible" v-if="detailVisible" @close="detailVisible = false" :detail="detail" />
</el-dialog>
</template>
<script setup lang="ts" name="LogFile">
import { FileList } from "@/api/modules/device";
import { toRefs, ref } from "vue";
import { Device } from "@/api/interface";
import Detail from "./Detail.vue";
const detailVisible = ref(false);
const detail = ref();
const props = defineProps<{
showLog: boolean;
deviceId: number;
}>();
const emit = defineEmits<{
(e: "close"): void;
}>();
let tableData = ref<Device.FileList[]>([]);
const handleClose = () => {
emit("close");
};
const handleClick = async (row: Device.FileList) => {
detailVisible.value = true;
detail.value = await getFileContent(row.path);
};
const getFileContent = async (url): Promise<string | void> => {
try {
const response = await fetch(url);
if (!response.ok) {
throw new Error("Network response was not ok");
}
const text = await response.text();
console.log(text);
return text;
} catch (error) {
console.log(error);
}
};
const { showLog, deviceId } = toRefs(props);
FileList({ device_id: deviceId.value }).then(res => {
tableData.value = res.data as Device.FileList[];
});
</script>
<style lang="scss" scoped>
.table-box {
max-height: 60vh;
overflow-y: auto;
}
</style>