message-verify 1.0.1-beta.6 → 1.0.1-beta.60

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/.arcconfig CHANGED
@@ -1,4 +1,5 @@
1
1
  {
2
+ "project.name": "message-verify",
2
3
  "phabricator.uri": "https://code.yangqianguan.com/",
3
4
  "lint.engine": "YqgWebDiffLintEngine"
4
5
  }
package/dist/index.d.ts CHANGED
@@ -1,3 +1,4 @@
1
- import { ModalConfig } from './utils/type.js';
1
+ import { VerifyModalConfig, LoginModalConfig } from './utils/type.js';
2
2
  export declare const initFingerprint: () => Promise<string>;
3
- export declare const createMessageVerifyModal: (modalProps: ModalConfig) => void;
3
+ export declare const createReLoginModal: (modalProps: LoginModalConfig) => void;
4
+ export declare const VerifyHandler: ({ data, config, http, verifyPromise, sendApi, response }: VerifyModalConfig) => Promise<any>;
package/dist/index.js CHANGED
@@ -1,46 +1,77 @@
1
1
  import { jsx as _jsx } from "react/jsx-runtime";
2
2
  import ReactDOM from 'react-dom/client';
3
- import VerifyModal from './verify-modal.js';
3
+ import VerifyModal from './modal/verify-modal.js';
4
4
  import Fingerprint2 from 'fingerprintjs2';
