Blame view

src/views/system/apilog/index.vue 15.4 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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
        <el-form-item label="仓库" prop="status">
        <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
64
65
66
67
68
69
70
        >
         <el-option
            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
80
81
82
83
84
85
86
        >
         <el-option
            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
98
99
          v-model="queryParams.hasException"
          placeholder="请输入异常"
          clearable
          size="small"
          style="width: 240px"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="响应时间>" prop="paramDuration">
        <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
141
142
143
144
145
146
          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"
          >导出</el-button
        >
      </el-col>
      <right-toolbar
        :showSearch.sync="showSearch"
        @queryTable="getList"
147
148
        :col-data="colData"
        @selectData="selectData"
yuanshuhui authored
149
150
151
      ></right-toolbar>
    </el-row>
152
    <el-table v-loading="loading" :data="list" ref="table">
yuanshuhui authored
153
yuanshuhui authored
154
155
156
157
      <el-table-column
        label="操作"
        align="center"
        class-name="small-padding fixed-width"
158
        v-if="colData[0].istrue"
yuanshuhui authored
159
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
172
173
174
175
176
177
178
179
180
181
       <el-table-column
        label="id"
        width="55"
        align="center"
        prop="id"
        v-if="colData[1].istrue"
      />
      <el-table-column label="from" align="center" prop="requestFrom" v-if="colData[2].istrue" />
      <el-table-column label="API" align="center" prop="apiName" v-if="colData[3].istrue" width="130" />
      <el-table-column label="to" align="center" prop="responseBy" v-if="colData[4].istrue" />
      <el-table-column label="http" align="center" prop="httpCode" v-if="colData[5].istrue">
yuanshuhui authored
182
183
184
185
186
187
188
        <template slot-scope="scope">
          <span
            :style="{ color: scope.row.httpCode == 200 ? 'green' : 'red' }"
            >{{ scope.row.httpCode }}</span
          >
        </template>
      </el-table-column>
yuanshuhui authored
189
      <el-table-column label="ret" align="center" prop="retCode" v-if="colData[6].istrue">
yuanshuhui authored
190
191
192
193
194
195
196
197
198
199
200
        <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
201
202
        width="160"
        v-if="colData[7].istrue"
yuanshuhui authored
203
204
205
206
207
      >
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.requestTime) }}</span>
        </template>
      </el-table-column>
yuanshuhui authored
208
      <el-table-column label="耗时" align="center" prop="duration" v-if="colData[8].istrue">
yuanshuhui authored
209
210
211
212
213
214
215
216
217
218
219
        <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
220
221
        v-if="colData[9].istrue"
        width="350"
yuanshuhui authored
222
223
224
225
226
227
      />
      <el-table-column
        label="响应内容"
        align="center"
        prop="responseBody"
        :show-overflow-tooltip="true"
yuanshuhui authored
228
229
        v-if="colData[10].istrue"
        width="350"
yuanshuhui authored
230
231
232
233
234
235
      />
      <el-table-column
        label="异常信息"
        align="center"
        prop="exceptionMsg"
        :show-overflow-tooltip="true"
yuanshuhui authored
236
        v-if="colData[11].istrue"
yuanshuhui authored
237
238
239
240
241
      >
        <template slot-scope="scope">
          <span style="color: red">{{ scope.row.exceptionMsg }}</span>
        </template>
      </el-table-column>
yuanshuhui authored
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
    </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
316
                type="info"
yuanshuhui authored
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
                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
334
            <el-form-item>
yuanshuhui authored
335
336
337
              <el-button
                class="request-body"
                :data-clipboard-text="form.requestBody"
yuanshuhui authored
338
                type="info"
yuanshuhui authored
339
340
341
342
343
344
345
346
347
348
349
350
                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
351
352
353
354
355
            <el-form-item
              label="异常信息:"
              :class="[form.exceptionMsg ? 'field-red' : '']"
              >{{ form.exceptionMsg }}</el-form-item
            >
yuanshuhui authored
356
357
          </el-col>
          <el-col :span="6">
yuanshuhui authored
358
            <el-form-item>
yuanshuhui authored
359
360
361
              <el-button
                class="exception-msg"
                :data-clipboard-text="form.exceptionMsg"
yuanshuhui authored
362
                type="info"
yuanshuhui authored
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
                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
