message-verify 1.0.0-beta.8 → 1.0.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/.arcconfig +8 -0
- package/arcanist/.phutil_module_cache +1 -0
- package/arcanist/__phutil_library_init__.php +3 -0
- package/arcanist/__phutil_library_map__.php +18 -0
- package/arcanist/lint/engine/YqgWebDiffLintEngine.php +68 -0
- package/dist/index.d.ts +3 -2
- package/dist/index.js +55 -29
- package/dist/locales/en.d.ts +5 -0
- package/dist/locales/en.js +6 -1
- package/dist/locales/id.d.ts +5 -0
- package/dist/locales/id.js +6 -1
- package/dist/locales/zh.d.ts +5 -0
- package/dist/locales/zh.js +6 -1
- package/dist/main.js +43 -9
- package/dist/modal/relogin-modal.d.ts +5 -0
- package/dist/modal/relogin-modal.js +24 -0
- package/dist/modal/verify-modal.d.ts +5 -0
- package/dist/modal/verify-modal.js +115 -0
- package/dist/relogin-modal.d.ts +5 -0
- package/dist/relogin-modal.js +23 -0
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/utils/resource.d.ts +2 -0
- package/dist/utils/resource.js +7 -0
- package/dist/utils/type.d.ts +14 -3
- package/dist/verify-modal.d.ts +2 -2
- package/dist/verify-modal.js +44 -15
- package/eslint.config.js +2 -0
- package/package.json +3 -2
- package/src/index.tsx +70 -43
- package/src/locales/en.ts +6 -1
- package/src/locales/id.ts +6 -1
- package/src/locales/zh.ts +6 -1
- package/src/main.tsx +50 -10
- package/src/modal/relogin-modal.tsx +43 -0
- package/src/{verify-modal.tsx → modal/verify-modal.tsx} +54 -25
- package/src/utils/type.ts +13 -3
- /package/src/{resource.ts → utils/resource.ts} +0 -0
package/.arcconfig
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
{"__symbol_cache_version__":11,"0861795cb7fca1601b342f4e44fe1aed":{"have":{"class":{"YqgWebDiffLintEngine":13}},"need":{"class":{"ArcanistLintEngine":42,"ExecFuture":1832,"PhutilConsole":1780}},"xmap":{"YqgWebDiffLintEngine":["ArcanistLintEngine"]}}}
|
@@ -0,0 +1,18 @@
|
|
1
|
+
<?php
|
2
|
+
|
3
|
+
/**
|
4
|
+
* This file is automatically generated. Use 'arc liberate' to rebuild it.
|
5
|
+
*
|
6
|
+
* @generated
|
7
|
+
* @phutil-library-version 2
|
8
|
+
*/
|
9
|
+
phutil_register_library_map(array(
|
10
|
+
'__library_version__' => 2,
|
11
|
+
'class' => array(
|
12
|
+
'YqgWebDiffLintEngine' => 'lint/engine/YqgWebDiffLintEngine.php',
|
13
|
+
),
|
14
|
+
'function' => array(),
|
15
|
+
'xmap' => array(
|
16
|
+
'YqgWebDiffLintEngine' => 'ArcanistLintEngine',
|
17
|
+
),
|
18
|
+
));
|
@@ -0,0 +1,68 @@
|
|
1
|
+
<?php
|
2
|
+
|
3
|
+
class YqgWebDiffLintEngine extends ArcanistLintEngine
|
4
|
+
{
|
5
|
+
/** @Override */
|
6
|
+
public function buildLinters()
|
7
|
+
{
|
8
|
+
// Filter the affected paths.
|
9
|
+
$paths = $this->getPaths();
|
10
|
+
foreach ($paths as $key => $path) {
|
11
|
+
if (!$this->pathExists($path)) {
|
12
|
+
// Don't lint removed files. In more complex linters it is sometimes
|
13
|
+
// appropriate to lint removed files so you can raise a warning like
|
14
|
+
// "you deleted X, but forgot to delete Y!", but most linters do not
|
15
|
+
// operate correctly on removed files.
|
16
|
+
unset($paths[$key]);
|
17
|
+
continue;
|
18
|
+
}
|
19
|
+
|
20
|
+
$disk = $this->getFilePathOnDisk($path);
|
21
|
+
if (is_dir($disk)) {
|
22
|
+
// Don't lint directories. (In SVN, they can be directly modified by
|
23
|
+
// changing properties on them, and may appear as modified paths.)
|
24
|
+
unset($paths[$key]);
|
25
|
+
continue;
|
26
|
+
}
|
27
|
+
}
|
28
|
+
|
29
|
+
$command = '';
|
30
|
+
$patterns = array(
|
31
|
+
'/\.(jsx?|tsx?|vue?|ts?)$/' => 'pnpm eslint',
|
32
|
+
// '/\.(less|s?css)$/' => 'npx stylelint --fix' // 理论上暂时不用 style lint
|
33
|
+
);
|
34
|
+
|
35
|
+
foreach ($patterns as $pattern => $lintCommand) {
|
36
|
+
$matchedPaths = preg_grep($pattern, $paths);
|
37
|
+
if (count($matchedPaths) > 0) {
|
38
|
+
if (strlen($command)) {
|
39
|
+
$command .= ' && \\';
|
40
|
+
}
|
41
|
+
|
42
|
+
$command .= $lintCommand . ' ' . join(' ', $matchedPaths);
|
43
|
+
}
|
44
|
+
}
|
45
|
+
|
46
|
+
$root = $this->getWorkingCopy()->getProjectRoot();
|
47
|
+
$console = PhutilConsole::getConsole();
|
48
|
+
|
49
|
+
$future = new ExecFuture($command);
|
50
|
+
$future->setCWD($root . "/");
|
51
|
+
list($exitcode, $stdout, $stderr) = $future->resolve();
|
52
|
+
$console->writeOut($stdout);
|
53
|
+
$console->writeOut($stderr);
|
54
|
+
$console->writeOut("\n");
|
55
|
+
|
56
|
+
if ($exitcode != 0) {
|
57
|
+
$console->writeOut("All code in any code-base should look like a single person typed it, no matter how many people contributed. --idiomatic.js\n");
|
58
|
+
$console->writeOut("无论有多少人在维护,所有在代码仓库中的代码理应看起来像同一个人写的。 --idiomatic.js\n");
|
59
|
+
$console->writeOut("https://github.com/rwaldron/idiomatic.js/tree/master/translations/zh_CN\n");
|
60
|
+
throw new Exception("Keep it in mind!");
|
61
|
+
} else {
|
62
|
+
$console->writeOut("All code are clean, you did a great job!\n");
|
63
|
+
}
|
64
|
+
|
65
|
+
return;
|
66
|
+
}
|
67
|
+
|
68
|
+
}
|
package/dist/index.d.ts
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
-
import {
|
1
|
+
import { VerifyModalConfig, LoginModalConfig } from './utils/type.js';
|
2
2
|
export declare const initFingerprint: () => Promise<string>;
|
3
|
-
export declare const
|
3
|
+
export declare const createReLoginModal: (modalProps: LoginModalConfig) => void;
|
4
|
+
export declare const VerifyHandler: ({ data, config, http, verifyPromise, sendApi }: VerifyModalConfig) => Promise<any>;
|
package/dist/index.js
CHANGED
@@ -1,45 +1,71 @@
|
|
1
1
|
import { jsx as _jsx } from "react/jsx-runtime";
|
2
2
|
import ReactDOM from 'react-dom/client';
|
3
|
-
import VerifyModal from './verify-modal.js';
|
3
|
+
import VerifyModal from './modal/verify-modal.js';
|
4
4
|
import Fingerprint2 from 'fingerprintjs2';
|
5
|
-
|
5
|
+
import ReLoginModal from './modal/relogin-modal.js';
|
6
|
+
let fingerprintPromise = null; // 用 Promise 本身作为缓存
|
7
|
+
let modalRoot = null;
|
6
8
|
export const initFingerprint = async () => {
|
7
|
-
if (
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
.join('###');
|
19
|
-
const fingerprint = Fingerprint2.x64hash128(values, 31);
|
20
|
-
cachedFingerprint = fingerprint;
|
21
|
-
resolve(fingerprint);
|
9
|
+
if (!fingerprintPromise) {
|
10
|
+
fingerprintPromise = new Promise((resolve) => {
|
11
|
+
Fingerprint2.get(components => {
|
12
|
+
const includeKeys = ['userAgent', 'cpuClass', 'hardwareConcurrency', 'platform'];
|
13
|
+
const values = components
|
14
|
+
.filter(c => includeKeys.includes(c.key))
|
15
|
+
.map(c => c.value)
|
16
|
+
.join('###');
|
17
|
+
const fingerprint = Fingerprint2.x64hash128(values, 31);
|
18
|
+
resolve(fingerprint);
|
19
|
+
});
|
22
20
|
});
|
23
|
-
}
|
21
|
+
}
|
22
|
+
return fingerprintPromise;
|
24
23
|
};
|
25
|
-
|
26
|
-
|
24
|
+
const destroyModal = (modalId) => {
|
25
|
+
if (modalRoot) {
|
26
|
+
modalRoot.unmount();
|
27
|
+
document.getElementById(modalId)?.remove();
|
28
|
+
modalRoot = null;
|
29
|
+
}
|
30
|
+
};
|
31
|
+
const creatModal = (modalProps, modalId, ModalDom) => {
|
32
|
+
destroyModal(modalId);
|
27
33
|
const container = document.createElement('div');
|
28
|
-
container.id =
|
34
|
+
container.id = modalId;
|
29
35
|
document.body.appendChild(container);
|
30
36
|
modalRoot = ReactDOM.createRoot(container);
|
31
|
-
modalRoot.render(_jsx(
|
37
|
+
modalRoot.render(_jsx(ModalDom, { props: {
|
32
38
|
...modalProps,
|
33
39
|
onClose: () => {
|
34
|
-
|
35
|
-
destroyModal();
|
40
|
+
destroyModal(modalId);
|
36
41
|
}
|
37
42
|
} }));
|
38
43
|
};
|
39
|
-
const
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
+
const createMessageVerifyModal = (modalProps) => {
|
45
|
+
const verifyModalId = 'verify-modal-container';
|
46
|
+
creatModal(modalProps, verifyModalId, VerifyModal);
|
47
|
+
};
|
48
|
+
// 新增 relogin 弹窗创建方法
|
49
|
+
export const createReLoginModal = (modalProps) => {
|
50
|
+
const reLoginModalId = 'relogin-modal-container';
|
51
|
+
creatModal(modalProps, reLoginModalId, ReLoginModal);
|
52
|
+
};
|
53
|
+
export const VerifyHandler = ({ data, config, http, verifyPromise, sendApi }) => {
|
54
|
+
const toEmpty = () => {
|
55
|
+
verifyPromise.current = null;
|
56
|
+
};
|
57
|
+
if (!verifyPromise.current) {
|
58
|
+
verifyPromise.current = new Promise((resolve, reject) => {
|
59
|
+
createMessageVerifyModal({
|
60
|
+
data,
|
61
|
+
config,
|
62
|
+
http,
|
63
|
+
apiResolve: resolve,
|
64
|
+
apiReject: reject,
|
65
|
+
apiPromiseToEmpty: toEmpty,
|
66
|
+
sendApi
|
67
|
+
});
|
68
|
+
}).finally(toEmpty);
|
44
69
|
}
|
70
|
+
return verifyPromise.current;
|
45
71
|
};
|
package/dist/locales/en.d.ts
CHANGED
package/dist/locales/en.js
CHANGED
@@ -6,5 +6,10 @@ export default {
|
|
6
6
|
sendSuccess: 'Successfully sent',
|
7
7
|
sendFailed: 'Send failed',
|
8
8
|
reSend: 'Resend',
|
9
|
-
countDownSecound: '{countdown} seconds'
|
9
|
+
countDownSecound: '{countdown} seconds',
|
10
|
+
accountAlert: 'Account Security Alert',
|
11
|
+
alertContent: 'Changes have been detected in your login environment or network information.To ensure account security, please log in again to verify your identity.',
|
12
|
+
ok: 'OK',
|
13
|
+
chidoriOpenPro: 'Chidori has activated security protection for you',
|
14
|
+
verifyFail: 'Validation failed'
|
10
15
|
};
|
package/dist/locales/id.d.ts
CHANGED
package/dist/locales/id.js
CHANGED
@@ -6,5 +6,10 @@ export default {
|
|
6
6
|
sendSuccess: 'Berhasil dikirim',
|
7
7
|
sendFailed: 'Gagal mengirim',
|
8
8
|
reSend: 'Kirim Ulang',
|
9
|
-
countDownSecound: '{countdown} detik'
|
9
|
+
countDownSecound: '{countdown} detik',
|
10
|
+
accountAlert: 'Peringatan Keamanan Akun',
|
11
|
+
alertContent: 'Terdeteksi perubahan pada lingkungan login atau informasi jaringan Anda.Untuk menjaga keamanan akun, silakan login kembali untuk memverifikasi identitas Anda.',
|
12
|
+
ok: 'Baiklah',
|
13
|
+
chidoriOpenPro: 'chidori telah mengaktifkan keamanan untuk Anda',
|
14
|
+
verifyFail: 'Autentikasi gagal'
|
10
15
|
};
|
package/dist/locales/zh.d.ts
CHANGED
package/dist/locales/zh.js
CHANGED
@@ -6,5 +6,10 @@ export default {
|
|
6
6
|
sendSuccess: '发送成功',
|
7
7
|
sendFailed: '发送失败',
|
8
8
|
reSend: '重新发送',
|
9
|
-
countDownSecound: '{countdown}秒'
|
9
|
+
countDownSecound: '{countdown}秒',
|
10
|
+
accountAlert: '账号安全提醒',
|
11
|
+
alertContent: '检测到您的登录环境或网络信息有变动,为保障账户安全,请重新登录验证身份',
|
12
|
+
ok: '好的',
|
13
|
+
chidoriOpenPro: 'chidori已为您开启安全防护',
|
14
|
+
verifyFail: '验证失败'
|
10
15
|
};
|
package/dist/main.js
CHANGED
@@ -1,13 +1,47 @@
|
|
1
|
-
import { jsx as _jsx } from "react/jsx-runtime";
|
1
|
+
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
|
2
2
|
import { createRoot } from 'react-dom/client';
|
3
|
-
import {
|
3
|
+
import { initFingerprint, createReLoginModal, VerifyHandler } from './index.js'; // 或 './index'
|
4
4
|
import { axios } from '@yqg/resource';
|
5
5
|
const data = "{\"mobile\":\"188****4035\",\"verifyCodeKey\":\"3f025b33-988e-47c0-950d-6beb776d043f\",\"needValid\":true,\"step\":2,\"message\":\"需要填写验证码\"}";
|
6
6
|
const fp = await initFingerprint();
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
7
|
+
const fp2 = await initFingerprint();
|
8
|
+
console.log(fp, fp2);
|
9
|
+
const config = {
|
10
|
+
"transitional": {
|
11
|
+
"silentJSONParsing": true,
|
12
|
+
"forcedJSONParsing": true,
|
13
|
+
"clarifyTimeoutError": false
|
14
|
+
},
|
15
|
+
"timeout": 0,
|
16
|
+
"xsrfCookieName": "XSRF-TOKEN",
|
17
|
+
"xsrfHeaderName": "X-XSRF-TOKEN",
|
18
|
+
"maxContentLength": -1,
|
19
|
+
"maxBodyLength": -1,
|
20
|
+
"headers": {
|
21
|
+
"Accept": "application/json, text/plain, */*",
|
22
|
+
"X-Device-Fingerprint": "531f14c7176b16ebeb18e2b23d6bd124",
|
23
|
+
"Content-Type": "application/json"
|
24
|
+
},
|
25
|
+
"url": "/classification/admin/level/edit",
|
26
|
+
"method": "post",
|
27
|
+
"dataFormat": "JSON",
|
28
|
+
"showRequestData": true,
|
29
|
+
"showResponseData": false,
|
30
|
+
"showGeneralResponseData": true,
|
31
|
+
"headersList": [],
|
32
|
+
"requestDataFunc": "\nfunction(formFilterData){\n // 这里写你的处理逻辑\n return {\n ...formFilterData,\n 'classificationLevel': 2 //等级\n }\n}\n",
|
33
|
+
"responseDataFunc": "",
|
34
|
+
"responseGeneralDataFunc": "function(req, { data, util, window }) {\n return req\n .then((response) => {\n return Promise.resolve({\n status: {\n code: 0,\n }\n })\n })\n .catch((error) => {\n // 检查是否有响应数据\n if (error.response && error.response.data) {\n const responseData = error.response.data;\n const detail = responseData.body?.status?.detail || responseData.status?.detail;\n if (detail) {\n util.message.error(detail);\n } else {\n util.message.error('编辑失败,请重试');\n }\n } else {\n util.message.error('编辑失败,请重试');\n }\n console.error('Error during deletion:', error);\n });\n}",
|
35
|
+
"formInstance": {},
|
36
|
+
"data": "{\"id\":1,\"classificationName\":\"个人基本概况信息\",\"classificationLevel\":2}",
|
37
|
+
"baseURL": "http://localhost:62888"
|
38
|
+
};
|
39
|
+
const promise = { current: null };
|
40
|
+
createRoot(document.getElementById('root')).render(_jsxs(_Fragment, { children: [_jsx("button", { onClick: () => {
|
41
|
+
return VerifyHandler({ data, config, http: axios, verifyPromise: promise });
|
42
|
+
}, children: "Show verify Modal" }), _jsx("button", { onClick: () => createReLoginModal({
|
43
|
+
goLogin: () => {
|
44
|
+
console.log('goLogin');
|
45
|
+
},
|
46
|
+
lang: 'zh',
|
47
|
+
}), children: "Show login Modal" })] }));
|
@@ -0,0 +1,24 @@
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
2
|
+
import { useState } from 'react';
|
3
|
+
import { Modal, Button } from '../compoments/index.js';
|
4
|
+
import t from '../utils/i18n.js';
|
5
|
+
const ReLoginModal = ({ props }) => {
|
6
|
+
const { goLogin, lang, onClose: destroyModal } = props || {};
|
7
|
+
const [visible, setVisible] = useState(true);
|
8
|
+
const onClose = () => {
|
9
|
+
setVisible(false);
|
10
|
+
goLogin();
|
11
|
+
destroyModal?.();
|
12
|
+
};
|
13
|
+
return (_jsxs(Modal, { visible: visible, onClose: onClose, width: 420, children: [_jsx("div", { style: { fontWeight: 500, fontSize: 20, marginBottom: 24 }, children: t('accountAlert', lang) }), _jsx("div", { style: { color: '#222', fontSize: 16, marginBottom: 40, lineHeight: '24px' }, children: t('alertContent', lang) }), _jsx("div", { style: { display: 'flex', justifyContent: 'center' }, children: _jsx(Button, { style: {
|
14
|
+
background: '#1677ff',
|
15
|
+
color: '#fff',
|
16
|
+
border: 'none',
|
17
|
+
width: 80,
|
18
|
+
height: 36,
|
19
|
+
fontSize: 14,
|
20
|
+
borderRadius: 8,
|
21
|
+
boxShadow: '0 2px 8px rgba(22,119,255,0.08)',
|
22
|
+
}, onClick: onClose, children: t('ok', lang) }) })] }));
|
23
|
+
};
|
24
|
+
export default ReLoginModal;
|
@@ -0,0 +1,115 @@
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
2
|
+
import { useEffect, useState } from 'react';
|
3
|
+
import { Modal, Input, Button, message } from '../compoments/index.js';
|
4
|
+
import Api from '../utils/resource.js';
|
5
|
+
import t from '../utils/i18n.js';
|
6
|
+
import { axios } from '@yqg/resource';
|
7
|
+
const CreateMessageVerifyModal = ({ props }) => {
|
8
|
+
const [visible, setVisible] = useState(true);
|
9
|
+
const [countdown, setCountdown] = useState(60);
|
10
|
+
const [otp, setOtp] = useState('');
|
11
|
+
const [captchaImage, setCaptchaImage] = useState('');
|
12
|
+
const [captchCode, setCaptchCode] = useState('');
|
13
|
+
const [captchaKey, setCaptchaKey] = useState('');
|
14
|
+
const { data, http, lang, sendApi = '/admin/sms/send', config, apiResolve, apiPromiseToEmpty, onClose } = props || {};
|
15
|
+
const dataObj = JSON.parse(data || '{}');
|
16
|
+
const { mobile, verifyCodeKey } = dataObj || {};
|
17
|
+
const getKey = async () => {
|
18
|
+
try {
|
19
|
+
const res = await Api.getCaptchaKey();
|
20
|
+
const { body: key } = res.data || {};
|
21
|
+
setCaptchaKey(key);
|
22
|
+
if (key) {
|
23
|
+
const image = Api.getCaptchaImgUrl(key);
|
24
|
+
setCaptchaImage(image);
|
25
|
+
}
|
26
|
+
}
|
27
|
+
catch (err) {
|
28
|
+
const msg = typeof err === 'object' && err !== null && 'message' in err
|
29
|
+
? err.message
|
30
|
+
: String(err);
|
31
|
+
message.error(msg);
|
32
|
+
}
|
33
|
+
};
|
34
|
+
useEffect(() => {
|
35
|
+
let timer = null;
|
36
|
+
if (visible && countdown > 0) {
|
37
|
+
timer = setInterval(() => {
|
38
|
+
setCountdown((prev) => prev - 1);
|
39
|
+
}, 1000);
|
40
|
+
}
|
41
|
+
if (countdown === 0) {
|
42
|
+
getKey();
|
43
|
+
}
|
44
|
+
return () => {
|
45
|
+
if (timer)
|
46
|
+
clearInterval(timer);
|
47
|
+
};
|
48
|
+
}, [visible, countdown]);
|
49
|
+
const handleResend = async () => {
|
50
|
+
const formData = new FormData();
|
51
|
+
formData.append('captchaKey', captchaKey);
|
52
|
+
formData.append('captcha', captchCode);
|
53
|
+
// 重新发送验证码
|
54
|
+
const res = await axios.post(sendApi, formData);
|
55
|
+
const { code, detail } = res.data?.status || {};
|
56
|
+
if (code !== 0) {
|
57
|
+
message.error(detail || t('sendFailed', lang));
|
58
|
+
return;
|
59
|
+
}
|
60
|
+
message.success(t('sendSuccess', lang));
|
61
|
+
// 重置倒计时、验证码
|
62
|
+
setCountdown(60);
|
63
|
+
setOtp('');
|
64
|
+
};
|
65
|
+
return (_jsxs(Modal, { width: 420, visible: visible, onClose: () => {
|
66
|
+
setVisible(false);
|
67
|
+
apiPromiseToEmpty?.();
|
68
|
+
onClose?.();
|
69
|
+
}, children: [_jsx("div", { style: { fontSize: 14, color: '#666' }, children: t('alreadySend', lang, { phone: mobile }) }), _jsxs("div", { style: { display: 'flex', alignItems: 'center', gap: 8, marginTop: 12 }, children: [_jsx(Input.OTP, { length: 6, value: otp, onChange: async (val) => {
|
70
|
+
setOtp(val);
|
71
|
+
if (val.length === 6) {
|
72
|
+
try {
|
73
|
+
const res = await Promise.race([
|
74
|
+
new Promise((resolve, reject) => {
|
75
|
+
setTimeout(() => {
|
76
|
+
reject(new Error('Timeout'));
|
77
|
+
}, 1000);
|
78
|
+
}),
|
79
|
+
new Promise((resolve, reject) => {
|
80
|
+
http({
|
81
|
+
...config,
|
82
|
+
headers: {
|
83
|
+
...http.defaults.headers.common,
|
84
|
+
'sms-code': val,
|
85
|
+
'sms-code-key': verifyCodeKey,
|
86
|
+
'Content-Type': config.headers['Content-Type'],
|
87
|
+
}
|
88
|
+
}).then(res => {
|
89
|
+
resolve(res);
|
90
|
+
}).catch(err => {
|
91
|
+
reject(err);
|
92
|
+
});
|
93
|
+
})
|
94
|
+
]);
|
95
|
+
if (res?.data?.status?.code === 0) {
|
96
|
+
apiResolve(res);
|
97
|
+
setVisible(false);
|
98
|
+
}
|
99
|
+
else {
|
100
|
+
message.error(t('verifyFail', lang));
|
101
|
+
setOtp('');
|
102
|
+
}
|
103
|
+
}
|
104
|
+
catch (error) {
|
105
|
+
console.warn('catch=>error', error);
|
106
|
+
message.error(t('verifyFail', lang));
|
107
|
+
setOtp('');
|
108
|
+
}
|
109
|
+
}
|
110
|
+
} }), _jsx(Button, { disabled: countdown > 0 || !captchCode, onClick: handleResend, style: { padding: '8px' }, children: countdown > 0 ? t('countDownSecound', lang, { countdown }) : t('reSend', lang) })] }), countdown > 0 ? null :
|
111
|
+
_jsxs("div", { style: { marginTop: 12, display: 'flex', alignItems: 'center' }, children: [_jsx(Input, { placeholder: t('pleaseEnterPicVerifyCode', lang), onChange: (e) => {
|
112
|
+
setCaptchCode(e);
|
113
|
+
}, style: { width: 300 } }), captchaImage && _jsx("img", { src: captchaImage, alt: t('verifyCode', lang), style: { width: 100, height: 30, marginLeft: 8 }, onClick: getKey })] }), (countdown > 0 || captchCode) ? null : _jsx("div", { style: { fontSize: 14, color: 'red' }, children: t('pleaseEnterAndSend', lang) }), _jsx("div", { style: { fontSize: 14, color: '#666', marginTop: 12 }, children: t('chidoriOpenPro', lang) })] }));
|
114
|
+
};
|
115
|
+
export default CreateMessageVerifyModal;
|
@@ -0,0 +1,23 @@
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
2
|
+
import { useState } from 'react';
|
3
|
+
import { Modal, Button } from './compoments/index.js';
|
4
|
+
import t from './utils/i18n.js';
|
5
|
+
const ReLoginModal = ({ props }) => {
|
6
|
+
const { goLogin, lang } = props || {};
|
7
|
+
const [visible, setVisible] = useState(true);
|
8
|
+
const onClose = () => {
|
9
|
+
setVisible(false);
|
10
|
+
goLogin();
|
11
|
+
};
|
12
|
+
return (_jsxs(Modal, { visible: visible, onClose: onClose, width: 420, children: [_jsx("div", { style: { fontWeight: 500, fontSize: 20, marginBottom: 24 }, children: t('accountAlert', lang) }), _jsx("div", { style: { color: '#222', fontSize: 16, marginBottom: 40, lineHeight: '24px' }, children: t('alertContent', lang) }), _jsx("div", { style: { display: 'flex', justifyContent: 'center' }, children: _jsx(Button, { style: {
|
13
|
+
background: '#1677ff',
|
14
|
+
color: '#fff',
|
15
|
+
border: 'none',
|
16
|
+
width: 80,
|
17
|
+
height: 36,
|
18
|
+
fontSize: 14,
|
19
|
+
borderRadius: 8,
|
20
|
+
boxShadow: '0 2px 8px rgba(22,119,255,0.08)',
|
21
|
+
}, onClick: onClose, children: t('ok', lang) }) })] }));
|
22
|
+
};
|
23
|
+
export default ReLoginModal;
|
@@ -1 +1 @@
|
|
1
|
-
{"root":["../src/index.tsx","../src/main.tsx","../src/
|
1
|
+
{"root":["../src/index.tsx","../src/main.tsx","../src/vite-env.d.ts","../src/compoments/button.tsx","../src/compoments/index.ts","../src/compoments/input.tsx","../src/compoments/message.tsx","../src/compoments/modal.tsx","../src/locales/en.ts","../src/locales/id.ts","../src/locales/zh.ts","../src/modal/relogin-modal.tsx","../src/modal/verify-modal.tsx","../src/utils/i18n.ts","../src/utils/resource.ts","../src/utils/status.ts","../src/utils/type.ts"],"version":"5.7.3"}
|
@@ -0,0 +1,7 @@
|
|
1
|
+
import { assign, customPost } from '@yqg/resource';
|
2
|
+
const api = {
|
3
|
+
getCaptchaKey: customPost('/messageVerify/admin/captcha/key'),
|
4
|
+
reSendCode: customPost('/admin/sms/send'),
|
5
|
+
getCaptchaImgUrl: (captchaKey) => { return `/messageVerify/admin/captcha/image/${captchaKey}`; },
|
6
|
+
};
|
7
|
+
export default assign(api);
|
package/dist/utils/type.d.ts
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
export type
|
1
|
+
export type VerifyModalConfig = {
|
2
2
|
data: string;
|
3
3
|
onClose?: () => void;
|
4
4
|
config: {
|
@@ -7,7 +7,7 @@ export type ModalConfig = {
|
|
7
7
|
};
|
8
8
|
[key: string]: unknown;
|
9
9
|
};
|
10
|
-
lang
|
10
|
+
lang?: 'zh' | 'en' | 'id';
|
11
11
|
http: {
|
12
12
|
(params: object): Promise<unknown>;
|
13
13
|
defaults: {
|
@@ -18,5 +18,16 @@ export type ModalConfig = {
|
|
18
18
|
};
|
19
19
|
};
|
20
20
|
};
|
21
|
-
|
21
|
+
sendApi?: string;
|
22
|
+
apiReject?: any;
|
23
|
+
apiResolve?: any;
|
24
|
+
apiPromiseToEmpty?: () => void;
|
25
|
+
verifyPromise: {
|
26
|
+
current: Promise<any> | null;
|
27
|
+
};
|
28
|
+
};
|
29
|
+
export type LoginModalConfig = {
|
30
|
+
goLogin: () => void;
|
31
|
+
onClose?: () => void;
|
32
|
+
lang?: 'zh' | 'en' | 'id';
|
22
33
|
};
|
package/dist/verify-modal.d.ts
CHANGED
@@ -1,5 +1,5 @@
|
|
1
|
-
import {
|
1
|
+
import { VerifyModalConfig } from './utils/type.js';
|
2
2
|
declare const CreateMessageVerifyModal: ({ props }: {
|
3
|
-
props:
|
3
|
+
props: VerifyModalConfig;
|
4
4
|
}) => import("react/jsx-runtime.js").JSX.Element;
|
5
5
|
export default CreateMessageVerifyModal;
|
package/dist/verify-modal.js
CHANGED
@@ -6,12 +6,12 @@ import t from './utils/i18n.js';
|
|
6
6
|
import { axios } from '@yqg/resource';
|
7
7
|
const CreateMessageVerifyModal = ({ props }) => {
|
8
8
|
const [visible, setVisible] = useState(true);
|
9
|
-
const [countdown, setCountdown] = useState(
|
9
|
+
const [countdown, setCountdown] = useState(60);
|
10
10
|
const [otp, setOtp] = useState('');
|
11
11
|
const [captchaImage, setCaptchaImage] = useState('');
|
12
12
|
const [captchCode, setCaptchCode] = useState('');
|
13
13
|
const [captchaKey, setCaptchaKey] = useState('');
|
14
|
-
const { data,
|
14
|
+
const { data, http, lang, sendApi = '/admin/sms/send', config, apiResolve, apiPromiseToEmpty } = props || {};
|
15
15
|
const dataObj = JSON.parse(data || '{}');
|
16
16
|
const { mobile, verifyCodeKey } = dataObj || {};
|
17
17
|
const getKey = async () => {
|
@@ -51,36 +51,65 @@ const CreateMessageVerifyModal = ({ props }) => {
|
|
51
51
|
formData.append('captchaKey', captchaKey);
|
52
52
|
formData.append('captcha', captchCode);
|
53
53
|
// 重新发送验证码
|
54
|
-
const res = await axios.post(
|
54
|
+
const res = await axios.post(sendApi, formData);
|
55
55
|
const { code, detail } = res.data?.status || {};
|
56
56
|
if (code !== 0) {
|
57
57
|
message.error(detail || t('sendFailed', lang));
|
58
58
|
return;
|
59
59
|
}
|
60
60
|
message.success(t('sendSuccess', lang));
|
61
|
+
// 重置倒计时、验证码
|
61
62
|
setCountdown(60);
|
63
|
+
setOtp('');
|
62
64
|
};
|
63
65
|
return (_jsxs(Modal, { width: 420, visible: visible, onClose: () => {
|
64
66
|
setVisible(false);
|
67
|
+
apiPromiseToEmpty?.();
|
65
68
|
props.onClose?.();
|
66
|
-
}, children: [_jsx("div", { style: { fontSize: 14, color: '#666' }, children: t('alreadySend', lang, { phone: mobile }) }), _jsxs("div", { style: { display: 'flex', alignItems: 'center', gap: 8, marginTop: 12 }, children: [_jsx(Input.OTP, { length: 6, value: otp, onChange: (val) => {
|
69
|
+
}, children: [_jsx("div", { style: { fontSize: 14, color: '#666' }, children: t('alreadySend', lang, { phone: mobile }) }), _jsxs("div", { style: { display: 'flex', alignItems: 'center', gap: 8, marginTop: 12 }, children: [_jsx(Input.OTP, { length: 6, value: otp, onChange: async (val) => {
|
67
70
|
setOtp(val);
|
68
|
-
console.log('打印Content-Type', config.headers['Content-Type']);
|
69
71
|
if (val.length === 6) {
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
72
|
+
try {
|
73
|
+
const res = await Promise.race([
|
74
|
+
new Promise((resolve, reject) => {
|
75
|
+
setTimeout(() => {
|
76
|
+
reject(new Error('Timeout'));
|
77
|
+
}, 1000);
|
78
|
+
}),
|
79
|
+
new Promise((resolve, reject) => {
|
80
|
+
http({
|
81
|
+
...config,
|
82
|
+
headers: {
|
83
|
+
...http.defaults.headers.common,
|
84
|
+
'sms-code': val,
|
85
|
+
'sms-code-key': verifyCodeKey,
|
86
|
+
'Content-Type': config.headers['Content-Type'],
|
87
|
+
}
|
88
|
+
}).then(res => {
|
89
|
+
resolve(res);
|
90
|
+
}).catch(err => {
|
91
|
+
reject(err);
|
92
|
+
});
|
93
|
+
})
|
94
|
+
]);
|
95
|
+
if (res?.data?.status?.code === 0) {
|
96
|
+
apiResolve(res);
|
97
|
+
setVisible(false);
|
77
98
|
}
|
78
|
-
|
79
|
-
|
99
|
+
else {
|
100
|
+
message.error('验证失败');
|
101
|
+
setOtp('');
|
102
|
+
}
|
103
|
+
}
|
104
|
+
catch (error) {
|
105
|
+
console.warn('catch', error);
|
106
|
+
message.error('验证失败');
|
107
|
+
setOtp('');
|
108
|
+
}
|
80
109
|
}
|
81
110
|
} }), _jsx(Button, { disabled: countdown > 0 || !captchCode, onClick: handleResend, style: { padding: '8px' }, children: countdown > 0 ? t('countDownSecound', lang, { countdown }) : t('reSend', lang) })] }), countdown > 0 ? null :
|
82
111
|
_jsxs("div", { style: { marginTop: 12, display: 'flex', alignItems: 'center' }, children: [_jsx(Input, { placeholder: t('pleaseEnterPicVerifyCode', lang), onChange: (e) => {
|
83
112
|
setCaptchCode(e);
|
84
|
-
}, style: { width: 300 } }), captchaImage && _jsx("img", { src: captchaImage, alt: t('verifyCode', lang), style: { width: 100, height: 30, marginLeft: 8 }, onClick: getKey })] }), (countdown > 0 || captchCode) ? null : _jsx("div", { style: { fontSize: 14, color: 'red' }, children: t('pleaseEnterAndSend', lang) })] }));
|
113
|
+
}, style: { width: 300 } }), captchaImage && _jsx("img", { src: captchaImage, alt: t('verifyCode', lang), style: { width: 100, height: 30, marginLeft: 8 }, onClick: getKey })] }), (countdown > 0 || captchCode) ? null : _jsx("div", { style: { fontSize: 14, color: 'red' }, children: t('pleaseEnterAndSend', lang) }), _jsx("div", { style: { fontSize: 14, color: '#666', marginTop: 12 }, children: t('chidoriOpenPro', lang) })] }));
|
85
114
|
};
|
86
115
|
export default CreateMessageVerifyModal;
|
package/eslint.config.js
CHANGED
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "message-verify",
|
3
|
-
"version": "1.0.0
|
3
|
+
"version": "1.0.0",
|
4
4
|
"type": "module",
|
5
5
|
"main": "dist/index.js",
|
6
6
|
"dependencies": {
|
@@ -29,6 +29,7 @@
|
|
29
29
|
"build": "tsc -b",
|
30
30
|
"analyze": "vite build",
|
31
31
|
"lint": "eslint .",
|
32
|
-
"preview": "vite preview"
|
32
|
+
"preview": "vite preview",
|
33
|
+
"release:beta": "pnpm version prerelease --preid=beta && pnpm run build && pnpm publish"
|
33
34
|
}
|
34
35
|
}
|
package/src/index.tsx
CHANGED
@@ -1,54 +1,81 @@
|
|
1
1
|
import ReactDOM from 'react-dom/client'
|
2
|
-
import VerifyModal from './verify-modal.js'
|
2
|
+
import VerifyModal from './modal/verify-modal.js'
|
3
3
|
import Fingerprint2 from 'fingerprintjs2';
|
4
|
-
import
|
4
|
+
import ReLoginModal from './modal/relogin-modal.js';
|
5
|
+
import { VerifyModalConfig, LoginModalConfig } from './utils/type.js';
|
5
6
|
|
6
|
-
let
|
7
|
+
let fingerprintPromise: Promise<string> | null = null; // 用 Promise 本身作为缓存
|
8
|
+
let modalRoot: ReactDOM.Root | null = null
|
7
9
|
export const initFingerprint = async (): Promise<string> => {
|
8
|
-
if (
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
.join('###');
|
20
|
-
const fingerprint = Fingerprint2.x64hash128(values, 31);
|
21
|
-
cachedFingerprint = fingerprint;
|
22
|
-
resolve(fingerprint);
|
10
|
+
if (!fingerprintPromise) {
|
11
|
+
fingerprintPromise = new Promise((resolve) => {
|
12
|
+
Fingerprint2.get(components => {
|
13
|
+
const includeKeys = ['userAgent', 'cpuClass', 'hardwareConcurrency', 'platform'];
|
14
|
+
const values = components
|
15
|
+
.filter(c => includeKeys.includes(c.key))
|
16
|
+
.map(c => c.value)
|
17
|
+
.join('###');
|
18
|
+
const fingerprint = Fingerprint2.x64hash128(values, 31);
|
19
|
+
resolve(fingerprint);
|
20
|
+
});
|
23
21
|
});
|
24
|
-
}
|
22
|
+
}
|
23
|
+
return fingerprintPromise;
|
25
24
|
};
|
26
25
|
|
27
|
-
|
26
|
+
const destroyModal = (modalId: string) => {
|
27
|
+
if (modalRoot) {
|
28
|
+
modalRoot.unmount()
|
29
|
+
document.getElementById(modalId)?.remove()
|
30
|
+
modalRoot = null
|
31
|
+
}
|
32
|
+
}
|
28
33
|
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
34
|
+
const creatModal = (modalProps: VerifyModalConfig | LoginModalConfig, modalId: string, ModalDom:any) => {
|
35
|
+
destroyModal(modalId);
|
36
|
+
const container = document.createElement('div')
|
37
|
+
container.id = modalId
|
38
|
+
document.body.appendChild(container)
|
33
39
|
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
)
|
40
|
+
modalRoot = ReactDOM.createRoot(container)
|
41
|
+
modalRoot.render(
|
42
|
+
<ModalDom
|
43
|
+
props={{
|
44
|
+
...modalProps,
|
45
|
+
onClose: () => {
|
46
|
+
destroyModal(modalId);
|
47
|
+
}
|
48
|
+
}}
|
49
|
+
/>
|
50
|
+
)
|
46
51
|
}
|
47
52
|
|
48
|
-
const
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
53
|
+
const createMessageVerifyModal = (modalProps: VerifyModalConfig) => {
|
54
|
+
const verifyModalId = 'verify-modal-container';
|
55
|
+
creatModal(modalProps, verifyModalId, VerifyModal);
|
56
|
+
}
|
57
|
+
// 新增 relogin 弹窗创建方法
|
58
|
+
export const createReLoginModal = (modalProps: LoginModalConfig) => {
|
59
|
+
const reLoginModalId = 'relogin-modal-container';
|
60
|
+
creatModal(modalProps, reLoginModalId, ReLoginModal);
|
61
|
+
}
|
62
|
+
|
63
|
+
export const VerifyHandler = ({data, config, http, verifyPromise, sendApi}: VerifyModalConfig): Promise<any> => {
|
64
|
+
const toEmpty = () => {
|
65
|
+
verifyPromise.current = null;
|
66
|
+
};
|
67
|
+
if (!verifyPromise.current) {
|
68
|
+
verifyPromise.current = new Promise((resolve, reject) => {
|
69
|
+
createMessageVerifyModal({
|
70
|
+
data,
|
71
|
+
config,
|
72
|
+
http,
|
73
|
+
apiResolve: resolve,
|
74
|
+
apiReject: reject,
|
75
|
+
apiPromiseToEmpty: toEmpty,
|
76
|
+
sendApi
|
77
|
+
} as VerifyModalConfig);
|
78
|
+
}).finally(toEmpty);
|
79
|
+
}
|
80
|
+
return verifyPromise.current;
|
81
|
+
};
|
package/src/locales/en.ts
CHANGED
@@ -6,5 +6,10 @@ export default {
|
|
6
6
|
sendSuccess: 'Successfully sent',
|
7
7
|
sendFailed: 'Send failed',
|
8
8
|
reSend: 'Resend',
|
9
|
-
countDownSecound: '{countdown} seconds'
|
9
|
+
countDownSecound: '{countdown} seconds',
|
10
|
+
accountAlert: 'Account Security Alert',
|
11
|
+
alertContent: 'Changes have been detected in your login environment or network information.To ensure account security, please log in again to verify your identity.',
|
12
|
+
ok: 'OK',
|
13
|
+
chidoriOpenPro: 'Chidori has activated security protection for you',
|
14
|
+
verifyFail: 'Validation failed'
|
10
15
|
};
|
package/src/locales/id.ts
CHANGED
@@ -6,5 +6,10 @@ export default {
|
|
6
6
|
sendSuccess: 'Berhasil dikirim',
|
7
7
|
sendFailed: 'Gagal mengirim',
|
8
8
|
reSend: 'Kirim Ulang',
|
9
|
-
countDownSecound: '{countdown} detik'
|
9
|
+
countDownSecound: '{countdown} detik',
|
10
|
+
accountAlert: 'Peringatan Keamanan Akun',
|
11
|
+
alertContent: 'Terdeteksi perubahan pada lingkungan login atau informasi jaringan Anda.Untuk menjaga keamanan akun, silakan login kembali untuk memverifikasi identitas Anda.',
|
12
|
+
ok: 'Baiklah',
|
13
|
+
chidoriOpenPro: 'chidori telah mengaktifkan keamanan untuk Anda',
|
14
|
+
verifyFail: 'Autentikasi gagal'
|
10
15
|
};
|
package/src/locales/zh.ts
CHANGED
@@ -6,5 +6,10 @@ export default {
|
|
6
6
|
sendSuccess: '发送成功',
|
7
7
|
sendFailed: '发送失败',
|
8
8
|
reSend: '重新发送',
|
9
|
-
countDownSecound: '{countdown}秒'
|
9
|
+
countDownSecound: '{countdown}秒',
|
10
|
+
accountAlert: '账号安全提醒',
|
11
|
+
alertContent: '检测到您的登录环境或网络信息有变动,为保障账户安全,请重新登录验证身份',
|
12
|
+
ok: '好的',
|
13
|
+
chidoriOpenPro: 'chidori已为您开启安全防护',
|
14
|
+
verifyFail: '验证失败'
|
10
15
|
};
|
package/src/main.tsx
CHANGED
@@ -1,18 +1,58 @@
|
|
1
1
|
import { createRoot } from 'react-dom/client';
|
2
|
-
import {
|
2
|
+
import { initFingerprint, createReLoginModal, VerifyHandler } from './index.js'; // 或 './index'
|
3
3
|
import { axios } from '@yqg/resource';
|
4
4
|
|
5
5
|
const data = "{\"mobile\":\"188****4035\",\"verifyCodeKey\":\"3f025b33-988e-47c0-950d-6beb776d043f\",\"needValid\":true,\"step\":2,\"message\":\"需要填写验证码\"}";
|
6
6
|
|
7
7
|
const fp = await initFingerprint();
|
8
|
-
|
8
|
+
const fp2 = await initFingerprint();
|
9
|
+
console.log(fp, fp2);
|
9
10
|
|
11
|
+
const config = {
|
12
|
+
"transitional": {
|
13
|
+
"silentJSONParsing": true,
|
14
|
+
"forcedJSONParsing": true,
|
15
|
+
"clarifyTimeoutError": false
|
16
|
+
},
|
17
|
+
"timeout": 0,
|
18
|
+
"xsrfCookieName": "XSRF-TOKEN",
|
19
|
+
"xsrfHeaderName": "X-XSRF-TOKEN",
|
20
|
+
"maxContentLength": -1,
|
21
|
+
"maxBodyLength": -1,
|
22
|
+
"headers": {
|
23
|
+
"Accept": "application/json, text/plain, */*",
|
24
|
+
"X-Device-Fingerprint": "531f14c7176b16ebeb18e2b23d6bd124",
|
25
|
+
"Content-Type": "application/json"
|
26
|
+
},
|
27
|
+
"url": "/classification/admin/level/edit",
|
28
|
+
"method": "post",
|
29
|
+
"dataFormat": "JSON",
|
30
|
+
"showRequestData": true,
|
31
|
+
"showResponseData": false,
|
32
|
+
"showGeneralResponseData": true,
|
33
|
+
"headersList": [],
|
34
|
+
"requestDataFunc": "\nfunction(formFilterData){\n // 这里写你的处理逻辑\n return {\n ...formFilterData,\n 'classificationLevel': 2 //等级\n }\n}\n",
|
35
|
+
"responseDataFunc": "",
|
36
|
+
"responseGeneralDataFunc": "function(req, { data, util, window }) {\n return req\n .then((response) => {\n return Promise.resolve({\n status: {\n code: 0,\n }\n })\n })\n .catch((error) => {\n // 检查是否有响应数据\n if (error.response && error.response.data) {\n const responseData = error.response.data;\n const detail = responseData.body?.status?.detail || responseData.status?.detail;\n if (detail) {\n util.message.error(detail);\n } else {\n util.message.error('编辑失败,请重试');\n }\n } else {\n util.message.error('编辑失败,请重试');\n }\n console.error('Error during deletion:', error);\n });\n}",
|
37
|
+
"formInstance": {},
|
38
|
+
"data": "{\"id\":1,\"classificationName\":\"个人基本概况信息\",\"classificationLevel\":2}",
|
39
|
+
"baseURL": "http://localhost:62888"
|
40
|
+
}
|
41
|
+
|
42
|
+
const promise = {current: null};
|
10
43
|
createRoot(document.getElementById('root')!).render(
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
44
|
+
<>
|
45
|
+
<button onClick={() => {
|
46
|
+
return VerifyHandler({data, config, http: axios, verifyPromise: promise});
|
47
|
+
}}>
|
48
|
+
Show verify Modal
|
49
|
+
</button>
|
50
|
+
<button onClick={() => createReLoginModal({
|
51
|
+
goLogin: () => {
|
52
|
+
console.log('goLogin');
|
53
|
+
},
|
54
|
+
lang: 'zh',
|
55
|
+
})}>
|
56
|
+
Show login Modal
|
57
|
+
</button>
|
58
|
+
</>);
|
@@ -0,0 +1,43 @@
|
|
1
|
+
import { useState } from 'react'
|
2
|
+
import { Modal, Button } from '../compoments/index.js'
|
3
|
+
import { LoginModalConfig } from '../utils/type.js';
|
4
|
+
import t from '../utils/i18n.js'
|
5
|
+
|
6
|
+
const ReLoginModal = ({ props }: { props: LoginModalConfig }) => {
|
7
|
+
const { goLogin, lang, onClose: destroyModal } = props || {};
|
8
|
+
const [visible, setVisible] = useState(true);
|
9
|
+
const onClose = () => {
|
10
|
+
setVisible(false);
|
11
|
+
goLogin();
|
12
|
+
destroyModal?.();
|
13
|
+
};
|
14
|
+
return (
|
15
|
+
<Modal visible={visible} onClose={onClose} width={420}>
|
16
|
+
<div style={{ fontWeight: 500, fontSize: 20, marginBottom: 24 }}>
|
17
|
+
{t('accountAlert', lang)}
|
18
|
+
</div>
|
19
|
+
<div style={{ color: '#222', fontSize: 16, marginBottom: 40, lineHeight: '24px' }}>
|
20
|
+
{t('alertContent', lang)}
|
21
|
+
</div>
|
22
|
+
<div style={{ display: 'flex', justifyContent: 'center' }}>
|
23
|
+
<Button
|
24
|
+
style={{
|
25
|
+
background: '#1677ff',
|
26
|
+
color: '#fff',
|
27
|
+
border: 'none',
|
28
|
+
width: 80,
|
29
|
+
height: 36,
|
30
|
+
fontSize: 14,
|
31
|
+
borderRadius: 8,
|
32
|
+
boxShadow: '0 2px 8px rgba(22,119,255,0.08)',
|
33
|
+
}}
|
34
|
+
onClick={onClose}
|
35
|
+
>
|
36
|
+
{t('ok', lang)}
|
37
|
+
</Button>
|
38
|
+
</div>
|
39
|
+
</Modal>
|
40
|
+
);
|
41
|
+
};
|
42
|
+
|
43
|
+
export default ReLoginModal;
|
@@ -1,18 +1,18 @@
|
|
1
1
|
import { useEffect, useState } from 'react'
|
2
|
-
import { Modal, Input, Button, message } from '
|
3
|
-
import Api from '
|
4
|
-
import t from '
|
5
|
-
import {
|
6
|
-
import { axios
|
2
|
+
import { Modal, Input, Button, message } from '../compoments/index.js'
|
3
|
+
import Api from '../utils/resource.js'
|
4
|
+
import t from '../utils/i18n.js'
|
5
|
+
import { VerifyModalConfig } from '../utils/type.js';
|
6
|
+
import { axios } from '@yqg/resource';
|
7
7
|
|
8
|
-
const CreateMessageVerifyModal = ({ props }: { props:
|
8
|
+
const CreateMessageVerifyModal = ({ props }: { props: VerifyModalConfig }) => {
|
9
9
|
const [visible, setVisible] = useState(true);
|
10
|
-
const [countdown, setCountdown] = useState(
|
10
|
+
const [countdown, setCountdown] = useState(60);
|
11
11
|
const [otp, setOtp] = useState('');
|
12
12
|
const [captchaImage, setCaptchaImage] = useState<string>('');
|
13
13
|
const [captchCode, setCaptchCode] = useState<string>('');
|
14
14
|
const [captchaKey, setCaptchaKey] = useState<string>('');
|
15
|
-
const { data,
|
15
|
+
const { data, http, lang, sendApi = '/admin/sms/send', config, apiResolve, apiPromiseToEmpty, onClose } = props || {};
|
16
16
|
const dataObj = JSON.parse(data || '{}');
|
17
17
|
const { mobile, verifyCodeKey } = dataObj || {};
|
18
18
|
|
@@ -25,10 +25,11 @@ const CreateMessageVerifyModal = ({ props }: { props: ModalConfig }) => {
|
|
25
25
|
const image = Api.getCaptchaImgUrl(key) as unknown;
|
26
26
|
setCaptchaImage(image as string);
|
27
27
|
}
|
28
|
-
} catch (err) {
|
29
|
-
|
30
|
-
|
31
|
-
|
28
|
+
} catch (err) {
|
29
|
+
const msg =
|
30
|
+
typeof err === 'object' && err !== null && 'message' in err
|
31
|
+
? (err as { message: string }).message
|
32
|
+
: String(err);
|
32
33
|
message.error(msg as React.ReactNode);
|
33
34
|
}
|
34
35
|
}
|
@@ -53,14 +54,16 @@ const CreateMessageVerifyModal = ({ props }: { props: ModalConfig }) => {
|
|
53
54
|
formData.append('captchaKey', captchaKey);
|
54
55
|
formData.append('captcha', captchCode);
|
55
56
|
// 重新发送验证码
|
56
|
-
const res = await axios.post(
|
57
|
+
const res = await axios.post(sendApi, formData);
|
57
58
|
const { code, detail } = res.data?.status || {};
|
58
59
|
if (code !== 0) {
|
59
60
|
message.error(detail || t('sendFailed', lang));
|
60
61
|
return;
|
61
62
|
}
|
62
63
|
message.success(t('sendSuccess', lang));
|
64
|
+
// 重置倒计时、验证码
|
63
65
|
setCountdown(60);
|
66
|
+
setOtp('');
|
64
67
|
}
|
65
68
|
|
66
69
|
return (
|
@@ -69,7 +72,8 @@ const CreateMessageVerifyModal = ({ props }: { props: ModalConfig }) => {
|
|
69
72
|
visible={visible}
|
70
73
|
onClose={() => {
|
71
74
|
setVisible(false);
|
72
|
-
|
75
|
+
apiPromiseToEmpty?.();
|
76
|
+
onClose?.();
|
73
77
|
}}
|
74
78
|
>
|
75
79
|
<div style={{ fontSize: 14, color: '#666' }}>{t('alreadySend', lang, { phone: mobile })}</div>
|
@@ -78,20 +82,44 @@ const CreateMessageVerifyModal = ({ props }: { props: ModalConfig }) => {
|
|
78
82
|
<Input.OTP
|
79
83
|
length={6}
|
80
84
|
value={otp}
|
81
|
-
onChange={(val) => {
|
85
|
+
onChange={async (val) => {
|
82
86
|
setOtp(val);
|
83
|
-
console.log('打印Content-Type', config.headers['Content-Type'])
|
84
87
|
if (val.length === 6) {
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
88
|
+
try {
|
89
|
+
const res = await Promise.race([
|
90
|
+
new Promise((resolve, reject) => {
|
91
|
+
setTimeout(() => {
|
92
|
+
reject(new Error('Timeout'));
|
93
|
+
}, 1000);
|
94
|
+
}),
|
95
|
+
new Promise((resolve, reject) => {
|
96
|
+
http({
|
97
|
+
...config,
|
98
|
+
headers: {
|
99
|
+
...http.defaults.headers.common,
|
100
|
+
'sms-code': val,
|
101
|
+
'sms-code-key': verifyCodeKey,
|
102
|
+
'Content-Type': config.headers['Content-Type'],
|
103
|
+
}
|
104
|
+
}).then(res => {
|
105
|
+
resolve(res);
|
106
|
+
}).catch(err => {
|
107
|
+
reject(err);
|
108
|
+
})
|
109
|
+
})
|
110
|
+
]) as any;
|
111
|
+
if (res?.data?.status?.code === 0) {
|
112
|
+
apiResolve(res);
|
113
|
+
setVisible(false);
|
114
|
+
} else {
|
115
|
+
message.error(t('verifyFail', lang));
|
116
|
+
setOtp('');
|
92
117
|
}
|
93
|
-
})
|
94
|
-
|
118
|
+
} catch (error) {
|
119
|
+
console.warn('catch=>error', error);
|
120
|
+
message.error(t('verifyFail', lang));
|
121
|
+
setOtp('');
|
122
|
+
}
|
95
123
|
}
|
96
124
|
}} />
|
97
125
|
<Button
|
@@ -115,6 +143,7 @@ const CreateMessageVerifyModal = ({ props }: { props: ModalConfig }) => {
|
|
115
143
|
{captchaImage && <img src={captchaImage} alt={t('verifyCode', lang)} style={{ width: 100, height: 30, marginLeft: 8 }} onClick={getKey} />}
|
116
144
|
</div>}
|
117
145
|
{(countdown > 0 || captchCode) ? null : <div style={{ fontSize: 14, color: 'red' }}>{t('pleaseEnterAndSend', lang)}</div>}
|
146
|
+
<div style={{ fontSize: 14, color: '#666', marginTop: 12 }}>{t('chidoriOpenPro', lang)}</div>
|
118
147
|
</Modal>
|
119
148
|
);
|
120
149
|
};
|
package/src/utils/type.ts
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
|
2
|
-
export type
|
2
|
+
export type VerifyModalConfig = {
|
3
3
|
data: string;
|
4
4
|
onClose?: () => void
|
5
5
|
config: {
|
@@ -8,7 +8,7 @@ export type ModalConfig = {
|
|
8
8
|
};
|
9
9
|
[key: string]: unknown;
|
10
10
|
};
|
11
|
-
lang
|
11
|
+
lang?: 'zh' | 'en' | 'id';
|
12
12
|
http: {
|
13
13
|
(params: object): Promise<unknown>;
|
14
14
|
defaults: {
|
@@ -19,5 +19,15 @@ export type ModalConfig = {
|
|
19
19
|
}
|
20
20
|
}
|
21
21
|
};
|
22
|
-
|
22
|
+
sendApi?: string;
|
23
|
+
apiReject?: any;
|
24
|
+
apiResolve?: any;
|
25
|
+
apiPromiseToEmpty?: () => void;
|
26
|
+
verifyPromise: {current: Promise<any> | null}
|
27
|
+
}
|
28
|
+
|
29
|
+
export type LoginModalConfig = {
|
30
|
+
goLogin: () => void;
|
31
|
+
onClose?: () => void
|
32
|
+
lang?: 'zh' | 'en' | 'id';
|
23
33
|
}
|
File without changes
|