5
- let cachedFingerprint = null;
5
+ import ReLoginModal from './modal/relogin-modal.js';
6
+ let fingerprintPromise = null; // 用 Promise 本身作为缓存
7
+ let modalRoot = null;
6
8
  export const initFingerprint = async () => {
7
- if (cachedFingerprint) {
8
- // 已有缓存,直接返回 Promise
9
- return Promise.resolve(cachedFingerprint);
10
- }
11
- // 首次异步获取并缓存
12
- return new Promise((resolve) => {
13
- Fingerprint2.get(function (components) {
14
- console.log('components', components);
15
- const includeKeys = ['userAgent', 'deviceMemory', 'cpuClass', 'hardwareConcurrency', 'platform'];
16
- const values = components
17
- .filter(component => includeKeys.includes(component.key))
18
- .map(component => component.value)
19
- .join('###');
20
- const fingerprint = Fingerprint2.x64hash128(values, 31);
21
- cachedFingerprint = fingerprint;
22
- resolve(fingerprint);
9
+ console.log('fingerprintPromise:', fingerprintPromise);
10
+ if (!fingerprintPromise) {
11
+ fingerprintPromise = new Promise((resolve) => {
12
+ Fingerprint2.get(components => {
13
+ const includeKeys = ['userAgent', 'cpuClass', 'hardwareConcurrency', 'platform'];
14
+ console.log('components:', components);
15
+ const values = components
16
+ .filter(c => includeKeys.includes(c.key))
17
+ .map(c => c.value)
18
+ .join('###');
19
+ console.log('values:', values);
20
+ const fingerprint = Fingerprint2.x64hash128(values, 31);
21
+ console.log('fingerprint:', fingerprint);
22
+ resolve(fingerprint);
23
+ });
23
24
  });
24
- });
25
+ }
26
+ return fingerprintPromise;
25
27
  };
26
- let modalRoot = null;
27
- export const createMessageVerifyModal = (modalProps) => {
28
+ const destroyModal = (modalId) => {
29
+ if (modalRoot) {
30
+ modalRoot.unmount();
31
+ document.getElementById(modalId)?.remove();
32
+ modalRoot = null;
33
+ }
34
+ };
35
+ const creatModal = (modalProps, modalId, ModalDom) => {
36
+ destroyModal(modalId);
28
37
  const container = document.createElement('div');
29
- container.id = 'antd-modal-container';
38
+ container.id = modalId;
30
39
  document.body.appendChild(container);
31
40
  modalRoot = ReactDOM.createRoot(container);
32
- modalRoot.render(_jsx(VerifyModal, { props: {
41
+ modalRoot.render(_jsx(ModalDom, { props: {
33
42
  ...modalProps,
34
43
  onClose: () => {
35
- modalProps.onClose?.();
36
- destroyModal();
44
+ destroyModal(modalId);
37
45
  }
38
46
  } }));
39
47
  };
40
- const destroyModal = () => {
41
- if (modalRoot) {
42
- modalRoot.unmount();
43
- document.getElementById('antd-modal-container')?.remove();
44
- modalRoot = null;
48
+ const createMessageVerifyModal = (modalProps) => {
49
+ const verifyModalId = 'verify-modal-container';
50
+ creatModal(modalProps, verifyModalId, VerifyModal);
51
+ };
52
+ // 新增 relogin 弹窗创建方法
53
+ export const createReLoginModal = (modalProps) => {
54
+ const reLoginModalId = 'relogin-modal-container';
55
+ creatModal(modalProps, reLoginModalId, ReLoginModal);
56
+ };
57
+ export const VerifyHandler = ({ data, config, http, verifyPromise, sendApi, response }) => {
58
+ console.log('VerifyHandler =>', response);
59
+ const toEmpty = () => {
60
+ verifyPromise.current = null;
61
+ };
62
+ if (!verifyPromise.current) {
63
+ verifyPromise.current = new Promise((resolve, reject) => {
64
+ createMessageVerifyModal({
65
+ data,
66
+ config,
67
+ http,
68
+ apiResolve: resolve,
69
+ apiReject: reject,
70
+ apiPromiseToEmpty: toEmpty,
71
+ sendApi,
72
+ response
73
+ });
74
+ }).finally(toEmpty);
45
75
  }
76
+ return verifyPromise.current;
46
77
  };
@@ -7,5 +7,10 @@ declare const _default: {
7
7
  sendFailed: string;
8
8
  reSend: string;
9
9
  countDownSecound: string;
10
+ accountAlert: string;
11
+ alertContent: string;
12
+ ok: string;
13
+ chidoriOpenPro: string;
14
+ verifyFail: string;
10
15
  };
11
16
  export default _default;
@@ -6,5 +6,10 @@ 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',
13
+ chidoriOpenPro: 'Chidori has activated security protection for you',
14
+ verifyFail: 'Validation failed'
10
15
  };
@@ -7,5 +7,10 @@ declare const _default: {
7
7
  sendFailed: string;
8
8
  reSend: string;
9
9
  countDownSecound: string;
10
+ accountAlert: string;
11
+ alertContent: string;
12
+ ok: string;
13
+ chidoriOpenPro: string;
14
+ verifyFail: string;
10
15
  };
11
16
  export default _default;
@@ -6,5 +6,10 @@ 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',
13
+ chidoriOpenPro: 'chidori telah mengaktifkan keamanan untuk Anda',
14
+ verifyFail: 'Autentikasi gagal'
10
15
  };
@@ -7,5 +7,10 @@ declare const _default: {
7
7
  sendFailed: string;
8
8
  reSend: string;
9
9
  countDownSecound: string;
10
+ accountAlert: string;
11
+ alertContent: string;
12
+ ok: string;
13
+ chidoriOpenPro: string;
14
+ verifyFail: string;
10
15
  };
11
16
  export default _default;
@@ -6,5 +6,10 @@ export default {
6
6
  sendSuccess: '发送成功',
7
7
  sendFailed: '发送失败',
8
8
  reSend: '重新发送',
9
- countDownSecound: '{countdown}秒'
9
+ countDownSecound: '{countdown}秒',
10
+ accountAlert: '账号安全提醒',
11
+ alertContent: '检测到您的登录环境或网络信息有变动,为保障账户安全,请重新登录验证身份',
12
+ ok: '好的',
13
+ chidoriOpenPro: 'chidori已为您开启安全防护',
14
+ verifyFail: '验证失败'
10
15
  };
package/dist/main.js CHANGED
@@ -1,22 +1,17 @@
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 { initFingerprint, createReLoginModal, VerifyHandler } 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();
7
- console.log(fp);
7
+ const fp2 = await initFingerprint();
8
+ console.log(fp, fp2);
8
9
  const config = {
9
10
  "transitional": {
10
11
  "silentJSONParsing": true,
11
12
  "forcedJSONParsing": true,
12
13
  "clarifyTimeoutError": false
13
14
  },
14
- "transformRequest": [
15
- null
16
- ],
17
- "transformResponse": [
18
- null
19
- ],
20
15
  "timeout": 0,
21
16
  "xsrfCookieName": "XSRF-TOKEN",
22
17
  "xsrfHeaderName": "X-XSRF-TOKEN",
@@ -24,10 +19,8 @@ const config = {
24
19
  "maxBodyLength": -1,
25
20
  "headers": {
26
21
  "Accept": "application/json, text/plain, */*",
27
- "X-Device-Fingerprint": "185fcce88c629725321adf29daa5e444",
28
- "Content-Type": "application/json",
29
- "sms-code": "121212",
30
- "sms-code-key": "212190c7-2f5e-4cc1-82ec-a242c2ab5425"
22
+ "X-Device-Fingerprint": "531f14c7176b16ebeb18e2b23d6bd124",
23
+ "Content-Type": "application/json"
31
24
  },
32
25
  "url": "/classification/admin/level/edit",
33
26
  "method": "post",
@@ -43,12 +36,12 @@ const config = {
43
36
  "data": "{\"id\":1,\"classificationName\":\"个人基本概况信息\",\"classificationLevel\":2}",
44
37
  "baseURL": "http://localhost:62888"
45
38
  };
46
- createRoot(document.getElementById('root')).render(_jsx(_Fragment, { children: _jsx("button", { onClick: () => createMessageVerifyModal({
47
- data,
48
- config,
49
- response: {
50
- config
51
- },
52
- lang: 'en',
53
- http: axios,
54
- }), children: "Show verify Modal" }) }));
39
+ const promise = { current: null };
40
+ createRoot(document.getElementById('root')).render(_jsxs(_Fragment, { children: [_jsx("button", { onClick: () => {
41
+ return VerifyHandler({ data, config, http: axios, verifyPromise: promise, response: {} });
42
+ }, children: "Show verify Modal" }), _jsx("button", { onClick: () => createReLoginModal({
43
+ goLogin: () => {
44
+ console.log('goLogin');
45
+ },
46
+ lang: 'zh',
47
+ }), children: "Show login Modal" })] }));
@@ -0,0 +1,5 @@
1
+ import { LoginModalConfig } from '../utils/type.js';
2
+ declare const ReLoginModal: ({ props }: {
3
+ props: LoginModalConfig;
4
+ }) => import("react/jsx-runtime.js").JSX.Element;
5
+ export default ReLoginModal;
@@ -0,0 +1,24 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { useState } from 'react';
3
+ import { Modal, Button } from '../compoments/index.js';
4
+ import t from '../utils/i18n.js';
5
+ const ReLoginModal = ({ props }) => {
6
+ const { goLogin, lang, onClose: destroyModal } = props || {};
7
+ const [visible, setVisible] = useState(true);
8
+ const onClose = () => {
9
+ setVisible(false);
10
+ goLogin();
11
+ destroyModal?.();
12
+ };
13
+ 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: {
14
+ background: '#1677ff',
15
+ color: '#fff',
16
+ border: 'none',
17
+ width: 80,
18
+ height: 36,
19
+ fontSize: 14,
20
+ borderRadius: 8,
21
+ boxShadow: '0 2px 8px rgba(22,119,255,0.08)',
22
+ }, onClick: onClose, children: t('ok', lang) }) })] }));
23
+ };
24
+ export default ReLoginModal;
@@ -0,0 +1,5 @@
1
+ import { VerifyModalConfig } from '../utils/type.js';
2
+ declare const CreateMessageVerifyModal: ({ props }: {
3
+ props: VerifyModalConfig;
4
+ }) => import("react/jsx-runtime.js").JSX.Element;
5
+ export default CreateMessageVerifyModal;
@@ -0,0 +1,117 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { useEffect, useState } from 'react';
3
+ import { Modal, Input, Button, message } from '../compoments/index.js';
4
+ import Api from '../utils/resource.js';
5
+ import t from '../utils/i18n.js';
6
+ import { axios } from '@yqg/resource';
7
+ const CreateMessageVerifyModal = ({ props }) => {
8
+ const [visible, setVisible] = useState(true);
9
+ const [countdown, setCountdown] = useState(60);
10
+ const [otp, setOtp] = useState('');
11
+ const [captchaImage, setCaptchaImage] = useState('');
12
+ const [captchCode, setCaptchCode] = useState('');
13
+ const [captchaKey, setCaptchaKey] = useState('');
14
+ const { data, http, lang, sendApi = '/admin/sms/send', config, apiResolve, apiPromiseToEmpty, onClose, response } = props || {};
15
+ const dataObj = JSON.parse(data || '{}');
16
+ const { mobile, verifyCodeKey } = dataObj || {};
17
+ const getKey = async () => {
18
+ try {
19
+ const res = await Api.getCaptchaKey();
20
+ const { body: key } = res.data || {};
21
+ setCaptchaKey(key);
22
+ if (key) {
23
+ const image = Api.getCaptchaImgUrl(key);
24
+ setCaptchaImage(image);
25
+ }
26
+ }
27
+ catch (err) {
28
+ const msg = typeof err === 'object' && err !== null && 'message' in err
29
+ ? err.message
30
+ : String(err);
31
+ message.error(msg);
32
+ }
33
+ };
34
+ useEffect(() => {
35
+ let timer = null;
36
+ if (visible && countdown > 0) {
37
+ timer = setInterval(() => {
38
+ setCountdown((prev) => prev - 1);
39
+ }, 1000);
40
+ }
41
+ if (countdown === 0) {
42
+ getKey();
43
+ }
44
+ return () => {
45
+ if (timer)
46
+ clearInterval(timer);
47
+ };
48
+ }, [visible, countdown]);
49
+ const handleResend = async () => {
50
+ const formData = new FormData();
51
+ formData.append('captchaKey', captchaKey);
52
+ formData.append('captcha', captchCode);
53
+ // 重新发送验证码
54
+ const res = await axios.post(sendApi, formData);
55
+ const { code, detail } = res.data?.status || {};
56
+ if (code !== 0) {
57
+ message.error(detail || t('sendFailed', lang));
58
+ return;
59
+ }
60
+ message.success(t('sendSuccess', lang));
61
+ // 重置倒计时、验证码
62
+ setCountdown(60);
63
+ setOtp('');
64
+ };
65
+ return (_jsxs(Modal, { width: 420, visible: visible, onClose: () => {
66
+ setVisible(false);
67
+ apiPromiseToEmpty?.();
68
+ onClose?.();
69
+ }, 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) => {
70
+ setOtp(val);
71
+ if (val.length === 6) {
72
+ try {
73
+ const res = await Promise.race([
74
+ new Promise((resolve, reject) => {
75
+ setTimeout(() => {
76
+ reject(new Error('Timeout'));
77
+ }, 1000);
78
+ }),
79
+ new Promise((resolve, reject) => {
80
+ http({
81
+ ...config,
82
+ headers: {
83
+ ...http.defaults.headers.common,
84
+ 'sms-code': val,
85
+ 'sms-code-key': verifyCodeKey,
86
+ 'Content-Type': config.headers['Content-Type'],
87
+ }
88
+ }).then(res => {
89
+ console.log('VerifyHandler => then', response);
90
+ resolve(res);
91
+ }).catch(err => {
92
+ reject(err);
93
+ });
94
+ })
95
+ ]);
96
+ if (res?.data?.status?.code === 0) {
97
+ // apiResolve(res);
98
+ setVisible(false);
99
+ }
100
+ else {
101
+ message.error(t('verifyFail', lang));
102
+ setOtp('');
103
+ }
104
+ }
105
+ catch (error) {
106
+ console.log('VerifyHandler => catch', response);
107
+ console.warn('catch=>error', error);
108
+ message.error(t('verifyFail', lang));
109
+ setOtp('');
110
+ }
111
+ }
112
+ } }), _jsx(Button, { disabled: countdown > 0 || !captchCode, onClick: handleResend, style: { padding: '8px' }, children: countdown > 0 ? t('countDownSecound', lang, { countdown }) : t('reSend', lang) })] }), countdown > 0 ? null :
113
+ _jsxs("div", { style: { marginTop: 12, display: 'flex', alignItems: 'center' }, children: [_jsx(Input, { placeholder: t('pleaseEnterPicVerifyCode', lang), onChange: (e) => {
114
+ setCaptchCode(e);
115
+ }, style: { width: 300 } }), captchaImage && _jsx("img", { src: captchaImage, alt: t('verifyCode', lang), style: { width: 100, height: 30, marginLeft: 8 }, onClick: getKey })] }), (countdown > 0 || captchCode) ? null : _jsx("div", { style: { fontSize: 14, color: 'red' }, children: t('pleaseEnterAndSend', lang) }), _jsx("div", { style: { fontSize: 14, color: '#666', marginTop: 12 }, children: t('chidoriOpenPro', lang) })] }));
116
+ };
117
+ export default CreateMessageVerifyModal;
@@ -1,5 +1,5 @@
1
- import { ModalConfig } from './utils/type.js';
1
+ import { LoginModalConfig } from './utils/type.js';
2
2
  declare const ReLoginModal: ({ props }: {
3
- props: ModalConfig;
3
+ props: LoginModalConfig;
4
4
  }) => import("react/jsx-runtime.js").JSX.Element;
