component-sanzhizhou 1.0.2 → 1.0.3

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.
@@ -0,0 +1,16 @@
1
+ import React from 'react';
2
+ interface Props {
3
+ productType: string;
4
+ apiUrl?: string;
5
+ clientUniqueKeyList: string[];
6
+ loginTypeList: Global.AuthClientLoginType[];
7
+ domain?: string;
8
+ env?: Global.Env;
9
+ roleType?: UserAuth.RoleType;
10
+ postData: {
11
+ [name: string]: any;
12
+ };
13
+ onLoginSuccess: () => void;
14
+ }
15
+ declare const Auth: React.FC<Props>;
16
+ export default Auth;
@@ -0,0 +1,374 @@
1
+ import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
2
+ import _regeneratorRuntime from "@babel/runtime/helpers/esm/regeneratorRuntime";
3
+ import _asyncToGenerator from "@babel/runtime/helpers/esm/asyncToGenerator";
4
+ import _toConsumableArray from "@babel/runtime/helpers/esm/toConsumableArray";
5
+ import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
6
+ import React, { useState, useEffect, useRef } from 'react';
7
+ import { WechatOutlined, RedoOutlined, UserOutlined } from '@ant-design/icons';
8
+ import { Tabs } from 'antd';
9
+ import { useRequest } from '@umijs/hooks';
10
+ import * as AuthController from "../service/api/AuthController";
11
+ import PageContentWarp from "../UI/PageContentWarp";
12
+ import AuthLoginReg from "../AuthClient/login-reg";
13
+ import Platform from "../lib/platform";
14
+ import QrWs from "../AuthClient/qr/ws";
15
+ import { getApiEnv } from "../lib/getApiUrl";
16
+ import styles from "../AuthClient/qr/index.css";
17
+ import QRCode from 'qrcode.react';
18
+ import h5WePublicLogin from "../AuthClient/qr/h5-we-public-login";
19
+ import Tool from "../lib/Tool";
20
+ import { jsx as _jsx } from "react/jsx-runtime";
21
+ import { Fragment as _Fragment } from "react/jsx-runtime";
22
+ import { jsxs as _jsxs } from "react/jsx-runtime";
23
+ var reTryMaxCount = 120;
24
+ var reTryTimeLoop = 1000; // ms
25
+ var FromWhere = 'web';
26
+
27
+ // 逐渐弃用 AuthClient ,使用 本函数
28
+ var Auth = function Auth(_ref) {
29
+ var productType = _ref.productType,
30
+ apiUrl = _ref.apiUrl,
31
+ clientUniqueKeyList = _ref.clientUniqueKeyList,
32
+ loginTypeList = _ref.loginTypeList,
33
+ env = _ref.env,
34
+ postData = _ref.postData,
35
+ roleType = _ref.roleType,
36
+ _ref$domain = _ref.domain,
37
+ domain = _ref$domain === void 0 ? document.location.hostname : _ref$domain,
38
+ _ref$onLoginSuccess = _ref.onLoginSuccess,
39
+ onLoginSuccess = _ref$onLoginSuccess === void 0 ? function () {} : _ref$onLoginSuccess;
40
+ var _useState = useState(false),
41
+ _useState2 = _slicedToArray(_useState, 2),
42
+ loading = _useState2[0],
43
+ setLoading = _useState2[1];
44
+ var qrWsRef = useRef();
45
+ var _useState3 = useState(_toConsumableArray(loginTypeList)),
46
+ _useState4 = _slicedToArray(_useState3, 2),
47
+ currentLoginTypeList = _useState4[0],
48
+ setCurrentLoginTypeList = _useState4[1];
49
+ var _useState5 = useState((currentLoginTypeList === null || currentLoginTypeList === void 0 ? void 0 : currentLoginTypeList[0]) || 'wechat'),
50
+ _useState6 = _slicedToArray(_useState5, 2),
51
+ activeKey = _useState6[0],
52
+ setActiveKey = _useState6[1];
53
+ var _useState7 = useState("".concat(Tool.math.randWord(20))),
54
+ _useState8 = _slicedToArray(_useState7, 1),
55
+ loginId = _useState8[0];
56
+ var _useState9 = useState(''),
57
+ _useState10 = _slicedToArray(_useState9, 2),
58
+ weQrUrl = _useState10[0],
59
+ setWeQrUrl = _useState10[1];
60
+ var isNextTryRef = useRef(activeKey === 'wechat');
61
+
62
+ // 要不要继续 try
63
+ var _useState11 = useState(isNextTryRef.current),
64
+ _useState12 = _slicedToArray(_useState11, 2),
65
+ isNextTry = _useState12[0],
66
+ setNextTry = _useState12[1];
67
+ var reTryCountRef = useRef(0);
68
+ var _useState13 = useState(0),
69
+ _useState14 = _slicedToArray(_useState13, 2),
70
+ reTryCount = _useState14[0],
71
+ setReTryCount = _useState14[1];
72
+ var timer = useRef(setTimeout(function () {}, 1));
73
+ var eventSourceRef = useRef(null);
74
+ var onLoginCancel = function onLoginCancel() {
75
+ var _eventSourceRef$curre, _qrWsRef$current;
76
+ (_eventSourceRef$curre = eventSourceRef.current) === null || _eventSourceRef$curre === void 0 || _eventSourceRef$curre.close();
77
+ clearInterval(timer.current);
78
+ reTryCountRef.current = 0;
79
+ setReTryCount(0);
80
+ (_qrWsRef$current = qrWsRef.current) === null || _qrWsRef$current === void 0 || _qrWsRef$current.destroy();
81
+ };
82
+ var onCheckLogin = /*#__PURE__*/function () {
83
+ var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
84
+ var init, post;
85
+ return _regeneratorRuntime().wrap(function _callee$(_context) {
86
+ while (1) switch (_context.prev = _context.next) {
87
+ case 0:
88
+ qrWsRef.current = new QrWs();
89
+
90
+ // 先初始化
91
+ _context.next = 3;
92
+ return qrWsRef.current.init().catch(function (err) {
93
+ Tool.toastError(err.message);
94
+ });
95
+ case 3:
96
+ init = _context.sent;
97
+ if (init) {
98
+ _context.next = 7;
99
+ break;
100
+ }
101
+ onLoginError();
102
+ return _context.abrupt("return");
103
+ case 7:
104
+ _context.next = 9;
105
+ return qrWsRef.current.post({
106
+ fromWhere: FromWhere,
107
+ loginId: loginId
108
+ }, {
109
+ onData: function onData(text) {}
110
+ }).catch(function (err) {
111
+ Tool.toastError(err.message);
112
+ onLoginError();
113
+ });
114
+ case 9:
115
+ post = _context.sent;
116
+ // 登录成功
117
+ if (post) {
118
+ // 登陆成功;
119
+ // let info = {};
120
+ // try {
121
+ // info = JSON.parse( post.data );
122
+ // }catch (e) {
123
+ // console.log("result:", post, e )
124
+ // }
125
+ onCheckSuccess(post.data);
126
+ }
127
+ case 11:
128
+ case "end":
129
+ return _context.stop();
130
+ }
131
+ }, _callee);
132
+ }));
133
+ return function onCheckLogin() {
134
+ return _ref2.apply(this, arguments);
135
+ };
136
+ }();
137
+ var onCheckSuccess = function onCheckSuccess(userInfo) {
138
+ Tool.setLocalUserInfo(_objectSpread(_objectSpread({}, userInfo), {}, {
139
+ isLogin: true
140
+ }));
141
+ onLoginSuccess();
142
+ Tool.event.run('login-success');
143
+ Tool.event.run("".concat(roleType || 'user', "-login-success"), _objectSpread(_objectSpread({}, userInfo), {}, {
144
+ isLogin: true
145
+ }));
146
+ Tool.toast('登录成功');
147
+ };
148
+ var _useRequest = useRequest(function () {
149
+ return AuthController.weMiniLoginQr({
150
+ loginId: loginId,
151
+ //string 32
152
+ loginType: 'client',
153
+ from: "web",
154
+ // 没有推荐者,会根据域名判断 经销商
155
+ inviteUserId: Tool.getInviteUserId(),
156
+ domain: domain || document.location.hostname,
157
+ env: getApiEnv()
158
+ });
159
+ }, {
160
+ manual: true,
161
+ //,
162
+ onSuccess: function onSuccess(result) {
163
+ setWeQrUrl(result.url);
164
+ onRunCheck();
165
+ }
166
+ }),
167
+ runWeLoginQr = _useRequest.run,
168
+ loadingWeLoginQr = _useRequest.loading,
169
+ errorWeLoginQr = _useRequest.error;
170
+ var onRunCheck = function onRunCheck() {
171
+ clearInterval(timer.current);
172
+ onCheckLogin();
173
+ reTryCountRef.current = 0;
174
+ setReTryCount(0);
175
+ timer.current = setInterval(function () {
176
+ reTryCountRef.current++;
177
+ setReTryCount(reTryCountRef.current);
178
+ console.log("reTryCount:", reTryCountRef.current);
179
+ if (reTryCountRef.current >= reTryMaxCount) {
180
+ onLoginError();
181
+ return;
182
+ }
183
+ }, reTryTimeLoop);
184
+ };
185
+ var onRetryWeQr = function onRetryWeQr() {
186
+ isNextTryRef.current = true;
187
+ setNextTry(true);
188
+ setReTryCount(0);
189
+ reTryCountRef.current = 0;
190
+
191
+ // 重新
192
+ setWeQrUrl('');
193
+ runWeLoginQr();
194
+ };
195
+ var onTabChange = /*#__PURE__*/function () {
196
+ var _ref3 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(keyName) {
197
+ var _qrWsRef$current2;
198
+ return _regeneratorRuntime().wrap(function _callee2$(_context2) {
199
+ while (1) switch (_context2.prev = _context2.next) {
200
+ case 0:
201
+ // @ts-ignore
202
+ setActiveKey(keyName);
203
+ if (keyName === 'wechat') {
204
+ // await runWeLoginQr();
205
+ onRetryWeQr();
206
+ } else {
207
+ // 停止 weixin
208
+ (_qrWsRef$current2 = qrWsRef.current) === null || _qrWsRef$current2 === void 0 || _qrWsRef$current2.destroy();
209
+ }
210
+ case 2:
211
+ case "end":
212
+ return _context2.stop();
213
+ }
214
+ }, _callee2);
215
+ }));
216
+ return function onTabChange(_x) {
217
+ return _ref3.apply(this, arguments);
218
+ };
219
+ }();
220
+ var onLoginError = function onLoginError() {
221
+ clearInterval(timer.current);
222
+ isNextTryRef.current = false;
223
+ setNextTry(false);
224
+ reTryCountRef.current = 0;
225
+ setReTryCount(0);
226
+ onLoginCancel();
227
+ };
228
+ var onInit = /*#__PURE__*/function () {
229
+ var _ref4 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3() {
230
+ return _regeneratorRuntime().wrap(function _callee3$(_context3) {
231
+ while (1) switch (_context3.prev = _context3.next) {
232
+ case 0:
233
+ if (!Platform.isWechat) {
234
+ _context3.next = 7;
235
+ break;
236
+ }
237
+ setLoading(true);
238
+ // jump
239
+ _context3.next = 4;
240
+ return h5WePublicLogin();
241
+ case 4:
242
+ setLoading(false);
243
+ _context3.next = 10;
244
+ break;
245
+ case 7:
246
+ if (!currentLoginTypeList.includes('wechat')) {
247
+ _context3.next = 10;
248
+ break;
249
+ }
250
+ _context3.next = 10;
251
+ return runWeLoginQr();
252
+ case 10:
253
+ case "end":
254
+ return _context3.stop();
255
+ }
256
+ }, _callee3);
257
+ }));
258
+ return function onInit() {
259
+ return _ref4.apply(this, arguments);
260
+ };
261
+ }();
262
+ var onCallWechat = function onCallWechat() {
263
+ currentLoginTypeList.push('wechat');
264
+ setCurrentLoginTypeList(_toConsumableArray(currentLoginTypeList));
265
+ };
266
+ var onCallAccount = function onCallAccount() {
267
+ currentLoginTypeList.push('account', 'account-reg', 'account-login');
268
+ setCurrentLoginTypeList(_toConsumableArray(currentLoginTypeList));
269
+ };
270
+ useEffect(function () {
271
+ onInit();
272
+ return function () {
273
+ clearTimeout(timer.current);
274
+ };
275
+ }, []);
276
+ return /*#__PURE__*/_jsxs(styles.AuthQrLogin, {
277
+ children: [/*#__PURE__*/_jsxs(styles.LoginForm, {
278
+ children: [/*#__PURE__*/_jsx(styles.WebTitle, {
279
+ children: /*#__PURE__*/_jsx("span", {
280
+ children: "\u767B\u5F55/\u6CE8\u518C"
281
+ })
282
+ }), /*#__PURE__*/_jsxs(Tabs, {
283
+ activeKey: activeKey,
284
+ onChange: function onChange(keyName) {
285
+ onTabChange(keyName);
286
+ },
287
+ children: [!((currentLoginTypeList === null || currentLoginTypeList === void 0 ? void 0 : currentLoginTypeList.length) > 0 && !currentLoginTypeList.includes('wechat')) && /*#__PURE__*/_jsx(Tabs.TabPane, {
288
+ tab: /*#__PURE__*/_jsxs(_Fragment, {
289
+ children: [/*#__PURE__*/_jsx(WechatOutlined, {}), " \u5FAE\u4FE1"]
290
+ }),
291
+ disabled: (currentLoginTypeList === null || currentLoginTypeList === void 0 ? void 0 : currentLoginTypeList.length) > 0 && !currentLoginTypeList.includes('wechat'),
292
+ children: /*#__PURE__*/_jsx(PageContentWarp, {
293
+ loading: loadingWeLoginQr || loading,
294
+ error: errorWeLoginQr,
295
+ onReload: function onReload() {
296
+ return onRetryWeQr();
297
+ },
298
+ children: /*#__PURE__*/_jsxs(styles.WeQrUrlBox, {
299
+ children: [/*#__PURE__*/_jsxs("div", {
300
+ style: {
301
+ // backgroundImage: `url('${ weQrUrl }')`,
302
+ },
303
+ className: "qr wechat ".concat(isNextTry ? '' : 'noTry'),
304
+ children: [!isNextTry && /*#__PURE__*/_jsx("div", {
305
+ className: "reTry",
306
+ onClick: onRetryWeQr,
307
+ children: /*#__PURE__*/_jsx("a", {
308
+ children: /*#__PURE__*/_jsx(RedoOutlined, {})
309
+ })
310
+ }), /*#__PURE__*/_jsx("div", {
311
+ className: "weQrUrl",
312
+ children: /*#__PURE__*/_jsx(QRCode, {
313
+ value: weQrUrl,
314
+ fgColor: "#0bc160",
315
+ size: 230
316
+ })
317
+ })]
318
+ }), Platform.isH5 ? /*#__PURE__*/_jsxs("div", {
319
+ className: "altWeb",
320
+ children: [/*#__PURE__*/_jsx("div", {
321
+ className: "titles",
322
+ children: "\u4E0B\u9762\u4EFB\u9009\u4E00\u4E2A\u65B9\u6CD5\u90FD\u53EF\u4EE5\u767B\u5F55\uFF1A"
323
+ }), /*#__PURE__*/_jsxs("ul", {
324
+ children: [/*#__PURE__*/_jsx("li", {
325
+ children: "1\u3001\u628A\u672C\u9875\u7F51\u5740\u590D\u5236\u5230\u5FAE\u4FE1\u91CC\u9762\u6253\u5F00"
326
+ }), /*#__PURE__*/_jsx("li", {
327
+ children: "2\u3001\u8BF7\u7528\u5FAE\u4FE1\u626B\u7801\u767B\u5F55"
328
+ }), /*#__PURE__*/_jsx("li", {
329
+ children: "3\u3001\u628A\u672C\u9875\u7F51\u5740\u590D\u5236\u5230\u5FAE\u4FE1\u91CC\u9762\u6253\u5F00"
330
+ })]
331
+ })]
332
+ }) : /*#__PURE__*/_jsx("div", {
333
+ className: "alt"
334
+ })]
335
+ })
336
+ })
337
+ }, "wechat"), /*#__PURE__*/_jsx(Tabs.TabPane, {
338
+ tab: /*#__PURE__*/_jsxs("span", {
339
+ className: "tab-icon",
340
+ children: [/*#__PURE__*/_jsx(UserOutlined, {}), " \u8D26\u6237"]
341
+ }),
342
+ disabled: !currentLoginTypeList.includes('account-login') && !currentLoginTypeList.includes('account'),
343
+ children: /*#__PURE__*/_jsx(AuthLoginReg, {
344
+ env: env,
345
+ apiUrl: apiUrl,
346
+ roleType: roleType,
347
+ postData: postData,
348
+ productType: productType,
349
+ clientUniqueKeyList: clientUniqueKeyList,
350
+ accountRegDisabled: !currentLoginTypeList.includes('account-reg'),
351
+ onSuccess: function onSuccess() {
352
+ return onLoginSuccess();
353
+ }
354
+ })
355
+ }, "account")]
356
+ }), activeKey === 'wechat' && /*#__PURE__*/_jsx("div", {
357
+ className: "percent",
358
+ children: /*#__PURE__*/_jsx("div", {
359
+ className: "warp",
360
+ style: {
361
+ width: "".concat(reTryCount / reTryMaxCount * 100, "%")
362
+ }
363
+ })
364
+ })]
365
+ }), /*#__PURE__*/_jsx("div", {
366
+ className: "callWechat",
367
+ onClick: onCallWechat
368
+ }), /*#__PURE__*/_jsx("div", {
369
+ className: "callAccount",
370
+ onClick: onCallAccount
371
+ })]
372
+ });
373
+ };
374
+ export default Auth;
@@ -112,13 +112,11 @@ var AuthReg = function AuthReg(_ref) {
112
112
  onSuccess();
113
113
  };
