message-verify 1.0.1-beta.38 → 1.0.1-beta.4

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 CHANGED
@@ -1,4 +1,3 @@
1
- import { ModalConfig, LoginModalConfig } from './utils/type.js';
1
+ import { ModalConfig } 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,27 +2,26 @@ 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
- import ReLoginModal from './relogin-modal.js';
6
- let fingerprintPromise = null; // 用 Promise 本身作为缓存
5
+ let cachedFingerprint = null;
7
6
  export const initFingerprint = async () => {
8
- console.log('fingerprintPromise:', fingerprintPromise);
9
- if (!fingerprintPromise) {
10
- fingerprintPromise = new Promise((resolve) => {
11
- Fingerprint2.get(components => {
12
- const includeKeys = ['userAgent', 'cpuClass', 'hardwareConcurrency', 'platform'];
13
- console.log('components:', components);
14
- const values = components
15
- .filter(c => includeKeys.includes(c.key))
16
- .map(c => c.value)
17
- .join('###');
18
- console.log('values:', values);
19
- const fingerprint = Fingerprint2.x64hash128(values, 31);
20
- console.log('fingerprint:', fingerprint);
21
- resolve(fingerprint);
22
- });
23
- });
7
+ if (cachedFingerprint) {
8
+ // 已有缓存,直接返回 Promise
9
+ return Promise.resolve(cachedFingerprint);
24
10
  }
25
- return fingerprintPromise;
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);
23
+ });
24
+ });
26
25
  };
27
26
  let modalRoot = null;
28
27
  export const createMessageVerifyModal = (modalProps) => {
@@ -38,16 +37,6 @@ export const createMessageVerifyModal = (modalProps) => {
38
37
  }
39
38
  } }));
40
39
  };
41
- // 新增 relogin 弹窗创建方法
42
- export const createReLoginModal = (modalProps) => {
43
- const container = document.createElement('div');
44
- container.id = 'antd-modal-container';
45
- document.body.appendChild(container);
46
- modalRoot = ReactDOM.createRoot(container);
47
- modalRoot.render(_jsx(ReLoginModal, { props: {
48
- ...modalProps,
49
- } }));
50
- };
51
40
  const destroyModal = () => {
52
41
  if (modalRoot) {
53
42
  modalRoot.unmount();
@@ -7,9 +7,5 @@ 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
10
  };
15
11
  export default _default;
@@ -6,9 +6,5 @@ export default {
6
6
  sendSuccess: 'Successfully sent',
7
7
  sendFailed: 'Send failed',
8
8
  reSend: 'Resend',
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'
9
+ countDownSecound: '{countdown} seconds'
14
10
  };
@@ -7,9 +7,5 @@ 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
10
  };
15
11
  export default _default;
@@ -6,9 +6,5 @@ export default {
6
6
  sendSuccess: 'Berhasil dikirim',
7
7
  sendFailed: 'Gagal mengirim',
8
8
  reSend: 'Kirim Ulang',
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'
9
+ countDownSecound: '{countdown} detik'
14
10
  };
@@ -7,9 +7,5 @@ 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
10
  };
15
11
  export default _default;
@@ -6,9 +6,5 @@ export default {
6
6
  sendSuccess: '发送成功',
7
7
  sendFailed: '发送失败',
8
8
  reSend: '重新发送',
9
- countDownSecound: '{countdown}秒',
10
- accountAlert: '账号安全提醒',
11
- alertContent: '检测到您的登录环境或网络信息有变动,为保障账户安全,请重新登录验证身份',
12
- ok: '好的',
13
- chidoriOpenPro: 'chidori已为您开启安全防护'
9
+ countDownSecound: '{countdown}秒'
14
10
  };
package/dist/main.js CHANGED
@@ -1,17 +1,22 @@
1
- import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
1
+ import { jsx as _jsx, Fragment as _Fragment } from "react/jsx-runtime";
2
2
  import { createRoot } from 'react-dom/client';
