message-verify 0.0.25-beta.0 → 0.0.26-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/app.d.ts CHANGED
@@ -6,6 +6,7 @@ interface Props {
6
6
  sendSuccess: boolean;
7
7
  };
8
8
  refresh: () => void;
9
+ isShow: boolean;
9
10
  }
10
11
  declare const App: React.FC<Props>;
11
12
  export default App;
package/dist/app.js CHANGED
@@ -1,12 +1,13 @@
1
1
  import { jsxs as _jsxs, jsx as _jsx } from "react/jsx-runtime";
2
2
  import { useEffect, useState } from 'react';
3
+ import { createPortal } from 'react-dom';
3
4
  import { Input, Button, Modal, message } from 'antd';
4
5
  import Api from './resource.js';
5
6
  import '@ant-design/v5-patch-for-react-19';
6
- const App = ({ data }) => {
7
+ const App = ({ data, isShow }) => {
7
8
  const { mobile } = data || {};
8
9
  const [countdown, setCountdown] = useState(3);
9
- const [visible, setVisible] = useState(false);
10
+ const [visible, setVisible] = useState(isShow || false);
10
11
  const [captchaImage, setCaptchaImage] = useState('');
11
12
  const [captchCode, setCaptchCode] = useState('');
12
13
  const [captchaKey, setCaptchaKey] = useState('');
@@ -45,9 +46,13 @@ const App = ({ data }) => {
45
46
  console.log('handleResend=>res', res);
46
47
  message.success('发送成功');
47
48
  };
48
- console.log('captchCode', captchCode);
49
- return (_jsxs(Modal, { open: visible, onClose: () => setVisible(false), width: 400, footer: _jsx(Button, { onClick: () => { }, children: "\u63D0\u4EA4" }), 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) => {
49
+ const renderModal = (_jsxs(Modal, { open: visible, onClose: () => setVisible(false), width: 400, footer: _jsx(Button, { onClick: () => { }, children: "\u63D0\u4EA4" }), 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) => {
50
50
  setCaptchCode(e.target.value);
51
51
  } }), 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.OTP, { disabled: !captchCode, length: 6, onChange: (val) => { console.log('change', val); } }), _jsx(Button, { disabled: countdown > 0 || !captchCode, onClick: handleResend, children: countdown > 0 ? `${countdown}秒` : '重新发送' })] })] }));
52
+ console.log('captchCode', captchCode);
53
+ if (isShow) {
54
+ return createPortal(renderModal, document.body);
55
+ }
56
+ return null;
52
57
  };
53
58
  export default App;
package/dist/index.d.ts CHANGED
@@ -5,6 +5,9 @@ interface Props {
5
5
  sendSuccess: boolean;
6
6
  };
7
7
  refresh: () => void;
8
+ isShow: boolean;
8
9
  }
9
- export declare function createMessageVerify(props: Props): import("react/jsx-runtime").JSX.Element;
10
- export {};
10
+ declare function createMessageVerify(props: Props): {
11
+ destroy: () => void;
12
+ };
13
+ export { createMessageVerify };
package/dist/index.js CHANGED
@@ -1,5 +1,20 @@
1
1
  import { jsx as _jsx } from "react/jsx-runtime";
2
2
  import App from './app';
3
- export function createMessageVerify(props) {
4
- return _jsx(App, { ...props });
3
+ import { createRoot } from 'react-dom/client';
4
+ function createMessageVerify(props) {
5
+ // 创建一个挂载点
6
+ const container = document.createElement('div');
7
+ document.body.appendChild(container);
8
+ // 渲染弹窗
9
+ const root = createRoot(container);
10
+ // 这里 isShow 直接传 true,弹窗立即显示
11
+ root.render(_jsx(App, { ...props, isShow: true }));
12
+ // 可选:返回关闭方法
13
+ return {
14
+ destroy: () => {
15
+ root.unmount();
16
+ document.body.removeChild(container);
17
+ }
18
+ };
5
19
  }
20
+ export { createMessageVerify };
package/dist/main.js CHANGED
@@ -5,4 +5,4 @@ createRoot(document.getElementById('root')).render(_jsx(App, { data: {
5
5
  mobile: '185****7760',
6
6
  verifyCodeKey: 'e381c5f9-c7f4-4bf1-a948-744334fb0203',
7
7
  sendSuccess: true
8
- }, refresh: () => { console.log('刷新'); } }));
8
+ }, refresh: () => { console.log('刷新'); }, isShow: true }));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "message-verify",
3
- "version": "0.0.25-beta.0",
3
+ "version": "0.0.26-beta.0",
4
4
  "type": "module",
