Blame view

HHECS.Web/src/views/logManage/components/interfaceLog.vue 13.7 KB
陈嘉新 authored
1
2
<template>
  <div class="interfacel">
陈嘉新 authored
3
4
5
6
7
8
9
10
11
12
    <el-form
      :model="queryConfig"
      :rules="rules"
      ref="queryConfig"
      label-width="100px"
      class="demo-queryConfig"
    >
      <el-row :gutter="10">
        <el-col :span="4">
          <el-form-item label="接口名:" prop="name">
陈嘉新 authored
13
14
15
16
            <el-input
              v-model="queryConfig.interfaceName"
              placeholder="请选择接口名"
            ></el-input>
陈嘉新 authored
17
18
19
20
          </el-form-item>
        </el-col>
        <el-col :span="4">
          <el-form-item label="标志:" prop="">
陈嘉新 authored
21
            <el-select v-model="queryConfig.flag" placeholder="请选择标志">
陈嘉新 authored
22
              <el-option
23
                v-for="item in optionsFlag"
陈嘉新 authored
24
25
26
27
28
                :key="item.value"
                :label="item.label"
                :value="item.value"
              />
            </el-select>
陈嘉新 authored
29
30
31
32
          </el-form-item>
        </el-col>
        <el-col :span="4">
          <el-form-item label="Url:" prop="">
陈嘉新 authored
33
            <el-input v-model="queryConfig.url" placeholder="请选择Url" />
陈嘉新 authored
34
35
36
37
          </el-form-item>
        </el-col>
        <el-col :span="4">
          <el-form-item label="请求方式:" prop="">
陈嘉新 authored
38
39
40
41
            <el-input
              v-model="queryConfig.method"
              placeholder="请选择请求方式"
            />
陈嘉新 authored
42
43
44
45
          </el-form-item>
        </el-col>
        <el-col :span="4">
          <el-form-item label="耗时:" prop="totalMilliseconds">
陈嘉新 authored
46
47
48
49
            <el-input
              v-model="queryConfig.totalMilliseconds"
              placeholder="请选择耗时"
            />
陈嘉新 authored
50
51
52
53
          </el-form-item>
        </el-col>
        <el-col :span="4">
          <el-form-item label="请求:" prop="">
陈嘉新 authored
54
            <el-input v-model="queryConfig.request" placeholder="请选择请求" />
陈嘉新 authored
55
56
57
58
          </el-form-item>
        </el-col>
        <el-col :span="3.5">
          <el-form-item label="回复:" prop="">
陈嘉新 authored
59
60
61
62
            <el-input
              v-model="queryConfig.response"
              placeholder="请选择请求回复"
            />
陈嘉新 authored
63
64
65
66
          </el-form-item>
        </el-col>
        <el-col :span="3.5">
          <el-form-item label="开始时间:" prop="">
陈嘉新 authored
67
68
69
70
71
            <el-date-picker
              v-model="form.startTime"
              type="datetime"
              placeholder="选择日期时间"
            />
陈嘉新 authored
72
73
74
75
          </el-form-item>
        </el-col>
        <el-col :span="4">
          <el-form-item label="结束时间:" prop="">
陈嘉新 authored
76
77
78
79
80
            <el-date-picker
              v-model="form.endTime"
              type="datetime"
              placeholder="选择日期时间"
            />
陈嘉新 authored
81
82
83
84
85
86
87
88
89
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="" prop="">
            <el-button
              icon="el-icon-search"
              class="T1"
              @click="btnAction('queryConfig')"
              type="primary"
陈嘉新 authored
90
              size="small"
陈嘉新 authored
91
92
              >查询</el-button
            >
陈嘉新 authored
93
94
95
            <el-button class="T1" size="small" @click="details()"
              >查询情况</el-button
            >
陈嘉新 authored
96
97
98
99
100
            <el-button
              class="T1"
              size="small"
              icon="el-icon-download"
              @click="ExportList()"
陈嘉新 authored
101
              >导出</el-button
陈嘉新 authored
102
            >
