doum
2025-09-19 9b8baee48d0bdd95ea157be10e7c24711c511dc1
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
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
147
<template>
  <TableLayout :permissions="['system:loginLog:query']">
    <!-- 搜索表单 -->
    <el-form ref="searchForm" slot="search-form" :model="searchForm" label-width="100px" inline>
      <el-form-item label="登录用户名" prop="loginUsername">
        <el-input v-model="searchForm.loginUsername" placeholder="请输入登录用户名" @keypress.enter.native="search"></el-input>
      </el-form-item>
      <el-form-item label="登录IP" prop="ip">
        <el-input v-model="searchForm.ip" placeholder="请输入登录IP" @keypress.enter.native="search"></el-input>
      </el-form-item>
      <el-form-item label="服务器IP" prop="serverIp">
        <el-input v-model="searchForm.serverIp" placeholder="请输入服务器IP" @keypress.enter.native="search"></el-input>
      </el-form-item>
      <el-form-item label="是否登录成功" prop="success">
        <el-select v-model="searchForm.success" placeholder="请选择是否登录状态" clearable @change="search">
          <el-option value="true" label="登录成功" />
          <el-option value="false" label="登录失败" />
        </el-select>
      </el-form-item>
      <el-form-item label="登录时间" prop="loginTime">
        <!-- <el-date-picker
          v-model="searchDateRange"
          type="datetimerange"
          range-separator="至"
          value-format="yyyy-MM-dd HH:mm:ss"
          start-placeholder="开始时间"
          end-placeholder="结束时间"
          @change="handleSearchTimeChange"
        ></el-date-picker> -->
        <el-date-picker type="datetime" v-model="searchForm.startTime" value-format="yyyy-MM-dd HH:mm:ss"
          placeholder="请选择开始时间" @change="changeRadio" />
        <el-date-picker type="datetime" v-model="searchForm.endTime" value-format="yyyy-MM-dd HH:mm:ss"
          placeholder="请选择结束时间" @change="changeRadio" />
      </el-form-item>
      <section>
        <el-button type="primary" @click="search">搜索</el-button>
        <el-button type="primary" :loading="isWorking.export" @click="exportExcel">导出</el-button>
        <el-button @click="reset">重置</el-button>
      </section>
    </el-form>
    <!-- 表格和分页 -->
    <template v-slot:table-wrap>
      <el-table v-loading="isWorking.search" :data="tableData.list" stripe :height="tableHeightNew"
        :default-sort="{ prop: 'loginTime', order: 'descending' }" @sort-change="handleSortChange">
        <el-table-column prop="loginUsername" label="登录用户名" min-width="100px"></el-table-column>
        <el-table-column prop="ip" label="登录IP" min-width="120px"></el-table-column>
        <el-table-column prop="location" label="登录地址" min-width="160px"></el-table-column>
        <el-table-column prop="clientInfo" label="客户端" min-width="160px"></el-table-column>
        <el-table-column prop="osInfo" label="操作系统" min-width="100px"></el-table-column>
        <el-table-column prop="platform" label="登录平台" min-width="100px"></el-table-column>
        <el-table-column prop="loginTime" label="登录时间" min-width="160px" sortable="custom"
          sort-by="LOGIN_TIME"></el-table-column>
        <el-table-column prop="systemVersion" label="系统版本" min-width="100px"></el-table-column>
        <el-table-column prop="serverIp" label="服务器IP" min-width="120px"></el-table-column>
        <el-table-column prop="success" label="状态" min-width="100px">
          <template slot-scope="{row}">
            {{ row.success | statusText }}
          </template>
        </el-table-column>
        <el-table-column prop="reason" label="失败原因" min-width="160px"></el-table-column>
      </el-table>
      <pagination @size-change="handleSizeChange" @current-change="handlePageChange" :pagination="tableData.pagination">
      </pagination>
    </template>
  </TableLayout>
</template>
 
<script>
import BaseTable from '@/components/base/BaseTable'
import TableLayout from '@/layouts/TableLayout'
import Pagination from '@/components/common/Pagination'
 
export default {
  name: 'SystemLoginLog',
  extends: BaseTable,
  components: { TableLayout, Pagination },
  data() {
    return {
      // 搜索时间范围
      searchDateRange: [],
      // 搜索
      searchForm: {
        loginUsername: '',
        ip: '',
        serverIp: '',
        success: '',
        startTime: null,
        endTime: null
      }
    }
  },
  filters: {
    // 登录状态
    statusText(value) {
      if (value != null && !value) {
        return '登录失败'
      }
      return '登录成功'
    }
  },
  methods: {
    reset() {
      this.searchForm = {
        loginUsername: '',
        ip: '',
        serverIp: '',
        success: '',
        startTime: null,
        endTime: null
      }
      this.search()
    },
    changeRadio() {
 
      if (this.searchForm.startTime && this.searchForm.endTime && new Date(this.searchForm.startTime).getTime() > new Date(this.searchForm.endTime).getTime()) {
        this.$message.error('开始时间不能大于结束时间')
        this.searchForm.startTime = ''
        return
      }
      this.search()
    },
    // 时间搜索范围变化
    handleSearchTimeChange(value) {
      this.searchForm.startTime = null
      this.searchForm.endTime = null
      if (value != null) {
        this.searchForm.startTime = value[0]
        this.searchForm.endTime = value[1]
      }
      this.search()
    }
  },
  created() {
    this.config({
      module: '登录日志',
      api: '/system/loginLog',
      'field.id': 'id',
      'field.main': 'id',
      sorts: [{
        property: 'LOGIN_TIME',
        direction: 'DESC'
      }]
    })
    this.search()
  }
}
</script>