message-verify 1.0.0-beta.6 → 1.0.0-beta.8

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.js CHANGED
@@ -2,7 +2,13 @@ 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
+ let cachedFingerprint = null;
5
6
  export const initFingerprint = async () => {
7
+ if (cachedFingerprint) {
8
+ // 已有缓存,直接返回 Promise
9
+ return Promise.resolve(cachedFingerprint);
10
+ }
11
+ // 首次异步获取并缓存
6
12
  return new Promise((resolve) => {
7
13
  Fingerprint2.get(function (components) {
8
14
  const includeKeys = ['userAgent', 'deviceMemory', 'cpuClass', 'hardwareConcurrency', 'platform'];
@@ -11,6 +17,7 @@ export const initFingerprint = async () => {
11
17
  .map(component => component.value)
12
18
  .join('###');
13
19
  const fingerprint = Fingerprint2.x64hash128(values, 31);
20
+ cachedFingerprint = fingerprint;
14
21
  resolve(fingerprint);
15
22
  });
16
23
  });
@@ -4,6 +4,7 @@ declare const _default: {
4
4
  verifyCode: string;
5
5
  pleaseEnterAndSend: string;
6
6
  sendSuccess: string;
7
+ sendFailed: string;
7
8
  reSend: string;
8
9
  countDownSecound: string;
9
10
  };
@@ -4,6 +4,7 @@ export default {
4
4
  verifyCode: 'Verification Code',
5
5
  pleaseEnterAndSend: 'Please enter the image verification code first, then resend the code',
6
6
  sendSuccess: 'Successfully sent',
7
+ sendFailed: 'Send failed',
7
8
  reSend: 'Resend',
8
9
  countDownSecound: '{countdown} seconds'
9
10
  };
@@ -4,6 +4,7 @@ declare const _default: {
4
4
  verifyCode: string;
5
5
  pleaseEnterAndSend: string;
6
6
  sendSuccess: string;
7
+ sendFailed: string;
7
8
  reSend: string;
8
9
  countDownSecound: string;
9
10
  };
@@ -4,6 +4,7 @@ export default {
4
4
  verifyCode: 'Kode Verifikasi',
5
5
  pleaseEnterAndSend: 'Harap masukkan kode verifikasi gambar terlebih dahulu, lalu kirim ulang kode',
6
6
  sendSuccess: 'Berhasil dikirim',
7
+ sendFailed: 'Gagal mengirim',
7
8
  reSend: 'Kirim Ulang',
8
9
  countDownSecound: '{countdown} detik'
9
10
  };
@@ -4,6 +4,7 @@ declare const _default: {
4
4
  verifyCode: string;
5
5
  pleaseEnterAndSend: string;
6
6
  sendSuccess: string;
7
+ sendFailed: string;
7
8
  reSend: string;
8
9
  countDownSecound: string;
9
10
  };
@@ -4,6 +4,7 @@ export default {
4
4
  verifyCode: '验证码',
5
5
  pleaseEnterAndSend: '请输入图形验证码后,重新发送验证码',
6
6
  sendSuccess: '发送成功',
7
+ sendFailed: '发送失败',
7
8
  reSend: '重新发送',
8
9
  countDownSecound: '{countdown}秒'
9
10
  };
@@ -6,7 +6,7 @@ import t from './utils/i18n.js';
6
6
  import { axios } from '@yqg/resource';
7
7
  const CreateMessageVerifyModal = ({ props }) => {
8
8
  const [visible, setVisible] = useState(true);
9
- const [countdown, setCountdown] = useState(60);
9
+ const [countdown, setCountdown] = useState(2);
10
10
  const [otp, setOtp] = useState('');
11
11
  const [captchaImage, setCaptchaImage] = useState('');
12
12
  const [captchCode, setCaptchCode] = useState('');
@@ -47,13 +47,18 @@ const CreateMessageVerifyModal = ({ props }) => {
47
47
  };
48
48
  }, [visible, countdown]);
49
49
  const handleResend = async () => {
50
- setCountdown(60);
51
50
  const formData = new FormData();
52
51
  formData.append('captchaKey', captchaKey);
53
52
  formData.append('captcha', captchCode);
54
53
  // 重新发送验证码
55
- await axios.post(api, formData);
54
+ const res = await axios.post(api, formData);
55
+ const { code, detail } = res.data?.status || {};
56
+ if (code !== 0) {
57
+ message.error(detail || t('sendFailed', lang));
58
+ return;
59
+ }
56
60
  message.success(t('sendSuccess', lang));
61
+ setCountdown(60);
57
62
  };
58
63
  return (_jsxs(Modal, { width: 420, visible: visible, onClose: () => {
59
64
  setVisible(false);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "message-verify",
3
- "version": "1.0.0-beta.6",
3
+ "version": "1.0.0-beta.8",
4
4
  "type": "module",
5
5
  "main": "dist/index.js",
6
6
  "dependencies": {
package/src/index.tsx CHANGED
@@ -3,7 +3,13 @@ import VerifyModal from './verify-modal.js'
3
3
  import Fingerprint2 from 'fingerprintjs2';
4
4
  import { ModalConfig } from './utils/type.js';
5
5
 
6
+ let cachedFingerprint: string | null = null;
6
7
  export const initFingerprint = async (): Promise<string> => {
8
+ if (cachedFingerprint) {
9
+ // 已有缓存,直接返回 Promise
10
+ return Promise.resolve(cachedFingerprint);
11
+ }
12
+ // 首次异步获取并缓存
7
13
  return new Promise((resolve) => {
8
14
  Fingerprint2.get(function (components) {
9
15
  const includeKeys = ['userAgent', 'deviceMemory', 'cpuClass', 'hardwareConcurrency', 'platform'];
@@ -12,6 +18,7 @@ export const initFingerprint = async (): Promise<string> => {
12
18
  .map(component => component.value)
13
19
  .join('###');
14
20
  const fingerprint = Fingerprint2.x64hash128(values, 31);
21
+ cachedFingerprint = fingerprint;
15
22
  resolve(fingerprint);
16
23
  });
17
24
  });
package/src/locales/en.ts CHANGED
@@ -4,6 +4,7 @@ export default {
4
4
  verifyCode: 'Verification Code',
5
5
  pleaseEnterAndSend: 'Please enter the image verification code first, then resend the code',
6
6
  sendSuccess: 'Successfully sent',
7
+ sendFailed: 'Send failed',
7
8
  reSend: 'Resend',
8
9
  countDownSecound: '{countdown} seconds'
9
10
  };
package/src/locales/id.ts CHANGED
@@ -4,6 +4,7 @@ export default {
4
4
  verifyCode: 'Kode Verifikasi',
5
5
  pleaseEnterAndSend: 'Harap masukkan kode verifikasi gambar terlebih dahulu, lalu kirim ulang kode',
6
6
  sendSuccess: 'Berhasil dikirim',
7
+ sendFailed: 'Gagal mengirim',
7
8
  reSend: 'Kirim Ulang',
8
9
  countDownSecound: '{countdown} detik'
9
10
  };
package/src/locales/zh.ts CHANGED
@@ -4,6 +4,7 @@ export default {
4
4
  verifyCode: '验证码',
5
5
  pleaseEnterAndSend: '请输入图形验证码后,重新发送验证码',
6
6
  sendSuccess: '发送成功',
7
+ sendFailed: '发送失败',
7
8
  reSend: '重新发送',
8
9
  countDownSecound: '{countdown}秒'
9
10
  };
@@ -3,11 +3,11 @@ import { Modal, Input, Button, message } from './compoments/index.js'
3
3
  import Api from './resource.js'
4
4
  import t from './utils/i18n.js'
5
5
  import { ModalConfig } from './utils/type.js';
6
- import { axios } from '@yqg/resource';
6
+ import { axios, customPost } from '@yqg/resource';
7
7
 
8
8
  const CreateMessageVerifyModal = ({ props }: { props: ModalConfig }) => {
9
9
  const [visible, setVisible] = useState(true);
10
- const [countdown, setCountdown] = useState(60);
10
+ const [countdown, setCountdown] = useState(2);
11
11
  const [otp, setOtp] = useState('');
12
12
  const [captchaImage, setCaptchaImage] = useState<string>('');
13
13
  const [captchCode, setCaptchCode] = useState<string>('');
@@ -49,13 +49,18 @@ const CreateMessageVerifyModal = ({ props }: { props: ModalConfig }) => {
49
49
  }, [visible, countdown]);
50
50
 
51
51
  const handleResend = async () => {
52
- setCountdown(60);
53
52
  const formData = new FormData();
54
53
  formData.append('captchaKey', captchaKey);
55
54
  formData.append('captcha', captchCode);
56
55
  // 重新发送验证码
57
- await axios.post(api, formData);
56
+ const res = await axios.post(api, formData);
57
+ const { code, detail } = res.data?.status || {};
58
+ if (code !== 0) {
59
+ message.error(detail || t('sendFailed', lang));
60
+ return;
61
+ }
58
62
  message.success(t('sendSuccess', lang));
63
+ setCountdown(60);
59
64
  }
60
65
 
61
66
  return (