@fle-ui/plus-im-record 0.0.8-beta.0 → 0.0.8-beta.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.
- package/es/@types/index.d.ts +620 -0
- package/es/CardTag/index.d.ts +3 -0
- package/es/CardTag/index.js +18 -0
- package/es/ChatMessageItem/index.d.ts +15 -0
- package/es/ChatMessageItem/index.js +130 -0
- package/es/ChatMessageItem/index.less +108 -0
- package/es/ChatMessageList/index.d.ts +29 -0
- package/es/ChatMessageList/index.js +66 -0
- package/es/ChatMessageList/index.less +34 -0
- package/es/GoodsCard/index.d.ts +15 -0
- package/es/GoodsCard/index.js +95 -0
- package/es/GoodsCard/index.less +49 -0
- package/es/GoodsOrderCard/index.d.ts +14 -0
- package/es/GoodsOrderCard/index.js +161 -0
- package/es/GoodsOrderCard/index.less +81 -0
- package/es/Icon/index.d.ts +8 -0
- package/es/Icon/index.js +11 -0
- package/es/ParseSession/AudioPlayer.d.ts +14 -0
- package/es/ParseSession/AudioPlayer.js +89 -0
- package/es/ParseSession/audioAndVideoTool.d.ts +3 -0
- package/es/ParseSession/audioAndVideoTool.js +21 -0
- package/es/ParseSession/index.d.ts +15 -0
- package/es/ParseSession/index.js +492 -0
- package/es/ParseSession/index.less +226 -0
- package/es/api/index.d.ts +30 -0
- package/es/api/index.js +48 -0
- package/es/audioAndVideoTool.d.ts +3 -0
- package/es/audioAndVideoTool.js +21 -0
- package/es/common/const/index.d.ts +46 -0
- package/es/common/const/index.js +82 -0
- package/es/common/utils/index.d.ts +33 -0
- package/es/common/utils/index.js +169 -0
- package/es/index.d.ts +38 -0
- package/es/index.js +111 -0
- package/es/styles/extends.less +50 -0
- package/es/styles/index.less +35 -0
- package/es/styles/vars.less +8 -0
- package/es/utils/index.d.ts +14 -0
- package/es/utils/index.js +50 -0
- package/lib/@types/index.d.ts +620 -0
- package/lib/CardTag/index.d.ts +3 -0
- package/lib/CardTag/index.js +25 -0
- package/lib/ChatMessageItem/index.d.ts +15 -0
- package/lib/ChatMessageItem/index.js +136 -0
- package/lib/ChatMessageItem/index.less +108 -0
- package/lib/ChatMessageList/index.d.ts +29 -0
- package/lib/ChatMessageList/index.js +76 -0
- package/lib/ChatMessageList/index.less +34 -0
- package/lib/GoodsCard/index.d.ts +15 -0
- package/lib/GoodsCard/index.js +105 -0
- package/lib/GoodsCard/index.less +49 -0
- package/lib/GoodsOrderCard/index.d.ts +14 -0
- package/lib/GoodsOrderCard/index.js +169 -0
- package/lib/GoodsOrderCard/index.less +81 -0
- package/lib/Icon/index.d.ts +8 -0
- package/lib/Icon/index.js +18 -0
- package/lib/ParseSession/AudioPlayer.d.ts +14 -0
- package/lib/ParseSession/AudioPlayer.js +98 -0
- package/lib/ParseSession/audioAndVideoTool.d.ts +3 -0
- package/lib/ParseSession/audioAndVideoTool.js +27 -0
- package/lib/ParseSession/index.d.ts +15 -0
- package/lib/ParseSession/index.js +494 -0
- package/lib/ParseSession/index.less +226 -0
- package/lib/api/index.d.ts +30 -0
- package/lib/api/index.js +55 -0
- package/lib/audioAndVideoTool.d.ts +3 -0
- package/lib/audioAndVideoTool.js +27 -0
- package/lib/common/const/index.d.ts +46 -0
- package/lib/common/const/index.js +88 -0
- package/lib/common/utils/index.d.ts +33 -0
- package/lib/common/utils/index.js +183 -0
- package/lib/index.d.ts +38 -0
- package/lib/index.js +119 -0
- package/lib/styles/extends.less +50 -0
- package/lib/styles/index.less +35 -0
- package/lib/styles/vars.less +8 -0
- package/lib/utils/index.d.ts +14 -0
- package/lib/utils/index.js +56 -0
- package/package.json +2 -2
|
@@ -0,0 +1,183 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.concatMsgs = concatMsgs;
|
|
7
|
+
exports.copyText = copyText;
|
|
8
|
+
exports.default = void 0;
|
|
9
|
+
exports.downloadByUrl = downloadByUrl;
|
|
10
|
+
exports.getDateDiff = getDateDiff;
|
|
11
|
+
exports.getSessionIdFromMsg = getSessionIdFromMsg;
|
|
12
|
+
exports.getSimplifyMsg = getSimplifyMsg;
|
|
13
|
+
exports.matchs = void 0;
|
|
14
|
+
exports.paserAttach = paserAttach;
|
|
15
|
+
var _const = require("../const");
|
|
16
|
+
function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
|
|
17
|
+
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."); }
|
|
18
|
+
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); }
|
|
19
|
+
function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
|
|
20
|
+
function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
|
|
21
|
+
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; }
|
|
22
|
+
/* eslint-disable radix */
|
|
23
|
+
function getSessionIdFromMsg(msg, myAccount) {
|
|
24
|
+
// 在群中,不管 from 是不是自己,sessionId 都要取 to
|
|
25
|
+
var from = msg.from,
|
|
26
|
+
to = msg.to,
|
|
27
|
+
scene = msg.scene;
|
|
28
|
+
var target = '';
|
|
29
|
+
if (scene === 'p2p') {
|
|
30
|
+
if (from === myAccount) {
|
|
31
|
+
target = to;
|
|
32
|
+
} else {
|
|
33
|
+
target = from;
|
|
34
|
+
}
|
|
35
|
+
} else {
|
|
36
|
+
target = to;
|
|
37
|
+
}
|
|
38
|
+
var sessionId = "".concat(scene, "-").concat(target);
|
|
39
|
+
return sessionId;
|
|
40
|
+
}
|
|
41
|
+
function paserAttach() {
|
|
42
|
+
var attach = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
43
|
+
if (attach.content && typeof attach.content === 'string' && ![_const.imMsgTypes.tip, _const.imMsgTypes.text].includes(attach.type)) {
|
|
44
|
+
var defaultObj = [_const.imMsgTypes.faq].includes(attach.type) ? [] : {};
|
|
45
|
+
try {
|
|
46
|
+
attach.content = JSON.parse(attach.content);
|
|
47
|
+
} catch (error) {
|
|
48
|
+
console.log('paser', error);
|
|
49
|
+
attach.content = defaultObj;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
return attach;
|
|
53
|
+
}
|
|
54
|
+
function getSimplifyMsg() {
|
|
55
|
+
var attach = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
56
|
+
var type = attach.type,
|
|
57
|
+
content = attach.content;
|
|
58
|
+
if ([_const.imMsgTypes.text, _const.imMsgTypes.tip].includes(type)) return content;
|
|
59
|
+
if (type === _const.imMsgTypes.faqLink) return content.title;
|
|
60
|
+
if (type === _const.imMsgTypes.event) return content.tips;
|
|
61
|
+
if (type === _const.imMsgTypes.audio) return '[音频]...';
|
|
62
|
+
if (type === _const.imMsgTypes.faq) return '[猜你想问]...';
|
|
63
|
+
if (type === _const.imMsgTypes.file) return '[文件]...';
|
|
64
|
+
if (type === _const.imMsgTypes.formCustomer) return '[表单]...';
|
|
65
|
+
if (type === _const.imMsgTypes.image) return '[图片]...';
|
|
66
|
+
if (type === _const.imMsgTypes.video) return '[视频]...';
|
|
67
|
+
if (type === _const.imMsgTypes.link) return '[链接]...';
|
|
68
|
+
if (type === _const.imMsgTypes.order) return '[订单卡片]...';
|
|
69
|
+
if (type === _const.imMsgTypes.product) return '[商品卡片]...';
|
|
70
|
+
if (type === _const.imMsgTypes.chatrecord) return '[转接记录]...';
|
|
71
|
+
}
|
|
72
|
+
function concatMsgs() {
|
|
73
|
+
var arr1 = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
|
|
74
|
+
var arr2 = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [];
|
|
75
|
+
var idMap = {};
|
|
76
|
+
var result = [];
|
|
77
|
+
[].concat(_toConsumableArray(arr1), _toConsumableArray(arr2)).forEach(function () {
|
|
78
|
+
var item = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
79
|
+
if (!idMap[item.idServer]) {
|
|
80
|
+
result.push(item);
|
|
81
|
+
idMap[item.idServer] = true;
|
|
82
|
+
}
|
|
83
|
+
});
|
|
84
|
+
result.sort(function (a, b) {
|
|
85
|
+
return a.time - b.time;
|
|
86
|
+
});
|
|
87
|
+
return result;
|
|
88
|
+
}
|
|
89
|
+
// 时间戳转多少分钟之前
|
|
90
|
+
function getDateDiff(dateTimeStamp) {
|
|
91
|
+
var timestamp = dateTimeStamp || new Date().getTime();
|
|
92
|
+
var minute = 1000 * 60;
|
|
93
|
+
var hour = minute * 60;
|
|
94
|
+
var day = hour * 24;
|
|
95
|
+
var month = day * 30;
|
|
96
|
+
var year = day * 365;
|
|
97
|
+
var now = new Date().getTime();
|
|
98
|
+
var diffValue = now - timestamp;
|
|
99
|
+
var result;
|
|
100
|
+
if (diffValue < 0) {
|
|
101
|
+
return '刚刚';
|
|
102
|
+
}
|
|
103
|
+
var yearC = Math.floor(diffValue / year);
|
|
104
|
+
var monthC = Math.floor(diffValue / month);
|
|
105
|
+
var weekC = Math.floor(diffValue / (7 * day));
|
|
106
|
+
var dayC = Math.floor(diffValue / day);
|
|
107
|
+
var hourC = Math.floor(diffValue / hour);
|
|
108
|
+
var minC = Math.floor(diffValue / minute);
|
|
109
|
+
if (yearC >= 1) {
|
|
110
|
+
result = "".concat(yearC, "\u5E74\u524D");
|
|
111
|
+
} else if (monthC >= 1) {
|
|
112
|
+
result = "".concat(monthC, "\u6708\u524D");
|
|
113
|
+
} else if (weekC >= 1) {
|
|
114
|
+
result = "".concat(weekC, "\u5468\u524D");
|
|
115
|
+
} else if (dayC >= 1) {
|
|
116
|
+
result = "".concat(dayC, "\u5929\u524D");
|
|
117
|
+
} else if (hourC >= 1) {
|
|
118
|
+
result = "".concat(hourC, "\u5C0F\u65F6\u524D");
|
|
119
|
+
} else if (minC >= 1) {
|
|
120
|
+
result = "".concat(minC, "\u5206\u949F\u524D");
|
|
121
|
+
} else result = '刚刚';
|
|
122
|
+
return result;
|
|
123
|
+
}
|
|
124
|
+
function downloadByUrl(src) {
|
|
125
|
+
fetch(src).then(function (response) {
|
|
126
|
+
return response.blob();
|
|
127
|
+
}).then(function (blob) {
|
|
128
|
+
var url = URL.createObjectURL(new Blob([blob]));
|
|
129
|
+
var link = document.createElement('a');
|
|
130
|
+
link.href = url;
|
|
131
|
+
link.download = 'image.png';
|
|
132
|
+
document.body.appendChild(link);
|
|
133
|
+
link.click();
|
|
134
|
+
URL.revokeObjectURL(url);
|
|
135
|
+
link.remove();
|
|
136
|
+
});
|
|
137
|
+
}
|
|
138
|
+
/**
|
|
139
|
+
* 将文字写入剪切板
|
|
140
|
+
* @param {string} text
|
|
141
|
+
* @returns {Promise} 返回promise对象
|
|
142
|
+
*/
|
|
143
|
+
function copyText() {
|
|
144
|
+
var text = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : '';
|
|
145
|
+
// 在调用前 先访问是否存在 clipboard 对象
|
|
146
|
+
if (navigator.clipboard) {
|
|
147
|
+
return navigator.clipboard.writeText(text);
|
|
148
|
+
} else {
|
|
149
|
+
try {
|
|
150
|
+
var t = document.createElement('textarea');
|
|
151
|
+
t.nodeValue = text;
|
|
152
|
+
t.value = text;
|
|
153
|
+
document.body.appendChild(t);
|
|
154
|
+
t.select();
|
|
155
|
+
document.execCommand('copy');
|
|
156
|
+
document.body.removeChild(t);
|
|
157
|
+
return Promise.resolve();
|
|
158
|
+
} catch (e) {
|
|
159
|
+
return Promise.reject(e);
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
var matchs = exports.matchs = {
|
|
164
|
+
paserProductFromUrl: function paserProductFromUrl(str) {
|
|
165
|
+
if (!str) return null;
|
|
166
|
+
var res = str.match(/^https*(.+?)(product\/product_info|productDetail|goodsDetail)\/(\d+)$/);
|
|
167
|
+
return res === null || res === void 0 ? void 0 : res[3];
|
|
168
|
+
},
|
|
169
|
+
paserOrderFromUrl: function paserOrderFromUrl(str) {
|
|
170
|
+
if (!str) return null;
|
|
171
|
+
var res = str.match(/^https*(.+?)(order\/order_detail.+?order_id=)(\d+)$/);
|
|
172
|
+
return res === null || res === void 0 ? void 0 : res[3];
|
|
173
|
+
}
|
|
174
|
+
};
|
|
175
|
+
var _default = exports.default = {
|
|
176
|
+
getSessionIdFromMsg: getSessionIdFromMsg,
|
|
177
|
+
paserAttach: paserAttach,
|
|
178
|
+
getDateDiff: getDateDiff,
|
|
179
|
+
downloadByUrl: downloadByUrl,
|
|
180
|
+
copyText: copyText,
|
|
181
|
+
getSimplifyMsg: getSimplifyMsg,
|
|
182
|
+
matchs: matchs
|
|
183
|
+
};
|
package/lib/index.d.ts
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import React, { UIEventHandler } from 'react';
|
|
2
|
+
import { RecordSession } from './ChatMessageList';
|
|
3
|
+
import { apiCreate, Env } from './api';
|
|
4
|
+
import { IMMessage } from './@types';
|
|
5
|
+
import './styles/index.less';
|
|
6
|
+
/**
|
|
7
|
+
* @name 客服记录组件
|
|
8
|
+
* @description 代码由小鲤客服平台搬运简来.
|
|
9
|
+
*/
|
|
10
|
+
export interface IMRecordProps {
|
|
11
|
+
env?: Env;
|
|
12
|
+
token?: string;
|
|
13
|
+
h5?: boolean;
|
|
14
|
+
msgs: IMMessage[];
|
|
15
|
+
myAccount?: string;
|
|
16
|
+
loadingStarus?: 'loading' | 'nomore';
|
|
17
|
+
onScrollTop?: UIEventHandler<HTMLDivElement>;
|
|
18
|
+
onScrollBottom?: UIEventHandler<HTMLDivElement>;
|
|
19
|
+
style?: React.CSSProperties;
|
|
20
|
+
isSessionEnd?: boolean;
|
|
21
|
+
recordSession?: RecordSession;
|
|
22
|
+
/**是否显示搜索输入框 默认为false*/
|
|
23
|
+
showSearchInput?: boolean;
|
|
24
|
+
/**搜索事件,对外抛出搜索关键字*/
|
|
25
|
+
onSearch?: (keyword: string) => void;
|
|
26
|
+
/**搜索模式
|
|
27
|
+
* internal: 内部搜索 只对输入到组件内部的msgs进行搜索
|
|
28
|
+
* external: 外部搜索 只对外抛出搜索关键字,在外部搜索,从而改变输入到组件的msgs
|
|
29
|
+
* 默认为internal
|
|
30
|
+
*/
|
|
31
|
+
searchMode?: 'internal' | 'external';
|
|
32
|
+
}
|
|
33
|
+
export interface ImContextProps {
|
|
34
|
+
api: ReturnType<typeof apiCreate>;
|
|
35
|
+
}
|
|
36
|
+
export declare const ImContext: React.Context<ImContextProps>;
|
|
37
|
+
declare const IMRecord: React.FC<IMRecordProps>;
|
|
38
|
+
export default IMRecord;
|
package/lib/index.js
ADDED
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
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); }
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.default = exports.ImContext = void 0;
|
|
8
|
+
var _react = _interopRequireWildcard(require("react"));
|
|
9
|
+
var _ChatMessageList = _interopRequireDefault(require("./ChatMessageList"));
|
|
10
|
+
var _api = require("./api");
|
|
11
|
+
var _antd = require("antd");
|
|
12
|
+
require("./styles/index.less");
|
|
13
|
+
var _excluded = ["env", "token", "msgs", "recordSession", "showSearchInput", "searchMode", "onSearch"];
|
|
14
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
15
|
+
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(e) { return e ? t : r; })(e); }
|
|
16
|
+
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != _typeof(e) && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
|
|
17
|
+
function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
|
|
18
|
+
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
19
|
+
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
20
|
+
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
21
|
+
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; }
|
|
22
|
+
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); }
|
|
23
|
+
function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
|
|
24
|
+
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."); }
|
|
25
|
+
function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
|
|
26
|
+
function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
|
|
27
|
+
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
|
|
28
|
+
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."); }
|
|
29
|
+
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); }
|
|
30
|
+
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; }
|
|
31
|
+
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; } }
|
|
32
|
+
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
33
|
+
function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
|
|
34
|
+
function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } } return target; }
|
|
35
|
+
var ImContext = exports.ImContext = /*#__PURE__*/(0, _react.createContext)({});
|
|
36
|
+
var IMRecord = function IMRecord(_ref) {
|
|
37
|
+
var env = _ref.env,
|
|
38
|
+
token = _ref.token,
|
|
39
|
+
msgs = _ref.msgs,
|
|
40
|
+
recordSession = _ref.recordSession,
|
|
41
|
+
_ref$showSearchInput = _ref.showSearchInput,
|
|
42
|
+
showSearchInput = _ref$showSearchInput === void 0 ? false : _ref$showSearchInput,
|
|
43
|
+
_ref$searchMode = _ref.searchMode,
|
|
44
|
+
searchMode = _ref$searchMode === void 0 ? 'internal' : _ref$searchMode,
|
|
45
|
+
onSearch = _ref.onSearch,
|
|
46
|
+
restProps = _objectWithoutProperties(_ref, _excluded);
|
|
47
|
+
var api = (0, _api.apiCreate)(env, token);
|
|
48
|
+
var _useState = (0, _react.useState)({}),
|
|
49
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
50
|
+
accountsMap = _useState2[0],
|
|
51
|
+
setAccountsMap = _useState2[1];
|
|
52
|
+
var _useState3 = (0, _react.useState)(),
|
|
53
|
+
_useState4 = _slicedToArray(_useState3, 2),
|
|
54
|
+
searchValue = _useState4[0],
|
|
55
|
+
setSearchValue = _useState4[1];
|
|
56
|
+
var messageListDomRef = (0, _react.useRef)(null);
|
|
57
|
+
(0, _react.useEffect)(function () {
|
|
58
|
+
var accids = _toConsumableArray(new Set(msgs.map(function (x) {
|
|
59
|
+
return x.from;
|
|
60
|
+
})));
|
|
61
|
+
if (accids.length) {
|
|
62
|
+
getAccountByAccids(accids);
|
|
63
|
+
}
|
|
64
|
+
}, [msgs]);
|
|
65
|
+
(0, _react.useEffect)(function () {
|
|
66
|
+
var handler = setTimeout(function () {
|
|
67
|
+
if (onSearch && searchValue !== undefined) {
|
|
68
|
+
onSearch(searchValue); // 仅在external模式下触发onSearch
|
|
69
|
+
}
|
|
70
|
+
}, 300); // 300ms的防抖时间,可以根据需要调整
|
|
71
|
+
return function () {
|
|
72
|
+
clearTimeout(handler); // 清除上一次的定时器
|
|
73
|
+
};
|
|
74
|
+
}, [searchValue, searchMode, onSearch]);
|
|
75
|
+
function getAccountByAccids(accids) {
|
|
76
|
+
api.getAccountInfoByAccid({
|
|
77
|
+
accids: accids
|
|
78
|
+
}).then(function (_ref2) {
|
|
79
|
+
var data = _ref2.data;
|
|
80
|
+
var temp = {};
|
|
81
|
+
if (Array.isArray(data)) {
|
|
82
|
+
data.forEach(function (item) {
|
|
83
|
+
if (!accountsMap[item.accid]) {
|
|
84
|
+
temp[item.accid] = item;
|
|
85
|
+
}
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
setAccountsMap(function (prev) {
|
|
89
|
+
return _objectSpread(_objectSpread({}, prev), temp);
|
|
90
|
+
});
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
return /*#__PURE__*/_react.default.createElement(ImContext.Provider, {
|
|
94
|
+
value: {
|
|
95
|
+
api: api
|
|
96
|
+
}
|
|
97
|
+
}, showSearchInput && /*#__PURE__*/_react.default.createElement("div", {
|
|
98
|
+
style: {
|
|
99
|
+
padding: 8,
|
|
100
|
+
backgroundColor: '#f7f7f7'
|
|
101
|
+
}
|
|
102
|
+
}, /*#__PURE__*/_react.default.createElement(_antd.Input, {
|
|
103
|
+
value: searchValue,
|
|
104
|
+
onChange: function onChange(e) {
|
|
105
|
+
return setSearchValue(e.target.value);
|
|
106
|
+
},
|
|
107
|
+
allowClear: true,
|
|
108
|
+
placeholder: "\u8F93\u5165\u5BF9\u8BDD\u5173\u952E\u8BCD\u641C\u7D22"
|
|
109
|
+
})), /*#__PURE__*/_react.default.createElement(_ChatMessageList.default, _extends({
|
|
110
|
+
searchValue: searchMode === 'internal' ? searchValue : undefined,
|
|
111
|
+
ref: messageListDomRef,
|
|
112
|
+
msgs: msgs,
|
|
113
|
+
h5: true,
|
|
114
|
+
accountsMap: accountsMap,
|
|
115
|
+
isSessionEnd: true,
|
|
116
|
+
recordSession: recordSession
|
|
117
|
+
}, restProps)));
|
|
118
|
+
};
|
|
119
|
+
var _default = exports.default = IMRecord;
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
@import './vars.less';
|
|
2
|
+
|
|
3
|
+
/* flex 布局样式 */
|
|
4
|
+
.flex {
|
|
5
|
+
display: flex;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
.flex-align-center {
|
|
9
|
+
align-items: center;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
.flex-center {
|
|
13
|
+
&:extend(.flex);
|
|
14
|
+
&:extend(.flex-align-center);
|
|
15
|
+
justify-content: center;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/* 文字样式 */
|
|
19
|
+
|
|
20
|
+
.one-line-text {
|
|
21
|
+
overflow: hidden;
|
|
22
|
+
text-overflow: ellipsis;
|
|
23
|
+
white-space: nowrap;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
.multi-line-text {
|
|
27
|
+
display: -webkit-box;
|
|
28
|
+
-webkit-box-orient: vertical;
|
|
29
|
+
overflow: hidden;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
.two-line-text {
|
|
33
|
+
&:extend(.multi-line-text);
|
|
34
|
+
-webkit-line-clamp: 2;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/* 小滚动条样式 */
|
|
38
|
+
.scrollmini {
|
|
39
|
+
&::-webkit-scrollbar {
|
|
40
|
+
width: 4px;
|
|
41
|
+
}
|
|
42
|
+
&::-webkit-scrollbar-thumb {
|
|
43
|
+
background: #ddd;
|
|
44
|
+
border-radius: 4px;
|
|
45
|
+
border-radius: 2px;
|
|
46
|
+
}
|
|
47
|
+
&::-webkit-scrollbar-thumb:hover {
|
|
48
|
+
background-color: #ddd;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
@import './vars.less';
|
|
2
|
+
@import './extends.less';
|
|
3
|
+
|
|
4
|
+
.mp0() {
|
|
5
|
+
margin: 0;
|
|
6
|
+
padding: 0;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
input::-ms-clear,
|
|
10
|
+
input::-ms-reveal {
|
|
11
|
+
display: none;
|
|
12
|
+
}
|
|
13
|
+
*,
|
|
14
|
+
*::before,
|
|
15
|
+
*::after {
|
|
16
|
+
box-sizing: border-box;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
ul,
|
|
20
|
+
li {
|
|
21
|
+
list-style: none;
|
|
22
|
+
.mp0();
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
::-webkit-scrollbar {
|
|
26
|
+
width: 3px;
|
|
27
|
+
border-radius: 4px;
|
|
28
|
+
}
|
|
29
|
+
::-webkit-scrollbar-thumb {
|
|
30
|
+
background: #ddd;
|
|
31
|
+
border-radius: 4px;
|
|
32
|
+
}
|
|
33
|
+
::-webkit-scrollbar-thumb:hover {
|
|
34
|
+
background-color: #ddd;
|
|
35
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export declare const debounce: <T extends (...args: any[]) => any>(fn: T, delay: number) => (...args: Parameters<T>) => void;
|
|
2
|
+
/**
|
|
3
|
+
* 格式化文件大小
|
|
4
|
+
* @param size 文件大小(字节)
|
|
5
|
+
* @returns 格式化后的文件大小字符串
|
|
6
|
+
*/
|
|
7
|
+
export declare const parseFileSize: (size: number, level?: number) => string;
|
|
8
|
+
/**
|
|
9
|
+
* 给URL添加查询参数
|
|
10
|
+
* @param url 原始URL
|
|
11
|
+
* @param search 要添加的查询字符串
|
|
12
|
+
* @returns 添加参数后的URL
|
|
13
|
+
*/
|
|
14
|
+
export declare const addUrlSearch: (url: string, search: string) => string;
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.parseFileSize = exports.debounce = exports.addUrlSearch = void 0;
|
|
7
|
+
var debounce = exports.debounce = function debounce(fn, delay) {
|
|
8
|
+
var timeoutId;
|
|
9
|
+
return function () {
|
|
10
|
+
var _this = this;
|
|
11
|
+
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
12
|
+
args[_key] = arguments[_key];
|
|
13
|
+
}
|
|
14
|
+
clearTimeout(timeoutId);
|
|
15
|
+
timeoutId = setTimeout(function () {
|
|
16
|
+
// @ts-ignore
|
|
17
|
+
fn.apply(_this, args);
|
|
18
|
+
}, delay);
|
|
19
|
+
};
|
|
20
|
+
};
|
|
21
|
+
/**
|
|
22
|
+
* 格式化文件大小
|
|
23
|
+
* @param size 文件大小(字节)
|
|
24
|
+
* @returns 格式化后的文件大小字符串
|
|
25
|
+
*/
|
|
26
|
+
var parseFileSize = exports.parseFileSize = function parseFileSize(size) {
|
|
27
|
+
var level = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
|
|
28
|
+
var fileSizeMap = {
|
|
29
|
+
0: 'B',
|
|
30
|
+
1: 'KB',
|
|
31
|
+
2: 'MB',
|
|
32
|
+
3: 'GB',
|
|
33
|
+
4: 'TB'
|
|
34
|
+
};
|
|
35
|
+
var handler = function handler(size, level) {
|
|
36
|
+
if (level >= Object.keys(fileSizeMap).length) {
|
|
37
|
+
return 'the file is too big';
|
|
38
|
+
}
|
|
39
|
+
if (size < 1024) {
|
|
40
|
+
return "".concat(size).concat(fileSizeMap[level]);
|
|
41
|
+
}
|
|
42
|
+
return handler(Math.round(size / 1024), level + 1);
|
|
43
|
+
};
|
|
44
|
+
return handler(size, level);
|
|
45
|
+
};
|
|
46
|
+
/**
|
|
47
|
+
* 给URL添加查询参数
|
|
48
|
+
* @param url 原始URL
|
|
49
|
+
* @param search 要添加的查询字符串
|
|
50
|
+
* @returns 添加参数后的URL
|
|
51
|
+
*/
|
|
52
|
+
var addUrlSearch = exports.addUrlSearch = function addUrlSearch(url, search) {
|
|
53
|
+
var urlObj = new URL(url);
|
|
54
|
+
urlObj.search += (urlObj.search.startsWith('?') ? '&' : '?') + search;
|
|
55
|
+
return urlObj.href;
|
|
56
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fle-ui/plus-im-record",
|
|
3
|
-
"version": "0.0.8-beta.
|
|
3
|
+
"version": "0.0.8-beta.3",
|
|
4
4
|
"description": "@fle-ui/plus-im-record",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"fle-ui",
|
|
@@ -45,5 +45,5 @@
|
|
|
45
45
|
"peerDependencies": {
|
|
46
46
|
"react": ">=17.0.0"
|
|
47
47
|
},
|
|
48
|
-
"gitHead": "
|
|
48
|
+
"gitHead": "8df4fb031a0dd746ad5e62f346ee7dd88278e297"
|
|
49
49
|
}
|