message-verify 1.0.1-beta.32 → 1.0.1-beta.33

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
@@ -3,29 +3,22 @@ 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 = null;
6
+ let fingerprintPromise = null; // 用 Promise 本身作为缓存
7
7
  export const initFingerprint = async () => {
8
- // console.log('cachedFingerprint', cachedFingerprint);
9
- if (cachedFingerprint) {
10
- // 已有缓存,直接返回 Promise
11
- return Promise.resolve(cachedFingerprint);
12
- }
13
- // 首次异步获取并缓存
14
- return new Promise((resolve) => {
15
- Fingerprint2.get(function (components) {
16
- console.log('components', components);
17
- const includeKeys = ['userAgent', 'deviceMemory', 'cpuClass', 'hardwareConcurrency', 'platform'];
18
- const values = components
19
- .filter(component => includeKeys.includes(component.key))
20
- .map(component => component.value)
21
- .join('###');
22
- console.log('values', values);
23
- const fingerprint = Fingerprint2.x64hash128(values, 31);
24
- console.log('fingerprint', fingerprint);
25
- cachedFingerprint = fingerprint;
26
- resolve(fingerprint);
8
+ if (!fingerprintPromise) {
9
+ fingerprintPromise = new Promise((resolve) => {
10
+ Fingerprint2.get(components => {
11
+ const includeKeys = ['userAgent', 'deviceMemory', 'cpuClass', 'hardwareConcurrency', 'platform'];
12
+ const values = components
13
+ .filter(c => includeKeys.includes(c.key))
14
+ .map(c => c.value)
15
+ .join('###');
16
+ const fingerprint = Fingerprint2.x64hash128(values, 31);
17
+ resolve(fingerprint);
18
+ });
27
19
  });
28
- });
20
+ }
21
+ return fingerprintPromise;
29
22
  };
30
23
  let modalRoot = null;
31
24
  export const createMessageVerifyModal = (modalProps) => {
package/dist/main.js CHANGED
@@ -4,7 +4,8 @@ import { createMessageVerifyModal, initFingerprint, createReLoginModal } from '.
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,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 } = props || {};
14
+ const { data, http, lang, api = '/admin/sms/send', config, apiResolve, apiReject } = props || {};
15
15
  const dataObj = JSON.parse(data || '{}');
16
16
  const { mobile, verifyCodeKey } = dataObj || {};
17
17
  const getKey = async () => {
@@ -64,6 +64,7 @@ const CreateMessageVerifyModal = ({ props }) => {
64
64
  };
65
65
  return (_jsxs(Modal, { width: 420, visible: visible, onClose: () => {
66
66
  setVisible(false);
67
+ apiReject();
67
68
  props.onClose?.();
68
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) => {
69
70
  setOtp(val);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "message-verify",
3
- "version": "1.0.1-beta.32",
3
+ "version": "1.0.1-beta.33",
4
4
  "type": "module",
5
5
  "main": "dist/index.js",
6
6
  "dependencies": {
package/src/index.tsx CHANGED
@@ -4,29 +4,23 @@ import Fingerprint2 from 'fingerprintjs2';
4
4
  import ReLoginModal from './relogin-modal.js';
5
5
  import { ModalConfig, LoginModalConfig } from './utils/type.js';
6
6
 
7
- let cachedFingerprint: string | null = null;
7
+ let fingerprintPromise: Promise<string> | null = null; // 用 Promise 本身作为缓存
8
+
8
9
  export const initFingerprint = async (): Promise<string> => {
9
- // console.log('cachedFingerprint', cachedFingerprint);
10
- if (cachedFingerprint) {
11
- // 已有缓存,直接返回 Promise
12
- return Promise.resolve(cachedFingerprint);
13
- }
14
- // 首次异步获取并缓存
15
- return new Promise((resolve) => {
16
- Fingerprint2.get(function (components) {
17
- console.log('components', components);
18
- const includeKeys = ['userAgent', 'deviceMemory', 'cpuClass', 'hardwareConcurrency', 'platform'];
19
- const values = components
20
- .filter(component => includeKeys.includes(component.key))
21
- .map(component => component.value)
22
- .join('###');
23
- console.log('values', values);
24
- const fingerprint = Fingerprint2.x64hash128(values, 31);
25
- console.log('fingerprint', fingerprint);
26
- cachedFingerprint = fingerprint;
27
- resolve(fingerprint);
10
+ if (!fingerprintPromise) {
11
+ fingerprintPromise = new Promise((resolve) => {
12
+ Fingerprint2.get(components => {
13
+ const includeKeys = ['userAgent', 'deviceMemory', 'cpuClass', 'hardwareConcurrency', 'platform'];
14
+ const values = components
15
+ .filter(c => includeKeys.includes(c.key))
16
+ .map(c => c.value)
17
+ .join('###');
18
+ const fingerprint = Fingerprint2.x64hash128(values, 31);
19
+ resolve(fingerprint);
20
+ });
28
21
  });
29
- });
22
+ }
23
+ return fingerprintPromise;
30
24
  };
31
25
 
32
26
  let modalRoot: ReactDOM.Root | null = null
package/src/main.tsx CHANGED
@@ -5,7 +5,8 @@ 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
 
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": {
@@ -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 } = props || {};
15
+ const { data, http, lang, api = '/admin/sms/send', config, apiResolve, apiReject } = props || {};
16
16
  const dataObj = JSON.parse(data || '{}');
17
17
  const { mobile, verifyCodeKey } = dataObj || {};
18
18
 
@@ -72,6 +72,7 @@ const CreateMessageVerifyModal = ({ props }: { props: ModalConfig }) => {
72
72
  visible={visible}
73
73
  onClose={() => {
74
74
  setVisible(false);
75
+ apiReject();
75
76
  props.onClose?.();
76
77
  }}
77
78
  >