Skip to content

Commit

Permalink
增加登陆日志,修复table分页的巨坑
Browse files Browse the repository at this point in the history
  • Loading branch information
zhangmrit committed Jun 7, 2019
1 parent f32def1 commit d3f628c
Show file tree
Hide file tree
Showing 5 changed files with 235 additions and 4 deletions.
24 changes: 23 additions & 1 deletion src/api/monitor.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { axios } from '@/utils/request'

const api = {
operLog: '/system/operLog'
operLog: '/system/operLog',
loginLog: '/system/logininfor'
}

export default api
Expand All @@ -28,3 +29,24 @@ export function cleanOperLog () {
method: 'post'
})
}
// LoginLog
export function getLoginLogList (parameter) {
return axios({
url: api.loginLog + '/list',
method: 'get',
params: parameter
})
}
export function delLoginLog (parameter) {
return axios({
url: api.loginLog + '/remove',
method: 'post',
params: parameter
})
}
export function cleanLoginLog () {
return axios({
url: api.loginLog + '/clean',
method: 'post'
})
}
2 changes: 1 addition & 1 deletion src/components/Table/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ export default {
// 这里用于判断接口是否有返回 r.totalCount 且 this.showPagination = true 且 pageNo 和 pageSize 存在 且 totalCount 小于等于 pageNo * pageSize 的大小
// 当情况满足时,表示数据不满足分页大小,关闭 table 分页功能
try {
if ((['auto', true].includes(this.showPagination) && r.total <= (r.pageNum * pagination.pageSize))) {
if ((['auto', true].includes(this.showPagination) && r.total <= (r.pageNum * this.localPagination.pageSize))) {
this.localPagination.hideOnSinglePage = true
}
} catch (e) {
Expand Down
3 changes: 2 additions & 1 deletion src/utils/routerUtil.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ const constantRouterComponents = {
permissionList: () => import('@/views/system/PermissionList'),
deptList: () => import('@/views/system/DeptList'),
// monitor
operLogList: () => import('@/views/monitor/OperLogList')
operLogList: () => import('@/views/monitor/OperLogList'),
loginLogList: () => import('@/views/monitor/LoginLogList')
// ...more
}

Expand Down
208 changes: 208 additions & 0 deletions src/views/monitor/LoginLogList.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,208 @@
<template>
<a-card :bordered="false">
<div class="table-page-search-wrapper">
<a-form layout="inline">
<a-row :gutter="48">
<a-col :md="5" :sm="15">
<a-form-item label="操作人员">
<a-input placeholder="请输入" v-model="queryParam.operName"/>
</a-form-item>
</a-col>
<a-col :md="4" :sm="12">
<a-form-item label="操作类型">
<a-select placeholder="请选择" v-model="queryParam.businessType" default-value="0">
<a-select-option :value="''">全部</a-select-option>
<a-select-option v-for="(d, index) in commonStatus" :key="index" :value="d.dictValue">{{ d.dictLabel }}</a-select-option>
</a-select>
</a-form-item>
</a-col>
<a-col :md="4" :sm="12">
<a-form-item label="操作状态">
<a-select placeholder="请选择" v-model="queryParam.status" default-value="0">
<a-select-option :value="''">全部</a-select-option>
<a-select-option :value="0">成功</a-select-option>
<a-select-option :value="1">失败</a-select-option>
</a-select>
</a-form-item>
</a-col>
<a-col :md="6" :sm="18">
<a-form-item label="操作时间">
<a-range-picker v-model="range"/>
</a-form-item>
</a-col>
<a-col :md="5" :sm="15">
<span class="table-page-search-submitButtons">
<a-button type="primary" @click="$refs.table.refresh(true)">查询</a-button>
<a-button style="margin-left: 8px" @click="() => queryParam = {}">重置</a-button>
</span>
</a-col>
</a-row>
</a-form>
</div>
<div class="table-operator">
<a-popconfirm title="确认清空吗?" @confirm="clean">
<a-icon slot="icon" type="question-circle-o" style="color: red" />
<a-button type="danger" ghost icon="close">清空</a-button>
</a-popconfirm>
<a-dropdown v-has="'role:del'" v-if="selectedRowKeys.length > 0">
<a-button type="danger" icon="delete" @click="delByIds(selectedRowKeys)">删除</a-button>
</a-dropdown>
</div>
<s-table
size="default"
ref="table"
rowKey="infoId"
:rowSelection="{selectedRowKeys: selectedRowKeys, onChange: onSelectChange}"
:columns="columns"
:data="loadData"
:rangPicker="range"
>
<span slot="status" slot-scope="text">
{{ text | statusFilter }}
</span>
</s-table>
</a-card>
</template>

<script>
import { STable } from '@/components'
import { getLoginLogList, delLoginLog, cleanLoginLog } from '@/api/monitor'
import { getDictArray } from '../../utils/dict'
const commonStatusMap = {}
export default {
name: 'TableList',
components: {
STable
},
data () {
return {
visible: false,
labelCol: {
xs: { span: 24 },
sm: { span: 5 }
},
wrapperCol: {
xs: { span: 24 },
sm: { span: 16 }
},
form: this.$form.createForm(this),
mdl: {},
permissions: [],
// 高级搜索 展开/关闭
advanced: false,
// 查询参数
queryParam: {},
// 表头
columns: [
{
title: '访问编号',
dataIndex: 'infoId'
},
{
title: '登录名称',
dataIndex: 'loginName'
},
{
title: '登录地址',
dataIndex: 'ipaddr'
},
{
title: '登录地点',
dataIndex: 'loginLocation'
},
{
title: '浏览器',
dataIndex: 'browser'
},
{
title: '操作系统',
dataIndex: 'os'
},
{
title: '状态',
dataIndex: 'status',
scopedSlots: { customRender: 'status' }
},
{
title: '操作信息',
dataIndex: 'msg'
},
{
title: '操作时间',
dataIndex: 'loginTime',
sorter: true
}
],
range: null,
// 加载数据方法 必须为 Promise 对象
loadData: parameter => {
return getLoginLogList(Object.assign(parameter, this.queryParam))
},
commonStatus: [],
selectedRowKeys: [],
selectedRows: []
}
},
filters: {
operTypeFilter (type) {
return commonStatusMap[type].text
},
statusFilter (status) {
const statusMap = {
'1': '失败',
'0': '成功'
}
return statusMap[status]
}
},
beforeCreate () {
},
async created () {
this.commonStatus = await getDictArray('sys_common_status')
this.commonStatus.map(d => {
commonStatusMap[d.dictValue] = { text: d.dictLabel }
})
},
methods: {
onSelectChange (selectedRowKeys, selectedRows) {
this.selectedRowKeys = selectedRowKeys
this.selectedRows = selectedRows
},
handleOk () {
this.$refs.table.refresh(true)
},
delByIds (ids) {
delLoginLog({ ids: ids.join(',') }).then(res => {
if (res.code === 0) {
this.$message.success(`删除成功`)
this.handleOk()
} else {
this.$message.error(res.msg)
}
this.selectedRowKeys = []
})
},
clean () {
cleanLoginLog().then(res => {
this.handleOk()
})
}
},
watch: {
/*
'selectedRows': function (selectedRows) {
this.needTotalList = this.needTotalList.map(item => {
return {
...item,
total: selectedRows.reduce( (sum, val) => {
return sum + val[item.dataIndex]
}, 0)
}
})
}
*/
}
}
</script>
2 changes: 1 addition & 1 deletion vue.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ module.exports = {
// target: 'https://mock.ihx.me/mock/5baf3052f7da7e07e04a5116/antd-pro',
// target: 'https://www.easy-mock.com/mock/5ce2743c2dda2d3b1365fb1b/ruoyi-cloud',
target: 'http://myzuul.com:9527',
// pathRewrite: { '^/api': '' },
pathRewrite: { '^/api': '' },
ws: false,
changeOrigin: true
}
Expand Down

0 comments on commit d3f628c

Please sign in to comment.