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' 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) => { export const getLoginLogPageApi = (params) => {
return request.get({ url: '/system/login-log/page', 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"> <script setup lang="ts">
// import
import { ref } from 'vue' 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 { 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 { t } = useI18n() //
// ========== ========== //
const { register, tableObject, methods } = useTable<LoginLogVO>({ const xGrid = ref<VxeGridInstance>() // Grid Ref
getListApi: getLoginLogPageApi, const { gridOptions } = useVxeGrid<LoginLogVO>({
exportListApi: exportLoginLogApi allSchemas: allSchemas,
getListApi: getLoginLogPageApi
}) })
const { getList, setSearchParams } = methods
// //
const detailRef = ref() // Ref
const dialogVisible = ref(false) // const dialogVisible = ref(false) //
const dialogTitle = ref(t('action.detail')) // const dialogTitle = ref(t('action.detail')) //
const detailRef = ref() // Ref
const handleDetail = async (row: LoginLogVO) => { const handleDetail = async (row: LoginLogVO) => {
// //
detailRef.value = row detailRef.value = row
dialogVisible.value = true 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> </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 { reactive } from 'vue'
import { DICT_TYPE } from '@/utils/dict'
import { useI18n } from '@/hooks/web/useI18n' 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 { t } = useI18n() // 国际化
const crudSchemas = reactive<CrudSchema[]>([
{ // CrudSchema
label: t('common.index'), const crudSchemas = reactive<VxeCrudSchema>({
field: 'id', primaryKey: 'id',
type: 'index', primaryType: 'seq',
form: { action: true,
show: false columns: [
{
title: '日志类型',
field: 'logType',
dictType: DICT_TYPE.SYSTEM_LOGIN_TYPE,
isSearch: true
}, },
detail: { {
show: false title: '用户名称',
} field: 'username',
}, isSearch: true
{
label: '日志类型',
field: 'logType',
dictType: DICT_TYPE.SYSTEM_LOGIN_TYPE,
search: {
show: true
}
},
{
label: '用户名称',
field: 'username',
search: {
show: true
}
},
{
label: '登录地址',
field: 'userIp',
search: {
show: true
}
},
{
label: 'userAgent',
field: 'userAgent'
},
{
label: '登陆结果',
field: 'result',
dictType: DICT_TYPE.SYSTEM_LOGIN_RESULT,
search: {
show: true
}
},
{
label: t('common.createTime'),
field: 'createTime',
form: {
show: false
}, },
search: { {
show: true, title: '登录地址',
component: 'DatePicker', field: 'userIp',
componentProps: { isSearch: true
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)]
}
}
},
{
label: t('table.action'),
field: 'action',
width: '120px',
form: {
show: false
}, },
detail: { {
show: false title: 'userAgent',
field: 'userAgent'
},
{
title: '登陆结果',
field: 'result',
dictType: DICT_TYPE.SYSTEM_LOGIN_RESULT,
isSearch: true
},
{
title: t('common.createTime'),
field: 'createTime',
formatter: 'formatDate',
isForm: false
} }
} ]
]) })
export const { allSchemas } = useCrudSchemas(crudSchemas) export const { allSchemas } = useVxeCrudSchemas(crudSchemas)