component-shipinlv 0.0.29 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
File without changes
package/dist/index.d.ts CHANGED
@@ -3,3 +3,4 @@ export { default as Buy } from './Buy';
3
3
  export { default as Login } from './Login';
4
4
  export { default as AuthClient } from './AuthClient';
5
5
  export { default as Product } from './Product';
6
+ export { default as JoinClient } from './join-client';
package/dist/index.js CHANGED
@@ -2,4 +2,5 @@ export { default as VipCompare } from "./VipCompare";
2
2
  export { default as Buy } from "./Buy";
3
3
  export { default as Login } from "./Login";
4
4
  export { default as AuthClient } from "./AuthClient";
5
- export { default as Product } from "./Product";
5
+ export { default as Product } from "./Product";
6
+ export { default as JoinClient } from "./join-client";
@@ -0,0 +1,9 @@
1
+ import React from 'react';
2
+ import './index.less';
3
+ interface Props {
4
+ productType: string;
5
+ port?: number;
6
+ onRunStatus: (runStatus: SubClient.RunStatus) => void;
7
+ }
8
+ declare const JoinClient: React.FC<Props>;
9
+ export default JoinClient;
@@ -0,0 +1,208 @@
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, { useEffect, useRef, useState } from 'react';
5
+ import * as SubClientController from "../service/api/SubClientController";
6
+ import { useRequest } from '@umijs/hooks';
7
+ import "./index.less";
8
+ import { CheckCircleFilled, ExclamationCircleFilled, LoadingOutlined, QuestionCircleOutlined, RedoOutlined } from "@ant-design/icons";
9
+ import { Button, Divider, Tooltip } from "antd";
10
+ import Tool from "../lib/Tool";
11
+ import { jsx as _jsx } from "react/jsx-runtime";
12
+ import { Fragment as _Fragment } from "react/jsx-runtime";
13
+ import { jsxs as _jsxs } from "react/jsx-runtime";
14
+ var TryRunStatusMaxCount = 1000;
15
+ var TryRunStatusIntervalMillisecond = 1000;
16
+ var JoinClient = function JoinClient(_ref) {
17
+ var productType = _ref.productType,
18
+ _ref$port = _ref.port,
19
+ port = _ref$port === void 0 ? 0 : _ref$port,
20
+ _ref$onRunStatus = _ref.onRunStatus,
21
+ onRunStatus = _ref$onRunStatus === void 0 ? function () {} : _ref$onRunStatus;
22
+ var _useState = useState('loading'),
23
+ _useState2 = _slicedToArray(_useState, 2),
24
+ runStatus = _useState2[0],
25
+ setRunStatus = _useState2[1];
26
+ var tryRunStatusTimerRef = useRef(setTimeout(function () {}, 0));
27
+ var _useRequest = useRequest(function () {
28
+ return SubClientController.start({
29
+ productType: productType
30
+ });
31
+ }, {
32
+ // manual: true,
33
+ onSuccess: function () {
34
+ var _onSuccess = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(result) {
35
+ return _regeneratorRuntime().wrap(function _callee$(_context) {
36
+ while (1) switch (_context.prev = _context.next) {
37
+ case 0:
38
+ console.log('JoinClient:', result);
39
+ if (result.status === 'client-not-exist') {
40
+ setRunStatus('loading');
41
+ } else if (result.status === 'client-exist') {
42
+ setRunStatus('loading');
43
+ } else {
44
+ console.log('JoinClient run status:', result);
45
+ setRunStatus('loading');
46
+ }
47
+ onTryRunStatus();
48
+ case 3:
49
+ case "end":
50
+ return _context.stop();
51
+ }
52
+ }, _callee);
53
+ }));
54
+ function onSuccess(_x) {
55
+ return _onSuccess.apply(this, arguments);
56
+ }
57
+ return onSuccess;
58
+ }(),
59
+ onError: function onError(err) {
60
+ console.log('SubClientController start err:', err.name, err.message);
61
+ setRunStatus('client-fail');
62
+ }
63
+ }),
64
+ loading = _useRequest.loading,
65
+ run = _useRequest.run;
66
+ var onTryRunStatus = /*#__PURE__*/function () {
67
+ var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3() {
68
+ var result;
69
+ return _regeneratorRuntime().wrap(function _callee3$(_context3) {
70
+ while (1) switch (_context3.prev = _context3.next) {
71
+ case 0:
72
+ _context3.next = 2;
73
+ return SubClientController.runStatus({
74
+ productType: productType,
75
+ port: port
76
+ }, {
77
+ silent: true
78
+ }).catch( /*#__PURE__*/function () {
79
+ var _ref3 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(err) {
80
+ return _regeneratorRuntime().wrap(function _callee2$(_context2) {
81
+ while (1) switch (_context2.prev = _context2.next) {
82
+ case 0:
83
+ if (err.name === 'sub-client-connect-fail') {
84
+ setRunStatus('loading');
85
+ } else {
86
+ setRunStatus('loading');
87
+ }
88
+ _context2.next = 3;
89
+ return Tool.sleep(TryRunStatusIntervalMillisecond);
90
+ case 3:
91
+ onTryRunStatus();
92
+ case 4:
93
+ case "end":
94
+ return _context2.stop();
95
+ }
96
+ }, _callee2);
97
+ }));
98
+ return function (_x2) {
99
+ return _ref3.apply(this, arguments);
100
+ };
101
+ }());
102
+ case 2:
103
+ result = _context3.sent;
104
+ if (result) {
105
+ _context3.next = 5;
106
+ break;
107
+ }
108
+ return _context3.abrupt("return");
109
+ case 5:
110
+ if (result.runStatus === 'working') {
111
+ setRunStatus('working');
112
+ }
113
+ case 6:
114
+ case "end":
115
+ return _context3.stop();
116
+ }
117
+ }, _callee3);
118
+ }));
119
+ return function onTryRunStatus() {
120
+ return _ref2.apply(this, arguments);
121
+ };
122
+ }();
123
+ var $status = function $status() {
124
+ // 'stop' | 'not-install' | 'downloading' | 'down-fail' | 'start-fail' | 'working'
125
+ if (runStatus === 'client-fail') {
126
+ return /*#__PURE__*/_jsxs(_Fragment, {
127
+ children: ["\u8BF7\u5148", /*#__PURE__*/_jsx("a", {
128
+ href: "https://shipinlv.com/product/client-shipinlv/download",
129
+ target: "_blank",
130
+ children: "\u4E0B\u8F7D"
131
+ }), "\u3001\u5B89\u88C5\u5BA2\u6237\u7AEF\uFF0C\u5E76", /*#__PURE__*/_jsx("strong", {
132
+ children: "\u542F\u52A8"
133
+ }), /*#__PURE__*/_jsx(Divider, {
134
+ type: "vertical"
135
+ }), /*#__PURE__*/_jsx(Button, {
136
+ size: "small",
137
+ type: "primary",
138
+ icon: /*#__PURE__*/_jsx(RedoOutlined, {}),
139
+ onClick: function onClick() {
140
+ return run();
141
+ },
142
+ children: "\u91CD\u65B0\u8FDE\u63A5"
143
+ })]
144
+ });
145
+ }
146
+
147
+ // if( runStatus === 'client-close' ){
148
+ // return <>
149
+ // 请先 <strong>启动</strong> 视频驴客户端
150
+ // <Divider type="vertical" />
151
+ // <Button size="small" type="primary" icon={ <RedoOutlined /> } onClick={ () => run() }>
152
+ // 连接
153
+ // </Button>
154
+ // </>
155
+ // }
156
+
157
+ if (runStatus === 'stop') {
158
+ return /*#__PURE__*/_jsx("span", {
159
+ children: "\u5BA2\u6237\u7AEF\u672A\u542F\u52A8"
160
+ });
161
+ }
162
+ if (runStatus === 'loading') {
163
+ return /*#__PURE__*/_jsxs("span", {
164
+ children: [/*#__PURE__*/_jsx(LoadingOutlined, {
165
+ className: "loading"
166
+ }), " \u8FDE\u63A5\u4E2D"]
167
+ });
168
+ }
169
+ if (runStatus === 'down-fail') {
170
+ return /*#__PURE__*/_jsx("span", {
171
+ children: "\u5BA2\u6237\u7AEF\u4E0B\u8F7D\u5931\u8D25"
172
+ });
173
+ }
174
+ if (runStatus === 'downloading') {
175
+ return /*#__PURE__*/_jsx("span", {
176
+ children: "\u4E0B\u8F7D\u4E2D"
177
+ });
178
+ }
179
+ if (runStatus === 'start-fail') {
180
+ return /*#__PURE__*/_jsxs("span", {
181
+ children: [/*#__PURE__*/_jsx(ExclamationCircleFilled, {}), " \u542F\u52A8\u5931\u8D25"]
182
+ });
183
+ }
184
+ if (runStatus == 'working') {
185
+ return /*#__PURE__*/_jsxs("span", {
186
+ children: [/*#__PURE__*/_jsx(CheckCircleFilled, {
187
+ className: "working"
188
+ }), " \u5BA2\u6237\u7AEF\u5DF2\u8FDE\u63A5"]
189
+ });
190
+ }
191
+ return /*#__PURE__*/_jsx(_Fragment, {
192
+ children: runStatus
193
+ });
194
+ };
195
+ useEffect(function () {
196
+ onRunStatus(runStatus);
197
+ }, [runStatus]);
198
+ return /*#__PURE__*/_jsxs("div", {
199
+ className: "clientStatus",
200
+ children: [$status(), /*#__PURE__*/_jsx(Divider, {
201
+ type: "vertical"
202
+ }), /*#__PURE__*/_jsxs(Tooltip, {
203
+ title: "\u672C\u9875\u9762\u529F\u80FD\u9700\u8981\u4F60\u7684\u7535\u8111\u4E0A\u5B89\u88C5\u4E13\u7528\u5BA2\u6237\u7AEF\u8F6F\u4EF6",
204
+ children: [" ", /*#__PURE__*/_jsx(QuestionCircleOutlined, {})]
205
+ })]
206
+ });
207
+ };
208
+ export default JoinClient;
@@ -0,0 +1,15 @@
1
+ .clientStatus{
2
+
3
+ .loading{
4
+ opacity: 0.7;
5
+ }
6
+
7
+ .downloading{
8
+ margin-left: 12px;
9
+ }
10
+
11
+ .working{
12
+ color: green;
13
+ }
14
+
15
+ }
@@ -163,7 +163,7 @@ declare const Tool: {
163
163
  setTimeOffset(serverTime: number): void;
164
164
  getTime(): number;
165
165
  h5Pay(query: Pay.H5PayQuery): void;
166
- notification(type: "info" | "error" | "success" | "warning", message: string, description?: import("react").ReactNode, options?: NotificationOptions): void;
166
+ notification(type: "success" | "info" | "warning" | "error", message: string, description?: import("react").ReactNode, options?: NotificationOptions): void;
167
167
  notificationSuccess(message: string, description?: import("react").ReactNode, options?: NotificationOptions): void;
168
168
  notificationError(message: string, description?: import("react").ReactNode, options?: NotificationOptions): void;
169
169
  notificationWarning(message: string, description?: import("react").ReactNode, options?: NotificationOptions): void;
@@ -61,7 +61,7 @@ var requestApi = function requestApi() {
61
61
  }
62
62
  }