3
- import { createMessageVerifyModal, initFingerprint, createReLoginModal } from './index.js'; // 或 './index'
3
+ import { createMessageVerifyModal, initFingerprint } 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
- const fp2 = await initFingerprint();
8
- console.log(fp, fp2);
7
+ console.log(fp);
9
8
  const config = {
10
9
  "transitional": {
11
10
  "silentJSONParsing": true,
12
11
  "forcedJSONParsing": true,
13
12
  "clarifyTimeoutError": false
14
13
  },
14
+ "transformRequest": [
15
+ null
16
+ ],
17
+ "transformResponse": [
18
+ null
19
+ ],
15
20
  "timeout": 0,
16
21
  "xsrfCookieName": "XSRF-TOKEN",
17
22
  "xsrfHeaderName": "X-XSRF-TOKEN",
@@ -20,7 +25,9 @@ const config = {
20
25
  "headers": {
21
26
  "Accept": "application/json, text/plain, */*",
22
27
  "X-Device-Fingerprint": "185fcce88c629725321adf29daa5e444",
23
- "Content-Type": "application/json"
28
+ "Content-Type": "application/json",
29
+ "sms-code": "121212",
30
+ "sms-code-key": "212190c7-2f5e-4cc1-82ec-a242c2ab5425"
24
31
  },
25
32
  "url": "/classification/admin/level/edit",
26
33
  "method": "post",
@@ -36,20 +43,12 @@ const config = {
36
43
  "data": "{\"id\":1,\"classificationName\":\"个人基本概况信息\",\"classificationLevel\":2}",
37
44
  "baseURL": "http://localhost:62888"
38
45
  };
39
- createRoot(document.getElementById('root')).render(_jsxs(_Fragment, { children: [_jsx("button", { onClick: () => createMessageVerifyModal({
40
- data,
41
- config,
42
- lang: 'en',
43
- http: axios,
44
- apiReject: () => {
45
- },
46
- apiResolve: () => {
47
- },
48
- apiPromiseToEmpty: () => {
49
- }
50
- }), children: "Show verify Modal" }), _jsx("button", { onClick: () => createReLoginModal({
51
- goLogin: () => {
52
- console.log('goLogin');
53
- },
54
- lang: 'zh',
55
- }), children: "Show login Modal" })] }));
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" }) }));
@@ -1,5 +1,5 @@
1
- import { LoginModalConfig } from './utils/type.js';
1
+ import { ModalConfig } from './utils/type.js';
2
2
  declare const ReLoginModal: ({ props }: {
3
- props: LoginModalConfig;
3
+ props: ModalConfig;
4
4
  }) => import("react/jsx-runtime.js").JSX.Element;
5
5
  export default ReLoginModal;
@@ -1,23 +1,22 @@
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';
5
4
  const ReLoginModal = ({ props }) => {
6
- const { goLogin, lang } = props || {};
5
+ console.log('props', props);
7
6
  const [visible, setVisible] = useState(true);
8
7
  const onClose = () => {
9
8
  setVisible(false);
10
- goLogin();
11
9
  };
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: {
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: {
13
11
  background: '#1677ff',
14
12
  color: '#fff',
15
13
  border: 'none',
16
- width: 80,
17
- height: 36,
18
- fontSize: 14,
14
+ width: 160,
15
+ height: 44,
16
+ fontSize: 18,
17
+ fontWeight: 500,
19
18
  borderRadius: 8,
20
19
  boxShadow: '0 2px 8px rgba(22,119,255,0.08)',
21
- }, onClick: onClose, children: t('ok', lang) }) })] }));
20
+ }, onClick: onClose, children: "\u597D\u7684" }) })] }));
22
21
  };
23
22
  export default ReLoginModal;
@@ -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: {
@@ -19,11 +19,5 @@ export type ModalConfig = {
19
19
  };
20
20
  };
21
21
  api?: string;
22
- apiReject: any;
23
- apiResolve: any;
24
- apiPromiseToEmpty: () => void;
25
- };
26
- export type LoginModalConfig = {
27
- goLogin: () => void;
28
- lang?: 'zh' | 'en' | 'id';
22
+ response: any;
29
23
  };
@@ -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, http, lang, api = '/admin/sms/send', config, apiResolve, apiPromiseToEmpty } = props || {};
14
+ const { data, http, lang, api = '/admin/sms/send', response } = props || {};
15
15
  const dataObj = JSON.parse(data || '{}');
16
16
  const { mobile, verifyCodeKey } = dataObj || {};
17
17
  const getKey = async () => {
@@ -58,58 +58,37 @@ const CreateMessageVerifyModal = ({ props }) => {
58
58
  return;
59
59
  }
60
60
  message.success(t('sendSuccess', lang));
61
- // 重置倒计时、验证码
62
61
  setCountdown(60);
63
- setOtp('');
64
62
  };
