From 09c5f959e241328fa905ac4097d97a9553cc33d1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=9A=93=E6=9C=88=E5=BD=92=E5=B0=98?= Date: Tue, 26 Mar 2024 17:52:47 +0800 Subject: [PATCH] =?UTF-8?q?types:=20=E5=B0=81=E8=A3=85=E9=80=9A=E7=94=A8?= =?UTF-8?q?=E8=AF=B7=E6=B1=82=E7=B1=BB=E5=9E=8B=EF=BC=8C=E5=87=8F=E5=B0=91?= =?UTF-8?q?=E9=87=8D=E5=A4=8D=E7=B1=BB=E5=9E=8B=E5=AE=9A=E4=B9=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/api/list.ts | 7 ++----- src/api/mock.ts | 9 ++------- src/api/routes.ts | 8 ++------ src/api/system.ts | 38 +++++++++++++++----------------------- src/api/user.ts | 38 ++++++++++++++++---------------------- src/store/modules/user.ts | 28 +++++++++++++++------------- src/utils/http/index.ts | 6 +++--- types/global.d.ts | 6 ++++++ 8 files changed, 61 insertions(+), 79 deletions(-) diff --git a/src/api/list.ts b/src/api/list.ts index c0017843f..3cf28e468 100644 --- a/src/api/list.ts +++ b/src/api/list.ts @@ -1,11 +1,8 @@ import { http } from "@/utils/http"; type Result = { - success: boolean; - data?: { - /** 列表数据 */ - list: Array; - }; + /** 列表数据 */ + list: Array; }; /** 卡片列表 */ diff --git a/src/api/mock.ts b/src/api/mock.ts index 549e9d09b..198b3b6e8 100644 --- a/src/api/mock.ts +++ b/src/api/mock.ts @@ -1,18 +1,13 @@ import { http } from "@/utils/http"; -type Result = { - success: boolean; - data: Array; -}; - /** 地图数据 */ export const mapJson = (params?: object) => { - return http.request("get", "/get-map-info", { params }); + return http.request>("get", "/get-map-info", { params }); }; /** 文件上传 */ export const formUpload = data => { - return http.request( + return http.request>( "post", "https://run.mocky.io/v3/3aa761d7-b0b3-4a03-96b3-6168d4f7467b", { data }, diff --git a/src/api/routes.ts b/src/api/routes.ts index 501ea3c7a..d5f454f5b 100644 --- a/src/api/routes.ts +++ b/src/api/routes.ts @@ -1,10 +1,6 @@ import { http } from "@/utils/http"; -type Result = { - success: boolean; - data: Array; -}; - +/**动态路由 */ export const getAsyncRoutes = () => { - return http.request("get", "/get-async-routes"); + return http.request>("get", "/get-async-routes"); }; diff --git a/src/api/system.ts b/src/api/system.ts index e4db23811..8f77ad5a2 100644 --- a/src/api/system.ts +++ b/src/api/system.ts @@ -1,22 +1,14 @@ import { http } from "@/utils/http"; -type Result = { - success: boolean; - data?: Array; -}; - type ResultTable = { - success: boolean; - data?: { - /** 列表数据 */ - list: Array; - /** 总条目数 */ - total?: number; - /** 每页显示条目个数 */ - pageSize?: number; - /** 当前页数 */ - currentPage?: number; - }; + /** 列表数据 */ + list: Array; + /** 总条目数 */ + total?: number; + /** 每页显示条目个数 */ + pageSize?: number; + /** 当前页数 */ + currentPage?: number; }; /** 获取系统管理-用户管理列表 */ @@ -26,12 +18,12 @@ export const getUserList = (data?: object) => { /** 系统管理-用户管理-获取所有角色列表 */ export const getAllRoleList = () => { - return http.request("get", "/list-all-role"); + return http.request>("get", "/list-all-role"); }; /** 系统管理-用户管理-根据userId,获取对应角色id列表(userId:用户id) */ export const getRoleIds = (data?: object) => { - return http.request("post", "/list-role-ids", { data }); + return http.request>("post", "/list-role-ids", { data }); }; /** 获取系统管理-角色管理列表 */ @@ -41,12 +33,12 @@ export const getRoleList = (data?: object) => { /** 获取系统管理-菜单管理列表 */ export const getMenuList = (data?: object) => { - return http.request("post", "/menu", { data }); + return http.request>("post", "/menu", { data }); }; /** 获取系统管理-部门管理列表 */ export const getDeptList = (data?: object) => { - return http.request("post", "/dept", { data }); + return http.request>("post", "/dept", { data }); }; /** 获取系统监控-在线用户列表 */ @@ -71,15 +63,15 @@ export const getSystemLogsList = (data?: object) => { /** 获取系统监控-系统日志-根据 id 查日志详情 */ export const getSystemLogsDetail = (data?: object) => { - return http.request("post", "/system-logs-detail", { data }); + return http.request>("post", "/system-logs-detail", { data }); }; /** 获取角色管理-权限-菜单权限 */ export const getRoleMenu = (data?: object) => { - return http.request("post", "/role-menu", { data }); + return http.request>("post", "/role-menu", { data }); }; /** 获取角色管理-权限-菜单权限-根据角色 id 查对应菜单 */ export const getRoleMenuIds = (data?: object) => { - return http.request("post", "/role-menu-ids", { data }); + return http.request>("post", "/role-menu-ids", { data }); }; diff --git a/src/api/user.ts b/src/api/user.ts index 66a797cb9..d486a99d6 100644 --- a/src/api/user.ts +++ b/src/api/user.ts @@ -1,31 +1,25 @@ import { http } from "@/utils/http"; export type UserResult = { - success: boolean; - data: { - /** 用户名 */ - username: string; - /** 当前登陆用户的角色 */ - roles: Array; - /** `token` */ - accessToken: string; - /** 用于调用刷新`accessToken`的接口时所需的`token` */ - refreshToken: string; - /** `accessToken`的过期时间(格式'xxxx/xx/xx xx:xx:xx') */ - expires: Date; - }; + /** 用户名 */ + username: string; + /** 当前登陆用户的角色 */ + roles: Array; + /** `token` */ + accessToken: string; + /** 用于调用刷新`accessToken`的接口时所需的`token` */ + refreshToken: string; + /** `accessToken`的过期时间(格式'xxxx/xx/xx xx:xx:xx') */ + expires: Date; }; export type RefreshTokenResult = { - success: boolean; - data: { - /** `token` */ - accessToken: string; - /** 用于调用刷新`accessToken`的接口时所需的`token` */ - refreshToken: string; - /** `accessToken`的过期时间(格式'xxxx/xx/xx xx:xx:xx') */ - expires: Date; - }; + /** `token` */ + accessToken: string; + /** 用于调用刷新`accessToken`的接口时所需的`token` */ + refreshToken: string; + /** `accessToken`的过期时间(格式'xxxx/xx/xx xx:xx:xx') */ + expires: Date; }; /** 登录 */ diff --git a/src/store/modules/user.ts b/src/store/modules/user.ts index f2ecab4c1..471fe7683 100644 --- a/src/store/modules/user.ts +++ b/src/store/modules/user.ts @@ -52,7 +52,7 @@ export const useUserStore = defineStore({ }, /** 登入 */ async loginByUsername(data) { - return new Promise((resolve, reject) => { + return new Promise>((resolve, reject) => { getLogin(data) .then(data => { if (data) { @@ -76,18 +76,20 @@ export const useUserStore = defineStore({ }, /** 刷新`token` */ async handRefreshToken(data) { - return new Promise((resolve, reject) => { - refreshTokenApi(data) - .then(data => { - if (data) { - setToken(data.data); - resolve(data); - } - }) - .catch(error => { - reject(error); - }); - }); + return new Promise>( + (resolve, reject) => { + refreshTokenApi(data) + .then(data => { + if (data) { + setToken(data.data); + resolve(data); + } + }) + .catch(error => { + reject(error); + }); + } + ); } } }); diff --git a/src/utils/http/index.ts b/src/utils/http/index.ts index 5f40e6969..4453bf0c0 100644 --- a/src/utils/http/index.ts +++ b/src/utils/http/index.ts @@ -151,7 +151,7 @@ class PureHttp { url: string, param?: AxiosRequestConfig, axiosConfig?: PureHttpRequestConfig - ): Promise { + ): Promise> { const config = { method, url, @@ -177,7 +177,7 @@ class PureHttp { url: string, params?: AxiosRequestConfig, config?: PureHttpRequestConfig - ): Promise

{ + ): Promise> { return this.request

("post", url, params, config); } @@ -186,7 +186,7 @@ class PureHttp { url: string, params?: AxiosRequestConfig, config?: PureHttpRequestConfig - ): Promise

{ + ): Promise> { return this.request

("get", url, params, config); } } diff --git a/types/global.d.ts b/types/global.d.ts index 087e5c719..48f3123e2 100644 --- a/types/global.d.ts +++ b/types/global.d.ts @@ -205,4 +205,10 @@ declare global { touched?: boolean; }; } + + /**通用请求响应类型 */ + interface ResponseResult { + success: boolean; + data?: T; + } }