Skip to content

Commit 347e995

Browse files
authored
Merge pull request #13 from thwiki/dev
修复日期判断问题
2 parents aabbe75 + d059241 commit 347e995

4 files changed

Lines changed: 23 additions & 43 deletions

File tree

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,4 @@ pnpm-debug.log*
2121
*.sln
2222
*.sw?
2323

24+
dist

description.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
更换THBLOGO新地址
2-
取消快捷年月选择
1+
修复日期判断
2+
将日期查询间隔调整为一个月

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "thb-calendar",
3-
"version": "0.1.9",
3+
"version": "1.0.0",
44
"scripts": {
55
"serve": "vue-cli-service serve",
66
"build": "vue-cli-service build",

src/components/calendar1.vue

Lines changed: 19 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@
9696
</el-link>
9797
</div>
9898
</template>
99-
</div>
99+
</div>
100100
</template>
101101
<div class="eventBtn" slot="reference"></div>
102102
</el-popover>
@@ -139,37 +139,22 @@ export default {
139139
nVal.getMonth() != oVal.getMonth()
140140
) {
141141
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);
154144
}
155145
},
156146
},
157147
created() {
158148
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);
171151
},
172152
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+
},
173158
getBaiduDays(date) {
174159
if (!date) date = this.currentDate;
175160
let year = date.getFullYear();
@@ -206,20 +191,15 @@ export default {
206191
);
207192
},
208193
getHoliday(day) {
209-
day = new Date(day + " 00:00+08:00");
194+
day = new Date(day + " 00:00+08:00").getTime();
210195
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;
215199
});
216-
if (hd.length > 0) {
217-
return hd[0];
218-
}
219-
return null;
200+
return hd.length > 0 ? hd[0] : null;
220201
},
221202
getEventDate(startDate, endDate) {
222-
let _this = this;
223203
if (this.userList.length > 0) {
224204
this.dateList = this.userList;
225205
} else {
@@ -269,13 +249,12 @@ export default {
269249
});
270250
},
271251
eventListFromDay(day) {
272-
day = new Date(day + " 00:00+08:00");
252+
day = new Date(day + " 00:00+08:00").getTime();
273253
let events = this.dateList.filter(function (v) {
274254
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;
279258
});
280259
return v.length > 0;
281260
});

0 commit comments

Comments
 (0)