@zgfe/business-lib 1.1.29-visual.3 → 1.1.29-visual.4
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/socket/demo/demo.js +120 -26
- package/es/socket/demo/index.less +23 -0
- package/es/socket/index.js +26 -19
- package/es/socket/types.d.ts +6 -2
- package/es/socket/types.js +1 -0
- package/package.json +2 -2
package/es/socket/demo/demo.js
CHANGED
|
@@ -1,58 +1,152 @@
|
|
|
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); }
|
|
1
5
|
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
|
|
2
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."); }
|
|
3
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); }
|
|
4
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; }
|
|
5
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; } }
|
|
6
10
|
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
7
|
-
import React, { useEffect, useState } from 'react';
|
|
11
|
+
import React, { useEffect, useRef, useState } from 'react';
|
|
8
12
|
import { SocketClient } from '@zgfe/business-lib';
|
|
9
|
-
import { notification } from 'antd';
|
|
10
|
-
|
|
13
|
+
import { Button, Card, Form, Input, notification } from 'antd';
|
|
14
|
+
import styles from './index.less';
|
|
15
|
+
var ChatPanel = function ChatPanel(_ref) {
|
|
16
|
+
var name = _ref.name,
|
|
17
|
+
param = _ref.param;
|
|
11
18
|
var _useState = useState(),
|
|
12
19
|
_useState2 = _slicedToArray(_useState, 2),
|
|
13
20
|
client = _useState2[0],
|
|
14
21
|
setClient = _useState2[1];
|
|
22
|
+
var _useState3 = useState([]),
|
|
23
|
+
_useState4 = _slicedToArray(_useState3, 2),
|
|
24
|
+
history = _useState4[0],
|
|
25
|
+
setHistory = _useState4[1];
|
|
26
|
+
var _useState5 = useState(true),
|
|
27
|
+
_useState6 = _slicedToArray(_useState5, 2),
|
|
28
|
+
online = _useState6[0],
|
|
29
|
+
setOnline = _useState6[1];
|
|
30
|
+
var formRef = useRef();
|
|
31
|
+
var historyRef = useRef();
|
|
15
32
|
useEffect(function () {
|
|
16
|
-
setClient(new SocketClient('wss://rt2.zhugeio.com/eventtracking/ws',
|
|
17
|
-
id: 'eti8-4ilv-876r-1wr5',
|
|
18
|
-
origin: 1,
|
|
19
|
-
appId: '146',
|
|
20
|
-
programId: 'zgej-3det-9edb-dje3',
|
|
21
|
-
type: 3,
|
|
22
|
-
event: 'login',
|
|
23
|
-
payload: {
|
|
24
|
-
unionid: 'hjadfhdskji884bdfd',
|
|
25
|
-
username: 'zhangsan'
|
|
26
|
-
}
|
|
27
|
-
}));
|
|
33
|
+
setClient(new SocketClient('wss://rt2.zhugeio.com/eventtracking/ws', param));
|
|
28
34
|
}, []);
|
|
35
|
+
useEffect(function () {
|
|
36
|
+
var _historyRef$current;
|
|
37
|
+
if (historyRef.current) historyRef.current.scrollTop = (_historyRef$current = historyRef.current) === null || _historyRef$current === void 0 ? void 0 : _historyRef$current.scrollHeight;
|
|
38
|
+
}, [history]);
|
|
29
39
|
useEffect(function () {
|
|
30
40
|
if (!client) return;
|
|
31
41
|
client.openLog(true);
|
|
32
42
|
client.onConnected(onConnected);
|
|
33
43
|
client.onError(onError);
|
|
34
|
-
client.onLogin(
|
|
35
|
-
|
|
44
|
+
client.onLogin(onLogin);
|
|
45
|
+
client.on('offline', function () {
|
|
46
|
+
setHistory(function (list) {
|
|
47
|
+
return [].concat(_toConsumableArray(list), [{
|
|
48
|
+
type: 'he',
|
|
49
|
+
message: '对方已下线'
|
|
50
|
+
}]);
|
|
51
|
+
});
|
|
36
52
|
});
|
|
37
|
-
client.on('
|
|
38
|
-
|
|
53
|
+
client.on('message', function (message) {
|
|
54
|
+
setHistory(function (list) {
|
|
55
|
+
return [].concat(_toConsumableArray(list), [{
|
|
56
|
+
type: 'he',
|
|
57
|
+
message: message
|
|
58
|
+
}]);
|
|
59
|
+
});
|
|
39
60
|
});
|
|
40
61
|
}, [client]);
|
|
41
62
|
function onConnected() {
|
|
42
63
|
notification.success({
|
|
43
64
|
message: '连接成功'
|
|
44
65
|
});
|
|
45
|
-
client.emit('init', {
|
|
46
|
-
msg: '这是初始化信息'
|
|
47
|
-
});
|
|
48
|
-
client.on('init', function (data) {
|
|
49
|
-
console.log('init response', data);
|
|
50
|
-
});
|
|
51
66
|
}
|
|
52
67
|
function onError() {
|
|
53
68
|
notification.error({
|
|
54
69
|
message: '连接失败'
|
|
55
70
|
});
|
|
56
71
|
}
|
|
57
|
-
|
|
72
|
+
function onLogin() {
|
|
73
|
+
setHistory(function (list) {
|
|
74
|
+
return [].concat(_toConsumableArray(list), [{
|
|
75
|
+
type: 'he',
|
|
76
|
+
message: '登录成功'
|
|
77
|
+
}]);
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
return /*#__PURE__*/React.createElement(Card, {
|
|
81
|
+
title: name
|
|
82
|
+
}, /*#__PURE__*/React.createElement("div", {
|
|
83
|
+
className: styles.history,
|
|
84
|
+
ref: historyRef
|
|
85
|
+
}, history.map(function (item, i) {
|
|
86
|
+
return /*#__PURE__*/React.createElement("div", {
|
|
87
|
+
className: styles[item.type],
|
|
88
|
+
key: i
|
|
89
|
+
}, item.type, ": ", item.message);
|
|
90
|
+
})), /*#__PURE__*/React.createElement("div", {
|
|
91
|
+
className: styles.footer
|
|
92
|
+
}, /*#__PURE__*/React.createElement(Form, {
|
|
93
|
+
ref: formRef,
|
|
94
|
+
autoComplete: "off",
|
|
95
|
+
onFinish: function onFinish(_ref2) {
|
|
96
|
+
var _formRef$current;
|
|
97
|
+
var message = _ref2.message;
|
|
98
|
+
client.emit('message', message);
|
|
99
|
+
setHistory(function (list) {
|
|
100
|
+
return [].concat(_toConsumableArray(list), [{
|
|
101
|
+
type: 'me',
|
|
102
|
+
message: message
|
|
103
|
+
}]);
|
|
104
|
+
});
|
|
105
|
+
(_formRef$current = formRef.current) === null || _formRef$current === void 0 ? void 0 : _formRef$current.resetFields();
|
|
106
|
+
}
|
|
107
|
+
}, /*#__PURE__*/React.createElement(Form.Item, {
|
|
108
|
+
name: "message"
|
|
109
|
+
}, /*#__PURE__*/React.createElement(Input, {
|
|
110
|
+
placeholder: "\u56DE\u8F66\u53D1\u9001\u4FE1\u606F",
|
|
111
|
+
autoFocus: true
|
|
112
|
+
})), /*#__PURE__*/React.createElement(Form.Item, null, /*#__PURE__*/React.createElement(Button, {
|
|
113
|
+
onClick: function onClick() {
|
|
114
|
+
if (online) {
|
|
115
|
+
client.close();
|
|
116
|
+
} else {
|
|
117
|
+
client.open();
|
|
118
|
+
}
|
|
119
|
+
setOnline(!online);
|
|
120
|
+
}
|
|
121
|
+
}, online ? '下线' : '上线')))));
|
|
122
|
+
};
|
|
123
|
+
export default (function () {
|
|
124
|
+
return /*#__PURE__*/React.createElement("div", {
|
|
125
|
+
className: styles.container
|
|
126
|
+
}, /*#__PURE__*/React.createElement(ChatPanel, {
|
|
127
|
+
name: "\u5F20\u4E09",
|
|
128
|
+
param: {
|
|
129
|
+
id: 'eti8-4ilv-876r-1wr5',
|
|
130
|
+
origin: 1,
|
|
131
|
+
appId: '146',
|
|
132
|
+
programId: 'zgej-3det-9edb-dje3',
|
|
133
|
+
type: 3,
|
|
134
|
+
payload: {
|
|
135
|
+
unionid: 'hjadfhdskji884bdfd',
|
|
136
|
+
username: 'zhangsan'
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
}), /*#__PURE__*/React.createElement(ChatPanel, {
|
|
140
|
+
name: "\u674E\u56DB",
|
|
141
|
+
param: {
|
|
142
|
+
id: 'ueks-d8d2-njka-8742-2mdd',
|
|
143
|
+
origin: 3,
|
|
144
|
+
appId: '146',
|
|
145
|
+
type: 3,
|
|
146
|
+
payload: {
|
|
147
|
+
unionid: 'web-unionid2132',
|
|
148
|
+
username: 'zhangsan'
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
}));
|
|
58
152
|
});
|
|
@@ -1,4 +1,27 @@
|
|
|
1
1
|
@import '../../assets/styles/inner.less';
|
|
2
2
|
.container {
|
|
3
|
+
display: flex;
|
|
4
|
+
flex-direction: row;
|
|
3
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;
|
|
4
27
|
}
|
package/es/socket/index.js
CHANGED
|
@@ -130,26 +130,33 @@ var SocketClient = /*#__PURE__*/function () {
|
|
|
130
130
|
}, {
|
|
131
131
|
key: "onMessage",
|
|
132
132
|
value: function onMessage(event) {
|
|
133
|
-
var
|
|
134
|
-
if (
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
133
|
+
var res_ = JSON.parse(event.data);
|
|
134
|
+
if (res_.code) {
|
|
135
|
+
var data = res_.data;
|
|
136
|
+
if (res_.code === '109001') {
|
|
137
|
+
var _this$listeners$Socke;
|
|
138
|
+
(_this$listeners$Socke = this.listeners[SocketClientTypes.EventType.offline]) === null || _this$listeners$Socke === void 0 ? void 0 : _this$listeners$Socke.forEach(function (handle) {
|
|
139
|
+
handle.call(undefined, res_);
|
|
140
|
+
});
|
|
141
|
+
return;
|
|
142
|
+
}
|
|
143
|
+
if (data.type === SocketClientTypes.RequestType.login) {
|
|
144
|
+
var _this$listeners$Socke2;
|
|
145
|
+
this.log('info', '登录成功');
|
|
146
|
+
(_this$listeners$Socke2 = this.listeners[SocketClientTypes.EventType.login]) === null || _this$listeners$Socke2 === void 0 ? void 0 : _this$listeners$Socke2.forEach(function (handle) {
|
|
147
|
+
handle.call(undefined, res_);
|
|
148
|
+
});
|
|
149
|
+
return;
|
|
150
|
+
}
|
|
151
|
+
} else if (res_.type === SocketClientTypes.RequestType.pong) {
|
|
146
152
|
return;
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
+
} else {
|
|
154
|
+
var _data = res_.data;
|
|
155
|
+
if (this.listeners[_data.event]) {
|
|
156
|
+
this.listeners[_data.event].forEach(function (handle) {
|
|
157
|
+
handle.call(undefined, _data.payload);
|
|
158
|
+
});
|
|
159
|
+
}
|
|
153
160
|
}
|
|
154
161
|
}
|
|
155
162
|
}, {
|
package/es/socket/types.d.ts
CHANGED
|
@@ -3,7 +3,8 @@ declare namespace SocketClientTypes {
|
|
|
3
3
|
connected = "connected",
|
|
4
4
|
disconnected = "disconnected",
|
|
5
5
|
error = "error",
|
|
6
|
-
login = "login"
|
|
6
|
+
login = "login",
|
|
7
|
+
offline = "offline"
|
|
7
8
|
}
|
|
8
9
|
enum RequestType {
|
|
9
10
|
common = 0,
|
|
@@ -22,7 +23,10 @@ declare namespace SocketClientTypes {
|
|
|
22
23
|
};
|
|
23
24
|
interface ResponseData {
|
|
24
25
|
code: string;
|
|
25
|
-
data:
|
|
26
|
+
data: {
|
|
27
|
+
type: RequestType;
|
|
28
|
+
[prop: string]: any;
|
|
29
|
+
};
|
|
26
30
|
}
|
|
27
31
|
type Handler = (msg?: Message['data']['payload']) => void;
|
|
28
32
|
}
|
package/es/socket/types.js
CHANGED
|
@@ -6,6 +6,7 @@ var SocketClientTypes;
|
|
|
6
6
|
EventType["disconnected"] = "disconnected";
|
|
7
7
|
EventType["error"] = "error";
|
|
8
8
|
EventType["login"] = "login";
|
|
9
|
+
EventType["offline"] = "offline";
|
|
9
10
|
})(EventType = SocketClientTypes.EventType || (SocketClientTypes.EventType = {}));
|
|
10
11
|
var RequestType;
|
|
11
12
|
(function (RequestType) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zgfe/business-lib",
|
|
3
|
-
"version": "1.1.29-visual.
|
|
3
|
+
"version": "1.1.29-visual.4",
|
|
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": "b020ab1026aa6a5d412a06f738b6ed6fa4c5ccd3"
|
|
63
63
|
}
|