陈嘉新 authored
103
104
105
106
          </el-form-item>
        </el-col>
      </el-row>
    </el-form>
陈嘉新 authored
107
    <div class="table">
陈嘉新 authored
108
109
      <el-table
        :data="tableData"
陈嘉新 authored
110
111
112
        border
        stripe
        :height="TableHeight"
113
        @selection-change="handleSelectionChange"
陈嘉新 authored
114
        :header-cell-style="{ color: '#000000' }"
陈嘉新 authored
115
      >
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
        <el-table-column
          type="selection"
          align="center"
          width="55"
        ></el-table-column>
        <el-table-column prop="id" label="内置ID" width="100">
        </el-table-column>
        <el-table-column
          prop="interfaceName"
          label="接口名"
          width="180"
          :show-overflow-tooltip="true"
        >
        </el-table-column>
        <el-table-column
          prop="url"
          width="180"
          label="URL"
          :show-overflow-tooltip="true"
        >
        </el-table-column>
        <el-table-column prop="method" label="请求方式"> </el-table-column>
        <el-table-column prop="totalMilliseconds" label="耗时">
陈嘉新 authored
139
        </el-table-column>
140
141
142
143
144
145
146
        <el-table-column prop="request" label="请求"> </el-table-column>
        <el-table-column
          prop="response"
          label="回复"
          width="200"
          :show-overflow-tooltip="true"
        >
陈嘉新 authored
147
        </el-table-column>
148
149
150
151
152
        <el-table-column prop="flag" label="标志"> </el-table-column>
        <el-table-column prop="requestIp" label="请求者IP"> </el-table-column>
        <el-table-column prop="remark" label="备注"> </el-table-column>
        <el-table-column prop="created" label="开始时间"> </el-table-column>
        <el-table-column prop="createdBy" label="创建人"> </el-table-column>
陈嘉新 authored
153
154
155
      </el-table>
      <div class="pagination-container">
        <el-pagination
陈嘉新 authored
156
157
158
159
          style="margin-top: 15px"
          align="center"
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
陈嘉新 authored
160
          :current-page="queryConfig.currentPage"
陈嘉新 authored
161
          :page-sizes="[20, 50, 100]"
陈嘉新 authored
162
          :page-size="queryConfig.pageSize"
陈嘉新 authored
163
          layout="total, sizes, prev, pager, next, jumper"
陈嘉新 authored
164
          :total="total"
陈嘉新 authored
165
        />
陈嘉新 authored
166
167
      </div>
    </div>
168
    <el-dialog title="接口日志详情" :visible.sync="dialogFormVisible">
陈嘉新 authored
169
      <div class="container" v-for="(item, index) in detailsData" :key="index">
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
        <div class="box">
          <div class="inner-left">内部id:</div>
          <div class="inner-right">{{ item.id }}</div>
        </div>
        <div class="box">
          <div class="inner-left">接口名:</div>
          <div class="inner-right">{{ item.interfaceName }}</div>
        </div>
        <div class="box">
          <div class="inner-left">耗时:</div>
          <div class="inner-right">{{ item.totalMilliseconds }}</div>
        </div>
        <div class="box">
          <div class="inner-left">标志:</div>
          <div class="inner-right">{{ item.flag }}</div>
        </div>
        <div class="box">
          <div class="inner-left">开始时间:</div>
          <div class="inner-right">{{ item.created }}</div>
        </div>
        <div class="box">
          <div class="inner-left">请求者IP:</div>
          <div class="inner-right">{{ item.requestIp }}</div>
        </div>
        <div class="box1">
          <div class="inner-left">请求:</div>
          <div class="inner-right">
            <el-input
              type="textarea"
              :autosize="{ minRows: 2, maxRows: 4 }"
              placeholder="请输入内容"
              v-model="item.request"
            />
          </div>
        </div>
        <div class="box1">
          <div class="inner-left">回复:</div>
          <div class="inner-right">
            <el-input
              type="textarea"
              :autosize="{ minRows: 2, maxRows: 4 }"
              placeholder="请输入内容"
              v-model="item.response"
            />
          </div>
        </div>
        <div class="box1">
          <div class="inner-left">内容:</div>
          <div class="inner-right">
            <el-input
              type="textarea"
              :autosize="{ minRows: 2, maxRows: 4 }"
              placeholder="请输入内容"
              v-model="item.content"
            />
          </div>
        </div>
        <div class="box1">
          <div class="inner-left">备注:</div>
          <div class="inner-right">
            <el-input
              type="textarea"
              :autosize="{ minRows: 2, maxRows: 4 }"
              placeholder="请输入内容"
              v-model="item.remark"
            />
          </div>
        </div>
      </div>
      <div slot="footer" class="dialog-footer">
        <el-button @click="dialogFormVisible = false">取 消</el-button>
      </div>
    </el-dialog>
