component-shipinlv 0.0.29 → 0.1.0

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.
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,8 @@
1
+ import React from 'react';
2
+ import './index.less';
3
+ interface Props {
4
+ productType: string;
5
+ port?: number;
6
+ }
7
+ declare const JoinClient: React.FC<Props>;
8
+ export default JoinClient;
@@ -0,0 +1,203 @@
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, { 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
+ var _useState = useState('loading'),
21
+ _useState2 = _slicedToArray(_useState, 2),
22
+ runStatus = _useState2[0],
23
+ setRunStatus = _useState2[1];
24
+ var tryRunStatusTimerRef = useRef(setTimeout(function () {}, 0));
25
+ var _useRequest = useRequest(function () {
26
+ return SubClientController.start({
27
+ productType: productType
28
+ });
29
+ }, {
30
+ // manual: true,
31
+ onSuccess: function () {
32
+ var _onSuccess = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(result) {
33
+ return _regeneratorRuntime().wrap(function _callee$(_context) {
34
+ while (1) switch (_context.prev = _context.next) {
35
+ case 0:
36
+ console.log('JoinClient:', result);
37
+ if (result.status === 'client-not-exist') {
38
+ setRunStatus('loading');
39
+ } else if (result.status === 'client-exist') {
40
+ setRunStatus('loading');
41
+ } else {
42
+ console.log('JoinClient run status:', result);
43
+ setRunStatus('loading');
44
+ }
45
+ onTryRunStatus();
46
+ case 3:
47
+ case "end":
48
+ return _context.stop();
49
+ }
50
+ }, _callee);
51
+ }));
52
+ function onSuccess(_x) {
53
+ return _onSuccess.apply(this, arguments);
54
+ }
55
+ return onSuccess;
56
+ }(),
57
+ onError: function onError(err) {
58
+ console.log('SubClientController start err:', err.name, err.message);
59
+ setRunStatus('client-fail');
60
+ }
61
+ }),
62
+ loading = _useRequest.loading,
63
+ run = _useRequest.run;
64
+ var onTryRunStatus = /*#__PURE__*/function () {
65
+ var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3() {
66
+ var result;
67
+ return _regeneratorRuntime().wrap(function _callee3$(_context3) {
68
+ while (1) switch (_context3.prev = _context3.next) {
69
+ case 0:
70
+ _context3.next = 2;
71
+ return SubClientController.runStatus({
72
+ productType: productType,
73
+ port: port
74
+ }, {
75
+ silent: true
76
+ }).catch( /*#__PURE__*/function () {
77
+ var _ref3 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(err) {
78
+ return _regeneratorRuntime().wrap(function _callee2$(_context2) {
79
+ while (1) switch (_context2.prev = _context2.next) {
80
+ case 0:
81
+ if (err.name === 'sub-client-connect-fail') {
82
+ setRunStatus('loading');
83
+ } else {
84
+ setRunStatus('loading');
85
+ }
86
+ _context2.next = 3;
87
+ return Tool.sleep(TryRunStatusIntervalMillisecond);
88
+ case 3:
89
+ onTryRunStatus();
90
+ case 4:
91
+ case "end":
92
+ return _context2.stop();
93
+ }
94
+ }, _callee2);
95
+ }));
96
+ return function (_x2) {
97
+ return _ref3.apply(this, arguments);
98
+ };
99
+ }());
100
+ case 2:
101
+ result = _context3.sent;
102
+ if (result) {
103
+ _context3.next = 5;
104
+ break;
105
+ }
106
+ return _context3.abrupt("return");
107
+ case 5:
108
+ if (result.runStatus === 'working') {
109
+ setRunStatus('working');
110
+ }
111
+ case 6:
112
+ case "end":
113
+ return _context3.stop();
114
+ }
115
+ }, _callee3);
116
+ }));
117
+ return function onTryRunStatus() {
118
+ return _ref2.apply(this, arguments);
119
+ };
120
+ }();
121
+ var $status = function $status() {
122
+ // 'stop' | 'not-install' | 'downloading' | 'down-fail' | 'start-fail' | 'working'
123
+ if (runStatus === 'client-fail') {
124
+ return /*#__PURE__*/_jsxs(_Fragment, {
125
+ children: ["\u8BF7\u5148", /*#__PURE__*/_jsx("a", {
126
+ href: "https://shipinlv.com/product/client-shipinlv/download",
127
+ target: "_blank",
128
+ children: "\u4E0B\u8F7D"
129
+ }), "\u3001\u5B89\u88C5\u5BA2\u6237\u7AEF\uFF0C\u5E76", /*#__PURE__*/_jsx("strong", {
130
+ children: "\u542F\u52A8"
131
+ }), /*#__PURE__*/_jsx(Divider, {
132
+ type: "vertical"
133
+ }), /*#__PURE__*/_jsx(Button, {
134
+ size: "small",
135
+ type: "primary",
136
+ icon: /*#__PURE__*/_jsx(RedoOutlined, {}),
137
+ onClick: function onClick() {
138
+ return run();
139
+ },
140
+ children: "\u91CD\u65B0\u8FDE\u63A5"
141
+ })]
142
+ });
143
+ }
144
+
145
+ // if( runStatus === 'client-close' ){
146
+ // return <>
147
+ // 请先 <strong>启动</strong> 视频驴客户端
148
+ // <Divider type="vertical" />
149
+ // <Button size="small" type="primary" icon={ <RedoOutlined /> } onClick={ () => run() }>
150
+ // 连接
151
+ // </Button>
152
+ // </>
153
+ // }
154
+
155
+ if (runStatus === 'stop') {
156
+ return /*#__PURE__*/_jsx("span", {
157
+ children: "\u5BA2\u6237\u7AEF\u672A\u542F\u52A8"
158
+ });
159
+ }
160
+ if (runStatus === 'loading') {
161
+ return /*#__PURE__*/_jsxs("span", {
162
+ children: [/*#__PURE__*/_jsx(LoadingOutlined, {
163
+ className: "loading"
164
+ }), " \u8FDE\u63A5\u4E2D"]
165
+ });
166
+ }
167
+ if (runStatus === 'down-fail') {
168
+ return /*#__PURE__*/_jsx("span", {
169
+ children: "\u5BA2\u6237\u7AEF\u4E0B\u8F7D\u5931\u8D25"
170
+ });
171
+ }
172
+ if (runStatus === 'downloading') {
173
+ return /*#__PURE__*/_jsx("span", {
174
+ children: "\u4E0B\u8F7D\u4E2D"
175
+ });
176
+ }
177
+ if (runStatus === 'start-fail') {
178
+ return /*#__PURE__*/_jsxs("span", {
179
+ children: [/*#__PURE__*/_jsx(ExclamationCircleFilled, {}), " \u542F\u52A8\u5931\u8D25"]
180
+ });
181
+ }
182
+ if (runStatus == 'working') {
183
+ return /*#__PURE__*/_jsxs("span", {
184
+ children: [/*#__PURE__*/_jsx(CheckCircleFilled, {
185
+ className: "working"
186
+ }), " \u5BA2\u6237\u7AEF\u5DF2\u8FDE\u63A5"]
187
+ });
188
+ }
189
+ return /*#__PURE__*/_jsx(_Fragment, {
190
+ children: runStatus
191
+ });
192
+ };
193
+ return /*#__PURE__*/_jsxs("div", {
194
+ className: "clientStatus",
195
+ children: [$status(), /*#__PURE__*/_jsx(Divider, {
196
+ type: "vertical"
197
+ }), /*#__PURE__*/_jsxs(Tooltip, {
198
+ title: "\u672C\u9875\u9762\u529F\u80FD\u9700\u8981\u4F60\u7684\u7535\u8111\u4E0A\u5B89\u88C5\u4E13\u7528\u5BA2\u6237\u7AEF\u8F6F\u4EF6",
199
+ children: [" ", /*#__PURE__*/_jsx(QuestionCircleOutlined, {})]
200
+ })]
201
+ });
202
+ };
203
+ 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.0",
4
4
  "description": "",
5
5
  "module": "dist/index.js",
6
6
  "types": "dist/index.d.ts",