647556386
昨天 b680585c3a6d43f0c72a83a115ea537ce8c91a07
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
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
<template>
  <div class="tree-container">
    <el-input placeholder="输入关键字进行过滤" v-model="filterText" class="filter-input">
    </el-input>
    <div class="custom-tree-wrapper">
      <el-tree ref="tree" class="filter-tree" :filter-node-method="filterNode" :data="data" node-key="id" accordion>
        <template #default="{ node, data }">
          <div class="custom-tree-node">
            <span class="node-label">{{ node.label }}</span>
            <span v-if="data.hidden" class="node-actions">
              <el-button type="text" size="mini" @click="() => view(data)" class="action-btn">
                查看
              </el-button>
              <el-button type="text" size="mini" @click="() => dowmload(node, data)" class="action-btn">
                下载
              </el-button>
            </span>
          </div>
        </template>
      </el-tree>
    </div>
  </div>
  <div class="log-container">
    <el-card shadow="always" v-if="logName" class="log-card">
      <template #header>
        <div class="card-header">
          <el-tag type="info" size="small">日志文件</el-tag>
          <span class="log-title">{{ logName }}</span>
        </div>
      </template>
      <div class="log-content">
        <div v-for="(item, index) in log" :key="index" class="log-line">
          <span class="line-number">{{ index + 1 }}</span>
          <span class="line-content">{{ item }}</span>
        </div>
      </div>
    </el-card>
    <div v-else class="empty-log">
      <el-empty description="请选择日志文件进行查看" />
    </div>
  </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?fileName=" + data.label, "正在查询中...")
        .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 scoped>
.tree-container {
  width: 30%;
  float: left;
  padding: 16px;
  background: #f8f9fa;
  border-radius: 8px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}
 
.filter-input {
  margin-bottom: 16px;
}
 
.filter-input :deep(.el-input__inner) {
  border-radius: 20px;
  border-color: #dcdfe6;
  transition: all 0.3s;
}
 
.filter-input :deep(.el-input__inner):focus {
  border-color: #409eff;
  box-shadow: 0 0 0 2px rgba(64, 158, 255, 0.1);
}
 
.custom-tree-wrapper {
  height: 760px;
  overflow-y: auto;
  padding: 8px;
  background: white;
  border-radius: 6px;
  border: 1px solid #ebeef5;
}
 
.filter-tree :deep(.el-tree-node__content) {
  height: 40px;
  margin: 2px 0;
  border-radius: 4px;
  transition: all 0.2s;
}
 
.filter-tree :deep(.el-tree-node__content:hover) {
  background-color: #f0f9ff;
}
 
.filter-tree :deep(.el-tree-node.is-current > .el-tree-node__content) {
  background-color: #ecf5ff;
  font-weight: 600;
}
 
.custom-tree-node {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  padding: 0 8px;
}
 
.node-label {
  font-size: 14px;
  color: #606266;
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
 
.node-actions {
  display: flex;
  gap: 8px;
  margin-left: 12px;
}
 
.action-btn {
  padding: 4px 8px;
  font-size: 12px;
  color: #409eff;
  border-radius: 3px;
}
 
.action-btn:hover {
  background-color: rgba(64, 158, 255, 0.1);
}
 
.log-container {
  width: 68%;
  float: right;
  padding: 16px;
}
 
.log-card {
  height: 800px;
  border-radius: 8px;
  border: 1px solid #ebeef5;
}
 
.log-card :deep(.el-card__header) {
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  border-bottom: 1px solid #ebeef5;
  padding: 16px 20px;
}
 
.card-header {
  display: flex;
  align-items: center;
  gap: 12px;
}
 
.log-title {
  font-size: 16px;
  font-weight: 600;
  color: white;
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
 
.log-content {
  height: 700px;
  overflow-y: auto;
  font-family: 'Consolas', 'Monaco', 'Courier New', monospace;
  background: #f8f9fa;
  padding: 12px;
  border-radius: 4px;
}
 
.log-line {
  display: flex;
  align-items: flex-start;
  margin-bottom: 4px;
  line-height: 1.5;
  background: white;
  padding: 8px 12px;
  border-radius: 4px;
  border-left: 3px solid #409eff;
  transition: all 0.2s;
}
 
.log-line:hover {
  background: #f0f9ff;
  transform: translateX(2px);
}
 
.line-number {
  display: inline-block;
  min-width: 40px;
  padding-right: 12px;
  text-align: right;
  color: #909399;
  font-size: 12px;
  user-select: none;
}
 
.line-content {
  flex: 1;
  color: #303133;
  font-size: 13px;
  word-break: break-all;
  white-space: pre-wrap;
}
 
.empty-log {
  height: 800px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: white;
  border-radius: 8px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}
 
.empty-log :deep(.el-empty__description) {
  margin-top: 8px;
}
 
/* 滚动条样式 */
.custom-tree-wrapper::-webkit-scrollbar,
.log-content::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}
 
.custom-tree-wrapper::-webkit-scrollbar-track,
.log-content::-webkit-scrollbar-track {
  background: #f1f1f1;
  border-radius: 3px;
}
 
.custom-tree-wrapper::-webkit-scrollbar-thumb,
.log-content::-webkit-scrollbar-thumb {
  background: #c1c1c1;
  border-radius: 3px;
}
 
.custom-tree-wrapper::-webkit-scrollbar-thumb:hover,
.log-content::-webkit-scrollbar-thumb:hover {
  background: #a8a8a8;
}
 
/* 清除浮动 */
.tree-container::after,
.log-container::after {
  content: "";
  display: table;
  clear: both;
}
</style>