通用评论 vedio

index.js 12KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. var _icon = require("antd/es/icon");
  6. var _icon2 = _interopRequireDefault(_icon);
  7. var _avatar = require("antd/es/avatar");
  8. var _avatar2 = _interopRequireDefault(_avatar);
  9. var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
  10. require("antd/es/icon/style/css");
  11. require("antd/es/avatar/style/css");
  12. var _react = require("react");
  13. var _react2 = _interopRequireDefault(_react);
  14. var _propTypes = require("prop-types");
  15. var _propTypes2 = _interopRequireDefault(_propTypes);
  16. var _dayjs = require("dayjs");
  17. var _dayjs2 = _interopRequireDefault(_dayjs);
  18. require("dayjs/locale/zh-cn");
  19. var _relativeTime = require("dayjs/plugin/relativeTime");
  20. var _relativeTime2 = _interopRequireDefault(_relativeTime);
  21. var _Comment = require("../../Comment");
  22. var _Comment2 = _interopRequireDefault(_Comment);
  23. var _CommentInput = require("../CommentInput");
  24. var _CommentInput2 = _interopRequireDefault(_CommentInput);
  25. var _avatar3 = require("../../avatar");
  26. var _avatar4 = _interopRequireDefault(_avatar3);
  27. var _helper = require("../../helper");
  28. var _constant = require("../../constant");
  29. require("./index.css");
  30. var _ImagePreviewer = require("../ImagePreviewer/ImagePreviewer");
  31. var _ImagePreviewer2 = _interopRequireDefault(_ImagePreviewer);
  32. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  33. function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } else { return Array.from(arr); } }
  34. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  35. function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
  36. function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
  37. // import 'dayjs/locale/es';
  38. // import intl from "react-intl-universal";
  39. _dayjs2.default.locale("zh-cn");
  40. _dayjs2.default.extend(_relativeTime2.default);
  41. // const LOCALES = {
  42. // "zh-CN": "zh-cn"
  43. // };
  44. var CommentItem = function (_Component) {
  45. _inherits(CommentItem, _Component);
  46. function CommentItem(props) {
  47. _classCallCheck(this, CommentItem);
  48. var _this = _possibleConstructorReturn(this, (CommentItem.__proto__ || Object.getPrototypeOf(CommentItem)).call(this, props));
  49. _this.state = {
  50. showInput: false,
  51. showPreviewer: false,
  52. previewerIndex: 0
  53. };
  54. _this.handleToggleInput = _this.handleToggleInput.bind(_this);
  55. _this.renderTextWithReply = _this.renderTextWithReply.bind(_this);
  56. _this.showPreviewer = _this.showPreviewer.bind(_this);
  57. _this.hidePreviewer = _this.hidePreviewer.bind(_this);
  58. return _this;
  59. }
  60. _createClass(CommentItem, [{
  61. key: "showPreviewer",
  62. value: function showPreviewer(index) {
  63. this.setState({
  64. showPreviewer: true,
  65. previewerIndex: index
  66. });
  67. }
  68. }, {
  69. key: "hidePreviewer",
  70. value: function hidePreviewer() {
  71. this.setState({
  72. showPreviewer: false
  73. });
  74. }
  75. }, {
  76. key: "handleToggleInput",
  77. value: function handleToggleInput() {
  78. this.setState({ showInput: !this.state.showInput });
  79. }
  80. }, {
  81. key: "renderTextWithReply",
  82. value: function renderTextWithReply(text, content) {
  83. var newText = text;
  84. var reply = content.reply;
  85. if (reply) {
  86. // newText = `${newText} //@<a href="/${reply.user_id}">${
  87. // reply.user_name
  88. // }</a> ${reply.content}`;
  89. newText = newText + " //@" + reply.user_name + " " + reply.content;
  90. // newText = (
  91. // <span>
  92. // {newText}
  93. // @<a href={`/${reply.user_id}`}>{reply.user_name}</a>{reply.content}
  94. // </span>
  95. // )
  96. if (reply.reply) {
  97. return this.renderTextWithReply(newText, reply);
  98. }
  99. }
  100. return newText;
  101. }
  102. }, {
  103. key: "render",
  104. value: function render() {
  105. var _this2 = this;
  106. var _props = this.props,
  107. commentId = _props.commentId,
  108. replyId = _props.replyId,
  109. content = _props.content,
  110. action = _props.action,
  111. showReply = _props.showReply,
  112. onShowReply = _props.onShowReply,
  113. app = _props.app;
  114. // const { locale } = this.props.app;
  115. var showInput = this.state.showInput;
  116. var newContent = content.content;
  117. var images = "";
  118. if (newContent.indexOf(_constant.IMAGE_SPLIT) !== -1) {
  119. newContent = newContent.split(_constant.IMAGE_SPLIT);
  120. images = newContent.pop();
  121. newContent = newContent.join("");
  122. }
  123. var imageList = images.split(",");
  124. // 在3, 7前需要换行
  125. var needClear = imageList.length === 5 || imageList.length === 6 || imageList.length === 9;
  126. var imgs = [].concat(_toConsumableArray(imageList));
  127. if (needClear) {
  128. if (imgs.length > 6) {
  129. imgs.splice(3, 0, { type: "divider" });
  130. imgs.splice(7, 0, { type: "divider" });
  131. } else {
  132. imgs.splice(3, 0, { type: "divider" });
  133. }
  134. }
  135. return _react2.default.createElement(
  136. "div",
  137. { className: "comment-item-box" },
  138. _react2.default.createElement(
  139. "div",
  140. { className: "comment-item-left" },
  141. _react2.default.createElement(_avatar2.default, { src: content.user_avatar || _avatar4.default, size: "large" })
  142. ),
  143. _react2.default.createElement(
  144. "div",
  145. { className: "comment-item-right" },
  146. _react2.default.createElement(
  147. "div",
  148. null,
  149. _react2.default.createElement(
  150. "strong",
  151. { style: { color: "#75ACFF" } },
  152. content.user_name || "游客"
  153. ),
  154. _react2.default.createElement(
  155. "span",
  156. {
  157. className: "comment-item-icon",
  158. onClick: this.handleToggleInput
  159. },
  160. _react2.default.createElement(_icon2.default, { type: "message" }),
  161. "\xA0 ",
  162. content.reply_count
  163. ),
  164. _react2.default.createElement(
  165. "span",
  166. { className: "comment-item-icon" },
  167. _react2.default.createElement(_icon2.default, {
  168. type: "heart",
  169. onClick: function onClick() {
  170. if (replyId) {
  171. // 如果有 replyId,则说明是评论的回复
  172. app.sReplyFavor(content.id, commentId, content.favored);
  173. return;
  174. }
  175. app.sCommentFavor(content.id, content.favored);
  176. },
  177. className: content.favored ? "comment-favor comment-favored" : "comment-favor"
  178. }),
  179. "\xA0 ",
  180. content.favor_count
  181. )
  182. ),
  183. _react2.default.createElement(
  184. "div",
  185. { style: { color: "#D5D5D5" } },
  186. (0, _dayjs2.default)(content.created * 1000).format("MM-DD HH:mm:ss")
  187. )
  188. ),
  189. _react2.default.createElement(
  190. "div",
  191. { style: { overflow: "auto" } },
  192. _react2.default.createElement("div", {
  193. className: "comment-item-content",
  194. dangerouslySetInnerHTML: {
  195. __html: (0, _helper.renderContent)(this.renderTextWithReply(newContent, content))
  196. }
  197. }),
  198. // image为空时不渲染comment-item-image
  199. imageList.length > 0 && imageList[0] !== "" && _react2.default.createElement(
  200. "div",
  201. { className: "comment-item-image" },
  202. !this.state.showPreviewer && imgs.map(function (item, index) {
  203. if (item.type === "divider") {
  204. return _react2.default.createElement(
  205. "div",
  206. { className: "comment-item-image-wrapper", key: index },
  207. _react2.default.createElement("div", { className: "comment-img-divider" })
  208. );
  209. }
  210. return _react2.default.createElement(
  211. "div",
  212. {
  213. className: "comment-item-image-wrapper",
  214. key: index,
  215. onClick: function onClick() {
  216. var i = index;
  217. if (needClear) {
  218. if (index > 3) {
  219. i -= 1;
  220. }
  221. if (index > 7) {
  222. i -= 1;
  223. }
  224. }
  225. _this2.showPreviewer(i);
  226. }
  227. },
  228. _react2.default.createElement("div", {
  229. style: { backgroundImage: "url(" + item + ")" },
  230. className: "comment-img-thumbnail"
  231. })
  232. );
  233. }),
  234. this.state.showPreviewer && _react2.default.createElement(_ImagePreviewer2.default, {
  235. list: imageList,
  236. index: this.state.previewerIndex,
  237. onFold: this.hidePreviewer
  238. }),
  239. _react2.default.createElement("div", { className: "clearfix" })
  240. ),
  241. _react2.default.createElement(
  242. "div",
  243. { className: "comment-item-bottom" },
  244. content.reply_count ? _react2.default.createElement(
  245. "div",
  246. null,
  247. _react2.default.createElement(
  248. "a",
  249. { className: "comment-item-bottom-left", onClick: onShowReply },
  250. content.reply_count,
  251. " \u6761\u56DE\u590D",
  252. showReply ? _react2.default.createElement(_icon2.default, { type: "up" }) : _react2.default.createElement(_icon2.default, { type: "down" })
  253. )
  254. ) : null
  255. )
  256. ),
  257. showInput && _react2.default.createElement(_CommentInput2.default, {
  258. content: app.children,
  259. action: action,
  260. replyId: replyId,
  261. commentId: commentId,
  262. callback: this.handleToggleInput
  263. })
  264. );
  265. }
  266. }]);
  267. return CommentItem;
  268. }(_react.Component);
  269. CommentItem.propTypes = {
  270. content: _propTypes2.default.object.isRequired,
  271. // comment 评论
  272. // reply 评论的回复
  273. // replyToReply 回复的回复
  274. action: _propTypes2.default.oneOf(["comment", "reply", "replyToReply"]),
  275. onShowReply: _propTypes2.default.func
  276. };
  277. CommentItem.defaultProps = {
  278. action: "comment",
  279. onShowReply: function onShowReply() {}
  280. };
  281. exports.default = (0, _Comment2.default)(CommentItem);
  282. //# sourceMappingURL=index.js.map