114
114
  var onFinish = /*#__PURE__*/function () {
115
- var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
116
- var values,
117
- _args = arguments;
115
+ var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(values) {
118
116
  return _regeneratorRuntime().wrap(function _callee$(_context) {
119
117
  while (1) switch (_context.prev = _context.next) {
120
118
  case 0:
121
- values = _args.length > 0 && _args[0] !== undefined ? _args[0] : {};
119
+ values.accountName = values.accountName.replace(/\s+/ig, '');
122
120
  run(values);
123
121
  case 2:
124
122
  case "end":
@@ -126,7 +124,7 @@ var AuthReg = function AuthReg(_ref) {
126
124
  }
127
125
  }, _callee);
128
126
  }));
129
- return function onFinish() {
127
+ return function onFinish(_x) {
130
128
  return _ref2.apply(this, arguments);
131
129
  };
132
130
  }();
@@ -138,24 +136,23 @@ var AuthReg = function AuthReg(_ref) {
138
136
  disabled: loading,
139
137
  autoComplete: "off",
140
138
  children: [/*#__PURE__*/_jsx(Form.Item, _objectSpread(_objectSpread({
141
- label: "\u8D26\u53F7"
139
+ label: "\u624B\u673A\u53F7\u7801"
142
140
  }, formItemLayout), {}, {
143
141
  name: "accountName",
144
142
  rules: [{
145
143
  required: true,
146
- message: '请输入'
147
- }
144
+ message: '请输入手机号码'
145
+ },
148
146
  // {
149
147
  // pattern: /^([a-z0-9]+[_\-.]?)*[a-z0-9]+@([a-z0-9]+[_\-.]?)*[a-z0-9]+\.[a-z]{2,10}$/i,
150
148
  // message: '这似乎不是一个电子邮箱'
151
149
  // },
152
- // {
153
- // pattern: /^\s*1\d{10}\s*$/,
154
- // message: '这似乎不是大陆手机号?'
155
- // }
156
- ],
150
+ {
151
+ pattern: /^\s*1\d{2}\s*\d{4}\s*\d{4}\s*$/,
152
+ message: '这似乎不是大陆手机号码?'
153
+ }],
157
154
  children: /*#__PURE__*/_jsx(Input, {
158
- placeholder: "\u8D26\u53F7",
155
+ placeholder: "\u624B\u673A\u53F7\u7801",
159
156
  prefix: /*#__PURE__*/_jsx(UserOutlined, {
160
157
  className: "input-prefix-icon"
161
158
  })
@@ -81,13 +81,11 @@ var Reg = function Reg(_ref) {
81
81
  onSuccess();
82
82
  };
83
83
  var onFinish = /*#__PURE__*/function () {
84
- var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
85
- var values,
86
- _args = arguments;
84
+ var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(values) {
87
85
  return _regeneratorRuntime().wrap(function _callee$(_context) {
88
86
  while (1) switch (_context.prev = _context.next) {
89
87
  case 0:
90
- values = _args.length > 0 && _args[0] !== undefined ? _args[0] : {};
88
+ values.accountName = values.accountName.replace(/\s+/ig, '');
91
89
  run(values);
92
90
  case 2:
93
91
  case "end":
@@ -95,7 +93,7 @@ var Reg = function Reg(_ref) {
95
93
  }
96
94
  }, _callee);
97
95
  }));
98
- return function onFinish() {
96
+ return function onFinish(_x) {
99
97
  return _ref2.apply(this, arguments);
100
98
  };
101
99
  }();
package/dist/index.d.ts CHANGED
@@ -1,6 +1,7 @@
1
1
  import './global.less';
2
2
  export { default as Buy } from './Buy';
3
3
  export { default as Login } from './Login';
4
+ export { default as Auth } from './Auth';
4
5
  export { default as AuthClient } from './AuthClient';
5
6
  export { default as Product } from './Product';
6
7
  export { default as ClientUpdate } from './Client/ClientUpdate';
package/dist/index.js CHANGED
@@ -3,6 +3,7 @@
3
3
  import "./global.less";
4
4
  export { default as Buy } from "./Buy";
5
5
  export { default as Login } from "./Login";
6
+ export { default as Auth } from "./Auth";
6
7
  export { default as AuthClient } from "./AuthClient";
7
8
  export { default as Product } from "./Product";
8
9
  export { default as ClientUpdate } from "./Client/ClientUpdate";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "component-sanzhizhou",
3
- "version": "1.0.2",
3
+ "version": "1.0.3",
4
4
  "description": "",
5
5
  "module": "dist/index.js",
6
6
  "types": "dist/index.d.ts",