message-verify 0.0.52-beta.0 → 0.1.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/README.md CHANGED
@@ -9,4 +9,29 @@
9
9
  ### 1. 引入组件
10
10
 
11
11
  ```typescript
12
- import {createMessageVerifyModal} from 'message-verify';
12
+ import {createMessageVerifyModal} from 'message-verify';
13
+ ```
14
+
15
+ ### 2. 参数说明
16
+
17
+ ```typescript
18
+ - data :字符串,包含手机号、验证码 key 等信息(JSON 字符串)。
19
+ - config :对象,必须包含 headers 字段(可为空对象),用于 http 请求配置。
20
+ - lang :组件使用语言,支持 'zh' (中文)、 'en' (英文)、 'id' (印尼语)。
21
+ - http :http 客户端实例(如 axios)。
22
+ - onClose :弹窗关闭回调(可选)。
23
+ ```
24
+
25
+ ### 3. 示例
26
+
27
+ ```typescript
28
+ createMessageVerifyModal({
29
+ data,
30
+ config: { headers: {} }, // 必须包含 headers 字段
31
+ lang: 'zh', // 支持 'zh' | 'en' | 'id'
32
+ http: axios,
33
+ onClose: () => {
34
+ // 可选,弹窗关闭回调
35
+ }
36
+ });
37
+ ```
package/dist/index.d.ts CHANGED
@@ -1,18 +1,3 @@
1
+ import { ModalConfig } from './utils/type.js';
1
2
  export declare const initFingerprint: () => Promise<string>;
2
- export type ModalConfig = {
3
- data: string;
4
- onClose?: () => void;
5
- config: object;
6
- lang: 'zh' | 'en' | 'id';
7
- http: {
8
- (params: object): Promise<unknown>;
9
- defaults: {
10
- headers: {
11
- common: {
12
- [key: string]: unknown;
13
- };
14
- };
15
- };
16
- };
17
- };
18
3
  export declare const createMessageVerifyModal: (modalProps: ModalConfig) => void;
