apiRecord.vue 2.63 KB
<!-- api调用记录 -->
<template>
  <d2-container>
    <el-form
      slot="header"
      inline="true"
    >
      <el-form-item label="访问时间:">
        <el-date-picker
          v-model="accessTime"
          :size="$store.state.d2admin.size.value"
          type="daterange"
          range-separator="至"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
          :clearable="false"
        >
        </el-date-picker>
      </el-form-item>
      <el-form-item>
        <el-button
          type="primary"
          icon="el-icon-search"
          :size="$store.state.d2admin.size.value"
          :id="tableParams.btnId"
        >查询</el-button>
        <el-button
          :size="$store.state.d2admin.size.value"
          @click="handleRest"
        >重置</el-button>
      </el-form-item>
    </el-form>
    <d2-table
      :hasNum="false"
      :searchForm="searchForm"
      :tableParams="tableParams"
      :getListApi="getListApi"
      :beforeSearchFn="beforeSearchFn"
    >
      <auth-button
        slot="auth-button"
        slot-scope="scope"
        :data="scope.scope"
      ></auth-button>
    </d2-table>
  </d2-container>
</template>

<script>
import { apiRecordList } from '@api/api'
export default {
  name: 'apiRecord',
  data() {
    return {
      searchForm: {},
      accessTime: '',
      getListApi: apiRecordList,
      tableParams: {
        btnId: new Date().getTime() + parseInt(Math.random() * 1000),
        listName: 'list',
        tableColumns: [{
          label: '序号',
          prop: 'id',
          width: '50px'
        }, {
          label: '访问时间',
          prop: 'createTime'
        }, {
          label: '客户',
          prop: 'customerName'
        }, {
          label: '调用API',
          prop: 'apiName'
        }, {
          label: '调用结果',
          prop: 'callResult',
          width: '80px',
          formatter: (cellValue) => {
            return {
              0: '失败',
              1: '成功'
            }[cellValue.callResult]
          }
        }]
      }
    }
  },

  mounted() { },

  methods: {
    beforeSearchFn() {
      return new Promise(resolve => {
        if (this.accessTime && this.accessTime.length) {
          this.searchForm.accessStartTime = new Date(this.accessTime[0]).toLocaleDateString().replace(/\//g, '-') + ' 00:00:00'
          this.searchForm.accessEndTime = new Date(this.accessTime[1]).toLocaleDateString().replace(/\//g, '-') + ' 23:59:59'
        }
        resolve()
      })
    },
    handleRest() {
      this.accessTime = []
      this.searchForm = {}
    }
  }
}

</script>
<style scoped>
</style>