"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);
require("dayjs/locale/zh-cn");
var _relativeTime = require("dayjs/plugin/relativeTime");
var _relativeTime2 = _interopRequireDefault(_relativeTime);
var _Comment = require("../../Comment");
var _Comment2 = _interopRequireDefault(_Comment);
var _CommentInput = require("../CommentInput");
var _CommentInput2 = _interopRequireDefault(_CommentInput);
var _avatar3 = require("../../avatar");
var _avatar4 = _interopRequireDefault(_avatar3);
var _helper = require("../../helper");
var _constant = require("../../constant");
require("./index.css");
var _ImagePreviewer = require("../ImagePreviewer/ImagePreviewer");
var _ImagePreviewer2 = _interopRequireDefault(_ImagePreviewer);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
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); } }
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; }
// import 'dayjs/locale/es';
// import intl from "react-intl-universal";
_dayjs2.default.locale("zh-cn");
_dayjs2.default.extend(_relativeTime2.default);
// const LOCALES = {
// "zh-CN": "zh-cn"
// };
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 = {
showInput: false,
showPreviewer: false,
previewerIndex: 0
};
_this.handleToggleInput = _this.handleToggleInput.bind(_this);
_this.renderTextWithReply = _this.renderTextWithReply.bind(_this);
_this.showPreviewer = _this.showPreviewer.bind(_this);
_this.hidePreviewer = _this.hidePreviewer.bind(_this);
return _this;
}
_createClass(CommentItem, [{
key: "showPreviewer",
value: function showPreviewer(index) {
this.setState({
showPreviewer: true,
previewerIndex: index
});
}
}, {
key: "hidePreviewer",
value: function hidePreviewer() {
this.setState({
showPreviewer: false
});
}
}, {
key: "handleToggleInput",
value: function handleToggleInput() {
this.setState({ showInput: !this.state.showInput });
}
}, {
key: "renderTextWithReply",
value: function renderTextWithReply(text, content) {
var newText = text;
var reply = content.reply;
if (reply) {
// newText = `${newText} //@${
// reply.user_name
// } ${reply.content}`;
newText = newText + " //@" + reply.user_name + " " + reply.content;
// newText = (
//
// {newText}
// @{reply.user_name}{reply.content}
//
// )
if (reply.reply) {
return this.renderTextWithReply(newText, reply);
}
}
return newText;
}
}, {
key: "render",
value: function render() {
var _this2 = this;
var _props = this.props,
commentId = _props.commentId,
replyId = _props.replyId,
content = _props.content,
action = _props.action,
showReply = _props.showReply,
onShowReply = _props.onShowReply,
app = _props.app;
// const { locale } = this.props.app;
var showInput = this.state.showInput;
var newContent = content.content;
var images = "";
if (newContent.indexOf(_constant.IMAGE_SPLIT) !== -1) {
newContent = newContent.split(_constant.IMAGE_SPLIT);
images = newContent.pop();
newContent = newContent.join("");
}
var imageList = images.split(",");
// 在3, 7前需要换行
var needClear = imageList.length === 5 || imageList.length === 6 || imageList.length === 9;
var imgs = [].concat(_toConsumableArray(imageList));
if (needClear) {
if (imgs.length > 6) {
imgs.splice(3, 0, { type: "divider" });
imgs.splice(7, 0, { type: "divider" });
} else {
imgs.splice(3, 0, { type: "divider" });
}
}
return _react2.default.createElement(
"div",
{ className: "comment-item-box" },
_react2.default.createElement(
"div",
{ className: "comment-item-left" },
_react2.default.createElement(_avatar2.default, { src: content.user_avatar || _avatar4.default, size: "large" })
),
_react2.default.createElement(
"div",
{ className: "comment-item-right" },
_react2.default.createElement(
"div",
null,
_react2.default.createElement(
"strong",
{ style: { color: "#75ACFF" } },
content.user_name || "游客"
),
_react2.default.createElement(
"span",
{
className: "comment-item-icon",
onClick: this.handleToggleInput
},
_react2.default.createElement(_icon2.default, { type: "message" }),
"\xA0 ",
content.reply_count
),
_react2.default.createElement(
"span",
{ className: "comment-item-icon" },
_react2.default.createElement(_icon2.default, {
type: "heart",
onClick: function onClick() {
if (replyId) {
// 如果有 replyId,则说明是评论的回复
app.sReplyFavor(content.id, commentId, content.favored);
return;
}
app.sCommentFavor(content.id, content.favored);
},
className: content.favored ? "comment-favor comment-favored" : "comment-favor"
}),
"\xA0 ",
content.favor_count
)
),
_react2.default.createElement(
"div",
{ style: { color: "#D5D5D5" } },
(0, _dayjs2.default)(content.created * 1000).format("MM-DD HH:mm:ss")
)
),
_react2.default.createElement(
"div",
{ style: { overflow: "auto" } },
_react2.default.createElement("div", {
className: "comment-item-content",
dangerouslySetInnerHTML: {
__html: (0, _helper.renderContent)(this.renderTextWithReply(newContent, content))
}
}),
// image为空时不渲染comment-item-image
imageList.length > 0 && imageList[0] !== "" && _react2.default.createElement(
"div",
{ className: "comment-item-image" },
!this.state.showPreviewer && imgs.map(function (item, index) {
if (item.type === "divider") {
return _react2.default.createElement(
"div",
{ className: "comment-item-image-wrapper", key: index },
_react2.default.createElement("div", { className: "comment-img-divider" })
);
}
return _react2.default.createElement(
"div",
{
className: "comment-item-image-wrapper",
key: index,
onClick: function onClick() {
var i = index;
if (needClear) {
if (index > 3) {
i -= 1;
}
if (index > 7) {
i -= 1;
}
}
_this2.showPreviewer(i);
}
},
_react2.default.createElement("div", {
style: { backgroundImage: "url(" + item + ")" },
className: "comment-img-thumbnail"
})
);
}),
this.state.showPreviewer && _react2.default.createElement(_ImagePreviewer2.default, {
list: imageList,
index: this.state.previewerIndex,
onFold: this.hidePreviewer
}),
_react2.default.createElement("div", { className: "clearfix" })
),
_react2.default.createElement(
"div",
{ className: "comment-item-bottom" },
content.reply_count ? _react2.default.createElement(
"div",
null,
_react2.default.createElement(
"a",
{ className: "comment-item-bottom-left", onClick: onShowReply },
content.reply_count,
" \u6761\u56DE\u590D",
showReply ? _react2.default.createElement(_icon2.default, { type: "up" }) : _react2.default.createElement(_icon2.default, { type: "down" })
)
) : null
)
),
showInput && _react2.default.createElement(_CommentInput2.default, {
content: app.children,
action: action,
replyId: replyId,
commentId: commentId,
callback: this.handleToggleInput
})
);
}
}]);
return CommentItem;
}(_react.Component);
CommentItem.propTypes = {
content: _propTypes2.default.object.isRequired,
// comment 评论
// reply 评论的回复
// replyToReply 回复的回复
action: _propTypes2.default.oneOf(["comment", "reply", "replyToReply"]),
onShowReply: _propTypes2.default.func
};
CommentItem.defaultProps = {
action: "comment",
onShowReply: function onShowReply() {}
};
exports.default = (0, _Comment2.default)(CommentItem);
//# sourceMappingURL=index.js.map