65
63
  return (_jsxs(Modal, { width: 420, visible: visible, onClose: () => {
66
64
  setVisible(false);
67
- apiPromiseToEmpty();
68
65
  props.onClose?.();
69
66
  }, 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
67
  setOtp(val);
71
68
  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
- 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('');
69
+ const { data: { status: { code, detail } = {}, config } } = response || {};
70
+ http({
71
+ ...config,
72
+ headers: {
73
+ ...http.defaults.headers.common,
74
+ 'sms-code': val,
75
+ 'sms-code-key': verifyCodeKey,
76
+ 'Content-Type': config.headers['Content-Type'],
102
77
  }
78
+ });
79
+ console.log(response, code, 'config');
80
+ if (code !== 0) {
81
+ message.error(detail || t('verifyFailed', lang));
82
+ return;
103
83
  }
104
- catch (error) {
105
- console.warn('catch', error);
106
- message.error('验证失败');
107
- setOtp('');
84
+ else {
85
+ message.success(t('verifySuccess', lang));
86
+ setVisible(false);
108
87
  }
109
88
  }
110
89
  } }), _jsx(Button, { disabled: countdown > 0 || !captchCode, onClick: handleResend, style: { padding: '8px' }, children: countdown > 0 ? t('countDownSecound', lang, { countdown }) : t('reSend', lang) })] }), countdown > 0 ? null :
111
90
  _jsxs("div", { style: { marginTop: 12, display: 'flex', alignItems: 'center' }, children: [_jsx(Input, { placeholder: t('pleaseEnterPicVerifyCode', lang), onChange: (e) => {
112
91
  setCaptchCode(e);
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) })] }));
92
+ }, 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) })] }));
114
93
  };
115
94
  export default CreateMessageVerifyModal;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "message-verify",
3
- "version": "1.0.1-beta.38",
3
+ "version": "1.0.1-beta.4",
4
4
  "type": "module",
5
5
  "main": "dist/index.js",
6
6
  "dependencies": {
@@ -29,7 +29,6 @@
29
29
  "build": "tsc -b",
30
30
  "analyze": "vite build",
31
31
  "lint": "eslint .",
32
- "preview": "vite preview",
33
- "release:beta": "pnpm version prerelease --preid=beta && pnpm run build && pnpm publish"
32
+ "preview": "vite preview"
34
33
  }
35
34
  }
package/src/index.tsx CHANGED
@@ -1,30 +1,28 @@
1
1
  import ReactDOM from 'react-dom/client'
2
2
  import VerifyModal from './verify-modal.js'
3
3
  import Fingerprint2 from 'fingerprintjs2';
4
- import ReLoginModal from './relogin-modal.js';
5
- import { ModalConfig, LoginModalConfig } from './utils/type.js';
6
-
7
- let fingerprintPromise: Promise<string> | null = null; // 用 Promise 本身作为缓存
4
+ import { ModalConfig } from './utils/type.js';
8
5
 
6
+ let cachedFingerprint: string | null = null;
9
7
  export const initFingerprint = async (): Promise<string> => {
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
- });
25
- });
8
+ if (cachedFingerprint) {
9
+ // 已有缓存,直接返回 Promise
10
+ return Promise.resolve(cachedFingerprint);
26
11
  }
27
- return fingerprintPromise;
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);
24
+ });
25
+ });
28
26
  };
29
27
 
30
28
  let modalRoot: ReactDOM.Root | null = null
@@ -48,22 +46,6 @@ export const createMessageVerifyModal = (modalProps: ModalConfig) => {
48
46
  )
49
47
  }
