66 <button
77 type =" button"
88 class =" viewButton"
9- @click =" changeViewMode('years' )"
9+ @click =" changeViewMode(MODE_ENUMS.YEAR )"
1010 >
1111 {{ viewButtonText }}
1212 </button >
4343 </button >
4444 </div >
4545 <div class =" viewmode" >
46- <div class =" years" v-show =" viewMode === 'years' " >
46+ <div class =" years" v-show =" viewMode === MODE_ENUMS.YEAR " >
4747 <button
4848 v-for =" y in years"
4949 :key =" y.year"
5555 {{ y.year }}
5656 </button >
5757 </div >
58- <div class =" months" v-show =" viewMode === 'months' " >
58+ <div class =" months" v-show =" viewMode === MODE_ENUMS.MONTH " >
5959 <button
6060 v-for =" month in months"
6161 :key =" month.index"
7373</template >
7474
7575<script >
76+ import { MODE_ENUMS } from ' @/utils/modes'
77+
7678export default {
7779 props: {
7880 calendar: {
@@ -122,12 +124,15 @@ export default {
122124 } else return this .selectedDate
123125 },
124126 isDayMode () {
125- return this .viewMode === ' days '
127+ return this .viewMode === MODE_ENUMS . DAY
126128 },
127129 yearsRange () {
128130 const years = this .calendar .years
129131 return years[0 ] + this .rangeSeperator + years[years .length - 1 ]
130132 },
133+ MODE_ENUMS () {
134+ return MODE_ENUMS
135+ },
131136 dayViewText () {
132137 return (
133138 this .calendar .months [this .currentDate .month ].name +
@@ -138,10 +143,10 @@ export default {
138143 viewButtonText () {
139144 let text
140145 switch (this .viewMode ) {
141- case ' years ' :
146+ case MODE_ENUMS . YEAR :
142147 text = this .yearsRange
143148 break
144- case ' months ' :
149+ case MODE_ENUMS . MONTH :
145150 text = this .currentDate .year
146151 break
147152 default :
@@ -206,31 +211,31 @@ export default {
206211 },
207212 prev () {
208213 switch (this .viewMode ) {
209- case ' days ' :
214+ case MODE_ENUMS . DAY :
210215 this .$emit (' prevMonth' , this .pickerType )
211216 break
212- case ' months ' :
217+ case MODE_ENUMS . MONTH :
213218 this .$emit (' setUniqYear' , {
214219 year: this .currentDate .year - 1 ,
215220 picker: this .pickerType
216221 })
217222 break
218- case ' years ' :
223+ case MODE_ENUMS . YEAR :
219224 this .$emit (' setYears' , { route: ' prev' , picker: this .pickerType })
220225 }
221226 },
222227 next () {
223228 switch (this .viewMode ) {
224- case ' days ' :
229+ case MODE_ENUMS . DAY :
225230 this .$emit (' nextMonth' , this .pickerType )
226231 break
227- case ' months ' :
232+ case MODE_ENUMS . MONTH :
228233 this .$emit (' setUniqYear' , {
229234 year: this .currentDate .year + 1 ,
230235 picker: this .pickerType
231236 })
232237 break
233- case ' years ' :
238+ case MODE_ENUMS . YEAR :
234239 this .$emit (' setYears' , { route: ' next' , picker: this .pickerType })
235240 }
236241 },
0 commit comments