refactor: loginlog vxe

This commit is contained in:
xingyu4j 2022-11-13 14:49:59 +08:00
parent 7250e23df3
commit 866247959e
4 changed files with 103 additions and 149 deletions

View File

@ -1,5 +1,17 @@
import request from '@/config/axios'
export interface LoginLogVO {
id: number
logType: number
traceId: number
userType: number
username: string
status: number
userIp: string
userAgent: string
createTime: string
}
// 查询登录日志列表
export const getLoginLogPageApi = (params) => {
return request.get({ url: '/system/login-log/page', params })

View File

@ -1,11 +0,0 @@
export type LoginLogVO = {
id: number
logType: number
traceId: number
userType: number
username: string
status: number
userIp: string
userAgent: string
createTime: string
}

View File

@ -1,80 +1,66 @@
<template>
<ContentWrap>
<!-- 列表 -->
<vxe-grid ref="xGrid" v-bind="gridOptions" class="xtable-scrollbar">
<template #toolbar_buttons>
<XButton
type="primary"
preIcon="ep:download"
:title="t('action.export')"
@click="handleExport()"
/>
</template>
<template #actionbtns_default="{ row }">
<!-- 操作详情 -->
<XTextButton preIcon="ep:view" :title="t('action.detail')" @click="handleDetail(row)" />
</template>
</vxe-grid>
</ContentWrap>
<!-- 弹窗 -->
<XModal id="postModel" v-model="dialogVisible" :title="dialogTitle">
<template #default>
<!-- 表单详情 -->
<Descriptions :schema="allSchemas.detailSchema" :data="detailRef" />
</template>
<template #footer>
<!-- 按钮关闭 -->
<XButton :title="t('dialog.close')" @click="dialogVisible = false" />
</template>
</XModal>
</template>
<script setup lang="ts">
// import
import { ref } from 'vue'
import dayjs from 'dayjs'
import { useTable } from '@/hooks/web/useTable'
import { allSchemas } from './loginLog.data'
import { DICT_TYPE } from '@/utils/dict'
import type { LoginLogVO } from '@/api/system/loginLog/types'
import { getLoginLogPageApi, exportLoginLogApi } from '@/api/system/loginLog'
import { useI18n } from '@/hooks/web/useI18n'
import { useVxeGrid } from '@/hooks/web/useVxeGrid'
import { VxeGridInstance } from 'vxe-table'
import { allSchemas } from './loginLog.data'
import { getLoginLogPageApi, exportLoginLogApi, LoginLogVO } from '@/api/system/loginLog'
import download from '@/utils/download'
const { t } = useI18n() //
// ========== ==========
const { register, tableObject, methods } = useTable<LoginLogVO>({
getListApi: getLoginLogPageApi,
exportListApi: exportLoginLogApi
//
const xGrid = ref<VxeGridInstance>() // Grid Ref
const { gridOptions } = useVxeGrid<LoginLogVO>({
allSchemas: allSchemas,
getListApi: getLoginLogPageApi
})
const { getList, setSearchParams } = methods
//
const detailRef = ref() // Ref
const dialogVisible = ref(false) //
const dialogTitle = ref(t('action.detail')) //
const detailRef = ref() // Ref
const handleDetail = async (row: LoginLogVO) => {
//
detailRef.value = row
dialogVisible.value = true
}
getList()
//
const handleExport = async () => {
const queryParams = Object.assign(
{},
JSON.parse(JSON.stringify(xGrid.value?.getRefMaps().refForm.value.data))
)
const res = await exportLoginLogApi(queryParams)
download.excel(res, '登录列表.xls')
}
</script>
<template>
<ContentWrap>
<Search :schema="allSchemas.searchSchema" @search="setSearchParams" @reset="setSearchParams" />
</ContentWrap>
<ContentWrap>
<Table
:columns="allSchemas.tableColumns"
:selection="false"
:data="tableObject.tableList"
:loading="tableObject.loading"
:pagination="{
total: tableObject.total
}"
v-model:pageSize="tableObject.pageSize"
v-model:currentPage="tableObject.currentPage"
@register="register"
>
<template #logType="{ row }">
<DictTag :type="DICT_TYPE.SYSTEM_LOGIN_TYPE" :value="row.logType" />
</template>
<template #result="{ row }">
<DictTag :type="DICT_TYPE.SYSTEM_LOGIN_RESULT" :value="row.result" />
</template>
<template #createTime="{ row }">
<span>{{ dayjs(row.createTime).format('YYYY-MM-DD HH:mm:ss') }}</span>
</template>
<template #action="{ row }">
<el-button link type="primary" @click="handleDetail(row)">
<Icon icon="ep:view" class="mr-1px" /> {{ t('action.detail') }}
</el-button>
</template>
</Table>
</ContentWrap>
<Dialog v-model="dialogVisible" :title="dialogTitle" maxHeight="500px" width="50%">
<!-- 对话框(详情) -->
<Descriptions :schema="allSchemas.detailSchema" :data="detailRef">
<template #logType="{ row }">
<DictTag :type="DICT_TYPE.SYSTEM_LOGIN_TYPE" :value="row.logType" />
</template>
<template #result="{ row }">
<DictTag :type="DICT_TYPE.SYSTEM_LOGIN_RESULT" :value="row.result" />
</template>
<template #createTime="{ row }">
<span>{{ dayjs(row.createTime).format('YYYY-MM-DD HH:mm:ss') }}</span>
</template>
</Descriptions>
<!-- 操作按钮 -->
<template #footer>
<el-button @click="dialogVisible = false">{{ t('dialog.close') }}</el-button>
</template>
</Dialog>
</template>

View File

@ -1,80 +1,47 @@
import { reactive } from 'vue'
import { DICT_TYPE } from '@/utils/dict'
import { useI18n } from '@/hooks/web/useI18n'
import { CrudSchema, useCrudSchemas } from '@/hooks/web/useCrudSchemas'
import { DICT_TYPE } from '@/utils/dict'
import { VxeCrudSchema, useVxeCrudSchemas } from '@/hooks/web/useVxeCrudSchemas'
const { t } = useI18n() // 国际化
const crudSchemas = reactive<CrudSchema[]>([
// CrudSchema
const crudSchemas = reactive<VxeCrudSchema>({
primaryKey: 'id',
primaryType: 'seq',
action: true,
columns: [
{
label: t('common.index'),
field: 'id',
type: 'index',
form: {
show: false
},
detail: {
show: false
}
},
{
label: '日志类型',
title: '日志类型',
field: 'logType',
dictType: DICT_TYPE.SYSTEM_LOGIN_TYPE,
search: {
show: true
}
isSearch: true
},
{
label: '用户名称',
title: '用户名称',
field: 'username',
search: {
show: true
}
isSearch: true
},
{
label: '登录地址',
title: '登录地址',
field: 'userIp',
search: {
show: true
}
isSearch: true
},
{
label: 'userAgent',
title: 'userAgent',
field: 'userAgent'
},
{
label: '登陆结果',
title: '登陆结果',
field: 'result',
dictType: DICT_TYPE.SYSTEM_LOGIN_RESULT,
search: {
show: true
}
isSearch: true
},
{
label: t('common.createTime'),
title: t('common.createTime'),
field: 'createTime',
form: {
show: false
},
search: {
show: true,
component: 'DatePicker',
componentProps: {
type: 'daterange',
valueFormat: 'YYYY-MM-DD HH:mm:ss',
defaultTime: [new Date(2000, 1, 1, 0, 0, 0), new Date(2000, 2, 1, 23, 59, 59)]
formatter: 'formatDate',
isForm: false
}
}
},
{
label: t('table.action'),
field: 'action',
width: '120px',
form: {
show: false
},
detail: {
show: false
}
}
])
export const { allSchemas } = useCrudSchemas(crudSchemas)
]
})
export const { allSchemas } = useVxeCrudSchemas(crudSchemas)