123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202 |
- "use strict";
-
- Object.defineProperty(exports, "__esModule", {
- value: true
- });
-
- 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; }; }();
-
- var _react = require("react");
-
- var _react2 = _interopRequireDefault(_react);
-
- var _propTypes = require("prop-types");
-
- var _propTypes2 = _interopRequireDefault(_propTypes);
-
- var _constant = require("../../constant");
-
- var _Comment = require("../../Comment");
-
- var _Comment2 = _interopRequireDefault(_Comment);
-
- var _Editor = require("../Editor");
-
- var _Editor2 = _interopRequireDefault(_Editor);
-
- 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 PLACEHOLDER = {
- normal: "说点什么吧...",
- default: "说点什么吧..."
- };
-
- var CommentInput = function (_Component) {
- _inherits(CommentInput, _Component);
-
- function CommentInput(props) {
- _classCallCheck(this, CommentInput);
-
- var _this = _possibleConstructorReturn(this, (CommentInput.__proto__ || Object.getPrototypeOf(CommentInput)).call(this, props));
-
- _this.state = {
- value: "",
-
- fileList: [], // 图片列表
- fileMap: {} // 已经上传的图片路径和 uid 的映射 { uid: path }
- };
- _this.handleChange = _this.handleChange.bind(_this);
- _this.handleSubmit = _this.handleSubmit.bind(_this);
- _this.handleChangeFileList = _this.handleChangeFileList.bind(_this);
- _this.handleChangeEmoji = _this.handleChangeEmoji.bind(_this);
- _this.handleUpload = _this.handleUpload.bind(_this);
- return _this;
- }
-
- _createClass(CommentInput, [{
- key: "handleChange",
- value: function handleChange(e) {
- this.setState({ value: e.target.value });
- }
- }, {
- key: "handleChangeFileList",
- value: function handleChangeFileList(fileList) {
- this.setState({ fileList: fileList });
- }
- }, {
- key: "handleChangeEmoji",
- value: function handleChangeEmoji(emojiId) {
- var value = this.state.value;
-
- value += "[" + emojiId + "]";
- this.setState({ value: value });
- }
- }, {
- key: "handleUpload",
- value: function handleUpload(_ref) {
- var uid = _ref.uid,
- path = _ref.path;
- var fileMap = this.state.fileMap;
-
- fileMap[uid] = path;
- this.setState({ fileMap: fileMap });
- }
- }, {
- key: "handleSubmit",
- value: function handleSubmit() {
- var _state = this.state,
- value = _state.value,
- fileMap = _state.fileMap,
- fileList = _state.fileList;
-
- if (fileList.length) {
- fileList.forEach(function (item) {
- value += "[" + _constant.OSS_LINK + fileMap[item.uid] + "]";
- });
- }
-
- var _props = this.props,
- type = _props.type,
- commentId = _props.commentId,
- replyId = _props.replyId,
- handleToggleInput = _props.handleToggleInput;
-
- if (type === "normal") {
- this.props.app.sCreateComment({
- type: 1,
- business_id: "1",
- content: value
- });
- } else if (type === "comment") {
- this.props.app.sCreateReply({
- comment_id: commentId,
- content: value
- }, function () {
- return handleToggleInput();
- });
- } else if (type === "reply") {
- this.props.app.sCreateReply({
- comment_id: commentId,
- content: value,
- reply_id: replyId
- }, function () {
- return handleToggleInput();
- });
- }
- }
- }, {
- key: "render",
- value: function render() {
- var type = this.props.type;
- var _state2 = this.state,
- value = _state2.value,
- fileList = _state2.fileList;
-
-
- return _react2.default.createElement(
- "div",
- null,
- type === "normal" ? _react2.default.createElement(
- "div",
- null,
- _react2.default.createElement(
- "span",
- {
- style: {
- border: "1px solid #CECECE",
- color: "#666",
- padding: "2px 3px"
- }
- },
- "\u56DE\u590D"
- ),
- _react2.default.createElement(
- "span",
- { style: { marginLeft: "20px", color: "#5198EB" } },
- "\u53E3\u7891",
- _react2.default.createElement(
- "span",
- { style: { marginLeft: "20px", color: "#666666" } },
- "(\u5168\u7AD9\u6311\u51FA\u6BDB\u75C5\u6216\u63D0\u51FA\u5408\u7406\u5EFA\u8BAE\uFF0C\u5956\u52B110\u5230100\u5143\u7EA2\u5305)"
- )
- )
- ) : null,
- _react2.default.createElement(
- "div",
- { style: { marginTop: 40 } },
- _react2.default.createElement(_Editor2.default, {
- value: value,
- placeholder: PLACEHOLDER[type] || PLACEHOLDER.default,
- fileList: fileList,
- onChange: this.handleChange,
- onSubmit: this.handleSubmit,
- onChangeFileList: this.handleChangeFileList,
- onChangeEmoji: this.handleChangeEmoji,
- onUpload: this.handleUpload,
- loading: this.props.app.loading.sCreateComment
- })
- )
- );
- }
- }]);
-
- return CommentInput;
- }(_react.Component);
-
- CommentInput.propTypes = {
- // normal 有切换回复/口碑的 header ; comment 评论输入框 / reply 回复输入框
- type: _propTypes2.default.oneOf(["normal", "comment", "reply"])
- };
-
- CommentInput.defaultProps = {
- type: "normal"
- };
-
- exports.default = (0, _Comment2.default)(CommentInput);
- //# sourceMappingURL=index.js.map
|