message-verify 1.0.0-beta.5 → 1.0.0-beta.7

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
  });
@@ -18,4 +18,5 @@ export type ModalConfig = {
18
18
  };
19
19
  };
20
20
  };
21
+ api?: string;
21
22
  };
@@ -3,6 +3,7 @@ import { useEffect, useState } from 'react';
3
3
  import { Modal, Input, Button, message } from './compoments/index.js';
4
4
  import Api from './resource.js';
5
5
  import t from './utils/i18n.js';
6
+ import { axios } from '@yqg/resource';
6
7
  const CreateMessageVerifyModal = ({ props }) => {
7
8
  const [visible, setVisible] = useState(true);
8
9
  const [countdown, setCountdown] = useState(60);
@@ -10,7 +11,7 @@ const CreateMessageVerifyModal = ({ props }) => {
10
11
  const [captchaImage, setCaptchaImage] = useState('');
11
12
  const [captchCode, setCaptchCode] = useState('');
12
13
  const [captchaKey, setCaptchaKey] = useState('');
13
- const { data, config, http, lang } = props || {};
14
+ const { data, config, http, lang, api = '/admin/sms/send' } = props || {};
14
15
  const dataObj = JSON.parse(data || '{}');
15
16
  const { mobile, verifyCodeKey } = dataObj || {};
16
17
  const getKey = async () => {
@@ -51,7 +52,7 @@ const CreateMessageVerifyModal = ({ props }) => {
51
52
  formData.append('captchaKey', captchaKey);
52
53
  formData.append('captcha', captchCode);
53
54
  // 重新发送验证码
54
- await Api.reSendCode(formData);
55
+ await axios.post(api, formData);
55
56
  message.success(t('sendSuccess', lang));
56
57
  };
57
58
  return (_jsxs(Modal, { width: 420, visible: visible, onClose: () => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "message-verify",
3
- "version": "1.0.0-beta.5",
3
+ "version": "1.0.0-beta.7",
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/utils/type.ts CHANGED
@@ -19,4 +19,5 @@ export type ModalConfig = {
19
19
  }
20
20
  }
21
21
  };
22
+ api?: string;
22
23
  }
@@ -3,6 +3,7 @@ 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
7
 
7
8
  const CreateMessageVerifyModal = ({ props }: { props: ModalConfig }) => {
8
9
  const [visible, setVisible] = useState(true);
@@ -11,7 +12,7 @@ const CreateMessageVerifyModal = ({ props }: { props: ModalConfig }) => {
11
12
  const [captchaImage, setCaptchaImage] = useState<string>('');
12
13
  const [captchCode, setCaptchCode] = useState<string>('');
13
14
  const [captchaKey, setCaptchaKey] = useState<string>('');
14
- const { data, config, http, lang } = props || {};
15
+ const { data, config, http, lang, api='/admin/sms/send' } = props || {};
15
16
  const dataObj = JSON.parse(data || '{}');
16
17
  const { mobile, verifyCodeKey } = dataObj || {};
17
18
 
@@ -53,7 +54,7 @@ const CreateMessageVerifyModal = ({ props }: { props: ModalConfig }) => {
53
54
  formData.append('captchaKey', captchaKey);
54
55
  formData.append('captcha', captchCode);
55
56
  // 重新发送验证码
56
- await Api.reSendCode(formData);
57
+ await axios.post(api, formData);
57
58
  message.success(t('sendSuccess', lang));
58
59
  }
59
60