diff --git a/app/controller/admin/auth/AuthController.php b/app/controller/admin/auth/AuthController.php index a751023..68914be 100644 --- a/app/controller/admin/auth/AuthController.php +++ b/app/controller/admin/auth/AuthController.php @@ -4,6 +4,8 @@ namespace app\controller\admin\auth; use app\BaseController; use app\entity\SysUser; +use app\enum\UserLoginEnum; +use app\service\admin\LoginService; use think\db\exception\DataNotFoundException; use think\db\exception\DbException; use think\db\exception\ModelNotFoundException; @@ -35,6 +37,8 @@ class AuthController extends BaseController */ public function logout(): Json { + $srv = new LoginService(); + $srv->logout($this->request, $this->auth->getUser()); return $this->writeSuccess('退出成功'); } } diff --git a/app/service/admin/LoginService.php b/app/service/admin/LoginService.php index 377d460..26ea9b7 100644 --- a/app/service/admin/LoginService.php +++ b/app/service/admin/LoginService.php @@ -84,6 +84,10 @@ class LoginService 'context_id' => $request->contextId, ]); } + public function logout(Request $request, SysUser $user) + { + $this->saveLoginRecord($request, $user->username,UserLoginEnum::LOGIN_EXIT, '退出登录'); + } public function checkUserAccessToken(string $token): HttpAuth diff --git a/z_ele/src/api/layout/index.ts b/z_ele/src/api/layout/index.ts index 8b2d4d7..5b0c956 100644 --- a/z_ele/src/api/layout/index.ts +++ b/z_ele/src/api/layout/index.ts @@ -3,6 +3,17 @@ import type { ApiResult } from '@/api'; import type { User } from '@/api/system/user/model'; import type { UpdatePasswordParam } from './model'; +/** + * 退出登录 + */ +export async function userLogout() { + const res = await request.post>('/auth/logout'); + if (res.data.code === 0) { + return res.data.message; + } + return Promise.reject(new Error(res.data.message)); +} + /** * 获取当前登录用户的个人信息/菜单/权限/角色 */ diff --git a/z_ele/src/utils/common.ts b/z_ele/src/utils/common.ts index 4d91f6b..f1ffcc7 100644 --- a/z_ele/src/utils/common.ts +++ b/z_ele/src/utils/common.ts @@ -2,6 +2,7 @@ import type { Router } from 'vue-router'; import type { Action } from 'element-plus'; import { ElMessageBox } from 'element-plus'; import { removeToken } from '@/utils/token-util'; +import { userLogout } from '@/api/layout'; /** * 退出登录 @@ -9,7 +10,12 @@ import { removeToken } from '@/utils/token-util'; * @param from 登录后跳转的地址 * @param push 路由跳转方法 */ -export function logout(route?: boolean, from?: string, push?: Router['push']) { +export async function logout( + route?: boolean, + from?: string, + push?: Router['push'] +) { + await userLogout(); removeToken(); if (route && push) { push({ diff --git a/z_ele/src/views/system/login-record/index.vue b/z_ele/src/views/system/login-record/index.vue index 9acbb1c..7d13599 100644 --- a/z_ele/src/views/system/login-record/index.vue +++ b/z_ele/src/views/system/login-record/index.vue @@ -36,7 +36,10 @@ type="danger" :disable-transitions="true" > - 登录失败 - {{ row.loginType }} + 登录失败/用户名错误 + 密码错误 + 用户已被禁用 + 登录异常 @@ -107,8 +110,7 @@ { prop: 'loginType', label: '操作类型', - sortable: 'custom', - width: 130, + width: 140, slot: 'loginType', filters: [ { @@ -136,8 +138,7 @@ value: '98' } ], - filterMultiple: false, - align: 'center' + filterMultiple: false }, { prop: 'comments',