5
5
  export default ReLoginModal;
@@ -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
- console.log('props', props);
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: "\u8D26\u53F7\u5B89\u5168\u63D0\u9192" }), _jsx("div", { style: { color: '#222', fontSize: 16, marginBottom: 40, lineHeight: '24px' }, children: "\u68C0\u6D4B\u5230\u60A8\u7684\u767B\u5F55\u73AF\u5883\u6216\u7F51\u7EDC\u4FE1\u606F\u6709\u53D8\u52A8\uFF0C\u4E3A\u4FDD\u969C\u8D26\u6237\u5B89\u5168\uFF0C\u8BF7\u91CD\u65B0\u767B\u5F55\u9A8C\u8BC1\u8EAB\u4EFD" }), _jsx("div", { style: { display: 'flex', justifyContent: 'center' }, children: _jsx(Button, { style: {
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: 160,
15
- height: 44,
16
- fontSize: 18,
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: "\u597D\u7684" }) })] }));
21
+ }, onClick: onClose, children: t('ok', lang) }) })] }));
21
22
  };
22
23
  export default ReLoginModal;
@@ -1 +1 @@
1
- {"root":["../src/index.tsx","../src/main.tsx","../src/relogin-modal.tsx","../src/resource.ts","../src/verify-modal.tsx","../src/vite-env.d.ts","../src/compoments/button.tsx","../src/compoments/index.ts","../src/compoments/input.tsx","../src/compoments/message.tsx","../src/compoments/modal.tsx","../src/locales/en.ts","../src/locales/id.ts","../src/locales/zh.ts","../src/utils/i18n.ts","../src/utils/status.ts","../src/utils/type.ts"],"version":"5.7.3"}
1
+ {"root":["../src/index.tsx","../src/main.tsx","../src/vite-env.d.ts","../src/compoments/button.tsx","../src/compoments/index.ts","../src/compoments/input.tsx","../src/compoments/message.tsx","../src/compoments/modal.tsx","../src/locales/en.ts","../src/locales/id.ts","../src/locales/zh.ts","../src/modal/relogin-modal.tsx","../src/modal/verify-modal.tsx","../src/utils/i18n.ts","../src/utils/resource.ts","../src/utils/status.ts","../src/utils/type.ts"],"version":"5.7.3"}
@@ -0,0 +1,2 @@
1
+ declare const _default: import("@yqg/resource").default & Record<"getCaptchaKey" | "reSendCode" | "getCaptchaImgUrl", import("@yqg/resource").CustomMethod>;
2
+ export default _default;
@@ -0,0 +1,7 @@
1
+ import { assign, customPost } from '@yqg/resource';
2
+ const api = {
3
+ getCaptchaKey: customPost('/messageVerify/admin/captcha/key'),
4
+ reSendCode: customPost('/admin/sms/send'),
5
+ getCaptchaImgUrl: (captchaKey) => { return `/messageVerify/admin/captcha/image/${captchaKey}`; },
6
+ };
7
+ export default assign(api);
@@ -1,4 +1,4 @@
1
- export type ModalConfig = {
1
+ export type VerifyModalConfig = {
2
2
  data: string;
3
3
  onClose?: () => void;
4
4
  config: {
@@ -7,7 +7,7 @@ export type ModalConfig = {
7
7
  };
8
8
  [key: string]: unknown;
9
9
  };
10
- lang: 'zh' | 'en' | 'id';
10
+ lang?: 'zh' | 'en' | 'id';
11
11
  http: {
12
12
  (params: object): Promise<unknown>;
13
13
  defaults: {
@@ -18,6 +18,17 @@ export type ModalConfig = {
18
18
  };
19
19
  };
20
20
  };
21
- api?: string;
21
+ sendApi?: string;
22
+ apiReject?: any;
23
+ apiResolve?: any;
24
+ apiPromiseToEmpty?: () => void;
25
+ verifyPromise: {
26
+ current: Promise<any> | null;
27
+ };
22
28
  response: any;
23
29
  };
30
+ export type LoginModalConfig = {
31
+ goLogin: () => void;
32
+ onClose?: () => void;
33
+ lang?: 'zh' | 'en' | 'id';
34
+ };
@@ -1,5 +1,5 @@
1
- import { ModalConfig } from './utils/type.js';
1
+ import { VerifyModalConfig } from './utils/type.js';
2
2
  declare const CreateMessageVerifyModal: ({ props }: {
3
- props: ModalConfig;
3
+ props: VerifyModalConfig;
4
4
  }) => import("react/jsx-runtime.js").JSX.Element;
5
5
  export default CreateMessageVerifyModal;
@@ -11,10 +11,9 @@ const CreateMessageVerifyModal = ({ props }) => {
11
11
  const [captchaImage, setCaptchaImage] = useState('');
12
12
  const [captchCode, setCaptchCode] = useState('');
13
13
  const [captchaKey, setCaptchaKey] = useState('');
14
- const { data, http, lang, api = '/admin/sms/send', response } = props || {};
14
+ const { data, http, lang, sendApi = '/admin/sms/send', config, apiResolve, apiPromiseToEmpty } = props || {};
15
15
  const dataObj = JSON.parse(data || '{}');
16
16
  const { mobile, verifyCodeKey } = dataObj || {};
17
- console.log('response===>', response);
18
17
  const getKey = async () => {
19
18
  try {
20
19
  const res = await Api.getCaptchaKey();
@@ -52,45 +51,65 @@ const CreateMessageVerifyModal = ({ props }) => {
52
51
  formData.append('captchaKey', captchaKey);
53
52
  formData.append('captcha', captchCode);
54
53
  // 重新发送验证码
55
- const res = await axios.post(api, formData);
54
+ const res = await axios.post(sendApi, formData);
56
55
  const { code, detail } = res.data?.status || {};
57
56
  if (code !== 0) {
58
57
  message.error(detail || t('sendFailed', lang));
59
58
  return;
60
59
  }
61
60
  message.success(t('sendSuccess', lang));
61
+ // 重置倒计时、验证码
62
62
  setCountdown(60);
63
+ setOtp('');
63
64
  };
64
65
  return (_jsxs(Modal, { width: 420, visible: visible, onClose: () => {
65
66
  setVisible(false);
67
+ apiPromiseToEmpty?.();
66
68
  props.onClose?.();
67
69
  }, 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) => {
68
70
  setOtp(val);
69
71
  if (val.length === 6) {
70
- const { data: { status: { code, detail } = {} } } = response || {};
71
- http({
72
- ...response?.config,
73
- headers: {
74
- ...http.defaults.headers.common,
75
- 'sms-code': val,
76
- 'sms-code-key': verifyCodeKey,
77
- 'Content-Type': response?.config.headers['Content-Type'],
72
+ try {
73
+ const res = await Promise.race([
74
+ new Promise((resolve, reject) => {
75
+ setTimeout(() => {
76
+ reject(new Error('Timeout'));
77
+ }, 1000);
78
+ }),
79
+ new Promise((resolve, reject) => {
80
+ http({
81
+ ...config,
82
+ headers: {
83
+ ...http.defaults.headers.common,
84
+ 'sms-code': val,
85
+ 'sms-code-key': verifyCodeKey,
86
+ 'Content-Type': config.headers['Content-Type'],
87
+ }
88
+ }).then(res => {
89
+ resolve(res);
90
+ }).catch(err => {
91
+ reject(err);
92
+ });
93
+ })
94
+ ]);
95
+ if (res?.data?.status?.code === 0) {
96
+ apiResolve(res);
97
+ setVisible(false);
98
+ }
99
+ else {
100
+ message.error('验证失败');
101
+ setOtp('');
78
102
  }
79
- });
80
- console.log(response, code, 'config');
81
- if (code !== 0) {
82
- const detailObj = JSON.parse(detail || '{}');
83
- message.error(detailObj?.message || t('verifyFailed', lang));
84
- return;
85
103
  }
86
- else {
87
- message.success(t('verifySuccess', lang));
88
- setVisible(false);
104
+ catch (error) {
105
+ console.warn('catch', error);
106
+ message.error('验证失败');
107
+ setOtp('');
89
108
  }
90
109
  }
91
110
  } }), _jsx(Button, { disabled: countdown > 0 || !captchCode, onClick: handleResend, style: { padding: '8px' }, children: countdown > 0 ? t('countDownSecound', lang, { countdown }) : t('reSend', lang) })] }), countdown > 0 ? null :
92
111
  _jsxs("div", { style: { marginTop: 12, display: 'flex', alignItems: 'center' }, children: [_jsx(Input, { placeholder: t('pleaseEnterPicVerifyCode', lang), onChange: (e) => {
93
112
  setCaptchCode(e);
94
- }, style: { width: 300 } }), captchaImage && _jsx("img", { src: captchaImage, alt: t('verifyCode', lang), style: { width: 100, height: 30, marginLeft: 8 }, onClick: getKey })] }), (countdown > 0 || captchCode) ? null : _jsx("div", { style: { fontSize: 14, color: 'red' }, children: t('pleaseEnterAndSend', lang) })] }));
113
+ }, style: { width: 300 } }), captchaImage && _jsx("img", { src: captchaImage, alt: t('verifyCode', lang), style: { width: 100, height: 30, marginLeft: 8 }, onClick: getKey })] }), (countdown > 0 || captchCode) ? null : _jsx("div", { style: { fontSize: 14, color: 'red' }, children: t('pleaseEnterAndSend', lang) }), _jsx("div", { style: { fontSize: 14, color: '#666', marginTop: 12 }, children: t('chidoriOpenPro', lang) })] }));
95
114
  };
