message-verify 1.0.1-beta.63 → 1.0.1-beta.65
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/modal/verify-modal.js +53 -26
- package/package.json +1 -1
- package/src/modal/verify-modal.tsx +51 -25
@@ -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,49 @@ const CreateMessageVerifyModal = ({ props }) => {
|
|
83
93
|
setOtp(val);
|
84
94
|
if (val.length === 6) {
|
85
95
|
try {
|
86
|
-
const res = await Promise.race([
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
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
|
+
});
|
109
137
|
if (res?.data?.status?.code === 0) {
|
110
|
-
|
138
|
+
apiResolve(res);
|
111
139
|
setVisible(false);
|
112
140
|
}
|
113
141
|
else {
|
@@ -120,7 +148,6 @@ const CreateMessageVerifyModal = ({ props }) => {
|
|
120
148
|
console.warn('catch=>error', error);
|
121
149
|
message.error(t('verifyFail', lang));
|
122
150
|
setOtp('');
|
123
|
-
setVisible(false);
|
124
151
|
}
|
125
152
|
}
|
126
153
|
} }), _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,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,49 @@ 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
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
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
|
-
|
153
|
+
}) as any;
|
127
154
|
if (res?.data?.status?.code === 0) {
|
128
|
-
|
155
|
+
apiResolve(res);
|
129
156
|
setVisible(false);
|
130
157
|
} else {
|
131
158
|
message.error(t('verifyFail', lang));
|
@@ -136,7 +163,6 @@ const CreateMessageVerifyModal = ({ props }: { props: VerifyModalConfig }) => {
|
|
136
163
|
console.warn('catch=>error', error);
|
137
164
|
message.error(t('verifyFail', lang));
|
138
165
|
setOtp('');
|
139
|
-
setVisible(false);
|
140
166
|
}
|
141
167
|
}
|
142
168
|
}} />
|