陈嘉新 authored
243
244
  </div>
</template>
陈嘉新 authored
245
陈嘉新 authored
246
<script>
247
248
249
import {
  GetDictWithDetailsLangs,
  GetInterfaceLog,
陈嘉新 authored
250
  GetInterfaceLogById,
251
} from "@/api/logManage/index";
陈嘉新 authored
252
import downloadFile from "@/api/user";
陈嘉新 authored
253
陈嘉新 authored
254
255
256
export default {
  data() {
    return {
257
      tableData: [],
陈嘉新 authored
258
259
260
      queryConfig: {
        currentPage: 1,
        pageSize: 20,
261
262
263
264
265
266
267
        interfaceName: "",
        flag: "",
        url: "",
        method: "",
        totalMilliseconds: 0,
        request: "",
        response: "",
陈嘉新 authored
268
      },
陈嘉新 authored
269
270
271
272
273
274
      rules: {
        totalMilliseconds: [
          { required: true, message: "该字段不能为空", trigger: "blur" },
          { validator: this.validateNumber, trigger: "blur" },
        ],
      },
陈嘉新 authored
275
276
277
278
279
280
281
      total: 0,
      form: {
        startTime: this.$moment()
          .subtract(3, "days")
          .format("YYYY-MM-DD 00:00:00"),
        endTime: this.$moment().add(1, "days").format("YYYY-MM-DD 23:59:59"),
      },
282
283
284
285
286
287
288
289
      optionsFlag: [
        {
          value: "",
          label: "全部",
        },
      ],
      dialogFormVisible: false,
      multipleSelection: [],
陈嘉新 authored
290
      detailsData: [],
陈嘉新 authored
291
      export: "http://localhost:5221/api/Log/ExportInterfaceLog",
陈嘉新 authored
292
293
    };
  },
294
295
296
297
  created() {
    this.getFlag("LogLevelFlag");
    this.getTableList();
  },
陈嘉新 authored
298
299
  computed: {
    TableHeight() {
陈嘉新 authored
300
      return `calc(100vh - 390px )`;
陈嘉新 authored
301
302
    },
  },
303
  methods: {
陈嘉新 authored
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
    //查询按钮
    btnAction(queryConfig) {
      this.$refs[queryConfig].validate((valid) => {
        if (valid) {
          this.getTableList();
        } else {
          return false;
        }
      });
    },
    //类型校验
    validateNumber(rule, value, callback) {
      if (value !== "" && isNaN(value)) {
        return callback(new Error("请输入有效的数字"));
      }
      callback(); // 验证通过
320
321
322
323
324
325
326
327
328
    },
    getFlag(data) {
      let params = { Code: data };
      GetDictWithDetailsLangs(params).then((response) => {
        response.data.dictDetails.forEach((x) => {
          this.optionsFlag.push({ value: x.code, label: x.name });
        });
      });
    },
陈嘉新 authored
329
    //表格数据
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
    getTableList() {
      const params = {
        pageNumber: this.queryConfig.currentPage,
        perPageCount: this.queryConfig.pageSize,
        queryConfig: {
          interfaceName: this.queryConfig.interfaceName,
          url: this.queryConfig.url,
          request: this.queryConfig.request,
          response: this.queryConfig.response,
          method: this.queryConfig.method,
          flag: this.queryConfig.flag,
          content: "",
          totalMilliseconds: this.queryConfig.totalMilliseconds,
          remark: "",
          begin: this.form.startTime,
          end: this.form.endTime,
        },
      };
      this.listLoading = true;
      GetInterfaceLog(params).then((response) => {
        this.total = response.data.totalCount;
        this.tableData = response.data.data;
        this.listLoading = false;
      });
    },
    //   详情
    details() {
      if (this.multipleSelection.length == 0) {
        this.$alert("请选择一条数据!", "标题名称", {
          confirmButtonText: "确定",
        });
      } else {
陈嘉新 authored
362
363
364
365
366
367
368
        this.detailsData = [];
        let params = {
          id: this.multipleSelection[0].id,
        };
        GetInterfaceLogById(params).then((response) => {
          this.detailsData.push(response.data);
        });
369
370
371
        this.dialogFormVisible = true;
      }
    },
陈嘉新 authored
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
    //导出按钮
    ExportList() {
      const params = {
        pageNumber: this.queryConfig.currentPage,
        perPageCount: this.queryConfig.pageSize,
        queryConfig: {
          interfaceName: this.queryConfig.interfaceName,
          url: this.queryConfig.url,
          request: this.queryConfig.request,
          response: this.queryConfig.response,
          method: this.queryConfig.method,
          flag: this.queryConfig.flag,
          content: "",
          totalMilliseconds: this.queryConfig.totalMilliseconds,
          remark: "",
          begin: this.form.startTime,
          end: this.form.endTime,
        },
      };
      let text = "接口日志数据.xlsx";
      // 调用下载函数
      downloadFile(this.export, params, text);
    },
395
396
397
398
399
    //获取表格行数据
    handleSelectionChange(val) {
      this.multipleSelection = val;
    },
    //分页
陈嘉新 authored
400
401
402
403
404
405
406
407
    handleSizeChange(val) {
      this.queryConfig.pageSize = val;
      this.queryConfig.currentPage = 1;
      this.getTableList();
    },

    handleCurrentChange(val) {
      this.queryConfig.currentPage = val;
408
409
410
      this.getTableList();
    },
  },
陈嘉新 authored
411
412
};
</script>
陈嘉新 authored
413
414

