component-sanzhizhou 1.2.0 → 1.2.1

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.
@@ -7,6 +7,6 @@ interface Props {
7
7
  accountRegDisabled?: boolean;
8
8
  onSuccess: () => void;
9
9
  }
10
- /** 账户登录 / 注册 / 找回密码 切换。 */
10
+ /** 账户登录 / 注册;找回密码通过抽屉弹出。 */
11
11
  declare const Account: React.FC<Props>;
12
12
  export default Account;
@@ -1,13 +1,13 @@
1
1
  import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
2
2
  import React, { useState } from 'react';
3
- import { Radio } from 'antd';
4
- import { UserOutlined, UserAddOutlined, UnlockOutlined } from '@ant-design/icons';
3
+ import { Radio, Drawer } from 'antd';
4
+ import { UserOutlined, UserAddOutlined } from '@ant-design/icons';
5
5
  import formatMessage from "../lib/formatMessage";
6
6
  import Login from "./login";
7
7
  import Register from "./register";
8
8
  import ForgotPassword from "./forgot-password";
9
- import styles from "./index.css";
10
- /** 账户登录 / 注册 / 找回密码 切换。 */
9
+ import styles from "./index.module.less";
10
+ /** 账户登录 / 注册;找回密码通过抽屉弹出。 */
11
11
  var Account = function Account(_ref) {
12
12
  var env = _ref.env,
13
13
  apiUrl = _ref.apiUrl,
@@ -15,12 +15,18 @@ var Account = function Account(_ref) {
15
15
  disabledFormItemLabel = _ref.disabledFormItemLabel,
16
16
  accountRegDisabled = _ref.accountRegDisabled,
17
17
  onSuccess = _ref.onSuccess;
18
- var _useState = useState(accountRegDisabled ? 'login' : 'login'),
18
+ var _useState = useState('login'),
19
19
  _useState2 = _slicedToArray(_useState, 2),
20
20
  activeKey = _useState2[0],
21
21
  setActiveKey = _useState2[1];
22
- return /*#__PURE__*/React.createElement(styles.Account, null, /*#__PURE__*/React.createElement("div", {
23
- className: "radioSelectBox"
22
+ var _useState3 = useState(false),
23
+ _useState4 = _slicedToArray(_useState3, 2),
24
+ forgotOpen = _useState4[0],
25
+ setForgotOpen = _useState4[1];
26
+ return /*#__PURE__*/React.createElement("div", {
27
+ className: styles.Account
28
+ }, /*#__PURE__*/React.createElement("div", {
29
+ className: styles.radioSelectBox
24
30
  }, /*#__PURE__*/React.createElement(Radio.Group, {
25
31
  value: activeKey,
26
32
  onChange: function onChange(e) {
@@ -31,27 +37,35 @@ var Account = function Account(_ref) {
31
37
  }, /*#__PURE__*/React.createElement(UserOutlined, null), " ", formatMessage('登录')), /*#__PURE__*/React.createElement(Radio.Button, {
32
38
  value: "reg",
33
39
  disabled: accountRegDisabled
34
- }, /*#__PURE__*/React.createElement(UserAddOutlined, null), " ", formatMessage('注册')), /*#__PURE__*/React.createElement(Radio.Button, {
35
- value: "forgot"
36
- }, /*#__PURE__*/React.createElement(UnlockOutlined, null), " ", formatMessage('忘记密码')))), activeKey === 'login' && /*#__PURE__*/React.createElement(Login, {
40
+ }, /*#__PURE__*/React.createElement(UserAddOutlined, null), " ", formatMessage('注册')))), activeKey === 'login' && /*#__PURE__*/React.createElement(Login, {
37
41
  env: env,
38
42
  apiUrl: apiUrl,
39
43
  roleType: roleType,
40
44
  disabledFormItemLabel: disabledFormItemLabel,
41
- onSuccess: onSuccess
45
+ onSuccess: onSuccess,
46
+ onForgotPassword: function onForgotPassword() {
47
+ return setForgotOpen(true);
48
+ }
42
49
  }), activeKey === 'reg' && /*#__PURE__*/React.createElement(Register, {
43
50
  env: env,
44
51
  apiUrl: apiUrl,
45
52
  roleType: roleType,
46
53
  disabledFormItemLabel: disabledFormItemLabel,
47
54
  onSuccess: onSuccess
48
- }), activeKey === 'forgot' && /*#__PURE__*/React.createElement(ForgotPassword, {
55
+ }), /*#__PURE__*/React.createElement(Drawer, {
56
+ title: formatMessage('找回密码'),
57
+ open: forgotOpen,
58
+ onClose: function onClose() {
59
+ return setForgotOpen(false);
60
+ },
61
+ size: 620
62
+ }, /*#__PURE__*/React.createElement(ForgotPassword, {
49
63
  env: env,
50
64
  apiUrl: apiUrl,
51
65
  disabledFormItemLabel: disabledFormItemLabel,
52
66
  onDone: function onDone() {
53
- return setActiveKey('login');
67
+ return setForgotOpen(false);
54
68
  }
55
- }));
69
+ })));
56
70
  };
