message-verify 0.0.40-beta.0 → 0.0.42-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/index.d.ts CHANGED
@@ -1,9 +1,7 @@
1
1
  export type ModalConfig = {
2
- data: {
3
- mobile: string;
4
- verifyCodeKey: string;
5
- sendSuccess: boolean;
6
- };
2
+ data: string;
7
3
  onClose?: () => void;
4
+ config: object;
5
+ http: (params: object) => Promise<unknown>;
8
6
  };
9
- export declare const createMessageVerifyModal: (config: ModalConfig) => void;
7
+ export declare const createMessageVerifyModal: (modalProps: ModalConfig) => void;
package/dist/index.js CHANGED
@@ -2,15 +2,15 @@ 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
  let modalRoot = null;
5
- export const createMessageVerifyModal = (config) => {
5
+ export const createMessageVerifyModal = (modalProps) => {
6
6
  const container = document.createElement('div');
7
7
  container.id = 'antd-modal-container';
8
8
  document.body.appendChild(container);
9
9
  modalRoot = ReactDOM.createRoot(container);
10
- modalRoot.render(_jsx(VerifyModal, { config: {
11
- ...config,
10
+ modalRoot.render(_jsx(VerifyModal, { props: {
11
+ ...modalProps,
12
12
  onClose: () => {
13
- config.onClose?.();
13
+ modalProps.onClose?.();
14
14
  destroyModal();
15
15
  }
16
16
  } }));
package/dist/main.js CHANGED
@@ -1,9 +1,9 @@
1
1
  import { jsx as _jsx } from "react/jsx-runtime";
2
2
  import { createRoot } from 'react-dom/client';
3
3
  import { createMessageVerifyModal } from './index.js'; // 或 './index'
4
- const data = {
5
- mobile: '185****7760',
6
- verifyCodeKey: 'e381c5f9-c7f4-4bf1-a948-744334fb0203',
7
- sendSuccess: true
8
- };
9
- createRoot(document.getElementById('root')).render(_jsx("button", { onClick: () => createMessageVerifyModal({ data }), children: "Show Modal" }));
4
+ const data = "{\"mobile\":\"188****4035\",\"verifyCodeKey\":\"3f025b33-988e-47c0-950d-6beb776d043f\",\"needValid\":true,\"step\":2,\"message\":\"需要填写验证码\"}";
5
+ createRoot(document.getElementById('root')).render(_jsx("button", { onClick: () => createMessageVerifyModal({
6
+ data,
7
+ config: {},
8
+ http: () => Promise.resolve({}),
9
+ }), children: "Show Modal" }));
package/dist/resource.js CHANGED
@@ -1,43 +1,46 @@
1
- import { assign, axios as instance, customPost } from '@yqg/resource';
2
- import { message } from './compoments/index.js';
3
- import { YQG_SUCCESS } from './utils/status.js';
1
+ import { assign, customPost } from '@yqg/resource';
2
+ // import { assign, axios as instance, customPost } from '@yqg/resource';
3
+ // import { message } from './compoments/index.js';
4
+ // import { YQG_SUCCESS } from './utils/status.js';
4
5
  const urlPrefix = '/admin/';
5
6
  // axios.defaults.headers.common['Access-Control-Allow-Origin'] = '*';
6
- instance.interceptors.response.use((res) => {
7
- const { status } = res?.data || {};
8
- const { code, detail } = status || {};
9
- if (res?.config?.responseType === 'blob') {
10
- if (res?.data?.type === 'application/json') {
11
- // 没有拿到文件时,将拿到的 blob 流转为 js 对象,进而拿到错误信息(detail)并返回 reject 状态
12
- // 不处理将默认下载一个 json 文件
13
- const reader = new FileReader();
14
- reader.readAsText(res.data, 'utf-8');
15
- reader.onload = () => {
16
- const parsedObj = JSON.parse(reader.result);
17
- message.info(parsedObj?.status?.detail);
18
- };
19
- return Promise.reject();
20
- }
21
- else {
22
- return res;
23
- }
24
- }
25
- if (res.headers && res.headers['content-type'] === 'image/jpeg') {
26
- return res;
27
- }
28
- switch (code) {
29
- case YQG_SUCCESS:
30
- return Promise.resolve(res);
31
- default: {
32
- message.error(detail);
33
- return Promise.reject(res);
34
- }
35
- }
36
- }, (err) => {
37
- const detail = err?.data?.status?.detail || 'Unknown error';
38
- message.error(detail);
39
- return Promise.reject(err);
40
- });
7
+ // instance.interceptors.response.use(
8
+ // (res) => {
9
+ // const { status } = res?.data || {};
10
+ // const { code, detail } = status || {};
11
+ // if (res?.config?.responseType === 'blob') {
12
+ // if (res?.data?.type === 'application/json') {
13
+ // // 没有拿到文件时,将拿到的 blob 流转为 js 对象,进而拿到错误信息(detail)并返回 reject 状态
14
+ // // 不处理将默认下载一个 json 文件
15
+ // const reader = new FileReader();
16
+ // reader.readAsText(res.data, 'utf-8');
17
+ // reader.onload = () => {
18
+ // const parsedObj = JSON.parse(reader.result as string);
19
+ // message.info(parsedObj?.status?.detail);
20
+ // };
21
+ // return Promise.reject();
22
+ // } else {
23
+ // return res;
24
+ // }
25
+ // }
26
+ // if (res.headers && res.headers['content-type'] === 'image/jpeg') {
27
+ // return res;
28
+ // }
29
+ // switch (code) {
30
+ // case YQG_SUCCESS:
31
+ // return Promise.resolve(res);
32
+ // default: {
33
+ // message.error(detail);
34
+ // return Promise.reject(res);
35
+ // }
36
+ // }
37
+ // },
38
+ // (err: {data: {status: {detail: string}}}) => {
39
+ // const detail = err?.data?.status?.detail || 'Unknown error';
40
+ // message.error(detail);
41
+ // return Promise.reject(err);
42
+ // },
43
+ // );
41
44
  const api = {
42
45
  urlPrefix,
43
46
  getCaptchaKey: customPost('captcha/key'),
@@ -1,12 +1,10 @@
1
1
  type ModalConfig = {
2
- data: {
3
- mobile: string;
4
- verifyCodeKey: string;
5
- sendSuccess: boolean;
6
- };
2
+ data: string;
7
3
  onClose?: () => void;
4
+ config: object;
5
+ http: (params: object) => Promise<unknown>;
8
6
  };
9
- declare const ModalDom: ({ config }: {
10
- config: ModalConfig;
7
+ declare const ModalDom: ({ props }: {
8
+ props: ModalConfig;
11
9
  }) => import("react/jsx-runtime.js").JSX.Element;
12
10
  export default ModalDom;
@@ -2,14 +2,15 @@ import { jsxs as _jsxs, jsx as _jsx } from "react/jsx-runtime";
2
2
  import { useEffect, useState } from 'react';
3
3
  import { Modal, Input, Button, message } from './compoments/index.js';
4
4
  import Api from './resource.js';
5
- const ModalDom = ({ config }) => {
5
+ const ModalDom = ({ props }) => {
6
6
  const [visible, setVisible] = useState(true);
7
7
  const [countdown, setCountdown] = useState(3);
8
8
  const [captchaImage, setCaptchaImage] = useState('');
9
9
  const [captchCode, setCaptchCode] = useState('');
10
10
  const [captchaKey, setCaptchaKey] = useState('');
11
- const { data } = config || {};
12
- const { mobile } = data || {};
11
+ const { data, config, http } = props || {};
12
+ const dataObj = JSON.parse(data || '{}');
13
+ const { mobile } = dataObj || {};
13
14
  const getKey = async () => {
14
15
  const res = await Api.getCaptchaKey();
15
16
  const { body: key } = res.data || {};
@@ -47,9 +48,14 @@ const ModalDom = ({ config }) => {
47
48
  };
48
49
  return (_jsxs(Modal, { visible: visible, onClose: () => {
49
50
  setVisible(false);
50
- config.onClose?.();
51
+ props.onClose?.();
51
52
  }, children: [_jsxs("div", { style: { fontSize: 14, color: '#666' }, children: ["\u5DF2\u53D1\u9001\u77ED\u4FE1\u81F3\u60A8\u7684\u624B\u673A\uFF1A", mobile] }), countdown > 0 ? null : _jsxs("div", { style: { marginBlock: 8, display: 'flex', alignItems: 'center', width: 300 }, children: [_jsx(Input, { placeholder: "\u8BF7\u8F93\u5165\u56FE\u5F62\u9A8C\u8BC1\u7801", onChange: (e) => {
52
53
  setCaptchCode(e);
53
- } }), captchaImage && _jsx("img", { src: captchaImage, alt: "\u9A8C\u8BC1\u7801", style: { width: 100, height: 30, marginLeft: 8 }, onClick: getKey })] }), (countdown > 0 || captchCode) ? null : _jsx("div", { style: { fontSize: 14, color: 'red' }, 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, { placeholder: "\u8BF7\u8F93\u5165\u9A8C\u8BC1\u7801", onChange: (val) => { console.log('change', val); } }), _jsx(Button, { disabled: countdown > 0 || !captchCode, onClick: handleResend, children: countdown > 0 ? `${countdown}秒` : '重新发送' })] })] }));
54
+ } }), captchaImage && _jsx("img", { src: captchaImage, alt: "\u9A8C\u8BC1\u7801", style: { width: 100, height: 30, marginLeft: 8 }, onClick: getKey })] }), (countdown > 0 || captchCode) ? null : _jsx("div", { style: { fontSize: 14, color: 'red' }, 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, { placeholder: "\u8BF7\u8F93\u5165\u9A8C\u8BC1\u7801", onChange: (val) => {
55
+ if (val.length === 6) {
56
+ console.log('change', val.length);
57
+ http(config);
58
+ }
59
+ } }), _jsx(Button, { disabled: countdown > 0 || !captchCode, onClick: handleResend, children: countdown > 0 ? `${countdown}秒` : '重新发送' })] })] }));
54
60
  };