50
48
 
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
-
67
49
  const destroyModal = () => {
68
50
  if (modalRoot) {
69
51
  modalRoot.unmount()
package/src/locales/en.ts CHANGED
@@ -6,9 +6,5 @@ export default {
6
6
  sendSuccess: 'Successfully sent',
7
7
  sendFailed: 'Send failed',
8
8
  reSend: 'Resend',
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'
9
+ countDownSecound: '{countdown} seconds'
14
10
  };
package/src/locales/id.ts CHANGED
@@ -6,9 +6,5 @@ export default {
6
6
  sendSuccess: 'Berhasil dikirim',
7
7
  sendFailed: 'Gagal mengirim',
8
8
  reSend: 'Kirim Ulang',
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'
9
+ countDownSecound: '{countdown} detik'
14
10
  };
package/src/locales/zh.ts CHANGED
@@ -6,9 +6,5 @@ export default {
6
6
  sendSuccess: '发送成功',
7
7
  sendFailed: '发送失败',
8
8
  reSend: '重新发送',
9
- countDownSecound: '{countdown}秒',
10
- accountAlert: '账号安全提醒',
11
- alertContent: '检测到您的登录环境或网络信息有变动,为保障账户安全,请重新登录验证身份',
12
- ok: '好的',
13
- chidoriOpenPro: 'chidori已为您开启安全防护'
9
+ countDownSecound: '{countdown}秒'
14
10
  };
package/src/main.tsx CHANGED
@@ -1,12 +1,11 @@
1
1
  import { createRoot } from 'react-dom/client';
2
- import { createMessageVerifyModal, initFingerprint, createReLoginModal } from './index.js'; // 或 './index'
2
+ import { createMessageVerifyModal, initFingerprint } 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
- const fp2 = await initFingerprint();
9
- console.log(fp, fp2);
8
+ console.log(fp);
10
9
 
11
10
  const config = {
12
11
  "transitional": {
@@ -14,6 +13,12 @@ const config = {
14
13
  "forcedJSONParsing": true,
15
14
  "clarifyTimeoutError": false
16
15
  },
16
+ "transformRequest": [
17
+ null
18
+ ],
19
+ "transformResponse": [
20
+ null
21
+ ],
17
22
  "timeout": 0,
18
23
  "xsrfCookieName": "XSRF-TOKEN",
19
24
  "xsrfHeaderName": "X-XSRF-TOKEN",
@@ -22,7 +27,9 @@ const config = {
22
27
  "headers": {
23
28
  "Accept": "application/json, text/plain, */*",
24
29
  "X-Device-Fingerprint": "185fcce88c629725321adf29daa5e444",
25
- "Content-Type": "application/json"
30
+ "Content-Type": "application/json",
31
+ "sms-code": "121212",
32
+ "sms-code-key": "212190c7-2f5e-4cc1-82ec-a242c2ab5425"
26
33
  },
27
34
  "url": "/classification/admin/level/edit",
28
35
  "method": "post",
@@ -43,23 +50,12 @@ createRoot(document.getElementById('root')!).render(
43
50
  <button onClick={() => createMessageVerifyModal({
44
51
  data,
45
52
  config,
53
+ response: {
54
+ config
55
+ },
46
56
  lang: 'en',
47
57
  http: axios,
48
- apiReject: () => {
49
- },
50
- apiResolve: () => {
51
- },
52
- apiPromiseToEmpty: () => {
53
- }
54
58
  })}>
55
59
  Show verify Modal
56
60
  </button>
57
- <button onClick={() => createReLoginModal({
58
- goLogin: () => {
59
- console.log('goLogin');
60
- },
61
- lang: 'zh',
62
- })}>
63
- Show login Modal
64
- </button>
65
61
  </>);
@@ -1,22 +1,20 @@
1
1
  import { useState } from 'react'
2
2
  import { Modal, Button } from './compoments/index.js'
3
- import { LoginModalConfig } from './utils/type.js';
4
- import t from './utils/i18n.js'
3
+ import { ModalConfig } from './utils/type.js';
5
4
 
6
- const ReLoginModal = ({ props }: { props: LoginModalConfig }) => {
7
- const { goLogin, lang } = props || {};
5
+ const ReLoginModal = ({ props }: { props: ModalConfig }) => {
6
+ console.log('props', props);
8
7
  const [visible, setVisible] = useState(true);
9
8
  const onClose = () => {
10
9
  setVisible(false);
11
- goLogin();
12
10
  };
13
11
  return (
14
12
  <Modal visible={visible} onClose={onClose} width={420}>
15
13
  <div style={{ fontWeight: 500, fontSize: 20, marginBottom: 24 }}>
16
- {t('accountAlert', lang)}
14
+ 账号安全提醒
17
15
  </div>
18
16
  <div style={{ color: '#222', fontSize: 16, marginBottom: 40, lineHeight: '24px' }}>
19
- {t('alertContent', lang)}
17
+ 检测到您的登录环境或网络信息有变动,为保障账户安全,请重新登录验证身份
20
18
  </div>
21
19
  <div style={{ display: 'flex', justifyContent: 'center' }}>
22
20
  <Button
@@ -24,15 +22,16 @@ const ReLoginModal = ({ props }: { props: LoginModalConfig }) => {
24
22
  background: '#1677ff',
25
23
  color: '#fff',
26
24
  border: 'none',
27
- width: 80,
28
- height: 36,
29
- fontSize: 14,
25
+ width: 160,
26
+ height: 44,
27
+ fontSize: 18,
28
+ fontWeight: 500,
30
29
  borderRadius: 8,
31
30
  boxShadow: '0 2px 8px rgba(22,119,255,0.08)',
32
31
  }}
33
32
  onClick={onClose}
34
33
  >
35
- {t('ok', lang)}
34
+ 好的
36
35
  </Button>
37
36
  </div>
38
37
  </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?: 'zh' | 'en' | 'id';
11
+ lang: 'zh' | 'en' | 'id';
12
12
  http: {
13
13
  (params: object): Promise<unknown>;
14
14
  defaults: {
@@ -20,12 +20,5 @@ export type ModalConfig = {
20
20
  }
21
21
  };
22
22
  api?: string;
23
- apiReject: any;
24
- apiResolve: any;
25
- apiPromiseToEmpty: () => void;
26
- }
27
-
28
- export type LoginModalConfig = {
29
- goLogin: () => void;
30
- lang?: 'zh' | 'en' | 'id';
23
+ response: any;
31
24
  }
@@ -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, http, lang, api = '/admin/sms/send', config, apiResolve, apiPromiseToEmpty } = props || {};
15
+ const { data, http, lang, api='/admin/sms/send', response } = props || {};
16
16
  const dataObj = JSON.parse(data || '{}');
17
17
  const { mobile, verifyCodeKey } = dataObj || {};
18
18
 
@@ -25,11 +25,10 @@ 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
- const msg =
30
- typeof err === 'object' && err !== null && 'message' in err
31
- ? (err as { message: string }).message
32
- : String(err);
28
+ } catch (err) {const msg =
29
+ typeof err === 'object' && err !== null && 'message' in err
30
+ ? (err as {message: string}).message
31
+ : String(err);
33
32
  message.error(msg as React.ReactNode);
34
33
  }
35
34
  }
@@ -61,9 +60,7 @@ const CreateMessageVerifyModal = ({ props }: { props: ModalConfig }) => {
61
60
  return;
62
61
  }
63
62
  message.success(t('sendSuccess', lang));
64
- // 重置倒计时、验证码
65
63
  setCountdown(60);
66
- setOtp('');
67
64
  }
68
65
 
69
66
  return (
@@ -72,7 +69,6 @@ const CreateMessageVerifyModal = ({ props }: { props: ModalConfig }) => {
72
69
  visible={visible}
73
70
  onClose={() => {
74
71
  setVisible(false);
75
- apiPromiseToEmpty();
76
72
  props.onClose?.();
77
73
  }}
78
74
  >
@@ -85,40 +81,23 @@ const CreateMessageVerifyModal = ({ props }: { props: ModalConfig }) => {
85
81
  onChange={async (val) => {
86
82
  setOtp(val);
87
83
  if (val.length === 6) {
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
- resolve(res);
106
- }).catch(err => {
107
- reject(err);
108
- })
109
- })
110
- ]) as any;
111
- if (res?.data?.status?.code === 0) {
112
- apiResolve(res);
113
- setVisible(false);
114
- } else {
115
- message.error('验证失败');
116
- setOtp('');
84
+ const {data: {status: {code, detail} = {}, config}} = response || {};
85
+ http({
86
+ ...config,
87
+ headers: {
88
+ ...http.defaults.headers.common,
89
+ 'sms-code': val,
90
+ 'sms-code-key': verifyCodeKey,
91
+ 'Content-Type': config.headers['Content-Type'],
117
92
  }
118
- } catch (error) {
119
- console.warn('catch', error);
120
- message.error('验证失败');
121
- setOtp('');
93
+ }) as any;
94
+ console.log(response, code, 'config');
95
+ if(code !== 0) {
96
+ message.error(detail || t('verifyFailed', lang));
97
+ return;
98
+ } else {
99
+ message.success(t('verifySuccess', lang));
100
+ setVisible(false);
122
101
  }
123
102
  }
124
103
  }} />
@@ -143,7 +122,6 @@ const CreateMessageVerifyModal = ({ props }: { props: ModalConfig }) => {
143
122
  {captchaImage && <img src={captchaImage} alt={t('verifyCode', lang)} style={{ width: 100, height: 30, marginLeft: 8 }} onClick={getKey} />}
144
123
  </div>}
145
124
  {(countdown > 0 || captchCode) ? null : <div style={{ fontSize: 14, color: 'red' }}>{t('pleaseEnterAndSend', lang)}</div>}
146
- <div style={{ fontSize: 14, color: '#666', marginTop: 12 }}>{t('chidoriOpenPro', lang)}</div>
147
125
  </Modal>
148
126
  );
149
127
  };