@chaoswise/ui 2.5.4 → 2.5.5
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.
|
@@ -13,7 +13,7 @@ function _asyncToGenerator(fn) { return function () { var self = this, args = ar
|
|
|
13
13
|
import React from "react";
|
|
14
14
|
import moment from "moment";
|
|
15
15
|
import { readInnerMessageApi } from "../../service";
|
|
16
|
-
import langConfig from
|
|
16
|
+
import langConfig from "../../locale";
|
|
17
17
|
import { formatMessage } from "../../../utils";
|
|
18
18
|
import "./index.less";
|
|
19
19
|
var TabList = function TabList(props) {
|
|
@@ -63,9 +63,9 @@ var TabList = function TabList(props) {
|
|
|
63
63
|
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
64
64
|
while (1) switch (_context.prev = _context.next) {
|
|
65
65
|
case 0:
|
|
66
|
-
resRequestApi = _readInnerMessageApi
|
|
66
|
+
resRequestApi = _readInnerMessageApi || readInnerMessageApi;
|
|
67
67
|
_context.next = 3;
|
|
68
|
-
return resRequestApi;
|
|
68
|
+
return resRequestApi(params, gatewayPrefix);
|
|
69
69
|
case 3:
|
|
70
70
|
res = _context.sent;
|
|
71
71
|
if (res.status == "success") {
|
|
@@ -89,9 +89,9 @@ var MessageContent = function MessageContent(props) {
|
|
|
89
89
|
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
90
90
|
while (1) switch (_context.prev = _context.next) {
|
|
91
91
|
case 0:
|
|
92
|
-
resRequestApi = _getMessageTypeApi
|
|
92
|
+
resRequestApi = _getMessageTypeApi || getMessageTypeApi;
|
|
93
93
|
_context.next = 3;
|
|
94
|
-
return resRequestApi;
|
|
94
|
+
return resRequestApi(gatewayPrefix);
|
|
95
95
|
case 3:
|
|
96
96
|
res = _context.sent;
|
|
97
97
|
if (res && res.status == "success") {
|
|
@@ -123,9 +123,9 @@ var MessageContent = function MessageContent(props) {
|
|
|
123
123
|
case 0:
|
|
124
124
|
setLoading(true);
|
|
125
125
|
conditionsRef.current = _objectSpread(_objectSpread({}, conditionsRef.current), params);
|
|
126
|
-
resRequestApi = _getMessageListApi
|
|
126
|
+
resRequestApi = _getMessageListApi || getMessageListApi;
|
|
127
127
|
_context2.next = 5;
|
|
128
|
-
return resRequestApi;
|
|
128
|
+
return resRequestApi(conditionsRef.current, gatewayPrefix);
|
|
129
129
|
case 5:
|
|
130
130
|
res = _context2.sent;
|
|
131
131
|
if (res && res.status == "success") {
|
|
@@ -151,9 +151,9 @@ var MessageContent = function MessageContent(props) {
|
|
|
151
151
|
return _regeneratorRuntime().wrap(function _callee3$(_context3) {
|
|
152
152
|
while (1) switch (_context3.prev = _context3.next) {
|
|
153
153
|
case 0:
|
|
154
|
-
resRequestApi = _getMessageUnreadCountApi
|
|
154
|
+
resRequestApi = _getMessageUnreadCountApi || getMessageUnreadCountApi;
|
|
155
155
|
_context3.next = 3;
|
|
156
|
-
return resRequestApi;
|
|
156
|
+
return resRequestApi(gatewayPrefix);
|
|
157
157
|
case 3:
|
|
158
158
|
res = _context3.sent;
|
|
159
159
|
if (res && res.status == "success") {
|
package/lib/CWMessage/index.js
CHANGED
|
@@ -91,6 +91,8 @@ function Message(props) {
|
|
|
91
91
|
setTotal = _useState6[1];
|
|
92
92
|
// 保存消息配置
|
|
93
93
|
var messageOptionRef = useRef({});
|
|
94
|
+
// 获取socket信息
|
|
95
|
+
var socketConnectInfo = useRef();
|
|
94
96
|
// 分页配置初始化
|
|
95
97
|
var _useState7 = useState({
|
|
96
98
|
current: 1,
|
|
@@ -113,6 +115,11 @@ function Message(props) {
|
|
|
113
115
|
top: headerHeight,
|
|
114
116
|
maxCount: 1
|
|
115
117
|
});
|
|
118
|
+
return function () {
|
|
119
|
+
if (socketConnectInfo.current) {
|
|
120
|
+
socketConnectInfo.current.disconnect && socketConnectInfo.current.disconnect();
|
|
121
|
+
}
|
|
122
|
+
};
|
|
116
123
|
}, []);
|
|
117
124
|
useEffect(function () {
|
|
118
125
|
setPageInfo(function (pre) {
|
|
@@ -152,9 +159,9 @@ function Message(props) {
|
|
|
152
159
|
userMessageId: id,
|
|
153
160
|
clientType: "BROWSER"
|
|
154
161
|
};
|
|
155
|
-
resRequestApi = _getMessageDetailApi
|
|
162
|
+
resRequestApi = _getMessageDetailApi || getMessageDetailApi;
|
|
156
163
|
_context.next = 4;
|
|
157
|
-
return resRequestApi;
|
|
164
|
+
return resRequestApi(params, gatewayPrefix);
|
|
158
165
|
case 4:
|
|
159
166
|
res = _context.sent;
|
|
160
167
|
if (res && res.status == "success") {
|
|
@@ -190,24 +197,13 @@ function Message(props) {
|
|
|
190
197
|
}();
|
|
191
198
|
var readInnerMessage = /*#__PURE__*/function () {
|
|
192
199
|
var _ref3 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(params) {
|
|
193
|
-
var resRequestApi
|
|
200
|
+
var resRequestApi;
|
|
194
201
|
return _regeneratorRuntime().wrap(function _callee2$(_context2) {
|
|
195
202
|
while (1) switch (_context2.prev = _context2.next) {
|
|
196
203
|
case 0:
|
|
197
|
-
resRequestApi = _readInnerMessageApi
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
case 3:
|
|
201
|
-
res = _context2.sent;
|
|
202
|
-
if (res.status == "success") {
|
|
203
|
-
// if (pageInfo.current > 1 && dataSource.length === 1) {
|
|
204
|
-
// let _params = { current: pageInfo.current - 1 };
|
|
205
|
-
// setPageInfo((pre) => ({ ...pre, current: pre.current - 1 }));
|
|
206
|
-
// conditionsRef.current = { ...conditionsRef.current, ..._params };
|
|
207
|
-
// }
|
|
208
|
-
// 已读消息
|
|
209
|
-
}
|
|
210
|
-
case 5:
|
|
204
|
+
resRequestApi = _readInnerMessageApi || readInnerMessageApi;
|
|
205
|
+
resRequestApi(params, gatewayPrefix);
|
|
206
|
+
case 2:
|
|
211
207
|
case "end":
|
|
212
208
|
return _context2.stop();
|
|
213
209
|
}
|
|
@@ -217,19 +213,47 @@ function Message(props) {
|
|
|
217
213
|
return _ref3.apply(this, arguments);
|
|
218
214
|
};
|
|
219
215
|
}();
|
|
216
|
+
var getSocketPostMessage = function getSocketPostMessage(data) {
|
|
217
|
+
var _JSON$parse = JSON.parse(data),
|
|
218
|
+
count = _JSON$parse.count,
|
|
219
|
+
message = _JSON$parse.message;
|
|
220
|
+
var _ref4 = count || {},
|
|
221
|
+
_ref4$total = _ref4.total,
|
|
222
|
+
total = _ref4$total === void 0 ? 0 : _ref4$total;
|
|
223
|
+
setMessageTotal(total);
|
|
224
|
+
onSocketChange(JSON.parse(data));
|
|
225
|
+
if (message) {
|
|
226
|
+
var noticeMessage = message.noticeMessage;
|
|
227
|
+
if (noticeMessage) {
|
|
228
|
+
var userMessageId = noticeMessage.id,
|
|
229
|
+
type = noticeMessage.type;
|
|
230
|
+
if (userMessageId) {
|
|
231
|
+
var _ref5 = messageOptionRef.current[type] || {},
|
|
232
|
+
enable = _ref5.enable,
|
|
233
|
+
mode = _ref5.mode,
|
|
234
|
+
_ref5$time = _ref5.time,
|
|
235
|
+
time = _ref5$time === void 0 ? 5 : _ref5$time;
|
|
236
|
+
if (enable) {
|
|
237
|
+
openNotification(time, userMessageId);
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
};
|
|
220
243
|
var connectSocket = /*#__PURE__*/function () {
|
|
221
|
-
var
|
|
244
|
+
var _ref6 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3() {
|
|
222
245
|
var resRequestApi, res, finalOrigin, socket;
|
|
223
|
-
return _regeneratorRuntime().wrap(function
|
|
224
|
-
while (1) switch (
|
|
246
|
+
return _regeneratorRuntime().wrap(function _callee3$(_context3) {
|
|
247
|
+
while (1) switch (_context3.prev = _context3.next) {
|
|
225
248
|
case 0:
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
249
|
+
// 获取sessionId
|
|
250
|
+
resRequestApi = _getSessionId || getSessionId;
|
|
251
|
+
_context3.next = 3;
|
|
252
|
+
return resRequestApi(gatewayPrefix);
|
|
229
253
|
case 3:
|
|
230
|
-
res =
|
|
254
|
+
res = _context3.sent;
|
|
231
255
|
if (res && res.status == "success") {
|
|
232
|
-
finalOrigin = socketOrigin
|
|
256
|
+
finalOrigin = socketOrigin || "ws://".concat(window.location.host); // 连接到后端socket服务器
|
|
233
257
|
socket = io(finalOrigin, {
|
|
234
258
|
transports: ["websocket"],
|
|
235
259
|
path: "".concat(socketPathPrefix, "/message/socket.io"),
|
|
@@ -237,95 +261,51 @@ function Message(props) {
|
|
|
237
261
|
sessionId: res.data,
|
|
238
262
|
clientType: "BROWSER"
|
|
239
263
|
}
|
|
240
|
-
});
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
return _regeneratorRuntime().wrap(function _callee3$(_context3) {
|
|
245
|
-
while (1) switch (_context3.prev = _context3.next) {
|
|
246
|
-
case 0:
|
|
247
|
-
_JSON$parse = JSON.parse(data), count = _JSON$parse.count, message = _JSON$parse.message;
|
|
248
|
-
_ref6 = count || {}, _ref6$total = _ref6.total, total = _ref6$total === void 0 ? 0 : _ref6$total;
|
|
249
|
-
setMessageTotal(total);
|
|
250
|
-
onSocketChange(JSON.parse(data));
|
|
251
|
-
if (message) {
|
|
252
|
-
noticeMessage = message.noticeMessage;
|
|
253
|
-
if (noticeMessage) {
|
|
254
|
-
userMessageId = noticeMessage.id, type = noticeMessage.type;
|
|
255
|
-
if (userMessageId) {
|
|
256
|
-
_ref7 = messageOptionRef.current[type] || {}, enable = _ref7.enable, mode = _ref7.mode, _ref7$time = _ref7.time, time = _ref7$time === void 0 ? 5 : _ref7$time;
|
|
257
|
-
if (enable) {
|
|
258
|
-
openNotification(time, userMessageId);
|
|
259
|
-
}
|
|
260
|
-
}
|
|
261
|
-
}
|
|
262
|
-
}
|
|
263
|
-
case 5:
|
|
264
|
-
case "end":
|
|
265
|
-
return _context3.stop();
|
|
266
|
-
}
|
|
267
|
-
}, _callee3);
|
|
268
|
-
}));
|
|
269
|
-
return function (_x4) {
|
|
270
|
-
return _ref5.apply(this, arguments);
|
|
271
|
-
};
|
|
272
|
-
}());
|
|
264
|
+
}); // 记录socket连接信息,用于关闭socket连接
|
|
265
|
+
socketConnectInfo.current = socket;
|
|
266
|
+
// 监听从服务器传来的消息
|
|
267
|
+
socket.on("push", getSocketPostMessage);
|
|
273
268
|
// socket重连
|
|
274
|
-
socket.on("reconnect_attempt",
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
return resRequestApi;
|
|
281
|
-
case 2:
|
|
282
|
-
res = _context4.sent;
|
|
283
|
-
if (res && res.status == "success") {
|
|
284
|
-
socket.io.opts.query = {
|
|
285
|
-
sessionId: res.data,
|
|
286
|
-
clientType: "BROWSER"
|
|
287
|
-
};
|
|
288
|
-
}
|
|
289
|
-
case 4:
|
|
290
|
-
case "end":
|
|
291
|
-
return _context4.stop();
|
|
292
|
-
}
|
|
293
|
-
}, _callee4);
|
|
294
|
-
})));
|
|
269
|
+
socket.on("reconnect_attempt", function () {
|
|
270
|
+
socket.io.opts.query = {
|
|
271
|
+
sessionId: res.data,
|
|
272
|
+
clientType: "BROWSER"
|
|
273
|
+
};
|
|
274
|
+
});
|
|
295
275
|
}
|
|
296
276
|
case 5:
|
|
297
277
|
case "end":
|
|
298
|
-
return
|
|
278
|
+
return _context3.stop();
|
|
299
279
|
}
|
|
300
|
-
},
|
|
280
|
+
}, _callee3);
|
|
301
281
|
}));
|
|
302
282
|
return function connectSocket() {
|
|
303
|
-
return
|
|
283
|
+
return _ref6.apply(this, arguments);
|
|
304
284
|
};
|
|
305
285
|
}();
|
|
306
286
|
var getMessageQuerySettings = /*#__PURE__*/function () {
|
|
307
|
-
var
|
|
287
|
+
var _ref7 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4() {
|
|
308
288
|
var resRequestApi, res, data;
|
|
309
|
-
return _regeneratorRuntime().wrap(function
|
|
310
|
-
while (1) switch (
|
|
289
|
+
return _regeneratorRuntime().wrap(function _callee4$(_context4) {
|
|
290
|
+
while (1) switch (_context4.prev = _context4.next) {
|
|
311
291
|
case 0:
|
|
312
|
-
resRequestApi = _getMessageQuerySettingsApi
|
|
313
|
-
|
|
314
|
-
return resRequestApi;
|
|
292
|
+
resRequestApi = _getMessageQuerySettingsApi || getMessageQuerySettingsApi;
|
|
293
|
+
_context4.next = 3;
|
|
294
|
+
return resRequestApi(gatewayPrefix);
|
|
315
295
|
case 3:
|
|
316
|
-
res =
|
|
296
|
+
res = _context4.sent;
|
|
317
297
|
if (res && res.status === "success") {
|
|
318
298
|
data = res.data;
|
|
319
299
|
messageOptionRef.current = data || {};
|
|
320
300
|
}
|
|
321
301
|
case 5:
|
|
322
302
|
case "end":
|
|
323
|
-
return
|
|
303
|
+
return _context4.stop();
|
|
324
304
|
}
|
|
325
|
-
},
|
|
305
|
+
}, _callee4);
|
|
326
306
|
}));
|
|
327
307
|
return function getMessageQuerySettings() {
|
|
328
|
-
return
|
|
308
|
+
return _ref7.apply(this, arguments);
|
|
329
309
|
};
|
|
330
310
|
}();
|
|
331
311
|
return /*#__PURE__*/React.createElement("div", {
|
|
@@ -5,28 +5,33 @@ function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _d
|
|
|
5
5
|
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
|
|
6
6
|
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|
7
7
|
var Dep = /*#__PURE__*/function () {
|
|
8
|
-
|
|
9
|
-
function Dep(name) {
|
|
8
|
+
function Dep() {
|
|
10
9
|
_classCallCheck(this, Dep);
|
|
11
|
-
this.subs = [];
|
|
10
|
+
this.subs = []; // 存放所有订阅者
|
|
12
11
|
}
|
|
12
|
+
// 添加订阅者
|
|
13
13
|
_createClass(Dep, [{
|
|
14
|
-
key: "
|
|
15
|
-
value: function
|
|
16
|
-
this.subs.
|
|
14
|
+
key: "addSub",
|
|
15
|
+
value: function addSub(watch) {
|
|
16
|
+
if (watch && this.subs.indexOf(watch) < 0) {
|
|
17
|
+
this.subs.push(watch);
|
|
18
|
+
}
|
|
17
19
|
}
|
|
20
|
+
// 移除订阅者
|
|
21
|
+
}, {
|
|
22
|
+
key: "removeSub",
|
|
23
|
+
value: function removeSub(watch) {
|
|
24
|
+
var index = this.subs.indexOf(watch);
|
|
25
|
+
if (index > -1) {
|
|
26
|
+
this.subs.splice(index, 1);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
// 通知所有订阅者
|
|
18
30
|
}, {
|
|
19
31
|
key: "notify",
|
|
20
32
|
value: function notify() {
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
if (typeof e.update === 'function') {
|
|
24
|
-
try {
|
|
25
|
-
e.update.apply(e); //触发订阅者更新函数
|
|
26
|
-
} catch (err) {
|
|
27
|
-
console.error(err);
|
|
28
|
-
}
|
|
29
|
-
}
|
|
33
|
+
this.subs.forEach(function (sub) {
|
|
34
|
+
return sub.update();
|
|
30
35
|
});
|
|
31
36
|
}
|
|
32
37
|
}]);
|
|
@@ -35,49 +40,44 @@ var Dep = /*#__PURE__*/function () {
|
|
|
35
40
|
var Watch = /*#__PURE__*/function () {
|
|
36
41
|
function Watch(name, fn) {
|
|
37
42
|
_classCallCheck(this, Watch);
|
|
38
|
-
this.name = name;
|
|
39
|
-
this.callBack = fn;
|
|
43
|
+
this.name = name;
|
|
44
|
+
this.callBack = fn;
|
|
40
45
|
}
|
|
41
46
|
_createClass(Watch, [{
|
|
42
|
-
key: "add",
|
|
43
|
-
value: function add(dep) {
|
|
44
|
-
//将订阅者放入dep订阅池
|
|
45
|
-
dep.subs.push(this);
|
|
46
|
-
}
|
|
47
|
-
}, {
|
|
48
47
|
key: "update",
|
|
49
48
|
value: function update() {
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
49
|
+
if (typeof this.callBack === 'function') {
|
|
50
|
+
this.callBack(this.name);
|
|
51
|
+
}
|
|
53
52
|
}
|
|
54
53
|
}]);
|
|
55
54
|
return Watch;
|
|
56
55
|
}();
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
} else if (name === 'pushState') {
|
|
66
|
-
var method = history[name];
|
|
67
|
-
return function () {
|
|
68
|
-
method.apply(history, arguments);
|
|
69
|
-
historyDep.notify();
|
|
70
|
-
};
|
|
71
|
-
} else if (name === 'replaceState') {
|
|
72
|
-
var _method = history[name];
|
|
73
|
-
return function () {
|
|
74
|
-
_method.apply(history, arguments);
|
|
75
|
-
historyDep.notify();
|
|
76
|
-
};
|
|
56
|
+
var historyDep = new Dep(); // 单例订阅池
|
|
57
|
+
|
|
58
|
+
// 修改history方法
|
|
59
|
+
var modifyHistoryMethod = function modifyHistoryMethod(methodName) {
|
|
60
|
+
var original = history[methodName];
|
|
61
|
+
history[methodName] = function () {
|
|
62
|
+
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
63
|
+
args[_key] = arguments[_key];
|
|
77
64
|
}
|
|
65
|
+
var result = original.apply(this, args);
|
|
66
|
+
historyDep.notify(); // 通知变动
|
|
67
|
+
return result;
|
|
68
|
+
};
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
// 添加订阅者
|
|
72
|
+
window.addHistoryListener = function (name, fn) {
|
|
73
|
+
var watcher = new Watch(name, fn);
|
|
74
|
+
historyDep.addSub(watcher);
|
|
75
|
+
// 返回取消订阅的函数
|
|
76
|
+
return function removeHistoryListener() {
|
|
77
|
+
historyDep.removeSub(watcher);
|
|
78
78
|
};
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
// 修改pushState和replaceState以便通知订阅者
|
|
82
|
+
modifyHistoryMethod('pushState');
|
|
83
|
+
modifyHistoryMethod('replaceState');
|
|
@@ -56,7 +56,7 @@ var ErrorBoundary = /*#__PURE__*/function (_React$PureComponent) {
|
|
|
56
56
|
_createClass(ErrorBoundary, [{
|
|
57
57
|
key: "componentDidMount",
|
|
58
58
|
value: function componentDidMount() {
|
|
59
|
-
window.addHistoryListener('history', this.historyChange);
|
|
59
|
+
this.removeListener = window.addHistoryListener('history', this.historyChange);
|
|
60
60
|
window.addEventListener('hashchange', this.historyChange);
|
|
61
61
|
this.timer = setTimeout(function () {
|
|
62
62
|
localStorage.setItem('ChunkLoadError', '');
|
|
@@ -65,8 +65,9 @@ var ErrorBoundary = /*#__PURE__*/function (_React$PureComponent) {
|
|
|
65
65
|
}, {
|
|
66
66
|
key: "componentWillUnmount",
|
|
67
67
|
value: function componentWillUnmount() {
|
|
68
|
-
|
|
68
|
+
this.removeListener();
|
|
69
69
|
window.removeEventListener('hashchange', this.historyChange);
|
|
70
|
+
clearTimeout(this.timer);
|
|
70
71
|
}
|
|
71
72
|
}, {
|
|
72
73
|
key: "componentDidCatch",
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@chaoswise/ui",
|
|
3
|
-
"version": "2.5.
|
|
3
|
+
"version": "2.5.5",
|
|
4
4
|
"description": "公共UI库",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"ui",
|
|
@@ -146,5 +146,6 @@
|
|
|
146
146
|
"publishConfig": {
|
|
147
147
|
"access": "public"
|
|
148
148
|
},
|
|
149
|
-
"license": "MIT"
|
|
149
|
+
"license": "MIT",
|
|
150
|
+
"gitHead": "46b2853aff3fc06cda3a575fcf49dc688b547551"
|
|
150
151
|
}
|