package/dist/index.js CHANGED
@@ -2,7 +2,7 @@ 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
- export const initFingerprint = () => {
5
+ export const initFingerprint = async () => {
6
6
  return new Promise((resolve) => {
7
7
  Fingerprint2.get(function (components) {
8
8
  const includeKeys = ['userAgent', 'deviceMemory', 'cpuClass', 'hardwareConcurrency', 'platform'];
package/dist/main.js CHANGED
@@ -1,16 +1,13 @@
1
1
  import { jsx as _jsx } from "react/jsx-runtime";
2
2
  import { createRoot } from 'react-dom/client';
3
- import { createMessageVerifyModal } from './index.js'; // 或 './index'
3
+ import { createMessageVerifyModal, initFingerprint } from './index.js'; // 或 './index'
4
+ import { axios } from '@yqg/resource';
4
5
  const data = "{\"mobile\":\"188****4035\",\"verifyCodeKey\":\"3f025b33-988e-47c0-950d-6beb776d043f\",\"needValid\":true,\"step\":2,\"message\":\"需要填写验证码\"}";
6
+ const fp = await initFingerprint();
7
+ console.log(fp);
5
8
  createRoot(document.getElementById('root')).render(_jsx("button", { onClick: () => createMessageVerifyModal({
6
9
  data,
7
- config: {},
10
+ config: { headers: {} },
8
11
  lang: 'en',
9
- http: Object.assign(() => Promise.resolve({}), {
10
- defaults: {
11
- headers: {
12
- common: {}
13
- }
14
- }
15
- }),
12
+ http: axios,
16
13
  }), children: "Show Modal" }));
@@ -1 +1 @@
1
- {"root":["../src/index.tsx","../src/main.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"],"version":"5.7.3"}
1
+ {"root":["../src/index.tsx","../src/main.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"}
@@ -0,0 +1,22 @@
1
+ export type ModalConfig = {
2
+ data: string;
3
+ onClose?: () => void;
4
+ config: {
5
+ headers: {
6
+ [key: string]: string | undefined;
7
+ };
8
+ [key: string]: unknown;
9
+ };
10
+ lang: 'zh' | 'en' | 'id';
11
+ http: {
12
+ (params: object): Promise<unknown>;
13
+ defaults: {
14
+ headers: {
15
+ common: {
16
+ [key: string]: unknown;
17
+ };
18
+ };
19
+ };
20
+ };
21
+ api?: string;
22
+ };
@@ -0,0 +1 @@
1
+ export {};
@@ -1,19 +1,4 @@
1
- type ModalConfig = {
2
- data: string;
3
- onClose?: () => void;
4
- config: object;
5
- lang: 'zh' | 'en' | 'id';
6
- http: {
7
- (params: object): Promise<unknown>;
8
- defaults: {
9
- headers: {
10
- common: {
11
- [key: string]: unknown;
12
- };
13
- };
14
- };
15
- };
16
- };
1
+ import { ModalConfig } from './utils/type.js';
17
2
  declare const CreateMessageVerifyModal: ({ props }: {
18
3
  props: ModalConfig;
19
4
  }) => import("react/jsx-runtime.js").JSX.Element;
@@ -3,14 +3,15 @@ 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
- const [countdown, setCountdown] = useState(3);
9
+ const [countdown, setCountdown] = useState(60);
9
10
  const [otp, setOtp] = useState('');
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 () => {
@@ -47,8 +48,11 @@ const CreateMessageVerifyModal = ({ props }) => {
47
48
  }, [visible, countdown]);
48
49
  const handleResend = async () => {
49
50
  setCountdown(60);
50
- const res = await Api.reSendCode({ captchaKey, captcha: captchCode });
51
- console.log('handleResend=>res', res);
51
+ const formData = new FormData();
52
+ formData.append('captchaKey', captchaKey);
53
+ formData.append('captcha', captchCode);
54
+ // 重新发送验证码
55
+ await axios.post(api, formData);
52
56
  message.success(t('sendSuccess', lang));
53
57
  };
54
58
  return (_jsxs(Modal, { width: 420, visible: visible, onClose: () => {
@@ -56,10 +60,17 @@ const CreateMessageVerifyModal = ({ props }) => {
56
60
  props.onClose?.();
57
61
  }, 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: (val) => {
58
62
  setOtp(val);
63
+ console.log('打印Content-Type', config.headers['Content-Type']);
59
64
  if (val.length === 6) {
60
- http.defaults.headers.common['sms-code'] = val;
61
- http.defaults.headers.common['sms-code-key'] = verifyCodeKey;
62
- http(config);
65
+ http({
66
+ ...config,
67
+ headers: {
68
+ ...http.defaults.headers.common,
69
+ 'sms-code': val,
70
+ 'sms-code-key': verifyCodeKey,
71
+ 'Content-Type': config.headers['Content-Type'],
72
+ }
73
+ });
63
74
  setVisible(false);
64
75
  }
65
76
  } }), _jsx(Button, { disabled: countdown > 0 || !captchCode, onClick: handleResend, style: { padding: '8px' }, children: countdown > 0 ? t('countDownSecound', lang, { countdown }) : t('reSend', lang) })] }), countdown > 0 ? null :
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "message-verify",
3
- "version": "0.0.52-beta.0",
3
+ "version": "0.1.1-beta.1",
4
4
  "type": "module",
5
5
  "main": "dist/index.js",
6
6
  "dependencies": {
package/src/index.tsx CHANGED
@@ -1,8 +1,9 @@
1
1
  import ReactDOM from 'react-dom/client'
2
2
  import VerifyModal from './verify-modal.js'
3
3
  import Fingerprint2 from 'fingerprintjs2';
4
+ import { ModalConfig } from './utils/type.js';
4
5
 
5
- export const initFingerprint = (): Promise<string> => {
6
+ export const initFingerprint = async (): Promise<string> => {
6
7
  return new Promise((resolve) => {
7
8
  Fingerprint2.get(function (components) {
8
9
  const includeKeys = ['userAgent', 'deviceMemory', 'cpuClass', 'hardwareConcurrency', 'platform'];
@@ -16,23 +17,6 @@ export const initFingerprint = (): Promise<string> => {
16
17
  });
17
18
  };
18
19
 
19
- export type ModalConfig = {
20
- data: string;
21
- onClose?: () => void
22
- config: object;
23
- lang: 'zh' | 'en' | 'id';
24
- http: {
25
- (params: object): Promise<unknown>;
26
- defaults: {
27
- headers: {
28
- common: {
29
- [key: string]: unknown;
30
- }
31
- }
32
- }
33
- };
34
- }
35
-
36
20
  let modalRoot: ReactDOM.Root | null = null
37
21
 
38
22
  export const createMessageVerifyModal = (modalProps: ModalConfig) => {
package/src/main.tsx CHANGED
@@ -1,23 +1,18 @@
1
1
  import { createRoot } from 'react-dom/client';
2
- import { createMessageVerifyModal } from './index.js'; // 或 './index'
2
+ import { createMessageVerifyModal, initFingerprint } from './index.js'; // 或 './index'
3
+ import { axios } from '@yqg/resource';
3
4
 
4
5
  const data = "{\"mobile\":\"188****4035\",\"verifyCodeKey\":\"3f025b33-988e-47c0-950d-6beb776d043f\",\"needValid\":true,\"step\":2,\"message\":\"需要填写验证码\"}";
5
6
 
7
+ const fp = await initFingerprint();
8
+ console.log(fp);
9
+
6
10
  createRoot(document.getElementById('root')!).render(
7
11
  <button onClick={() => createMessageVerifyModal({
8
12
  data,
9
- config: {},
13
+ config: {headers: {}},
10
14
  lang: 'en',
11
- http: Object.assign(
12
- () => Promise.resolve({}),
13
- {
14
- defaults: {
15
- headers: {
16
- common: {}
17
- }
18
- }
19
- }
20
- ),
15
+ http: axios,
21
16
  })}>
22
17
  Show Modal
23
18
  </button>);
@@ -0,0 +1,23 @@
1
+
2
+ export type ModalConfig = {
3
+ data: string;
4
+ onClose?: () => void
5
+ config: {
6
+ headers: {
7
+ [key: string]: string | undefined;
8
+ };
9
+ [key: string]: unknown;
10
+ };
11
+ lang: 'zh' | 'en' | 'id';
12
+ http: {
13
+ (params: object): Promise<unknown>;
14
+ defaults: {
15
+ headers: {
16
+ common: {
17
+ [key: string]: unknown;
18
+ }
19
+ }
20
+ }
21
+ };
22
+ api?: string;
23
+ }
@@ -2,31 +2,17 @@ import { useEffect, useState } from 'react'
2
2
  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
+ import { ModalConfig } from './utils/type.js';
6
+ import { axios } from '@yqg/resource';
5
7
 
6
- type ModalConfig = {
7
- data: string;
8
- onClose?: () => void;
9
- config: object;
10
- lang: 'zh' | 'en' | 'id';
11
- http: {
12
- (params: object): Promise<unknown>;
13
- defaults: {
14
- headers: {
15
- common: {
16
- [key: string]: unknown;
17
- }
18
- }
19
- }
20
- };
21
- }
22
8
  const CreateMessageVerifyModal = ({ props }: { props: ModalConfig }) => {
23
9
  const [visible, setVisible] = useState(true);
24
- const [countdown, setCountdown] = useState(3);
10
+ const [countdown, setCountdown] = useState(60);
25
11
  const [otp, setOtp] = useState('');
26
12
  const [captchaImage, setCaptchaImage] = useState<string>('');
27
13
  const [captchCode, setCaptchCode] = useState<string>('');
28
14
  const [captchaKey, setCaptchaKey] = useState<string>('');
29
- const { data, config, http, lang } = props || {};
15
+ const { data, config, http, lang, api='/admin/sms/send' } = props || {};
30
16
  const dataObj = JSON.parse(data || '{}');
31
17
  const { mobile, verifyCodeKey } = dataObj || {};
32
18
 
@@ -64,8 +50,11 @@ const CreateMessageVerifyModal = ({ props }: { props: ModalConfig }) => {
64
50
 
65
51
  const handleResend = async () => {
66
52
  setCountdown(60);
67
- const res = await Api.reSendCode({ captchaKey, captcha: captchCode });
68
- console.log('handleResend=>res', res);
53
+ const formData = new FormData();
54
+ formData.append('captchaKey', captchaKey);
55
+ formData.append('captcha', captchCode);
56
+ // 重新发送验证码
57
+ await axios.post(api, formData);
69
58
  message.success(t('sendSuccess', lang));
70
59
  }
71
60
 
@@ -86,10 +75,17 @@ const CreateMessageVerifyModal = ({ props }: { props: ModalConfig }) => {
86
75
  value={otp}
87
76
  onChange={(val) => {
88
77
  setOtp(val);
78
+ console.log('打印Content-Type', config.headers['Content-Type'])
89
79
  if (val.length === 6) {
90
- http.defaults.headers.common['sms-code'] = val as string;
91
- http.defaults.headers.common['sms-code-key'] = verifyCodeKey as string;
92
- http(config);
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
+ });
93
89
  setVisible(false);
94
90
  }
95
91
  }} />