1 | import "core-js/modules/es7.object.get-own-property-descriptors";
|
2 | import "core-js/modules/es6.symbol";
|
3 | import "core-js/modules/web.dom.iterable";
|
4 | import "core-js/modules/es6.array.iterator";
|
5 | import "core-js/modules/es6.object.to-string";
|
6 | import "core-js/modules/es6.object.keys";
|
7 | import "core-js/modules/es6.object.assign";
|
8 | import "core-js/modules/es6.function.name";
|
9 | import _defineProperty from "@babel/runtime/helpers/defineProperty";
|
10 | import _regeneratorRuntime from "@babel/runtime/regenerator";
|
11 | import "regenerator-runtime/runtime";
|
12 | import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
|
13 |
|
14 | function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }
|
15 |
|
16 | function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(source, true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(source).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
|
17 |
|
18 | import * as React from 'react';
|
19 | import Reply from '@beisen-cmps/italent-reply';
|
20 | import { ShowPopConfirm } from '@beisen-cmps/italent-feedmix-components';
|
21 | import { deleteCommentById, addComment, getAllComment } from './helper/require';
|
22 | import { handleReward, isI18NZH } from './helper/index';
|
23 | import EmptyPage from './components/emptyPage/index';
|
24 | import CommentorCooperation from './commentor-cooperation';
|
25 | import ImgPreview from '@beisen-phoenix/img-preview';
|
26 | import { isTop, getTenantId, getUserId, getApiPath, imgPreviewTop, getUserUrl } from './helper';
|
27 | import { LIMITNUM } from './helper/const';
|
28 | import '@beisen-cmps/italent-icon';
|
29 | var useCallback = React.useCallback,
|
30 | useState = React.useState,
|
31 | useRef = React.useRef;
|
32 |
|
33 | var CooReplyUser = function CooReplyUser(props) {
|
34 | return React.createElement("div", {
|
35 | className: "rp-container"
|
36 | }, props.translation.replyTo, React.createElement("span", {
|
37 | className: "rp-container-name"
|
38 | }, props.commentUser, React.createElement("span", {
|
39 | className: "_italent-font-close close",
|
40 | onClick: props.handleclearCommentUser
|
41 | })));
|
42 | };
|
43 |
|
44 | var CooReply = function CooReply(props) {
|
45 | var _props$feedComments = props.feedComments,
|
46 | feedComments = _props$feedComments === void 0 ? {
|
47 | total: 0,
|
48 | comments: []
|
49 | } : _props$feedComments,
|
50 | id = props.id,
|
51 | _props$isShowReward = props.isShowReward,
|
52 | isShowReward = _props$isShowReward === void 0 ? false : _props$isShowReward,
|
53 | _props$isShowMentionA = props.isShowMentionAllBtn,
|
54 | isShowMentionAllBtn = _props$isShowMentionA === void 0 ? true : _props$isShowMentionA,
|
55 | _props$userAdvanceMod = props.userAdvanceMode,
|
56 | userAdvanceMode = _props$userAdvanceMod === void 0 ? false : _props$userAdvanceMod,
|
57 | _props$isShowMentionB = props.isShowMentionBtn,
|
58 | isShowMentionBtn = _props$isShowMentionB === void 0 ? true : _props$isShowMentionB,
|
59 | _props$isShowEmojyBtn = props.isShowEmojyBtn,
|
60 | isShowEmojyBtn = _props$isShowEmojyBtn === void 0 ? true : _props$isShowEmojyBtn,
|
61 | _props$isShowVisible = props.isShowVisible,
|
62 | isShowVisible = _props$isShowVisible === void 0 ? false : _props$isShowVisible,
|
63 | _props$isShowModal = props.isShowModal,
|
64 | isShowModal = _props$isShowModal === void 0 ? false : _props$isShowModal,
|
65 | _props$isShowUploadBt = props.isShowUploadBtn,
|
66 | isShowUploadBtn = _props$isShowUploadBt === void 0 ? true : _props$isShowUploadBt,
|
67 | operationBtnExternal = props.operationBtnExternal,
|
68 | translation = props.translation;
|
69 |
|
70 | var _ref = feedComments || {},
|
71 | _ref$total = _ref.total,
|
72 | total = _ref$total === void 0 ? 0 : _ref$total,
|
73 | _ref$comments = _ref.comments,
|
74 | comments = _ref$comments === void 0 ? [] : _ref$comments;
|
75 |
|
76 | var textareaRef = useRef();
|
77 |
|
78 | var _useState = useState(false),
|
79 | _useState2 = _slicedToArray(_useState, 2),
|
80 | showImgPreview = _useState2[0],
|
81 | setShowImgPreview = _useState2[1];
|
82 |
|
83 |
|
84 | var _useState3 = useState(),
|
85 | _useState4 = _slicedToArray(_useState3, 2),
|
86 | previewFiles = _useState4[0],
|
87 | setPreviewFiles = _useState4[1];
|
88 |
|
89 |
|
90 | var _useState5 = useState(0),
|
91 | _useState6 = _slicedToArray(_useState5, 2),
|
92 | previewIndex = _useState6[0],
|
93 | setPreviewIndex = _useState6[1];
|
94 |
|
95 |
|
96 | var _useState7 = useState(total),
|
97 | _useState8 = _slicedToArray(_useState7, 2),
|
98 | allTotal = _useState8[0],
|
99 | setAllTotal = _useState8[1];
|
100 |
|
101 |
|
102 | var _useState9 = useState(0),
|
103 | _useState10 = _slicedToArray(_useState9, 2),
|
104 | commentId = _useState10[0],
|
105 | setCommentId = _useState10[1];
|
106 |
|
107 |
|
108 | var _useState11 = useState(''),
|
109 | _useState12 = _slicedToArray(_useState11, 2),
|
110 | commentUser = _useState12[0],
|
111 | setCommentUser = _useState12[1];
|
112 |
|
113 |
|
114 | var _useState13 = useState(comments),
|
115 | _useState14 = _slicedToArray(_useState13, 2),
|
116 | allComments = _useState14[0],
|
117 | setComments = _useState14[1];
|
118 |
|
119 | var handleDeleteReply = useCallback(function (commentId, target, hoverCallback) {
|
120 | ShowPopConfirm({
|
121 | message: translation.deleteMsg,
|
122 | targetNode: target,
|
123 | isShowTriangle: false,
|
124 | align: 'right',
|
125 | handleOk: function handleOk() {
|
126 | var _ref2, Code, newComments;
|
127 |
|
128 | return _regeneratorRuntime.async(function handleOk$(_context) {
|
129 | while (1) {
|
130 | switch (_context.prev = _context.next) {
|
131 | case 0:
|
132 | _context.next = 2;
|
133 | return _regeneratorRuntime.awrap(deleteCommentById({
|
134 | feed_id: id,
|
135 | comment_id: commentId
|
136 | }));
|
137 |
|
138 | case 2:
|
139 | _ref2 = _context.sent;
|
140 | Code = _ref2.Code;
|
141 |
|
142 | if (Code == 1) {
|
143 |
|
144 | newComments = allComments.filter(function (item) {
|
145 | return item.commentId != commentId;
|
146 | });
|
147 | setComments(newComments);
|
148 | setAllTotal(allTotal - 1);
|
149 | }
|
150 |
|
151 |
|
152 | hoverCallback(true);
|
153 |
|
154 | case 6:
|
155 | case "end":
|
156 | return _context.stop();
|
157 | }
|
158 | }
|
159 | });
|
160 | },
|
161 | handleClose: function handleClose() {
|
162 | hoverCallback(true);
|
163 | },
|
164 | cancelText: translation.cancelText,
|
165 | confirmText: translation.confirmText,
|
166 | size: {
|
167 | height: isI18NZH() ? 80 : 100,
|
168 | width: 260
|
169 | }
|
170 | });
|
171 | }, [allTotal, allComments]);
|
172 | var handleAddComment = useCallback(function (obj) {
|
173 | addComment(_objectSpread({}, obj, {
|
174 | FeedId: id,
|
175 | CommentId: commentId
|
176 | })).then(function (data) {
|
177 | var Code = data.Code,
|
178 | Data = data.Data;
|
179 |
|
180 | if (Code === 1) {
|
181 | var newComments;
|
182 |
|
183 | if (allComments && allComments.length > 0) {
|
184 | newComments = [].concat(allComments, [Data]);
|
185 | } else {
|
186 | newComments = [Data];
|
187 | }
|
188 |
|
189 | setCommentId(0);
|
190 | setCommentUser('');
|
191 | setComments(newComments);
|
192 | setAllTotal(allTotal + 1);
|
193 | }
|
194 | });
|
195 | }, [id, allComments, allTotal, commentId, commentUser]);
|
196 | var handleReplyClick = useCallback(function (commentId, target, hoverCallback) {
|
197 | setCommentId(commentId);
|
198 | setCommentUser(target.name);
|
199 |
|
200 | textareaRef.current && textareaRef.current.focus();
|
201 | }, [commentId, commentUser]);
|
202 |
|
203 | var handleShowAllReply = useCallback(function (flag) {
|
204 | if (flag) {
|
205 | getAllComment({
|
206 | feed_id: id
|
207 | }).then(function (data) {
|
208 | var Code = data.Code,
|
209 | Data = data.Data;
|
210 |
|
211 | if (Code === 1 && Data) {
|
212 | setAllTotal(Data.total);
|
213 | setComments(Data.comments);
|
214 | }
|
215 | });
|
216 | } else {
|
217 | var cLength = allComments.length;
|
218 |
|
219 | if (cLength > LIMITNUM) {
|
220 | setComments(allComments.slice(cLength - LIMITNUM));
|
221 | }
|
222 | }
|
223 | }, [allComments, id]);
|
224 |
|
225 | var handleImgPreview = useCallback(function (files, index) {
|
226 | if (isTop()) {
|
227 | setPreviewFiles(files);
|
228 | setPreviewIndex(index);
|
229 | setShowImgPreview(true);
|
230 | } else {
|
231 | imgPreviewTop(files, index);
|
232 | }
|
233 | }, []);
|
234 |
|
235 | var handleImgPreviewClose = useCallback(function () {
|
236 | setShowImgPreview(false);
|
237 | }, []);
|
238 |
|
239 | var handleImgDownload = useCallback(function (file) {
|
240 | if (file && file.downloadUrl) {
|
241 | window.open(file.downloadUrl, '_self');
|
242 | }
|
243 | }, []);
|
244 |
|
245 | var handleclearCommentUser = useCallback(function () {
|
246 | setCommentUser('');
|
247 | setCommentId(0);
|
248 | }, []);
|
249 | var getTextRef = useCallback(function (ref) {
|
250 | textareaRef.current = ref;
|
251 | }, []);
|
252 |
|
253 | var handleRewardFunc = useCallback(function (val) {
|
254 | handleReward(val, id);
|
255 | }, [id]);
|
256 | var replyProps = {
|
257 | total: allTotal,
|
258 | comments: allComments,
|
259 | isShowAllReply: total > LIMITNUM,
|
260 | isShowReward: isShowReward,
|
261 | onReward: handleRewardFunc,
|
262 | onReplyDelete: handleDeleteReply,
|
263 | onShowAllReply: handleShowAllReply,
|
264 | onImgPreview: handleImgPreview,
|
265 | onReply: handleReplyClick,
|
266 | isShowModal: isShowModal,
|
267 | getUserUrl: getUserUrl,
|
268 | isBgColor: false
|
269 | };
|
270 | return React.createElement(React.Fragment, null, allTotal > 0 ? React.createElement(Reply, Object.assign({}, replyProps)) : React.createElement(EmptyPage, {
|
271 | translation: translation
|
272 | }), React.createElement("div", {
|
273 | className: "rp-body"
|
274 | }, commentUser && React.createElement(CooReplyUser, {
|
275 | commentUser: commentUser,
|
276 | handleclearCommentUser: handleclearCommentUser,
|
277 | translation: translation
|
278 | }), React.createElement(CommentorCooperation, {
|
279 | tenantId: getTenantId(),
|
280 | apiPath: getApiPath(),
|
281 | userId: getUserId(),
|
282 | onAddComment: handleAddComment,
|
283 | getTextRef: getTextRef,
|
284 | isShowRewardBtn: isShowReward,
|
285 | feedId: id,
|
286 | userAdvanceMode: userAdvanceMode,
|
287 | isShowMentionAllBtn: isShowMentionAllBtn,
|
288 | isShowVisible: isShowVisible,
|
289 | isShowMentionBtn: isShowMentionBtn,
|
290 | isShowEmojyBtn: isShowEmojyBtn,
|
291 | isShowUploadBtn: isShowUploadBtn,
|
292 | isShowModal: isShowModal,
|
293 | operationBtnExternal: operationBtnExternal,
|
294 | translation: translation
|
295 | })), showImgPreview && React.createElement(ImgPreview, {
|
296 | files: previewFiles,
|
297 | onClose: handleImgPreviewClose,
|
298 | onDownload: handleImgDownload,
|
299 | defaultSelected: previewIndex
|
300 | }));
|
301 | };
|
302 |
|
303 | export default CooReply; |
\ | No newline at end of file |