Blame view

src/views/system/apilog/index.vue 16.1 KB
yuanshuhui authored
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
<template>
  <div class="app-container">
    <el-form
      :model="queryParams"
      ref="queryForm"
      :inline="true"
      v-show="showSearch"
      label-width="100px"
    >
      <el-form-item label="API" prop="apiName">
        <el-input
          v-model="queryParams.apiName"
          placeholder="请输入API"
          clearable
          size="small"
          style="width: 240px"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="请求方" prop="requestFrom">
        <el-input
          v-model="queryParams.requestFrom"
          placeholder="请输入请求方"
          clearable
          size="small"
          style="width: 240px"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="响应方" prop="responseBy">
        <el-input
          v-model="queryParams.responseBy"
          placeholder="请输入响应方"
          clearable
          size="small"
          style="width: 240px"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
yuanshuhui authored
40
      <el-form-item label="仓库" prop="status">
yuanshuhui authored
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
        <el-select
          v-model="queryParams.warehouseCode"
          placeholder="仓库"
          clearable
          size="small"
          style="width: 240px"
        >
          <el-option
            v-for="item in warehouseOptions"
            :key="item.code"
            :label="item.name"
            :value="item.code"
          />
        </el-select>
      </el-form-item>
yuanshuhui authored
56
      <el-form-item label="httpCode" prop="httpCode">
yuanshuhui authored
57
        <el-select
yuanshuhui authored
58
          v-model="queryParams.httpCode"
yuanshuhui authored
59
          placeholder="httpCode"
yuanshuhui authored
60
61
62
          clearable
          size="small"
          style="width: 240px"
yuanshuhui authored
63
        >
yuanshuhui authored
64
          <el-option
yuanshuhui authored
65
66
67
68
69
70
            v-for="dict in httpOptions"
            :key="dict.dictValue"
            :label="dict.dictLabel"
            :value="dict.dictValue"
          />
        </el-select>
yuanshuhui authored
71
72
      </el-form-item>
      <el-form-item label="retCode" prop="retCode">
yuanshuhui authored
73
        <el-select
yuanshuhui authored
74
          v-model="queryParams.retCode"
yuanshuhui authored
75
          placeholder="retCode"
yuanshuhui authored
76
77
78
          clearable
          size="small"
          style="width: 240px"
yuanshuhui authored
79
        >
yuanshuhui authored
80
          <el-option
yuanshuhui authored
81
82
83
84
85
86
            v-for="dict in retOptions"
            :key="dict.dictValue"
            :label="dict.dictLabel"
            :value="dict.dictValue"
          />
        </el-select>
yuanshuhui authored
87
      </el-form-item>
yuanshuhui authored
88
      <el-form-item label="异常" prop="hasException">
yuanshuhui authored
89
        <el-input
yuanshuhui authored
90
91
92
93
94
95
96
97
          v-model="queryParams.hasException"
          placeholder="请输入异常"
          clearable
          size="small"
          style="width: 240px"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
yuanshuhui authored
98
      <el-form-item label="响应时间>" prop="duration">
yuanshuhui authored
99
        <el-input
yuanshuhui authored
100
          v-model="queryParams.duration"
yuanshuhui authored
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
          placeholder="1000毫秒"
          clearable
          size="small"
          style="width: 240px"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="请求时间">
        <el-date-picker
          v-model="dateRange"
          size="small"
          style="width: 240px"
          value-format="yyyy-MM-dd"
          type="daterange"
          range-separator="-"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
        ></el-date-picker>
      </el-form-item>
      <el-form-item>
        <el-button
          type="cyan"
          icon="el-icon-search"
          size="mini"
          @click="handleQuery"
          >搜索</el-button
        >
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery"
          >重置</el-button
        >
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="warning"
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
fuxiaohan authored
141
          :loading="exportLoading"
yuanshuhui authored
142
143
144
145
146
147
          >导出</el-button
        >
      </el-col>
      <right-toolbar
        :showSearch.sync="showSearch"
        @queryTable="getList"
148
149
        :col-data="colData"
        @selectData="selectData"
yuanshuhui authored
150
151
152
      ></right-toolbar>
    </el-row>
153
    <el-table v-loading="loading" :data="list" ref="table">
yuanshuhui authored
154
      <el-table-column
yuanshuhui authored
155
        fixed="left"
yuanshuhui authored
156
157
158
        label="操作"
        align="center"
        class-name="small-padding fixed-width"
159
        v-if="colData[0].istrue"
