wangxinhui
2024-11-06 8f392cc88b0768b74efca3b68785cf5aa1c38e70
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
<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>