Skip to content
This repository was archived by the owner on Aug 12, 2025. It is now read-only.

Commit 59ce68e

Browse files
committed
Merge branch 'master' into feat/fast-login
2 parents 36dfdf6 + 6ae3a5e commit 59ce68e

File tree

8 files changed

+69
-57
lines changed

8 files changed

+69
-57
lines changed

example/xconsole-example/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "xconsole",
3-
"version": "2.3.43",
3+
"version": "2.3.44",
44
"description": "",
55
"main": "src/index.js",
66
"scripts": {
@@ -20,7 +20,7 @@
2020
],
2121
"author": "",
2222
"dependencies": {
23-
"@alicloud/xconsole": "^2.3.43",
23+
"@alicloud/xconsole": "^2.3.44",
2424
"lodash": "^4.17.4",
2525
"moment": "^2.22.1",
2626
"prop-types": "^15.6.1",

lerna.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,6 @@
1313
"tagVersionPrefix": ""
1414
}
1515
},
16-
"version": "2.3.43",
16+
"version": "2.3.44",
1717
"lerna": "2.11.0"
1818
}

packages/console-utils/xconsole-service/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@alicloud/xconsole-service",
3-
"version": "2.4.0-alpha.11",
3+
"version": "2.4.0-alpha.13",
44
"main": "lib/index.js",
55
"module": "es/index.js",
66
"types": "lib/index.d.ts",
@@ -46,6 +46,7 @@
4646
"@ungap/url-search-params": "^0.2.2",
4747
"axios": "^0.19.2",
4848
"js-cookie": "^2.2.1",
49+
"qs": "^6.10.2",
4950
"swr": "^0.2.3",
5051
"tslib": "^2.0.0"
5152
},

packages/console-utils/xconsole-service/src/interceptors/fastloginInterceptor/login.tsx

Lines changed: 46 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -17,22 +17,16 @@ export const refreshToken = async () => {
1717
collina: getCollina(),
1818
};
1919

20-
try {
21-
const res = await axiosInstance({
22-
method: 'get',
23-
url: '/tool/user/info.json',
24-
// url: 'https://oneapi.alibaba-inc.com/mock/oneconsole/data/api.json?product=consoledemo&action=DescribeUserInfo',
25-
data: reqData,
26-
timeout: 15000,
27-
});
20+
const res = await axiosInstance({
21+
method: 'get',
22+
url: '/tool/user/info.json',
23+
data: reqData,
24+
timeout: 15000,
25+
});
2826

29-
const { data: { data: resData } } = res;
30-
// @ts-ignore
31-
window.ALIYUN_CONSOLE_CONFIG && (window.ALIYUN_CONSOLE_CONFIG.SEC_TOKEN = resData?.secToken);
32-
} catch (e) {
33-
console.log('xxxxxxx',e)
34-
// TODO
35-
}
27+
const { data: { data: resData } } = res;
28+
// @ts-ignore
29+
window.ALIYUN_CONSOLE_CONFIG && (window.ALIYUN_CONSOLE_CONFIG.SEC_TOKEN = resData?.secToken);
3630
}
3731

3832
export const LoginContent: React.FC<any> = (props) => {
@@ -49,7 +43,6 @@ export const LoginContent: React.FC<any> = (props) => {
4943
}
5044
props.onSuccess()
5145
} catch(e) {
52-
console.log(e)
5346
props.onError(e);
5447
}
5548
})()
@@ -71,24 +64,34 @@ export const LoginContent: React.FC<any> = (props) => {
7164
)
7265
}
7366