379
380
import { listApi, getApi } from "@/api/system/apilog";
import { getWarehouseByUserCode } from "@/api/system/warehouse";
yuanshuhui authored
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
import Clipboard from "clipboard";
export default {
  name: "Operlog",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 表格数据
      list: [],
      // 是否显示弹出层
      open: false,
      // 日期范围
      dateRange: [],
      // 表单参数
      form: {},
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        apiName: undefined,
        requestFrom: undefined,
        responseBy: undefined,
yuanshuhui authored
407
408
        duration: undefined,
        warehouseCode: undefined,
yuanshuhui authored
409
410
411
412
        httpCode: undefined,
        retCode: undefined,
        hasException: undefined,
      },
yuanshuhui authored
413
414
415
416
417
418
      // 仓库下拉数据
      warehouseOptions:[],
      // httpCode数据字典
      httpOptions:[],
       // retCode数据字典
      retOptions:[],
419
420
421
      // istrue属性存放列的状态
      colData: [
        { title: "操作", istrue: true, disabled: true },
yuanshuhui authored
422
        { title: "id", istrue: false },
423
424
425
426
427
428
429
430
431
432
433
        { 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
434
435
436
437
    };
  },
  created() {
    this.getList();
yuanshuhui authored
438
439
440
441
442
    this.getDicts("httpCode").then((response) => {
      this.httpOptions = response.data;
    });
      this.getDicts("retCode").then((response) => {
      this.retOptions = response.data;
yuanshuhui authored
443
    });
yuanshuhui authored
444
445
446
     getWarehouseByUserCode(this.$store.getters.name).then((response) => {
      console.log(response)
        this.warehouseOptions =  response.data
yuanshuhui authored
447
448
    });
  },
449
450
451
452
453
  beforeUpdate() {
    this.$nextTick(() => {
      this.$refs["table"].doLayout();
    });
  },
yuanshuhui authored
454
  methods: {
yuanshuhui authored
455
    /** 查询接口日志 */
yuanshuhui authored
456
457
    getList() {
      this.loading = true;
yuanshuhui authored
458
      listApi(this.addDateRange(this.queryParams, this.dateRange)).then(
yuanshuhui authored
459
        (response) => {
yuanshuhui authored
460
          console.log(response)
yuanshuhui authored
461
462
463
464
465
466
467
          this.list = response.rows;
          this.total = response.total;
          this.loading = false;
        }
      );
    },
    // 复制
yuanshuhui authored
468
    copy(value) {
yuanshuhui authored
469
470
471
472
473
      const clipboard = new Clipboard(value);
      clipboard.on("success", (e) => {
        // 成功提示
        this.msgSuccess("复制成功");
        // 释放内存
yuanshuhui authored
474
        e.clearSelection();
yuanshuhui authored
475
476
477
478
479
480
481
      });
      // 浏览器不支持
      clipboard.on("error", (e) => {
        // 释放内存
        clipboard.destroy();
      });
    },
yuanshuhui authored
482
yuanshuhui authored
483
484
485
486
487
488
489
490
491
492
493
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.dateRange = [];
      this.resetForm("queryForm");
      this.handleQuery();
    },
yuanshuhui authored
494
yuanshuhui authored
495
496
497
    /** 详细按钮操作 */
    handleView(row) {
      this.open = true;
yuanshuhui authored
498
499
500
501
502
503
504
505
506

       getApi(row.id).then(
        (response) => {
          console.log(response)
          this.form  = response.data;


        }
      );
yuanshuhui authored
507
    },
yuanshuhui authored
508
yuanshuhui authored
509
510
511
    /** 导出按钮操作 */
    handleExport() {
      this.download(
yuanshuhui authored
512
        "system/apiLog/export",
yuanshuhui authored
513
514
515
516
517
518
        {
          ...this.queryParams,
        },
        `apilog_${new Date().getTime()}.xlsx`
      );
    },
519
520
521
522
523
524
525
526
527
528
529
530
531
    /** 表格切换字段显示操作 */
    selectData(val) {
      if (val) {
        this.colData.filter((i) => {
          if (val.indexOf(i.title) !== -1) {
            i.istrue = true;
          } else {
            i.istrue = false;
          }
        });
      }
    },
yuanshuhui authored
532
533
534
535
536
537
538
539
540
541
542
  },
};
</script>

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