message-verify 1.0.0 → 1.0.1-beta.1

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,8 +1,4 @@
1
1
  {
2
- "project.name": "yqg-message-verify",
3
2
  "phabricator.uri": "https://code.yangqianguan.com/",
4
- "phutil_libraries": {
5
- "libcustom": "./arcanist"
6
- },
7
3
  "lint.engine": "YqgWebDiffLintEngine"
8
4
  }
package/dist/index.d.ts CHANGED
@@ -1,4 +1,3 @@
1
- import { VerifyModalConfig, LoginModalConfig } from './utils/type.js';
1
+ import { ModalConfig } from './utils/type.js';
2
2
  export declare const initFingerprint: () => Promise<string>;
3
- export declare const createReLoginModal: (modalProps: LoginModalConfig) => void;
4
- export declare const VerifyHandler: ({ data, config, http, verifyPromise, sendApi }: VerifyModalConfig) => Promise<any>;
3
+ export declare const createMessageVerifyModal: (modalProps: ModalConfig) => void;
package/dist/index.js CHANGED
@@ -1,71 +1,46 @@
1
1
  import { jsx as _jsx } from "react/jsx-runtime";
2
2
  import ReactDOM from 'react-dom/client';
3
- import VerifyModal from './modal/verify-modal.js';
3
+ import VerifyModal from './verify-modal.js';
4
4
  import Fingerprint2 from 'fingerprintjs2';
5
- import ReLoginModal from './modal/relogin-modal.js';
6
- let fingerprintPromise = null; // 用 Promise 本身作为缓存
7
- let modalRoot = null;
5
+ let cachedFingerprint = null;
8
6
  export const initFingerprint = async () => {
9
- if (!fingerprintPromise) {
10
- fingerprintPromise = new Promise((resolve) => {
11
- Fingerprint2.get(components => {
12
- const includeKeys = ['userAgent', 'cpuClass', 'hardwareConcurrency', 'platform'];
13
- const values = components
14
- .filter(c => includeKeys.includes(c.key))
15
- .map(c => c.value)
16
- .join('###');
17
- const fingerprint = Fingerprint2.x64hash128(values, 31);
18
- resolve(fingerprint);
19
- });
20
- });
21
- }
22
- return fingerprintPromise;
23
- };
24
- const destroyModal = (modalId) => {
25
- if (modalRoot) {
26
- modalRoot.unmount();
27
- document.getElementById(modalId)?.remove();
28
- modalRoot = null;
7
+ if (cachedFingerprint) {
8
+ // 已有缓存,直接返回 Promise
9
+ return Promise.resolve(cachedFingerprint);
29
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);
23
+ });
24
+ });
30
25
  };
