index.vue 8.71 KB
Newer Older
sunhongwei's avatar
sunhongwei committed
1 2 3 4 5
<template>
  <div class="app-container">

    <!-- 搜索工作栏 -->
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
Marcus's avatar
Marcus committed
6 7
      <el-form-item :label="$t('用户编号')" prop="userId">
        <el-input v-model="queryParams.userId" :placeholder="$t('请输入用户编号')" clearable @keyup.enter.native="handleQuery"/>
sunhongwei's avatar
sunhongwei committed
8
      </el-form-item>
Marcus's avatar
Marcus committed
9 10
      <el-form-item :label="$t('用户类型')" prop="userType">
        <el-select v-model="queryParams.userType" :placeholder="$t('请选择用户类型')" clearable>
sunhongwei's avatar
sunhongwei committed
11 12 13 14
          <el-option v-for="dict in this.getDictDatas(DICT_TYPE.USER_TYPE)"
                     :key="dict.value" :label="dict.label" :value="dict.value"/>
        </el-select>
      </el-form-item>
Marcus's avatar
Marcus committed
15 16
      <el-form-item :label="$t('应用名')" prop="applicationName">
        <el-input v-model="queryParams.applicationName" :placeholder="$t('请输入应用名')" clearable @keyup.enter.native="handleQuery"/>
sunhongwei's avatar
sunhongwei committed
17
      </el-form-item>
Marcus's avatar
Marcus committed
18 19
      <el-form-item :label="$t('请求地址')" prop="requestUrl">
        <el-input v-model="queryParams.requestUrl" :placeholder="$t('请输入请求地址')" clearable @keyup.enter.native="handleQuery"/>
sunhongwei's avatar
sunhongwei committed
20
      </el-form-item>
Marcus's avatar
Marcus committed
21
      <el-form-item :label="$t('请求时间')">
邓春圆's avatar
邓春圆 committed
22 23
        <el-date-picker v-model="dateRangeBeginTime" style="width: 240px" value-format="yyyy-MM-dd HH:mm:ss"
                        type="datetimerange" range-separator="-" start-placeholder="开始日期" end-placeholder="结束日期" />
sunhongwei's avatar
sunhongwei committed
24
      </el-form-item>
Marcus's avatar
Marcus committed
25 26
      <el-form-item :label="$t('执行时长')" prop="duration">
        <el-input v-model="queryParams.duration" :placeholder="$t('请输入执行时长')" clearable @keyup.enter.native="handleQuery"/>
sunhongwei's avatar
sunhongwei committed
27
      </el-form-item>
Marcus's avatar
Marcus committed
28 29
      <el-form-item :label="$t('结果码')" prop="resultCode">
        <el-input v-model="queryParams.resultCode" :placeholder="$t('请输入结果码')" clearable @keyup.enter.native="handleQuery"/>
sunhongwei's avatar
sunhongwei committed
30 31
      </el-form-item>
      <el-form-item>
Marcus's avatar
Marcus committed
32 33
        <el-button type="primary" icon="el-icon-search" @click="handleQuery">{{ $t('搜索') }}</el-button>
        <el-button icon="el-icon-refresh" @click="resetQuery">{{ $t('重置') }}</el-button>
sunhongwei's avatar
sunhongwei committed
34 35 36 37 38 39 40
      </el-form-item>
    </el-form>

    <!-- 操作工具栏 -->
    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button type="warning" plain icon="el-icon-download" size="mini" :loading="exportLoading" @click="handleExport"
Marcus's avatar
Marcus committed
41
                   v-hasPermi="['infra:api-access-log:export']">{{ $t('导出') }}</el-button>
sunhongwei's avatar
sunhongwei committed
42 43 44 45 46 47
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <!-- 列表 -->
    <el-table v-loading="loading" :data="list">
Marcus's avatar
Marcus committed
48 49 50
      <el-table-column :label="$t('日志编号')" align="center" prop="id" />
      <el-table-column :label="$t('用户编号')" align="center" prop="userId" />
      <el-table-column :label="$t('用户类型')" align="center" prop="userType">
sunhongwei's avatar
sunhongwei committed
51 52 53 54
        <template slot-scope="scope">
          <dict-tag :type="DICT_TYPE.USER_TYPE" :value="scope.row.userType"/>
        </template>
      </el-table-column>>
Marcus's avatar
Marcus committed
55 56 57 58
      <el-table-column :label="$t('应用名')" align="center" prop="applicationName" />
      <el-table-column :label="$t('请求方法名')" align="center" prop="requestMethod" />
      <el-table-column :label="$t('请求地址')" align="center" prop="requestUrl" width="250" />
      <el-table-column :label="$t('请求时间')" align="center" prop="beginTime" width="180">
sunhongwei's avatar
sunhongwei committed
59 60 61 62
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.beginTime) }}</span>
        </template>
      </el-table-column>
Marcus's avatar
Marcus committed
63
      <el-table-column :label="$t('执行时长')" align="center" prop="startTime">
sunhongwei's avatar
sunhongwei committed
64 65 66 67
        <template slot-scope="scope">
          <span>{{ scope.row.duration }}  ms</span>
        </template>
      </el-table-column>
Marcus's avatar
Marcus committed
68
      <el-table-column :label="$t('操作结果')" align="center" prop="status">