57
71
  export default Account;
@@ -7,6 +7,8 @@ import Tool from "../lib/Tool";
7
7
  import * as AuthController from "../service/api/AuthController";
8
8
  import formatMessage from "../lib/formatMessage";
9
9
  import PhoneCode from "./phone-code";
10
+ var FormSpan = 6;
11
+
10
12
  /** 找回密码:短信验证码 + 新密码。 */
11
13
  var ForgotPassword = function ForgotPassword(_ref) {
12
14
  var env = _ref.env,
@@ -38,18 +40,16 @@ var ForgotPassword = function ForgotPassword(_ref) {
38
40
  values.accountName = (values.accountName || '').replace(/\s+/g, '');
39
41
  run(values);
40
42
  };
41
- return /*#__PURE__*/React.createElement("section", {
42
- className: "authMainForgot"
43
- }, /*#__PURE__*/React.createElement(Form, {
43
+ return /*#__PURE__*/React.createElement("section", null, /*#__PURE__*/React.createElement(Form, {
44
44
  form: form,
45
45
  onFinish: onFinish,
46
46
  disabled: loading,
47
- autoComplete: "off"
47
+ autoComplete: "off",
48
+ labelCol: {
49
+ span: FormSpan
50
+ }
48
51
  }, /*#__PURE__*/React.createElement(Form.Item, {
49
52
  label: disabledFormItemLabel ? undefined : formatMessage('手机号码'),
50
- labelCol: {
51
- span: 8
52
- },
53
53
  name: "accountName",
54
54
  rules: [{
55
55
  required: true,
@@ -64,6 +64,7 @@ var ForgotPassword = function ForgotPassword(_ref) {
64
64
  className: "input-prefix-icon"
65
65
  })
66
66
  })), /*#__PURE__*/React.createElement(PhoneCode, {
67
+ formSpan: FormSpan,
67
68
  form: form,
68
69
  scene: "forgot",
69
70
  env: env,
@@ -71,9 +72,6 @@ var ForgotPassword = function ForgotPassword(_ref) {
71
72
  disabledFormItemLabel: disabledFormItemLabel
72
73
  }), /*#__PURE__*/React.createElement(Form.Item, {
73
74
  label: disabledFormItemLabel ? undefined : formatMessage('新密码'),
74
- labelCol: {
75
- span: 8
76
- },
77
75
  name: "password",
78
76
  rules: [{
79
77
  required: true,
@@ -97,8 +95,10 @@ var ForgotPassword = function ForgotPassword(_ref) {
97
95
  iconRender: function iconRender(visible) {
98
96
  return visible ? /*#__PURE__*/React.createElement(EyeTwoTone, null) : /*#__PURE__*/React.createElement(EyeInvisibleOutlined, null);
99
97
  }
100
- })), /*#__PURE__*/React.createElement("div", {
101
- className: "auth-submits"
98
+ })), /*#__PURE__*/React.createElement(Form.Item, {
99
+ wrapperCol: {
100
+ offset: 6
101
+ }
102
102
  }, /*#__PURE__*/React.createElement(Button, {
103
103
  type: "primary",
104
104
  loading: loading,
@@ -0,0 +1,12 @@
1
+ import React from 'react';
2
+ import type { SmsScene } from './types';
3
+ interface Props {
4
+ phone: string;
5
+ scene: SmsScene;
6
+ env?: Global.Env;
7
+ apiUrl?: string;
8
+ onVerified: (challenge: string, nonce: string) => void;
9
+ }
10
+ /** 人机验证(工作量证明):点击后后台计算,通过后变绿。 */
11
+ declare const HumanVerify: React.FC<Props>;
12
+ export default HumanVerify;
@@ -0,0 +1,89 @@
1
+ import _regeneratorRuntime from "@babel/runtime/helpers/esm/regeneratorRuntime";
2
+ import _asyncToGenerator from "@babel/runtime/helpers/esm/asyncToGenerator";
3
+ import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
4
+ import React, { useState } from 'react';
5
+ import { Spin } from 'antd';
6
+ import { SafetyCertificateOutlined, CheckCircleFilled, LoadingOutlined } from '@ant-design/icons';
7
+ import Tool from "../lib/Tool";
8
+ import formatMessage from "../lib/formatMessage";
9
+ import * as AuthController from "../service/api/AuthController";
10
+ import { solvePow } from "./pow";
11
+ import styles from "./index.module.less";
12
+ var phoneReg = /^1\d{10}$/;
13
+ /** 人机验证(工作量证明):点击后后台计算,通过后变绿。 */
14
+ var HumanVerify = function HumanVerify(_ref) {
15
+ var phone = _ref.phone,
16
+ scene = _ref.scene,
17
+ env = _ref.env,
18
+ apiUrl = _ref.apiUrl,
19
+ onVerified = _ref.onVerified;
20
+ var _useState = useState('idle'),
21
+ _useState2 = _slicedToArray(_useState, 2),
22
+ status = _useState2[0],
23
+ setStatus = _useState2[1];
24
+ var onVerify = /*#__PURE__*/function () {
25
+ var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
26
+ var challengeData, _nonce;
27
+ return _regeneratorRuntime().wrap(function _callee$(_context) {
28
+ while (1) switch (_context.prev = _context.next) {
29
+ case 0:
30
+ if (!(status !== 'idle')) {
31
+ _context.next = 2;
32
+ break;
33
+ }
34
+ return _context.abrupt("return");
35
+ case 2:
36
+ if (phoneReg.test(phone)) {
37
+ _context.next = 5;
38
+ break;
39
+ }
40
+ Tool.toastError(formatMessage('请输入正确的手机号码'));
41
+ return _context.abrupt("return");
42
+ case 5:
43
+ setStatus('verifying');
44
+ _context.prev = 6;
45
+ _context.next = 9;
46
+ return AuthController.powChallenge({
47
+ accountName: phone,
48
+ scene: scene
49
+ }, {
50
+ env: env,
51
+ apiUrl: apiUrl
52
+ });
53
+ case 9:
54
+ challengeData = _context.sent;
55
+ _context.next = 12;
56
+ return solvePow(challengeData.challenge, challengeData.difficulty);
57
+ case 12:
58
+ _nonce = _context.sent;
59
+ setStatus('verified');
60
+ onVerified(challengeData.challenge, _nonce);
61
+ _context.next = 20;
62
+ break;
63
+ case 17:
64
+ _context.prev = 17;
65
+ _context.t0 = _context["catch"](6);
66
+ // 错误已由 request 层 toast
67
+ setStatus('idle');
68
+ case 20:
69
+ case "end":
70
+ return _context.stop();
71
+ }
72
+ }, _callee, null, [[6, 17]]);
73
+ }));
74
+ return function onVerify() {
75
+ return _ref2.apply(this, arguments);
76
+ };
77
+ }();
78
+ return /*#__PURE__*/React.createElement("div", {
79
+ className: "".concat(styles.humanVerify, " ").concat(status === 'verified' ? styles.humanVerifyOk : ''),
80
+ onClick: onVerify
81
+ }, /*#__PURE__*/React.createElement("span", {
82
+ className: styles.humanVerifyIcon
83
+ }, status === 'verified' ? /*#__PURE__*/React.createElement(CheckCircleFilled, null) : status === 'verifying' ? /*#__PURE__*/React.createElement(LoadingOutlined, null) : /*#__PURE__*/React.createElement(SafetyCertificateOutlined, null)), /*#__PURE__*/React.createElement("span", {
84
+ className: styles.humanVerifyText
85
+ }, status === 'verifying' ? "".concat(formatMessage('人机校验中'), "...") : status === 'verified' ? formatMessage('验证通过') : formatMessage('我不是机器人')), status === 'verifying' && /*#__PURE__*/React.createElement(Spin, {
86
+ size: "small"
87
+ }));
88
+ };
89
+ export default HumanVerify;
@@ -8,7 +8,7 @@ import formatMessage from "../lib/formatMessage";
8
8
  import h5WePublicLogin from "../AuthClient/qr/h5-we-public-login";
9
9
  import WechatQr from "./wechat-qr";
10
10
  import Account from "./account";
11
- import styles from "./index.css";
11
+ import styles from "./index.module.less";
12
12
  /**
13
13
  * 登录 / 注册(重构版)。
14
14
  * - 微信扫码:逻辑与旧 Auth 保持一致(WechatQr)。
@@ -18,7 +18,8 @@ var Auth = function Auth(_ref) {
18
18
  var productType = _ref.productType,
19
19
  apiUrl = _ref.apiUrl,
20
20
  clientUniqueKeyList = _ref.clientUniqueKeyList,
21
- loginTypeList = _ref.loginTypeList,
21
+ _ref$loginTypeList = _ref.loginTypeList,
22
+ loginTypeList = _ref$loginTypeList === void 0 ? [] : _ref$loginTypeList,
22
23
  env = _ref.env,
23
24
  postData = _ref.postData,
24
25
  roleType = _ref.roleType,
@@ -55,8 +56,12 @@ var Auth = function Auth(_ref) {
55
56
  }
56
57
  // eslint-disable-next-line react-hooks/exhaustive-deps
57
58
  }, []);
58
- return /*#__PURE__*/React.createElement(styles.AuthQrLogin, null, /*#__PURE__*/React.createElement(styles.LoginForm, null, /*#__PURE__*/React.createElement("div", {
59
- className: "ssz-webTitle"
59
+ return /*#__PURE__*/React.createElement("div", {
60
+ className: styles.AuthQrLogin
61
+ }, /*#__PURE__*/React.createElement("div", {
62
+ className: styles.LoginForm
63
+ }, /*#__PURE__*/React.createElement("div", {
64
+ className: styles.sszWebTitle
60
65
  }, formatMessage('登录/注册')), /*#__PURE__*/React.createElement(Tabs, {
61
66
  activeKey: activeKey,
62
67
  onChange: onTabChange
@@ -67,9 +72,7 @@ var Auth = function Auth(_ref) {
67
72
  domain: domain,
68
73
  onLoginSuccess: onLoginSuccess
69
74
  })), /*#__PURE__*/React.createElement(Tabs.TabPane, {
70
- tab: /*#__PURE__*/React.createElement("span", {
71
- className: "tab-icon"
72
- }, /*#__PURE__*/React.createElement(UserOutlined, null), " ", formatMessage('账户')),
75
+ tab: /*#__PURE__*/React.createElement("span", null, /*#__PURE__*/React.createElement(UserOutlined, null), " ", formatMessage('账户')),
73
76
  disabled: !hasAccount,
74
77
  key: "account"
75
78
  }, /*#__PURE__*/React.createElement(Account, {
@@ -82,10 +85,10 @@ var Auth = function Auth(_ref) {
82
85
  return onLoginSuccess();
83
86
  }
84
87
  })))), /*#__PURE__*/React.createElement("div", {
85
- className: "callWechat",
88
+ className: styles.callWechat,
86
89
  onClick: onCallWechat
87
90
  }), /*#__PURE__*/React.createElement("div", {
88
- className: "callAccount",
91
+ className: styles.callAccount,
89
92
  onClick: onCallAccount
90
93
  }));
91
94
  };
@@ -0,0 +1,178 @@
1
+ .AuthQrLogin {
2
+ position: relative;
3
+
4
+ :global(.ant-tabs-tab-btn .anticon) {
5
+ margin-right: 6px;
6
+ }
7
+
8
+ .weQrUrl {
9
+ position: absolute;
10
+ left: 50%;
11
+ transform: translateX(-50%);
12
+ }
13
+
14
+ .qr {
15
+ position: relative;
16
+ display: block;
17
+ margin: 12px auto 0;
18
+ width: 230px;
19
+ height: 230px;
20
+ background-repeat: no-repeat;
21
+ background-size: cover;
22
+ background-position: center;
23
+
24
+ .reTry {
25
+ position: absolute;
26
+ z-index: 100;
27
+ left: 0;
28
+ top: 0;
29
+ width: 100%;
30
+ font-size: 80px;
31
+ background-color: rgba(255, 255, 255, 0.95);
32
+ text-align: center;
33
+ line-height: 210px;
34
+ height: 100%;
35
+
36
+ a {
37
+ display: block;
38
+ }
39
+ }
40
+ }
41
+
42
+ .alt {
43
+ padding: 10px 0 0;
44
+ color: #999;
45
+ text-align: center;
46
+ }
47
+
48
+ .altWeb {
49
+ padding: 16px 0 0;
50
+ max-width: 300px;
51
+ margin: 0 auto;
52
+
53
+ .titles {
54
+ text-align: center;
55
+ font-weight: bold;
56
+ }
57
+
58
+ ul {
59
+ margin: 0 10px;
60
+ }
61
+ }
62
+
63
+ .percent {
64
+ width: 100%;
65
+ position: absolute;
66
+ overflow: hidden;
67
+ left: 0;
68
+ bottom: 0;
69
+
70
+ .warp {
71
+ height: 4px;
72
+ background-color: #1677ff;
73
+ transition: all 1.6s ease-in-out;
74
+ -webkit-transition: all 1.6s ease-in-out;
75
+ }
76
+ }
77
+
78
+ .callWechat {
79
+ position: absolute;
80
+ left: 6px;
81
+ bottom: 6px;
82
+ background: #f6f6f6;
83
+ width: 4px;
84
+ height: 4px;
85
+ }
86
+
87
+ .callAccount {
88
+ position: absolute;
89
+ right: 6px;
90
+ bottom: 6px;
91
+ background: #f6f6f6;
92
+ width: 4px;
93
+ height: 4px;
94
+ }
95
+
96
+ .sszWebTitle {
97
+ font-weight: normal;
98
+ font-size: 26px;
99
+ text-align: center;
100
+ padding: 6px 0 0 0;
101
+ line-height: 1em;
102
+
103
+ span {
104
+ display: inline-block;
105
+ padding-left: 5px;
106
+ font-weight: lighter;
107
+ font-size: 16px;
108
+ }
109
+ }
110
+ }
111
+
112
+ .LoginForm {
113
+ margin: 0 auto;
114
+ padding: 12px 16px 6px 16px;
115
+ background-color: rgba(255, 255, 255, 0.9);
116
+ border-radius: 6px;
117
+ }
118
+
119
+ .WeQrUrlBox {
120
+ min-height: 240px !important;
121
+ }
122
+
123
+ .Account {
124
+ .radioSelectBox {
125
+ text-align: right;
126
+ margin-bottom: 8px;
127
+ }
128
+
129
+
130
+ .forgotLink {
131
+ padding: 6px 0 0 0;
132
+ text-align: right;
133
+ }
134
+ }
135
+
136
+ .humanVerifyItem {
137
+ margin-bottom: 12px;
138
+ }
139
+
140
+ .humanVerify {
141
+ display: flex;
142
+ align-items: center;
143
+ gap: 10px;
144
+ width: 100%;
145
+ max-width: 300px;
146
+ padding: 10px 14px;
147
+ border: 1px solid #d9d9d9;
148
+ border-radius: 6px;
149
+ background: #fafafa;
150
+ cursor: pointer;
151
+ user-select: none;
152
+ transition: all 0.2s;
153
+
154
+ &:hover {
155
+ border-color: #1677ff;
156
+ }
157
+
158
+ .humanVerifyIcon {
159
+ font-size: 20px;
160
+ line-height: 1;
161
+ color: #1677ff;
162
+ }
163
+
164
+ .humanVerifyText {
165
+ flex: 1;
166
+ font-size: 14px;
167
+ color: rgba(0, 0, 0, 0.85);
168
+ }
169
+ }
170
+
171
+ .humanVerifyOk {
172
+ border-color: #52c41a;
173
+ background: #f6ffed;
174
+
175
+ .humanVerifyIcon {
176
+ color: #52c41a;
177
+ }
178
+ }
@@ -3,6 +3,7 @@ import type { AccountFormProps } from './types';
3
3
  interface Props extends AccountFormProps {
4
4
  roleType?: UserAuth.RoleType;
5
5
  disabledFormItemLabel?: boolean;
6
+ onForgotPassword?: () => void;
6
7
  }
7
8
  /** 账户密码登录。 */
8
9
  declare const Login: React.FC<Props>;
@@ -6,13 +6,15 @@ import { useRequest } from '@umijs/hooks';
6
6
  import * as AuthController from "../service/api/AuthController";
7
7
  import formatMessage from "../lib/formatMessage";
8
8
  import { applyLoginSuccess } from "./login-success";
9
+ import styles from "./index.module.less";
9
10
  /** 账户密码登录。 */
10
11
  var Login = function Login(_ref) {
11
12
  var env = _ref.env,
12
13
  apiUrl = _ref.apiUrl,
13
14
  roleType = _ref.roleType,
14
15
  disabledFormItemLabel = _ref.disabledFormItemLabel,
15
- _onSuccess = _ref.onSuccess;
16
+ _onSuccess = _ref.onSuccess,
17
+ onForgotPassword = _ref.onForgotPassword;
16
18
  var _Form$useForm = Form.useForm(),
17
19
  _Form$useForm2 = _slicedToArray(_Form$useForm, 1),
18
20
  form = _Form$useForm2[0];
@@ -34,9 +36,7 @@ var Login = function Login(_ref) {
34
36
  values.accountName = (values.accountName || '').replace(/\s+/g, '');
35
37
  run(values);
36
38
  };
37
- return /*#__PURE__*/React.createElement("section", {
38
- className: "authMainLogin"
39
- }, /*#__PURE__*/React.createElement(Form, {
39
+ return /*#__PURE__*/React.createElement("section", null, /*#__PURE__*/React.createElement(Form, {
40
40
  form: form,
41
41
  onFinish: onFinish,
42
42
  disabled: loading,
@@ -78,7 +78,14 @@ var Login = function Login(_ref) {
78
78
  message: formatMessage('最多{maxCount}个字符', {
79
79
  maxCount: 60
80
80
  })
81
- }]
81
+ }],
82
+ extra: /*#__PURE__*/React.createElement("div", {
83
+ className: styles.forgotLink
84
+ }, /*#__PURE__*/React.createElement(Button, {
85
+ type: "link",
86
+ size: "small",
87
+ onClick: onForgotPassword
88
+ }, formatMessage('忘记密码')))
82
89
  }, /*#__PURE__*/React.createElement(Input.Password, {
83
90
  prefix: /*#__PURE__*/React.createElement(LockOutlined, {
84
91
  className: "input-prefix-icon"
@@ -87,8 +94,10 @@ var Login = function Login(_ref) {
87
94
  iconRender: function iconRender(visible) {
88
95
  return visible ? /*#__PURE__*/React.createElement(EyeTwoTone, null) : /*#__PURE__*/React.createElement(EyeInvisibleOutlined, null);
89
96
  }
90
- })), /*#__PURE__*/React.createElement("div", {
91
- className: "auth-submits"
97
+ })), /*#__PURE__*/React.createElement(Form.Item, {
98
+ wrapperCol: {
99
+ offset: 8
100
+ }
92
101
  }, /*#__PURE__*/React.createElement(Button, {
93
102
  type: "primary",
94
103
  loading: loading,
@@ -2,11 +2,12 @@ import React from 'react';
2
2
  import type { SmsScene } from './types';
3
3
  interface Props {
4
4
  form: any;
5
+ formSpan: number;
5
6
  scene: SmsScene;
6
7
  env?: Global.Env;
7
8
  apiUrl?: string;
8
9
  disabledFormItemLabel?: boolean;
9
10
  }
10
- /** 手机号 + 验证码 + 发送按钮(含倒计时与工作量证明)。 */
11
+ /** 人机验证 + 手机验证码 + 发送按钮(含倒计时)。 */
11
12
  declare const PhoneCode: React.FC<Props>;
12
13
  export default PhoneCode;