96
115
  export default CreateMessageVerifyModal;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "message-verify",
3
- "version": "1.0.1-beta.6",
3
+ "version": "1.0.1-beta.60",
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,55 +1,87 @@
1
1
  import ReactDOM from 'react-dom/client'
2
- import VerifyModal from './verify-modal.js'
2
+ import VerifyModal from './modal/verify-modal.js'
3
3
  import Fingerprint2 from 'fingerprintjs2';
4
- import { ModalConfig } from './utils/type.js';
4
+ import ReLoginModal from './modal/relogin-modal.js';
5
+ import { VerifyModalConfig, LoginModalConfig } from './utils/type.js';
5
6
 
6
- let cachedFingerprint: string | null = null;
7
+ let fingerprintPromise: Promise<string> | null = null; // 用 Promise 本身作为缓存
8
+ let modalRoot: ReactDOM.Root | null = null
7
9
  export const initFingerprint = async (): Promise<string> => {
8
- if (cachedFingerprint) {
9
- // 已有缓存,直接返回 Promise
10
- return Promise.resolve(cachedFingerprint);
11
- }
12
- // 首次异步获取并缓存
13
- return new Promise((resolve) => {
14
- Fingerprint2.get(function (components) {
15
- console.log('components', components);
16
- const includeKeys = ['userAgent', 'deviceMemory', 'cpuClass', 'hardwareConcurrency', 'platform'];
17
- const values = components
18
- .filter(component => includeKeys.includes(component.key))
19
- .map(component => component.value)
20
- .join('###');
21
- const fingerprint = Fingerprint2.x64hash128(values, 31);
22
- cachedFingerprint = fingerprint;
23
- resolve(fingerprint);
10
+ console.log('fingerprintPromise:', fingerprintPromise);
11
+ if (!fingerprintPromise) {
12
+ fingerprintPromise = new Promise((resolve) => {
13
+ Fingerprint2.get(components => {
14
+ const includeKeys = ['userAgent', 'cpuClass', 'hardwareConcurrency', 'platform'];
15
+ console.log('components:', components);
16
+ const values = components
17
+ .filter(c => includeKeys.includes(c.key))
18
+ .map(c => c.value)
19
+ .join('###');
20
+ console.log('values:', values);
21
+ const fingerprint = Fingerprint2.x64hash128(values, 31);
22
+ console.log('fingerprint:', fingerprint);
23
+ resolve(fingerprint);
24
+ });
24
25
  });
25
- });
26
+ }
27
+ return fingerprintPromise;
26
28
  };
27
29
 
28
- let modalRoot: ReactDOM.Root | null = null
30
+ const destroyModal = (modalId: string) => {
31
+ if (modalRoot) {
32
+ modalRoot.unmount()
33
+ document.getElementById(modalId)?.remove()
34
+ modalRoot = null
35
+ }
36
+ }
29
37
 
30
- export const createMessageVerifyModal = (modalProps: ModalConfig) => {
31
- const container = document.createElement('div')
32
- container.id = 'antd-modal-container'
33
- document.body.appendChild(container)
38
+ const creatModal = (modalProps: VerifyModalConfig | LoginModalConfig, modalId: string, ModalDom:any) => {
39
+ destroyModal(modalId);
40
+ const container = document.createElement('div')
41
+ container.id = modalId
42
+ document.body.appendChild(container)
34
43
 
35
- modalRoot = ReactDOM.createRoot(container)
36
- modalRoot.render(
37
- <VerifyModal
38
- props={{
39
- ...modalProps,
40
- onClose: () => {
41
- modalProps.onClose?.()
42
- destroyModal()
43
- }
44
- }}
45
- />
46
- )
44
+ modalRoot = ReactDOM.createRoot(container)
45
+ modalRoot.render(
46
+ <ModalDom
47
+ props={{
48
+ ...modalProps,
49
+ onClose: () => {
50
+ destroyModal(modalId);
51
+ }
52
+ }}
53
+ />
54
+ )
47
55
  }
48
56
 
49
- const destroyModal = () => {
50
- if (modalRoot) {
51
- modalRoot.unmount()
52
- document.getElementById('antd-modal-container')?.remove()
53
- modalRoot = null
54
- }
55
- }
57
+ const createMessageVerifyModal = (modalProps: VerifyModalConfig) => {
58
+ const verifyModalId = 'verify-modal-container';
59
+ creatModal(modalProps, verifyModalId, VerifyModal);
60
+ }
61
+ // 新增 relogin 弹窗创建方法
62
+ export const createReLoginModal = (modalProps: LoginModalConfig) => {
63
+ const reLoginModalId = 'relogin-modal-container';
64
+ creatModal(modalProps, reLoginModalId, ReLoginModal);
65
+ }
66
+
67
+ export const VerifyHandler = ({data, config, http, verifyPromise, sendApi, response}: VerifyModalConfig): Promise<any> => {
68
+ console.log('VerifyHandler =>', response);
69
+ const toEmpty = () => {
70
+ verifyPromise.current = null;
71
+ };
72
+ if (!verifyPromise.current) {
73
+ verifyPromise.current = new Promise((resolve, reject) => {
74
+ createMessageVerifyModal({
75
+ data,
76
+ config,
77
+ http,
78
+ apiResolve: resolve,
79
+ apiReject: reject,
80
+ apiPromiseToEmpty: toEmpty,
81
+ sendApi,
82
+ response
83
+ } as VerifyModalConfig);
84
+ }).finally(toEmpty);
85
+ }
86
+ return verifyPromise.current;
87
+ };
package/src/locales/en.ts CHANGED
@@ -6,5 +6,10 @@ 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',
13
+ chidoriOpenPro: 'Chidori has activated security protection for you',
14
+ verifyFail: 'Validation failed'
10
15
  };
package/src/locales/id.ts CHANGED
@@ -6,5 +6,10 @@ 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',
13
+ chidoriOpenPro: 'chidori telah mengaktifkan keamanan untuk Anda',
14
+ verifyFail: 'Autentikasi gagal'
10
15
  };
package/src/locales/zh.ts CHANGED
@@ -6,5 +6,10 @@ export default {
6
6
  sendSuccess: '发送成功',
7
7
  sendFailed: '发送失败',
8
8
  reSend: '重新发送',
9
- countDownSecound: '{countdown}秒'
9
+ countDownSecound: '{countdown}秒',
10
+ accountAlert: '账号安全提醒',
11
+ alertContent: '检测到您的登录环境或网络信息有变动,为保障账户安全,请重新登录验证身份',
12
+ ok: '好的',
13
+ chidoriOpenPro: 'chidori已为您开启安全防护',
14
+ verifyFail: '验证失败'
10
15
  };
package/src/main.tsx CHANGED
@@ -1,11 +1,12 @@
1
1
  import { createRoot } from 'react-dom/client';
2
- import { createMessageVerifyModal, initFingerprint } from './index.js'; // 或 './index'
2
+ import { initFingerprint, createReLoginModal, VerifyHandler } 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\":\"需要填写验证码\"}";
6
6
 
7
7
  const fp = await initFingerprint();
8
- console.log(fp);
8
+ const fp2 = await initFingerprint();
9
+ console.log(fp, fp2);
9
10
 
10
11
  const config = {
11
12
  "transitional": {
@@ -13,12 +14,6 @@ const config = {
13
14
  "forcedJSONParsing": true,
14
15
  "clarifyTimeoutError": false
15
16
  },
16
- "transformRequest": [
17
- null
18
- ],
19
- "transformResponse": [
20
- null
21
- ],
22
17
  "timeout": 0,
23
18
  "xsrfCookieName": "XSRF-TOKEN",
24
19
  "xsrfHeaderName": "X-XSRF-TOKEN",
@@ -26,10 +21,8 @@ const config = {
26
21
  "maxBodyLength": -1,
27
22
  "headers": {
28
23
  "Accept": "application/json, text/plain, */*",
29
- "X-Device-Fingerprint": "185fcce88c629725321adf29daa5e444",
30
- "Content-Type": "application/json",
31
- "sms-code": "121212",
32
- "sms-code-key": "212190c7-2f5e-4cc1-82ec-a242c2ab5425"
24
+ "X-Device-Fingerprint": "531f14c7176b16ebeb18e2b23d6bd124",
25
+ "Content-Type": "application/json"
33
26
  },
34
27
  "url": "/classification/admin/level/edit",
35
28
  "method": "post",
@@ -44,18 +37,22 @@ const config = {
44
37
  "formInstance": {},
45
38
  "data": "{\"id\":1,\"classificationName\":\"个人基本概况信息\",\"classificationLevel\":2}",
46
39
  "baseURL": "http://localhost:62888"
47
- };
40
+ }
41
+
42
+ const promise = {current: null};
48
43
  createRoot(document.getElementById('root')!).render(
49
44
  <>
50
- <button onClick={() => createMessageVerifyModal({
51
- data,
52
- config,
53
- response: {
54
- config
45
+ <button onClick={() => {
46
+ return VerifyHandler({data, config, http: axios, verifyPromise: promise, response: {}});
47
+ }}>
48
+ Show verify Modal
49
+ </button>
50
+ <button onClick={() => createReLoginModal({
51
+ goLogin: () => {
52
+ console.log('goLogin');
55
53
  },
56
- lang: 'en',
57
- http: axios,
54
+ lang: 'zh',
58
55
  })}>
59
- Show verify Modal
56
+ Show login Modal
60
57
  </button>
61
58
  </>);
@@ -1,20 +1,23 @@
1
1
  import { useState } from 'react'
2
- import { Modal, Button } from './compoments/index.js'
3
- import { ModalConfig } from './utils/type.js';
2
+ import { Modal, Button } from '../compoments/index.js'
3
+ import { LoginModalConfig } from '../utils/type.js';
4
+ import t from '../utils/i18n.js'
4
5
 
5
- const ReLoginModal = ({ props }: { props: ModalConfig }) => {
6
- console.log('props', props);
6
+ const ReLoginModal = ({ props }: { props: LoginModalConfig }) => {
7
+ const { goLogin, lang, onClose: destroyModal } = props || {};
7
8
  const [visible, setVisible] = useState(true);
8
9
  const onClose = () => {
9
10
  setVisible(false);
11
+ goLogin();
12
+ destroyModal?.();
10
13
  };
11
14
  return (
12
15
  <Modal visible={visible} onClose={onClose} width={420}>
13
16
  <div style={{ fontWeight: 500, fontSize: 20, marginBottom: 24 }}>
14
- 账号安全提醒
17
+ {t('accountAlert', lang)}
15
18
  </div>
16
19
  <div style={{ color: '#222', fontSize: 16, marginBottom: 40, lineHeight: '24px' }}>
17
- 检测到您的登录环境或网络信息有变动,为保障账户安全,请重新登录验证身份
20
+ {t('alertContent', lang)}
18
21
  </div>
19
22
  <div style={{ display: 'flex', justifyContent: 'center' }}>
20
23
  <Button
@@ -22,16 +25,15 @@ const ReLoginModal = ({ props }: { props: ModalConfig }) => {
22
25
  background: '#1677ff',
23
26
  color: '#fff',
24
27
  border: 'none',
25
- width: 160,
26
- height: 44,
27
- fontSize: 18,
28
- fontWeight: 500,
28
+ width: 80,
29
+ height: 36,
30
+ fontSize: 14,
29
31
  borderRadius: 8,
30
32
  boxShadow: '0 2px 8px rgba(22,119,255,0.08)',
31
33
  }}
32
34
  onClick={onClose}
33
35
  >
34
- 好的
36
+ {t('ok', lang)}
35
37
  </Button>
36
38
  </div>
37
39
  </Modal>
@@ -1,21 +1,20 @@
1
1
  import { useEffect, useState } from 'react'
2
- import { Modal, Input, Button, message } from './compoments/index.js'
3
- import Api from './resource.js'
4
- import t from './utils/i18n.js'
5
- import { ModalConfig } from './utils/type.js';
2
+ import { Modal, Input, Button, message } from '../compoments/index.js'
3
+ import Api from '../utils/resource.js'
4
+ import t from '../utils/i18n.js'
5
+ import { VerifyModalConfig } from '../utils/type.js';
6
6
  import { axios } from '@yqg/resource';
7
7
 
8
- const CreateMessageVerifyModal = ({ props }: { props: ModalConfig }) => {
8
+ const CreateMessageVerifyModal = ({ props }: { props: VerifyModalConfig }) => {
9
9
  const [visible, setVisible] = useState(true);
10
10
  const [countdown, setCountdown] = useState(60);
11
11
  const [otp, setOtp] = useState('');
12
12
  const [captchaImage, setCaptchaImage] = useState<string>('');
13
13
  const [captchCode, setCaptchCode] = useState<string>('');
14
14
  const [captchaKey, setCaptchaKey] = useState<string>('');
15
- const { data, http, lang, api='/admin/sms/send', response } = props || {};
15
+ const { data, http, lang, sendApi = '/admin/sms/send', config, apiResolve, apiPromiseToEmpty, onClose, response } = props || {};
16
16
  const dataObj = JSON.parse(data || '{}');
17
17
  const { mobile, verifyCodeKey } = dataObj || {};
18
- console.log('response===>', response);
19
18
 
20
19
  const getKey = async () => {
21
20
  try {
@@ -26,10 +25,11 @@ const CreateMessageVerifyModal = ({ props }: { props: ModalConfig }) => {
26
25
  const image = Api.getCaptchaImgUrl(key) as unknown;
27
26
  setCaptchaImage(image as string);
28
27
  }
29
- } catch (err) {const msg =
30
- typeof err === 'object' && err !== null && 'message' in err
31
- ? (err as {message: string}).message
32
- : String(err);
28
+ } catch (err) {
29
+ const msg =
30
+ typeof err === 'object' && err !== null && 'message' in err
31
+ ? (err as { message: string }).message
32
+ : String(err);
33
33
  message.error(msg as React.ReactNode);
34
34
  }
35
35
  }
@@ -54,14 +54,16 @@ const CreateMessageVerifyModal = ({ props }: { props: ModalConfig }) => {
54
54
  formData.append('captchaKey', captchaKey);
55
55
  formData.append('captcha', captchCode);
56
56
  // 重新发送验证码
57
- const res = await axios.post(api, formData);
57
+ const res = await axios.post(sendApi, formData);
58
58
  const { code, detail } = res.data?.status || {};
59
59
  if (code !== 0) {
60
60
  message.error(detail || t('sendFailed', lang));
61
61
  return;
62
62
  }
63
63
  message.success(t('sendSuccess', lang));
64
+ // 重置倒计时、验证码
64
65
  setCountdown(60);
66
+ setOtp('');
65
67
  }
66
68
 
67
69
  return (
@@ -70,7 +72,8 @@ const CreateMessageVerifyModal = ({ props }: { props: ModalConfig }) => {
70
72
  visible={visible}
71
73
  onClose={() => {
72
74
  setVisible(false);
73
- props.onClose?.();
75
+ apiPromiseToEmpty?.();
76
+ onClose?.();
74
77
  }}
75
78
  >
76
79
  <div style={{ fontSize: 14, color: '#666' }}>{t('alreadySend', lang, { phone: mobile })}</div>
@@ -82,24 +85,42 @@ const CreateMessageVerifyModal = ({ props }: { props: ModalConfig }) => {
82
85
  onChange={async (val) => {
83
86
  setOtp(val);
84
87
  if (val.length === 6) {
85
- const {data: {status: {code, detail} = {}}} = response || {};
86
- http({
87
- ...response?.config,
88
- headers: {
89
- ...http.defaults.headers.common,
90
- 'sms-code': val,
91
- 'sms-code-key': verifyCodeKey,
92
- 'Content-Type': response?.config.headers['Content-Type'],
88
+ try {
89
+ const res = await Promise.race([
90
+ new Promise((resolve, reject) => {
91
+ setTimeout(() => {
92
+ reject(new Error('Timeout'));
93
+ }, 1000);
94
+ }),
95
+ new Promise((resolve, reject) => {
96
+ http({
97
+ ...config,
98
+ headers: {
99
+ ...http.defaults.headers.common,
100
+ 'sms-code': val,
101
+ 'sms-code-key': verifyCodeKey,
102
+ 'Content-Type': config.headers['Content-Type'],
103
+ }
104
+ }).then(res => {
105
+ console.log('VerifyHandler => then', response);
106
+ resolve(res);
107
+ }).catch(err => {
108
+ reject(err);
109
+ })
110
+ })
111
+ ]) as any;
112
+ if (res?.data?.status?.code === 0) {
113
+ // apiResolve(res);
114
+ setVisible(false);
115
+ } else {
116
+ message.error(t('verifyFail', lang));
117
+ setOtp('');
93
118
  }
94
- }) as any;
95
- console.log(response, code, 'config');
96
- if(code !== 0) {
97
- const detailObj = JSON.parse(detail || '{}');
98
- message.error(detailObj?.message || t('verifyFailed', lang));
99
- return;
100
- } else {
101
- message.success(t('verifySuccess', lang));
102
- setVisible(false);
119
+ } catch (error) {
120
+ console.log('VerifyHandler => catch', response);
121
+ console.warn('catch=>error', error);
122
+ message.error(t('verifyFail', lang));
123
+ setOtp('');
103
124
  }
104
125
  }
105
126
  }} />
@@ -124,6 +145,7 @@ const CreateMessageVerifyModal = ({ props }: { props: ModalConfig }) => {
124
145
  {captchaImage && <img src={captchaImage} alt={t('verifyCode', lang)} style={{ width: 100, height: 30, marginLeft: 8 }} onClick={getKey} />}
125
146
  </div>}
126
147
  {(countdown > 0 || captchCode) ? null : <div style={{ fontSize: 14, color: 'red' }}>{t('pleaseEnterAndSend', lang)}</div>}
148
+ <div style={{ fontSize: 14, color: '#666', marginTop: 12 }}>{t('chidoriOpenPro', lang)}</div>
127
149
  </Modal>
128
150
  );
129
151
  };
package/src/utils/type.ts CHANGED
@@ -1,5 +1,5 @@
1
1
 
2
- export type ModalConfig = {
2
+ export type VerifyModalConfig = {
3
3
  data: string;
4
4
  onClose?: () => void
5
5
  config: {
@@ -8,7 +8,7 @@ export type ModalConfig = {
8
8
  };
9
9
  [key: string]: unknown;
10
10
  };
11
- lang: 'zh' | 'en' | 'id';
11
+ lang?: 'zh' | 'en' | 'id';
12
12
  http: {
13
13
  (params: object): Promise<unknown>;
14
14
  defaults: {
@@ -19,6 +19,16 @@ export type ModalConfig = {
19
19
  }
20
20
  }
21
21
  };
22
- api?: string;
22
+ sendApi?: string;
23
+ apiReject?: any;
24
+ apiResolve?: any;
25
+ apiPromiseToEmpty?: () => void;
26
+ verifyPromise: {current: Promise<any> | null}
23
27
  response: any;
28
+ }
29
+
30
+ export type LoginModalConfig = {
31
+ goLogin: () => void;
32
+ onClose?: () => void
33
+ lang?: 'zh' | 'en' | 'id';
24
34
  }
File without changes