|
96 | 96 | </el-link> |
97 | 97 | </div> |
98 | 98 | </template> |
99 | | - </div> |
| 99 | + </div> |
100 | 100 | </template> |
101 | 101 | <div class="eventBtn" slot="reference"></div> |
102 | 102 | </el-popover> |
@@ -139,37 +139,22 @@ export default { |
139 | 139 | nVal.getMonth() != oVal.getMonth() |
140 | 140 | ) { |
141 | 141 | this.getBaiduDays(nVal); |
142 | | - this.getEventDate( |
143 | | - nVal |
144 | | - .getMonthFirstDay() |
145 | | - .addDays(-1) |
146 | | - .getMonthFirstDay() |
147 | | - .Format("yyyy-MM-dd"), |
148 | | - nVal |
149 | | - .getMonthLastDay() |
150 | | - .addDays(1) |
151 | | - .getMonthLastDay() |
152 | | - .Format("yyyy-MM-dd") |
153 | | - ); |
| 142 | + const { firstDay, lastDay } = this.getMonthRange(nVal); |
| 143 | + this.getEventDate(firstDay, lastDay); |
154 | 144 | } |
155 | 145 | }, |
156 | 146 | }, |
157 | 147 | created() { |
158 | 148 | this.getBaiduDays(); |
159 | | - this.getEventDate( |
160 | | - this.currentDate |
161 | | - .getMonthFirstDay() |
162 | | - .addDays(-1) |
163 | | - .getMonthFirstDay() |
164 | | - .Format("yyyy-MM-dd"), |
165 | | - this.currentDate |
166 | | - .getMonthLastDay() |
167 | | - .addDays(1) |
168 | | - .getMonthLastDay() |
169 | | - .Format("yyyy-MM-dd") |
170 | | - ); |
| 149 | + const { firstDay, lastDay } = this.getMonthRange(this.currentDate); |
| 150 | + this.getEventDate(firstDay, lastDay); |
171 | 151 | }, |
172 | 152 | methods: { |
| 153 | + getMonthRange(date) { |
| 154 | + let firstDay = date.getMonthFirstDay().addDays(-6).Format("yyyy-MM-dd"); |
| 155 | + let lastDay = date.getMonthLastDay().addDays(6).Format("yyyy-MM-dd"); |
| 156 | + return { firstDay, lastDay }; |
| 157 | + }, |
173 | 158 | getBaiduDays(date) { |
174 | 159 | if (!date) date = this.currentDate; |
175 | 160 | let year = date.getFullYear(); |
@@ -206,20 +191,15 @@ export default { |
206 | 191 | ); |
207 | 192 | }, |
208 | 193 | getHoliday(day) { |
209 | | - day = new Date(day + " 00:00+08:00"); |
| 194 | + day = new Date(day + " 00:00+08:00").getTime(); |
210 | 195 | let hd = this.baiduDays.filter(function (v) { |
211 | | - return ( |
212 | | - new Date(v.startDate + " 00:00+08:00") <= day && |
213 | | - new Date(v.endDate + " 00:00+08:00") >= day |
214 | | - ); |
| 196 | + let startDate = new Date(v.startDate + " 00:00+08:00").getTime(); |
| 197 | + let endDate = new Date(v.endDate + " 00:00+08:00").getTime(); |
| 198 | + return startDate <= day && endDate >= day; |
215 | 199 | }); |
216 | | - if (hd.length > 0) { |
217 | | - return hd[0]; |
218 | | - } |
219 | | - return null; |
| 200 | + return hd.length > 0 ? hd[0] : null; |
220 | 201 | }, |
221 | 202 | getEventDate(startDate, endDate) { |
222 | | - let _this = this; |
223 | 203 | if (this.userList.length > 0) { |
224 | 204 | this.dateList = this.userList; |
225 | 205 | } else { |
@@ -269,13 +249,12 @@ export default { |
269 | 249 | }); |
270 | 250 | }, |
271 | 251 | eventListFromDay(day) { |
272 | | - day = new Date(day + " 00:00+08:00"); |
| 252 | + day = new Date(day + " 00:00+08:00").getTime(); |
273 | 253 | let events = this.dateList.filter(function (v) { |
274 | 254 | v = v.filter(function (v1) { |
275 | | - return ( |
276 | | - new Date(v1.startDate + " 00:00+08:00") <= day && |
277 | | - new Date(v1.endDate + " 00:00+08:00") >= day |
278 | | - ); |
| 255 | + let startDate = new Date(v1.startDate + " 00:00+08:00").getTime(); |
| 256 | + let endDate = new Date(v1.endDate + " 00:00+08:00").getTime(); |
| 257 | + return startDate <= day && endDate >= day; |
279 | 258 | }); |
280 | 259 | return v.length > 0; |
281 | 260 | }); |
|
0 commit comments