185 lines
5.6 KiB
Vue
185 lines
5.6 KiB
Vue
|
|
<template>
|
|||
|
|
<div>
|
|||
|
|
<el-form :model="downLoadLog" :label-width="120" style="width: 30vh">
|
|||
|
|
<div style="font-size: 0.8rem; margin-bottom: 1rem; color: coral">
|
|||
|
|
下载路径在您的浏览器里设置哦
|
|||
|
|
</div>
|
|||
|
|
<el-form-item label="日志类型:">
|
|||
|
|
<el-select v-model="downLoadLog.logType" @change="changeLogType">
|
|||
|
|
<el-option label="系统日志" value="系统日志" />
|
|||
|
|
<el-option label="事件日志" value="事件日志" />
|
|||
|
|
<el-option label="接口请求日志" value="接口请求日志" />
|
|||
|
|
<el-option label="接口接收日志" value="接口接收日志" />
|
|||
|
|
<el-option label="异常日志" value="异常日志" />
|
|||
|
|
<el-option label="数据库日志" value="数据库日志" />
|
|||
|
|
</el-select>
|
|||
|
|
</el-form-item>
|
|||
|
|
<el-form-item label="日志时间:">
|
|||
|
|
<el-badge :value="fileName.length">
|
|||
|
|
<el-select v-model="downLoadLog.logFileName" style="width: calc(30vh - 120px)">
|
|||
|
|
<el-option v-for="item in fileName" :label="item" :value="item" />
|
|||
|
|
</el-select>
|
|||
|
|
</el-badge>
|
|||
|
|
</el-form-item>
|
|||
|
|
</el-form>
|
|||
|
|
<span class="dialog-footer">
|
|||
|
|
<el-button @click="preview">预览</el-button>
|
|||
|
|
<el-button type="primary" @click="startDownLoad">下载</el-button>
|
|||
|
|
</span>
|
|||
|
|
</div>
|
|||
|
|
</template>
|
|||
|
|
|
|||
|
|
<script>
|
|||
|
|
// import 《组件名称》 from '《组件路径》 ';
|
|||
|
|
import sysApi from "@/axios/system";
|
|||
|
|
import {ElMessage} from "element-plus";
|
|||
|
|
|
|||
|
|
export default {
|
|||
|
|
// import 引入的组件需要注入到对象中才能使用
|
|||
|
|
components: {},
|
|||
|
|
props: ['modelValue'],
|
|||
|
|
emits: ['update:modelValue'],
|
|||
|
|
data() {
|
|||
|
|
// 这里存放数据
|
|||
|
|
return {
|
|||
|
|
downLoadLog: {
|
|||
|
|
// log类型
|
|||
|
|
logType: '',
|
|||
|
|
// log文件名
|
|||
|
|
logFileName: ''
|
|||
|
|
},
|
|||
|
|
// 文件列表
|
|||
|
|
fileName: []
|
|||
|
|
}
|
|||
|
|
},
|
|||
|
|
// 计算属性 类似于 data 概念
|
|||
|
|
computed: {
|
|||
|
|
|
|||
|
|
},
|
|||
|
|
// 监控 data 中的数据变化
|
|||
|
|
watch: {},
|
|||
|
|
// 方法集合
|
|||
|
|
methods: {
|
|||
|
|
// 下载文件
|
|||
|
|
startDownLoad() {
|
|||
|
|
if(this.downLoadLog.logFileName === '' || this.downLoadLog.logType === '')
|
|||
|
|
{
|
|||
|
|
ElMessage({
|
|||
|
|
message: '需要先选择类型和时间',
|
|||
|
|
type: 'warning',
|
|||
|
|
})
|
|||
|
|
return
|
|||
|
|
}
|
|||
|
|
sysApi.checkDownloadFile(this.downLoadLog).then((response) => {
|
|||
|
|
const responseData = response.data
|
|||
|
|
if(responseData.success === false) {
|
|||
|
|
ElMessage({
|
|||
|
|
message: '文件不存在',
|
|||
|
|
type: 'warning',
|
|||
|
|
})
|
|||
|
|
return
|
|||
|
|
}
|
|||
|
|
sysApi.downloadFile(this.downLoadLog).then((response) => {
|
|||
|
|
const responseData = response.data
|
|||
|
|
const link = document.createElement('a');
|
|||
|
|
link.href = window.URL.createObjectURL(new Blob([responseData]));
|
|||
|
|
link.setAttribute('download', this.downLoadLog.logType + this.downLoadLog.logFileName);
|
|||
|
|
document.body.appendChild(link);
|
|||
|
|
link.click();
|
|||
|
|
document.body.removeChild(link);
|
|||
|
|
ElMessage({
|
|||
|
|
message: '您的下载将在 30秒内开始,请稍后',
|
|||
|
|
type: 'success',
|
|||
|
|
})
|
|||
|
|
}).catch((ex) => {
|
|||
|
|
// 通讯报错
|
|||
|
|
ElMessage({
|
|||
|
|
message: '下载出现异常:' + ex,
|
|||
|
|
type: 'error',
|
|||
|
|
})
|
|||
|
|
})
|
|||
|
|
}).catch((ex) => {
|
|||
|
|
// 通讯报错
|
|||
|
|
ElMessage({
|
|||
|
|
message: '下载文件验证出现异常:' + ex,
|
|||
|
|
type: 'error',
|
|||
|
|
})
|
|||
|
|
})
|
|||
|
|
},
|
|||
|
|
changeLogType() {
|
|||
|
|
this.downLoadLog.logFileName = ''
|
|||
|
|
sysApi.getLogFileName(this.downLoadLog.logType).then((response) => {
|
|||
|
|
const responseData = response.data
|
|||
|
|
if(responseData.code !== 0 || responseData["returnData"] === undefined || responseData["returnData"] === null) {
|
|||
|
|
ElMessage({
|
|||
|
|
message: '没有文件',
|
|||
|
|
type: 'warning',
|
|||
|
|
})
|
|||
|
|
this.fileName = []
|
|||
|
|
return
|
|||
|
|
}
|
|||
|
|
this.fileName = responseData["returnData"]
|
|||
|
|
}).catch((ex) => {
|
|||
|
|
// 通讯报错
|
|||
|
|
ElMessage({
|
|||
|
|
message: '请求出现异常:' + ex,
|
|||
|
|
type: 'error',
|
|||
|
|
})
|
|||
|
|
this.fileName = []
|
|||
|
|
})
|
|||
|
|
},
|
|||
|
|
// 预览
|
|||
|
|
preview() {
|
|||
|
|
if(this.downLoadLog.logFileName === '' || this.downLoadLog.logType === '')
|
|||
|
|
{
|
|||
|
|
ElMessage({
|
|||
|
|
message: '需要先选择类型和时间',
|
|||
|
|
type: 'warning',
|
|||
|
|
})
|
|||
|
|
return
|
|||
|
|
}
|
|||
|
|
this.$emit('update:modelValue', '')
|
|||
|
|
sysApi.checkDownloadFile(this.downLoadLog).then((response) => {
|
|||
|
|
const responseData = response.data
|
|||
|
|
if(responseData.success === false) {
|
|||
|
|
ElMessage({
|
|||
|
|
message: '文件不存在',
|
|||
|
|
type: 'warning',
|
|||
|
|
})
|
|||
|
|
return
|
|||
|
|
}
|
|||
|
|
sysApi.downloadFile(this.downLoadLog).then((response) => {
|
|||
|
|
const responseData = response.data
|
|||
|
|
responseData.text().then(data=>{
|
|||
|
|
this.$emit('update:modelValue', data)
|
|||
|
|
}).catch(err=>{
|
|||
|
|
ElMessage({
|
|||
|
|
message: '预览出现异常:' + err,
|
|||
|
|
type: 'error',
|
|||
|
|
})
|
|||
|
|
})
|
|||
|
|
}).catch((ex) => {
|
|||
|
|
// 通讯报错
|
|||
|
|
ElMessage({
|
|||
|
|
message: '预览出现异常:' + ex,
|
|||
|
|
type: 'error',
|
|||
|
|
})
|
|||
|
|
})
|
|||
|
|
}).catch((ex) => {
|
|||
|
|
// 通讯报错
|
|||
|
|
ElMessage({
|
|||
|
|
message: '预览文件验证出现异常:' + ex,
|
|||
|
|
type: 'error',
|
|||
|
|
})
|
|||
|
|
})
|
|||
|
|
}
|
|||
|
|
},
|
|||
|
|
// 生命周期 - 挂载完成(可以访问 DOM 元素)
|
|||
|
|
mounted() {
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
</script>
|
|||
|
|
|
|||
|
|
<style scoped>
|
|||
|
|
|
|||
|
|
</style>
|