@zgfe/business-lib 1.1.29-visual.9 → 1.1.29
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.
- package/es/addToPanel/components/addPanel.js +21 -8
- package/es/addToPanel/components/radioGroup.js +3 -1
- package/es/addToPanel/components/styleList.js +22 -5
- package/es/addToPanel/demo/edit.js +12 -5
- package/es/addToPanel/demo/index.js +12 -5
- package/es/addToPanel/index.js +58 -21
- package/es/addToScene/addGroup.js +4 -0
- package/es/addToScene/demo/index.js +12 -5
- package/es/addToScene/index.js +40 -13
- package/es/assets/demo/index.js +2 -0
- package/es/assets/demo/input.js +12 -5
- package/es/assets/iconfont/iconfont.js +17 -10
- package/es/assets/theme.js +1 -0
- package/es/attrConditions/components/operateList.js +27 -10
- package/es/attrConditions/components/stringList.js +97 -68
- package/es/attrConditions/components/valuesList.js +40 -14
- package/es/attrConditions/demo/group.js +23 -11
- package/es/attrConditions/demo/index.js +26 -17
- package/es/attrConditions/group.js +48 -17
- package/es/attrConditions/index.js +49 -22
- package/es/attrConditions/types.js +1 -0
- package/es/attributeSelector/demo/disable.js +16 -8
- package/es/attributeSelector/demo/index.js +17 -8
- package/es/attributeSelector/index.js +45 -22
- package/es/attributeSelector/listPanel.js +46 -18
- package/es/attributeSelector/option.js +13 -3
- package/es/attributeSelector/types.js +5 -0
- package/es/attributeSelector/util.js +3 -0
- package/es/chart/demo/index.js +14 -5
- package/es/chart/index.js +44 -30
- package/es/chart/util/chartOptionConfig.d.ts +3 -3
- package/es/chart/util/chartOptionConfig.js +37 -13
- package/es/chart/util/data/china.js +4 -1
- package/es/chart/util/formatData.d.ts +2 -2
- package/es/chart/util/formatData.js +5 -0
- package/es/chart/util/formatOption.js +13 -0
- package/es/chart/util/mapUtil.js +26 -5
- package/es/config.js +2 -0
- package/es/constants/apis.d.ts +0 -1
- package/es/constants/apis.js +1 -2
- package/es/cycleTime/demo/disable.js +1 -0
- package/es/cycleTime/index.js +46 -19
- package/es/cycleTime/month.js +27 -8
- package/es/datePicker/datePicker.js +23 -5
- package/es/datePicker/demo/customType.js +22 -13
- package/es/datePicker/demo/day.js +22 -13
- package/es/datePicker/demo/index.js +21 -12
- package/es/datePicker/index.js +41 -18
- package/es/datePicker/utils.js +7 -0
- package/es/demoWrapper/content.d.ts +1 -2
- package/es/demoWrapper/content.js +64 -42
- package/es/demoWrapper/demo/index.js +4 -5
- package/es/demoWrapper/head.d.ts +1 -3
- package/es/demoWrapper/head.js +27 -25
- package/es/demoWrapper/index.js +36 -28
- package/es/dialog/demo/index.js +12 -5
- package/es/dialog/index.js +6 -4
- package/es/dnd/demo/data.js +28 -19
- package/es/dnd/demo/handle.js +28 -19
- package/es/dnd/index.js +45 -21
- package/es/dnd/item.js +30 -10
- package/es/eventSelector/demo/index.js +23 -12
- package/es/eventSelector/index.js +42 -14
- package/es/eventSelector/listPanel.js +73 -31
- package/es/eventSelector/option.js +11 -6
- package/es/icon/iconFont.js +13 -7
- package/es/index.d.ts +1 -2
- package/es/index.js +1 -2
- package/es/layout/analysisLayout/demo/index.js +6 -0
- package/es/layout/analysisLayout/index.d.ts +1 -1
- package/es/layout/analysisLayout/index.js +34 -16
- package/es/layout/detail/index.js +3 -1
- package/es/loginForm/index.js +18 -7
- package/es/searchInput/index.js +7 -2
- package/es/select/demo/children.js +16 -8
- package/es/select/demo/customLabel.js +2 -0
- package/es/select/demo/group.js +17 -8
- package/es/select/demo/index.js +19 -11
- package/es/select/demo/loading.js +18 -8
- package/es/select/demo/multiple.js +16 -8
- package/es/select/handle.js +34 -14
- package/es/select/index.js +59 -22
- package/es/select/option.js +30 -10
- package/es/select/overlay.js +62 -25
- package/es/table/demo/data/table.js +2 -0
- package/es/table/demo/index.js +39 -13
- package/es/table/demo/index2.js +15 -5
- package/es/table/demo/index3.js +28 -7
- package/es/table/index.js +33 -14
- package/es/targetConditionGroup/components/targetDimension.js +38 -12
- package/es/targetConditionGroup/demo/group.js +36 -21
- package/es/targetConditionGroup/demo/index.js +13 -5
- package/es/targetConditionGroup/index.js +84 -31
- package/es/targetSelector/demo/index.js +28 -15
- package/es/targetSelector/editBox.js +20 -5
- package/es/targetSelector/index.js +36 -15
- package/es/targetSelector/optionIcon.js +5 -1
- package/es/targetSelector/optionMenu.js +3 -0
- package/es/userCondition/conditionTypeList.js +12 -7
- package/es/userCondition/conditionWrap.js +2 -0
- package/es/userCondition/conditions/cdpCondition.js +97 -51
- package/es/userCondition/conditions/eventCondition.js +16 -6
- package/es/userCondition/conditions/periodCondition.js +26 -8
- package/es/userCondition/conditions/propCondition.js +61 -29
- package/es/userCondition/conditions/runTimesCondition.js +10 -5
- package/es/userCondition/conditions/tagsCondition.d.ts +1 -1
- package/es/userCondition/conditions/tagsCondition.js +33 -15
- package/es/userCondition/conditions/textDesc.js +67 -16
- package/es/userCondition/demo/index.js +21 -11
- package/es/userCondition/index.js +91 -51
- package/es/userCondition/orConditions.js +48 -11
- package/es/userCondition/relationLabel.js +4 -1
- package/es/userCondition/types.d.ts +1 -1
- package/es/userCondition/types.js +1 -0
- package/es/userCondition/util.js +13 -4
- package/es/userGroup/demo/group.js +23 -14
- package/es/userGroup/demo/index.js +15 -5
- package/es/userGroup/index.js +30 -12
- package/es/userTagsSelector/cascaderOverlay.js +51 -19
- package/es/userTagsSelector/components/search/index.js +2 -0
- package/es/userTagsSelector/demo/index.js +3 -0
- package/es/userTagsSelector/groups/groupOption.js +8 -6
- package/es/userTagsSelector/groups/index.js +30 -15
- package/es/userTagsSelector/index.js +35 -17
- package/es/userTagsSelector/multipleCheckPanel/checkOption.js +6 -3
- package/es/userTagsSelector/multipleCheckPanel/index.js +21 -8
- package/es/userTagsSelector/util.js +2 -0
- package/es/utils/ajax.js +71 -45
- package/es/utils/base64.js +22 -3
- package/es/utils/type.d.ts +1 -1
- package/es/utils/type.js +7 -4
- package/es/utils/util.js +16 -0
- package/package.json +2 -2
- package/es/socket/demo/demo.d.ts +0 -2
- package/es/socket/demo/demo.js +0 -139
- package/es/socket/demo/index.less +0 -27
- package/es/socket/index.d.ts +0 -31
- package/es/socket/index.js +0 -278
- package/es/socket/types.d.ts +0 -37
- package/es/socket/types.js +0 -26
package/es/utils/util.js
CHANGED
|
@@ -37,11 +37,13 @@ var util = {
|
|
|
37
37
|
function s4() {
|
|
38
38
|
return Math.floor((1 + Math.random()) * 0x10000).toString(16).substring(1);
|
|
39
39
|
}
|
|
40
|
+
|
|
40
41
|
return s4() + s4() + '-' + s4() + '-' + s4() + '-' + s4() + '-' + s4() + s4() + s4();
|
|
41
42
|
},
|
|
42
43
|
mergeObject: function mergeObject(defaults, option) {
|
|
43
44
|
defaults = defaults || {};
|
|
44
45
|
option = option || {};
|
|
46
|
+
|
|
45
47
|
for (var prop in defaults) {
|
|
46
48
|
if (this.isObject(defaults[prop])) {
|
|
47
49
|
option[prop] = option[prop] ? option[prop] : {};
|
|
@@ -53,6 +55,7 @@ var util = {
|
|
|
53
55
|
var i = 0;
|
|
54
56
|
var optLenght = option[prop].length;
|
|
55
57
|
var defaultLength = defaults[prop].length;
|
|
58
|
+
|
|
56
59
|
for (i; i < optLenght && i < defaultLength; i++) {
|
|
57
60
|
option[prop][i] = this.mergeObject(defaults[prop][i], option[prop][i]);
|
|
58
61
|
}
|
|
@@ -61,6 +64,7 @@ var util = {
|
|
|
61
64
|
option[prop] = option[prop] === null || option[prop] === undefined ? defaults[prop] : option[prop];
|
|
62
65
|
}
|
|
63
66
|
}
|
|
67
|
+
|
|
64
68
|
return option;
|
|
65
69
|
},
|
|
66
70
|
toThousands: function toThousands(num) {
|
|
@@ -81,6 +85,7 @@ var util = {
|
|
|
81
85
|
var date = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : new Date();
|
|
82
86
|
var formatter = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'hh:mm:ss';
|
|
83
87
|
var autoShort = arguments.length > 2 ? arguments[2] : undefined;
|
|
88
|
+
|
|
84
89
|
if (this.isDate(date)) {
|
|
85
90
|
return formatter.replace('hh', this.toDoubleNumber(date.getHours())).replace('mm', this.toDoubleNumber(date.getMinutes())).replace('ss', this.toDoubleNumber(date.getSeconds()));
|
|
86
91
|
} else if (this.isNumber(date)) {
|
|
@@ -89,13 +94,16 @@ var util = {
|
|
|
89
94
|
var h = parseInt(m / 60 + '');
|
|
90
95
|
s = s - m * 60;
|
|
91
96
|
m = m - h * 60;
|
|
97
|
+
|
|
92
98
|
if (!h && autoShort) {
|
|
93
99
|
formatter = formatter.replace(/hh\S*?mm/, 'mm');
|
|
100
|
+
|
|
94
101
|
if (!m) {
|
|
95
102
|
formatter = formatter.replace(/mm\S*?ss/, 'ss');
|
|
96
103
|
return formatter.replace('ss', s + '');
|
|
97
104
|
}
|
|
98
105
|
}
|
|
106
|
+
|
|
99
107
|
return formatter.replace('hh', this.toDoubleNumber(h)).replace('mm', this.toDoubleNumber(m)).replace('ss', this.toDoubleNumber(s));
|
|
100
108
|
}
|
|
101
109
|
},
|
|
@@ -118,6 +126,7 @@ var util = {
|
|
|
118
126
|
var beginLength = 0;
|
|
119
127
|
var endArr = [];
|
|
120
128
|
var endLength = 0;
|
|
129
|
+
|
|
121
130
|
if (fullLength > config.maxLength) {
|
|
122
131
|
var strArr = str.match(reg.anyChars) || [];
|
|
123
132
|
strArr.forEach(function (char) {
|
|
@@ -134,25 +143,32 @@ var util = {
|
|
|
134
143
|
});
|
|
135
144
|
return beginArr.join('') + config.replaceStr + endArr.reverse().join('');
|
|
136
145
|
}
|
|
146
|
+
|
|
137
147
|
return str;
|
|
138
148
|
},
|
|
139
149
|
setHighLight: function setHighLight(content, search, wrapper) {
|
|
140
150
|
var res = [];
|
|
141
151
|
var match = content.match(_.isRegExp(search) ? search : new RegExp(_.escapeRegExp(search), 'i'));
|
|
152
|
+
|
|
142
153
|
if (!match) {
|
|
143
154
|
res.push(content);
|
|
144
155
|
return res;
|
|
145
156
|
}
|
|
157
|
+
|
|
146
158
|
var text = match[0];
|
|
147
159
|
var matchIndex = match.index;
|
|
160
|
+
|
|
148
161
|
if (matchIndex - 1 >= 0) {
|
|
149
162
|
res.push(content.substring(0, matchIndex));
|
|
150
163
|
}
|
|
164
|
+
|
|
151
165
|
res.push(wrapper(text, "".concat(content, "-").concat(search)));
|
|
166
|
+
|
|
152
167
|
if (matchIndex + text.length < content.length) {
|
|
153
168
|
var beginIndex = matchIndex + text.length;
|
|
154
169
|
res.push(this.setHighLight(content.substring(beginIndex, content.length), search, wrapper));
|
|
155
170
|
}
|
|
171
|
+
|
|
156
172
|
return res;
|
|
157
173
|
}
|
|
158
174
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zgfe/business-lib",
|
|
3
|
-
"version": "1.1.29
|
|
3
|
+
"version": "1.1.29",
|
|
4
4
|
"scripts": {
|
|
5
5
|
"start": "dumi dev",
|
|
6
6
|
"docs:build": "dumi build",
|
|
@@ -59,5 +59,5 @@
|
|
|
59
59
|
"react": "^16.12.0 || ^17.0.0",
|
|
60
60
|
"yorkie": "^2.0.0"
|
|
61
61
|
},
|
|
62
|
-
"gitHead": "
|
|
62
|
+
"gitHead": "c4bbf49197e719bf3674f1b30402f5f879c0ecc5"
|
|
63
63
|
}
|
package/es/socket/demo/demo.d.ts
DELETED
package/es/socket/demo/demo.js
DELETED
|
@@ -1,139 +0,0 @@
|
|
|
1
|
-
function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
|
|
2
|
-
function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
3
|
-
function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
|
|
4
|
-
function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
|
|
5
|
-
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
|
|
6
|
-
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
7
|
-
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
8
|
-
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
|
|
9
|
-
function _iterableToArrayLimit(arr, i) { var _i = null == arr ? null : "undefined" != typeof Symbol && arr[Symbol.iterator] || arr["@@iterator"]; if (null != _i) { var _s, _e, _x, _r, _arr = [], _n = !0, _d = !1; try { if (_x = (_i = _i.call(arr)).next, 0 === i) { if (Object(_i) !== _i) return; _n = !1; } else for (; !(_n = (_s = _x.call(_i)).done) && (_arr.push(_s.value), _arr.length !== i); _n = !0); } catch (err) { _d = !0, _e = err; } finally { try { if (!_n && null != _i.return && (_r = _i.return(), Object(_r) !== _r)) return; } finally { if (_d) throw _e; } } return _arr; } }
|
|
10
|
-
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
11
|
-
import React, { useContext, useEffect, useRef, useState } from 'react';
|
|
12
|
-
import { SocketClient } from '@zgfe/business-lib';
|
|
13
|
-
import { Button, Card, Form, Input, notification } from 'antd';
|
|
14
|
-
import styles from './index.less';
|
|
15
|
-
import { DemoWrapper, BizGlobalDataContext } from '@zgfe/business-lib';
|
|
16
|
-
var ChatPanel = function ChatPanel(_ref) {
|
|
17
|
-
var name = _ref.name,
|
|
18
|
-
param = _ref.param;
|
|
19
|
-
var _useState = useState(),
|
|
20
|
-
_useState2 = _slicedToArray(_useState, 2),
|
|
21
|
-
client = _useState2[0],
|
|
22
|
-
setClient = _useState2[1];
|
|
23
|
-
var _useState3 = useState([]),
|
|
24
|
-
_useState4 = _slicedToArray(_useState3, 2),
|
|
25
|
-
history = _useState4[0],
|
|
26
|
-
setHistory = _useState4[1];
|
|
27
|
-
var _useState5 = useState(true),
|
|
28
|
-
_useState6 = _slicedToArray(_useState5, 2),
|
|
29
|
-
online = _useState6[0],
|
|
30
|
-
setOnline = _useState6[1];
|
|
31
|
-
var formRef = useRef();
|
|
32
|
-
var historyRef = useRef();
|
|
33
|
-
var _useContext = useContext(BizGlobalDataContext),
|
|
34
|
-
currentApp = _useContext.currentApp;
|
|
35
|
-
useEffect(function () {
|
|
36
|
-
setClient(new SocketClient('wss://rt2.zhugeio.com/eventtracking/ws', currentApp === null || currentApp === void 0 ? void 0 : currentApp.appKey, param));
|
|
37
|
-
}, []);
|
|
38
|
-
useEffect(function () {
|
|
39
|
-
var _historyRef$current;
|
|
40
|
-
if (historyRef.current) historyRef.current.scrollTop = (_historyRef$current = historyRef.current) === null || _historyRef$current === void 0 ? void 0 : _historyRef$current.scrollHeight;
|
|
41
|
-
}, [history]);
|
|
42
|
-
useEffect(function () {
|
|
43
|
-
if (!client) return;
|
|
44
|
-
client.openLog(true);
|
|
45
|
-
client.onConnected(onConnected);
|
|
46
|
-
client.onError(onError);
|
|
47
|
-
client.on('offline', function () {
|
|
48
|
-
setHistory(function (list) {
|
|
49
|
-
return [].concat(_toConsumableArray(list), [{
|
|
50
|
-
type: 'he',
|
|
51
|
-
message: '对方已下线'
|
|
52
|
-
}]);
|
|
53
|
-
});
|
|
54
|
-
});
|
|
55
|
-
client.on('exist', function () {
|
|
56
|
-
console.log('连接已存在');
|
|
57
|
-
});
|
|
58
|
-
client.on('message', function (message) {
|
|
59
|
-
setHistory(function (list) {
|
|
60
|
-
return [].concat(_toConsumableArray(list), [{
|
|
61
|
-
type: 'he',
|
|
62
|
-
message: message
|
|
63
|
-
}]);
|
|
64
|
-
});
|
|
65
|
-
});
|
|
66
|
-
}, [client]);
|
|
67
|
-
function onConnected() {
|
|
68
|
-
notification.success({
|
|
69
|
-
message: '连接成功'
|
|
70
|
-
});
|
|
71
|
-
}
|
|
72
|
-
function onError(err) {
|
|
73
|
-
notification.error({
|
|
74
|
-
message: '连接失败',
|
|
75
|
-
description: err.message
|
|
76
|
-
});
|
|
77
|
-
}
|
|
78
|
-
return /*#__PURE__*/React.createElement(Card, {
|
|
79
|
-
title: name
|
|
80
|
-
}, /*#__PURE__*/React.createElement("div", {
|
|
81
|
-
className: styles.history,
|
|
82
|
-
ref: historyRef
|
|
83
|
-
}, history.map(function (item, i) {
|
|
84
|
-
return /*#__PURE__*/React.createElement("div", {
|
|
85
|
-
className: styles[item.type],
|
|
86
|
-
key: i
|
|
87
|
-
}, item.type, ": ", item.message);
|
|
88
|
-
})), /*#__PURE__*/React.createElement("div", {
|
|
89
|
-
className: styles.footer
|
|
90
|
-
}, /*#__PURE__*/React.createElement(Form, {
|
|
91
|
-
ref: formRef,
|
|
92
|
-
autoComplete: "off",
|
|
93
|
-
onFinish: function onFinish(_ref2) {
|
|
94
|
-
var _formRef$current;
|
|
95
|
-
var message = _ref2.message;
|
|
96
|
-
client.emit('message', message);
|
|
97
|
-
setHistory(function (list) {
|
|
98
|
-
return [].concat(_toConsumableArray(list), [{
|
|
99
|
-
type: 'me',
|
|
100
|
-
message: message
|
|
101
|
-
}]);
|
|
102
|
-
});
|
|
103
|
-
(_formRef$current = formRef.current) === null || _formRef$current === void 0 ? void 0 : _formRef$current.resetFields();
|
|
104
|
-
}
|
|
105
|
-
}, /*#__PURE__*/React.createElement(Form.Item, {
|
|
106
|
-
name: "message"
|
|
107
|
-
}, /*#__PURE__*/React.createElement(Input, {
|
|
108
|
-
placeholder: "\u56DE\u8F66\u53D1\u9001\u4FE1\u606F",
|
|
109
|
-
autoFocus: true
|
|
110
|
-
})), /*#__PURE__*/React.createElement(Form.Item, null, /*#__PURE__*/React.createElement(Button, {
|
|
111
|
-
onClick: function onClick() {
|
|
112
|
-
if (online) {
|
|
113
|
-
client.close();
|
|
114
|
-
} else {
|
|
115
|
-
client.open();
|
|
116
|
-
}
|
|
117
|
-
setOnline(!online);
|
|
118
|
-
}
|
|
119
|
-
}, online ? '下线' : '上线')))));
|
|
120
|
-
};
|
|
121
|
-
export default (function () {
|
|
122
|
-
var ctx = useContext(BizGlobalDataContext);
|
|
123
|
-
var currentApp = ctx.currentApp;
|
|
124
|
-
return /*#__PURE__*/React.createElement(DemoWrapper, null, /*#__PURE__*/React.createElement("div", {
|
|
125
|
-
className: styles.container
|
|
126
|
-
}, /*#__PURE__*/React.createElement(ChatPanel, {
|
|
127
|
-
name: "\u5F20\u4E09",
|
|
128
|
-
param: {
|
|
129
|
-
appId: currentApp === null || currentApp === void 0 ? void 0 : currentApp.appId,
|
|
130
|
-
origin: 3
|
|
131
|
-
}
|
|
132
|
-
}), /*#__PURE__*/React.createElement(ChatPanel, {
|
|
133
|
-
name: "\u674E\u56DB",
|
|
134
|
-
param: {
|
|
135
|
-
appId: currentApp === null || currentApp === void 0 ? void 0 : currentApp.appId,
|
|
136
|
-
origin: 5
|
|
137
|
-
}
|
|
138
|
-
})));
|
|
139
|
-
});
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
@import '../../assets/styles/inner.less';
|
|
2
|
-
.container {
|
|
3
|
-
display: flex;
|
|
4
|
-
flex-direction: row;
|
|
5
|
-
border: 1px solid red;
|
|
6
|
-
& > :global(.ant-card) {
|
|
7
|
-
flex: 1;
|
|
8
|
-
margin: @margin-md;
|
|
9
|
-
}
|
|
10
|
-
}
|
|
11
|
-
.history {
|
|
12
|
-
height: 400px;
|
|
13
|
-
overflow: auto;
|
|
14
|
-
}
|
|
15
|
-
.he,
|
|
16
|
-
.me {
|
|
17
|
-
margin-bottom: @margin-sm;
|
|
18
|
-
padding: @padding-sm;
|
|
19
|
-
line-height: 24px;
|
|
20
|
-
background: @background-color-base;
|
|
21
|
-
}
|
|
22
|
-
.he {
|
|
23
|
-
text-align: left;
|
|
24
|
-
}
|
|
25
|
-
.me {
|
|
26
|
-
text-align: right;
|
|
27
|
-
}
|
package/es/socket/index.d.ts
DELETED
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
import SocketClientTypes from './types';
|
|
2
|
-
declare class SocketClient {
|
|
3
|
-
private client?;
|
|
4
|
-
private url;
|
|
5
|
-
private params?;
|
|
6
|
-
private listeners;
|
|
7
|
-
private catch;
|
|
8
|
-
private showLog;
|
|
9
|
-
private pingTimer?;
|
|
10
|
-
private appkey?;
|
|
11
|
-
constructor(url: string, appkey: string, params?: Record<string, any>);
|
|
12
|
-
emit(event: string, payload: SocketClientTypes.Message['data']['payload']): void;
|
|
13
|
-
on(type: SocketClientTypes.EventType | string, handle: SocketClientTypes.Handler): void;
|
|
14
|
-
onConnected(handle: SocketClientTypes.Handler): void;
|
|
15
|
-
onDisconnected(handle: SocketClientTypes.Handler): void;
|
|
16
|
-
onError(handle: SocketClientTypes.Handler): void;
|
|
17
|
-
private _onError;
|
|
18
|
-
private _onClose;
|
|
19
|
-
private _onOpen;
|
|
20
|
-
private onMessage;
|
|
21
|
-
private ping;
|
|
22
|
-
removeAllListeners(): void;
|
|
23
|
-
removeListener(event: string, handle?: SocketClientTypes.Handler): void;
|
|
24
|
-
private getToken;
|
|
25
|
-
open(url?: string, params?: Record<string, any>): void;
|
|
26
|
-
close(): void;
|
|
27
|
-
destroy(): void;
|
|
28
|
-
private log;
|
|
29
|
-
openLog(open: boolean): void;
|
|
30
|
-
}
|
|
31
|
-
export default SocketClient;
|
package/es/socket/index.js
DELETED
|
@@ -1,278 +0,0 @@
|
|
|
1
|
-
function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
|
|
2
|
-
function _regeneratorRuntime() { "use strict"; /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */ _regeneratorRuntime = function _regeneratorRuntime() { return exports; }; var exports = {}, Op = Object.prototype, hasOwn = Op.hasOwnProperty, defineProperty = Object.defineProperty || function (obj, key, desc) { obj[key] = desc.value; }, $Symbol = "function" == typeof Symbol ? Symbol : {}, iteratorSymbol = $Symbol.iterator || "@@iterator", asyncIteratorSymbol = $Symbol.asyncIterator || "@@asyncIterator", toStringTagSymbol = $Symbol.toStringTag || "@@toStringTag"; function define(obj, key, value) { return Object.defineProperty(obj, key, { value: value, enumerable: !0, configurable: !0, writable: !0 }), obj[key]; } try { define({}, ""); } catch (err) { define = function define(obj, key, value) { return obj[key] = value; }; } function wrap(innerFn, outerFn, self, tryLocsList) { var protoGenerator = outerFn && outerFn.prototype instanceof Generator ? outerFn : Generator, generator = Object.create(protoGenerator.prototype), context = new Context(tryLocsList || []); return defineProperty(generator, "_invoke", { value: makeInvokeMethod(innerFn, self, context) }), generator; } function tryCatch(fn, obj, arg) { try { return { type: "normal", arg: fn.call(obj, arg) }; } catch (err) { return { type: "throw", arg: err }; } } exports.wrap = wrap; var ContinueSentinel = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} var IteratorPrototype = {}; define(IteratorPrototype, iteratorSymbol, function () { return this; }); var getProto = Object.getPrototypeOf, NativeIteratorPrototype = getProto && getProto(getProto(values([]))); NativeIteratorPrototype && NativeIteratorPrototype !== Op && hasOwn.call(NativeIteratorPrototype, iteratorSymbol) && (IteratorPrototype = NativeIteratorPrototype); var Gp = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(IteratorPrototype); function defineIteratorMethods(prototype) { ["next", "throw", "return"].forEach(function (method) { define(prototype, method, function (arg) { return this._invoke(method, arg); }); }); } function AsyncIterator(generator, PromiseImpl) { function invoke(method, arg, resolve, reject) { var record = tryCatch(generator[method], generator, arg); if ("throw" !== record.type) { var result = record.arg, value = result.value; return value && "object" == _typeof(value) && hasOwn.call(value, "__await") ? PromiseImpl.resolve(value.__await).then(function (value) { invoke("next", value, resolve, reject); }, function (err) { invoke("throw", err, resolve, reject); }) : PromiseImpl.resolve(value).then(function (unwrapped) { result.value = unwrapped, resolve(result); }, function (error) { return invoke("throw", error, resolve, reject); }); } reject(record.arg); } var previousPromise; defineProperty(this, "_invoke", { value: function value(method, arg) { function callInvokeWithMethodAndArg() { return new PromiseImpl(function (resolve, reject) { invoke(method, arg, resolve, reject); }); } return previousPromise = previousPromise ? previousPromise.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg(); } }); } function makeInvokeMethod(innerFn, self, context) { var state = "suspendedStart"; return function (method, arg) { if ("executing" === state) throw new Error("Generator is already running"); if ("completed" === state) { if ("throw" === method) throw arg; return doneResult(); } for (context.method = method, context.arg = arg;;) { var delegate = context.delegate; if (delegate) { var delegateResult = maybeInvokeDelegate(delegate, context); if (delegateResult) { if (delegateResult === ContinueSentinel) continue; return delegateResult; } } if ("next" === context.method) context.sent = context._sent = context.arg;else if ("throw" === context.method) { if ("suspendedStart" === state) throw state = "completed", context.arg; context.dispatchException(context.arg); } else "return" === context.method && context.abrupt("return", context.arg); state = "executing"; var record = tryCatch(innerFn, self, context); if ("normal" === record.type) { if (state = context.done ? "completed" : "suspendedYield", record.arg === ContinueSentinel) continue; return { value: record.arg, done: context.done }; } "throw" === record.type && (state = "completed", context.method = "throw", context.arg = record.arg); } }; } function maybeInvokeDelegate(delegate, context) { var methodName = context.method, method = delegate.iterator[methodName]; if (undefined === method) return context.delegate = null, "throw" === methodName && delegate.iterator.return && (context.method = "return", context.arg = undefined, maybeInvokeDelegate(delegate, context), "throw" === context.method) || "return" !== methodName && (context.method = "throw", context.arg = new TypeError("The iterator does not provide a '" + methodName + "' method")), ContinueSentinel; var record = tryCatch(method, delegate.iterator, context.arg); if ("throw" === record.type) return context.method = "throw", context.arg = record.arg, context.delegate = null, ContinueSentinel; var info = record.arg; return info ? info.done ? (context[delegate.resultName] = info.value, context.next = delegate.nextLoc, "return" !== context.method && (context.method = "next", context.arg = undefined), context.delegate = null, ContinueSentinel) : info : (context.method = "throw", context.arg = new TypeError("iterator result is not an object"), context.delegate = null, ContinueSentinel); } function pushTryEntry(locs) { var entry = { tryLoc: locs[0] }; 1 in locs && (entry.catchLoc = locs[1]), 2 in locs && (entry.finallyLoc = locs[2], entry.afterLoc = locs[3]), this.tryEntries.push(entry); } function resetTryEntry(entry) { var record = entry.completion || {}; record.type = "normal", delete record.arg, entry.completion = record; } function Context(tryLocsList) { this.tryEntries = [{ tryLoc: "root" }], tryLocsList.forEach(pushTryEntry, this), this.reset(!0); } function values(iterable) { if (iterable) { var iteratorMethod = iterable[iteratorSymbol]; if (iteratorMethod) return iteratorMethod.call(iterable); if ("function" == typeof iterable.next) return iterable; if (!isNaN(iterable.length)) { var i = -1, next = function next() { for (; ++i < iterable.length;) if (hasOwn.call(iterable, i)) return next.value = iterable[i], next.done = !1, next; return next.value = undefined, next.done = !0, next; }; return next.next = next; } } return { next: doneResult }; } function doneResult() { return { value: undefined, done: !0 }; } return GeneratorFunction.prototype = GeneratorFunctionPrototype, defineProperty(Gp, "constructor", { value: GeneratorFunctionPrototype, configurable: !0 }), defineProperty(GeneratorFunctionPrototype, "constructor", { value: GeneratorFunction, configurable: !0 }), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, toStringTagSymbol, "GeneratorFunction"), exports.isGeneratorFunction = function (genFun) { var ctor = "function" == typeof genFun && genFun.constructor; return !!ctor && (ctor === GeneratorFunction || "GeneratorFunction" === (ctor.displayName || ctor.name)); }, exports.mark = function (genFun) { return Object.setPrototypeOf ? Object.setPrototypeOf(genFun, GeneratorFunctionPrototype) : (genFun.__proto__ = GeneratorFunctionPrototype, define(genFun, toStringTagSymbol, "GeneratorFunction")), genFun.prototype = Object.create(Gp), genFun; }, exports.awrap = function (arg) { return { __await: arg }; }, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, asyncIteratorSymbol, function () { return this; }), exports.AsyncIterator = AsyncIterator, exports.async = function (innerFn, outerFn, self, tryLocsList, PromiseImpl) { void 0 === PromiseImpl && (PromiseImpl = Promise); var iter = new AsyncIterator(wrap(innerFn, outerFn, self, tryLocsList), PromiseImpl); return exports.isGeneratorFunction(outerFn) ? iter : iter.next().then(function (result) { return result.done ? result.value : iter.next(); }); }, defineIteratorMethods(Gp), define(Gp, toStringTagSymbol, "Generator"), define(Gp, iteratorSymbol, function () { return this; }), define(Gp, "toString", function () { return "[object Generator]"; }), exports.keys = function (val) { var object = Object(val), keys = []; for (var key in object) keys.push(key); return keys.reverse(), function next() { for (; keys.length;) { var key = keys.pop(); if (key in object) return next.value = key, next.done = !1, next; } return next.done = !0, next; }; }, exports.values = values, Context.prototype = { constructor: Context, reset: function reset(skipTempReset) { if (this.prev = 0, this.next = 0, this.sent = this._sent = undefined, this.done = !1, this.delegate = null, this.method = "next", this.arg = undefined, this.tryEntries.forEach(resetTryEntry), !skipTempReset) for (var name in this) "t" === name.charAt(0) && hasOwn.call(this, name) && !isNaN(+name.slice(1)) && (this[name] = undefined); }, stop: function stop() { this.done = !0; var rootRecord = this.tryEntries[0].completion; if ("throw" === rootRecord.type) throw rootRecord.arg; return this.rval; }, dispatchException: function dispatchException(exception) { if (this.done) throw exception; var context = this; function handle(loc, caught) { return record.type = "throw", record.arg = exception, context.next = loc, caught && (context.method = "next", context.arg = undefined), !!caught; } for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i], record = entry.completion; if ("root" === entry.tryLoc) return handle("end"); if (entry.tryLoc <= this.prev) { var hasCatch = hasOwn.call(entry, "catchLoc"), hasFinally = hasOwn.call(entry, "finallyLoc"); if (hasCatch && hasFinally) { if (this.prev < entry.catchLoc) return handle(entry.catchLoc, !0); if (this.prev < entry.finallyLoc) return handle(entry.finallyLoc); } else if (hasCatch) { if (this.prev < entry.catchLoc) return handle(entry.catchLoc, !0); } else { if (!hasFinally) throw new Error("try statement without catch or finally"); if (this.prev < entry.finallyLoc) return handle(entry.finallyLoc); } } } }, abrupt: function abrupt(type, arg) { for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i]; if (entry.tryLoc <= this.prev && hasOwn.call(entry, "finallyLoc") && this.prev < entry.finallyLoc) { var finallyEntry = entry; break; } } finallyEntry && ("break" === type || "continue" === type) && finallyEntry.tryLoc <= arg && arg <= finallyEntry.finallyLoc && (finallyEntry = null); var record = finallyEntry ? finallyEntry.completion : {}; return record.type = type, record.arg = arg, finallyEntry ? (this.method = "next", this.next = finallyEntry.finallyLoc, ContinueSentinel) : this.complete(record); }, complete: function complete(record, afterLoc) { if ("throw" === record.type) throw record.arg; return "break" === record.type || "continue" === record.type ? this.next = record.arg : "return" === record.type ? (this.rval = this.arg = record.arg, this.method = "return", this.next = "end") : "normal" === record.type && afterLoc && (this.next = afterLoc), ContinueSentinel; }, finish: function finish(finallyLoc) { for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i]; if (entry.finallyLoc === finallyLoc) return this.complete(entry.completion, entry.afterLoc), resetTryEntry(entry), ContinueSentinel; } }, catch: function _catch(tryLoc) { for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i]; if (entry.tryLoc === tryLoc) { var record = entry.completion; if ("throw" === record.type) { var thrown = record.arg; resetTryEntry(entry); } return thrown; } } throw new Error("illegal catch attempt"); }, delegateYield: function delegateYield(iterable, resultName, nextLoc) { return this.delegate = { iterator: values(iterable), resultName: resultName, nextLoc: nextLoc }, "next" === this.method && (this.arg = undefined), ContinueSentinel; } }, exports; }
|
|
3
|
-
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
|
|
4
|
-
function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
|
|
5
|
-
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
|
|
6
|
-
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
7
|
-
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
8
|
-
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
|
|
9
|
-
function _iterableToArrayLimit(arr, i) { var _i = null == arr ? null : "undefined" != typeof Symbol && arr[Symbol.iterator] || arr["@@iterator"]; if (null != _i) { var _s, _e, _x, _r, _arr = [], _n = !0, _d = !1; try { if (_x = (_i = _i.call(arr)).next, 0 === i) { if (Object(_i) !== _i) return; _n = !1; } else for (; !(_n = (_s = _x.call(_i)).done) && (_arr.push(_s.value), _arr.length !== i); _n = !0); } catch (err) { _d = !0, _e = err; } finally { try { if (!_n && null != _i.return && (_r = _i.return(), Object(_r) !== _r)) return; } finally { if (_d) throw _e; } } return _arr; } }
|
|
10
|
-
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
11
|
-
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
12
|
-
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor); } }
|
|
13
|
-
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
|
|
14
|
-
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
|
|
15
|
-
function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
|
|
16
|
-
import { notification } from 'antd';
|
|
17
|
-
import _ from 'lodash';
|
|
18
|
-
import request from 'umi-request';
|
|
19
|
-
import Apis from '../constants/apis';
|
|
20
|
-
import SocketClientTypes from './types';
|
|
21
|
-
var SocketClient = /*#__PURE__*/function () {
|
|
22
|
-
function SocketClient(url, appkey, params) {
|
|
23
|
-
_classCallCheck(this, SocketClient);
|
|
24
|
-
this.client = void 0;
|
|
25
|
-
this.url = void 0;
|
|
26
|
-
this.params = void 0;
|
|
27
|
-
this.listeners = {};
|
|
28
|
-
this.catch = [];
|
|
29
|
-
this.showLog = false;
|
|
30
|
-
this.pingTimer = void 0;
|
|
31
|
-
this.appkey = void 0;
|
|
32
|
-
this.appkey = appkey;
|
|
33
|
-
this.url = url;
|
|
34
|
-
this.params = params;
|
|
35
|
-
this.open();
|
|
36
|
-
}
|
|
37
|
-
_createClass(SocketClient, [{
|
|
38
|
-
key: "emit",
|
|
39
|
-
value: function emit(event, payload) {
|
|
40
|
-
var _this$client, _this$client2;
|
|
41
|
-
switch ((_this$client = this.client) === null || _this$client === void 0 ? void 0 : _this$client.readyState) {
|
|
42
|
-
case WebSocket.CLOSED:
|
|
43
|
-
notification.warn({
|
|
44
|
-
message: '连接已关闭'
|
|
45
|
-
});
|
|
46
|
-
break;
|
|
47
|
-
case WebSocket.CLOSING:
|
|
48
|
-
notification.warn({
|
|
49
|
-
message: '正在关闭连接'
|
|
50
|
-
});
|
|
51
|
-
break;
|
|
52
|
-
case WebSocket.CONNECTING:
|
|
53
|
-
notification.warn({
|
|
54
|
-
message: '连接中'
|
|
55
|
-
});
|
|
56
|
-
this.catch.push([event, payload]);
|
|
57
|
-
break;
|
|
58
|
-
case WebSocket.OPEN:
|
|
59
|
-
(_this$client2 = this.client) === null || _this$client2 === void 0 ? void 0 : _this$client2.send(JSON.stringify({
|
|
60
|
-
type: SocketClientTypes.RequestType.normal,
|
|
61
|
-
data: {
|
|
62
|
-
event: event,
|
|
63
|
-
payload: payload
|
|
64
|
-
}
|
|
65
|
-
}));
|
|
66
|
-
break;
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
}, {
|
|
70
|
-
key: "on",
|
|
71
|
-
value: function on(type, handle) {
|
|
72
|
-
if (!this.listeners[type]) {
|
|
73
|
-
this.listeners[type] = [];
|
|
74
|
-
}
|
|
75
|
-
this.listeners[type].push(handle);
|
|
76
|
-
}
|
|
77
|
-
}, {
|
|
78
|
-
key: "onConnected",
|
|
79
|
-
value: function onConnected(handle) {
|
|
80
|
-
this.on(SocketClientTypes.EventType.connected, handle);
|
|
81
|
-
}
|
|
82
|
-
}, {
|
|
83
|
-
key: "onDisconnected",
|
|
84
|
-
value: function onDisconnected(handle) {
|
|
85
|
-
this.on(SocketClientTypes.EventType.disconnected, handle);
|
|
86
|
-
}
|
|
87
|
-
}, {
|
|
88
|
-
key: "onError",
|
|
89
|
-
value: function onError(handle) {
|
|
90
|
-
this.on(SocketClientTypes.EventType.error, handle);
|
|
91
|
-
}
|
|
92
|
-
}, {
|
|
93
|
-
key: "_onError",
|
|
94
|
-
value: function _onError(error) {
|
|
95
|
-
var _this$listeners$error;
|
|
96
|
-
this.log('error', 'socket连接异常', error);
|
|
97
|
-
(_this$listeners$error = this.listeners['error']) === null || _this$listeners$error === void 0 ? void 0 : _this$listeners$error.forEach(function (handle) {
|
|
98
|
-
handle.call(undefined, error);
|
|
99
|
-
});
|
|
100
|
-
}
|
|
101
|
-
}, {
|
|
102
|
-
key: "_onClose",
|
|
103
|
-
value: function _onClose(_event) {
|
|
104
|
-
var _this$listeners$disco;
|
|
105
|
-
this.log('error', 'socket连接已关闭');
|
|
106
|
-
(_this$listeners$disco = this.listeners['disconnected']) === null || _this$listeners$disco === void 0 ? void 0 : _this$listeners$disco.forEach(function (handle) {
|
|
107
|
-
handle.call(undefined);
|
|
108
|
-
});
|
|
109
|
-
clearInterval(this.pingTimer);
|
|
110
|
-
}
|
|
111
|
-
}, {
|
|
112
|
-
key: "_onOpen",
|
|
113
|
-
value: function _onOpen(event) {
|
|
114
|
-
var _this$listeners$conne,
|
|
115
|
-
_this = this;
|
|
116
|
-
this.log('info', 'socket连接成功', event);
|
|
117
|
-
(_this$listeners$conne = this.listeners['connected']) === null || _this$listeners$conne === void 0 ? void 0 : _this$listeners$conne.forEach(function (handle) {
|
|
118
|
-
handle.call(undefined);
|
|
119
|
-
});
|
|
120
|
-
this.catch.forEach(function (_ref) {
|
|
121
|
-
var _ref2 = _slicedToArray(_ref, 2),
|
|
122
|
-
event = _ref2[0],
|
|
123
|
-
payload = _ref2[1];
|
|
124
|
-
_this.emit(event, payload);
|
|
125
|
-
});
|
|
126
|
-
this.catch = [];
|
|
127
|
-
this.ping();
|
|
128
|
-
}
|
|
129
|
-
}, {
|
|
130
|
-
key: "onMessage",
|
|
131
|
-
value: function onMessage(event) {
|
|
132
|
-
var _this$listeners$Socke, _this$listeners$Socke2;
|
|
133
|
-
var res = JSON.parse(event.data);
|
|
134
|
-
if (res.code) {
|
|
135
|
-
switch (Number(res.code)) {
|
|
136
|
-
case SocketClientTypes.ResponseCode.offline:
|
|
137
|
-
(_this$listeners$Socke = this.listeners[SocketClientTypes.EventType.offline]) === null || _this$listeners$Socke === void 0 ? void 0 : _this$listeners$Socke.forEach(function (handle) {
|
|
138
|
-
handle.call(undefined, res);
|
|
139
|
-
});
|
|
140
|
-
break;
|
|
141
|
-
case SocketClientTypes.ResponseCode.exist:
|
|
142
|
-
(_this$listeners$Socke2 = this.listeners[SocketClientTypes.EventType.exist]) === null || _this$listeners$Socke2 === void 0 ? void 0 : _this$listeners$Socke2.forEach(function (handle) {
|
|
143
|
-
handle.call(undefined, res);
|
|
144
|
-
});
|
|
145
|
-
break;
|
|
146
|
-
case SocketClientTypes.ResponseCode.paramError:
|
|
147
|
-
this._onError(new Error('参数缺失或错误'));
|
|
148
|
-
}
|
|
149
|
-
} else if (res.type === SocketClientTypes.RequestType.pong) {
|
|
150
|
-
return;
|
|
151
|
-
} else {
|
|
152
|
-
var data = res.data;
|
|
153
|
-
if (this.listeners[data.event]) {
|
|
154
|
-
this.listeners[data.event].forEach(function (handle) {
|
|
155
|
-
handle.call(undefined, data.payload);
|
|
156
|
-
});
|
|
157
|
-
}
|
|
158
|
-
}
|
|
159
|
-
}
|
|
160
|
-
}, {
|
|
161
|
-
key: "ping",
|
|
162
|
-
value: function ping() {
|
|
163
|
-
var _this2 = this;
|
|
164
|
-
this.pingTimer = setInterval(function () {
|
|
165
|
-
var _this2$client;
|
|
166
|
-
(_this2$client = _this2.client) === null || _this2$client === void 0 ? void 0 : _this2$client.send(JSON.stringify({
|
|
167
|
-
type: SocketClientTypes.RequestType.ping
|
|
168
|
-
}));
|
|
169
|
-
}, 3000);
|
|
170
|
-
}
|
|
171
|
-
}, {
|
|
172
|
-
key: "removeAllListeners",
|
|
173
|
-
value: function removeAllListeners() {
|
|
174
|
-
this.listeners = {};
|
|
175
|
-
}
|
|
176
|
-
}, {
|
|
177
|
-
key: "removeListener",
|
|
178
|
-
value: function removeListener(event, handle) {
|
|
179
|
-
var _this3 = this;
|
|
180
|
-
if (handle) {
|
|
181
|
-
this.listeners[event].forEach(function (item, i) {
|
|
182
|
-
if (item === handle) {
|
|
183
|
-
_this3.listeners[event].splice(i, 1);
|
|
184
|
-
}
|
|
185
|
-
});
|
|
186
|
-
} else {
|
|
187
|
-
this.listeners[event] = [];
|
|
188
|
-
}
|
|
189
|
-
}
|
|
190
|
-
}, {
|
|
191
|
-
key: "getToken",
|
|
192
|
-
value: function () {
|
|
193
|
-
var _getToken = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
|
|
194
|
-
var res;
|
|
195
|
-
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
196
|
-
while (1) switch (_context.prev = _context.next) {
|
|
197
|
-
case 0:
|
|
198
|
-
_context.next = 2;
|
|
199
|
-
return request(Apis.getSocketToken, {
|
|
200
|
-
method: 'get',
|
|
201
|
-
params: {
|
|
202
|
-
appKey: this.appkey
|
|
203
|
-
}
|
|
204
|
-
});
|
|
205
|
-
case 2:
|
|
206
|
-
res = _context.sent;
|
|
207
|
-
return _context.abrupt("return", res.data.socketToken);
|
|
208
|
-
case 4:
|
|
209
|
-
case "end":
|
|
210
|
-
return _context.stop();
|
|
211
|
-
}
|
|
212
|
-
}, _callee, this);
|
|
213
|
-
}));
|
|
214
|
-
function getToken() {
|
|
215
|
-
return _getToken.apply(this, arguments);
|
|
216
|
-
}
|
|
217
|
-
return getToken;
|
|
218
|
-
}()
|
|
219
|
-
}, {
|
|
220
|
-
key: "open",
|
|
221
|
-
value: function open(url, params) {
|
|
222
|
-
var _this4 = this;
|
|
223
|
-
this.getToken().then(function (token) {
|
|
224
|
-
_this4.params = params || _this4.params;
|
|
225
|
-
if (_this4.client) _this4.close();
|
|
226
|
-
var paramUrl = ["socketToken=".concat(token)];
|
|
227
|
-
if (_this4.params) {
|
|
228
|
-
Object.keys(_this4.params || {}).forEach(function (key) {
|
|
229
|
-
if (_.isObject(_this4.params[key]) || _.isArray(_this4.params[key])) {
|
|
230
|
-
paramUrl.push("".concat(key, "=").concat(JSON.stringify(_this4.params[key])));
|
|
231
|
-
} else {
|
|
232
|
-
paramUrl.push("".concat(key, "=").concat(_this4.params[key]));
|
|
233
|
-
}
|
|
234
|
-
});
|
|
235
|
-
}
|
|
236
|
-
var client = new WebSocket("".concat(url || _this4.url, "?").concat(paramUrl.join('&')));
|
|
237
|
-
_this4.client = client;
|
|
238
|
-
client.onmessage = _this4.onMessage.bind(_this4);
|
|
239
|
-
client.onerror = _this4._onError.bind(_this4);
|
|
240
|
-
client.onclose = _this4._onClose.bind(_this4);
|
|
241
|
-
client.onopen = _this4._onOpen.bind(_this4);
|
|
242
|
-
}).catch(function (err) {
|
|
243
|
-
_this4.log('error', 'socket获取token信息异常');
|
|
244
|
-
_this4._onError(err);
|
|
245
|
-
});
|
|
246
|
-
}
|
|
247
|
-
}, {
|
|
248
|
-
key: "close",
|
|
249
|
-
value: function close() {
|
|
250
|
-
var _this$client3;
|
|
251
|
-
(_this$client3 = this.client) === null || _this$client3 === void 0 ? void 0 : _this$client3.close();
|
|
252
|
-
this.log('info', '关闭socket连接');
|
|
253
|
-
}
|
|
254
|
-
}, {
|
|
255
|
-
key: "destroy",
|
|
256
|
-
value: function destroy() {
|
|
257
|
-
this.removeAllListeners();
|
|
258
|
-
this.close();
|
|
259
|
-
this.client = undefined;
|
|
260
|
-
}
|
|
261
|
-
}, {
|
|
262
|
-
key: "log",
|
|
263
|
-
value: function log(type) {
|
|
264
|
-
var _console;
|
|
265
|
-
for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
|
|
266
|
-
args[_key - 1] = arguments[_key];
|
|
267
|
-
}
|
|
268
|
-
if (this.showLog) (_console = console).log.apply(_console, ["%c\u3010socketClient\u3011:".concat(type), "color: ".concat(type === 'error' ? 'red' : '#1890ff')].concat(args));
|
|
269
|
-
}
|
|
270
|
-
}, {
|
|
271
|
-
key: "openLog",
|
|
272
|
-
value: function openLog(open) {
|
|
273
|
-
this.showLog = open;
|
|
274
|
-
}
|
|
275
|
-
}]);
|
|
276
|
-
return SocketClient;
|
|
277
|
-
}();
|
|
278
|
-
export default SocketClient;
|
package/es/socket/types.d.ts
DELETED
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
declare namespace SocketClientTypes {
|
|
2
|
-
enum EventType {
|
|
3
|
-
connected = "connected",
|
|
4
|
-
disconnected = "disconnected",
|
|
5
|
-
error = "error",
|
|
6
|
-
offline = "offline",
|
|
7
|
-
exist = "exist"
|
|
8
|
-
}
|
|
9
|
-
enum RequestType {
|
|
10
|
-
common = 0,
|
|
11
|
-
ping = 1,
|
|
12
|
-
pong = 2,
|
|
13
|
-
normal = 5,
|
|
14
|
-
img = 6
|
|
15
|
-
}
|
|
16
|
-
enum ResponseCode {
|
|
17
|
-
offline = 109001,
|
|
18
|
-
exist = 109002,
|
|
19
|
-
paramError = 109005
|
|
20
|
-
}
|
|
21
|
-
type Message = {
|
|
22
|
-
type: RequestType;
|
|
23
|
-
data: {
|
|
24
|
-
event: string;
|
|
25
|
-
payload: Record<string, any> | string | number | boolean;
|
|
26
|
-
};
|
|
27
|
-
};
|
|
28
|
-
interface ResponseData {
|
|
29
|
-
code: string;
|
|
30
|
-
data: {
|
|
31
|
-
type: RequestType;
|
|
32
|
-
[prop: string]: any;
|
|
33
|
-
};
|
|
34
|
-
}
|
|
35
|
-
type Handler = (msg?: Message['data']['payload']) => void;
|
|
36
|
-
}
|
|
37
|
-
export default SocketClientTypes;
|