message-verify 0.0.5-beta.0 → 0.0.8-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/package.json CHANGED
@@ -1,8 +1,8 @@
1
1
  {
2
2
  "name": "message-verify",
3
- "version": "0.0.5-beta.0",
3
+ "version": "0.0.8-beta.0",
4
4
  "type": "module",
5
- "main": "src/index.ts",
5
+ "main": "src/main.tsx",
6
6
  "dependencies": {
7
7
  "react": "^19.0.0",
8
8
  "react-dom": "^19.0.0"
package/src/App.tsx CHANGED
@@ -1,25 +1,57 @@
1
- import { useState } from 'react'
1
+ import { useEffect, useState } from 'react'
2
2
  import './App.css'
3
+ import Modal from './components/modal'
4
+ import Input from './components/input'
3
5
 
4
- function App() {
5
- const [count, setCount] = useState(0);
6
+ interface Props {
7
+ data: {
8
+ mobile: string;
9
+ verifyCodeKey: string;
10
+ sendSuccess: boolean;
11
+ };
12
+ }
13
+ const App: React.FC<Props> = ({ data }) => {
14
+ const { mobile } = data || {};
15
+ const [countdown, setCountdown] = useState(60);
16
+ const [visible, setVisible] = useState(false);
17
+
18
+ useEffect(() => {
19
+ setVisible(true);
20
+ }, [])
21
+ useEffect(() => {
22
+ let timer: number | null = null;
23
+ if (visible && countdown > 0) {
24
+ timer = setInterval(() => {
25
+ setCountdown((prev) => prev - 1);
26
+ }, 1000);
27
+ }
28
+ return () => {
29
+ if (timer) clearInterval(timer);
30
+ };
31
+ }, [visible, countdown]);
32
+
33
+ const handleResend = () => {
34
+ setCountdown(60);
35
+ // 这里可以加上重新发送验证码的逻辑
36
+ };
6
37
 
7
- return (
8
- <>
9
- <h1>Vite + React</h1>
10
- <div className="card">
11
- <button onClick={() => setCount((count) => count + 1)}>
12
- count is {count}
13
- </button>
14
- <p>
15
- Edit <code>src/App.tsx</code> and save to test HMR
16
- </p>
17
- </div>
18
- <p className="read-the-docs">
19
- Click on the Vite and React logos to learn more
20
- </p>
21
- </>
22
- )
38
+ return (
39
+ <>
40
+ <Modal visible={visible} onClose={() => setVisible(false)}>
41
+ <div>已发送短信至您的手机:{mobile}</div>
42
+ <div style={{ display: 'flex', alignItems: 'center', gap: 8 }}>
43
+ <Input placeholder="请输入验证码" />
44
+ <button
45
+ disabled={countdown > 0}
46
+ onClick={handleResend}
47
+ style={countdown > 0 ? { marginLeft: 8 } : { marginLeft: 8, backgroundColor: '#1677ff', color: '#fff' }}
48
+ >
49
+ {countdown > 0 ? `${countdown}秒` : '重新发送'}
50
+ </button>
51
+ </div>
52
+ </Modal>
53
+ </>
54
+ )
23
55
  }
24
56
 
25
57
  export default App
@@ -0,0 +1,35 @@
1
+ import React from 'react';
2
+
3
+ interface InputProps extends React.InputHTMLAttributes<HTMLInputElement> {
4
+ placeholder?: string;
5
+ }
6
+
7
+ const inputStyle: React.CSSProperties = {
8
+ padding: '8px 12px',
9
+ border: '1px solid #ccc',
10
+ borderRadius: 4,
11
+ fontSize: 16,
12
+ outline: 'none',
13
+ transition: 'border-color 0.2s',
14
+ };
15
+
16
+ const Input: React.FC<InputProps> = (props) => {
17
+ const { placeholder = '请输入' } = props;
18
+ return (
19
+ <input
20
+ style={inputStyle}
21
+ placeholder={placeholder}
22
+ {...props}
23
+ onFocus={e => {
24
+ props.onFocus?.(e);
25
+ (e.target as HTMLInputElement).style.borderColor = '#1677ff';
26
+ }}
27
+ onBlur={e => {
28
+ props.onBlur?.(e);
29
+ (e.target as HTMLInputElement).style.borderColor = '#ccc';
30
+ }}
31
+ />
32
+ );
33
+ };
34
+
35
+ export default Input;
@@ -0,0 +1,60 @@
1
+ import React from 'react';
2
+
3
+ interface ModalProps {
4
+ visible: boolean;
5
+ onClose: () => void;
6
+ children: React.ReactNode;
7
+ }
8
+
9
+ const modalStyle: React.CSSProperties = {
10
+ position: 'fixed',
11
+ top: 0,
12
+ left: 0,
13
+ width: '100vw',
14
+ height: '100vh',
15
+ background: 'rgba(0,0,0,0.3)',
16
+ display: 'flex',
17
+ alignItems: 'center',
18
+ justifyContent: 'center',
19
+ zIndex: 1000,
20
+ };
21
+
22
+ const contentStyle: React.CSSProperties = {
23
+ position: 'relative',
24
+ background: '#fff',
25
+ borderRadius: 8,
26
+ padding: 24,
27
+ minWidth: 320,
28
+ minHeight: 120,
29
+ boxShadow: '0 2px 8px rgba(0,0,0,0.15)',
30
+ };
31
+
32
+ const closeBtnStyle: React.CSSProperties = {
33
+ position: 'absolute',
34
+ top: 12,
35
+ right: 12,
36
+ width: 24,
37
+ height: 24,
38
+ border: 'none',
39
+ background: 'transparent',
40
+ fontSize: 20,
41
+ cursor: 'pointer',
42
+ lineHeight: 1,
43
+ };
44
+
45
+ const Modal: React.FC<ModalProps> = ({ visible, onClose, children }) => {
46
+ if (!visible) return null;
47
+
48
+ return (
49
+ <div style={modalStyle}>
50
+ <div style={contentStyle}>
51
+ <button style={closeBtnStyle} onClick={onClose} aria-label="关闭">
52
+ ×
53
+ </button>
54
+ {children}
55
+ </div>
56
+ </div>
57
+ );
58
+ };
59
+
60
+ export default Modal;
package/src/index.ts CHANGED
@@ -1,3 +1,3 @@
1
1
  import App from './App'
2
2
 
3
- export default { App };
3
+ export default { messageVerifyModal: App };
package/src/main.tsx CHANGED
@@ -3,8 +3,18 @@ import { createRoot } from 'react-dom/client'
3
3
  import './index.css'
4
4
  import App from './App.tsx'
5
5
 
6
+ const data = {
7
+ mobile: '185****7760',
8
+ verifyCodeKey: 'e381c5f9-c7f4-4bf1-a948-744334fb0203',
9
+ sendSuccess: true
10
+ };
11
+
6
12
  createRoot(document.getElementById('root')!).render(
7
13
  <StrictMode>
8
- <App />
14
+ <App data={data} />
9
15
  </StrictMode>,
10
- )
16
+ )
17
+
18
+ export default {
19
+ messageVerifyModal: App
20
+ }