55
61
  export default ModalDom;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "message-verify",
3
- "version": "0.0.40-beta.0",
3
+ "version": "0.0.42-beta.0",
4
4
  "type": "module",
5
5
  "main": "dist/index.js",
6
6
  "dependencies": {
package/src/index.tsx CHANGED
@@ -2,17 +2,15 @@ import ReactDOM from 'react-dom/client'
2
2
  import VerifyModal from './verify-modal.js'
3
3
 
4
4
  export type ModalConfig = {
5
- data: {
6
- mobile: string;
7
- verifyCodeKey: string;
8
- sendSuccess: boolean;
9
- };
10
- onClose?: () => void
5
+ data: string;
6
+ onClose?: () => void
7
+ config: object;
8
+ http: (params: object) => Promise<unknown>;
11
9
  }
12
10
 
13
11
  let modalRoot: ReactDOM.Root | null = null
14
12
 
15
- export const createMessageVerifyModal = (config: ModalConfig) => {
13
+ export const createMessageVerifyModal = (modalProps: ModalConfig) => {
16
14
  const container = document.createElement('div')
17
15
  container.id = 'antd-modal-container'
18
16
  document.body.appendChild(container)
@@ -20,10 +18,10 @@ export const createMessageVerifyModal = (config: ModalConfig) => {
20
18
  modalRoot = ReactDOM.createRoot(container)
21
19
  modalRoot.render(
22
20
  <VerifyModal
23
- config={{
24
- ...config,
21
+ props={{
22
+ ...modalProps,
25
23
  onClose: () => {
26
- config.onClose?.()
24
+ modalProps.onClose?.()
27
25
  destroyModal()
28
26
  }
29
27
  }}
package/src/main.tsx CHANGED
@@ -1,13 +1,13 @@
1
1
  import { createRoot } from 'react-dom/client';
2
2
  import { createMessageVerifyModal } from './index.js'; // 或 './index'
3
3
 
4
- const data = {
5
- mobile: '185****7760',
6
- verifyCodeKey: 'e381c5f9-c7f4-4bf1-a948-744334fb0203',
7
- sendSuccess: true
8
- }
4
+ const data = "{\"mobile\":\"188****4035\",\"verifyCodeKey\":\"3f025b33-988e-47c0-950d-6beb776d043f\",\"needValid\":true,\"step\":2,\"message\":\"需要填写验证码\"}";
9
5
 
10
6
  createRoot(document.getElementById('root')!).render(
11
- <button onClick={() => createMessageVerifyModal({ data })}>
7
+ <button onClick={() => createMessageVerifyModal({
8
+ data,
9
+ config: {},
10
+ http: () => Promise.resolve({}),
11
+ })}>
12
12
  Show Modal
13
13
  </button>);
package/src/resource.ts CHANGED
@@ -1,50 +1,51 @@
1
- import { assign, axios as instance, customPost } from '@yqg/resource';
2
- import { message } from './compoments/index.js';
3
- import { YQG_SUCCESS } from './utils/status.js';
1
+ import { assign, customPost } from '@yqg/resource';
2
+ // import { assign, axios as instance, customPost } from '@yqg/resource';
3
+ // import { message } from './compoments/index.js';
4
+ // import { YQG_SUCCESS } from './utils/status.js';
4
5
 
5
6
  const urlPrefix = '/admin/';
6
7
  // axios.defaults.headers.common['Access-Control-Allow-Origin'] = '*';
7
- instance.interceptors.response.use(
8
- (res) => {
9
- const { status } = res?.data || {};
10
- const { code, detail } = status || {};
11
- if (res?.config?.responseType === 'blob') {
12
- if (res?.data?.type === 'application/json') {
13
- // 没有拿到文件时,将拿到的 blob 流转为 js 对象,进而拿到错误信息(detail)并返回 reject 状态
14
- // 不处理将默认下载一个 json 文件
15
- const reader = new FileReader();
16
- reader.readAsText(res.data, 'utf-8');
17
- reader.onload = () => {
18
- const parsedObj = JSON.parse(reader.result as string);
19
- message.info(parsedObj?.status?.detail);
20
- };
8
+ // instance.interceptors.response.use(
9
+ // (res) => {
10
+ // const { status } = res?.data || {};
11
+ // const { code, detail } = status || {};
12
+ // if (res?.config?.responseType === 'blob') {
13
+ // if (res?.data?.type === 'application/json') {
14
+ // // 没有拿到文件时,将拿到的 blob 流转为 js 对象,进而拿到错误信息(detail)并返回 reject 状态
15
+ // // 不处理将默认下载一个 json 文件
16
+ // const reader = new FileReader();
17
+ // reader.readAsText(res.data, 'utf-8');
18
+ // reader.onload = () => {
19
+ // const parsedObj = JSON.parse(reader.result as string);
20
+ // message.info(parsedObj?.status?.detail);
21
+ // };
21
22
 
22
- return Promise.reject();
23
- } else {
24
- return res;
25
- }
26
- }
23
+ // return Promise.reject();
24
+ // } else {
25
+ // return res;
26
+ // }
27
+ // }
27
28
 
28
- if (res.headers && res.headers['content-type'] === 'image/jpeg') {
29
- return res;
30
- }
29
+ // if (res.headers && res.headers['content-type'] === 'image/jpeg') {
30
+ // return res;
31
+ // }
31
32
 
32
- switch (code) {
33
- case YQG_SUCCESS:
34
- return Promise.resolve(res);
35
- default: {
36
- message.error(detail);
37
- return Promise.reject(res);
38
- }
39
- }
40
- },
41
- (err: {data: {status: {detail: string}}}) => {
42
- const detail = err?.data?.status?.detail || 'Unknown error';
43
- message.error(detail);
33
+ // switch (code) {
34
+ // case YQG_SUCCESS:
35
+ // return Promise.resolve(res);
36
+ // default: {
37
+ // message.error(detail);
38
+ // return Promise.reject(res);
39
+ // }
40
+ // }
41
+ // },
42
+ // (err: {data: {status: {detail: string}}}) => {
43
+ // const detail = err?.data?.status?.detail || 'Unknown error';
44
+ // message.error(detail);
44
45
 
45
- return Promise.reject(err);
46
- },
47
- );
46
+ // return Promise.reject(err);
47
+ // },
48
+ // );
48
49
  const api = {
49
50
  urlPrefix,
50
51
 
@@ -3,21 +3,20 @@ import { Modal, Input, Button, message } from './compoments/index.js'
3
3
  import Api from './resource.js'
4
4
 
5
5
  type ModalConfig = {
6
- data: {
7
- mobile: string;
8
- verifyCodeKey: string;
9
- sendSuccess: boolean;
10
- };
11
- onClose?: () => void
6
+ data: string;
7
+ onClose?: () => void;
8
+ config: object;
9
+ http: (params: object) => Promise<unknown>;
12
10
  }
13
- const ModalDom = ({ config }: { config: ModalConfig }) => {
11
+ const ModalDom = ({ props }: { props: ModalConfig }) => {
14
12
  const [visible, setVisible] = useState(true);
15
13
  const [countdown, setCountdown] = useState(3);
16
14
  const [captchaImage, setCaptchaImage] = useState<string>('');
17
15
  const [captchCode, setCaptchCode] = useState<string>('');
18
16
  const [captchaKey, setCaptchaKey] = useState<string>('');
19
- const { data } = config || {};
20
- const { mobile } = data || {};
17
+ const { data, config, http } = props || {};
18
+ const dataObj = JSON.parse(data || '{}');
19
+ const { mobile } = dataObj || {};
21
20
 
22
21
 
23
22
  const getKey = async () => {
@@ -63,7 +62,7 @@ const ModalDom = ({ config }: { config: ModalConfig }) => {
63
62
  visible={visible}
64
63
  onClose={() => {
65
64
  setVisible(false);
66
- config.onClose?.();
65
+ props.onClose?.();
67
66
  }}
68
67
  >
69
68
  <div style={{ fontSize: 14, color: '#666' }}>已发送短信至您的手机:{mobile}</div>
@@ -81,7 +80,12 @@ const ModalDom = ({ config }: { config: ModalConfig }) => {
81
80
  <div style={{ display: 'flex', alignItems: 'center', gap: 8, marginTop: 8 }}>
82
81
  <Input
83
82
  placeholder="请输入验证码"
84
- onChange={(val) => {console.log('change', val)}}
83
+ onChange={(val) => {
84
+ if(val.length === 6) {
85
+ console.log('change', val.length)
86
+ http(config);
87
+ }
88
+ }}
85
89
  />
86
90
  <Button
87
91
  disabled={countdown > 0 || !captchCode}