sunhongwei's avatar
sunhongwei committed
69 70 71 72
        <template slot-scope="scope">
          <span>{{ scope.row.resultCode === 0 ? '成功' : '失败(' + scope.row.resultMsg + ')' }}</span>
        </template>
      </el-table-column>
Marcus's avatar
Marcus committed
73
      <el-table-column :label="$t('操作')" align="center" class-name="small-padding fixed-width">
sunhongwei's avatar
sunhongwei committed
74 75
        <template slot-scope="scope">
          <el-button size="mini" type="text" icon="el-icon-view" @click="handleView(scope.row,scope.index)"
Marcus's avatar
Marcus committed
76
                     v-hasPermi="['infra:api-access-log:query']">{{ $t('详细') }}</el-button>
sunhongwei's avatar
sunhongwei committed
77 78 79 80 81 82 83 84 85 86 87 88
        </template>
      </el-table-column>
    </el-table>
    <!-- 分页组件 -->
    <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNo" :limit.sync="queryParams.pageSize"
                @pagination="getList"/>

    <!-- 查看明细 -->
    <el-dialog title="API 访问日志详细" :visible.sync="open" width="700px" append-to-body>
      <el-form ref="form" :model="form" label-width="100px" size="mini">
        <el-row>
          <el-col :span="24">
Marcus's avatar
Marcus committed
89 90 91 92
            <el-form-item :label="$t('日志主键:')">{{ form.id }}</el-form-item>
            <el-form-item :label="$t('链路追踪:')">{{ form.traceId }}</el-form-item>
            <el-form-item :label="$t('应用名:')">{{ form.applicationName }}</el-form-item>
            <el-form-item :label="$t('用户信息:')">
sunhongwei's avatar
sunhongwei committed
93 94
              {{ form.userId }} <dict-tag :type="DICT_TYPE.USER_TYPE" :value="form.userType"/> | {{ form.userIp }} | {{ form.userAgent}}
            </el-form-item>
Marcus's avatar
Marcus committed
95 96 97
            <el-form-item :label="$t('请求信息:')">{{ form.requestMethod }} | {{ form.requestUrl }} </el-form-item>
            <el-form-item :label="$t('请求参数:')">{{ form.requestParams }}</el-form-item>
            <el-form-item :label="$t('开始时间:')">
sunhongwei's avatar
sunhongwei committed
98 99
              {{ parseTime(form.beginTime) }} ~ {{ parseTime(form.endTime) }} | {{ form.duration }} ms
            </el-form-item>
Marcus's avatar
Marcus committed
100 101
            <el-form-item :label="$t('操作结果:')">
              <div v-if="form.resultCode === 0">{{ $t('正常') }}</div>
sunhongwei's avatar
sunhongwei committed
102 103 104 105 106 107
              <div v-else-if="form.resultCode > 0">失败 | {{ form.resultCode }} || {{ form.resultMsg}}</div>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <div slot="footer" class="dialog-footer">
Marcus's avatar
Marcus committed
108
        <el-button @click="open = false">{{ $t('关 闭') }}</el-button>
sunhongwei's avatar
sunhongwei committed
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
      </div>
    </el-dialog>

  </div>
</template>

<script>
import { getApiAccessLogPage, exportApiAccessLogExcel } from "@/api/infra/apiAccessLog";

export default {
  name: "ApiAccessLog",
  components: {
  },
  data() {
    return {
      // 遮罩层
      loading: true,
      // 导出遮罩层
      exportLoading: false,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // API 访问日志列表
      list: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      dateRangeBeginTime: [],
      // 查询参数
      queryParams: {
        pageNo: 1,
        pageSize: 10,
        userId: null,
        userType: null,
        applicationName: null,
        requestUrl: null,
        duration: null,
        resultCode: null,
      },
      // 表单参数
      form: {},
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询列表 */
    getList() {
      this.loading = true;
      // 处理查询参数
      let params = {...this.queryParams};
邓春圆's avatar
邓春圆 committed
163
      this.addBeginAndEndTime(params, this.dateRangeBeginTime, 'beginTime',false);
sunhongwei's avatar
sunhongwei committed
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
      // 执行查询
      getApiAccessLogPage(params).then(response => {
        this.list = response.data.list;
        this.total = response.data.total;
        this.loading = false;
      });
    },
    /** 取消按钮 */
    cancel() {
      this.open = false;
      this.reset();
    },
    /** 表单重置 */
    reset() {
      this.form = {};
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNo = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.dateRangeBeginTime = [];
      this.resetForm("queryForm");
      this.handleQuery();
    },
    /** 详细按钮操作 */
    handleView(row) {
      this.open = true;
      this.form = row;
    },
    /** 导出按钮操作 */
    handleExport() {
      // 处理查询参数
      let params = {...this.queryParams};
      params.pageNo = undefined;
      params.pageSize = undefined;
      this.addBeginAndEndTime(params, this.dateRangeBeginTime, 'beginTime');
      // 执行导出
      this.$modal.confirm('是否确认导出所有API 访问日志数据项?').then(() => {
        this.exportLoading = true;
        return exportApiAccessLogExcel(params);
      }).then(response => {
        this.$download.excel(response, 'API 访问日志.xls');
        this.exportLoading = false;
      }).catch(() => {});
    }
  }
};
</script>