This commit is contained in:
Jay 2017-04-14 18:20:30 +08:00
parent 12ff3a4020
commit eb6b8d9ad5
2 changed files with 156 additions and 8 deletions

View File

@ -94097,6 +94097,8 @@ Object.defineProperty(exports, "__esModule", {
value: true
});
var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };
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 = __webpack_require__(0);
@ -94130,16 +94132,88 @@ var UnitTime = function (_React$Component) {
}
return _ret = (_temp = (_this = _possibleConstructorReturn(this, (_ref = UnitTime.__proto__ || Object.getPrototypeOf(UnitTime)).call.apply(_ref, [this].concat(args))), _this), _this.state = {
list: []
list: [],
data: {
op: '',
id: 'dt0,mode0',
year: '-',
week: '-',
month: '-',
day: '-',
hour: '-',
min: '-'
}
}, _this.changeState = function (key, value) {
var data = _extends({}, _this.state.data);
if (key == 'op') {
data.op = value;
}
if (key == 'year') {
data.year = value == '' ? '-' : value;
}
if (key == 'week') {
data.week = value == '' ? '-' : value;
}
if (key == 'month') {
data.month = value == '' ? '-' : value;
}
if (key == 'day') {
data.day = value == '' ? '-' : value;
}
if (key == 'hour') {
data.hour = value == '' ? '-' : value;
}
if (key == 'min') {
data.min = value == '' ? '-' : value;
}
_this.setState({
data: _extends({}, data)
}, function () {
_this.sendUpdate();
});
}, _this.sendUpdate = function () {
var data = _extends({}, _this.state.data);
data.value = data.min + '|' + data.hour + '|' + data.day + '|' + data.month + '|' + data.week + '|' + data.year;
delete data.year;
delete data.week;
delete data.month;
delete data.day;
delete data.hour;
delete data.min;
_this.props.updateData(_extends({}, _this.props.data, data));
}, _temp), _possibleConstructorReturn(_this, _ret);
}
_createClass(UnitTime, [{
key: 'componentDidMount',
value: function componentDidMount() {}
key: 'componentWillReceiveProps',
value: function componentWillReceiveProps(np) {
var data = _extends({}, this.state.data);
if (np.data.op != data.op) data.op = np.data.op;
var year = np.data.split('|')[5] || '-';
var week = np.data.split('|')[4] || '-';
var month = np.data.split('|')[3] || '-';
var day = np.data.split('|')[2] || '-';
var hour = np.data.split('|')[1] || '-';
var min = np.data.split('|')[0] || '-';
if (year != data.year) data.year = year;
if (week != data.week) data.week = week;
if (month != data.month) data.month = month;
if (day != data.day) data.day = day;
if (hour != data.hour) data.hour = hour;
if (min != data.min) data.min = min;
this.setState({
data: _extends({}, data)
});
}
}, {
key: 'render',
value: function render() {
var _this2 = this;
var ops = this.props.ops;
return _react2.default.createElement(
@ -94147,7 +94221,9 @@ var UnitTime = function (_React$Component) {
null,
_react2.default.createElement(
'select',
null,
{ value: this.state.data.op, onChange: function onChange(e) {
_this2.changeState('op', e.target.value);
} },
_react2.default.createElement(
'option',
{ value: '' },

View File

@ -4,18 +4,90 @@ import {getRequest} from '../../../../../actions';
class UnitTime extends React.Component {
state = {
list: []
list: [],
data: {
op: '',
id: 'dt0,mode0',
year: '-',
week: '-',
month: '-',
day: '-',
hour: '-',
min: '-'
}
}
componentDidMount(){
componentWillReceiveProps(np) {
let data = {...this.state.data};
if(np.data.op != data.op) data.op = np.data.op;
let year = np.data.split('|')[5] || '-';
let week = np.data.split('|')[4] || '-';
let month = np.data.split('|')[3] || '-';
let day = np.data.split('|')[2] || '-';
let hour = np.data.split('|')[1] || '-';
let min = np.data.split('|')[0] || '-';
if(year != data.year) data.year = year;
if(week != data.week) data.week = week;
if(month != data.month) data.month = month;
if(day != data.day) data.day = day;
if(hour != data.hour) data.hour = hour;
if(min != data.min) data.min = min;
this.setState({
data: {...data}
})
}
changeState = (key, value) => {
let data = {
...this.state.data
}
if(key == 'op'){
data.op = value;
}
if(key == 'year') {
data.year = value == '' ? '-' : value;
}
if(key == 'week') {
data.week = value == '' ? '-' : value;
}
if(key == 'month') {
data.month = value == '' ? '-' : value;
}
if(key == 'day') {
data.day = value == '' ? '-' : value;
}
if(key == 'hour') {
data.hour = value == '' ? '-' : value;
}
if(key == 'min') {
data.min = value == '' ? '-' : value;
}
this.setState({
data: {...data}
}, ()=>{ this.sendUpdate() });
}
sendUpdate = () => {
let data = {...this.state.data};
data.value = `${data.min}|${data.hour}|${data.day}|${data.month}|${data.week}|${data.year}`;
delete data.year;
delete data.week;
delete data.month;
delete data.day;
delete data.hour;
delete data.min;
this.props.updateData({...this.props.data, ...data});
}
render() {
let {ops} = this.props;
return (
<div>
<select>
<select value={this.state.data.op} onChange={e=>{this.changeState('op', e.target.value)}}>
<option value="">選擇條件</option>
{
ops.map((t,idx) => {