yuanshuhui authored
160
161
162
163
164
165
166
167
168
169
170
      >
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-view"
            @click="handleView(scope.row, scope.index)"
            >详细</el-button
          >
        </template>
      </el-table-column>
yuanshuhui authored
171
      <el-table-column
yuanshuhui authored
172
173
174
175
176
177
        label="id"
        width="55"
        align="center"
        prop="id"
        v-if="colData[1].istrue"
      />
yuanshuhui authored
178
      <el-table-column
yuanshuhui authored
179
180
181
182
183
184
185
186
187
188
189
        label="仓库"
        align="center"
        prop="warehouseCode"
        v-if="colData[2].istrue"
        width="150"
        :show-overflow-tooltip="true"
      >
        <template slot-scope="scope">
          {{ warehouseCodeFormat(scope.row, scope.column) }}
        </template>
      </el-table-column>
yuanshuhui authored
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
      <el-table-column
        label="from"
        align="center"
        prop="requestFrom"
        v-if="colData[3].istrue"
      />
      <el-table-column
        label="API"
        align="center"
        prop="apiName"
        v-if="colData[4].istrue"
        width="130"
      />
      <el-table-column
        label="to"
        align="center"
        prop="responseBy"
        v-if="colData[5].istrue"
      />
      <el-table-column
        label="http"
        align="center"
        prop="httpCode"
        v-if="colData[6].istrue"
      >
yuanshuhui authored
215
216
217
218
219
220
221
        <template slot-scope="scope">
          <span
            :style="{ color: scope.row.httpCode == 200 ? 'green' : 'red' }"
            >{{ scope.row.httpCode }}</span
          >
        </template>
      </el-table-column>
yuanshuhui authored
222
223
224
225
226
227
      <el-table-column
        label="ret"
        align="center"
        prop="retCode"
        v-if="colData[7].istrue"
      >
yuanshuhui authored
228
229
230
231
232
233
234
235
236
237
238
        <template slot-scope="scope">
          <span
            :style="{ color: scope.row.retCode == 200 ? 'green' : 'red' }"
            >{{ scope.row.retCode }}</span
          >
        </template>
      </el-table-column>
      <el-table-column
        label="请求时间"
        align="center"
        prop="requestTime"
yuanshuhui authored
239
        width="160"
yuanshuhui authored
240
        v-if="colData[8].istrue"
yuanshuhui authored
241
242
243
244
245
      >
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.requestTime) }}</span>
        </template>
      </el-table-column>
yuanshuhui authored
246
247
248
249
250
251
      <el-table-column
        label="耗时"
        align="center"
        prop="duration"
        v-if="colData[9].istrue"
      >
yuanshuhui authored
252
253
254
255
256
257
258
259
260
261
262
        <template slot-scope="scope">
          <span :style="{ color: scope.row.duration > 1000 ? 'red' : '' }">{{
            scope.row.duration
          }}</span>
        </template>
      </el-table-column>
      <el-table-column
        label="请求内容"
        align="center"
        prop="requestBody"
        :show-overflow-tooltip="true"
yuanshuhui authored
263
        v-if="colData[10].istrue"
yuanshuhui authored
264
        width="350"
yuanshuhui authored
265
266
267
268
269
270
      />
      <el-table-column
        label="响应内容"
        align="center"
        prop="responseBody"
        :show-overflow-tooltip="true"
yuanshuhui authored
271
        v-if="colData[11].istrue"
yuanshuhui authored
272
        width="350"
yuanshuhui authored
273
274
275
276
277
278
      />
      <el-table-column
        label="异常信息"
        align="center"
        prop="exceptionMsg"
        :show-overflow-tooltip="true"
yuanshuhui authored
279
        v-if="colData[12].istrue"
yuanshuhui authored
280
281
282
283
284
      >
        <template slot-scope="scope">
          <span style="color: red">{{ scope.row.exceptionMsg }}</span>
        </template>
      </el-table-column>
