<template>
|
<div style="width: 30%; margin-top: 1%; float: left">
|
<el-input placeholder="输入关键字进行过滤" v-model="filterText"> </el-input>
|
<div class="custom-tree-node">
|
<el-tree
|
ref="tree"
|
class="filter-tree"
|
:filter-node-method="filterNode"
|
:data="data"
|
node-key="id"
|
accordion
|
>
|
<template #default="{ node, data }">
|
<span class="custom-tree-node">
|
<span>{{ node.label }}</span>
|
<span v-if="data.hidden">
|
<el-button type="text" size="mini" @click="() => view(data)">
|
查看
|
</el-button>
|
<el-button
|
type="text"
|
size="mini"
|
@click="() => dowmload(node, data)"
|
>
|
下载
|
</el-button>
|
</span>
|
</span>
|
</template>
|
</el-tree>
|
</div>
|
</div>
|
<div style="width: 68%; float: left; margin-left: 1%; margin-top: 1%">
|
<el-card
|
shadow="hover"
|
v-if="logName"
|
style="height: 800px; overflow: auto"
|
>
|
<template #header>
|
<div class="card-header">
|
<span>{{ logName }}</span>
|
</div>
|
</template>
|
<div v-for="(item, index) in log" :key="index" class="text item">
|
{{ item }}
|
</div>
|
</el-card>
|
</div>
|
</template>
|
|
<script>
|
export default {
|
data() {
|
return {
|
data: [],
|
defaultProps: {
|
children: "children",
|
label: "label",
|
},
|
filterText: "",
|
logName: "",
|
log: [],
|
};
|
},
|
watch: {
|
filterText(val) {
|
this.$refs.tree.filter(val);
|
},
|
},
|
created() {
|
this.getLogName();
|
},
|
|
methods: {
|
filterNode(value, data) {
|
if (!value) return true;
|
return data.label.indexOf(value) !== -1;
|
},
|
getLogName() {
|
this.http
|
.post("/api/Sys_Log/GetLogName", null, "正在执行中...")
|
.then((x) => {
|
if (x.status) {
|
this.data = x.data;
|
}
|
});
|
},
|
|
view(data) {
|
var params = {
|
MainData: { fileName: data.label },
|
};
|
this.http
|
.post("/api/Sys_Log/GetLog", params, "正在查询中...")
|
.then((x) => {
|
if (x.status) {
|
this.logName = data.label;
|
this.log = x.data;
|
}
|
});
|
},
|
|
dowmload(node, data) {
|
let ipAddress = this.http.ipAddress;
|
let url =
|
"api/Sys_Log/DownLoadLog?fileName=" +
|
data.fatherNode +
|
"\\" +
|
data.label;
|
let fileName = data.label;
|
let xmlResquest = new XMLHttpRequest();
|
xmlResquest.open("GET", ipAddress + url, true);
|
xmlResquest.setRequestHeader("Content-type", "application/json");
|
xmlResquest.setRequestHeader(
|
"Authorization",
|
this.$store.getters.getToken()
|
);
|
let elink = this.$refs.template;
|
xmlResquest.responseType = "blob";
|
let $_vue = this;
|
this.loadingStatus = true;
|
xmlResquest.onload = function (e) {
|
// 请求成功
|
if (this.status == 200) {
|
let blob = this.response;
|
let a = document.createElement("a");
|
//window.URL.createObjectURL() 静态方法会创建一个 DOMString,其中包含一个表示参数中给出的对象的URL。这个 URL 的生命周期和创建它的窗口中的 document 绑定。这个新的URL 对象表示指定的 File 对象或 Blob 对象。
|
let url = window.URL.createObjectURL(blob);
|
a.href = url;
|
a.download = fileName;
|
a.click();
|
//URL.revokeObjectURL() 静态方法用来释放一个之前已经存在的、通过调用 URL.createObjectURL() 创建的 URL 对象。当你结束使用某个 URL 对象之后,应该通过调用这个方法来让浏览器知道不用在内存中继续保留对这个文件的引用了。
|
window.URL.revokeObjectURL(url);
|
|
} else {
|
//下载失败处理
|
|
}
|
};
|
xmlResquest.send();
|
},
|
},
|
};
|
</script>
|
|
<style>
|
.custom-tree-node {
|
flex: 1;
|
display: flex;
|
align-items: center;
|
justify-content: space-between;
|
font-size: 14px;
|
padding-right: 8px;
|
}
|
.text {
|
font-size: 14px;
|
}
|
|
.item {
|
margin-bottom: 18px;
|
}
|
|
.clearfix:before,
|
.clearfix:after {
|
display: table;
|
content: "";
|
}
|
.clearfix:after {
|
clear: both;
|
}
|
|
.box-card {
|
width: 480px;
|
}
|
</style>
|