提交 58940930 编写于 作者: V vben

perf: adjust the return value of the interface to obtain user information in array format #259

上级 993538de
......@@ -6,6 +6,10 @@
- 升级 husky 到 5.0
- 新增 `brotli`|`gzip`压缩及相关测试命令
### ⚡ Performance Improvements
- 调整获取用户信息接口返回值为数组格式
### 🐛 Bug Fixes
- 修复 Upload 组件 maxNumber 失效问题
......
......@@ -10,10 +10,12 @@ function createFakeUserList() {
desc: 'manager',
password: '123456',
token: 'fakeToken1',
role: {
roleName: 'Super Admin',
value: 'super',
},
roles: [
{
roleName: 'Super Admin',
value: 'super',
},
],
},
{
userId: '2',
......@@ -22,10 +24,12 @@ function createFakeUserList() {
realName: 'test user',
desc: 'tester',
token: 'fakeToken2',
role: {
roleName: 'Tester',
value: 'test',
},
roles: [
{
roleName: 'Tester',
value: 'test',
},
],
},
];
}
......@@ -49,9 +53,9 @@ export default [
if (!checkUser) {
return resultError('Incorrect account or password!');
}
const { userId, username: _username, token, realName, desc, role } = checkUser;
const { userId, username: _username, token, realName, desc, roles } = checkUser;
return resultSuccess({
role,
roles,
userId,
username: _username,
token,
......
......@@ -113,7 +113,8 @@
},
"resolutions": {
"//": "Used to install imagemin dependencies, because imagemin may not be installed in China.If it is abroad, you can delete it",
"bin-wrapper": "npm:bin-wrapper-china"
"bin-wrapper": "npm:bin-wrapper-china",
"ecstatic": "4.1.4"
},
"repository": {
"type": "git",
......
......@@ -31,7 +31,7 @@ export interface LoginResultModel {
* @description: Get user information return value
*/
export interface GetUserInfoByUserIdModel {
role: RoleInfo;
roles: RoleInfo[];
// 用户id
userId: string | number;
// 用户名
......
......@@ -113,8 +113,6 @@ class User extends VuexModule {
// get user info
const userInfo = await this.getUserInfoAction({ userId });
// const name = FULL_PAGE_NOT_FOUND_ROUTE.name;
// name && router.removeRoute(name);
goHome && (await router.replace(PageEnum.BASE_HOME));
return userInfo;
} catch (error) {
......@@ -125,8 +123,8 @@ class User extends VuexModule {
@Action
async getUserInfoAction({ userId }: GetUserInfoByUserIdParams) {
const userInfo = await getUserInfoById({ userId });
const { role } = userInfo;
const roleList = [role.value] as RoleEnum[];
const { roles } = userInfo;
const roleList = roles.map((item) => item.value) as RoleEnum[];
this.commitUserInfoState(userInfo);
this.commitRoleListState(roleList);
return userInfo;
......
......@@ -6,14 +6,13 @@ import { isFunction } from '/@/utils/is';
import { cloneDeep } from 'lodash-es';
import type { RequestOptions, CreateAxiosOptions, Result, UploadFileParams } from './types';
// import { ContentTypeEnum } from '/@/enums/httpEnum';
import { errorResult } from './const';
import { ContentTypeEnum } from '/@/enums/httpEnum';
export * from './axiosTransform';
/**
* @description: axios模块
* @description: axios module
*/
export class VAxios {
private axiosInstance: AxiosInstance;
......@@ -26,7 +25,7 @@ export class VAxios {
}
/**
* @description: 创建axios实例
* @description: Create axios instance
*/
private createAxios(config: CreateAxiosOptions): void {
this.axiosInstance = axios.create(config);
......@@ -42,7 +41,7 @@ export class VAxios {
}
/**
* @description: 重新配置axios
* @description: Reconfigure axios
*/
configAxios(config: CreateAxiosOptions) {
if (!this.axiosInstance) {
......@@ -52,7 +51,7 @@ export class VAxios {
}
/**
* @description: 设置通用header
* @description: Set general header
*/
setHeader(headers: any): void {
if (!this.axiosInstance) {
......@@ -62,7 +61,7 @@ export class VAxios {
}
/**
* @description: 拦截器配置
* @description: Interceptor configuration
*/
private setupInterceptors() {
const transform = this.getTransform();
......@@ -78,7 +77,7 @@ export class VAxios {
const axiosCanceler = new AxiosCanceler();
// 请求拦截器配置处理
// Request interceptor configuration processing
this.axiosInstance.interceptors.request.use((config: AxiosRequestConfig) => {
// If cancel repeat request is turned on, then cancel repeat request is prohibited
const {
......@@ -91,12 +90,12 @@ export class VAxios {
return config;
}, undefined);
// 请求拦截器错误捕获
// Request interceptor error capture
requestInterceptorsCatch &&
isFunction(requestInterceptorsCatch) &&
this.axiosInstance.interceptors.request.use(undefined, requestInterceptorsCatch);
// 响应结果拦截器处理
// Response result interceptor processing
this.axiosInstance.interceptors.response.use((res: AxiosResponse<any>) => {
res && axiosCanceler.removePending(res.config);
if (responseInterceptors && isFunction(responseInterceptors)) {
......@@ -105,14 +104,14 @@ export class VAxios {
return res;
}, undefined);
// 响应结果拦截器错误捕获
// Response result interceptor error capture
responseInterceptorsCatch &&
isFunction(responseInterceptorsCatch) &&
this.axiosInstance.interceptors.response.use(undefined, responseInterceptorsCatch);
}
/**
* @description: 文件上传
* @description: File Upload
*/
uploadFile<T = any>(config: AxiosRequestConfig, params: UploadFileParams) {
const formData = new window.FormData();
......@@ -145,9 +144,6 @@ export class VAxios {
});
}
/**
* @description: 请求方法
*/
request<T = any>(config: AxiosRequestConfig, options?: RequestOptions): Promise<T> {
let conf: AxiosRequestConfig = cloneDeep(config);
const transform = this.getTransform();
......
......@@ -10,9 +10,9 @@ export function checkStatus(status: number, msg: string): void {
case 400:
error(`${msg}`);
break;
// 401: 未登录
// 未登录则跳转登录页面,并携带当前页面的路径
// 在登录成功后返回当前页面,这一步需要在登录页操作。
// 401: Not logged in
// Jump to the login page if not logged in, and carry the path of the current page
// Return to the current page after successful login. This step needs to be operated on the login page.
case 401:
error(t('sys.api.errMsg401'));
userStore.loginOut(true);
......
......@@ -2807,6 +2807,11 @@ chardet@^0.7.0:
resolved "https://registry.npmjs.org/chardet/-/chardet-0.7.0.tgz#90094849f0937f2eedc2425d0d28a9e5f0cbad9e"
integrity sha512-mT8iDcrh03qDGRRmoA2hmBJnxpllMR+0/0qlzjqZES6NdiWDcZkCNAk4rPFZ9Q85r27unkiNNg8ZOiwZXBHwcA==
charset@^1.0.1:
version "1.0.1"
resolved "https://registry.npmjs.org/charset/-/charset-1.0.1.tgz#8d59546c355be61049a8fa9164747793319852bd"
integrity sha512-6dVyOOYjpfFcL1Y4qChrAoQLRHvj2ziyhcm0QJlhOcAhykL/k1kTUPbeo+87MNRTRdk2OIIsIXbuF3x2wi5EXg==
chokidar@^3.5.1:
version "3.5.1"
resolved "https://registry.npmjs.org/chokidar/-/chokidar-3.5.1.tgz#ee9ce7bbebd2b79f49f304799d5468e31e14e68a"
......@@ -3811,15 +3816,17 @@ echarts@^4.9.0:
dependencies:
zrender "4.3.2"
ecstatic@^3.3.2:
version "3.3.2"
resolved "https://registry.npmjs.org/ecstatic/-/ecstatic-3.3.2.tgz#6d1dd49814d00594682c652adb66076a69d46c48"
integrity sha512-fLf9l1hnwrHI2xn9mEDT7KIi22UDqA2jaCwyCbSUJh9a1V+LEUSL/JO/6TIz/QyuBURWUHrFL5Kg2TtO1bkkog==
ecstatic@4.1.4, ecstatic@^3.3.2:
version "4.1.4"
resolved "https://registry.npmjs.org/ecstatic/-/ecstatic-4.1.4.tgz#86bf340dabe56c4d0c93d406ac36c040f68e1d79"
integrity sha512-8E4ZLK4uRuB9pwywGpy/B9vcz4gCp6IY7u4cMbeCINr/fjb1v+0wf0Ae2XlfSnG8xZYnE4uaJBjFkYI0bqcIdw==
dependencies:
charset "^1.0.1"
he "^1.1.1"
mime "^1.6.0"
mime "^2.4.1"
minimist "^1.1.0"
url-join "^2.0.5"
on-finished "^2.3.0"
url-join "^4.0.0"
ee-first@1.1.1:
version "1.1.1"
......@@ -6416,11 +6423,16 @@ mime-types@~2.1.24:
dependencies:
mime-db "1.45.0"
mime@^1.4.1, mime@^1.6.0:
mime@^1.4.1:
version "1.6.0"
resolved "https://registry.npmjs.org/mime/-/mime-1.6.0.tgz#32cd9e5c64553bd58d19a568af452acff04981b1"
integrity sha512-x0Vn8spI+wuJ1O6S7gnbaQg8Pxh4NNHb7KSINmEWKiPE4RKOplvijn+NkmYmmRgP68mc70j2EbeTFRsrswaQeg==
mime@^2.4.1:
version "2.5.0"
resolved "https://registry.npmjs.org/mime/-/mime-2.5.0.tgz#2b4af934401779806ee98026bb42e8c1ae1876b1"
integrity sha512-ft3WayFSFUVBuJj7BMLKAQcSlItKtfjsKDDsii3rqFDAZ7t11zRe8ASw/GlmivGwVUYtwkQrxiGGpL6gFvB0ag==
mimic-fn@^1.0.0:
version "1.2.0"
resolved "https://registry.npmjs.org/mimic-fn/-/mimic-fn-1.2.0.tgz#820c86a39334640e99516928bd03fca88057d022"
......@@ -6768,7 +6780,7 @@ omit.js@^2.0.0:
resolved "https://registry.npmjs.org/omit.js/-/omit.js-2.0.2.tgz#dd9b8436fab947a5f3ff214cb2538631e313ec2f"
integrity sha512-hJmu9D+bNB40YpL9jYebQl4lsTW6yEHRTroJzNLqQJYHm7c+NQnJGfZmIWh8S3q3KoaxV1aLhV6B3+0N0/kyJg==
on-finished@~2.3.0:
on-finished@^2.3.0, on-finished@~2.3.0:
version "2.3.0"
resolved "https://registry.npmjs.org/on-finished/-/on-finished-2.3.0.tgz#20f1336481b083cd75337992a16971aa2d906947"
integrity sha1-IPEzZIGwg811M3mSoWlxqi2QaUc=
......@@ -9166,10 +9178,10 @@ urix@^0.1.0:
resolved "https://registry.npmjs.org/urix/-/urix-0.1.0.tgz#da937f7a62e21fec1fd18d49b35c2935067a6c72"
integrity sha1-2pN/emLiH+wf0Y1Js1wpNQZ6bHI=
url-join@^2.0.5:
version "2.0.5"
resolved "https://registry.npmjs.org/url-join/-/url-join-2.0.5.tgz#5af22f18c052a000a48d7b82c5e9c2e2feeda728"
integrity sha1-WvIvGMBSoACkjXuCxenC4v7tpyg=
url-join@^4.0.0:
version "4.0.1"
resolved "https://registry.npmjs.org/url-join/-/url-join-4.0.1.tgz#b642e21a2646808ffa178c4c5fda39844e12cde7"
integrity sha512-jk1+QP6ZJqyOiuEI9AEWQfju/nB2Pw466kbA0LEZljHwKeMgd9WrAEgEGxjPDD2+TNbbb37rTyhEfrCXfuKXnA==
url-parse-lax@^1.0.0:
version "1.0.0"
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册