yuanshuhui authored
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
347
348
349
350
351
352
353
354
355
356
357
358
    </el-table>

    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 接口日志详细 -->
    <el-dialog
      title="接口调用日志详细"
      :visible.sync="open"
      width="700px"
      append-to-body
    >
      <el-form ref="form" :model="form" label-width="100px" size="mini">
        <el-row>
          <el-col :span="12">
            <el-form-item label="ID:">{{ form.id }}</el-form-item>
            <el-form-item label="接口名:">{{ form.apiName }}</el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="请求方ip:">{{ form.ip }}</el-form-item>
            <el-form-item label="调用方向:"
              >{{ form.requestFrom }} -> {{ form.responseBy }}</el-form-item
            >
          </el-col>
          <el-col :span="12">
            <el-form-item label="请求方式:">{{ form.apiMethod }}</el-form-item>
            <el-form-item label="接口地址:">{{ form.url }}</el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="请求时间:">{{
              parseTime(form.requestTime)
            }}</el-form-item>
            <el-form-item
              label="耗时:"
              :class="[form.duration > 1000 ? 'field-red' : '']"
              ><span :style="{ color: form.duration > 1000 ? 'red' : '' }">{{
                form.duration
              }}</span></el-form-item
            >
          </el-col>
          <el-col :span="12">
            <el-form-item
              label="HttpCode:"
              :class="[form.httpCode == 200 ? 'field-green' : 'field-red']"
            >
              <span
                :style="{ color: form.httpCode == 200 ? 'green' : 'red' }"
                >{{ form.httpCode }}</span
              ></el-form-item
            >
            <el-form-item
              label="RetCode:"
              :class="[form.RetCode == 200 ? 'field-green' : 'field-red']"
              ><span
                :style="{ color: form.RetCode == 200 ? 'green' : 'red' }"
                >{{ form.retCode }}</span
              ></el-form-item
            >
          </el-col>
          <el-col :span="18">
            <el-form-item label="请求头:"
              >{{ form.requestHeader }}
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item>
              <el-button
                class="request-header"
                :data-clipboard-text="form.requestHeader"
yuanshuhui authored
359
                type="info"
yuanshuhui authored
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
                size="mini"
                @click="copy('.request-header')"
                >复制</el-button
              ></el-form-item
            >
          </el-col>
          <el-col :span="24">
            <el-form-item label="响应头:">{{
              form.responseHeader
            }}</el-form-item>
          </el-col>
          <el-col :span="18">
            <el-form-item label="请求内容:">{{
              form.requestBody
            }}</el-form-item>
          </el-col>
          <el-col :span="6">
yuanshuhui authored
377
            <el-form-item>
yuanshuhui authored
378
379
380
              <el-button
                class="request-body"
                :data-clipboard-text="form.requestBody"
yuanshuhui authored
381
                type="info"
yuanshuhui authored
382
383
384
385
386
387
388
389
390
391
392
393
                size="mini"
                @click="copy('.request-body')"
                >复制</el-button
              ></el-form-item
            >
          </el-col>
          <el-col :span="24">
            <el-form-item label="响应内容:">{{
              form.responseBody
            }}</el-form-item>
          </el-col>
          <el-col :span="18">
yuanshuhui authored
394
395
396
397
398
            <el-form-item
              label="异常信息:"
              :class="[form.exceptionMsg ? 'field-red' : '']"
              >{{ form.exceptionMsg }}</el-form-item
            >
yuanshuhui authored
399
400
          </el-col>
          <el-col :span="6">
yuanshuhui authored
401
            <el-form-item>
yuanshuhui authored
402
403
404
              <el-button
                class="exception-msg"
                :data-clipboard-text="form.exceptionMsg"
yuanshuhui authored
405
                type="info"
yuanshuhui authored
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
                size="mini"
                @click="copy('.exception-msg')"
                >复制</el-button
              ></el-form-item
            >
          </el-col>
        </el-row>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="open = false">关 闭</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
