@wangxinowo/vue-datepicker-next 1.0.3 → 1.0.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,124 +1,130 @@
1
- import PropTypes from '../../../_util/vue-types';
2
- import BaseMixin from '../../../_util/BaseMixin';
3
- import { hasProp, getListeners } from '../../../_util/props-util';
4
- import MonthTable from './MonthTable';
5
-
6
- function goYear(direction) {
7
- this.changeYear(direction);
8
- }
9
-
10
- function noop() {}
11
-
12
- const MonthPanel = {
13
- name: 'MonthPanel',
14
- mixins: [BaseMixin],
15
- props: {
16
- value: PropTypes.any,
17
- defaultValue: PropTypes.any,
18
- // 支持单个值或数组(范围选择)
19
- selectedValue: PropTypes.oneOfType([PropTypes.any, PropTypes.array]),
20
- cellRender: PropTypes.any,
21
- contentRender: PropTypes.any,
22
- locale: PropTypes.any,
23
- rootPrefixCls: PropTypes.string,
24
- // onChange: PropTypes.func,
25
- disabledDate: PropTypes.func,
26
- // onSelect: PropTypes.func,
27
- renderFooter: PropTypes.func,
28
- changeYear: PropTypes.func.def(noop),
29
- },
30
-
31
- data() {
32
- const { value, defaultValue } = this;
33
- // bind methods
34
- this.nextYear = goYear.bind(this, 1);
35
- this.previousYear = goYear.bind(this, -1);
36
- return {
37
- sValue: value || defaultValue,
38
- };
39
- },
40
- watch: {
41
- value(val) {
42
- this.setState({
43
- sValue: val,
44
- });
45
- },
46
- },
47
- methods: {
48
- setAndSelectValue(value) {
49
- this.setValue(value);
50
- this.__emit('select', value);
51
- },
52
-
53
- setValue(value) {
54
- if (hasProp(this, 'value')) {
55
- this.setState({
56
- sValue: value,
57
- });
58
- }
59
- },
60
- },
61
-
62
- render() {
63
- const {
64
- sValue,
65
- cellRender,
66
- contentRender,
67
- locale,
68
- rootPrefixCls,
69
- disabledDate,
70
- renderFooter,
71
- selectedValue,
72
- } = this;
73
- const year = sValue.year();
74
- const prefixCls = `${rootPrefixCls}-month-panel`;
75
-
76
- const footer = renderFooter && renderFooter('month');
77
- return (
78
- <div class={prefixCls}>
79
- <div>
80
- <div class={`${prefixCls}-header`}>
81
- <a
82
- class={`${prefixCls}-prev-year-btn`}
83
- role="button"
84
- onClick={this.previousYear}
85
- title={locale.previousYear}
86
- />
87
-
88
- <a
89
- class={`${prefixCls}-year-select`}
90
- role="button"
91
- onClick={getListeners(this).yearPanelShow || noop}
92
- title={locale.yearSelect}
93
- >
94
- <span class={`${prefixCls}-year-select-content`}>{year}</span>
95
- <span class={`${prefixCls}-year-select-arrow`}>x</span>
96
- </a>
97
-
98
- <a
99
- class={`${prefixCls}-next-year-btn`}
100
- role="button"
101
- onClick={this.nextYear}
102
- title={locale.nextYear}
103
- />
104
- </div>
105
- <div class={`${prefixCls}-body`}>
106
- <MonthTable
107
- disabledDate={disabledDate}
108
- onSelect={this.setAndSelectValue}
109
- locale={locale}
110
- value={sValue}
111
- selectedValue={selectedValue}
112
- cellRender={cellRender}
113
- contentRender={contentRender}
114
- prefixCls={prefixCls}
115
- />
116
- </div>
117
- {footer && <div class={`${prefixCls}-footer`}>{footer}</div>}
118
- </div>
119
- </div>
120
- );
121
- },
122
- };
123
-
124
- export default MonthPanel;
1
+ import PropTypes from '../../../_util/vue-types';
2
+ import BaseMixin from '../../../_util/BaseMixin';
3
+ import { hasProp, getListeners } from '../../../_util/props-util';
4
+ import MonthTable from './MonthTable';
5
+
6
+ function goYear(direction) {
7
+ this.changeYear(direction);
8
+ }
9
+
10
+ function noop() {}
11
+
12
+ const MonthPanel = {
13
+ name: 'MonthPanel',
14
+ mixins: [BaseMixin],
15
+ props: {
16
+ value: PropTypes.any,
17
+ defaultValue: PropTypes.any,
18
+ // 支持单个值或数组(范围选择)
19
+ selectedValue: PropTypes.oneOfType([PropTypes.any, PropTypes.array]),
20
+ // hover 值,用于范围选择时的预览效果
21
+ hoverValue: PropTypes.array.def([]),
22
+ cellRender: PropTypes.any,
23
+ contentRender: PropTypes.any,
24
+ locale: PropTypes.any,
25
+ rootPrefixCls: PropTypes.string,
26
+ // onChange: PropTypes.func,
27
+ disabledDate: PropTypes.func,
28
+ // onSelect: PropTypes.func,
29
+ renderFooter: PropTypes.func,
30
+ changeYear: PropTypes.func.def(noop),
31
+ },
32
+
33
+ data() {
34
+ const { value, defaultValue } = this;
35
+ // bind methods
36
+ this.nextYear = goYear.bind(this, 1);
37
+ this.previousYear = goYear.bind(this, -1);
38
+ return {
39
+ sValue: value || defaultValue,
40
+ };
41
+ },
42
+ watch: {
43
+ value(val) {
44
+ this.setState({
45
+ sValue: val,
46
+ });
47
+ },
48
+ },
49
+ methods: {
50
+ setAndSelectValue(value) {
51
+ this.setValue(value);
52
+ this.__emit('select', value);
53
+ },
54
+
55
+ setValue(value) {
56
+ if (hasProp(this, 'value')) {
57
+ this.setState({
58
+ sValue: value,
59
+ });
60
+ }
61
+ },
62
+ },
63
+
64
+ render() {
65
+ const {
66
+ sValue,
67
+ cellRender,
68
+ contentRender,
69
+ locale,
70
+ rootPrefixCls,
71
+ disabledDate,
72
+ renderFooter,
73
+ selectedValue,
74
+ hoverValue,
75
+ } = this;
76
+ const year = sValue.year();
77
+ const prefixCls = `${rootPrefixCls}-month-panel`;
78
+ const monthHover = getListeners(this).monthHover || noop;
79
+
80
+ const footer = renderFooter && renderFooter('month');
81
+ return (
82
+ <div class={prefixCls}>
83
+ <div>
84
+ <div class={`${prefixCls}-header`}>
85
+ <a
86
+ class={`${prefixCls}-prev-year-btn`}
87
+ role="button"
88
+ onClick={this.previousYear}
89
+ title={locale.previousYear}
90
+ />
91
+
92
+ <a
93
+ class={`${prefixCls}-year-select`}
94
+ role="button"
95
+ onClick={getListeners(this).yearPanelShow || noop}
96
+ title={locale.yearSelect}
97
+ >
98
+ <span class={`${prefixCls}-year-select-content`}>{year}</span>
99
+ <span class={`${prefixCls}-year-select-arrow`}>x</span>
100
+ </a>
101
+
102
+ <a
103
+ class={`${prefixCls}-next-year-btn`}
104
+ role="button"
105
+ onClick={this.nextYear}
106
+ title={locale.nextYear}
107
+ />
108
+ </div>
109
+ <div class={`${prefixCls}-body`}>
110
+ <MonthTable
111
+ disabledDate={disabledDate}
112
+ onSelect={this.setAndSelectValue}
113
+ onMonthHover={monthHover}
114
+ locale={locale}
115
+ value={sValue}
116
+ selectedValue={selectedValue}
117
+ hoverValue={hoverValue}
118
+ cellRender={cellRender}
119
+ contentRender={contentRender}
120
+ prefixCls={prefixCls}
121
+ />
122
+ </div>
123
+ {footer && <div class={`${prefixCls}-footer`}>{footer}</div>}
124
+ </div>
125
+ </div>
126
+ );
127
+ },
128
+ };
129
+
130
+ export default MonthPanel;