Commit 77e43f2b871102554600b0d0a231be4647a703e3
1 parent
8f6aeda4
Correct year date navigation logic
Showing
2 changed files
with
34 additions
and
16 deletions
Show diff stats
src/components/date-picker/panel/Date/date-range.vue
| @@ -218,30 +218,44 @@ | @@ -218,30 +218,44 @@ | ||
| 218 | labels: labels.map(obj => ((obj.handler = handler(obj.type)), obj)) | 218 | labels: labels.map(obj => ((obj.handler = handler(obj.type)), obj)) |
| 219 | }; | 219 | }; |
| 220 | }, | 220 | }, |
| 221 | - prevYear (direction) { | ||
| 222 | - this.changePanelDate(direction, 'FullYear', -1); | 221 | + prevYear (panel) { |
| 222 | + console.log(this) | ||
| 223 | + const increment = this.currentView === 'year' ? -10 : -1; | ||
| 224 | + this.changePanelDate(panel, 'FullYear', increment); | ||
| 223 | }, | 225 | }, |
| 224 | - nextYear (direction) { | ||
| 225 | - this.changePanelDate(direction, 'FullYear', 1); | 226 | + nextYear (panel) { |
| 227 | + const increment = this.currentView === 'year' ? 10 : 1; | ||
| 228 | + this.changePanelDate(panel, 'FullYear', increment); | ||
| 226 | }, | 229 | }, |
| 227 | - prevMonth(direction){ | ||
| 228 | - this.changePanelDate(direction, 'Month', -1); | 230 | + prevMonth(panel){ |
| 231 | + this.changePanelDate(panel, 'Month', -1); | ||
| 229 | }, | 232 | }, |
| 230 | - nextMonth(direction){ | ||
| 231 | - this.changePanelDate(direction, 'Month', 1); | 233 | + nextMonth(panel){ |
| 234 | + this.changePanelDate(panel, 'Month', 1); | ||
| 232 | }, | 235 | }, |
| 233 | changePanelDate(panel, type, increment){ | 236 | changePanelDate(panel, type, increment){ |
| 234 | const current = new Date(this[`${panel}PanelDate`]); | 237 | const current = new Date(this[`${panel}PanelDate`]); |
| 235 | current[`set${type}`](current[`get${type}`]() + increment); | 238 | current[`set${type}`](current[`get${type}`]() + increment); |
| 236 | this[`${panel}PanelDate`] = current; | 239 | this[`${panel}PanelDate`] = current; |
| 237 | 240 | ||
| 238 | - // change other panels if they overlap | ||
| 239 | - const otherPanel = panel === 'left' ? 'right' : 'left'; | ||
| 240 | - if (panel === 'left' && this.leftPanelDate >= this.rightPanelDate){ | ||
| 241 | - this.changePanelDate(otherPanel, type, 1); | ||
| 242 | - } | ||
| 243 | - if (panel === 'right' && this.rightPanelDate <= this.leftPanelDate){ | ||
| 244 | - this.changePanelDate(otherPanel, type, -1); | 241 | + |
| 242 | + if (this.splitPanels){ | ||
| 243 | + // change other panel if dates overlap | ||
| 244 | + const otherPanel = panel === 'left' ? 'right' : 'left'; | ||
| 245 | + if (panel === 'left' && this.leftPanelDate >= this.rightPanelDate){ | ||
| 246 | + this.changePanelDate(otherPanel, type, 1); | ||
| 247 | + } | ||
| 248 | + if (panel === 'right' && this.rightPanelDate <= this.leftPanelDate){ | ||
| 249 | + this.changePanelDate(otherPanel, type, -1); | ||
| 250 | + } | ||
| 251 | + } else { | ||
| 252 | + // keep the panels together | ||
| 253 | + const otherPanel = panel === 'left' ? 'right' : 'left'; | ||
| 254 | + const otherCurrent = new Date(this[`${otherPanel}PanelDate`]); | ||
| 255 | + otherCurrent[`set${type}`](otherCurrent[`get${type}`]() + increment); | ||
| 256 | + if (current[`get${type}`]() !== otherCurrent[`get${type}`]()){ | ||
| 257 | + this[`${otherPanel}PanelDate`] = otherCurrent; | ||
| 258 | + } | ||
| 245 | } | 259 | } |
| 246 | }, | 260 | }, |
| 247 | showYearPicker () { | 261 | showYearPicker () { |
src/components/date-picker/panel/Date/date.vue
| @@ -145,7 +145,11 @@ | @@ -145,7 +145,11 @@ | ||
| 145 | }, | 145 | }, |
| 146 | methods: { | 146 | methods: { |
| 147 | changeYear(dir){ | 147 | changeYear(dir){ |
| 148 | - this.panelDate = siblingMonth(this.panelDate, dir * 12); | 148 | + if (this.selectionMode === 'year'){ |
| 149 | + this.panelDate = new Date(this.panelDate.getFullYear() + dir * 10, 0, 1); | ||
| 150 | + } else { | ||
| 151 | + this.panelDate = siblingMonth(this.panelDate, dir * 12); | ||
| 152 | + } | ||
| 149 | }, | 153 | }, |
| 150 | changeMonth(dir){ | 154 | changeMonth(dir){ |
| 151 | this.panelDate = siblingMonth(this.panelDate, dir); | 155 | this.panelDate = siblingMonth(this.panelDate, dir); |