@beisen/ethos
Version:
beisencloud pc react components
235 lines (188 loc) • 7.84 kB
JavaScript
'use strict';
var _defineProperty2 = require('babel-runtime/helpers/defineProperty');
var _defineProperty3 = _interopRequireDefault(_defineProperty2);
var _extends3 = require('babel-runtime/helpers/extends');
var _extends4 = _interopRequireDefault(_extends3);
var _getPrototypeOf = require('babel-runtime/core-js/object/get-prototype-of');
var _getPrototypeOf2 = _interopRequireDefault(_getPrototypeOf);
var _classCallCheck2 = require('babel-runtime/helpers/classCallCheck');
var _classCallCheck3 = _interopRequireDefault(_classCallCheck2);
var _createClass2 = require('babel-runtime/helpers/createClass');
var _createClass3 = _interopRequireDefault(_createClass2);
var _possibleConstructorReturn2 = require('babel-runtime/helpers/possibleConstructorReturn');
var _possibleConstructorReturn3 = _interopRequireDefault(_possibleConstructorReturn2);
var _inherits2 = require('babel-runtime/helpers/inherits');
var _inherits3 = _interopRequireDefault(_inherits2);
var _class, _temp;
var _react = require('react');
var _react2 = _interopRequireDefault(_react);
var _reactDom = require('react-dom');
require('./index.scss');
var _commonMount = require('../common-mount');
var _commonMount2 = _interopRequireDefault(_commonMount);
var _edit = require('./edit');
var _edit2 = _interopRequireDefault(_edit);
var _search = require('./search');
var _search2 = _interopRequireDefault(_search);
var _contains = require('./contains');
var _contains2 = _interopRequireDefault(_contains);
var _uid = require('./uid');
var _uid2 = _interopRequireDefault(_uid);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function empty() {}
var defaultTranslation = {
showAllText: '全部查找',
emptyBgText: '这里什么都没有...',
notAllowedText: '额...您没有访问权限~',
notInstalledText: '租户未安装应用!'
};
var LookUpV2 = (_temp = _class = function (_Component) {
(0, _inherits3.default)(LookUpV2, _Component);
function LookUpV2(props) {
(0, _classCallCheck3.default)(this, LookUpV2);
var _this = (0, _possibleConstructorReturn3.default)(this, (LookUpV2.__proto__ || (0, _getPrototypeOf2.default)(LookUpV2)).call(this, props));
_this.setComState = function (key, value) {
_this.setState({ isShowDoropList: value });
};
_this.handlerMouseDown = function (event) {
if (_this.props.readOnly) return;
if (!_this.isClickValid(event)) {
_this.isCloseWithoutChooseItem = true;
_this.setState({ isShowDoropList: false });
_this.commonMount.unmountBox();
_this.props.onEditMouseDown(event);
}
};
_this.isClickValid = function (event) {
var mountContainer = document.getElementById('BS_lookupV2_container__' + _this.state.uid);
var lookupContaienr = (0, _reactDom.findDOMNode)(_this.refs.edit.refs.input);
if (mountContainer && !(0, _contains2.default)(mountContainer, event.target) && lookupContaienr && !(0, _contains2.default)(lookupContaienr, event.target)) {
return false;
}
return true;
};
_this.setListHeight = function () {
var height = 0,
listHeight = 0;
if (Array.isArray(_this.props.listValue) && _this.props.listValue.length) {
if (_this.props.listValue[0][1]) {
listHeight = 46;
} else {
if (_this.props.listValue[0][0] && _this.props.listValue[0][0]['avatars']) {
listHeight = 40;
} else {
listHeight = 32;
}
}
// let _length = this.props.listValue.length > 8 ? 8 : this.props.listValue.length;
// height = this.props.listValue.length * listHeight;
// height = height > 300 ? 300 : height
height = 340;
if (!_this.props.isShowFindAll) {
height = height - 32;
}
// 高度计算
} else {
// no-data
height = 340;
}
if (_this.props.isFetching) {
height = 360;
}
return {
itemHeight: listHeight,
listHeight: height
};
};
_this.handlerFindAll = function (event) {
_this.commonMount.unmountBox();
_this.props.onFindAll();
};
_this.clearDom = function () {
var doms = document.getElementsByClassName('BS_lookupV2_wrapper_common');
var parDoms = void 0;
for (var i = 0; i < doms.length; i++) {
if (doms[i]) {
parDoms = doms[i].parentNode;
parDoms.removeChild(doms[i]);
}
}
};
_this.onBlurChange = function (event) {
if (_this.props.onBlur) {
_this.props.onBlur(event, _this.isCloseWithoutChooseItem);
}
_this.isCloseWithoutChooseItem = false;
};
_this.setClassName = function (id) {
var dom = document.getElementById(id);
dom.className = 'BS_lookupV2_wrapper_common';
};
_this.state = {
uid: (0, _uid2.default)(),
isShowDoropList: false
};
_this.translation = (0, _extends4.default)({}, defaultTranslation, props.translation);
_this.isCloseWithoutChooseItem = false;
if (!Array.isArray) {
Array.isArray = function (arg) {
return Object.prototype.toString.call(arg) === '[object Array]';
};
}
return _this;
}
(0, _createClass3.default)(LookUpV2, [{
key: 'componentDidUpdate',
value: function componentDidUpdate(prevProps, prevState) {
var props = (0, _extends4.default)({}, this.props);
if (props.disabled || props.readOnly) {
this.commonMount.unmountBox();
}
}
}, {
key: 'componentWillMount',
value: function componentWillMount() {
this.commonMount = new _commonMount2.default({
containerId: 'BS_lookupV2_wrapper__' + this.state.uid,
follow: true, // 是否滚动跟随,默认true
fixed: true // 定位:fixed,false时为absolute
});
this.setClassName('BS_lookupV2_wrapper__' + this.state.uid);
}
}, {
key: 'componentDidMount',
value: function componentDidMount() {
if (this.props.status == 'edit') {
document.removeEventListener('mousedown', this.handlerMouseDown);
document.addEventListener('mousedown', this.handlerMouseDown);
}
}
}, {
key: 'componentWillUnmount',
value: function componentWillUnmount() {
if (this.props.status == 'edit') {
document.removeEventListener('mousedown', this.handlerMouseDown);
//由于弹窗关闭后会卸载组件导致其它的组件卸载而找不到id进行渲染
this.commonMount.unmountBox();
}
}
}, {
key: 'render',
value: function render() {
var props = this.props;
if (props.status == 'edit') {
var _extends2;
return _react2.default.createElement(_edit2.default, (0, _extends4.default)({}, props, (_extends2 = { setListHeight: this.setListHeight, translation: this.translation, uid: this.state.uid, isShowDoropList: this.state.isShowDoropList, setComState: this.setComState, onBlur: this.onBlurChange, commonMount: this.commonMount, handlerFindAll: this.handlerFindAll }, (0, _defineProperty3.default)(_extends2, 'translation', this.translation), (0, _defineProperty3.default)(_extends2, 'ref', 'edit'), _extends2)));
} else {
return _react2.default.createElement(_search2.default, (0, _extends4.default)({}, props, { setListHeight: this.setListHeight, isShowDoropList: this.state.isShowDoropList, setComState: this.setComState, commonMount: this.commonMount, handlerFindAll: this.handlerFindAll, ref: 'search', translation: this.translation }));
}
}
}]);
return LookUpV2;
}(_react.Component), _class.defaultProps = {
status: 'edit',
isShowFindAll: true,
onFindAll: empty,
onEditMouseDown: empty
}, _temp);
module.exports = LookUpV2;