message-verify 0.0.34-beta.0 → 0.0.36-beta.0
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/compoments/button.d.ts +9 -0
- package/dist/compoments/button.js +20 -0
- package/dist/compoments/index.d.ts +4 -0
- package/dist/compoments/index.js +4 -0
- package/dist/compoments/input.d.ts +9 -0
- package/dist/compoments/input.js +13 -0
- package/dist/index.js +42 -3
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +1 -1
- package/src/compoments/button.tsx +38 -0
- package/src/compoments/index.ts +5 -0
- package/src/compoments/input.tsx +30 -0
- package/src/index.tsx +60 -1
@@ -0,0 +1,9 @@
|
|
1
|
+
import React from 'react';
|
2
|
+
interface CustomButtonProps {
|
3
|
+
disabled?: boolean;
|
4
|
+
onClick?: (e: React.MouseEvent<HTMLButtonElement>) => void;
|
5
|
+
children?: React.ReactNode;
|
6
|
+
style?: React.CSSProperties;
|
7
|
+
}
|
8
|
+
declare const Button: React.FC<CustomButtonProps>;
|
9
|
+
export default Button;
|
@@ -0,0 +1,20 @@
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
2
|
+
const Button = ({ disabled, onClick, children, style }) => {
|
3
|
+
const handleClick = (e) => {
|
4
|
+
if (!disabled) {
|
5
|
+
onClick?.(e);
|
6
|
+
// 这里可以记录点击事件
|
7
|
+
console.log('按钮被点击');
|
8
|
+
}
|
9
|
+
};
|
10
|
+
return (_jsx("button", { disabled: disabled, onClick: handleClick, style: {
|
11
|
+
padding: '6px 16px',
|
12
|
+
borderRadius: 4,
|
13
|
+
border: '1px solid #d9d9d9',
|
14
|
+
background: disabled ? '#f5f5f5' : '#1677ff',
|
15
|
+
color: disabled ? '#aaa' : '#fff',
|
16
|
+
cursor: disabled ? 'not-allowed' : 'pointer',
|
17
|
+
...style,
|
18
|
+
}, children: children }));
|
19
|
+
};
|
20
|
+
export default Button;
|
@@ -0,0 +1,13 @@
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
2
|
+
const Input = ({ value, onChange, placeholder, type = 'text' }) => {
|
3
|
+
return (_jsx("input", { type: type, value: value, placeholder: placeholder, onChange: e => onChange?.(e.target.value), style: {
|
4
|
+
padding: '6px 12px',
|
5
|
+
border: '1px solid #d9d9d9',
|
6
|
+
borderRadius: 4,
|
7
|
+
outline: 'none',
|
8
|
+
fontSize: 14,
|
9
|
+
width: '100%',
|
10
|
+
boxSizing: 'border-box'
|
11
|
+
} }));
|
12
|
+
};
|
13
|
+
export default Input;
|
package/dist/index.js
CHANGED
@@ -1,19 +1,58 @@
|
|
1
1
|
import { jsxs as _jsxs, jsx as _jsx } from "react/jsx-runtime";
|
2
|
-
import Modal from './compoments/
|
2
|
+
import { Modal, Input, Button } from './compoments/index.js';
|
3
3
|
import ReactDOM from 'react-dom/client';
|
4
4
|
import { useEffect, useState } from 'react';
|
5
|
+
import Api from './resource.js';
|
5
6
|
let modalRoot = null;
|
6
7
|
const ModalDom = ({ config }) => {
|
7
8
|
const [visible, setVisible] = useState(true);
|
9
|
+
const [countdown, setCountdown] = useState(60);
|
10
|
+
const [captchaImage, setCaptchaImage] = useState('');
|
11
|
+
const [captchCode, setCaptchCode] = useState('');
|
12
|
+
const [captchaKey, setCaptchaKey] = useState('');
|
8
13
|
const { data } = config || {};
|
9
14
|
const { mobile } = data || {};
|
15
|
+
const getKey = async () => {
|
16
|
+
const res = await Api.getCaptchaKey();
|
17
|
+
const { body: key } = res.data || {};
|
18
|
+
setCaptchaKey(key);
|
19
|
+
if (key) {
|
20
|
+
console.log('res=>key', key);
|
21
|
+
const image = Api.getCaptchaImgUrl(key);
|
22
|
+
console.log('image', image);
|
23
|
+
setCaptchaImage(image);
|
24
|
+
}
|
25
|
+
};
|
26
|
+
useEffect(() => {
|
27
|
+
let timer = null;
|
28
|
+
if (visible && countdown > 0) {
|
29
|
+
timer = setInterval(() => {
|
30
|
+
setCountdown((prev) => prev - 1);
|
31
|
+
}, 1000);
|
32
|
+
}
|
33
|
+
if (countdown === 0) {
|
34
|
+
getKey();
|
35
|
+
}
|
36
|
+
return () => {
|
37
|
+
if (timer)
|
38
|
+
clearInterval(timer);
|
39
|
+
};
|
40
|
+
}, [visible, countdown]);
|
10
41
|
useEffect(() => {
|
11
42
|
console.log('mobile', mobile);
|
12
43
|
}, []);
|
13
|
-
|
44
|
+
const handleResend = async () => {
|
45
|
+
setCountdown(60);
|
46
|
+
const res = await Api.reSendCode({ captchaKey, captcha: captchCode });
|
47
|
+
console.log('handleResend=>res', res);
|
48
|
+
// message.success('发送成功');
|
49
|
+
};
|
50
|
+
return (_jsxs(Modal, { visible: visible, onClose: () => {
|
14
51
|
setVisible(false);
|
15
52
|
config.onClose?.();
|
16
|
-
}, children: _jsxs("div", { children: ["\u5DF2\u53D1\u9001\u77ED\u4FE1\u81F3\u60A8\u7684\u624B\u673A\uFF1A", mobile] }) })
|
53
|
+
}, children: [_jsxs("div", { children: ["\u5DF2\u53D1\u9001\u77ED\u4FE1\u81F3\u60A8\u7684\u624B\u673A\uFF1A", mobile] }), countdown > 0 ? null : _jsxs("div", { style: { marginTop: 8, display: 'flex', alignItems: 'center', width: 300 }, children: [_jsx(Input, { onChange: (e) => {
|
54
|
+
setCaptchCode(e);
|
55
|
+
} }), captchaImage && _jsx("img", { src: captchaImage, alt: "\u9A8C\u8BC1\u7801", style: { width: 100, height: 30, marginLeft: 8 }, onClick: getKey })] }), countdown > 0 ? null : _jsx("div", { children: "\u8BF7\u8F93\u5165\u56FE\u5F62\u9A8C\u8BC1\u7801\u540E\uFF0C\u91CD\u65B0\u53D1\u9001\u9A8C\u8BC1\u7801" }), _jsxs("div", { style: { display: 'flex', alignItems: 'center', gap: 8, marginTop: 8 }, children: [_jsx(Input, { onChange: (val) => { console.log('change', val); } }), _jsx(Button, { disabled: countdown > 0 || !captchCode, onClick: handleResend, children: countdown > 0 ? `${countdown}秒` : '重新发送' })] })] }));
|
17
56
|
};
|
18
57
|
// ... existing code ...
|
19
58
|
export const createMessageVerifyModal = (config) => {
|
@@ -1 +1 @@
|
|
1
|
-
{"root":["../src/app.tsx","../src/index.tsx","../src/main.tsx","../src/resource.ts","../src/vite-env.d.ts","../src/compoments/modal.tsx","../src/utils/getfingerprint.ts","../src/utils/index.ts","../src/utils/status.ts"],"version":"5.7.3"}
|
1
|
+
{"root":["../src/app.tsx","../src/index.tsx","../src/main.tsx","../src/resource.ts","../src/vite-env.d.ts","../src/compoments/button.tsx","../src/compoments/index.ts","../src/compoments/input.tsx","../src/compoments/modal.tsx","../src/utils/getfingerprint.ts","../src/utils/index.ts","../src/utils/status.ts"],"version":"5.7.3"}
|
package/package.json
CHANGED
@@ -0,0 +1,38 @@
|
|
1
|
+
import React from 'react';
|
2
|
+
|
3
|
+
interface CustomButtonProps {
|
4
|
+
disabled?: boolean;
|
5
|
+
onClick?: (e: React.MouseEvent<HTMLButtonElement>) => void;
|
6
|
+
children?: React.ReactNode;
|
7
|
+
style?: React.CSSProperties;
|
8
|
+
}
|
9
|
+
|
10
|
+
const Button: React.FC<CustomButtonProps> = ({ disabled, onClick, children, style }) => {
|
11
|
+
const handleClick = (e: React.MouseEvent<HTMLButtonElement>) => {
|
12
|
+
if (!disabled) {
|
13
|
+
onClick?.(e);
|
14
|
+
// 这里可以记录点击事件
|
15
|
+
console.log('按钮被点击');
|
16
|
+
}
|
17
|
+
};
|
18
|
+
|
19
|
+
return (
|
20
|
+
<button
|
21
|
+
disabled={disabled}
|
22
|
+
onClick={handleClick}
|
23
|
+
style={{
|
24
|
+
padding: '6px 16px',
|
25
|
+
borderRadius: 4,
|
26
|
+
border: '1px solid #d9d9d9',
|
27
|
+
background: disabled ? '#f5f5f5' : '#1677ff',
|
28
|
+
color: disabled ? '#aaa' : '#fff',
|
29
|
+
cursor: disabled ? 'not-allowed' : 'pointer',
|
30
|
+
...style,
|
31
|
+
}}
|
32
|
+
>
|
33
|
+
{children}
|
34
|
+
</button>
|
35
|
+
);
|
36
|
+
};
|
37
|
+
|
38
|
+
export default Button;
|
@@ -0,0 +1,30 @@
|
|
1
|
+
import React from 'react';
|
2
|
+
|
3
|
+
interface CustomInputProps {
|
4
|
+
value?: string;
|
5
|
+
onChange?: (val: string) => void;
|
6
|
+
placeholder?: string;
|
7
|
+
type?: string;
|
8
|
+
}
|
9
|
+
|
10
|
+
const Input: React.FC<CustomInputProps> = ({ value, onChange, placeholder, type = 'text' }) => {
|
11
|
+
return (
|
12
|
+
<input
|
13
|
+
type={type}
|
14
|
+
value={value}
|
15
|
+
placeholder={placeholder}
|
16
|
+
onChange={e => onChange?.(e.target.value)}
|
17
|
+
style={{
|
18
|
+
padding: '6px 12px',
|
19
|
+
border: '1px solid #d9d9d9',
|
20
|
+
borderRadius: 4,
|
21
|
+
outline: 'none',
|
22
|
+
fontSize: 14,
|
23
|
+
width: '100%',
|
24
|
+
boxSizing: 'border-box'
|
25
|
+
}}
|
26
|
+
/>
|
27
|
+
);
|
28
|
+
};
|
29
|
+
|
30
|
+
export default Input;
|
package/src/index.tsx
CHANGED
@@ -1,6 +1,7 @@
|
|
1
|
-
import Modal from './compoments/
|
1
|
+
import { Modal, Input, Button } from './compoments/index.js'
|
2
2
|
import ReactDOM from 'react-dom/client'
|
3
3
|
import { useEffect, useState } from'react'
|
4
|
+
import Api from './resource.js'
|
4
5
|
|
5
6
|
export type ModalConfig = {
|
6
7
|
data: {
|
@@ -15,12 +16,51 @@ let modalRoot: ReactDOM.Root | null = null
|
|
15
16
|
|
16
17
|
const ModalDom = ({ config }: { config: ModalConfig }) => {
|
17
18
|
const [visible, setVisible] = useState(true);
|
19
|
+
const [countdown, setCountdown] = useState(60);
|
20
|
+
const [captchaImage, setCaptchaImage] = useState<string>('');
|
21
|
+
const [captchCode, setCaptchCode] = useState<string>('');
|
22
|
+
const [captchaKey, setCaptchaKey] = useState<string>('');
|
18
23
|
const { data } = config || {};
|
19
24
|
const { mobile } = data || {};
|
20
25
|
|
26
|
+
|
27
|
+
const getKey = async () => {
|
28
|
+
const res = await Api.getCaptchaKey();
|
29
|
+
const { body: key } = res.data || {};
|
30
|
+
setCaptchaKey(key);
|
31
|
+
if(key) {
|
32
|
+
console.log('res=>key', key);
|
33
|
+
const image = Api.getCaptchaImgUrl(key) as unknown;
|
34
|
+
console.log('image', image);
|
35
|
+
setCaptchaImage(image as string);
|
36
|
+
}
|
37
|
+
}
|
38
|
+
|
39
|
+
useEffect(() => {
|
40
|
+
let timer: number | null = null;
|
41
|
+
if (visible && countdown > 0) {
|
42
|
+
timer = setInterval(() => {
|
43
|
+
setCountdown((prev) => prev - 1);
|
44
|
+
}, 1000);
|
45
|
+
}
|
46
|
+
if (countdown === 0) {
|
47
|
+
getKey();
|
48
|
+
}
|
49
|
+
return () => {
|
50
|
+
if (timer) clearInterval(timer);
|
51
|
+
};
|
52
|
+
}, [visible, countdown]);
|
53
|
+
|
21
54
|
useEffect(() => {
|
22
55
|
console.log('mobile', mobile);
|
23
56
|
}, [])
|
57
|
+
|
58
|
+
const handleResend = async() => {
|
59
|
+
setCountdown(60);
|
60
|
+
const res = await Api.reSendCode({captchaKey, captcha: captchCode});
|
61
|
+
console.log('handleResend=>res', res);
|
62
|
+
// message.success('发送成功');
|
63
|
+
}
|
24
64
|
|
25
65
|
return (
|
26
66
|
<Modal
|
@@ -31,6 +71,25 @@ const ModalDom = ({ config }: { config: ModalConfig }) => {
|
|
31
71
|
}}
|
32
72
|
>
|
33
73
|
<div>已发送短信至您的手机:{mobile}</div>
|
74
|
+
{countdown > 0 ? null : <div style={{ marginTop: 8, display: 'flex', alignItems: 'center', width: 300 }}>
|
75
|
+
<Input onChange={(e) => {
|
76
|
+
setCaptchCode(e as string)
|
77
|
+
}} />
|
78
|
+
|
79
|
+
{captchaImage && <img src={captchaImage} alt="验证码" style={{ width: 100, height: 30, marginLeft: 8 }} onClick={getKey} />}
|
80
|
+
</div>}
|
81
|
+
{countdown > 0 ? null : <div>请输入图形验证码后,重新发送验证码</div>}
|
82
|
+
<div style={{ display: 'flex', alignItems: 'center', gap: 8, marginTop: 8 }}>
|
83
|
+
<Input
|
84
|
+
onChange={(val) => {console.log('change', val)}}
|
85
|
+
/>
|
86
|
+
<Button
|
87
|
+
disabled={countdown > 0 || !captchCode}
|
88
|
+
onClick={handleResend}
|
89
|
+
>
|
90
|
+
{countdown > 0 ? `${countdown}秒` : '重新发送'}
|
91
|
+
</Button>
|
92
|
+
</div>
|
34
93
|
</Modal>
|
35
94
|
);
|
36
95
|
};
|