UNPKG

rax-tbms-chat-plugin

Version:

tbms-chat-plugin with rax

286 lines (247 loc) 11.1 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.default = void 0; var _raxTbmsChatBase = require("rax-tbms-chat-base"); var _raxView = _interopRequireDefault(require("rax-view")); var _raxText = _interopRequireDefault(require("rax-text")); var _raxImage = _interopRequireDefault(require("rax-image")); var _raxScrollview = _interopRequireDefault(require("rax-scrollview")); var _map = require("./map"); var _cloneDeep = _interopRequireDefault(require("lodash/cloneDeep")); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); } function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a 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); } } function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; } function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); } function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); } function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; } function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); } function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); } function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; } var MY_FREE_STYLE = { containerHeight: _raxTbmsChatBase.systemStyles.pluginContainerHeight, footContainerHeight: 80, BodyContainerHeight: _raxTbmsChatBase.systemStyles.pluginContainerHeight - 80, containerTitleHeight: 30, containerTitleMarginTop: 20, containerTitlePaddingLeft: 40, containerBodyPadding: 10, containerBodyPaddingRight: 30, emojiImageRectangle: 60, emojiImagePadding: 4, emojiImageMargin: 28, pluginIconRectangle: 40, pluginBorderColor: '#E7E7E7', buttonWidth: 140 }; var EMOJI_MAP = { ww: _map.ww }; var EMOJI_LIST = { ww: { active: false, defaultUrl: 'https://img.alicdn.com/tfs/TB1oW1mwYPpK1RjSZFFXXa5PpXa-200-200.png', activeUrl: 'https://gw.alicdn.com/tfs/TB1o6mtwVzqK1RjSZFCXXbbxVXa-200-200.png' } // xm: { // active: false, // defaultUrl: 'https://gw.alicdn.com/tfs/TB1019rwVzqK1RjSZSgXXcpAVXa-200-200.png', // activeUrl: 'https://gw.alicdn.com/tfs/TB1nQ1nw6TpK1RjSZKPXXa3UpXa-200-200.png', // } /** * @class * @name EmojiPlugin * Emoji表情插件 * @property {Object} props * @property {String} props.type - ww, xm, ww_en * */ }; var _default = /*#__PURE__*/ function (_BaseComponent) { _inherits(_default, _BaseComponent); function _default(props) { var _this; _classCallCheck(this, _default); _this = _possibleConstructorReturn(this, _getPrototypeOf(_default).call(this, props)); // 初始化选中状态 _defineProperty(_assertThisInitialized(_this), "state", { EMOJI_MAP: EMOJI_LIST, type: 'ww' }); _defineProperty(_assertThisInitialized(_this), "styles", { container: { height: _raxTbmsChatBase.systemStyles.pluginContainerHeight, width: 750, backgroundColor: _raxTbmsChatBase.systemStyles.containerFooterBackgroundColor, borderTopWidth: 1, borderColor: '#DDD' }, containerTlt: { height: MY_FREE_STYLE.containerTitleHeight, lineHeight: MY_FREE_STYLE.containerTitleHeight, marginTop: MY_FREE_STYLE.containerTitleMarginTop, paddingLeft: MY_FREE_STYLE.containerTitlePaddingLeft, fontSize: _raxTbmsChatBase.customStyles.font.subFontSize, color: _raxTbmsChatBase.customStyles.font.subFontColor }, containerScroll: { width: 750, height: MY_FREE_STYLE.BodyContainerHeight }, containerBody: { paddingRight: MY_FREE_STYLE.containerBodyPaddingRight, paddingLeft: MY_FREE_STYLE.containerBodyPadding, paddingBottom: MY_FREE_STYLE.containerBodyPadding, flexDirection: 'row', flexWrap: 'wrap' }, EmojiImageItem: { height: MY_FREE_STYLE.emojiImageRectangle, width: MY_FREE_STYLE.emojiImageRectangle, paddingLeft: MY_FREE_STYLE.emojiImagePadding, paddingRight: MY_FREE_STYLE.emojiImagePadding, paddingBottom: MY_FREE_STYLE.emojiImagePadding, paddingTop: MY_FREE_STYLE.emojiImagePadding, marginLeft: MY_FREE_STYLE.emojiImageMargin, marginTop: MY_FREE_STYLE.emojiImageMargin }, pluginItem: { height: MY_FREE_STYLE.pluginIconRectangle, width: MY_FREE_STYLE.footContainerHeight, justifyContent: 'center', alignItems: 'center', borderLeftWidth: 1, borderLeftColor: MY_FREE_STYLE.pluginBorderColor }, pluginItemIcon: { height: MY_FREE_STYLE.pluginIconRectangle, width: MY_FREE_STYLE.pluginIconRectangle }, containerFoot: { width: 750, height: MY_FREE_STYLE.footContainerHeight, flexDirection: 'row', alignItems: 'center', justifyContent: 'space-between', backgroundColor: '#FFF' }, containerFootLeft: { flexDirection: 'row', height: MY_FREE_STYLE.footContainerHeight, alignItems: 'center', marginLeft: -2 }, containerFootRight: { backgroundImage: _raxTbmsChatBase.customStyles.color.linearGradientColor }, sendBtn: { height: MY_FREE_STYLE.footContainerHeight, lineHeight: MY_FREE_STYLE.footContainerHeight, width: MY_FREE_STYLE.buttonWidth, textAlign: 'center', fontSize: _raxTbmsChatBase.customStyles.font.titleFontColor, color: _raxTbmsChatBase.systemStyles.mainButtonFontColor } }); _defineProperty(_assertThisInitialized(_this), "handleActivedToMap", function (value) { var keyList = Object.keys(_this.state.EMOJI_MAP); var emojiMap = (0, _cloneDeep.default)(_this.state.EMOJI_MAP); var list = keyList.map(function (key) { if (value === key) { emojiMap[key].active = true; } else { emojiMap[key].active = false; } }); return emojiMap; }); _defineProperty(_assertThisInitialized(_this), "handlePluginItemClick", function (value) { _this.setState({ EMOJI_MAP: _this.handleActivedToMap(value), type: value }); }); _defineProperty(_assertThisInitialized(_this), "handleEmojiItemClick", function (word) { _this.props.onChange && _this.props.onChange(word.alias, _this.state.type); }); _defineProperty(_assertThisInitialized(_this), "handleSend", function () { _this.props.onSend && _this.props.onSend(); }); _this.state.type = props.type || 'ww'; _this.state.EMOJI_MAP = _this.handleActivedToMap(_this.state.type); return _this; } _createClass(_default, [{ key: "renderBody", value: function renderBody() { var _this2 = this; var list = EMOJI_MAP[this.state.type]; var styles = this.styles; var prefix = this.state.type; var ImageList = list.map(function (word) { return (0, _raxTbmsChatBase.createElement)(_raxImage.default, { source: { uri: word.src }, style: styles.EmojiImageItem, resizeMode: "cover", onClick: _this2.handleEmojiItemClick.bind(_this2, word) }); }); return (0, _raxTbmsChatBase.createElement)(_raxView.default, { style: styles.containerBody }, ImageList); } }, { key: "renderFoot", value: function renderFoot() { var _this3 = this; var styles = this.styles; var keyList = Object.keys(this.state.EMOJI_MAP); var EMOJI_LIST = this.state.EMOJI_MAP; return (0, _raxTbmsChatBase.createElement)(_raxView.default, { style: styles.containerFoot }, (0, _raxTbmsChatBase.createElement)(_raxView.default, { style: styles.containerFootLeft }, keyList.map(function (key) { var item = EMOJI_LIST[key]; return (0, _raxTbmsChatBase.createElement)(_raxView.default, { style: styles.pluginItem }, (0, _raxTbmsChatBase.createElement)(_raxImage.default, { source: { uri: item.active ? item.activeUrl : item.defaultUrl }, style: styles.pluginItemIcon, resizeMode: "cover", onClick: _this3.handlePluginItemClick.bind(_this3, key) })); })), (0, _raxTbmsChatBase.createElement)(_raxView.default, { style: styles.containerFootRight, onClick: this.handleSend }, (0, _raxTbmsChatBase.createElement)(_raxText.default, { style: styles.sendBtn }, "\u53D1\u9001"))); } }, { key: "render", value: function render() { var styles = this.styles; return (0, _raxTbmsChatBase.createElement)(_raxView.default, { style: styles.container }, (0, _raxTbmsChatBase.createElement)(_raxScrollview.default, { style: styles.containerScroll }, (0, _raxTbmsChatBase.createElement)(_raxText.default, { style: styles.containerTlt }, "\u5168\u90E8\u8868\u60C5"), this.renderBody()), this.renderFoot()); } }]); return _default; }(_raxTbmsChatBase.BaseComponent); exports.default = _default; _defineProperty(_default, "defaultProps", { onChange: function onChange() {}, onSend: function onSend() {} });