From 2cae42e8d9e9892e67aa8a363a6e36b6ce59554a Mon Sep 17 00:00:00 2001 From: ray <1490493387@qq.com> Date: Mon, 13 Jan 2025 18:28:03 +0800 Subject: [PATCH] =?UTF-8?q?style:=20:lipstick:=20mock=E6=8E=A5=E5=8F=A3?= =?UTF-8?q?=E6=A0=B9=E6=8D=AE=20prettier=20=E6=A0=BC=E5=BC=8F=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- mock/base.ts | 5 +---- mock/notice.mock.ts | 11 ++++------- mock/role.mock.ts | 9 ++++----- mock/user.mock.ts | 28 ++++++++++------------------ src/api/auth/index.ts | 18 ++++++++++-------- src/store/modules/user.ts | 8 ++++---- 6 files changed, 33 insertions(+), 46 deletions(-) diff --git a/mock/base.ts b/mock/base.ts index 438e1c1c..e68e642f 100644 --- a/mock/base.ts +++ b/mock/base.ts @@ -3,8 +3,5 @@ import { createDefineMock } from "vite-plugin-mock-dev-server"; export const defineMock = createDefineMock((mock) => { // 拼接url - mock.url = path.join( - import.meta.env.VITE_APP_BASE_API + "/api/v1/", - mock.url - ); + mock.url = path.join(import.meta.env.VITE_APP_BASE_API + "/api/v1/", mock.url); }); diff --git a/mock/notice.mock.ts b/mock/notice.mock.ts index 7b5a37f0..c140c163 100644 --- a/mock/notice.mock.ts +++ b/mock/notice.mock.ts @@ -127,8 +127,7 @@ export default defineMock([ }, { id: 10, - title: - "v2.16.1 版本修复了 WebSocket 重复连接导致的后台线程阻塞问题,优化了通知公告。", + title: "v2.16.1 版本修复了 WebSocket 重复连接导致的后台线程阻塞问题,优化了通知公告。", publishStatus: 1, type: 1, publisherName: "系统管理员", @@ -150,7 +149,7 @@ export default defineMock([ { url: "notices", method: ["POST"], - body({ body }) { + body() { return { code: "00000", data: null, @@ -220,8 +219,7 @@ export default defineMock([ list: [ { id: 10, - title: - "v2.16.1 版本修复了 WebSocket 重复连接导致的后台线程阻塞问题,优化了通知公告。", + title: "v2.16.1 版本修复了 WebSocket 重复连接导致的后台线程阻塞问题,优化了通知公告。", type: 1, level: "L", publisherName: "系统管理员", @@ -403,8 +401,7 @@ const noticeMap: Record = { }, 10: { id: 10, - title: - "v2.16.1 版本修复了 WebSocket 重复连接导致的后台线程阻塞问题,优化了通知公告。", + title: "v2.16.1 版本修复了 WebSocket 重复连接导致的后台线程阻塞问题,优化了通知公告。", publishStatus: 1, type: 1, publisherName: "系统管理员", diff --git a/mock/role.mock.ts b/mock/role.mock.ts index cc870267..ee856999 100644 --- a/mock/role.mock.ts +++ b/mock/role.mock.ts @@ -214,14 +214,13 @@ export default defineMock([ { url: "roles/:id/menuIds", method: ["GET"], - body: ({ params }) => { + body: ({}) => { return { code: "00000", data: [ - 1, 2, 31, 32, 33, 88, 3, 70, 71, 72, 4, 73, 75, 74, 5, 76, 77, 78, 6, - 79, 81, 84, 85, 86, 87, 40, 41, 26, 30, 20, 21, 22, 23, 24, 89, 90, - 91, 36, 37, 38, 39, 93, 94, 95, 97, 102, 89, 90, 91, 93, 94, 95, 97, - 102, 103, 104, + 1, 2, 31, 32, 33, 88, 3, 70, 71, 72, 4, 73, 75, 74, 5, 76, 77, 78, 6, 79, 81, 84, 85, 86, + 87, 40, 41, 26, 30, 20, 21, 22, 23, 24, 89, 90, 91, 36, 37, 38, 39, 93, 94, 95, 97, 102, + 89, 90, 91, 93, 94, 95, 97, 102, 103, 104, ], msg: "一切ok", }; diff --git a/mock/user.mock.ts b/mock/user.mock.ts index e82a2e15..57c8482d 100644 --- a/mock/user.mock.ts +++ b/mock/user.mock.ts @@ -10,8 +10,7 @@ export default defineMock([ userId: 2, username: "admin", nickname: "系统管理员", - avatar: - "https://foruda.gitee.com/images/1723603502796844527/03cdca2a_716974.gif", + avatar: "https://foruda.gitee.com/images/1723603502796844527/03cdca2a_716974.gif", roles: ["ADMIN"], perms: [ "sys:notice:edit", @@ -65,8 +64,7 @@ export default defineMock([ nickname: "系统管理员", mobile: "17621210366", gender: 1, - avatar: - "https://foruda.gitee.com/images/1723603502796844527/03cdca2a_716974.gif", + avatar: "https://foruda.gitee.com/images/1723603502796844527/03cdca2a_716974.gif", email: "", status: 1, deptId: 1, @@ -78,8 +76,7 @@ export default defineMock([ nickname: "测试小用户", mobile: "17621210366", gender: 1, - avatar: - "https://foruda.gitee.com/images/1723603502796844527/03cdca2a_716974.gif", + avatar: "https://foruda.gitee.com/images/1723603502796844527/03cdca2a_716974.gif", email: "youlaitech@163.com", status: 1, deptId: 3, @@ -161,10 +158,8 @@ export default defineMock([ url: "users/_export", method: ["GET"], headers: { - "Content-Disposition": - "attachment; filename=%E7%94%A8%E6%88%B7%E5%88%97%E8%A1%A8.xlsx", - "Content-Type": - "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", + "Content-Disposition": "attachment; filename=%E7%94%A8%E6%88%B7%E5%88%97%E8%A1%A8.xlsx", + "Content-Type": "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", }, }, @@ -177,8 +172,7 @@ export default defineMock([ id: 2, username: "admin", nickname: "系统管理员", - avatar: - "https://foruda.gitee.com/images/1723603502796844527/03cdca2a_716974.gif", + avatar: "https://foruda.gitee.com/images/1723603502796844527/03cdca2a_716974.gif", gender: 1, mobile: "17621210366", email: null, @@ -192,7 +186,7 @@ export default defineMock([ { url: "users/profile", method: ["PUT"], - body({ query }) { + body() { return { code: "00000", data: null, @@ -204,7 +198,7 @@ export default defineMock([ { url: "users/password", method: ["PUT"], - body({ query }) { + body() { return { code: "00000", data: null, @@ -222,8 +216,7 @@ const userMap: Record = { nickname: "系统管理员", mobile: "17621210366", gender: 1, - avatar: - "https://foruda.gitee.com/images/1723603502796844527/03cdca2a_716974.gif", + avatar: "https://foruda.gitee.com/images/1723603502796844527/03cdca2a_716974.gif", email: "", status: 1, deptId: 1, @@ -235,8 +228,7 @@ const userMap: Record = { nickname: "测试小用户", mobile: "17621210366", gender: 1, - avatar: - "https://foruda.gitee.com/images/1723603502796844527/03cdca2a_716974.gif", + avatar: "https://foruda.gitee.com/images/1723603502796844527/03cdca2a_716974.gif", email: "youlaitech@163.com", status: 1, deptId: 3, diff --git a/src/api/auth/index.ts b/src/api/auth/index.ts index 7728ad61..ec95620c 100644 --- a/src/api/auth/index.ts +++ b/src/api/auth/index.ts @@ -4,7 +4,7 @@ const AUTH_BASE_URL = "/api/v1/auth"; const AuthAPI = { /** 登录接口*/ - login(data: LoginData) { + login(data: LoginFormData) { const formData = new FormData(); formData.append("username", data.username); formData.append("password", data.password); @@ -22,17 +22,19 @@ const AuthAPI = { /** 刷新 token 接口*/ refreshToken(refreshToken: string) { + const formData = new FormData(); + formData.append("refreshToken", refreshToken); return request({ url: `${AUTH_BASE_URL}/refresh-token`, method: "post", - data: { refreshToken: refreshToken }, + data: formData, headers: { Authorization: "no-auth", }, }); }, - /** 注销接口*/ + /** 注销接口 */ logout() { return request({ url: `${AUTH_BASE_URL}/logout`, @@ -42,7 +44,7 @@ const AuthAPI = { /** 获取验证码接口*/ getCaptcha() { - return request({ + return request({ url: `${AUTH_BASE_URL}/captcha`, method: "get", }); @@ -51,8 +53,8 @@ const AuthAPI = { export default AuthAPI; -/** 登录请求参数 */ -export interface LoginData { +/** 登录表单数据 */ +export interface LoginFormData { /** 用户名 */ username: string; /** 密码 */ @@ -75,8 +77,8 @@ export interface LoginResult { expiresIn: number; } -/** 验证码响应 */ -export interface CaptchaResult { +/** 验证码信息 */ +export interface CaptchaInfo { /** 验证码缓存key */ captchaKey: string; /** 验证码图片Base64字符串 */ diff --git a/src/store/modules/user.ts b/src/store/modules/user.ts index 273e4fcb..5812f7a5 100644 --- a/src/store/modules/user.ts +++ b/src/store/modules/user.ts @@ -2,7 +2,7 @@ import { store } from "@/store"; import { usePermissionStoreHook } from "@/store/modules/permission"; import { useDictStoreHook } from "@/store/modules/dict"; -import AuthAPI, { type LoginData } from "@/api/auth"; +import AuthAPI, { type LoginFormData } from "@/api/auth"; import UserAPI, { type UserInfo } from "@/api/system/user"; import { setToken, setRefreshToken, getRefreshToken, clearToken } from "@/utils/auth"; @@ -13,12 +13,12 @@ export const useUserStore = defineStore("user", () => { /** * 登录 * - * @param {LoginData} + * @param {LoginFormData} * @returns */ - function login(loginData: LoginData) { + function login(LoginFormData: LoginFormData) { return new Promise((resolve, reject) => { - AuthAPI.login(loginData) + AuthAPI.login(LoginFormData) .then((data) => { const { tokenType, accessToken, refreshToken } = data; setToken(tokenType + " " + accessToken); // Bearer eyJhbGciOiJIUzI1NiJ9.xxx.xxx