Commit 589409305f58ebc2f6b110bd7b31f924ecd06c16
1 parent
993538de
perf: adjust the return value of the interface to obtain user information in array format #259
Showing
8 changed files
with
60 additions
and
45 deletions
CHANGELOG.zh_CN.md
mock/sys/user.ts
... | ... | @@ -10,10 +10,12 @@ function createFakeUserList() { |
10 | 10 | desc: 'manager', |
11 | 11 | password: '123456', |
12 | 12 | token: 'fakeToken1', |
13 | - role: { | |
14 | - roleName: 'Super Admin', | |
15 | - value: 'super', | |
16 | - }, | |
13 | + roles: [ | |
14 | + { | |
15 | + roleName: 'Super Admin', | |
16 | + value: 'super', | |
17 | + }, | |
18 | + ], | |
17 | 19 | }, |
18 | 20 | { |
19 | 21 | userId: '2', |
... | ... | @@ -22,10 +24,12 @@ function createFakeUserList() { |
22 | 24 | realName: 'test user', |
23 | 25 | desc: 'tester', |
24 | 26 | token: 'fakeToken2', |
25 | - role: { | |
26 | - roleName: 'Tester', | |
27 | - value: 'test', | |
28 | - }, | |
27 | + roles: [ | |
28 | + { | |
29 | + roleName: 'Tester', | |
30 | + value: 'test', | |
31 | + }, | |
32 | + ], | |
29 | 33 | }, |
30 | 34 | ]; |
31 | 35 | } |
... | ... | @@ -49,9 +53,9 @@ export default [ |
49 | 53 | if (!checkUser) { |
50 | 54 | return resultError('Incorrect account or password!'); |
51 | 55 | } |
52 | - const { userId, username: _username, token, realName, desc, role } = checkUser; | |
56 | + const { userId, username: _username, token, realName, desc, roles } = checkUser; | |
53 | 57 | return resultSuccess({ |
54 | - role, | |
58 | + roles, | |
55 | 59 | userId, |
56 | 60 | username: _username, |
57 | 61 | token, | ... | ... |
package.json
... | ... | @@ -113,7 +113,8 @@ |
113 | 113 | }, |
114 | 114 | "resolutions": { |
115 | 115 | "//": "Used to install imagemin dependencies, because imagemin may not be installed in China.If it is abroad, you can delete it", |
116 | - "bin-wrapper": "npm:bin-wrapper-china" | |
116 | + "bin-wrapper": "npm:bin-wrapper-china", | |
117 | + "ecstatic": "4.1.4" | |
117 | 118 | }, |
118 | 119 | "repository": { |
119 | 120 | "type": "git", | ... | ... |
src/api/sys/model/userModel.ts
src/store/modules/user.ts
... | ... | @@ -113,8 +113,6 @@ class User extends VuexModule { |
113 | 113 | // get user info |
114 | 114 | const userInfo = await this.getUserInfoAction({ userId }); |
115 | 115 | |
116 | - // const name = FULL_PAGE_NOT_FOUND_ROUTE.name; | |
117 | - // name && router.removeRoute(name); | |
118 | 116 | goHome && (await router.replace(PageEnum.BASE_HOME)); |
119 | 117 | return userInfo; |
120 | 118 | } catch (error) { |
... | ... | @@ -125,8 +123,8 @@ class User extends VuexModule { |
125 | 123 | @Action |
126 | 124 | async getUserInfoAction({ userId }: GetUserInfoByUserIdParams) { |
127 | 125 | const userInfo = await getUserInfoById({ userId }); |
128 | - const { role } = userInfo; | |
129 | - const roleList = [role.value] as RoleEnum[]; | |
126 | + const { roles } = userInfo; | |
127 | + const roleList = roles.map((item) => item.value) as RoleEnum[]; | |
130 | 128 | this.commitUserInfoState(userInfo); |
131 | 129 | this.commitRoleListState(roleList); |
132 | 130 | return userInfo; | ... | ... |
src/utils/http/axios/Axios.ts
... | ... | @@ -6,14 +6,13 @@ import { isFunction } from '/@/utils/is'; |
6 | 6 | import { cloneDeep } from 'lodash-es'; |
7 | 7 | |
8 | 8 | import type { RequestOptions, CreateAxiosOptions, Result, UploadFileParams } from './types'; |
9 | -// import { ContentTypeEnum } from '/@/enums/httpEnum'; | |
10 | 9 | import { errorResult } from './const'; |
11 | 10 | import { ContentTypeEnum } from '/@/enums/httpEnum'; |
12 | 11 | |
13 | 12 | export * from './axiosTransform'; |
14 | 13 | |
15 | 14 | /** |
16 | - * @description: axios模块 | |
15 | + * @description: axios module | |
17 | 16 | */ |
18 | 17 | export class VAxios { |
19 | 18 | private axiosInstance: AxiosInstance; |
... | ... | @@ -26,7 +25,7 @@ export class VAxios { |
26 | 25 | } |
27 | 26 | |
28 | 27 | /** |
29 | - * @description: 创建axios实例 | |
28 | + * @description: Create axios instance | |
30 | 29 | */ |
31 | 30 | private createAxios(config: CreateAxiosOptions): void { |
32 | 31 | this.axiosInstance = axios.create(config); |
... | ... | @@ -42,7 +41,7 @@ export class VAxios { |
42 | 41 | } |
43 | 42 | |
44 | 43 | /** |
45 | - * @description: 重新配置axios | |
44 | + * @description: Reconfigure axios | |
46 | 45 | */ |
47 | 46 | configAxios(config: CreateAxiosOptions) { |
48 | 47 | if (!this.axiosInstance) { |
... | ... | @@ -52,7 +51,7 @@ export class VAxios { |
52 | 51 | } |
53 | 52 | |
54 | 53 | /** |
55 | - * @description: 设置通用header | |
54 | + * @description: Set general header | |
56 | 55 | */ |
57 | 56 | setHeader(headers: any): void { |
58 | 57 | if (!this.axiosInstance) { |
... | ... | @@ -62,7 +61,7 @@ export class VAxios { |
62 | 61 | } |
63 | 62 | |
64 | 63 | /** |
65 | - * @description: 拦截器配置 | |
64 | + * @description: Interceptor configuration | |
66 | 65 | */ |
67 | 66 | private setupInterceptors() { |
68 | 67 | const transform = this.getTransform(); |
... | ... | @@ -78,7 +77,7 @@ export class VAxios { |
78 | 77 | |
79 | 78 | const axiosCanceler = new AxiosCanceler(); |
80 | 79 | |
81 | - // 请求拦截器配置处理 | |
80 | + // Request interceptor configuration processing | |
82 | 81 | this.axiosInstance.interceptors.request.use((config: AxiosRequestConfig) => { |
83 | 82 | // If cancel repeat request is turned on, then cancel repeat request is prohibited |
84 | 83 | const { |
... | ... | @@ -91,12 +90,12 @@ export class VAxios { |
91 | 90 | return config; |
92 | 91 | }, undefined); |
93 | 92 | |
94 | - // 请求拦截器错误捕获 | |
93 | + // Request interceptor error capture | |
95 | 94 | requestInterceptorsCatch && |
96 | 95 | isFunction(requestInterceptorsCatch) && |
97 | 96 | this.axiosInstance.interceptors.request.use(undefined, requestInterceptorsCatch); |
98 | 97 | |
99 | - // 响应结果拦截器处理 | |
98 | + // Response result interceptor processing | |
100 | 99 | this.axiosInstance.interceptors.response.use((res: AxiosResponse<any>) => { |
101 | 100 | res && axiosCanceler.removePending(res.config); |
102 | 101 | if (responseInterceptors && isFunction(responseInterceptors)) { |
... | ... | @@ -105,14 +104,14 @@ export class VAxios { |
105 | 104 | return res; |
106 | 105 | }, undefined); |
107 | 106 | |
108 | - // 响应结果拦截器错误捕获 | |
107 | + // Response result interceptor error capture | |
109 | 108 | responseInterceptorsCatch && |
110 | 109 | isFunction(responseInterceptorsCatch) && |
111 | 110 | this.axiosInstance.interceptors.response.use(undefined, responseInterceptorsCatch); |
112 | 111 | } |
113 | 112 | |
114 | 113 | /** |
115 | - * @description: 文件上传 | |
114 | + * @description: File Upload | |
116 | 115 | */ |
117 | 116 | uploadFile<T = any>(config: AxiosRequestConfig, params: UploadFileParams) { |
118 | 117 | const formData = new window.FormData(); |
... | ... | @@ -145,9 +144,6 @@ export class VAxios { |
145 | 144 | }); |
146 | 145 | } |
147 | 146 | |
148 | - /** | |
149 | - * @description: 请求方法 | |
150 | - */ | |
151 | 147 | request<T = any>(config: AxiosRequestConfig, options?: RequestOptions): Promise<T> { |
152 | 148 | let conf: AxiosRequestConfig = cloneDeep(config); |
153 | 149 | const transform = this.getTransform(); | ... | ... |
src/utils/http/axios/checkStatus.ts
... | ... | @@ -10,9 +10,9 @@ export function checkStatus(status: number, msg: string): void { |
10 | 10 | case 400: |
11 | 11 | error(`${msg}`); |
12 | 12 | break; |
13 | - // 401: 未登录 | |
14 | - // 未登录则跳转登录页面,并携带当前页面的路径 | |
15 | - // 在登录成功后返回当前页面,这一步需要在登录页操作。 | |
13 | + // 401: Not logged in | |
14 | + // Jump to the login page if not logged in, and carry the path of the current page | |
15 | + // Return to the current page after successful login. This step needs to be operated on the login page. | |
16 | 16 | case 401: |
17 | 17 | error(t('sys.api.errMsg401')); |
18 | 18 | userStore.loginOut(true); | ... | ... |
yarn.lock
... | ... | @@ -2807,6 +2807,11 @@ chardet@^0.7.0: |
2807 | 2807 | resolved "https://registry.npmjs.org/chardet/-/chardet-0.7.0.tgz#90094849f0937f2eedc2425d0d28a9e5f0cbad9e" |
2808 | 2808 | integrity sha512-mT8iDcrh03qDGRRmoA2hmBJnxpllMR+0/0qlzjqZES6NdiWDcZkCNAk4rPFZ9Q85r27unkiNNg8ZOiwZXBHwcA== |
2809 | 2809 | |
2810 | +charset@^1.0.1: | |
2811 | + version "1.0.1" | |
2812 | + resolved "https://registry.npmjs.org/charset/-/charset-1.0.1.tgz#8d59546c355be61049a8fa9164747793319852bd" | |
2813 | + integrity sha512-6dVyOOYjpfFcL1Y4qChrAoQLRHvj2ziyhcm0QJlhOcAhykL/k1kTUPbeo+87MNRTRdk2OIIsIXbuF3x2wi5EXg== | |
2814 | + | |
2810 | 2815 | chokidar@^3.5.1: |
2811 | 2816 | version "3.5.1" |
2812 | 2817 | resolved "https://registry.npmjs.org/chokidar/-/chokidar-3.5.1.tgz#ee9ce7bbebd2b79f49f304799d5468e31e14e68a" |
... | ... | @@ -3811,15 +3816,17 @@ echarts@^4.9.0: |
3811 | 3816 | dependencies: |
3812 | 3817 | zrender "4.3.2" |
3813 | 3818 | |
3814 | -ecstatic@^3.3.2: | |
3815 | - version "3.3.2" | |
3816 | - resolved "https://registry.npmjs.org/ecstatic/-/ecstatic-3.3.2.tgz#6d1dd49814d00594682c652adb66076a69d46c48" | |
3817 | - integrity sha512-fLf9l1hnwrHI2xn9mEDT7KIi22UDqA2jaCwyCbSUJh9a1V+LEUSL/JO/6TIz/QyuBURWUHrFL5Kg2TtO1bkkog== | |
3819 | +ecstatic@4.1.4, ecstatic@^3.3.2: | |
3820 | + version "4.1.4" | |
3821 | + resolved "https://registry.npmjs.org/ecstatic/-/ecstatic-4.1.4.tgz#86bf340dabe56c4d0c93d406ac36c040f68e1d79" | |
3822 | + integrity sha512-8E4ZLK4uRuB9pwywGpy/B9vcz4gCp6IY7u4cMbeCINr/fjb1v+0wf0Ae2XlfSnG8xZYnE4uaJBjFkYI0bqcIdw== | |
3818 | 3823 | dependencies: |
3824 | + charset "^1.0.1" | |
3819 | 3825 | he "^1.1.1" |
3820 | - mime "^1.6.0" | |
3826 | + mime "^2.4.1" | |
3821 | 3827 | minimist "^1.1.0" |
3822 | - url-join "^2.0.5" | |
3828 | + on-finished "^2.3.0" | |
3829 | + url-join "^4.0.0" | |
3823 | 3830 | |
3824 | 3831 | ee-first@1.1.1: |
3825 | 3832 | version "1.1.1" |
... | ... | @@ -6416,11 +6423,16 @@ mime-types@~2.1.24: |
6416 | 6423 | dependencies: |
6417 | 6424 | mime-db "1.45.0" |
6418 | 6425 | |
6419 | -mime@^1.4.1, mime@^1.6.0: | |
6426 | +mime@^1.4.1: | |
6420 | 6427 | version "1.6.0" |
6421 | 6428 | resolved "https://registry.npmjs.org/mime/-/mime-1.6.0.tgz#32cd9e5c64553bd58d19a568af452acff04981b1" |
6422 | 6429 | integrity sha512-x0Vn8spI+wuJ1O6S7gnbaQg8Pxh4NNHb7KSINmEWKiPE4RKOplvijn+NkmYmmRgP68mc70j2EbeTFRsrswaQeg== |
6423 | 6430 | |
6431 | +mime@^2.4.1: | |
6432 | + version "2.5.0" | |
6433 | + resolved "https://registry.npmjs.org/mime/-/mime-2.5.0.tgz#2b4af934401779806ee98026bb42e8c1ae1876b1" | |
6434 | + integrity sha512-ft3WayFSFUVBuJj7BMLKAQcSlItKtfjsKDDsii3rqFDAZ7t11zRe8ASw/GlmivGwVUYtwkQrxiGGpL6gFvB0ag== | |
6435 | + | |
6424 | 6436 | mimic-fn@^1.0.0: |
6425 | 6437 | version "1.2.0" |
6426 | 6438 | resolved "https://registry.npmjs.org/mimic-fn/-/mimic-fn-1.2.0.tgz#820c86a39334640e99516928bd03fca88057d022" |
... | ... | @@ -6768,7 +6780,7 @@ omit.js@^2.0.0: |
6768 | 6780 | resolved "https://registry.npmjs.org/omit.js/-/omit.js-2.0.2.tgz#dd9b8436fab947a5f3ff214cb2538631e313ec2f" |
6769 | 6781 | integrity sha512-hJmu9D+bNB40YpL9jYebQl4lsTW6yEHRTroJzNLqQJYHm7c+NQnJGfZmIWh8S3q3KoaxV1aLhV6B3+0N0/kyJg== |
6770 | 6782 | |
6771 | -on-finished@~2.3.0: | |
6783 | +on-finished@^2.3.0, on-finished@~2.3.0: | |
6772 | 6784 | version "2.3.0" |
6773 | 6785 | resolved "https://registry.npmjs.org/on-finished/-/on-finished-2.3.0.tgz#20f1336481b083cd75337992a16971aa2d906947" |
6774 | 6786 | integrity sha1-IPEzZIGwg811M3mSoWlxqi2QaUc= |
... | ... | @@ -9166,10 +9178,10 @@ urix@^0.1.0: |
9166 | 9178 | resolved "https://registry.npmjs.org/urix/-/urix-0.1.0.tgz#da937f7a62e21fec1fd18d49b35c2935067a6c72" |
9167 | 9179 | integrity sha1-2pN/emLiH+wf0Y1Js1wpNQZ6bHI= |
9168 | 9180 | |
9169 | -url-join@^2.0.5: | |
9170 | - version "2.0.5" | |
9171 | - resolved "https://registry.npmjs.org/url-join/-/url-join-2.0.5.tgz#5af22f18c052a000a48d7b82c5e9c2e2feeda728" | |
9172 | - integrity sha1-WvIvGMBSoACkjXuCxenC4v7tpyg= | |
9181 | +url-join@^4.0.0: | |
9182 | + version "4.0.1" | |
9183 | + resolved "https://registry.npmjs.org/url-join/-/url-join-4.0.1.tgz#b642e21a2646808ffa178c4c5fda39844e12cde7" | |
9184 | + integrity sha512-jk1+QP6ZJqyOiuEI9AEWQfju/nB2Pw466kbA0LEZljHwKeMgd9WrAEgEGxjPDD2+TNbbb37rTyhEfrCXfuKXnA== | |
9173 | 9185 | |
9174 | 9186 | url-parse-lax@^1.0.0: |
9175 | 9187 | version "1.0.0" | ... | ... |