yuanshuhui authored
422
423
import { listApi, getApi } from "@/api/system/apilog";
import { getWarehouseByUserCode } from "@/api/system/warehouse";
yuanshuhui authored
424
425
426
427
428
import Clipboard from "clipboard";
export default {
  name: "Operlog",
  data() {
    return {
fuxiaohan authored
429
430
      // 导出加载状态
      exportLoading: false,
yuanshuhui authored
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
      // 遮罩层
      loading: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 表格数据
      list: [],
      // 是否显示弹出层
      open: false,
      // 日期范围
      dateRange: [],
      // 表单参数
      form: {},
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        apiName: undefined,
        requestFrom: undefined,
        responseBy: undefined,
yuanshuhui authored
452
453
        duration: undefined,
        warehouseCode: undefined,
yuanshuhui authored
454
455
456
457
        httpCode: undefined,
        retCode: undefined,
        hasException: undefined,
      },
yuanshuhui authored
458
      // 仓库下拉数据
yuanshuhui authored
459
      warehouseOptions: [],
yuanshuhui authored
460
      // httpCode数据字典
yuanshuhui authored
461
462
463
      httpOptions: [],
      // retCode数据字典
      retOptions: [],
464
465
466
      // istrue属性存放列的状态
      colData: [
        { title: "操作", istrue: true, disabled: true },
yuanshuhui authored
467
        { title: "id", istrue: false },
lector authored
468
        { title: "仓库", istrue: false },
469
470
471
472
473
474
475
476
477
478
479
        { title: "from", istrue: true },
        { title: "API", istrue: true },
        { title: "to", istrue: true },
        { title: "http", istrue: true },
        { title: "ret", istrue: true },
        { title: "请求时间", istrue: true },
        { title: "耗时", istrue: true },
        { title: "请求内容", istrue: true },
        { title: "响应内容", istrue: true },
        { title: "异常信息", istrue: true },
      ],
yuanshuhui authored
480
481
482
483
    };
  },
  created() {
    this.getList();
yuanshuhui authored
484
485
486
    this.getDicts("httpCode").then((response) => {
      this.httpOptions = response.data;
    });
yuanshuhui authored
487
    this.getDicts("retCode").then((response) => {
yuanshuhui authored
488
      this.retOptions = response.data;
yuanshuhui authored
489
    });
yuanshuhui authored
490
491
    getWarehouseByUserCode(this.$store.getters.name).then((response) => {
      this.warehouseOptions = response.data;
yuanshuhui authored
492
493
    });
  },
494
495
496
497
498
  beforeUpdate() {
    this.$nextTick(() => {
      this.$refs["table"].doLayout();
    });
  },
yuanshuhui authored
499
  methods: {
yuanshuhui authored
500
    /** 查询接口日志 */
yuanshuhui authored
501
502
    getList() {
      this.loading = true;
yuanshuhui authored
503
      listApi(this.addDateRange(this.queryParams, this.dateRange)).then(
yuanshuhui authored
504
505
506
507
508
509
510
        (response) => {
          this.list = response.rows;
          this.total = response.total;
          this.loading = false;
        }
      );
    },
yuanshuhui authored
511
    // 仓库字典翻译
yuanshuhui authored
512
513
514
    warehouseCodeFormat(row, column) {
      return this.selectCommonLabel(this.warehouseOptions, row.warehouseCode);
    },
yuanshuhui authored
515
    // 复制
yuanshuhui authored
516
    copy(value) {
yuanshuhui authored
517
518
519
520
521
      const clipboard = new Clipboard(value);
      clipboard.on("success", (e) => {
        // 成功提示
        this.msgSuccess("复制成功");
        // 释放内存
yuanshuhui authored
522
        e.clearSelection();
yuanshuhui authored
523
524
525
526
527
528
529
      });
      // 浏览器不支持
      clipboard.on("error", (e) => {
        // 释放内存
        clipboard.destroy();
      });
    },
yuanshuhui authored
530
yuanshuhui authored
531
532
533
534
535
536
537
538
539
540
541
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.dateRange = [];
      this.resetForm("queryForm");
      this.handleQuery();
    },
yuanshuhui authored
542
yuanshuhui authored
543
544
545
    /** 详细按钮操作 */
    handleView(row) {
      this.open = true;
yuanshuhui authored
546
547
548
549

      getApi(row.id).then((response) => {
        this.form = response.data;
      });
yuanshuhui authored
550
    },
yuanshuhui authored
551
yuanshuhui authored
552
553
    /** 导出按钮操作 */
    handleExport() {
fuxiaohan authored
554
      this.exportLoading = true;
yuanshuhui authored
555
      this.download(
yuanshuhui authored
556
        "system/apiLog/export",
yuanshuhui authored
557
558
559
        {
          ...this.queryParams,
        },
fuxiaohan authored
560
        `接口日志_${this.formatTime(new Date(),'{y}-{m}-{d}')}.xlsx`
yuanshuhui authored
561
562
      );
    },
563
564
565
566
567
568
569
570
571
572
573
574
    /** 表格切换字段显示操作 */
    selectData(val) {
      if (val) {
        this.colData.filter((i) => {
          if (val.indexOf(i.title) !== -1) {
            i.istrue = true;
          } else {
            i.istrue = false;
          }
        });
      }
    },
yuanshuhui authored
575
576
577
578
579
580
581
582
583
584
585
  },
};
</script>

<style lang="scss">
.field-green .el-form-item__label {
  color: green;
}
.field-red .el-form-item__label {
  color: red;
}
586
</style>