63
63
  }).catch(function (err) {
64
- console.log('ajax error:', err);
64
+ console.log('ajax error:', err.name, err.message, err);
65
65
  if (['Failed to fetch', 'http error'].includes(err === null || err === void 0 ? void 0 : err.message)) {
66
66
  err.message = '发生了一些问题,请稍后重试';
67
67
  }
@@ -0,0 +1,7 @@
1
+ export declare function start(body: {
2
+ productType: string;
3
+ }, options?: Global.RequestOptions): Promise<SubClient.StartResult>;
4
+ export declare function runStatus(body: {
5
+ productType: string;
6
+ port: number;
7
+ }, options?: Global.RequestOptions): Promise<SubClient.RunStatusResult>;
@@ -0,0 +1,47 @@
1
+ import _regeneratorRuntime from "@babel/runtime/helpers/esm/regeneratorRuntime";
2
+ import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
3
+ import _asyncToGenerator from "@babel/runtime/helpers/esm/asyncToGenerator";
4
+ import request from "../../lib/request";
5
+ export function start(_x, _x2) {
6
+ return _start.apply(this, arguments);
7
+ }
8
+
9
+ // 测试是否联通
10
+ function _start() {
11
+ _start = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(body, options) {
12
+ return _regeneratorRuntime().wrap(function _callee$(_context) {
13
+ while (1) switch (_context.prev = _context.next) {
14
+ case 0:
15
+ return _context.abrupt("return", request("http://127.0.0.1:61800/sub-client/start", _objectSpread({
16
+ env: (options === null || options === void 0 ? void 0 : options.env) || '',
17
+ method: 'GET',
18
+ params: _objectSpread({}, body)
19
+ }, options || {})));
20
+ case 1:
21
+ case "end":
22
+ return _context.stop();
23
+ }
24
+ }, _callee);
25
+ }));
26
+ return _start.apply(this, arguments);
27
+ }
28
+ export function runStatus(_x3, _x4) {
29
+ return _runStatus.apply(this, arguments);
30
+ }
31
+ function _runStatus() {
32
+ _runStatus = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(body, options) {
33
+ return _regeneratorRuntime().wrap(function _callee2$(_context2) {
34
+ while (1) switch (_context2.prev = _context2.next) {
35
+ case 0:
36
+ return _context2.abrupt("return", request("http://127.0.0.1:".concat((body === null || body === void 0 ? void 0 : body.port) || 61800, "/sub-client/runStatus"), _objectSpread({
37
+ method: 'GET',
38
+ params: _objectSpread({}, body)
39
+ }, options || {})));
40
+ case 1:
41
+ case "end":
42
+ return _context2.stop();
43
+ }
44
+ }, _callee2);
45
+ }));
46
+ return _runStatus.apply(this, arguments);
47
+ }
@@ -0,0 +1,10 @@
1
+ declare namespace SubClient {
2
+ type ClientRunStatus = 'client-not-exist' | 'client-exist';
3
+ type RunStatus = 'loading' | 'not-install' | 'stop' | 'downloading' | 'down-fail' | 'start-fail' | 'working' | 'client-fail';
4
+ interface StartResult {
5
+ status: ClientRunStatus;
6
+ }
7
+ interface RunStatusResult {
8
+ runStatus: RunStatus;
9
+ }
10
+ }
File without changes
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "component-shipinlv",
3
- "version": "0.0.29",
3
+ "version": "0.1.1",
4
4
  "description": "",
5
5
  "module": "dist/index.js",
6
6
  "types": "dist/index.d.ts",