123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201 |
- "use strict";
-
- Object.defineProperty(exports, "__esModule", {
- value: true
- });
-
- var _icon = require("antd/es/icon");
-
- var _icon2 = _interopRequireDefault(_icon);
-
- var _avatar = require("antd/es/avatar");
-
- var _avatar2 = _interopRequireDefault(_avatar);
-
- 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; }; }();
-
- require("antd/es/icon/style/css");
-
- require("antd/es/avatar/style/css");
-
- var _react = require("react");
-
- var _react2 = _interopRequireDefault(_react);
-
- var _propTypes = require("prop-types");
-
- var _propTypes2 = _interopRequireDefault(_propTypes);
-
- var _dayjs = require("dayjs");
-
- var _dayjs2 = _interopRequireDefault(_dayjs);
-
- var _Comment = require("../../Comment");
-
- var _Comment2 = _interopRequireDefault(_Comment);
-
- var _CommentInput = require("../CommentInput");
-
- var _CommentInput2 = _interopRequireDefault(_CommentInput);
-
- var _helper = require("../../helper");
-
- require("./index.css");
-
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
-
- function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
-
- 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; }
-
- 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; }
-
- var CommentItem = function (_Component) {
- _inherits(CommentItem, _Component);
-
- function CommentItem(props) {
- _classCallCheck(this, CommentItem);
-
- var _this = _possibleConstructorReturn(this, (CommentItem.__proto__ || Object.getPrototypeOf(CommentItem)).call(this, props));
-
- _this.state = {
- isShowInput: false
- };
- _this.handleToggleInput = _this.handleToggleInput.bind(_this);
- _this.renderTextWithReply = _this.renderTextWithReply.bind(_this);
- return _this;
- }
-
- _createClass(CommentItem, [{
- key: "handleToggleInput",
- value: function handleToggleInput() {
- this.setState({ isShowInput: !this.state.isShowInput });
- }
- }, {
- key: "renderTextWithReply",
- value: function renderTextWithReply(text, content) {
- var newText = text;
- var reply = content.reply;
-
- if (reply) {
- newText = newText + " //@<a href=\"/" + reply.user_id + "\">" + reply.user_name + "</a> " + reply.content;
- if (reply.reply) {
- return this.renderTextWithReply(newText, reply);
- }
- }
- return newText;
- }
- }, {
- key: "render",
- value: function render() {
- var _props = this.props,
- commentId = _props.commentId,
- replyId = _props.replyId,
- content = _props.content,
- type = _props.type,
- showReply = _props.showReply,
- onShowReply = _props.onShowReply,
- app = _props.app;
- var isShowInput = this.state.isShowInput;
-
- var isComment = type === "comment";
- return _react2.default.createElement(
- "div",
- { className: "box" },
- _react2.default.createElement(
- "div",
- { className: "left" },
- _react2.default.createElement(_avatar2.default, { src: content.user_avatar, size: "large" })
- ),
- _react2.default.createElement(
- "div",
- { className: "right" },
- _react2.default.createElement(
- "div",
- { className: "name" },
- _react2.default.createElement(
- "a",
- { href: "/" + content.user_id },
- content.user_name || "暂无昵称"
- ),
- _react2.default.createElement(
- "span",
- { style: { marginLeft: 10 } },
- (0, _dayjs2.default)(content.created * 1000).format("YYYY-MM-DD HH:mm:ss")
- )
- ),
- _react2.default.createElement("div", {
- className: "content",
- dangerouslySetInnerHTML: {
- __html: (0, _helper.renderContent)(this.renderTextWithReply(content.content, content))
- }
- }),
- _react2.default.createElement(
- "div",
- { className: "bottom" },
- isComment && content.reply_count ? _react2.default.createElement(
- "div",
- null,
- _react2.default.createElement(
- "a",
- {
- className: "itemLeft",
- onClick: onShowReply,
- style: { userSelect: "none" }
- },
- content.reply_count,
- " \u6761\u56DE\u590D",
- showReply ? _react2.default.createElement(_icon2.default, { type: "up" }) : _react2.default.createElement(_icon2.default, { type: "down" })
- )
- ) : null,
- _react2.default.createElement(
- "a",
- { onClick: this.handleToggleInput, className: "itemRight" },
- "\xA0 \u56DE\u590D"
- ),
- _react2.default.createElement(
- "div",
- {
- className: "itemRight",
- style: { cursor: "pointer" },
- onClick: function onClick() {
- return app.sCommentFavor(content.id, content.favored);
- }
- },
- _react2.default.createElement(_icon2.default, {
- type: "like-o",
- className: content.favored ? "favored" : ""
- }),
- "\xA0",
- content.favor_count
- )
- ),
- isShowInput ? _react2.default.createElement(_CommentInput2.default, {
- type: type,
- replyId: replyId,
- commentId: commentId,
- handleToggleInput: this.handleToggleInput
- }) : null
- )
- );
- }
- }]);
-
- return CommentItem;
- }(_react.Component);
-
- CommentItem.propTypes = {
- content: _propTypes2.default.object.isRequired,
- // comment 评论
- // reply 回复
- type: _propTypes2.default.oneOf(["comment", "reply"]),
- onShowReply: _propTypes2.default.func
- };
-
- CommentItem.defaultProps = {
- type: "comment",
- onShowReply: function onShowReply() {}
- };
-
- exports.default = (0, _Comment2.default)(CommentItem);
- //# sourceMappingURL=index.js.map
|