joywok-material-components
Version:
<h1 align="center"> Joywok Material Components </h1>
314 lines (297 loc) • 15.8 kB
JavaScript
;
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 _dva = require('dva');
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 Emoji = function (_React$Component) {
_inherits(Emoji, _React$Component);
function Emoji(props) {
_classCallCheck(this, Emoji);
var _this = _possibleConstructorReturn(this, (Emoji.__proto__ || Object.getPrototypeOf(Emoji)).call(this, props));
_this.state = {
path: '/dist/images/emoji',
jw_emojy: {
'1f603': '[' + i18n('label.emoji-smile') + ']',
'1f604': '[' + i18n('label.emoji-laugh') + ']',
'1f609': '[' + i18n('label.emoji-wink') + ']',
'1f601': '[' + i18n('label.emoji-hee') + ']',
'1f602': '[' + i18n('label.emoji-laugh-cry') + ']',
'1f612': '[' + i18n('label.emoji-no-happy') + ']',
'1f613': '[' + i18n('label.emoji-sweat') + ']',
'1f614': '[' + i18n('label.emoji-disappointment') + ']',
'1f618': '[' + i18n('label.emoji-kisses') + ']',
'1f620': '[' + i18n('label.emoji-angry') + ']',
'1f621': '[' + i18n('label.emoji-very-angry') + ']',
'1f622': '[' + i18n('label.emoji-desperate') + ']',
'1f623': '[' + i18n('label.emoji-unlucky') + ']',
'1f625': '[' + i18n('label.emoji-sad') + ']',
'1f628': '[' + i18n('label.emoji-sick') + ']',
'1f631': '[' + i18n('label.emoji-shock') + ']',
'1f632': '[' + i18n('label.emoji-avert-look') + ']',
'1f633': '[' + i18n('label.emoji-orto') + ']',
'1f637': '[' + i18n('label.emoji-shut-up') + ']',
'1f60a': '[' + i18n('label.emoji-shy') + ']',
'1f60c': '[' + i18n('label.emoji-pround') + ']',
'1f60d': '[' + i18n('label.emoji-sexy') + ']',
'1f60f': '[' + i18n('label.emoji-lip') + ']',
'1f61a': '[' + i18n('label.emoji-kiss') + ']',
'1f61c': '[' + i18n('label.emoji-make-face') + ']',
'1f61d': '[' + i18n('label.emoji-tongue') + ']',
'1f62a': '[' + i18n('label.emoji-sleep') + ']',
'1f62d': '[' + i18n('label.emoji-tears') + ']',
'1f491': '[' + i18n('label.emoji-love') + ']',
'1f494': '[' + i18n('label.emoji-broken-heart') + ']',
'1f497': '[' + i18n('label.emoji-heart') + ']',
'1f511': '[' + i18n('label.emoji-key') + ']',
'1f512': '[' + i18n('label.emoji-locks') + ']',
'1f513': '[' + i18n('label.emoji-unlock') + ']',
'1f514': '[' + i18n('label.emoji-bell') + ']',
'1f525': '[' + i18n('label.emoji-fire') + ']',
'1f528': '[' + i18n('label.emoji-hammer') + ']',
'1f64f': '[' + i18n('label.emoji-worship') + ']',
'1f68c': '[' + i18n('label.emoji-bus') + ']',
'1f69a': '[' + i18n('label.emoji-truck') + ']',
'1f194': '[' + i18n('label.emoji-account') + ']',
'1f302': '[' + i18n('label.emoji-umbrella') + ']',
'1f303': '[' + i18n('label.emoji-late-night') + ']',
'1f304': '[' + i18n('label.emoji-sunrise') + ']',
'1f305': '[' + i18n('label.emoji-sunset') + ']',
'1f306': '[' + i18n('label.emoji-morning') + ']',
'1f307': '[' + i18n('label.emoji-evening') + ']',
'1f308': '[' + i18n('label.emoji-rainbow') + ']',
'1f319': '[' + i18n('label.emoji-moon') + ']',
'1f334': '[' + i18n('label.emoji-tree') + ']',
'1f335': '[' + i18n('label.emoji-cactus') + ']',
'1f337': '[' + i18n('label.emoji-tulips') + ']',
'1f338': '[' + i18n('label.emoji-mahogany') + ']',
'1f339': '[' + i18n('label.emoji-rose') + ']',
'1f340': '[' + i18n('label.emoji-clover') + ']',
'1f341': '[' + i18n('label.emoji-maple-leaf') + ']',
'1f342': '[' + i18n('label.emoji-leaf') + ']',
'1f343': '[' + i18n('label.emoji-fallen-leafs') + ']',
'1f345': '[' + i18n('label.emoji-tomato') + ']',
'1f346': '[' + i18n('label.emoji-eggplant') + ']',
'1f349': '[' + i18n('label.emoji-watermelon') + ']',
'1f353': '[' + i18n('label.emoji-strawberry') + ']',
'1f354': '[' + i18n('label.emoji-hamburger') + ']',
'1f359': '[' + i18n('label.emoji-wototou') + ']',
'1f363': '[' + i18n('label.emoji-sushi') + ']',
'1f366': '[' + i18n('label.emoji-torch') + ']',
'1f367': '[' + i18n('label.emoji-ice-cream') + ']',
'1f370': '[' + i18n('label.emoji-cake') + ']',
'1f372': '[' + i18n('label.emoji-hot-drinks') + ']',
'1f373': '[' + i18n('label.emoji-fried-egg') + ']',
'1f374': '[' + i18n('label.emoji-knife-fork') + ']',
'1f375': '[' + i18n('label.emoji-tea') + ']',
'1f376': '[' + i18n('label.emoji-alcohol') + ']',
'1f378': '[' + i18n('label.emoji-drinks') + ']',
'1f380': '[' + i18n('label.emoji-bows') + ']',
'1f381': '[' + i18n('label.emoji-gift') + ']',
'1f382': '[' + i18n('label.emoji-birthday') + ']',
'1f383': '[' + i18n('label.emoji-halloween') + ']',
'1f384': '[' + i18n('label.emoji-christmas') + ']',
'1f385': '[' + i18n('label.emoji-santa') + ']',
'1f386': '[' + i18n('label.emoji-fireworks') + ']',
'1f387': '[' + i18n('label.emoji-stars') + ']',
'1f388': '[' + i18n('label.emoji-balloon') + ']',
'1f389': '[' + i18n('label.emoji-coloured-ribbon') + ']',
'1f485': '[' + i18n('label.emoji-nail-polish') + ']',
'1f486': '[' + i18n('label.emoji-massage') + ']',
'1f487': '[' + i18n('label.emoji-haircut') + ']',
'1f64b': '[' + i18n('label.emoji-hand-up') + ']',
'1f498': '[' + i18n('label.emoji-cupit') + ']',
'1f645': '[' + i18n('label.emoji-noway') + ']',
'1f646': '[' + i18n('label.emoji-surrender') + ']',
'1f647': '[' + i18n('label.emoji-thingking') + ']',
'1f680': '[' + i18n('label.emoji-rocket') + ']',
'1f683': '[' + i18n('label.emoji-subway') + ']',
'1f684': '[' + i18n('label.emoji-high-speed') + ']',
'1f691': '[' + i18n('label.emoji-ambulance') + ']',
'1f692': '[' + i18n('label.emoji-fire-engine') + ']',
'1f693': '[' + i18n('label.emoji-police-car') + ']',
'1f695': '[' + i18n('label.emoji-taxi') + ']',
'1f697': '[' + i18n('label.emoji-car') + ']',
'1f699': '[' + i18n('label.emoji-truck') + ']',
'1f3a4': '[' + i18n('label.emoji-microphone') + ']',
'1f3a5': '[' + i18n('label.emoji-camera') + ']',
'1f3a6': '[' + i18n('label.emoji-watch-movie') + ']',
'1f3a7': '[' + i18n('label.emoji-songs') + ']',
'1f3a8': '[' + i18n('label.emoji-painting') + ']',
'1f3a9': '[' + i18n('label.emoji-hat') + ']',
'1f3ab': '[' + i18n('label.emoji-certificate') + ']',
'1f3ac': '[' + i18n('label.emoji-make-movie') + ']',
'1f3af': '[' + i18n('label.emoji-shooting') + ']',
'1f3b1': '[' + i18n('label.emoji-billiards') + ']',
'1f3be': '[' + i18n('label.emoji-tennis') + ']',
'1f3bf': '[' + i18n('label.emoji-skiing') + ']',
'1f3c0': '[' + i18n('label.emoji-basketball') + ']',
'1f3c1': '[' + i18n('label.emoji-racing') + ']',
'1f3c3': '[' + i18n('label.emoji-running') + ']',
'1f3c4': '[' + i18n('label.emoji-surfing') + ']',
'1f3c6': '[' + i18n('label.emoji-trophy') + ']',
'1f3c8': '[' + i18n('label.emoji-rugby') + ']',
'1f3ca': '[' + i18n('label.emoji-swimming') + ']',
'1f004': '[' + i18n('label.emoji-mahjong') + ']',
'1f4a1': '[' + i18n('label.emoji-electric-light') + ']',
'1f4a2': '[' + i18n('label.emoji-hit') + ']',
'1f4a3': '[' + i18n('label.emoji-bomb') + ']',
'1f4a4': '[' + i18n('label.emoji-asleep') + ']',
'1f4a6': '[' + i18n('label.emoji-sneeze') + ']',
'1f4a8': '[' + i18n('label.emoji-slid') + ']',
'1f4a9': '[' + i18n('label.emoji-shit') + ']',
'1f4aa': '[' + i18n('label.emoji-exercise') + ']',
'1f4b0': '[' + i18n('label.emoji-money') + ']',
'1f4bb': '[' + i18n('label.emoji-computer') + ']',
'1f4dd': '[' + i18n('label.emoji-writing') + ']',
'1f4e2': '[' + i18n('label.emoji-radio-broadcast') + ']',
'1f4e9': '[' + i18n('label.emoji-receive-mail') + ']',
'1f4f1': '[' + i18n('label.emoji-mobile') + ']',
'1f4f2': '[' + i18n('label.emoji-answer-phone') + ']',
'1f4f6': '[' + i18n('label.emoji-signal') + ']',
'1f4f7': '[' + i18n('label.emoji-d-camera') + ']',
'1f4fa': '[' + i18n('label.emoji-tv') + ']',
'1f6ac': '[' + i18n('label.emoji-smoke') + ']',
'1f44a': '[' + i18n('label.emoji-fist') + ']',
'1f44b': '[' + i18n('label.emoji-wave') + ']',
'1f44c': '[' + i18n('label.emoji-ok') + ']',
'1f44d': '[' + i18n('label.emoji-agreen') + ']',
'1f44e': '[' + i18n('label.emoji-despise') + ']',
'1f44f': '[' + i18n('label.emoji-applause') + ']',
'1f446': '[' + i18n('label.emoji-upward') + ']',
'1f447': '[' + i18n('label.emoji-downward') + ']',
'1f448': '[' + i18n('label.emoji-aleft') + ']',
'1f449': '[' + i18n('label.emoji-rightward') + ']',
'1f48b': '[' + i18n('label.emoji-hickeys') + ']',
'1f48d': '[' + i18n('label.emoji-ring') + ']',
'1f37b': '[' + i18n('label.emoji-beer') + ']',
'1f31f': '[' + i18n('label.emoji-starlinght') + ']'
},
open: !!props.open,
el: props.el
};
return _this;
}
_createClass(Emoji, [{
key: 'componentDidMount',
value: function componentDidMount() {
var self = this;
}
}, {
key: 'replaceEmoj',
value: function replaceEmoj(str) {
var self = this;
var str2 = str.replace(/\[(.*?)\]/g, function (e1) {
var has = false;
for (var i in self.state.jw_emojy) {
if (self.state.jw_emojy[i] == e1) {
has = true;
var c = (Array(20).join(0) + parseInt(eval('0x' + i + '-0x10000')).toString(2)).slice(-20);
var c1 = c.slice(0, 10);
var c2 = c.slice(10, 20);
var l = (parseInt(c1, 2) + 0xd800).toString(16);
var t = (parseInt(c2, 2) + 0xDC00).toString(16);
var code = '\\' + 'u' + l + '\\' + 'u' + t;
return window.eval('"' + code + '"');
}
}
if (has == false) {
return e1;
}
});
console.log(str2, str);
return str2 == window.undefined ? str : str2;
}
}, {
key: 'open',
value: function open(el) {
var self = this;
var obj = {};
obj.open = true;
if (el) {
obj.el = el;
}
self.setState(obj);
}
}, {
key: 'close',
value: function close() {
var self = this;
self.setState({
open: false
});
self.props.onClose && self.props.onClose();
}
}, {
key: 'emo1',
value: function emo1(item, index) {
var self = this;
var imgPath = self.state.path + '/' + index + '.png';
var i = _react2.default.createElement(
'i',
{ onClick: self.onClick.bind(self, index), title: item, rel: item },
_react2.default.createElement('img', { src: imgPath, alt: 'emoji' })
);
return i;
}
}, {
key: 'onClick',
value: function onClick(text) {
var self = this;
var obj = {
text: self.state.jw_emojy[text],
key: text
};
self.props.onChange && self.props.onChange(obj, this.props.index);
self.setState({
open: false
});
}
}, {
key: 'render',
value: function render() {
var self = this;
var offset = void 0;
if (self.state.el && self.state.el.offset()) {
offset = self.state.el.offset();
if (offset && offset.top > 200) {
offset.top = offset.top - 150;
}
if (offset && offset.left > 440) {
offset.left = offset.left - 440;
}
var height = $('body').height();
if (offset.top + 342 > height) {
offset.top = height - 352;
}
}
console.log(self.state.el, self.state.open);
return _react2.default.createElement(
'div',
{ className: self.state.open ? "emoji" : "emoji hide" },
_react2.default.createElement(
'div',
{ className: 'emoji-bg', onClick: self.close.bind(self) },
'\xA0'
),
_react2.default.createElement(
'div',
{ className: 'emoji-c', style: offset },
_.map(self.state.jw_emojy, function (item, index) {
return self.emo1(item, index);
})
)
);
}
}]);
return Emoji;
}(_react2.default.Component);
exports.default = Emoji;