yylib-quick-mobile
Version:
yylib-quick-mobile
195 lines (166 loc) • 5.87 kB
JavaScript
Object.defineProperty(exports, "__esModule", {
value: true
});
var _activityIndicator = require('antd-mobile/lib/activity-indicator');
var _activityIndicator2 = _interopRequireDefault(_activityIndicator);
var _menu = require('antd-mobile/lib/menu');
var _menu2 = _interopRequireDefault(_menu);
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-mobile/lib/activity-indicator/style/css');
require('antd-mobile/lib/menu/style/css');
var _react = require('react');
var _react2 = _interopRequireDefault(_react);
require('./YYMenu.less');
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 designData = [{
value: '1',
label: 'Food',
children: [{
label: 'All Foods',
value: '1',
disabled: false
}, {
label: 'Chinese Food',
value: '2'
}, {
label: 'Hot Pot',
value: '3'
}, {
label: 'Buffet',
value: '4'
}, {
label: 'Fast Food',
value: '5'
}, {
label: 'Snack',
value: '6'
}, {
label: 'Bread',
value: '7'
}, {
label: 'Fruit',
value: '8'
}, {
label: 'Noodle',
value: '9'
}, {
label: 'Leisure Food',
value: '10'
}]
}, {
value: '2',
label: 'Supermarket',
children: [{
label: 'All Supermarkets',
value: '1'
}, {
label: 'Supermarket',
value: '2',
disabled: true
}, {
label: 'C-Store',
value: '3'
}, {
label: 'Personal Care',
value: '4'
}]
}, {
value: '3',
label: 'Extra',
isLeaf: true,
children: [{
label: 'you can not see',
value: '1'
}]
}];
var YYMenu = function (_Component) {
_inherits(YYMenu, _Component);
function YYMenu(props) {
_classCallCheck(this, YYMenu);
var _this = _possibleConstructorReturn(this, (YYMenu.__proto__ || Object.getPrototypeOf(YYMenu)).call(this, props));
_this.onChange = function (value) {
var data = _this.props.data;
if (_this.props.RunInDesign) {
data = designData;
}
var label = '';
data.forEach(function (dataItem) {
if (dataItem.value === value[0]) {
label = dataItem.label;
if (dataItem.children && value[1]) {
dataItem.children.forEach(function (cItem) {
if (cItem.value === value[1]) {
label += ' ' + cItem.label;
}
});
}
}
});
if (_this.props.onChange) {
_this.props.onChange(value, label);
}
};
_this.onMaskClick = function () {
_this.props.onClose && _this.props.onClose();
};
_this.onOk = function (value) {
_this.props.onOk && _this.props.onOk(value);
};
_this.onCancel = function () {
_this.props.onCancel && _this.props.onCancel();
};
return _this;
}
_createClass(YYMenu, [{
key: 'render',
value: function render() {
var _props = this.props,
data = _props.data,
show = _props.show,
RunInDesign = _props.RunInDesign,
value = _props.value,
height = _props.height,
multiSelect = _props.multiSelect,
level = _props.level;
if (RunInDesign) {
if (window.ModelID && this.props.nid == window.ModelID) {
data = designData;
show = true;
}
}
var menuEl = _react2.default.createElement(_menu2.default, {
className: 'foo-menu',
data: data,
value: value,
level: level ? parseInt(level) : 2,
onChange: this.onChange,
onOk: this.onOk,
onCancel: this.onCancel,
height: height,
multiSelect: multiSelect });
var loadingEl = _react2.default.createElement(
'div',
{ style: { position: 'absolute', width: '100%', height: document.documentElement.clientHeight * 0.6, display: 'flex', justifyContent: 'center' } },
_react2.default.createElement(_activityIndicator2.default, { size: 'large' })
);
return _react2.default.createElement(
'div',
{ className: show ? 'menu-active' : '' },
show ? data ? menuEl : loadingEl : null,
show ? _react2.default.createElement('div', { className: 'menu-mask', onClick: this.onMaskClick }) : null
);
}
}]);
return YYMenu;
}(_react.Component);
YYMenu.defaultProps = {
data: [],
value: [],
height: document.documentElement.clientHeight * 0.6,
multiSelect: false
};
exports.default = YYMenu;
;