74-
export const login = (response: AxiosResponse) => {
75-
return new window.Promise<AxiosResponse>((resolve, reject) => {
67+
const requestAgain = async (response: AxiosResponse) => {
68+
const reqData = new URLSearchParams(response.config.data);
69+
reqData.set('sec_token', getSecToken())
70+
const newResponse = await axios.request({
71+
method: 'post',
72+
url: response.config.url,
73+
baseURL: '/',
74+
data: reqData.toString()
75+
});
76+
return newResponse;
77+
}
78+
79+
let loginPromise: Promise<void> = null;
80+
81+
const fastLoginWithDialog = () => {
82+
if (loginPromise) {
83+
return loginPromise;
84+
}
85+
86+
loginPromise = new window.Promise<void>((resolve, reject) => {
7687
const div = document.createElement('div');
7788
document.body.appendChild(div);
7889
ReactDOM.render(
7990
<LoginContent
8091
onSuccess={async () => {
8192
try {
8293
setTimeout(async() => {
83-
const reqData = new URLSearchParams(response.config.data);
84-
reqData.set('sec_token', getSecToken())
85-
const newResponse = await axios.request({
86-
method: 'post',
87-
url: response.config.url,
88-
baseURL: '/',
89-
data: reqData.toString()
90-
})
91-
resolve(newResponse);
94+
resolve()
9295
ReactDOM.unmountComponentAtNode(div);
9396
}, 200)
9497
} catch (e) {
@@ -97,8 +100,23 @@ export const login = (response: AxiosResponse) => {
97100
}}
98101
onError={() => {
99102
ReactDOM.unmountComponentAtNode(div);
100-
reject(response);
103+
reject();
101104
}}
102105
/>, div);
103106
})
107+
108+
loginPromise.finally(() => {
109+
loginPromise = null;
110+
});
111+
112+
return loginPromise;
113+
}
114+
115+
export const login = async (response: AxiosResponse) => {
116+
try {
117+
await fastLoginWithDialog();
118+
return await requestAgain(response)
119+
} catch (e) {
120+
return response;
121+
}
104122
}

packages/console-utils/xconsole-service/src/interceptors/paramsInterceptor/index.ts

Lines changed: 7 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
1-
import URLSearchParams from '@ungap/url-search-params';
1+
import qs from 'qs';
22
import { IOptions } from '../../types';
33
import { ApiType } from '../../const/index';
44

5-
export { URLSearchParams };
6-
75
// This is an axios request interceptor
86
// By using this interceptor, user can transform normal JavaScript data object
97
// into an URLSearchParams instance
@@ -12,25 +10,17 @@ function searchParamsInterceptor(config: IOptions): IOptions {
1210
const { params, data, apiType } = config;
1311
if (apiType === ApiType.custom) return config;
1412

15-
function transform(target: any = {}): URLSearchParams {
16-
const searchParams = new URLSearchParams();
17-
// Iterate over request data and append them to searchParams
18-
Object.keys(target).forEach((key) => {
19-
const value = target[key];
20-
if (typeof value !== 'undefined') {
21-
searchParams.append(key, value);
22-
}
23-
});
24-
return searchParams;
25-
}
26-
27-
const paramsSearchParams = transform(params);
28-
const dataSearchParams = transform(data);
13+
const paramsSearchParams = qs.stringify(params);
14+
const dataSearchParams = qs.stringify(data);
2915

3016
// Return the new config
3117
return {
3218
...config,
19+
headers: {
20+
'content-type': 'application/x-www-form-urlencoded'
21+
},
3322
params: paramsSearchParams,
23+
//@ts-ignore
3424
data: dataSearchParams,
3525
originParams: params,
3626
originData: data,

packages/console-utils/xconsole-service/src/interceptors/riskInterceptor/handleDoubleConfirm.tsx

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
import axios, { AxiosResponse } from 'axios';
2-
import { URLSearchParams } from '../paramsInterceptor/index';
2+
import qs from 'qs';
33
import getVerifyInformation from './getVerifyInformation';
44
import {
55
guideToVerificationMethodSetting,
66
guideToVerificationDetailSetting,
77
} from './helpers';
88
import { IResponse, IResponseData, Risk } from '../../types';
9+
import paramsInterceptor from '../paramsInterceptor/index'
910

1011
export interface IVerifyOptions {
1112
isVerifyCodeValid: boolean;
@@ -17,6 +18,7 @@ export interface IVerifyOptions {
1718
}
1819

1920
const axiosInstance = axios.create();
21+
axiosInstance.interceptors.request.use(paramsInterceptor)
2022

2123
function isVerifyCodeValid(
2224
res: AxiosResponse | null,
@@ -75,10 +77,10 @@ async function handleDoubleConfirm(
7577
const {
7678
config: { data: reqDataString, url: reqUrl },
7779
} = response;
78-
const reqData = new URLSearchParams(reqDataString);
79-
reqData.append('verifyType', verifyType);
80-
if (verifyCode) reqData.append('verifyCode', verifyCode);
81-
if (requestId) reqData.append('requestId', requestId);
80+
const reqData = qs.parse(reqDataString)
81+
reqData['verifyType'] = verifyType;
82+
if (verifyCode) reqData['verifyCode'] = verifyCode;
83+
if (requestId) reqData['requestId'] = requestId;
8284

8385
newResponse = await axiosInstance({
8486
method: 'post',

packages/console-utils/xconsole-service/stories/index.stories.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ defaultAxiosRequest.interceptors.request.handlers.unshift({
1818
console.log(config.url, config.url.replace(/\/tool\/user\/info\.json/, '/data/api.json?action=DescribeUserInfo'))
1919
config.url = config.url.replace(/\/tool\/user\/info\.json/, 'data/api.json?action=DescribeUserInfo')
2020
}
21+
2122
return config;
2223
}
2324
});
@@ -28,7 +29,7 @@ storiesOf('XConsole Service', module)
2829
// .addDecorator(withAxiosDecorator(defaultAxiosRequest))
2930
.add('AppCode', () => {
3031
const action = select('action', ['DescribeInstance', 'DescribeAPI'], 'DescribeInstance')
31-
const { data, error } = useOpenApi('consoledemo', action, null, { throwDoubleConfirmError: true })
32+
const { data, error } = useOpenApi('consoledemo', action, {'xxxx': 'xxxx2'}, { throwDoubleConfirmError: true })
3233
// @ts-ignore
3334
console.log(error?.response)
3435
return <div>{JSON.stringify(data)}{JSON.stringify(error)}</div>

packages/xconsole/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@alicloud/xconsole",
3-
"version": "2.3.43",
3+
"version": "2.3.44",
44
"repository": {
55
"type": "git",
66
"url": "https://github.com/aliyun/alibabacloud-console-design.git"
@@ -76,7 +76,7 @@
7676
"@alicloud/xconsole-rc-page-header": "^2.3.30",
7777
"@alicloud/xconsole-rc-result": "^2.3.30",
7878
"@alicloud/xconsole-rc-step": "^1.0.0-beta.1",
79-
"@alicloud/xconsole-service": "^2.3.43",
79+
"@alicloud/xconsole-service": "^2.3.44",
8080
"babel-preset-breezr-wind": "^1.0.0-rc.7",
8181
"commander": "^2.20.0",
8282
"dva": "2.6.0-beta.20",

0 commit comments

Comments
 (0)