1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
import _defineProperty from 'babel-runtime/helpers/defineProperty';
import PropTypes from '../../../_util/vue-types';
import BaseMixin from '../../../_util/BaseMixin';
import { hasProp } from '../../../_util/props-util';
import moment from 'moment';
import { isAllowedDate as _isAllowedDate, getTodayTime } from '../util/index';
function noop() {}
function getNow() {
return moment();
}
function getNowByCurrentStateValue(value) {
var ret = void 0;
if (value) {
ret = getTodayTime(value);
} else {
ret = getNow();
}
return ret;
}
function isMoment(value) {
if (Array.isArray(value)) {
return value.length === 0 || value.findIndex(function (val) {
return val === undefined || moment.isMoment(val);
}) !== -1;
} else {
return value === undefined || moment.isMoment(value);
}
}
var MomentType = PropTypes.custom(isMoment);
var CalendarMixin = {
mixins: [BaseMixin],
props: {
value: MomentType,
defaultValue: MomentType
},
data: function data() {
var props = this.$props;
var sValue = props.value || props.defaultValue || getNow();
return {
sValue: sValue,
sSelectedValue: props.selectedValue || props.defaultSelectedValue
};
},
watch: {
value: function value(val) {
var sValue = val || this.defaultValue || getNowByCurrentStateValue(this.sValue);
this.setState({
sValue: sValue
});
},
selectedValue: function selectedValue(val) {
this.setState({
sSelectedValue: val
});
}
},
methods: {
onSelect: function onSelect(value, cause) {
if (value) {
this.setValue(value);
}
this.setSelectedValue(value, cause);
},
renderRoot: function renderRoot(newProps) {
var _className;
var h = this.$createElement;
var props = this.$props;
var prefixCls = props.prefixCls;
var className = (_className = {}, _defineProperty(_className, prefixCls, 1), _defineProperty(_className, prefixCls + '-hidden', !props.visible), _defineProperty(_className, newProps['class'], !!newProps['class']), _className);
return h(
'div',
{ ref: 'rootInstance', 'class': className, attrs: { tabIndex: '0' },
on: {
'keydown': this.onKeyDown || noop
}
},
[newProps.children]
);
},
setSelectedValue: function setSelectedValue(selectedValue, cause) {
// if (this.isAllowedDate(selectedValue)) {
if (!hasProp(this, 'selectedValue')) {
this.setState({
sSelectedValue: selectedValue
});
}
this.__emit('select', selectedValue, cause);
// }
},
setValue: function setValue(value) {
var originalValue = this.sValue;
if (!hasProp(this, 'value')) {
this.setState({
sValue: value
});
}
if (originalValue && value && !originalValue.isSame(value) || !originalValue && value || originalValue && !value) {
this.__emit('change', value);
}
},
isAllowedDate: function isAllowedDate(value) {
var disabledDate = this.disabledDate;
var disabledTime = this.disabledTime;
return _isAllowedDate(value, disabledDate, disabledTime);
}
}
};
export default CalendarMixin;