@chaoswise/ui 3.1.2 → 3.1.3

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.
Binary file
@@ -1,6 +1,7 @@
1
1
  function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
2
2
  import _Drawer from "@chaoswise/ui/lib/Drawer";
3
3
  import _Badge from "@chaoswise/ui/lib/Badge";
4
+ import _Modal from "@chaoswise/ui/lib/Modal";
4
5
  import _notification from "@chaoswise/ui/lib/notification";
5
6
  var _excluded = ["count"],
6
7
  _excluded2 = ["onClickStrongMessageItem"];
@@ -21,16 +22,18 @@ function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r)
21
22
  function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
22
23
  function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t["return"] && (u = t["return"](), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
23
24
  function _arrayWithHoles(r) { if (Array.isArray(r)) return r; }
24
- import React, { useState, useEffect, useMemo, useRef } from "react";
25
- import useConfigContext from "../useConfigContext";
26
- import MessageIcon from "./messageSvg.js";
27
- import CommonIcon from "./CommonIcon";
28
- import { getSessionId, getMessageDetailApi, getMessageQuerySettingsApi, readInnerMessageApi } from "./service";
29
- import MessageContent from "./MessageContent";
30
- import classnames from "classnames";
31
- import PropTypes from "prop-types";
32
- import io from "socket.io-client";
33
- import useStyle from "./index.style";
25
+ import React, { useState, useEffect, useMemo, useRef } from 'react';
26
+ import useConfigContext from '../useConfigContext';
27
+ import MessageIcon from './messageSvg.js';
28
+ import CommonIcon from './CommonIcon';
29
+ import { getSessionId, getMessageDetailApi, getMessageQuerySettingsApi, readInnerMessageApi } from './service';
30
+ import MessageContent from './MessageContent';
31
+ import classnames from 'classnames';
32
+ import PropTypes from 'prop-types';
33
+ import io from 'socket.io-client';
34
+ import audioMp3 from './audioMp3.wav';
35
+ import useStyle from './index.style';
36
+ import { useIntl } from '../locales';
34
37
  function Message(props) {
35
38
  var _props$hideOnSinglePa = props.hideOnSinglePage,
36
39
  hideOnSinglePage = _props$hideOnSinglePa === void 0 ? false : _props$hideOnSinglePa,
@@ -46,9 +49,9 @@ function Message(props) {
46
49
  _props$onTabListAllRe = props.onTabListAllRead,
47
50
  onTabListAllRead = _props$onTabListAllRe === void 0 ? function () {} : _props$onTabListAllRe,
48
51
  _props$gatewayPrefix = props.gatewayPrefix,
49
- gatewayPrefix = _props$gatewayPrefix === void 0 ? "" : _props$gatewayPrefix,
52
+ gatewayPrefix = _props$gatewayPrefix === void 0 ? '' : _props$gatewayPrefix,
50
53
  _props$socketPathPref = props.socketPathPrefix,
51
- socketPathPrefix = _props$socketPathPref === void 0 ? "" : _props$socketPathPref,
54
+ socketPathPrefix = _props$socketPathPref === void 0 ? '' : _props$socketPathPref,
52
55
  isClose = props.isClose,
53
56
  _props$imgOption = props.imgOption,
54
57
  imgOption = _props$imgOption === void 0 ? {} : _props$imgOption,
@@ -60,11 +63,15 @@ function Message(props) {
60
63
  _props$onSocketChange = props.onSocketChange,
61
64
  onSocketChange = _props$onSocketChange === void 0 ? function () {} : _props$onSocketChange,
62
65
  _props$renderMessageD = props.renderMessageDateFormat,
63
- renderMessageDateFormat = _props$renderMessageD === void 0 ? function () {} : _props$renderMessageD;
66
+ renderMessageDateFormat = _props$renderMessageD === void 0 ? function () {} : _props$renderMessageD,
67
+ customAudioSrc = props.customAudioSrc,
68
+ _props$enableVoicePro = props.enableVoicePrompt,
69
+ enableVoicePrompt = _props$enableVoicePro === void 0 ? false : _props$enableVoicePro;
70
+ var intl = useIntl();
64
71
  var _useConfigContext = useConfigContext(),
65
72
  getPrefixCls = _useConfigContext.getPrefixCls;
66
73
  var prefixCls = getPrefixCls();
67
- var messagePrefixCls = getPrefixCls("business-message");
74
+ var messagePrefixCls = getPrefixCls('business-message');
68
75
  var _useStyle = useStyle("".concat(messagePrefixCls, "-wrapper")),
69
76
  _useStyle2 = _slicedToArray(_useStyle, 3),
70
77
  wrapCSSVar = _useStyle2[0],
@@ -82,7 +89,7 @@ function Message(props) {
82
89
  var _strongMessageOption$ = strongMessageOption.onClickStrongMessageItem,
83
90
  onClickStrongMessageItem = _strongMessageOption$ === void 0 ? function () {} : _strongMessageOption$,
84
91
  restStrongMessageOption = _objectWithoutProperties(strongMessageOption, _excluded2);
85
- var _useState = useState("windows"),
92
+ var _useState = useState('windows'),
86
93
  _useState2 = _slicedToArray(_useState, 2),
87
94
  mode = _useState2[0],
88
95
  setMode = _useState2[1];
@@ -113,18 +120,25 @@ function Message(props) {
113
120
  setPageInfo = _useState10[1];
114
121
  var _notification$useNoti = _notification.useNotification({
115
122
  top: headerHeight,
116
- maxCount: mode === "windows" ? 1 : null
123
+ maxCount: mode === 'windows' ? 1 : null
117
124
  }),
118
125
  _notification$useNoti2 = _slicedToArray(_notification$useNoti, 2),
119
126
  api = _notification$useNoti2[0],
120
127
  contextHolder = _notification$useNoti2[1];
128
+ var _Modal$useModal = _Modal.useModal(),
129
+ _Modal$useModal2 = _slicedToArray(_Modal$useModal, 2),
130
+ modalApi = _Modal$useModal2[0],
131
+ contextHolderModal = _Modal$useModal2[1];
121
132
  // 初始化条件
122
133
  var conditionsRef = useRef({
123
134
  current: 1,
124
135
  size: pageInfo.pageSize,
125
- clientType: "BROWSER",
136
+ clientType: 'BROWSER',
126
137
  status: 0
127
138
  });
139
+ //初始化提示弹框
140
+ var modal = useRef(null);
141
+ var audioRef = useRef(null);
128
142
  useEffect(function () {
129
143
  getMessageQuerySettings();
130
144
  connectSocket();
@@ -132,6 +146,10 @@ function Message(props) {
132
146
  if (socketConnectInfo.current) {
133
147
  socketConnectInfo.current.disconnect && socketConnectInfo.current.disconnect();
134
148
  }
149
+ var audio = audioRef.current;
150
+ if (audio) {
151
+ audio.pause();
152
+ }
135
153
  };
136
154
  }, []);
137
155
  useEffect(function () {
@@ -149,7 +167,7 @@ function Message(props) {
149
167
  return 24;
150
168
  }, [hideOnSinglePage, total]);
151
169
  var hasOnTabMore = useMemo(function () {
152
- return "onTabMore" in props ? true : false;
170
+ return 'onTabMore' in props ? true : false;
153
171
  }, [onTabMore]);
154
172
  var onClose = function onClose(e) {
155
173
  setVisible(false);
@@ -165,6 +183,30 @@ function Message(props) {
165
183
  var onClickBell = function onClickBell() {
166
184
  setVisible(true);
167
185
  };
186
+ // 播放音频
187
+ var playAudio = function playAudio() {
188
+ var audio = audioRef.current;
189
+ if (audio) {
190
+ audio.currentTime = 0; // 重置播放时间
191
+ audio.play()["catch"](function (err) {
192
+ var _err$message;
193
+ if ((err === null || err === void 0 ? void 0 : err.name) === 'NotAllowedError' && err !== null && err !== void 0 && (_err$message = err.message) !== null && _err$message !== void 0 && _err$message.includes('play() failed')) {
194
+ if (!modal.current) {
195
+ modal.current = modalApi.warning({
196
+ title: intl.get('de6eaecc-9d39-41f1-82d3-80694c558028').d('消息提醒需要有交互行为才可以自动播放'),
197
+ okText: intl.get('4253417c-d699-4eed-8c75-34d2a8b18a68').d('确定'),
198
+ mask: true,
199
+ maskClosable: true
200
+ });
201
+ } else {
202
+ modal.current.update(function (prevConfig) {
203
+ return _objectSpread({}, prevConfig);
204
+ });
205
+ }
206
+ }
207
+ });
208
+ }
209
+ };
168
210
  var openNotification = /*#__PURE__*/function () {
169
211
  var _ref = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee(time, id) {
170
212
  var params, resRequestApi, res, data, _ref2, userMessageId, title, summary;
@@ -173,14 +215,16 @@ function Message(props) {
173
215
  case 0:
174
216
  params = {
175
217
  userMessageId: id,
176
- clientType: "BROWSER"
218
+ clientType: 'BROWSER'
177
219
  };
178
220
  resRequestApi = _getMessageDetailApi || getMessageDetailApi;
179
221
  _context.next = 4;
180
222
  return resRequestApi(params, gatewayPrefix);
181
223
  case 4:
182
224
  res = _context.sent;
183
- if (res && res.status == "success") {
225
+ if (res && res.status == 'success') {
226
+ // 消息语音提示
227
+ playAudio();
184
228
  data = res.data;
185
229
  _ref2 = data || {}, userMessageId = _ref2.userMessageId, title = _ref2.title, summary = _ref2.summary;
186
230
  api.open(_objectSpread({
@@ -244,7 +288,7 @@ function Message(props) {
244
288
  userMessageId = _ref5.id,
245
289
  type = _ref5.type;
246
290
  if (!userMessageId) return;
247
- if (action && action.mode === "recall") {
291
+ if (action && action.mode === 'recall') {
248
292
  // 销毁强提醒
249
293
  api.destroy(userMessageId);
250
294
  // 销毁后如果弹窗开启关闭弹窗
@@ -275,21 +319,21 @@ function Message(props) {
275
319
  return resRequestApi(gatewayPrefix);
276
320
  case 3:
277
321
  res = _context4.sent;
278
- if (res && res.status == "success") {
322
+ if (res && res.status == 'success') {
279
323
  finalOrigin = socketOrigin ? socketOrigin : "ws://".concat(window.location.host);
280
324
  socket = io(finalOrigin, {
281
- transports: ["websocket"],
325
+ transports: ['websocket'],
282
326
  path: "".concat(socketPathPrefix, "/message/socket.io"),
283
327
  query: {
284
328
  sessionId: res.data,
285
- clientType: "BROWSER"
329
+ clientType: 'BROWSER'
286
330
  }
287
331
  }); // 记录socket连接信息,用于关闭socket连接
288
332
  socketConnectInfo.current = socket;
289
333
  // 监听从服务器传来的消息
290
- socket.on("push", getSocketPostMessage);
334
+ socket.on('push', getSocketPostMessage);
291
335
  // socket重连
292
- socket.on("reconnect_attempt", /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee3() {
336
+ socket.on('reconnect_attempt', /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee3() {
293
337
  var res;
294
338
  return _regeneratorRuntime().wrap(function _callee3$(_context3) {
295
339
  while (1) switch (_context3.prev = _context3.next) {
@@ -298,10 +342,10 @@ function Message(props) {
298
342
  return resRequestApi;
299
343
  case 2:
300
344
  res = _context3.sent;
301
- if (res && res.status == "success") {
345
+ if (res && res.status == 'success') {
302
346
  socket.io.opts.query = {
303
347
  sessionId: res.data,
304
- clientType: "BROWSER"
348
+ clientType: 'BROWSER'
305
349
  };
306
350
  }
307
351
  case 4:
@@ -332,7 +376,7 @@ function Message(props) {
332
376
  return resRequestApi(gatewayPrefix);
333
377
  case 3:
334
378
  res = _context5.sent;
335
- if (res && res.status === "success") {
379
+ if (res && res.status === 'success') {
336
380
  data = res.data;
337
381
  messageOptionRef.current = data || {};
338
382
  }
@@ -348,7 +392,7 @@ function Message(props) {
348
392
  }();
349
393
  return wrapCSSVar(/*#__PURE__*/React.createElement("div", {
350
394
  className: classnames(hashId, cssVarCls, "".concat(messagePrefixCls, "-wrapper"))
351
- }, contextHolder, /*#__PURE__*/React.createElement(_Badge, _extends({
395
+ }, contextHolder, contextHolderModal, /*#__PURE__*/React.createElement(_Badge, _extends({
352
396
  count: messageTotal,
353
397
  offset: [6, 5]
354
398
  }, _badgeOption), /*#__PURE__*/React.createElement(CommonIcon, {
@@ -358,16 +402,16 @@ function Message(props) {
358
402
  })), /*#__PURE__*/React.createElement(_Drawer, {
359
403
  bodyStyle: {
360
404
  height: "calc(100% - ".concat(delHeight, "px)"),
361
- overflow: "visible"
405
+ overflow: 'visible'
362
406
  },
363
- size: "middle",
407
+ size: 'middle',
364
408
  onClose: onClose,
365
409
  open: visible,
366
410
  closeIcon: closable,
367
411
  headerStyle: {
368
412
  height: 0,
369
- border: "none",
370
- overflow: "hidden"
413
+ border: 'none',
414
+ overflow: 'hidden'
371
415
  },
372
416
  rootClassName: classnames("".concat(messagePrefixCls, "-drawer"), _defineProperty({}, "".concat(messagePrefixCls, "-drawer-has-cloable"), closable)),
373
417
  destroyOnClose: true,
@@ -393,16 +437,20 @@ function Message(props) {
393
437
  conditionsRef: conditionsRef,
394
438
  messagePrefixCls: messagePrefixCls,
395
439
  renderMessageDateFormat: renderMessageDateFormat
396
- }))));
440
+ })), enableVoicePrompt && /*#__PURE__*/React.createElement("audio", {
441
+ ref: audioRef,
442
+ preload: "auto",
443
+ src: customAudioSrc || audioMp3
444
+ })));
397
445
  }
398
446
  Message.defaultProps = {
399
447
  pageSize: 30,
400
448
  hideOnSinglePage: false,
401
449
  headerHeight: 48,
402
- gatewayPrefix: "",
450
+ gatewayPrefix: '',
403
451
  isClose: false,
404
452
  timeout: 3000,
405
- socketPathPrefix: "",
453
+ socketPathPrefix: '',
406
454
  closable: false
407
455
  };
408
456
  Message.propTypes = {
@@ -34,7 +34,7 @@ var CWConfigProvider = function CWConfigProvider(_ref) {
34
34
  locales = _ref$locales === void 0 ? {} : _ref$locales,
35
35
  children = _ref.children,
36
36
  _ref$hasAppHolder = _ref.hasAppHolder,
37
- hasAppHolder = _ref$hasAppHolder === void 0 ? true : _ref$hasAppHolder,
37
+ hasAppHolder = _ref$hasAppHolder === void 0 ? false : _ref$hasAppHolder,
38
38
  resProps = _objectWithoutProperties(_ref, _excluded);
39
39
  var _useState = useState(true),
40
40
  _useState2 = _slicedToArray(_useState, 2),
@@ -7,7 +7,7 @@ var genCustomSiderMenuStyle = function genCustomSiderMenuStyle(token) {
7
7
  var prefixCls = token.antCls,
8
8
  iconCls = token.iconCls;
9
9
  var SiderMenuPrefix = "".concat(prefixCls, "-sider-menu");
10
- return _defineProperty(_defineProperty(_defineProperty({}, "".concat(SiderMenuPrefix, "-goup-label"), {
10
+ return _defineProperty({}, "".concat(SiderMenuPrefix, "-cw-menu-box"), _defineProperty(_defineProperty(_defineProperty({}, "".concat(SiderMenuPrefix, "-goup-label"), {
11
11
  borderBottom: "1px solid rgb(246, 247, 248)",
12
12
  width: "calc(100% + 14px)",
13
13
  marginLeft: "-7px",
@@ -29,9 +29,9 @@ var genCustomSiderMenuStyle = function genCustomSiderMenuStyle(token) {
29
29
  color: token.colorPrimary
30
30
  }, iconCls, {
31
31
  transform: "rotate(180deg)"
32
- }))), "".concat(SiderMenuPrefix, "-cw-menu-box-collapsed"), _defineProperty({}, "".concat(SiderMenuPrefix, "-expand-arrow"), {
32
+ }))), "&".concat(SiderMenuPrefix, "-cw-menu-box-collapsed"), _defineProperty({}, "".concat(SiderMenuPrefix, "-expand-arrow"), {
33
33
  display: "none"
34
- }));
34
+ })));
35
35
  };
36
36
  // ============================== Export ==============================
37
37
  export default genStyleHooks("SiderMenu", function (token) {
@@ -67,7 +67,7 @@
67
67
  "d9ef3e74-3325-4272-aa97-2b861fdcf8ff": "Load failed",
68
68
  "dd25dcba-5aea-4f44-9653-9ff61442e830": "Back",
69
69
  "dd9a42ea-9eca-4315-b925-8cc97cacfd41": "Absolute",
70
- "dda16720-d447-4d73-9e71-b5af7b5bbcfd": "Click or drag files to this area",
70
+ "de6eaecc-9d39-41f1-82d3-80694c558028": "Message alerts can be played automatically only when interactive behavior is required",
71
71
  "df9a3bfb-00df-44cd-9761-87dc21ffc0e8": "Smooth forward",
72
72
  "e1f25f97-3a00-4e98-b73c-069638e57184": "The browser version is too early. We recommended that upgrade the browser to avoid potential security risks",
73
73
  "e2008629-6fc2-4222-b28c-ada43aa79a74": "Does not match the input format, please re-enter",
@@ -67,7 +67,7 @@
67
67
  "d9ef3e74-3325-4272-aa97-2b861fdcf8ff": "加载失败",
68
68
  "dd25dcba-5aea-4f44-9653-9ff61442e830": "上一步",
69
69
  "dd9a42ea-9eca-4315-b925-8cc97cacfd41": "绝对",
70
- "dda16720-d447-4d73-9e71-b5af7b5bbcfd": "单击或拖动文件到此区域",
70
+ "de6eaecc-9d39-41f1-82d3-80694c558028": "消息提醒需要有交互行为才可以自动播放",
71
71
  "df9a3bfb-00df-44cd-9761-87dc21ffc0e8": "向前平滑",
72
72
  "e1f25f97-3a00-4e98-b73c-069638e57184": "浏览器版本过低,为避免可能存在的安全隐患,推荐升级一下浏览器",
73
73
  "e2008629-6fc2-4222-b28c-ada43aa79a74": "不符合输入格式,请重新输入",
@@ -67,7 +67,7 @@
67
67
  "d9ef3e74-3325-4272-aa97-2b861fdcf8ff": "加載失敗",
68
68
  "dd25dcba-5aea-4f44-9653-9ff61442e830": "上一步",
69
69
  "dd9a42ea-9eca-4315-b925-8cc97cacfd41": "絕對",
70
- "dda16720-d447-4d73-9e71-b5af7b5bbcfd": "單擊或拖動檔案到此區域",
70
+ "de6eaecc-9d39-41f1-82d3-80694c558028": "消息提醒需要有交互行爲纔可以自動播放",
71
71
  "df9a3bfb-00df-44cd-9761-87dc21ffc0e8": "向前平滑",
72
72
  "e1f25f97-3a00-4e98-b73c-069638e57184": "瀏覽器版本過低,爲避免可能存在的安全隱患,推薦升級一下瀏覽器",
73
73
  "e2008629-6fc2-4222-b28c-ada43aa79a74": "不符合輸入格式,請重新輸入",
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@chaoswise/ui",
3
3
  "packageName": "chaoswiseUI",
4
- "version": "3.1.2",
4
+ "version": "3.1.3",
5
5
  "description": "公共UI库",
6
6
  "keywords": [
7
7
  "ui",