loginlog.vue 4.01 KB
<template>
  <div class="manage-container deviceStatus-wrapper">
    <el-row class="manage-head-wrapper">
      <header class="title-header">
        <span class="title">{{ $t('Management.LoginLog') }}</span>
      </header>
    </el-row>
    <el-row class="manage-content">
      <el-col :span="24">
        <el-table
          :data="tableData"
          :max-height="tableHeight"
          :empty-text="dataMsg"
          class="data-compare-table"
          style="width: 100%"
          header-row-class-name="manage-tab-head"
        >
          <el-table-column align="center" :label="$t('table.order')" width="100" type="index"></el-table-column>
          <el-table-column :label="$t('table.username')" align="center" prop="opLoginname"></el-table-column>
          <el-table-column :label="$t('table.name')" align="center" prop="opUsername"></el-table-column>
          <el-table-column :label="$t('table.blocName')" align="center" prop="accountName"></el-table-column>
          <el-table-column label="IP" align="center" prop="opIp"></el-table-column>
          <el-table-column :label="$t('table.loginTime')" align="center" prop="opTime"></el-table-column>
          <el-table-column :label="$t('table.address')" align="center" prop="country">
            <template #default="{row}">
                {{formatAddress(row.country)}}
                {{formatAddress(row.province,1)}}
                {{formatAddress(row.city,1)}}
                {{formatAddress(row.county,1)}}
            </template>
          </el-table-column>
        </el-table>
        <el-pagination
          class="manage-pagination-box"
          background
          :current-page="currentPage"
          :page-sizes="[10, 20, 50, 100]"
          :page-size="pageSize"
          @size-change="sizeChange"
          @current-change="cerrentChange"
          layout="sizes, prev, pager, next, slot"
          :total="total"
        >
          <span
            class="slot-ele-total"
          >{{$t('table.pageHead')}} {{ total }} {{$t('table.pageTail')}}</span>
        </el-pagination>
      </el-col>
    </el-row>
  </div>
</template>
<script>
export default {
  data() {
    return {
      tableData: [],
      total: 0,
      pageSize: 20,
      currentPage: 1,
      dataMsg: ""
    };
  },
  computed: {
    tableHeight() {
      const windowInnerHeight = window.innerHeight;
      return (
        windowInnerHeight -
        (windowInnerHeight <= 720
          ? windowInnerHeight * 0.26
          : windowInnerHeight * 0.24)
      );
    }
  },
  mounted() {
    this.dataMsg = this.$t("echartsTitle.loading");
    this.getLoginLog();
  },
  methods: {
    formatAddress(str,val){
      if(str){
        if(val){
          let text = str?'-'+str:''
          return text
        }else{
          let text = str?str:''
          return text
        }
      }else{
        return ''
      }
    },
    getLoginLog() {
      this.dataMsg = this.$t("echartsTitle.loading");
      this.$api.management
        .loginLog({
          accountId: this.$cookie.get("accountId"),
          page: this.currentPage,
          pageSize: this.pageSize,
          sortName: "op_time",
          sortOrder: "desc"
        })
        .then(res => {
          let result = res.data.data;
          this.tableData = result.list;
          this.total = result.total;
          this.tableData.length === 0 &&
            (this.dataMsg = this.$t("echartsTitle.noData"));
        })
        .catch(error => {});
    },
    sizeChange(val) {
      this.pageSize = val;
      this.getLoginLog();
    },
    cerrentChange(val) {
      if (this.currentPage != val) {
        this.currentPage = val;
        this.getLoginLog();
      }
    },
    // 搜索
    searchFun() {
      this.currentPage = 1;
      // this.getDeviceList();
    }
  }
};
</script>
<style scoped>
.manage-head-wrapper {
  padding: 15px 12px 10px;
}
.title-header {
  text-align: center;
  padding-bottom: 10px;
}
.title {
  line-height: 20px;
  display: inline-block;
  font-size: 20px;
  vertical-align: middle;
  text-align: center;
  color: #555;
}
</style>