message-verify 1.0.1-beta.63 → 1.0.1-beta.66

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.
@@ -1,5 +1,5 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
- import { useEffect, useState } from 'react';
2
+ import { useRef, useEffect, useState } from 'react';
3
3
  import { Modal, Input, Button, message } from '../compoments/index.js';
4
4
  import Api from '../utils/resource.js';
5
5
  import t from '../utils/i18n.js';
@@ -16,6 +16,8 @@ const CreateMessageVerifyModal = ({ props }) => {
16
16
  const { data, http, lang, sendApi = '/admin/sms/send', config, apiResolve, apiPromiseToEmpty, onClose, response } = props || {};
17
17
  const dataObj = JSON.parse(data || '{}');
18
18
  const { mobile, verifyCodeKey } = dataObj || {};
19
+ const resolveRef = useRef(null);
20
+ const rejectRef = useRef(null);
19
21
  const getKey = async () => {
20
22
  try {
21
23
  const res = await Api.getCaptchaKey();
@@ -52,6 +54,14 @@ const CreateMessageVerifyModal = ({ props }) => {
52
54
  const handler = (data) => {
53
55
  // 这里处理收到的数据
54
56
  console.log('收到 response 事件:', data);
57
+ if (data === 0) {
58
+ resolveRef.current();
59
+ // setVisible(false);
60
+ }
61
+ else {
62
+ rejectRef.current();
63
+ // setVisible(false);
64
+ }
55
65
  setResCode(data);
56
66
  };
57
67
  eventEmitter.on('response', handler);
@@ -83,31 +93,50 @@ const CreateMessageVerifyModal = ({ props }) => {
83
93
  setOtp(val);
84
94
  if (val.length === 6) {
85
95
  try {
86
- const res = await Promise.race([
87
- new Promise((resolve, reject) => {
88
- setTimeout(() => {
89
- reject(new Error('Timeout'));
90
- }, 1000);
91
- }),
92
- new Promise((resolve, reject) => {
93
- http({
94
- ...config,
95
- headers: {
96
- ...http.defaults.headers.common,
97
- 'sms-code': val,
98
- 'sms-code-key': verifyCodeKey,
99
- 'Content-Type': config.headers['Content-Type'],
100
- }
101
- }).then(res => {
102
- console.log('VerifyHandler => then', response, resCode);
103
- resolve(res);
104
- }).catch(err => {
105
- reject(err);
106
- });
107
- })
108
- ]);
96
+ // const res = await Promise.race([
97
+ // new Promise((resolve, reject) => {
98
+ // setTimeout(() => {
99
+ // reject(new Error('Timeout'));
100
+ // }, 1000);
101
+ // }),
102
+ // new Promise((resolve, reject) => {
103
+ // http({
104
+ // ...config,
105
+ // headers: {
106
+ // ...http.defaults.headers.common,
107
+ // 'sms-code': val,
108
+ // 'sms-code-key': verifyCodeKey,
109
+ // 'Content-Type': config.headers['Content-Type'],
110
+ // }
111
+ // }).then(res => {
112
+ // console.log('VerifyHandler => then', response, resCode);
113
+ // resolve(res);
114
+ // }).catch(err => {
115
+ // reject(err);
116
+ // })
117
+ // })
118
+ // ]) as any;
119
+ const res = await new Promise((resolve, reject) => {
120
+ resolveRef.current = resolve;
121
+ rejectRef.current = reject;
122
+ http({
123
+ ...config,
124
+ headers: {
125
+ ...http.defaults.headers.common,
126
+ 'sms-code': val,
127
+ 'sms-code-key': verifyCodeKey,
128
+ 'Content-Type': config.headers['Content-Type'],
129
+ }
130
+ }).then(res => {
131
+ console.log('VerifyHandler => then', response, resCode);
132
+ resolve(res);
133
+ }).catch(err => {
134
+ reject(err);
135
+ });
136
+ });
137
+ console.log('res=====>', res);
109
138
  if (res?.data?.status?.code === 0) {
110
- // apiResolve(res);
139
+ apiResolve(res);
111
140
  setVisible(false);
112
141
  }
113
142
  else {
@@ -120,7 +149,6 @@ const CreateMessageVerifyModal = ({ props }) => {
120
149
  console.warn('catch=>error', error);
121
150
  message.error(t('verifyFail', lang));
122
151
  setOtp('');
123
- setVisible(false);
124
152
  }
125
153
  }
126
154
  } }), _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": "1.0.1-beta.63",
3
+ "version": "1.0.1-beta.66",
4
4
  "type": "module",
5
5
  "main": "dist/index.js",
6
6
  "dependencies": {
@@ -1,4 +1,4 @@
1
- import { useEffect, useState } from 'react'
1
+ import { useRef, useEffect, useState } from 'react'
2
2
  import { Modal, Input, Button, message } from '../compoments/index.js'
3
3
  import Api from '../utils/resource.js'
4
4
  import t from '../utils/i18n.js'
@@ -17,6 +17,8 @@ const CreateMessageVerifyModal = ({ props }: { props: VerifyModalConfig }) => {
17
17
  const { data, http, lang, sendApi = '/admin/sms/send', config, apiResolve, apiPromiseToEmpty, onClose, response } = props || {};
18
18
  const dataObj = JSON.parse(data || '{}');
19
19
  const { mobile, verifyCodeKey } = dataObj || {};
20
+ const resolveRef = useRef<any>(null);
21
+ const rejectRef = useRef<any>(null);
20
22
 
21
23
  const getKey = async () => {
22
24
  try {
@@ -56,6 +58,13 @@ const CreateMessageVerifyModal = ({ props }: { props: VerifyModalConfig }) => {
56
58
  const handler = (data: any) => {
57
59
  // 这里处理收到的数据
58
60
  console.log('收到 response 事件:', data);
61
+ if (data === 0) {
62
+ resolveRef.current();
63
+ // setVisible(false);
64
+ } else {
65
+ rejectRef.current();
66
+ // setVisible(false);
67
+ }
59
68
  setResCode(data);
60
69
  };
61
70
  eventEmitter.on('response', handler);
@@ -101,31 +110,50 @@ const CreateMessageVerifyModal = ({ props }: { props: VerifyModalConfig }) => {
101
110
  setOtp(val);
102
111
  if (val.length === 6) {
103
112
  try {
104
- const res = await Promise.race([
105
- new Promise((resolve, reject) => {
106
- setTimeout(() => {
107
- reject(new Error('Timeout'));
108
- }, 1000);
109
- }),
110
- new Promise((resolve, reject) => {
111
- http({
112
- ...config,
113
- headers: {
114
- ...http.defaults.headers.common,
115
- 'sms-code': val,
116
- 'sms-code-key': verifyCodeKey,
117
- 'Content-Type': config.headers['Content-Type'],
118
- }
119
- }).then(res => {
120
- console.log('VerifyHandler => then', response, resCode);
121
- resolve(res);
122
- }).catch(err => {
123
- reject(err);
124
- })
113
+ // const res = await Promise.race([
114
+ // new Promise((resolve, reject) => {
115
+ // setTimeout(() => {
116
+ // reject(new Error('Timeout'));
117
+ // }, 1000);
118
+ // }),
119
+ // new Promise((resolve, reject) => {
120
+ // http({
121
+ // ...config,
122
+ // headers: {
123
+ // ...http.defaults.headers.common,
124
+ // 'sms-code': val,
125
+ // 'sms-code-key': verifyCodeKey,
126
+ // 'Content-Type': config.headers['Content-Type'],
127
+ // }
128
+ // }).then(res => {
129
+ // console.log('VerifyHandler => then', response, resCode);
130
+ // resolve(res);
131
+ // }).catch(err => {
132
+ // reject(err);
133
+ // })
134
+ // })
135
+ // ]) as any;
136
+ const res = await new Promise((resolve, reject) => {
137
+ resolveRef.current = resolve;
138
+ rejectRef.current = reject;
139
+ http({
140
+ ...config,
141
+ headers: {
142
+ ...http.defaults.headers.common,
143
+ 'sms-code': val,
144
+ 'sms-code-key': verifyCodeKey,
145
+ 'Content-Type': config.headers['Content-Type'],
146
+ }
147
+ }).then(res => {
148
+ console.log('VerifyHandler => then', response, resCode);
149
+ resolve(res);
150
+ }).catch(err => {
151
+ reject(err);
125
152
  })
126
- ]) as any;
153
+ }) as any;
154
+ console.log('res=====>', res);
127
155
  if (res?.data?.status?.code === 0) {
128
- // apiResolve(res);
156
+ apiResolve(res);
129
157
  setVisible(false);
130
158
  } else {
131
159
  message.error(t('verifyFail', lang));
@@ -136,7 +164,6 @@ const CreateMessageVerifyModal = ({ props }: { props: VerifyModalConfig }) => {
136
164
  console.warn('catch=>error', error);
137
165
  message.error(t('verifyFail', lang));
138
166
  setOtp('');
139
- setVisible(false);
140
167
  }
141
168
  }
142
169
  }} />