component-shipinlv 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- package/LICENSE +21 -0
- package/README.md +4 -0
- package/dist/AuthClient/index.d.ts +10 -0
- package/dist/AuthClient/index.js +24 -0
- package/dist/AuthClient/login-reg.d.ts +9 -0
- package/dist/AuthClient/login-reg.js +62 -0
- package/dist/AuthClient/login-reg.less +13 -0
- package/dist/AuthClient/login.d.ts +7 -0
- package/dist/AuthClient/login.js +159 -0
- package/dist/AuthClient/login.less +52 -0
- package/dist/AuthClient/qr/index.d.ts +13 -0
- package/dist/AuthClient/qr/index.js +315 -0
- package/dist/AuthClient/qr/index.less +84 -0
- package/dist/AuthClient/qr/typings.d.ts +22 -0
- package/dist/AuthClient/qr/ws.d.ts +20 -0
- package/dist/AuthClient/qr/ws.js +253 -0
- package/dist/AuthClient/reg.d.ts +7 -0
- package/dist/AuthClient/reg.js +170 -0
- package/dist/AuthClient/reg.less +3 -0
- package/dist/Buy/index.d.ts +14 -0
- package/dist/Buy/index.js +91 -0
- package/dist/Buy/index.less +26 -0
- package/dist/Buy/qr.d.ts +11 -0
- package/dist/Buy/qr.js +185 -0
- package/dist/Buy/qr.less +69 -0
- package/dist/Login/index.d.ts +2 -0
- package/dist/Login/index.js +5 -0
- package/dist/Product/index.d.ts +4 -0
- package/dist/Product/index.js +34 -0
- package/dist/Product/index.less +84 -0
- package/dist/UI/DialogDrawer.d.ts +8 -0
- package/dist/UI/DialogDrawer.js +67 -0
- package/dist/UI/DialogDrawer.less +10 -0
- package/dist/UI/DialogDrawerFooter.d.ts +7 -0
- package/dist/UI/DialogDrawerFooter.js +23 -0
- package/dist/UI/DialogDrawerFooter.less +19 -0
- package/dist/UI/LoadError.d.ts +10 -0
- package/dist/UI/LoadError.js +37 -0
- package/dist/UI/LoadError.less +18 -0
- package/dist/UI/PageContentWarp.d.ts +16 -0
- package/dist/UI/PageContentWarp.js +46 -0
- package/dist/UI/PageContentWarp.less +11 -0
- package/dist/VipCompare/commend.d.ts +7 -0
- package/dist/VipCompare/commend.js +29 -0
- package/dist/VipCompare/commend.less +7 -0
- package/dist/VipCompare/index.d.ts +9 -0
- package/dist/VipCompare/index.js +320 -0
- package/dist/VipCompare/index.less +26 -0
- package/dist/component/product-dict.d.ts +10 -0
- package/dist/component/product-dict.js +11 -0
- package/dist/component/product-type.d.ts +6 -0
- package/dist/component/product-type.js +19 -0
- package/dist/component/websocket/index.d.ts +22 -0
- package/dist/component/websocket/index.js +139 -0
- package/dist/config/apiUrls.d.ts +9 -0
- package/dist/config/apiUrls.js +25 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.js +5 -0
- package/dist/lib/Tool.d.ts +201 -0
- package/dist/lib/Tool.js +1086 -0
- package/dist/lib/call-mini-url.d.ts +2 -0
- package/dist/lib/call-mini-url.js +8 -0
- package/dist/lib/getApiUrl.d.ts +5 -0
- package/dist/lib/getApiUrl.js +56 -0
- package/dist/lib/goAuth.d.ts +1 -0
- package/dist/lib/goAuth.js +28 -0
- package/dist/lib/js-error.d.ts +2 -0
- package/dist/lib/js-error.js +27 -0
- package/dist/lib/notification.d.ts +9 -0
- package/dist/lib/notification.js +42 -0
- package/dist/lib/platform.d.ts +12 -0
- package/dist/lib/platform.js +48 -0
- package/dist/lib/postMessage.d.ts +3 -0
- package/dist/lib/postMessage.js +8 -0
- package/dist/lib/request.d.ts +3 -0
- package/dist/lib/request.js +97 -0
- package/dist/service/api/AuthController.d.ts +16 -0
- package/dist/service/api/AuthController.js +75 -0
- package/dist/service/api/JsErrorController.d.ts +5 -0
- package/dist/service/api/JsErrorController.js +27 -0
- package/dist/service/api/ProductController.d.ts +7 -0
- package/dist/service/api/ProductController.js +53 -0
- package/dist/service/api/TradeController.d.ts +7 -0
- package/dist/service/api/TradeController.js +52 -0
- package/dist/service/api/UserController.d.ts +2 -0
- package/dist/service/api/UserController.js +52 -0
- package/dist/service/api/VipController.d.ts +6 -0
- package/dist/service/api/VipController.js +50 -0
- package/dist/service/typing.d.ts +12 -0
- package/dist/typings/Product.d.ts +25 -0
- package/dist/typings/Product.js +0 -0
- package/dist/typings/Trade.d.ts +29 -0
- package/dist/typings/Trade.js +0 -0
- package/dist/typings/User.d.ts +54 -0
- package/dist/typings/User.js +0 -0
- package/dist/typings/Vip.d.ts +15 -0
- package/dist/typings/Vip.js +0 -0
- package/dist/typings.d.ts +66 -0
- package/dist/window.d.ts +9 -0
- package/package.json +88 -0
@@ -0,0 +1,315 @@
|
|
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 Tool from "../../lib/Tool";
|
9
|
+
import { useRequest } from '@umijs/hooks';
|
10
|
+
import "./index.less";
|
11
|
+
import * as AuthController from "../../service/api/AuthController";
|
12
|
+
import PageContentWarp from "../../UI/PageContentWarp";
|
13
|
+
import AuthLoginReg from "../login-reg";
|
14
|
+
import Platform from "../../lib/platform";
|
15
|
+
import QrWs from "./ws";
|
16
|
+
import { getApiEnv } from "../../lib/getApiUrl";
|
17
|
+
// import LoginQrAlipay from "component-shipinlv/AuthClient/alipay";
|
18
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
19
|
+
import { jsxs as _jsxs } from "react/jsx-runtime";
|
20
|
+
var reTryMaxCount = 120;
|
21
|
+
var reTryTimeLoop = 1000; // ms
|
22
|
+
var FromWhere = 'web';
|
23
|
+
var LoginQr = function LoginQr(_ref) {
|
24
|
+
var defaultLoginType = _ref.defaultLoginType,
|
25
|
+
wechatDisabled = _ref.wechatDisabled,
|
26
|
+
accountDisabled = _ref.accountDisabled,
|
27
|
+
accountRegDisabled = _ref.accountRegDisabled,
|
28
|
+
accountHidden = _ref.accountHidden,
|
29
|
+
alipayDisabled = _ref.alipayDisabled,
|
30
|
+
_ref$onLoginSuccess = _ref.onLoginSuccess,
|
31
|
+
onLoginSuccess = _ref$onLoginSuccess === void 0 ? function () {} : _ref$onLoginSuccess;
|
32
|
+
var _useState = useState(false),
|
33
|
+
_useState2 = _slicedToArray(_useState, 2),
|
34
|
+
loading = _useState2[0],
|
35
|
+
setLoading = _useState2[1];
|
36
|
+
var qrWsRef = useRef();
|
37
|
+
var _useState3 = useState(defaultLoginType || 'wechat'),
|
38
|
+
_useState4 = _slicedToArray(_useState3, 2),
|
39
|
+
activeKey = _useState4[0],
|
40
|
+
setActiveKey = _useState4[1];
|
41
|
+
// 受限于 小程序 Scene 长度的限制
|
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
|
+
// 没有推荐者,会根据域名判断 经销商
|
140
|
+
inviteUserId: Tool.getInviteUserId(),
|
141
|
+
env: getApiEnv()
|
142
|
+
});
|
143
|
+
}, {
|
144
|
+
manual: true,
|
145
|
+
onSuccess: function onSuccess(result) {
|
146
|
+
setWeQrUrl(Tool.makeQrUrl(result.url, '#0bc160'));
|
147
|
+
onRunCheck();
|
148
|
+
}
|
149
|
+
}),
|
150
|
+
runWeLoginQr = _useRequest.run,
|
151
|
+
loadingWeLoginQr = _useRequest.loading,
|
152
|
+
errorWeLoginQr = _useRequest.error;
|
153
|
+
var onRunCheck = function onRunCheck() {
|
154
|
+
clearInterval(timer.current);
|
155
|
+
onCheckLogin();
|
156
|
+
reTryCountRef.current = 0;
|
157
|
+
setReTryCount(0);
|
158
|
+
timer.current = setInterval(function () {
|
159
|
+
reTryCountRef.current++;
|
160
|
+
setReTryCount(reTryCountRef.current);
|
161
|
+
console.log("reTryCount:", reTryCountRef.current);
|
162
|
+
if (reTryCountRef.current >= reTryMaxCount) {
|
163
|
+
onLoginError();
|
164
|
+
return;
|
165
|
+
}
|
166
|
+
}, reTryTimeLoop);
|
167
|
+
};
|
168
|
+
var onRetryWeQr = function onRetryWeQr() {
|
169
|
+
isNextTryRef.current = true;
|
170
|
+
setNextTry(true);
|
171
|
+
setReTryCount(0);
|
172
|
+
reTryCountRef.current = 0;
|
173
|
+
|
174
|
+
// 重新
|
175
|
+
setWeQrUrl('');
|
176
|
+
runWeLoginQr();
|
177
|
+
};
|
178
|
+
var onTabChange = /*#__PURE__*/function () {
|
179
|
+
var _ref3 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(keyName) {
|
180
|
+
var _qrWsRef$current2;
|
181
|
+
return _regeneratorRuntime().wrap(function _callee2$(_context2) {
|
182
|
+
while (1) switch (_context2.prev = _context2.next) {
|
183
|
+
case 0:
|
184
|
+
// @ts-ignore
|
185
|
+
setActiveKey(keyName);
|
186
|
+
if (keyName === 'wechat') {
|
187
|
+
// await runWeLoginQr();
|
188
|
+
onRetryWeQr();
|
189
|
+
} else {
|
190
|
+
// 停止 weixin
|
191
|
+
(_qrWsRef$current2 = qrWsRef.current) === null || _qrWsRef$current2 === void 0 || _qrWsRef$current2.destroy();
|
192
|
+
}
|
193
|
+
case 2:
|
194
|
+
case "end":
|
195
|
+
return _context2.stop();
|
196
|
+
}
|
197
|
+
}, _callee2);
|
198
|
+
}));
|
199
|
+
return function onTabChange(_x) {
|
200
|
+
return _ref3.apply(this, arguments);
|
201
|
+
};
|
202
|
+
}();
|
203
|
+
var onLoginError = function onLoginError() {
|
204
|
+
clearInterval(timer.current);
|
205
|
+
isNextTryRef.current = false;
|
206
|
+
setNextTry(false);
|
207
|
+
reTryCountRef.current = 0;
|
208
|
+
setReTryCount(0);
|
209
|
+
onLoginCancel();
|
210
|
+
};
|
211
|
+
var onInit = /*#__PURE__*/function () {
|
212
|
+
var _ref4 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3() {
|
213
|
+
return _regeneratorRuntime().wrap(function _callee3$(_context3) {
|
214
|
+
while (1) switch (_context3.prev = _context3.next) {
|
215
|
+
case 0:
|
216
|
+
case "end":
|
217
|
+
return _context3.stop();
|
218
|
+
}
|
219
|
+
}, _callee3);
|
220
|
+
}));
|
221
|
+
return function onInit() {
|
222
|
+
return _ref4.apply(this, arguments);
|
223
|
+
};
|
224
|
+
}();
|
225
|
+
useEffect(function () {
|
226
|
+
onInit();
|
227
|
+
return function () {
|
228
|
+
clearTimeout(timer.current);
|
229
|
+
};
|
230
|
+
}, []);
|
231
|
+
return /*#__PURE__*/_jsx("section", {
|
232
|
+
className: "authQrLogin",
|
233
|
+
children: /*#__PURE__*/_jsxs("div", {
|
234
|
+
className: "loginForm",
|
235
|
+
children: [/*#__PURE__*/_jsx("div", {
|
236
|
+
className: "form-group",
|
237
|
+
children: /*#__PURE__*/_jsx("h1", {
|
238
|
+
className: "webTitle",
|
239
|
+
children: /*#__PURE__*/_jsx("span", {
|
240
|
+
children: "\u767B\u5F55/\u6CE8\u518C"
|
241
|
+
})
|
242
|
+
})
|
243
|
+
}), /*#__PURE__*/_jsxs(Tabs, {
|
244
|
+
activeKey: activeKey,
|
245
|
+
onChange: function onChange(keyName) {
|
246
|
+
onTabChange(keyName);
|
247
|
+
},
|
248
|
+
children: [/*#__PURE__*/_jsx(Tabs.TabPane, {
|
249
|
+
tab: /*#__PURE__*/_jsxs("span", {
|
250
|
+
className: "tab-icon",
|
251
|
+
children: [/*#__PURE__*/_jsx(WechatOutlined, {}), "\u5FAE\u4FE1"]
|
252
|
+
}),
|
253
|
+
disabled: wechatDisabled,
|
254
|
+
children: /*#__PURE__*/_jsxs(PageContentWarp, {
|
255
|
+
loading: loadingWeLoginQr || loading,
|
256
|
+
error: errorWeLoginQr,
|
257
|
+
onReload: function onReload() {
|
258
|
+
return onRetryWeQr();
|
259
|
+
},
|
260
|
+
className: "weQrUrlBox",
|
261
|
+
children: [/*#__PURE__*/_jsx("div", {
|
262
|
+
style: {
|
263
|
+
backgroundImage: "url('".concat(weQrUrl, "')")
|
264
|
+
},
|
265
|
+
className: "qr wechat ".concat(isNextTry ? '' : 'noTry'),
|
266
|
+
children: !isNextTry && /*#__PURE__*/_jsx("div", {
|
267
|
+
className: "reTry",
|
268
|
+
onClick: onRetryWeQr,
|
269
|
+
children: /*#__PURE__*/_jsx("a", {
|
270
|
+
children: /*#__PURE__*/_jsx(RedoOutlined, {})
|
271
|
+
})
|
272
|
+
})
|
273
|
+
}), Platform.isH5 ? /*#__PURE__*/_jsxs("div", {
|
274
|
+
className: "altWeb",
|
275
|
+
children: [/*#__PURE__*/_jsx("div", {
|
276
|
+
className: "titles",
|
277
|
+
children: "\u4E0B\u9762\u4EFB\u9009\u4E00\u4E2A\u65B9\u6CD5\u90FD\u53EF\u4EE5\u767B\u5F55\uFF1A"
|
278
|
+
}), /*#__PURE__*/_jsxs("ul", {
|
279
|
+
children: [/*#__PURE__*/_jsx("li", {
|
280
|
+
children: "1\u3001\u628A\u672C\u9875\u7F51\u5740\u590D\u5236\u5230\u5FAE\u4FE1\u91CC\u9762\u6253\u5F00"
|
281
|
+
}), /*#__PURE__*/_jsx("li", {
|
282
|
+
children: "2\u3001\u8BF7\u7528\u5FAE\u4FE1\u626B\u7801\u767B\u5F55"
|
283
|
+
})]
|
284
|
+
})]
|
285
|
+
}) : /*#__PURE__*/_jsx("div", {
|
286
|
+
className: "alt",
|
287
|
+
children: "\u8BF7\u7528\u5FAE\u4FE1\u626B\u7801\u767B\u5F55"
|
288
|
+
})]
|
289
|
+
})
|
290
|
+
}, "wechat"), !accountHidden && /*#__PURE__*/_jsx(Tabs.TabPane, {
|
291
|
+
tab: /*#__PURE__*/_jsxs("span", {
|
292
|
+
className: "tab-icon",
|
293
|
+
children: [/*#__PURE__*/_jsx(UserOutlined, {}), "\u8D26\u6237"]
|
294
|
+
}),
|
295
|
+
disabled: accountDisabled,
|
296
|
+
children: /*#__PURE__*/_jsx(AuthLoginReg, {
|
297
|
+
accountRegDisabled: accountRegDisabled,
|
298
|
+
onSuccess: function onSuccess() {
|
299
|
+
return onLoginSuccess();
|
300
|
+
}
|
301
|
+
})
|
302
|
+
}, "account")]
|
303
|
+
}), activeKey === 'wechat' && /*#__PURE__*/_jsx("div", {
|
304
|
+
className: "percent",
|
305
|
+
children: /*#__PURE__*/_jsx("div", {
|
306
|
+
className: "warp",
|
307
|
+
style: {
|
308
|
+
width: "".concat(reTryCount / reTryMaxCount * 100, "%")
|
309
|
+
}
|
310
|
+
})
|
311
|
+
})]
|
312
|
+
})
|
313
|
+
});
|
314
|
+
};
|
315
|
+
export default LoginQr;
|
@@ -0,0 +1,84 @@
|
|
1
|
+
.authQrLogin{
|
2
|
+
.loginForm{
|
3
|
+
margin: 0 auto;
|
4
|
+
padding: 0 0 5px 0 ;
|
5
|
+
background-color: rgba(255, 255, 255, 0.75 );
|
6
|
+
border-radius: 6px;
|
7
|
+
}
|
8
|
+
.webTitle{
|
9
|
+
font-weight: normal;
|
10
|
+
font-size: 22px;
|
11
|
+
text-align: center;
|
12
|
+
padding: 0;
|
13
|
+
margin: 6px 0 0 0;
|
14
|
+
line-height: 1em;
|
15
|
+
span{
|
16
|
+
display: inline-block;
|
17
|
+
padding-left: 5px;
|
18
|
+
font-weight: lighter;
|
19
|
+
font-size: 16px;
|
20
|
+
};
|
21
|
+
}
|
22
|
+
.weQrUrlBox{
|
23
|
+
min-height: 240px !important;
|
24
|
+
.weQrUrl{
|
25
|
+
width: 240px;
|
26
|
+
display: block;
|
27
|
+
margin: 10px auto 0;
|
28
|
+
}
|
29
|
+
}
|
30
|
+
|
31
|
+
.qr{
|
32
|
+
display: block;
|
33
|
+
margin: 12px auto 0;
|
34
|
+
width: 230px;
|
35
|
+
height: 230px;
|
36
|
+
background-repeat: no-repeat;
|
37
|
+
background-size: cover;
|
38
|
+
background-position: center;
|
39
|
+
&.qrAlipay{
|
40
|
+
border: 3px solid #1677ff;
|
41
|
+
}
|
42
|
+
.reTry{
|
43
|
+
font-size: 80px;
|
44
|
+
background-color: rgba( 255, 255, 255, 0.95 );
|
45
|
+
text-align: center;
|
46
|
+
line-height: 210px;
|
47
|
+
height: 100%;
|
48
|
+
a{
|
49
|
+
display: block;
|
50
|
+
}
|
51
|
+
}
|
52
|
+
}
|
53
|
+
.alt{
|
54
|
+
padding: 10px 0 0;
|
55
|
+
color: #999;
|
56
|
+
text-align: center;
|
57
|
+
}
|
58
|
+
.altWeb{
|
59
|
+
padding: 16px 0 0;
|
60
|
+
max-width: 300px;
|
61
|
+
margin: 0 auto;
|
62
|
+
.titles{
|
63
|
+
text-align: center;
|
64
|
+
font-weight: bold;
|
65
|
+
}
|
66
|
+
ul{
|
67
|
+
margin: 0 10px;
|
68
|
+
}
|
69
|
+
|
70
|
+
}
|
71
|
+
.percent{
|
72
|
+
width: 100%;
|
73
|
+
position: absolute;
|
74
|
+
overflow: hidden;
|
75
|
+
left: 0;
|
76
|
+
bottom: 0;
|
77
|
+
.warp{
|
78
|
+
height: 4px;
|
79
|
+
background-color: #1677ff;
|
80
|
+
transition: all 1.6s ease-in-out;
|
81
|
+
-webkit-transition: all 1.6s ease-in-out;
|
82
|
+
}
|
83
|
+
}
|
84
|
+
}
|
@@ -0,0 +1,22 @@
|
|
1
|
+
declare namespace QrWebsocket{
|
2
|
+
interface Options{
|
3
|
+
|
4
|
+
}
|
5
|
+
|
6
|
+
interface PostData{
|
7
|
+
// question 为空时候,用最后一条问题;
|
8
|
+
fromWhere: string;
|
9
|
+
loginId: string;
|
10
|
+
}
|
11
|
+
|
12
|
+
interface PostQuery{
|
13
|
+
onData: ( text: string ) => void;
|
14
|
+
}
|
15
|
+
|
16
|
+
type PostResult = Promise<Global.RequestResult>;
|
17
|
+
|
18
|
+
interface HistoryList{
|
19
|
+
chatClassifyId: string;
|
20
|
+
title: string;
|
21
|
+
}
|
22
|
+
}
|
@@ -0,0 +1,20 @@
|
|
1
|
+
import WS from "../../component/websocket";
|
2
|
+
import type { ConnectStatus } from '../../component/websocket';
|
3
|
+
type EventName = 'connect-status' | 'message';
|
4
|
+
declare class QrWs {
|
5
|
+
wsId: string;
|
6
|
+
connectStatus: ConnectStatus;
|
7
|
+
ws: WS | null;
|
8
|
+
private events;
|
9
|
+
constructor();
|
10
|
+
destroy(): void;
|
11
|
+
onCancel(): void;
|
12
|
+
on(name: EventName, fn?: (data?: any) => void): void;
|
13
|
+
run(name: EventName, data?: any): void;
|
14
|
+
off(name: EventName): void;
|
15
|
+
init(): Promise<unknown>;
|
16
|
+
post(postData: QrWebsocket.PostData, query: QrWebsocket.PostQuery): Promise<Global.RequestResult>;
|
17
|
+
onReConnect(): void;
|
18
|
+
onConnectSuccess(): void;
|
19
|
+
}
|
20
|
+
export default QrWs;
|
@@ -0,0 +1,253 @@
|
|
1
|
+
import _regeneratorRuntime from "@babel/runtime/helpers/esm/regeneratorRuntime";
|
2
|
+
import _asyncToGenerator from "@babel/runtime/helpers/esm/asyncToGenerator";
|
3
|
+
import _classCallCheck from "@babel/runtime/helpers/esm/classCallCheck";
|
4
|
+
import _createClass from "@babel/runtime/helpers/esm/createClass";
|
5
|
+
import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
|
6
|
+
import WS from "../../component/websocket";
|
7
|
+
import Tool from "../../lib/Tool";
|
8
|
+
import { getWsUrl } from "../../lib/getApiUrl";
|
9
|
+
// 1、先 onInit
|
10
|
+
// 2、再 post
|
11
|
+
var QrWs = /*#__PURE__*/function () {
|
12
|
+
function QrWs() {
|
13
|
+
_classCallCheck(this, QrWs);
|
14
|
+
_defineProperty(this, "wsId", '');
|
15
|
+
_defineProperty(this, "connectStatus", 'processing');
|
16
|
+
_defineProperty(this, "ws", null);
|
17
|
+
_defineProperty(this, "events", []);
|
18
|
+
// this.onInit();
|
19
|
+
this.wsId = Tool.math.randWord(16);
|
20
|
+
}
|
21
|
+
_createClass(QrWs, [{
|
22
|
+
key: "destroy",
|
23
|
+
value: function destroy() {
|
24
|
+
this.onCancel();
|
25
|
+
}
|
26
|
+
}, {
|
27
|
+
key: "onCancel",
|
28
|
+
value: function onCancel() {
|
29
|
+
var _this$ws;
|
30
|
+
console.log("chat qr ask onCancel", this.ws);
|
31
|
+
(_this$ws = this.ws) === null || _this$ws === void 0 || _this$ws.destroy();
|
32
|
+
this.events = [];
|
33
|
+
}
|
34
|
+
}, {
|
35
|
+
key: "on",
|
36
|
+
value: function on(name) {
|
37
|
+
var fn = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : function (data) {};
|
38
|
+
this.events.push({
|
39
|
+
name: name,
|
40
|
+
fn: fn
|
41
|
+
});
|
42
|
+
}
|
43
|
+
}, {
|
44
|
+
key: "run",
|
45
|
+
value: function run(name, data) {
|
46
|
+
this.events.forEach(function (items) {
|
47
|
+
if (name === items.name) {
|
48
|
+
items.fn(data);
|
49
|
+
}
|
50
|
+
});
|
51
|
+
}
|
52
|
+
}, {
|
53
|
+
key: "off",
|
54
|
+
value: function off(name) {
|
55
|
+
var _this = this;
|
56
|
+
this.events.forEach(function (items, index) {
|
57
|
+
if (name === items.name) {
|
58
|
+
_this.events.splice(index, 1);
|
59
|
+
}
|
60
|
+
});
|
61
|
+
}
|
62
|
+
}, {
|
63
|
+
key: "init",
|
64
|
+
value: function () {
|
65
|
+
var _init = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3() {
|
66
|
+
var _this2 = this;
|
67
|
+
return _regeneratorRuntime().wrap(function _callee3$(_context3) {
|
68
|
+
while (1) switch (_context3.prev = _context3.next) {
|
69
|
+
case 0:
|
70
|
+
return _context3.abrupt("return", new Promise( /*#__PURE__*/function () {
|
71
|
+
var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(resolve, reject) {
|
72
|
+
var postParam, url;
|
73
|
+
return _regeneratorRuntime().wrap(function _callee2$(_context2) {
|
74
|
+
while (1) switch (_context2.prev = _context2.next) {
|
75
|
+
case 0:
|
76
|
+
_this2.connectStatus = 'processing';
|
77
|
+
postParam = Tool.param({
|
78
|
+
wsId: _this2.wsId
|
79
|
+
});
|
80
|
+
url = getWsUrl() + "client/auth/checkLogin".toLocaleLowerCase() + "?".concat(postParam);
|
81
|
+
_this2.ws = new WS(url);
|
82
|
+
_this2.ws.on('message', /*#__PURE__*/function () {
|
83
|
+
var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(result) {
|
84
|
+
var resultData;
|
85
|
+
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
86
|
+
while (1) switch (_context.prev = _context.next) {
|
87
|
+
case 0:
|
88
|
+
// console.log(' socket message:', result.data );
|
89
|
+
|
90
|
+
try {
|
91
|
+
resultData = JSON.parse(result.data);
|
92
|
+
} catch (e) {
|
93
|
+
resultData = {
|
94
|
+
data: {
|
95
|
+
success: false,
|
96
|
+
data: [],
|
97
|
+
type: '',
|
98
|
+
message: '发生了一些问题'
|
99
|
+
}
|
100
|
+
};
|
101
|
+
console.warn('dataFlow message', result);
|
102
|
+
}
|
103
|
+
_this2.run('message', resultData);
|
104
|
+
case 2:
|
105
|
+
case "end":
|
106
|
+
return _context.stop();
|
107
|
+
}
|
108
|
+
}, _callee);
|
109
|
+
}));
|
110
|
+
return function (_x3) {
|
111
|
+
return _ref2.apply(this, arguments);
|
112
|
+
};
|
113
|
+
}());
|
114
|
+
_this2.ws.on('connect-status', function (status) {
|
115
|
+
_this2.connectStatus = status;
|
116
|
+
console.log('Client Server Status: connect:', status);
|
117
|
+
switch (status) {
|
118
|
+
// 初始化时候出发
|
119
|
+
case 'success':
|
120
|
+
_this2.onConnectSuccess();
|
121
|
+
resolve(true);
|
122
|
+
break;
|
123
|
+
case 'error':
|
124
|
+
// // 初始化时候, 连接后任意时间 出发
|
125
|
+
reject(new Error("WS 连接错误,请重试"));
|
126
|
+
break;
|
127
|
+
}
|
128
|
+
});
|
129
|
+
case 6:
|
130
|
+
case "end":
|
131
|
+
return _context2.stop();
|
132
|
+
}
|
133
|
+
}, _callee2);
|
134
|
+
}));
|
135
|
+
return function (_x, _x2) {
|
136
|
+
return _ref.apply(this, arguments);
|
137
|
+
};
|
138
|
+
}()));
|
139
|
+
case 1:
|
140
|
+
case "end":
|
141
|
+
return _context3.stop();
|
142
|
+
}
|
143
|
+
}, _callee3);
|
144
|
+
}));
|
145
|
+
function init() {
|
146
|
+
return _init.apply(this, arguments);
|
147
|
+
}
|
148
|
+
return init;
|
149
|
+
}() // 每个实例,同时 只能 有一个 post ,不然 message 会混淆
|
150
|
+
}, {
|
151
|
+
key: "post",
|
152
|
+
value: function () {
|
153
|
+
var _post = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee5(postData, query) {
|
154
|
+
var _this3 = this;
|
155
|
+
return _regeneratorRuntime().wrap(function _callee5$(_context5) {
|
156
|
+
while (1) switch (_context5.prev = _context5.next) {
|
157
|
+
case 0:
|
158
|
+
console.log('client qr on Init:');
|
159
|
+
return _context5.abrupt("return", new Promise( /*#__PURE__*/function () {
|
160
|
+
var _ref3 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4(resolve, reject) {
|
161
|
+
var _this3$ws, _this3$ws2;
|
162
|
+
var sendData;
|
163
|
+
return _regeneratorRuntime().wrap(function _callee4$(_context4) {
|
164
|
+
while (1) switch (_context4.prev = _context4.next) {
|
165
|
+
case 0:
|
166
|
+
if (!(_this3.connectStatus !== 'success')) {
|
167
|
+
_context4.next = 2;
|
168
|
+
break;
|
169
|
+
}
|
170
|
+
return _context4.abrupt("return", reject(new Error('ws未连接,请重试')));
|
171
|
+
case 2:
|
172
|
+
_this3.on('message', function (result) {
|
173
|
+
// query.onData( result );
|
174
|
+
console.log('message 1:', result);
|
175
|
+
switch (result.code) {
|
176
|
+
case 'success':
|
177
|
+
_this3.onCancel();
|
178
|
+
resolve(result);
|
179
|
+
break;
|
180
|
+
case 'fail':
|
181
|
+
_this3.onCancel();
|
182
|
+
reject(new Error(result.message || '发生了一些问题'));
|
183
|
+
break;
|
184
|
+
case 'message':
|
185
|
+
var _data = result.message;
|
186
|
+
query.onData(_data);
|
187
|
+
break;
|
188
|
+
default:
|
189
|
+
// 到这里相当于失败了
|
190
|
+
_this3.onCancel();
|
191
|
+
reject(new Error(result.message || '发生了一些问题'));
|
192
|
+
}
|
193
|
+
});
|
194
|
+
(_this3$ws = _this3.ws) === null || _this3$ws === void 0 || _this3$ws.on('connect-status', function (status) {
|
195
|
+
switch (status) {
|
196
|
+
case 'error':
|
197
|
+
// // 初始化时候, 连接后任意时间 出发
|
198
|
+
reject(new Error("WS 连接错误,请重试"));
|
199
|
+
break;
|
200
|
+
case 'close':
|
201
|
+
// 连接后,任意时间 出发
|
202
|
+
_this3.onCancel();
|
203
|
+
reject(new Error("连接已关闭"));
|
204
|
+
break;
|
205
|
+
}
|
206
|
+
});
|
207
|
+
sendData = {
|
208
|
+
messageType: 'auth',
|
209
|
+
query: postData
|
210
|
+
};
|
211
|
+
(_this3$ws2 = _this3.ws) === null || _this3$ws2 === void 0 || _this3$ws2.send(sendData);
|
212
|
+
case 6:
|
213
|
+
case "end":
|
214
|
+
return _context4.stop();
|
215
|
+
}
|
216
|
+
}, _callee4);
|
217
|
+
}));
|
218
|
+
return function (_x6, _x7) {
|
219
|
+
return _ref3.apply(this, arguments);
|
220
|
+
};
|
221
|
+
}()));
|
222
|
+
case 2:
|
223
|
+
case "end":
|
224
|
+
return _context5.stop();
|
225
|
+
}
|
226
|
+
}, _callee5);
|
227
|
+
}));
|
228
|
+
function post(_x4, _x5) {
|
229
|
+
return _post.apply(this, arguments);
|
230
|
+
}
|
231
|
+
return post;
|
232
|
+
}()
|
233
|
+
}, {
|
234
|
+
key: "onReConnect",
|
235
|
+
value: function onReConnect() {}
|
236
|
+
}, {
|
237
|
+
key: "onConnectSuccess",
|
238
|
+
value: function onConnectSuccess() {}
|
239
|
+
}]);
|
240
|
+
return QrWs;
|
241
|
+
}(); // useEffect(() => {
|
242
|
+
//
|
243
|
+
// if( reTryTimer.current ){
|
244
|
+
// clearTimeout( reTryTimer.current );
|
245
|
+
// }
|
246
|
+
// reTryTimer.current = setTimeout(() => {
|
247
|
+
// if( ['error', 'close'].includes( connectStatus ) ){
|
248
|
+
// onInit();
|
249
|
+
// }
|
250
|
+
// reTryTimer.current = 0;
|
251
|
+
// }, 6000 );
|
252
|
+
// }, [ connectStatus ]);
|
253
|
+
export default QrWs;
|