component-shipinlv 1.0.5 → 1.0.7

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