mirror of
				https://gitee.com/hhyykk/ipms-sjy-ui.git
				synced 2025-10-31 18:28:44 +08:00 
			
		
		
		
	Vue3 重构:登录日志
This commit is contained in:
		| @@ -21,10 +21,10 @@ export interface LoginLogReqVO extends PageParam { | |||||||
| } | } | ||||||
|  |  | ||||||
| // 查询登录日志列表 | // 查询登录日志列表 | ||||||
| export const getLoginLogPageApi = (params: LoginLogReqVO) => { | export const getLoginLogPage = (params: LoginLogReqVO) => { | ||||||
|   return request.get({ url: '/system/login-log/page', params }) |   return request.get({ url: '/system/login-log/page', params }) | ||||||
| } | } | ||||||
| // 导出登录日志 | // 导出登录日志 | ||||||
| export const exportLoginLogApi = (params: LoginLogReqVO) => { | export const exportLoginLog = (params: LoginLogReqVO) => { | ||||||
|   return request.download({ url: '/system/login-log/export', params }) |   return request.download({ url: '/system/login-log/export', params }) | ||||||
| } | } | ||||||
|   | |||||||
| @@ -26,3 +26,9 @@ | |||||||
|     border-left-color: var(--el-color-primary); |     border-left-color: var(--el-color-primary); | ||||||
|   } |   } | ||||||
| } | } | ||||||
|  |  | ||||||
|  | // 添加表头样式 | ||||||
|  | .el-table.yudao-table { | ||||||
|  |   --el-table-header-bg-color: #f8f8f9; | ||||||
|  |   --el-table-header-text-color: #606266; | ||||||
|  | } | ||||||
|   | |||||||
							
								
								
									
										49
									
								
								src/views/system/loginlog/detail.vue
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										49
									
								
								src/views/system/loginlog/detail.vue
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,49 @@ | |||||||
|  | <template> | ||||||
|  |   <Dialog title="详情" v-model="modelVisible" :scroll="true" :max-height="500" width="800"> | ||||||
|  |     <el-descriptions border :column="1"> | ||||||
|  |       <el-descriptions-item label="日志编号" min-width="120"> | ||||||
|  |         {{ detailData.id }} | ||||||
|  |       </el-descriptions-item> | ||||||
|  |       <el-descriptions-item label="操作类型"> | ||||||
|  |         <dict-tag :type="DICT_TYPE.SYSTEM_LOGIN_TYPE" :value="detailData.logType" /> | ||||||
|  |       </el-descriptions-item> | ||||||
|  |       <el-descriptions-item label="用户名称"> | ||||||
|  |         {{ detailData.username }} | ||||||
|  |       </el-descriptions-item> | ||||||
|  |       <el-descriptions-item label="登录地址"> | ||||||
|  |         {{ detailData.userIp }} | ||||||
|  |       </el-descriptions-item> | ||||||
|  |       <el-descriptions-item label="浏览器"> | ||||||
|  |         {{ detailData.userAgent }} | ||||||
|  |       </el-descriptions-item> | ||||||
|  |       <el-descriptions-item label="登陆结果"> | ||||||
|  |         <dict-tag :type="DICT_TYPE.SYSTEM_LOGIN_RESULT" :value="detailData.result" /> | ||||||
|  |       </el-descriptions-item> | ||||||
|  |       <el-descriptions-item label="登录日期"> | ||||||
|  |         {{ formatDate(detailData.createTime, 'YYYY-MM-DD HH:mm:ss') }} | ||||||
|  |       </el-descriptions-item> | ||||||
|  |     </el-descriptions> | ||||||
|  |   </Dialog> | ||||||
|  | </template> | ||||||
|  | <script setup lang="ts"> | ||||||
|  | import { DICT_TYPE } from '@/utils/dict' | ||||||
|  | import { formatDate } from '@/utils/formatTime' | ||||||
|  | import * as LoginLogApi from '@/api/system/loginLog' | ||||||
|  |  | ||||||
|  | const modelVisible = ref(false) // 弹窗的是否展示 | ||||||
|  | const detailLoading = ref(false) // 表单的加载中 | ||||||
|  | const detailData = ref() // 详情数据 | ||||||
|  |  | ||||||
|  | /** 打开弹窗 */ | ||||||
|  | const openModal = async (data: LoginLogApi.LoginLogVO) => { | ||||||
|  |   modelVisible.value = true | ||||||
|  |   // 设置数据 | ||||||
|  |   detailLoading.value = true | ||||||
|  |   try { | ||||||
|  |     detailData.value = data | ||||||
|  |   } finally { | ||||||
|  |     detailLoading.value = false | ||||||
|  |   } | ||||||
|  | } | ||||||
|  | defineExpose({ openModal }) // 提供 openModal 方法,用于打开弹窗 | ||||||
|  | </script> | ||||||
| @@ -1,53 +1,176 @@ | |||||||
| <template> | <template> | ||||||
|   <ContentWrap> |   <content-wrap> | ||||||
|     <!-- 列表 --> |     <!-- 搜索工作栏 --> | ||||||
|     <XTable @register="registerTable"> |     <el-form | ||||||
|       <!-- 操作:导出 --> |       class="-mb-15px" | ||||||
|       <template #toolbar_buttons> |       :model="queryParams" | ||||||
|         <XButton |       ref="queryFormRef" | ||||||
|           type="warning" |       :inline="true" | ||||||
|           preIcon="ep:download" |       label-width="68px" | ||||||
|           :title="t('action.export')" |     > | ||||||
|           @click="exportList('登录列表.xls')" |       <el-form-item label="用户名称" prop="username"> | ||||||
|  |         <el-input | ||||||
|  |           v-model="queryParams.username" | ||||||
|  |           placeholder="请输入用户名称" | ||||||
|  |           clearable | ||||||
|  |           @keyup.enter="handleQuery" | ||||||
|  |           class="!w-240px" | ||||||
|         /> |         /> | ||||||
|  |       </el-form-item> | ||||||
|  |       <el-form-item label="登录地址" prop="userIp"> | ||||||
|  |         <el-input | ||||||
|  |           v-model="queryParams.userIp" | ||||||
|  |           placeholder="请输入登录地址" | ||||||
|  |           clearable | ||||||
|  |           @keyup.enter="handleQuery" | ||||||
|  |           class="!w-240px" | ||||||
|  |         /> | ||||||
|  |       </el-form-item> | ||||||
|  |       <el-form-item label="登录日期" prop="createTime"> | ||||||
|  |         <el-date-picker | ||||||
|  |           v-model="queryParams.createTime" | ||||||
|  |           value-format="YYYY-MM-DD HH:mm:ss" | ||||||
|  |           type="daterange" | ||||||
|  |           start-placeholder="开始日期" | ||||||
|  |           end-placeholder="结束日期" | ||||||
|  |           :default-time="[new Date('1 00:00:00'), new Date('1 23:59:59')]" | ||||||
|  |           class="!w-240px" | ||||||
|  |         /> | ||||||
|  |       </el-form-item> | ||||||
|  |       <el-form-item> | ||||||
|  |         <el-button @click="handleQuery"><Icon icon="ep:search" class="mr-5px" /> 搜索</el-button> | ||||||
|  |         <el-button @click="resetQuery"><Icon icon="ep:refresh" class="mr-5px" /> 重置</el-button> | ||||||
|  |         <el-button | ||||||
|  |           type="success" | ||||||
|  |           plain | ||||||
|  |           @click="handleExport" | ||||||
|  |           :loading="exportLoading" | ||||||
|  |           v-hasPermi="['infra:config:export']" | ||||||
|  |         > | ||||||
|  |           <Icon icon="ep:download" class="mr-5px" /> 导出 | ||||||
|  |         </el-button> | ||||||
|  |       </el-form-item> | ||||||
|  |     </el-form> | ||||||
|  |   </content-wrap> | ||||||
|  |  | ||||||
|  |   <!-- 列表 --> | ||||||
|  |   <content-wrap> | ||||||
|  |     <el-table class="yudao-table" v-loading="loading" :data="list"> | ||||||
|  |       <el-table-column label="日志编号" align="center" prop="id" /> | ||||||
|  |       <el-table-column label="操作类型" align="center" prop="logType"> | ||||||
|  |         <template #default="scope"> | ||||||
|  |           <dict-tag :type="DICT_TYPE.SYSTEM_LOGIN_TYPE" :value="scope.row.logType" /> | ||||||
|         </template> |         </template> | ||||||
|       <template #actionbtns_default="{ row }"> |       </el-table-column> | ||||||
|         <!-- 操作:详情 --> |       <el-table-column label="用户名称" align="center" prop="username" width="180" /> | ||||||
|         <XTextButton preIcon="ep:view" :title="t('action.detail')" @click="handleDetail(row)" /> |       <el-table-column label="登录地址" align="center" prop="userIp" width="180" /> | ||||||
|  |  | ||||||
|  |       <el-table-column label="浏览器" align="center" prop="userAgent" /> | ||||||
|  |       <el-table-column label="登陆结果" align="center" prop="result"> | ||||||
|  |         <template #default="scope"> | ||||||
|  |           <dict-tag :type="DICT_TYPE.SYSTEM_LOGIN_RESULT" :value="scope.row.result" /> | ||||||
|         </template> |         </template> | ||||||
|     </XTable> |       </el-table-column> | ||||||
|   </ContentWrap> |       <el-table-column | ||||||
|   <!-- 弹窗 --> |         label="登录日期" | ||||||
|   <XModal id="postModel" v-model="dialogVisible" :title="dialogTitle"> |         align="center" | ||||||
|     <!-- 表单:详情 --> |         prop="createTime" | ||||||
|     <Descriptions :schema="allSchemas.detailSchema" :data="detailData" /> |         width="180" | ||||||
|     <template #footer> |         :formatter="dateFormatter" | ||||||
|       <!-- 按钮:关闭 --> |       /> | ||||||
|       <XButton :title="t('dialog.close')" @click="dialogVisible = false" /> |       <el-table-column label="操作" align="center"> | ||||||
|  |         <template #default="scope"> | ||||||
|  |           <el-button | ||||||
|  |             link | ||||||
|  |             type="primary" | ||||||
|  |             @click="openModal(scope.row)" | ||||||
|  |             v-hasPermi="['infra:config:query']" | ||||||
|  |           > | ||||||
|  |             详情 | ||||||
|  |           </el-button> | ||||||
|         </template> |         </template> | ||||||
|   </XModal> |       </el-table-column> | ||||||
|  |     </el-table> | ||||||
|  |     <!-- 分页 --> | ||||||
|  |     <Pagination | ||||||
|  |       :total="total" | ||||||
|  |       v-model:page="queryParams.pageNo" | ||||||
|  |       v-model:limit="queryParams.pageSize" | ||||||
|  |       @pagination="getList" | ||||||
|  |     /> | ||||||
|  |   </content-wrap> | ||||||
|  |  | ||||||
|  |   <!-- 表单弹窗:详情 --> | ||||||
|  |   <login-log-detail ref="modalRef" /> | ||||||
| </template> | </template> | ||||||
| <script setup lang="ts" name="Loginlog"> | <script setup lang="ts" name="LoginLog"> | ||||||
| // 业务相关的 import | import { DICT_TYPE } from '@/utils/dict' | ||||||
| import { allSchemas } from './loginLog.data' | import { dateFormatter } from '@/utils/formatTime' | ||||||
| import { getLoginLogPageApi, exportLoginLogApi, LoginLogVO } from '@/api/system/loginLog' | import download from '@/utils/download' | ||||||
|  | import * as LoginLogApi from '@/api/system/loginLog' | ||||||
|  | import LoginLogDetail from './detail.vue' | ||||||
|  | const message = useMessage() // 消息弹窗 | ||||||
|  |  | ||||||
| const { t } = useI18n() // 国际化 | const loading = ref(true) // 列表的加载中 | ||||||
| // 列表相关的变量 | const total = ref(0) // 列表的总页数 | ||||||
| const [registerTable, { exportList }] = useXTable({ | const list = ref([]) // 列表的数据 | ||||||
|   allSchemas: allSchemas, | const queryParams = reactive({ | ||||||
|   getListApi: getLoginLogPageApi, |   pageNo: 1, | ||||||
|   exportListApi: exportLoginLogApi |   pageSize: 10, | ||||||
|  |   username: undefined, | ||||||
|  |   userIp: undefined, | ||||||
|  |   createTime: [] | ||||||
| }) | }) | ||||||
|  | const queryFormRef = ref() // 搜索的表单 | ||||||
|  | const exportLoading = ref(false) // 导出的加载中 | ||||||
|  |  | ||||||
| // 详情操作 | /** 查询参数列表 */ | ||||||
| const detailData = ref() // 详情 Ref | const getList = async () => { | ||||||
| const dialogVisible = ref(false) // 是否显示弹出层 |   loading.value = true | ||||||
| const dialogTitle = ref(t('action.detail')) // 弹出层标题 |   try { | ||||||
| // 详情 |     const data = await LoginLogApi.getLoginLogPage(queryParams) | ||||||
| const handleDetail = async (row: LoginLogVO) => { |     list.value = data.list | ||||||
|   // 设置数据 |     total.value = data.total | ||||||
|   detailData.value = row |   } finally { | ||||||
|   dialogVisible.value = true |     loading.value = false | ||||||
|  |   } | ||||||
| } | } | ||||||
|  |  | ||||||
|  | /** 搜索按钮操作 */ | ||||||
|  | const handleQuery = () => { | ||||||
|  |   queryParams.pageNo = 1 | ||||||
|  |   getList() | ||||||
|  | } | ||||||
|  |  | ||||||
|  | /** 重置按钮操作 */ | ||||||
|  | const resetQuery = () => { | ||||||
|  |   queryFormRef.value.resetFields() | ||||||
|  |   handleQuery() | ||||||
|  | } | ||||||
|  |  | ||||||
|  | /** 详情操作 */ | ||||||
|  | const modalRef = ref() | ||||||
|  | const openModal = (data: LoginLogApi.LoginLogVO) => { | ||||||
|  |   modalRef.value.openModal(data) | ||||||
|  | } | ||||||
|  |  | ||||||
|  | /** 导出按钮操作 */ | ||||||
|  | const handleExport = async () => { | ||||||
|  |   try { | ||||||
|  |     // 导出的二次确认 | ||||||
|  |     await message.exportConfirm() | ||||||
|  |     // 发起导出 | ||||||
|  |     exportLoading.value = true | ||||||
|  |     const data = await LoginLogApi.exportLoginLog(queryParams) | ||||||
|  |     download.excel(data, '登录日志.xls') | ||||||
|  |   } catch { | ||||||
|  |   } finally { | ||||||
|  |     exportLoading.value = false | ||||||
|  |   } | ||||||
|  | } | ||||||
|  |  | ||||||
|  | /** 初始化 **/ | ||||||
|  | onMounted(() => { | ||||||
|  |   getList() | ||||||
|  | }) | ||||||
| </script> | </script> | ||||||
|   | |||||||
| @@ -1,53 +0,0 @@ | |||||||
| import type { VxeCrudSchema } from '@/hooks/web/useVxeCrudSchemas' |  | ||||||
|  |  | ||||||
| // CrudSchema |  | ||||||
| const crudSchemas = reactive<VxeCrudSchema>({ |  | ||||||
|   primaryKey: 'id', |  | ||||||
|   primaryType: 'id', |  | ||||||
|   primaryTitle: '日志编号', |  | ||||||
|   action: true, |  | ||||||
|   actionWidth: '100px', |  | ||||||
|   columns: [ |  | ||||||
|     { |  | ||||||
|       title: '日志类型', |  | ||||||
|       field: 'logType', |  | ||||||
|       dictType: DICT_TYPE.SYSTEM_LOGIN_TYPE, |  | ||||||
|       dictClass: 'number' |  | ||||||
|     }, |  | ||||||
|     { |  | ||||||
|       title: '用户名称', |  | ||||||
|       field: 'username', |  | ||||||
|       isSearch: true |  | ||||||
|     }, |  | ||||||
|     { |  | ||||||
|       title: '登录地址', |  | ||||||
|       field: 'userIp', |  | ||||||
|       isSearch: true |  | ||||||
|     }, |  | ||||||
|     { |  | ||||||
|       title: '浏览器', |  | ||||||
|       field: 'userAgent' |  | ||||||
|     }, |  | ||||||
|     { |  | ||||||
|       title: '登陆结果', |  | ||||||
|       field: 'result', |  | ||||||
|       dictType: DICT_TYPE.SYSTEM_LOGIN_RESULT, |  | ||||||
|       dictClass: 'number' |  | ||||||
|     }, |  | ||||||
|     { |  | ||||||
|       title: '登录日期', |  | ||||||
|       field: 'createTime', |  | ||||||
|       formatter: 'formatDate', |  | ||||||
|       table: { |  | ||||||
|         width: 150 |  | ||||||
|       }, |  | ||||||
|       search: { |  | ||||||
|         show: true, |  | ||||||
|         itemRender: { |  | ||||||
|           name: 'XDataTimePicker' |  | ||||||
|         } |  | ||||||
|       } |  | ||||||
|     } |  | ||||||
|   ] |  | ||||||
| }) |  | ||||||
| export const { allSchemas } = useVxeCrudSchemas(crudSchemas) |  | ||||||
		Reference in New Issue
	
	Block a user
	 lour6498
					lour6498