31
- const creatModal = (modalProps, modalId, ModalDom) => {
32
- destroyModal(modalId);
26
+ let modalRoot = null;
27
+ export const createMessageVerifyModal = (modalProps) => {
33
28
  const container = document.createElement('div');
34
- container.id = modalId;
29
+ container.id = 'antd-modal-container';
35
30
  document.body.appendChild(container);
36
31
  modalRoot = ReactDOM.createRoot(container);
37
- modalRoot.render(_jsx(ModalDom, { props: {
32
+ modalRoot.render(_jsx(VerifyModal, { props: {
38
33
  ...modalProps,
39
34
  onClose: () => {
40
- destroyModal(modalId);
35
+ modalProps.onClose?.();
36
+ destroyModal();
41
37
  }
42
38
  } }));
43
39
  };
44
- const createMessageVerifyModal = (modalProps) => {
45
- const verifyModalId = 'verify-modal-container';
46
- creatModal(modalProps, verifyModalId, VerifyModal);
47
- };
48
- // 新增 relogin 弹窗创建方法
49
- export const createReLoginModal = (modalProps) => {
50
- const reLoginModalId = 'relogin-modal-container';
51
- creatModal(modalProps, reLoginModalId, ReLoginModal);
52
- };
53
- export const VerifyHandler = ({ data, config, http, verifyPromise, sendApi }) => {
54
- const toEmpty = () => {
55
- verifyPromise.current = null;
56
- };
57
- if (!verifyPromise.current) {
58
- verifyPromise.current = new Promise((resolve, reject) => {
59
- createMessageVerifyModal({
60
- data,
61
- config,
62
- http,
63
- apiResolve: resolve,
64
- apiReject: reject,
65
- apiPromiseToEmpty: toEmpty,
66
- sendApi
67
- });
68
- }).finally(toEmpty);
40
+ const destroyModal = () => {
41
+ if (modalRoot) {
42
+ modalRoot.unmount();
43
+ document.getElementById('antd-modal-container')?.remove();
44
+ modalRoot = null;
69
45
  }
70
- return verifyPromise.current;
71
46
  };
@@ -7,10 +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
- verifyFail: string;
15
10
  };
16
11
  export default _default;
@@ -6,10 +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',
14
- verifyFail: 'Validation failed'
9
+ countDownSecound: '{countdown} seconds'
15
10
  };
@@ -7,10 +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
- verifyFail: string;
15
10
  };
16
11
  export default _default;
@@ -6,10 +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',
14
- verifyFail: 'Autentikasi gagal'
9
+ countDownSecound: '{countdown} detik'
15
10
  };
@@ -7,10 +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
- verifyFail: string;
15
10
  };
16
11
  export default _default;
@@ -6,10 +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已为您开启安全防护',
14
- verifyFail: '验证失败'
9
+ countDownSecound: '{countdown}秒'
15
10
  };
package/dist/main.js CHANGED
@@ -1,47 +1,42 @@
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 { initFingerprint, createReLoginModal, VerifyHandler } 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);
9
- const config = {
10
- "transitional": {
11
- "silentJSONParsing": true,
12
- "forcedJSONParsing": true,
13
- "clarifyTimeoutError": false
14
- },
15
- "timeout": 0,
16
- "xsrfCookieName": "XSRF-TOKEN",
17
- "xsrfHeaderName": "X-XSRF-TOKEN",
18
- "maxContentLength": -1,
19
- "maxBodyLength": -1,
20
- "headers": {
21
- "Accept": "application/json, text/plain, */*",
22
- "X-Device-Fingerprint": "531f14c7176b16ebeb18e2b23d6bd124",
23
- "Content-Type": "application/json"
24
- },
25
- "url": "/classification/admin/level/edit",
26
- "method": "post",
27
- "dataFormat": "JSON",
28
- "showRequestData": true,
29
- "showResponseData": false,
30
- "showGeneralResponseData": true,
31
- "headersList": [],
32
- "requestDataFunc": "\nfunction(formFilterData){\n // 这里写你的处理逻辑\n return {\n ...formFilterData,\n 'classificationLevel': 2 //等级\n }\n}\n",
33
- "responseDataFunc": "",
34
- "responseGeneralDataFunc": "function(req, { data, util, window }) {\n return req\n .then((response) => {\n return Promise.resolve({\n status: {\n code: 0,\n }\n })\n })\n .catch((error) => {\n // 检查是否有响应数据\n if (error.response && error.response.data) {\n const responseData = error.response.data;\n const detail = responseData.body?.status?.detail || responseData.status?.detail;\n if (detail) {\n util.message.error(detail);\n } else {\n util.message.error('编辑失败,请重试');\n }\n } else {\n util.message.error('编辑失败,请重试');\n }\n console.error('Error during deletion:', error);\n });\n}",
35
- "formInstance": {},
36
- "data": "{\"id\":1,\"classificationName\":\"个人基本概况信息\",\"classificationLevel\":2}",
37
- "baseURL": "http://localhost:62888"
38
- };
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 });
42
- }, children: "Show verify Modal" }), _jsx("button", { onClick: () => createReLoginModal({
43
- goLogin: () => {
44
- console.log('goLogin');
7
+ console.log(fp);
8
+ createRoot(document.getElementById('root')).render(_jsx(_Fragment, { children: _jsx("button", { onClick: () => createMessageVerifyModal({
9
+ data,
10
+ config: {
11
+ "transitional": {
12
+ "silentJSONParsing": true,
13
+ "forcedJSONParsing": true,
14
+ "clarifyTimeoutError": false
45
15
  },
46
- lang: 'zh',
47
- }), children: "Show login Modal" })] }));
16
+ "timeout": 0,
17
+ "xsrfCookieName": "XSRF-TOKEN",
18
+ "xsrfHeaderName": "X-XSRF-TOKEN",
19
+ "maxContentLength": -1,
20
+ "maxBodyLength": -1,
21
+ "headers": {
22
+ "Accept": "application/json, text/plain, */*",
23
+ "X-Device-Fingerprint": "185fcce88c629725321adf29daa5e444",
24
+ "Content-Type": "application/json"
25
+ },
26
+ "url": "/classification/admin/level/edit",
27
+ "method": "post",
28
+ "dataFormat": "JSON",
29
+ "showRequestData": true,
30
+ "showResponseData": false,
31
+ "showGeneralResponseData": true,
32
+ "headersList": [],
33
+ "requestDataFunc": "\nfunction(formFilterData){\n // 这里写你的处理逻辑\n return {\n ...formFilterData,\n 'classificationLevel': 2 //等级\n }\n}\n",
34
+ "responseDataFunc": "",
35
+ "responseGeneralDataFunc": "function(req, { data, util, window }) {\n return req\n .then((response) => {\n return Promise.resolve({\n status: {\n code: 0,\n }\n })\n })\n .catch((error) => {\n // 检查是否有响应数据\n if (error.response && error.response.data) {\n const responseData = error.response.data;\n const detail = responseData.body?.status?.detail || responseData.status?.detail;\n if (detail) {\n util.message.error(detail);\n } else {\n util.message.error('编辑失败,请重试');\n }\n } else {\n util.message.error('编辑失败,请重试');\n }\n console.error('Error during deletion:', error);\n });\n}",
36
+ "formInstance": {},
37
+ "data": "{\"id\":1,\"classificationName\":\"个人基本概况信息\",\"classificationLevel\":2}",
38
+ "baseURL": "http://localhost:62888"
39
+ },
40
+ lang: 'en',
41
+ http: axios,
42
+ }), 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;
@@ -1 +1 @@
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"}
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,4 +1,4 @@
1
- export type VerifyModalConfig = {
1
+ export type ModalConfig = {
2
2
  data: string;
3
3
  onClose?: () => void;
4
4
  config: {
@@ -7,7 +7,7 @@ export type VerifyModalConfig = {
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,16 +18,5 @@ export type VerifyModalConfig = {
18
18
  };
19
19
  };
20
20
  };
21
- sendApi?: string;
22
- apiReject?: any;
23
- apiResolve?: any;
24
- apiPromiseToEmpty?: () => void;
25
- verifyPromise: {
26
- current: Promise<any> | null;
27
- };
28
- };
29
- export type LoginModalConfig = {
30
- goLogin: () => void;
31
- onClose?: () => void;
32
- lang?: 'zh' | 'en' | 'id';
21
+ api?: string;
33
22
  };
@@ -1,5 +1,5 @@
1
- import { VerifyModalConfig } from './utils/type.js';
1
+ import { ModalConfig } from './utils/type.js';
2
2
  declare const CreateMessageVerifyModal: ({ props }: {
3
- props: VerifyModalConfig;
3
+ props: ModalConfig;
4
4
  }) => import("react/jsx-runtime.js").JSX.Element;
5
5
  export default CreateMessageVerifyModal;
@@ -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, sendApi = '/admin/sms/send', config, apiResolve, apiPromiseToEmpty } = props || {};
14
+ const { data, config, http, lang, api = '/admin/sms/send' } = props || {};
15
15
  const dataObj = JSON.parse(data || '{}');
16
16
  const { mobile, verifyCodeKey } = dataObj || {};
17
17
  const getKey = async () => {
@@ -51,65 +51,44 @@ const CreateMessageVerifyModal = ({ props }) => {
51
51
  formData.append('captchaKey', captchaKey);
52
52
  formData.append('captcha', captchCode);
53
53
  // 重新发送验证码
54
- const res = await axios.post(sendApi, formData);
54
+ const res = await axios.post(api, formData);
55
55
  const { code, detail } = res.data?.status || {};
56
56
  if (code !== 0) {
57
57
  message.error(detail || t('sendFailed', lang));
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 res = await http({
70
+ ...config,
71
+ headers: {
72
+ ...http.defaults.headers.common,
73
+ 'sms-code': val,
74
+ 'sms-code-key': verifyCodeKey,
75
+ 'Content-Type': config.headers['Content-Type'],
102
76
  }
77
+ });
78
+ console.log(res, 'res');
79
+ const { data: { status: { code, detail } = {} } } = res;
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/eslint.config.js CHANGED
@@ -23,8 +23,7 @@ export default tseslint.config(
23
23
  'warn',
24
24
  { allowConstantExport: true },
25
25
  ],
26
- "@typescript-eslint/no-explicit-any": "off",
27
- 'constructor-super': 'off'
26
+ "@typescript-eslint/no-explicit-any": "off"
28
27
  },
29
28
  },
30
29
  )
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "message-verify",
3
- "version": "1.0.0",
3
+ "version": "1.0.1-beta.1",
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,81 +1,55 @@
1
1
  import ReactDOM from 'react-dom/client'
2
- import VerifyModal from './modal/verify-modal.js'
2
+ import VerifyModal from './verify-modal.js'
3
3
  import Fingerprint2 from 'fingerprintjs2';
4
- import ReLoginModal from './modal/relogin-modal.js';
5
- import { VerifyModalConfig, LoginModalConfig } from './utils/type.js';
4
+ import { ModalConfig } from './utils/type.js';
6
5
 
7
- let fingerprintPromise: Promise<string> | null = null; // 用 Promise 本身作为缓存
8
- let modalRoot: ReactDOM.Root | null = null
6
+ let cachedFingerprint: string | null = null;
9
7
  export const initFingerprint = async (): Promise<string> => {
10
- if (!fingerprintPromise) {
11
- fingerprintPromise = new Promise((resolve) => {
12
- Fingerprint2.get(components => {
13
- const includeKeys = ['userAgent', '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
- });
21
- });
8
+ if (cachedFingerprint) {
9
+ // 已有缓存,直接返回 Promise
10
+ return Promise.resolve(cachedFingerprint);
22
11
  }
23
- 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
+ });
24
26
  };
25
27
 
26
- const destroyModal = (modalId: string) => {
27
- if (modalRoot) {
28
- modalRoot.unmount()
29
- document.getElementById(modalId)?.remove()
30
- modalRoot = null
31
- }
32
- }
33
-
34
- const creatModal = (modalProps: VerifyModalConfig | LoginModalConfig, modalId: string, ModalDom:any) => {
35
- destroyModal(modalId);
36
- const container = document.createElement('div')
37
- container.id = modalId
38
- document.body.appendChild(container)
28
+ let modalRoot: ReactDOM.Root | null = null
39
29
 
40
- modalRoot = ReactDOM.createRoot(container)
41
- modalRoot.render(
42
- <ModalDom
43
- props={{
44
- ...modalProps,
45
- onClose: () => {
46
- destroyModal(modalId);
47
- }
48
- }}
49
- />
50
- )
51
- }
30
+ export const createMessageVerifyModal = (modalProps: ModalConfig) => {
31
+ const container = document.createElement('div')
32
+ container.id = 'antd-modal-container'
33
+ document.body.appendChild(container)
52
34
 
53
- const createMessageVerifyModal = (modalProps: VerifyModalConfig) => {
54
- const verifyModalId = 'verify-modal-container';
55
- creatModal(modalProps, verifyModalId, VerifyModal);
56
- }
57
- // 新增 relogin 弹窗创建方法
58
- export const createReLoginModal = (modalProps: LoginModalConfig) => {
59
- const reLoginModalId = 'relogin-modal-container';
60
- creatModal(modalProps, reLoginModalId, ReLoginModal);
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
+ )
61
47
  }
62
48
 
63
- export const VerifyHandler = ({data, config, http, verifyPromise, sendApi}: VerifyModalConfig): Promise<any> => {
64
- const toEmpty = () => {
65
- verifyPromise.current = null;
66
- };
67
- if (!verifyPromise.current) {
68
- verifyPromise.current = new Promise((resolve, reject) => {
69
- createMessageVerifyModal({
70
- data,
71
- config,
72
- http,
73
- apiResolve: resolve,
74
- apiReject: reject,
75
- apiPromiseToEmpty: toEmpty,
76
- sendApi
77
- } as VerifyModalConfig);
78
- }).finally(toEmpty);
79
- }
80
- return verifyPromise.current;
81
- };
49
+ const destroyModal = () => {
50
+ if (modalRoot) {
51
+ modalRoot.unmount()
52
+ document.getElementById('antd-modal-container')?.remove()
53
+ modalRoot = null
54
+ }
55
+ }
package/src/locales/en.ts CHANGED
@@ -6,10 +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',
14
- verifyFail: 'Validation failed'
9
+ countDownSecound: '{countdown} seconds'
15
10
  };