message-verify 1.0.1-beta.3 → 1.0.1-beta.30
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +2 -1
- package/dist/index.js +18 -6
- package/dist/locales/en.d.ts +3 -0
- package/dist/locales/en.js +4 -1
- package/dist/locales/id.d.ts +3 -0
- package/dist/locales/id.js +4 -1
- package/dist/locales/zh.d.ts +3 -0
- package/dist/locales/zh.js +4 -1
- package/dist/main.js +18 -20
- package/dist/relogin-modal.d.ts +2 -2
- package/dist/relogin-modal.js +8 -7
- package/dist/utils/type.d.ts +7 -2
- package/dist/verify-modal.js +39 -18
- package/package.json +3 -2
- package/src/index.tsx +25 -7
- package/src/locales/en.ts +4 -1
- package/src/locales/id.ts +4 -1
- package/src/locales/zh.ts +4 -1
- package/src/main.tsx +14 -13
- package/src/relogin-modal.tsx +11 -10
- package/src/utils/type.ts +8 -2
- package/src/verify-modal.tsx +42 -22
package/dist/index.d.ts
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
-
import { ModalConfig } from './utils/type.js';
|
1
|
+
import { ModalConfig, LoginModalConfig } from './utils/type.js';
|
2
2
|
export declare const initFingerprint: () => Promise<string>;
|
3
3
|
export declare const createMessageVerifyModal: (modalProps: ModalConfig) => void;
|
4
|
+
export declare const createReLoginModal: (modalProps: LoginModalConfig) => void;
|
package/dist/index.js
CHANGED
@@ -2,12 +2,14 @@ import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
2
|
import ReactDOM from 'react-dom/client';
|
3
3
|
import VerifyModal from './verify-modal.js';
|
4
4
|
import Fingerprint2 from 'fingerprintjs2';
|
5
|
-
|
5
|
+
import ReLoginModal from './relogin-modal.js';
|
6
|
+
// let cachedFingerprint: string | null = null;
|
6
7
|
export const initFingerprint = async () => {
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
8
|
+
// console.log('cachedFingerprint', cachedFingerprint);
|
9
|
+
// if (cachedFingerprint) {
|
10
|
+
// // 已有缓存,直接返回 Promise
|
11
|
+
// return Promise.resolve(cachedFingerprint);
|
12
|
+
// }
|
11
13
|
// 首次异步获取并缓存
|
12
14
|
return new Promise((resolve) => {
|
13
15
|
Fingerprint2.get(function (components) {
|
@@ -18,7 +20,7 @@ export const initFingerprint = async () => {
|
|
18
20
|
.map(component => component.value)
|
19
21
|
.join('###');
|
20
22
|
const fingerprint = Fingerprint2.x64hash128(values, 31);
|
21
|
-
cachedFingerprint = fingerprint;
|
23
|
+
// cachedFingerprint = fingerprint;
|
22
24
|
resolve(fingerprint);
|
23
25
|
});
|
24
26
|
});
|
@@ -37,6 +39,16 @@ export const createMessageVerifyModal = (modalProps) => {
|
|
37
39
|
}
|
38
40
|
} }));
|
39
41
|
};
|
42
|
+
// 新增 relogin 弹窗创建方法
|
43
|
+
export const createReLoginModal = (modalProps) => {
|
44
|
+
const container = document.createElement('div');
|
45
|
+
container.id = 'antd-modal-container';
|
46
|
+
document.body.appendChild(container);
|
47
|
+
modalRoot = ReactDOM.createRoot(container);
|
48
|
+
modalRoot.render(_jsx(ReLoginModal, { props: {
|
49
|
+
...modalProps,
|
50
|
+
} }));
|
51
|
+
};
|
40
52
|
const destroyModal = () => {
|
41
53
|
if (modalRoot) {
|
42
54
|
modalRoot.unmount();
|
package/dist/locales/en.d.ts
CHANGED
package/dist/locales/en.js
CHANGED
@@ -6,5 +6,8 @@ export default {
|
|
6
6
|
sendSuccess: 'Successfully sent',
|
7
7
|
sendFailed: 'Send failed',
|
8
8
|
reSend: 'Resend',
|
9
|
-
countDownSecound: '{countdown} seconds'
|
9
|
+
countDownSecound: '{countdown} seconds',
|
10
|
+
accountAlert: 'Account Security Alert',
|
11
|
+
alertContent: 'Changes have been detected in your login environment or network information.To ensure account security, please log in again to verify your identity.',
|
12
|
+
ok: 'OK'
|
10
13
|
};
|
package/dist/locales/id.d.ts
CHANGED
package/dist/locales/id.js
CHANGED
@@ -6,5 +6,8 @@ export default {
|
|
6
6
|
sendSuccess: 'Berhasil dikirim',
|
7
7
|
sendFailed: 'Gagal mengirim',
|
8
8
|
reSend: 'Kirim Ulang',
|
9
|
-
countDownSecound: '{countdown} detik'
|
9
|
+
countDownSecound: '{countdown} detik',
|
10
|
+
accountAlert: 'Peringatan Keamanan Akun',
|
11
|
+
alertContent: 'Terdeteksi perubahan pada lingkungan login atau informasi jaringan Anda.Untuk menjaga keamanan akun, silakan login kembali untuk memverifikasi identitas Anda.',
|
12
|
+
ok: 'Baiklah'
|
10
13
|
};
|
package/dist/locales/zh.d.ts
CHANGED
package/dist/locales/zh.js
CHANGED
package/dist/main.js
CHANGED
@@ -1,6 +1,6 @@
|
|
1
|
-
import { jsx as _jsx, Fragment as _Fragment } from "react/jsx-runtime";
|
1
|
+
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
|
2
2
|
import { createRoot } from 'react-dom/client';
|
3
|
-
import { createMessageVerifyModal, initFingerprint } from './index.js'; // 或 './index'
|
3
|
+
import { createMessageVerifyModal, initFingerprint, createReLoginModal } from './index.js'; // 或 './index'
|
4
4
|
import { axios } from '@yqg/resource';
|
5
5
|
const data = "{\"mobile\":\"188****4035\",\"verifyCodeKey\":\"3f025b33-988e-47c0-950d-6beb776d043f\",\"needValid\":true,\"step\":2,\"message\":\"需要填写验证码\"}";
|
6
6
|
const fp = await initFingerprint();
|
@@ -11,12 +11,6 @@ const config = {
|
|
11
11
|
"forcedJSONParsing": true,
|
12
12
|
"clarifyTimeoutError": false
|
13
13
|
},
|
14
|
-
"transformRequest": [
|
15
|
-
null
|
16
|
-
],
|
17
|
-
"transformResponse": [
|
18
|
-
null
|
19
|
-
],
|
20
14
|
"timeout": 0,
|
21
15
|
"xsrfCookieName": "XSRF-TOKEN",
|
22
16
|
"xsrfHeaderName": "X-XSRF-TOKEN",
|
@@ -25,9 +19,7 @@ const config = {
|
|
25
19
|
"headers": {
|
26
20
|
"Accept": "application/json, text/plain, */*",
|
27
21
|
"X-Device-Fingerprint": "185fcce88c629725321adf29daa5e444",
|
28
|
-
"Content-Type": "application/json"
|
29
|
-
"sms-code": "121212",
|
30
|
-
"sms-code-key": "212190c7-2f5e-4cc1-82ec-a242c2ab5425"
|
22
|
+
"Content-Type": "application/json"
|
31
23
|
},
|
32
24
|
"url": "/classification/admin/level/edit",
|
33
25
|
"method": "post",
|
@@ -43,12 +35,18 @@ const config = {
|
|
43
35
|
"data": "{\"id\":1,\"classificationName\":\"个人基本概况信息\",\"classificationLevel\":2}",
|
44
36
|
"baseURL": "http://localhost:62888"
|
45
37
|
};
|
46
|
-
createRoot(document.getElementById('root')).render(
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
38
|
+
createRoot(document.getElementById('root')).render(_jsxs(_Fragment, { children: [_jsx("button", { onClick: () => createMessageVerifyModal({
|
39
|
+
data,
|
40
|
+
config,
|
41
|
+
lang: 'en',
|
42
|
+
http: axios,
|
43
|
+
apiReject: () => {
|
44
|
+
},
|
45
|
+
apiResolve: () => {
|
46
|
+
}
|
47
|
+
}), children: "Show verify Modal" }), _jsx("button", { onClick: () => createReLoginModal({
|
48
|
+
goLogin: () => {
|
49
|
+
console.log('goLogin');
|
50
|
+
},
|
51
|
+
lang: 'zh',
|
52
|
+
}), children: "Show login Modal" })] }));
|
package/dist/relogin-modal.d.ts
CHANGED
@@ -1,5 +1,5 @@
|
|
1
|
-
import {
|
1
|
+
import { LoginModalConfig } from './utils/type.js';
|
2
2
|
declare const ReLoginModal: ({ props }: {
|
3
|
-
props:
|
3
|
+
props: LoginModalConfig;
|
4
4
|
}) => import("react/jsx-runtime.js").JSX.Element;
|
5
5
|
export default ReLoginModal;
|
package/dist/relogin-modal.js
CHANGED
@@ -1,22 +1,23 @@
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
2
2
|
import { useState } from 'react';
|
3
3
|
import { Modal, Button } from './compoments/index.js';
|
4
|
+
import t from './utils/i18n.js';
|
4
5
|
const ReLoginModal = ({ props }) => {
|
5
|
-
|
6
|
+
const { goLogin, lang } = props || {};
|
6
7
|
const [visible, setVisible] = useState(true);
|
7
8
|
const onClose = () => {
|
8
9
|
setVisible(false);
|
10
|
+
goLogin();
|
9
11
|
};
|
10
|
-
return (_jsxs(Modal, { visible: visible, onClose: onClose, width: 420, children: [_jsx("div", { style: { fontWeight: 500, fontSize: 20, marginBottom: 24 }, children:
|
12
|
+
return (_jsxs(Modal, { visible: visible, onClose: onClose, width: 420, children: [_jsx("div", { style: { fontWeight: 500, fontSize: 20, marginBottom: 24 }, children: t('accountAlert', lang) }), _jsx("div", { style: { color: '#222', fontSize: 16, marginBottom: 40, lineHeight: '24px' }, children: t('alertContent', lang) }), _jsx("div", { style: { display: 'flex', justifyContent: 'center' }, children: _jsx(Button, { style: {
|
11
13
|
background: '#1677ff',
|
12
14
|
color: '#fff',
|
13
15
|
border: 'none',
|
14
|
-
width:
|
15
|
-
height:
|
16
|
-
fontSize:
|
17
|
-
fontWeight: 500,
|
16
|
+
width: 80,
|
17
|
+
height: 36,
|
18
|
+
fontSize: 14,
|
18
19
|
borderRadius: 8,
|
19
20
|
boxShadow: '0 2px 8px rgba(22,119,255,0.08)',
|
20
|
-
}, onClick: onClose, children:
|
21
|
+
}, onClick: onClose, children: t('ok', lang) }) })] }));
|
21
22
|
};
|
22
23
|
export default ReLoginModal;
|
package/dist/utils/type.d.ts
CHANGED
@@ -7,7 +7,7 @@ export type ModalConfig = {
|
|
7
7
|
};
|
8
8
|
[key: string]: unknown;
|
9
9
|
};
|
10
|
-
lang
|
10
|
+
lang?: 'zh' | 'en' | 'id';
|
11
11
|
http: {
|
12
12
|
(params: object): Promise<unknown>;
|
13
13
|
defaults: {
|
@@ -19,5 +19,10 @@ export type ModalConfig = {
|
|
19
19
|
};
|
20
20
|
};
|
21
21
|
api?: string;
|
22
|
-
|
22
|
+
apiReject: any;
|
23
|
+
apiResolve: any;
|
24
|
+
};
|
25
|
+
export type LoginModalConfig = {
|
26
|
+
goLogin: () => void;
|
27
|
+
lang?: 'zh' | 'en' | 'id';
|
23
28
|
};
|
package/dist/verify-modal.js
CHANGED
@@ -11,7 +11,7 @@ const CreateMessageVerifyModal = ({ props }) => {
|
|
11
11
|
const [captchaImage, setCaptchaImage] = useState('');
|
12
12
|
const [captchCode, setCaptchCode] = useState('');
|
13
13
|
const [captchaKey, setCaptchaKey] = useState('');
|
14
|
-
const { data,
|
14
|
+
const { data, http, lang, api = '/admin/sms/send', config, apiResolve } = props || {};
|
15
15
|
const dataObj = JSON.parse(data || '{}');
|
16
16
|
const { mobile, verifyCodeKey } = dataObj || {};
|
17
17
|
const getKey = async () => {
|
@@ -58,7 +58,9 @@ const CreateMessageVerifyModal = ({ props }) => {
|
|
58
58
|
return;
|
59
59
|
}
|
60
60
|
message.success(t('sendSuccess', lang));
|
61
|
+
// 重置倒计时、验证码
|
61
62
|
setCountdown(60);
|
63
|
+
setOtp('');
|
62
64
|
};
|
63
65
|
return (_jsxs(Modal, { width: 420, visible: visible, onClose: () => {
|
64
66
|
setVisible(false);
|
@@ -66,24 +68,43 @@ const CreateMessageVerifyModal = ({ props }) => {
|
|
66
68
|
}, children: [_jsx("div", { style: { fontSize: 14, color: '#666' }, children: t('alreadySend', lang, { phone: mobile }) }), _jsxs("div", { style: { display: 'flex', alignItems: 'center', gap: 8, marginTop: 12 }, children: [_jsx(Input.OTP, { length: 6, value: otp, onChange: async (val) => {
|
67
69
|
setOtp(val);
|
68
70
|
if (val.length === 6) {
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
71
|
+
try {
|
72
|
+
const res = await Promise.race([
|
73
|
+
new Promise((resolve, reject) => {
|
74
|
+
setTimeout(() => {
|
75
|
+
reject(new Error('Timeout'));
|
76
|
+
}, 1000);
|
77
|
+
}),
|
78
|
+
new Promise((resolve, reject) => {
|
79
|
+
http({
|
80
|
+
...config,
|
81
|
+
headers: {
|
82
|
+
...http.defaults.headers.common,
|
83
|
+
'sms-code': val,
|
84
|
+
'sms-code-key': verifyCodeKey,
|
85
|
+
'Content-Type': config.headers['Content-Type'],
|
86
|
+
}
|
87
|
+
}).then(res => {
|
88
|
+
resolve(res);
|
89
|
+
}).catch(err => {
|
90
|
+
reject(err);
|
91
|
+
});
|
92
|
+
})
|
93
|
+
]);
|
94
|
+
if (res?.data?.status?.code === 0) {
|
95
|
+
apiResolve(res);
|
96
|
+
setVisible(false);
|
76
97
|
}
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
98
|
+
else {
|
99
|
+
message.error('验证失败');
|
100
|
+
setOtp('');
|
101
|
+
}
|
102
|
+
}
|
103
|
+
catch (error) {
|
104
|
+
console.warn('catch', error);
|
105
|
+
message.error('验证失败');
|
106
|
+
setOtp('');
|
107
|
+
}
|
87
108
|
}
|
88
109
|
} }), _jsx(Button, { disabled: countdown > 0 || !captchCode, onClick: handleResend, style: { padding: '8px' }, children: countdown > 0 ? t('countDownSecound', lang, { countdown }) : t('reSend', lang) })] }), countdown > 0 ? null :
|
89
110
|
_jsxs("div", { style: { marginTop: 12, display: 'flex', alignItems: 'center' }, children: [_jsx(Input, { placeholder: t('pleaseEnterPicVerifyCode', lang), onChange: (e) => {
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "message-verify",
|
3
|
-
"version": "1.0.1-beta.
|
3
|
+
"version": "1.0.1-beta.30",
|
4
4
|
"type": "module",
|
5
5
|
"main": "dist/index.js",
|
6
6
|
"dependencies": {
|
@@ -29,6 +29,7 @@
|
|
29
29
|
"build": "tsc -b",
|
30
30
|
"analyze": "vite build",
|
31
31
|
"lint": "eslint .",
|
32
|
-
"preview": "vite preview"
|
32
|
+
"preview": "vite preview",
|
33
|
+
"release:beta": "pnpm version prerelease --preid=beta && pnpm run build && pnpm publish"
|
33
34
|
}
|
34
35
|
}
|
package/src/index.tsx
CHANGED
@@ -1,14 +1,16 @@
|
|
1
1
|
import ReactDOM from 'react-dom/client'
|
2
2
|
import VerifyModal from './verify-modal.js'
|
3
3
|
import Fingerprint2 from 'fingerprintjs2';
|
4
|
-
import
|
4
|
+
import ReLoginModal from './relogin-modal.js';
|
5
|
+
import { ModalConfig, LoginModalConfig } from './utils/type.js';
|
5
6
|
|
6
|
-
let cachedFingerprint: string | null = null;
|
7
|
+
// let cachedFingerprint: string | null = null;
|
7
8
|
export const initFingerprint = async (): Promise<string> => {
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
// console.log('cachedFingerprint', cachedFingerprint);
|
10
|
+
// if (cachedFingerprint) {
|
11
|
+
// // 已有缓存,直接返回 Promise
|
12
|
+
// return Promise.resolve(cachedFingerprint);
|
13
|
+
// }
|
12
14
|
// 首次异步获取并缓存
|
13
15
|
return new Promise((resolve) => {
|
14
16
|
Fingerprint2.get(function (components) {
|
@@ -19,7 +21,7 @@ export const initFingerprint = async (): Promise<string> => {
|
|
19
21
|
.map(component => component.value)
|
20
22
|
.join('###');
|
21
23
|
const fingerprint = Fingerprint2.x64hash128(values, 31);
|
22
|
-
cachedFingerprint = fingerprint;
|
24
|
+
// cachedFingerprint = fingerprint;
|
23
25
|
resolve(fingerprint);
|
24
26
|
});
|
25
27
|
});
|
@@ -46,6 +48,22 @@ export const createMessageVerifyModal = (modalProps: ModalConfig) => {
|
|
46
48
|
)
|
47
49
|
}
|
48
50
|
|
51
|
+
// 新增 relogin 弹窗创建方法
|
52
|
+
export const createReLoginModal = (modalProps: LoginModalConfig) => {
|
53
|
+
const container = document.createElement('div')
|
54
|
+
container.id = 'antd-modal-container'
|
55
|
+
document.body.appendChild(container)
|
56
|
+
|
57
|
+
modalRoot = ReactDOM.createRoot(container)
|
58
|
+
modalRoot.render(
|
59
|
+
<ReLoginModal
|
60
|
+
props={{
|
61
|
+
...modalProps,
|
62
|
+
}}
|
63
|
+
/>
|
64
|
+
)
|
65
|
+
}
|
66
|
+
|
49
67
|
const destroyModal = () => {
|
50
68
|
if (modalRoot) {
|
51
69
|
modalRoot.unmount()
|
package/src/locales/en.ts
CHANGED
@@ -6,5 +6,8 @@ export default {
|
|
6
6
|
sendSuccess: 'Successfully sent',
|
7
7
|
sendFailed: 'Send failed',
|
8
8
|
reSend: 'Resend',
|
9
|
-
countDownSecound: '{countdown} seconds'
|
9
|
+
countDownSecound: '{countdown} seconds',
|
10
|
+
accountAlert: 'Account Security Alert',
|
11
|
+
alertContent: 'Changes have been detected in your login environment or network information.To ensure account security, please log in again to verify your identity.',
|
12
|
+
ok: 'OK'
|
10
13
|
};
|
package/src/locales/id.ts
CHANGED
@@ -6,5 +6,8 @@ export default {
|
|
6
6
|
sendSuccess: 'Berhasil dikirim',
|
7
7
|
sendFailed: 'Gagal mengirim',
|
8
8
|
reSend: 'Kirim Ulang',
|
9
|
-
countDownSecound: '{countdown} detik'
|
9
|
+
countDownSecound: '{countdown} detik',
|
10
|
+
accountAlert: 'Peringatan Keamanan Akun',
|
11
|
+
alertContent: 'Terdeteksi perubahan pada lingkungan login atau informasi jaringan Anda.Untuk menjaga keamanan akun, silakan login kembali untuk memverifikasi identitas Anda.',
|
12
|
+
ok: 'Baiklah'
|
10
13
|
};
|
package/src/locales/zh.ts
CHANGED
package/src/main.tsx
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
import { createRoot } from 'react-dom/client';
|
2
|
-
import { createMessageVerifyModal, initFingerprint } from './index.js'; // 或 './index'
|
2
|
+
import { createMessageVerifyModal, initFingerprint, createReLoginModal } from './index.js'; // 或 './index'
|
3
3
|
import { axios } from '@yqg/resource';
|
4
4
|
|
5
5
|
const data = "{\"mobile\":\"188****4035\",\"verifyCodeKey\":\"3f025b33-988e-47c0-950d-6beb776d043f\",\"needValid\":true,\"step\":2,\"message\":\"需要填写验证码\"}";
|
@@ -13,12 +13,6 @@ const config = {
|
|
13
13
|
"forcedJSONParsing": true,
|
14
14
|
"clarifyTimeoutError": false
|
15
15
|
},
|
16
|
-
"transformRequest": [
|
17
|
-
null
|
18
|
-
],
|
19
|
-
"transformResponse": [
|
20
|
-
null
|
21
|
-
],
|
22
16
|
"timeout": 0,
|
23
17
|
"xsrfCookieName": "XSRF-TOKEN",
|
24
18
|
"xsrfHeaderName": "X-XSRF-TOKEN",
|
@@ -27,9 +21,7 @@ const config = {
|
|
27
21
|
"headers": {
|
28
22
|
"Accept": "application/json, text/plain, */*",
|
29
23
|
"X-Device-Fingerprint": "185fcce88c629725321adf29daa5e444",
|
30
|
-
"Content-Type": "application/json"
|
31
|
-
"sms-code": "121212",
|
32
|
-
"sms-code-key": "212190c7-2f5e-4cc1-82ec-a242c2ab5425"
|
24
|
+
"Content-Type": "application/json"
|
33
25
|
},
|
34
26
|
"url": "/classification/admin/level/edit",
|
35
27
|
"method": "post",
|
@@ -50,12 +42,21 @@ createRoot(document.getElementById('root')!).render(
|
|
50
42
|
<button onClick={() => createMessageVerifyModal({
|
51
43
|
data,
|
52
44
|
config,
|
53
|
-
response: {
|
54
|
-
config
|
55
|
-
},
|
56
45
|
lang: 'en',
|
57
46
|
http: axios,
|
47
|
+
apiReject: () => {
|
48
|
+
},
|
49
|
+
apiResolve: () => {
|
50
|
+
}
|
58
51
|
})}>
|
59
52
|
Show verify Modal
|
60
53
|
</button>
|
54
|
+
<button onClick={() => createReLoginModal({
|
55
|
+
goLogin: () => {
|
56
|
+
console.log('goLogin');
|
57
|
+
},
|
58
|
+
lang: 'zh',
|
59
|
+
})}>
|
60
|
+
Show login Modal
|
61
|
+
</button>
|
61
62
|
</>);
|
package/src/relogin-modal.tsx
CHANGED
@@ -1,20 +1,22 @@
|
|
1
1
|
import { useState } from 'react'
|
2
2
|
import { Modal, Button } from './compoments/index.js'
|
3
|
-
import {
|
3
|
+
import { LoginModalConfig } from './utils/type.js';
|
4
|
+
import t from './utils/i18n.js'
|
4
5
|
|
5
|
-
const ReLoginModal = ({ props }: { props:
|
6
|
-
|
6
|
+
const ReLoginModal = ({ props }: { props: LoginModalConfig }) => {
|
7
|
+
const { goLogin, lang } = props || {};
|
7
8
|
const [visible, setVisible] = useState(true);
|
8
9
|
const onClose = () => {
|
9
10
|
setVisible(false);
|
11
|
+
goLogin();
|
10
12
|
};
|
11
13
|
return (
|
12
14
|
<Modal visible={visible} onClose={onClose} width={420}>
|
13
15
|
<div style={{ fontWeight: 500, fontSize: 20, marginBottom: 24 }}>
|
14
|
-
|
16
|
+
{t('accountAlert', lang)}
|
15
17
|
</div>
|
16
18
|
<div style={{ color: '#222', fontSize: 16, marginBottom: 40, lineHeight: '24px' }}>
|
17
|
-
|
19
|
+
{t('alertContent', lang)}
|
18
20
|
</div>
|
19
21
|
<div style={{ display: 'flex', justifyContent: 'center' }}>
|
20
22
|
<Button
|
@@ -22,16 +24,15 @@ const ReLoginModal = ({ props }: { props: ModalConfig }) => {
|
|
22
24
|
background: '#1677ff',
|
23
25
|
color: '#fff',
|
24
26
|
border: 'none',
|
25
|
-
width:
|
26
|
-
height:
|
27
|
-
fontSize:
|
28
|
-
fontWeight: 500,
|
27
|
+
width: 80,
|
28
|
+
height: 36,
|
29
|
+
fontSize: 14,
|
29
30
|
borderRadius: 8,
|
30
31
|
boxShadow: '0 2px 8px rgba(22,119,255,0.08)',
|
31
32
|
}}
|
32
33
|
onClick={onClose}
|
33
34
|
>
|
34
|
-
|
35
|
+
{t('ok', lang)}
|
35
36
|
</Button>
|
36
37
|
</div>
|
37
38
|
</Modal>
|
package/src/utils/type.ts
CHANGED
@@ -8,7 +8,7 @@ export type ModalConfig = {
|
|
8
8
|
};
|
9
9
|
[key: string]: unknown;
|
10
10
|
};
|
11
|
-
lang
|
11
|
+
lang?: 'zh' | 'en' | 'id';
|
12
12
|
http: {
|
13
13
|
(params: object): Promise<unknown>;
|
14
14
|
defaults: {
|
@@ -20,5 +20,11 @@ export type ModalConfig = {
|
|
20
20
|
}
|
21
21
|
};
|
22
22
|
api?: string;
|
23
|
-
|
23
|
+
apiReject: any;
|
24
|
+
apiResolve: any;
|
25
|
+
}
|
26
|
+
|
27
|
+
export type LoginModalConfig = {
|
28
|
+
goLogin: () => void;
|
29
|
+
lang?: 'zh' | 'en' | 'id';
|
24
30
|
}
|
package/src/verify-modal.tsx
CHANGED
@@ -12,7 +12,7 @@ const CreateMessageVerifyModal = ({ props }: { props: ModalConfig }) => {
|
|
12
12
|
const [captchaImage, setCaptchaImage] = useState<string>('');
|
13
13
|
const [captchCode, setCaptchCode] = useState<string>('');
|
14
14
|
const [captchaKey, setCaptchaKey] = useState<string>('');
|
15
|
-
const { data,
|
15
|
+
const { data, http, lang, api = '/admin/sms/send', config, apiResolve } = props || {};
|
16
16
|
const dataObj = JSON.parse(data || '{}');
|
17
17
|
const { mobile, verifyCodeKey } = dataObj || {};
|
18
18
|
|
@@ -25,10 +25,11 @@ const CreateMessageVerifyModal = ({ props }: { props: ModalConfig }) => {
|
|
25
25
|
const image = Api.getCaptchaImgUrl(key) as unknown;
|
26
26
|
setCaptchaImage(image as string);
|
27
27
|
}
|
28
|
-
} catch (err) {
|
29
|
-
|
30
|
-
|
31
|
-
|
28
|
+
} catch (err) {
|
29
|
+
const msg =
|
30
|
+
typeof err === 'object' && err !== null && 'message' in err
|
31
|
+
? (err as { message: string }).message
|
32
|
+
: String(err);
|
32
33
|
message.error(msg as React.ReactNode);
|
33
34
|
}
|
34
35
|
}
|
@@ -60,7 +61,9 @@ const CreateMessageVerifyModal = ({ props }: { props: ModalConfig }) => {
|
|
60
61
|
return;
|
61
62
|
}
|
62
63
|
message.success(t('sendSuccess', lang));
|
64
|
+
// 重置倒计时、验证码
|
63
65
|
setCountdown(60);
|
66
|
+
setOtp('');
|
64
67
|
}
|
65
68
|
|
66
69
|
return (
|
@@ -81,24 +84,41 @@ const CreateMessageVerifyModal = ({ props }: { props: ModalConfig }) => {
|
|
81
84
|
onChange={async (val) => {
|
82
85
|
setOtp(val);
|
83
86
|
if (val.length === 6) {
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
87
|
+
try {
|
88
|
+
const res = await Promise.race([
|
89
|
+
new Promise((resolve, reject) => {
|
90
|
+
setTimeout(() => {
|
91
|
+
reject(new Error('Timeout'));
|
92
|
+
}, 1000);
|
93
|
+
}),
|
94
|
+
new Promise((resolve, reject) => {
|
95
|
+
http({
|
96
|
+
...config,
|
97
|
+
headers: {
|
98
|
+
...http.defaults.headers.common,
|
99
|
+
'sms-code': val,
|
100
|
+
'sms-code-key': verifyCodeKey,
|
101
|
+
'Content-Type': config.headers['Content-Type'],
|
102
|
+
}
|
103
|
+
}).then(res => {
|
104
|
+
resolve(res);
|
105
|
+
}).catch(err => {
|
106
|
+
reject(err);
|
107
|
+
})
|
108
|
+
})
|
109
|
+
]) as any;
|
110
|
+
if (res?.data?.status?.code === 0) {
|
111
|
+
apiResolve(res);
|
112
|
+
setVisible(false);
|
113
|
+
} else {
|
114
|
+
message.error('验证失败');
|
115
|
+
setOtp('');
|
91
116
|
}
|
92
|
-
})
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
// return;
|
98
|
-
// } else {
|
99
|
-
// message.success(t('verifySuccess', lang));
|
100
|
-
// setVisible(false);
|
101
|
-
// }
|
117
|
+
} catch (error) {
|
118
|
+
console.warn('catch', error);
|
119
|
+
message.error('验证失败');
|
120
|
+
setOtp('');
|
121
|
+
}
|
102
122
|
}
|
103
123
|
}} />
|
104
124
|
<Button
|