5
5
  "main": "dist/index.js",
6
6
  "dependencies": {
package/src/app.tsx CHANGED
@@ -1,4 +1,5 @@
1
1
  import { useEffect, useState } from 'react'
2
+ import { createPortal } from 'react-dom';
2
3
  import { Input, Button, Modal, message } from 'antd';
3
4
  import Api from './resource.js'
4
5
  import '@ant-design/v5-patch-for-react-19';
@@ -10,11 +11,12 @@ interface Props {
10
11
  sendSuccess: boolean;
11
12
  };
12
13
  refresh: () => void;
14
+ isShow: boolean;
13
15
  }
14
- const App: React.FC<Props> = ({ data }) => {
16
+ const App: React.FC<Props> = ({ data, isShow }) => {
15
17
  const { mobile } = data || {};
16
18
  const [countdown, setCountdown] = useState(3);
17
- const [visible, setVisible] = useState(false);
19
+ const [visible, setVisible] = useState(isShow || false);
18
20
  const [captchaImage, setCaptchaImage] = useState<string>('');
19
21
  const [captchCode, setCaptchCode] = useState<string>('');
20
22
  const [captchaKey, setCaptchaKey] = useState<string>('');
@@ -57,9 +59,7 @@ const App: React.FC<Props> = ({ data }) => {
57
59
  message.success('发送成功');
58
60
  }
59
61
 
60
- console.log('captchCode', captchCode);
61
- return (
62
- <Modal
62
+ const renderModal = (<Modal
63
63
  open={visible}
64
64
  onClose={() => setVisible(false)}
65
65
  width={400}
@@ -93,6 +93,12 @@ const App: React.FC<Props> = ({ data }) => {
93
93
  </div>
94
94
  </Modal>
95
95
  )
96
+
97
+ console.log('captchCode', captchCode);
98
+ if(isShow) {
99
+ return createPortal(renderModal, document.body);
100
+ }
101
+ return null;
96
102
  }
97
103
 
98
104
  export default App;
package/src/index.tsx CHANGED
@@ -1,4 +1,5 @@
1
1
  import App from './app';
2
+ import { createRoot } from 'react-dom/client';
2
3
 
3
4
  interface Props {
4
5
  data: {
@@ -7,8 +8,26 @@ interface Props {
7
8
  sendSuccess: boolean;
8
9
  };
9
10
  refresh: () => void;
11
+ isShow: boolean;
10
12
  }
11
13
 
12
- export function createMessageVerify(props: Props) {
13
- return <App {...props} />;
14
- }
14
+ function createMessageVerify(props: Props) {
15
+ // 创建一个挂载点
16
+ const container = document.createElement('div');
17
+ document.body.appendChild(container);
18
+
19
+ // 渲染弹窗
20
+ const root = createRoot(container);
21
+ // 这里 isShow 直接传 true,弹窗立即显示
22
+ root.render(<App {...props} isShow={true} />);
23
+
24
+ // 可选:返回关闭方法
25
+ return {
26
+ destroy: () => {
27
+ root.unmount();
28
+ document.body.removeChild(container);
29
+ }
30
+ };
31
+ }
32
+
33
+ export { createMessageVerify };
package/src/main.tsx CHANGED
@@ -9,4 +9,5 @@ createRoot(document.getElementById('root')!).render(
9
9
  sendSuccess: true
10
10
  }}
11
11
  refresh={() => {console.log('刷新')}}
12
+ isShow={true}
12
13
  />);