@94ai/nf-double-year 3.1.37 → 3.1.39

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.
@@ -0,0 +1 @@
1
+ import '@94ai/nf-theme-chalk/lib/css/nf-double-year.css'
@@ -0,0 +1 @@
1
+ import '@94ai/nf-theme-chalk/lib/nf-double-year.scss'
@@ -0,0 +1,234 @@
1
+ <template>
2
+ <transition name="el-zoom-in-top" @after-leave="$emit('dodestroy')">
3
+ <div
4
+ v-show="visible"
5
+ class="el-picker-panel el-date-range-picker el-popper nf-double-year-year-range"
6
+ :class="[{
7
+ 'has-sidebar': $slots.sidebar || shortcuts
8
+ }, popperClass]">
9
+ <div class="el-picker-panel__body-wrapper">
10
+ <slot name="sidebar" class="el-picker-panel__sidebar"></slot>
11
+ <div class="el-picker-panel__sidebar" v-if="shortcuts">
12
+ <button
13
+ type="button"
14
+ class="el-picker-panel__shortcut"
15
+ v-for="(shortcut,index) in shortcuts"
16
+ @click="handleShortcutClick(shortcut)"
17
+ :key="index">
18
+ {{shortcut.text}}
19
+ </button>
20
+ </div>
21
+ <div class="el-picker-panel__body">
22
+ <div class="el-picker-panel__content el-date-range-picker__content is-left">
23
+ <div class="el-date-range-picker__header">
24
+ <button type="button" @click="prevYear(true)" class="el-picker-panel__icon-btn el-icon-d-arrow-left"></button>
25
+ <button
26
+ type="button"
27
+ v-if="unlinkPanels"
28
+ @click="nextYear(true)"
29
+ :disabled="!enableYearArrow"
30
+ :class="{ 'is-disabled': !enableYearArrow }"
31
+ class="el-picker-panel__icon-btn el-icon-d-arrow-right"></button>
32
+ <div>{{ leftYear }} {{t('el.datepicker.year')}}</div>
33
+ </div>
34
+ <year-table
35
+ :date="date"
36
+ :min-date="minDate"
37
+ :max-date="maxDate"
38
+ :year="leftYear"
39
+ selection-mode="range"
40
+ :rangeState="rangeState"
41
+ :disabled-date="disabledDate"
42
+ @changerange="handleChangeRange"
43
+ @pick="handleRangePick">
44
+ </year-table>
45
+ </div>
46
+ <div class="el-picker-panel__content el-date-range-picker__content is-right">
47
+ <div class="el-date-range-picker__header">
48
+ <button
49
+ type="button"
50
+ v-if="unlinkPanels"
51
+ @click="prevYear(false)"
52
+ :disabled="!enableYearArrow"
53
+ :class="{ 'is-disabled': !enableYearArrow }"
54
+ class="el-picker-panel__icon-btn el-icon-d-arrow-left"></button>
55
+ <button type="button" @click="nextYear(false)" class="el-picker-panel__icon-btn el-icon-d-arrow-right"></button>
56
+ <div>{{ rightYear }} {{t('el.datepicker.year')}}</div>
57
+ </div>
58
+ <year-table
59
+ :min-date="minDate"
60
+ :max-date="maxDate"
61
+ :date="rightDate"
62
+ :year="rightYear"
63
+ selection-mode="range"
64
+ :rangeState="rangeState"
65
+ :disabled-date="disabledDate"
66
+ @changerange="handleChangeRange"
67
+ @pick="handleRangePick">
68
+ </year-table>
69
+ </div>
70
+ </div>
71
+ </div>
72
+ </div>
73
+ </transition>
74
+ </template>
75
+
76
+ <script type="text/babel">
77
+ import Clickoutside from 'element-ui/src/utils/clickoutside';
78
+ import Locale from 'element-ui/src/mixins/locale';
79
+ import {
80
+ toDate,
81
+ modifyWithTimeString
82
+ } from 'element-ui/src/utils/date-util';
83
+ import yearTable from './year-table.vue';
84
+
85
+ const calcDefaultValue = (defaultValue) => {
86
+ var date;
87
+ if (Array.isArray(defaultValue)) {
88
+ return [new Date(defaultValue[0]), new Date(defaultValue[1])];
89
+ } else if (defaultValue) {
90
+ date = new Date(defaultValue);
91
+ return [new Date(date), new Date(date.setFullYear(date.getFullYear() + 12))];
92
+ } else {
93
+ date = new Date();
94
+ return [new Date(), new Date(date.setFullYear(date.getFullYear() + 12))];
95
+ }
96
+ };
97
+
98
+ export default {
99
+ mixins: [Locale],
100
+ directives: { Clickoutside },
101
+ computed: {
102
+ btnDisabled() {
103
+ return !(this.minDate && this.maxDate && !this.selecting);
104
+ },
105
+ leftYear() {
106
+ return Math.floor(this.date.getFullYear() / 12) * 12;
107
+ },
108
+ rightYear() {
109
+ return Math.floor(this.rightDate.getFullYear() / 12) * 12;
110
+ },
111
+ enableYearArrow() {
112
+ return this.rightYear - 12 > this.leftYear;
113
+ }
114
+ },
115
+ data() {
116
+ return {
117
+ defaultTime: null,
118
+ popperClass: '',
119
+ defaultValue: null,
120
+ date: calcDefaultValue(this.defaultValue)[0],
121
+ rightDate: calcDefaultValue(this.defaultValue)[1],
122
+ minDate: '',
123
+ maxDate: '',
124
+ rangeState: {
125
+ endDate: null,
126
+ selecting: false
127
+ },
128
+ showTime: false,
129
+ shortcuts: '',
130
+ value: '',
131
+ visible: '',
132
+ disabledDate: '',
133
+ firstDayOfWeek: 7,
134
+ format: '',
135
+ toolTipTop: 0,
136
+ toolTipLeft: 0,
137
+ unlinkPanels: false,
138
+ arrowControl: false
139
+ };
140
+ },
141
+ watch: {
142
+ value: {
143
+ handler(newVal) {
144
+ if (!newVal) {
145
+ this.minDate = null;
146
+ this.maxDate = null;
147
+ } else if (Array.isArray(newVal)) {
148
+ this.minDate = newVal[0] ? toDate(newVal[0])?.getFullYear() : null;
149
+ this.maxDate = newVal[1] ? toDate(newVal[1])?.getFullYear() : null;
150
+ this.date = new Date(this.minDate, 0, 1);
151
+ this.rangeState.endDate = null;
152
+ }
153
+ },
154
+ immediate: true
155
+ },
156
+ date(val) {
157
+ const date = new Date(val);
158
+ if (!this.unlinkPanels || date.getFullYear() + 12 > this.rightDate.getFullYear()) {
159
+ this.rightDate = new Date(date.setFullYear(date.getFullYear() + 12));
160
+ }
161
+ },
162
+ defaultValue(val) {
163
+ if (!Array.isArray(this.value) || !this.value.length) {
164
+ const [left, right] = calcDefaultValue(val);
165
+ this.date = left;
166
+ if (this.unlinkPanels) this.rightDate = right;
167
+ }
168
+ }
169
+ },
170
+ methods: {
171
+ handleClear() {
172
+ this.minDate = null;
173
+ this.maxDate = null;
174
+ this.date = calcDefaultValue(this.defaultValue)[0];
175
+ this.handleConfirm(false);
176
+ },
177
+ handleChangeRange(val) {
178
+ this.minDate = val.minDate;
179
+ this.maxDate = val.maxDate;
180
+ this.rangeState = val.rangeState;
181
+ },
182
+ handleRangePick(val, close = true) {
183
+ const defaultTime = this.defaultTime || [];
184
+ const minDate = modifyWithTimeString(val.minDate, defaultTime[0]);
185
+ const maxDate = modifyWithTimeString(val.maxDate, defaultTime[1]);
186
+ if (this.maxDate === maxDate && this.minDate === minDate) {
187
+ return;
188
+ }
189
+ this.onPick && this.onPick(val);
190
+ this.maxDate = maxDate;
191
+ this.minDate = minDate;
192
+
193
+ // workaround for https://github.com/ElemeFE/element/issues/7539, should remove this block when we don't have to care about Chromium 55 - 57
194
+ setTimeout(() => {
195
+ this.maxDate = maxDate;
196
+ this.minDate = minDate;
197
+ }, 10);
198
+ if (!close) return;
199
+ this.handleConfirm();
200
+
201
+ },
202
+ handleShortcutClick(shortcut) {
203
+ if (shortcut.onClick) {
204
+ shortcut.onClick(this);
205
+ }
206
+ },
207
+
208
+ nextYear(left = false) {
209
+ const date = left || !this.unlinkPanels ? this.date : this.rightDate;
210
+ date.setFullYear(date.getFullYear() + 12);
211
+ this.resetDate();
212
+ },
213
+
214
+ prevYear(left = false) {
215
+ const date = left ? this.date : this.rightDate;
216
+ date.setFullYear(date.getFullYear() - 12);
217
+ this.resetDate();
218
+ },
219
+ handleConfirm(visible = false) {
220
+ if (!this.minDate || !this.maxDate) return;
221
+ this.$emit('pick', [new Date(this.minDate, 0, 1), new Date(this.maxDate, 0, 1)], visible);
222
+ },
223
+ resetDate() {
224
+ this.date = new Date(this.date);
225
+ this.rightDate = new Date(this.rightDate);
226
+ }
227
+ },
228
+ components: {
229
+ yearTable
230
+ }
231
+ };
232
+ </script>
233
+
234
+
@@ -0,0 +1,216 @@
1
+ <template>
2
+ <table @click="handleYearTableClick" class="el-year-table nf-double-year-table" @mousemove="handleMouseMove">
3
+ <tbody>
4
+ <tr>
5
+ <td class="available" :class="getCellStyle(startYear + 0)">
6
+ <div>
7
+ <a class="cell">{{ startYear }}</a>
8
+ </div>
9
+ </td>
10
+ <td class="available" :class="getCellStyle(startYear + 1)">
11
+ <div>
12
+ <a class="cell">{{ startYear + 1 }}</a>
13
+ </div>
14
+ </td>
15
+ <td class="available" :class="getCellStyle(startYear + 2)">
16
+ <div>
17
+ <a class="cell">{{ startYear + 2 }}</a>
18
+ </div>
19
+ </td>
20
+ </tr>
21
+ <tr>
22
+ <td class="available" :class="getCellStyle(startYear + 3)">
23
+ <div>
24
+ <a class="cell">{{ startYear + 3 }}</a>
25
+ </div>
26
+ </td>
27
+ <td class="available" :class="getCellStyle(startYear + 4)">
28
+ <div>
29
+ <a class="cell">{{ startYear + 4 }}</a>
30
+ </div>
31
+ </td>
32
+ <td class="available" :class="getCellStyle(startYear + 5)">
33
+ <div>
34
+ <a class="cell">{{ startYear + 5 }}</a>
35
+ </div>
36
+ </td>
37
+ </tr>
38
+ <tr>
39
+ <td class="available" :class="getCellStyle(startYear + 6)">
40
+ <div>
41
+ <a class="cell">{{ startYear + 6 }}</a>
42
+ </div>
43
+ </td>
44
+ <td class="available" :class="getCellStyle(startYear + 7)">
45
+ <div>
46
+ <a class="cell">{{ startYear + 7 }}</a>
47
+ </div>
48
+ </td>
49
+ <td class="available" :class="getCellStyle(startYear + 8)">
50
+ <div>
51
+ <a class="cell">{{ startYear + 8 }}</a>
52
+ </div>
53
+ </td>
54
+ </tr>
55
+ <tr>
56
+ <td class="available" :class="getCellStyle(startYear + 9)">
57
+ <div>
58
+ <a class="cell">{{ startYear + 9 }}</a>
59
+ </div>
60
+ </td>
61
+ <td class="available" :class="getCellStyle(startYear + 10)">
62
+ <div>
63
+ <a class="cell">{{ startYear + 10 }}</a>
64
+ </div>
65
+ </td>
66
+ <td class="available" :class="getCellStyle(startYear + 11)">
67
+ <div>
68
+ <a class="cell">{{ startYear + 11 }}</a>
69
+ </div>
70
+ </td>
71
+ </tr>
72
+ </tbody>
73
+ </table>
74
+ </template>
75
+
76
+ <script type="text/babel">
77
+ import { hasClass } from 'element-ui/src/utils/dom';
78
+ import { range, nextDate, getDayCountOfYear, isDate} from 'element-ui/src/utils/date-util';
79
+ import { arrayFindIndex, coerceTruthyValueToArray } from 'element-ui/src/utils/util';
80
+
81
+ const datesInYear = year => {
82
+ const numOfDays = getDayCountOfYear(year);
83
+ const firstDay = new Date(year, 0, 1);
84
+ return range(numOfDays).map(n => nextDate(firstDay, n));
85
+ };
86
+
87
+ export default {
88
+ props: {
89
+ defaultValue: {
90
+ validator(val) {
91
+ // null or valid Date Object
92
+ return val === null || (val instanceof Date && isDate(val));
93
+ }
94
+ },
95
+ disabledDate: {},
96
+ date: {},
97
+ value: {},
98
+ year: {},
99
+ minDate: {},
100
+ maxDate: {},
101
+ selectionMode: {
102
+ default: 'year'
103
+ },
104
+ rangeState: {
105
+ default() {
106
+ return {
107
+ endDate: null,
108
+ selecting: false
109
+ };
110
+ }
111
+ }
112
+ },
113
+
114
+ computed: {
115
+ startYear() {
116
+ return Math.floor(this.date.getFullYear() / 12) * 12;
117
+ }
118
+ },
119
+
120
+ methods: {
121
+ getCellStyle(year) {
122
+ const style = {};
123
+ const today = new Date();
124
+
125
+ style.disabled = typeof this.disabledDate === 'function'
126
+ ? datesInYear(year).every(this.disabledDate)
127
+ : false;
128
+ style.today = today.getFullYear() === year;
129
+ style.default = this.defaultValue && this.defaultValue.getFullYear() === year;
130
+
131
+ if (this.selectionMode === 'range') {
132
+ let minYear = this.minDate;
133
+ let maxYear = this.rangeState.endDate ? this.rangeState.endDate : this.maxDate;
134
+ [minYear, maxYear] = [Math.min(minYear, maxYear), Math.max(minYear, maxYear)];
135
+ style['start-date'] = year === minYear;
136
+ style['end-date'] = minYear && year === maxYear;
137
+ style['in-range'] = minYear && year >= minYear && year <= maxYear;
138
+ } else {
139
+ style.current = arrayFindIndex(coerceTruthyValueToArray(this.value), date => date.getFullYear() === year) >= 0;
140
+ }
141
+
142
+ return style;
143
+ },
144
+
145
+ nextTenYear() {
146
+ this.$emit('pick', Number(this.year) + 12, false);
147
+ },
148
+
149
+ prevTenYear() {
150
+ this.$emit('pick', Number(this.year) - 12, false);
151
+ },
152
+
153
+ handleYearTableClick(event) {
154
+ let target = event.target;
155
+ if (target.tagName === 'A') {
156
+ target = target.parentNode.parentNode;
157
+ }
158
+ if (target.tagName === 'DIV') {
159
+ target = target.parentNode;
160
+ }
161
+ if (target.tagName !== 'TD') return;
162
+ if (hasClass(target, 'disabled')) return;
163
+
164
+ /* istanbul ignore if */
165
+ const year = Number(target.textContent || target.innerText);
166
+ if (this.selectionMode === 'range') {
167
+ if (!this.rangeState.selecting) {
168
+ this.$emit('pick', {minDate: year, maxDate: null});
169
+ // eslint-disable-next-line
170
+ this.rangeState.selecting = true;
171
+ // eslint-disable-next-line
172
+ this.rangeState.endDate = null;
173
+ } else {
174
+ // eslint-disable-next-line
175
+ this.rangeState.selecting = false;
176
+ if (year >= this.minDate) {
177
+ this.$emit('pick', {minDate: this.minDate, maxDate: year});
178
+ } else {
179
+ this.$emit('pick', {minDate: year, maxDate: this.minDate});
180
+ }
181
+ }
182
+ } else {
183
+ this.$emit('pick', year);
184
+ }
185
+ this.handleMouseMove(event);
186
+ },
187
+
188
+ handleMouseMove(event) {
189
+ let target = event.target;
190
+ if (!this.rangeState.selecting) return;
191
+
192
+ if (target.tagName === 'A') {
193
+ target = target.parentNode.parentNode;
194
+ }
195
+ if (target.tagName === 'DIV') {
196
+ target = target.parentNode;
197
+ }
198
+ if (target.tagName !== 'TD') return;
199
+ const row = target.parentNode.rowIndex;
200
+ const column = target.cellIndex;
201
+ if (hasClass(target.parentNode, 'disabled')) return;
202
+ if (row !== this.lastRow || column !== this.lastColumn) {
203
+ this.$emit('changerange', {
204
+ minDate: this.minDate,
205
+ maxDate: this.maxDate,
206
+ rangeState: {
207
+ selecting: true,
208
+ endDate: Number(target.textContent || target.innerText)
209
+ },
210
+ el: target
211
+ });
212
+ }
213
+ }
214
+ }
215
+ };
216
+ </script>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@94ai/nf-double-year",
3
- "version": "3.1.37",
3
+ "version": "3.1.39",
4
4
  "description": "> TODO: description",
5
5
  "keywords": [],
6
6
  "author": "zoujiahe <zoujiahe@94ai.com>",
@@ -14,7 +14,7 @@
14
14
  "url": "http://94ai.gitlab.com/zoujiahe/common-ui.git"
15
15
  },
16
16
  "dependencies": {
17
- "@94ai/nf-theme-chalk": "^3.1.37",
17
+ "@94ai/nf-theme-chalk": "^1.0.0",
18
18
  "vue-demi": "^0.14.5"
19
19
  },
20
20
  "peerDependenciesMeta": {
@@ -30,5 +30,5 @@
30
30
  "types": "lib/index.d.ts",
31
31
  "main": "lib/nf-double-year.cjs.js",
32
32
  "module": "lib/nf-double-year.esm-bundler.js",
33
- "gitHead": "14dfc729b9988003d4686b414e1e9c0aaa7c4dcd"
33
+ "gitHead": "2b60696b405feafbbaeed385e5bcf666ceefbf2c"
34
34
  }