react-form-ui-y
Version:
262 lines (199 loc) • 8.68 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 _propTypes = require("prop-types");
var _propTypes2 = _interopRequireDefault(_propTypes);
var _reactUtilsY = require("react-utils-y");
var _reactRedux = require("react-redux");
var _themeY = require("theme-y");
var _index = require("../../actions/index");
var _selectStyle = require("./selectStyle");
var _subpage = require("./subpage");
var _publicField = require("../publicField");
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; }
// import {Theme} from '../../../theme/index';
var propTypes = {
designationTheme: _propTypes2.default.string,
formType: _propTypes2.default.string,
inputName: _propTypes2.default.string.isRequired,
formText: _propTypes2.default.string,
disabled: _propTypes2.default.bool,
required: _propTypes2.default.bool,
hintText: _propTypes2.default.string,
textWidth: _propTypes2.default.string,
valueWidth: _propTypes2.default.string,
changeValue: _propTypes2.default.func,
errorText: _propTypes2.default.string,
dataType: _propTypes2.default.string,
// remarks 无规则 自定义传参
// regex:PropTypes.number,//正则 input特有
regexText: _propTypes2.default.string //input特有
};
var SelectCheckboxField = function (_Theme) {
_inherits(SelectCheckboxField, _Theme);
function SelectCheckboxField(props) {
_classCallCheck(this, SelectCheckboxField);
var _this = _possibleConstructorReturn(this, (SelectCheckboxField.__proto__ || Object.getPrototypeOf(SelectCheckboxField)).call(this, props));
_initialiseProps.call(_this);
var _state = {
focusState: false, //处理点击的样式
initFocusState: 0, //是否触发过 0 未触发 1 已经触发
errorState: false, //是否显示报错提示框, true 显示报错 false 不显示
showSelect: false, //是否显示下拉值
moveSelect: "",
shouldUpdateChoose: true, //选择展示区滚动条
shouldUpdateList: true //列表滚动条true
};
_this.state = _reactUtilsY._Object.merge(_this.state || {}, _state);
return _this;
}
//列表滚动条
//选择展示区滚动条
//显示下拉选项
//关闭下拉选项
//移动select
//移除select
//选中下拉值
//删除选中的值
_createClass(SelectCheckboxField, [{
key: "componentWillMount",
value: function componentWillMount() {
var props = this.props;
var flag = "set";
try {
//已经存在数据 就不 重新赋值
flag = props.formData[props.dataType || "default"][props.inputName] ? "none" : "set";
} catch (ex) {
flag = "set";
} finally {
if (props.inputName && flag == "set") {
var obj = [{
type: "selectCheckbox", //type 类型
name: this.props.inputName, //name input名称
text: [], //text input值
value: [],
obj: [],
remarks: this.props.remarks, //备注
other: {
required: this.props.required
}
}];
props.setFormData(obj, props.dataType);
}
}
}
}, {
key: "componentDidMount",
value: function componentDidMount() {}
}, {
key: "componentWillUnmount",
value: function componentWillUnmount() {
this.props.delFormData(this.props.inputName || "", this.props.dataType);
}
}, {
key: "render",
value: function render() {
return (0, _publicField.renderBox)(this, _selectStyle.selectSty, _subpage.formTypeDom, _subpage.verifyFn);
}
}]);
return SelectCheckboxField;
}(_themeY.Theme);
var _initialiseProps = function _initialiseProps() {
var _this2 = this;
this.initScrollList = function () {
_this2.setState({ shouldUpdateList: false });
};
this.initScrollChoose = function () {
_this2.setState({ shouldUpdateChoose: false });
};
this.showSelectFn = function (e) {
_this2.setState({
showSelect: true,
focusState: true,
shouldUpdateChoose: true,
shouldUpdateList: true
});
(0, _publicField.setLocationFn)(_this2, e);
};
this.closeSelect = function () {
_this2.setState({
showSelect: false,
focusState: false,
initFocusState: 1
});
};
this.moveSelect = function (item) {
_this2.setState({
moveSelect: item.text
});
};
this.leaveSelect = function () {
_this2.setState({
moveSelect: ""
});
};
this.handleSelect = function (item) {
var props = _this2.props;
if (props.disabled || !props.inputName) return false;
_this2.setState({
//showSelect: false,
focusState: false,
shouldUpdateChoose: true
});
var selectCheckbox = props.formData.default[props.inputName];
var texts = selectCheckbox.text || [],
values = selectCheckbox.value || [],
objs = selectCheckbox.obj || [];
var index = values.indexOf(item.value);
if (index >= 0) {
texts.splice(index, 1);
values.splice(index, 1);
objs.splice(index, 1);
} else {
texts.push(item.text);
values.push(item.value);
objs.push(item);
}
var obj = [{
type: "selectCheckbox", //type 类型
name: props.inputName, //name input名称
text: texts, //text input值
value: values,
obj: objs,
remarks: props.remarks, //备注
other: {
required: props.required
}
}];
props.setFormData(obj, props.dataType);
props.changeValue && props.changeValue(obj[0]);
};
this.delChooseItem = function (item) {};
};
SelectCheckboxField.propTypes = propTypes;
var mapStateToProps = function mapStateToProps(state) {
return {
formData: state.formData,
subVerifyRes: state.subVerifyRes,
theme: state.theme
};
};
var mapDispatchToProps = function mapDispatchToProps(dispatch) {
return {
setFormData: function setFormData(data, dataType) {
return dispatch((0, _index.setFormData)(data, dataType));
},
delFormData: function delFormData(inputName, dataType) {
return dispatch((0, _index.delFormData)(inputName, dataType));
}
};
};
exports.default = (0, _reactRedux.connect)(mapStateToProps, mapDispatchToProps)(SelectCheckboxField);
//# sourceMappingURL=selectCheckboxField.js.map