<style>
陈嘉新 authored
415
416
417
418
419
420
421
422
423
424
.interfacel {
  width: 100%;
}
.table {
  border: 1px solid #e5e9f2;
}
.pagination-container {
  text-align: center; /* 使分页组件靠右 */
  margin-top: 20px; /* 添加顶部间距 */
}
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
.container {
  width: 100%; /* 大 div 宽度 */
  display: flex; /* 使用 Flexbox 布局 */
  flex-wrap: wrap; /* 允许换行 */
  padding: 10px; /* 内边距 */
  box-sizing: border-box; /* 包含内边距在内 */
}
.box {
  width: 50%; /* 小 div 宽度为 50% */
  height: 50px; /* 小 div 高度 */
  margin: 5px 0; /* 上下外边距 */
  display: flex; /* 嵌套使用 Flexbox */
}
.box1 {
  width: 50%; /* 小 div 宽度为 50% */
  height: 100px; /* 小 div 高度 */
  margin: 5px 0; /* 上下外边距 */
  display: flex; /* 嵌套使用 Flexbox */
}
.inner-left {
  width: 40%; /* 内部左侧 div 宽度为 50% */
  height: 100%; /* 高度为 100% */
  display: flex; /* 使用 Flexbox */
  justify-content: flex-end; /* 内容靠右 */
  align-items: center; /* 垂直居中 */
  padding-right: 5px; /* 右侧内边距 */
}
.inner-right {
  width: 50%; /* 内部右侧 div 宽度为 50% */
  height: 100%; /* 高度为 100% */
  display: flex; /* 使用 Flexbox */
  justify-content: flex-start; /* 内容靠左 */
  align-items: center; /* 垂直居中 */
  padding-left: 5px; /* 左侧内边距 */
}
陈嘉新 authored
460
461
462
463

.demo-ruleForm {
  margin-top: 20px;
}
陈嘉新 authored
464
</style>