提交 58940930 编写于 作者: V vben

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

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