Commit c7ffaecb by fengzhaoyu

首页日期ios 安卓 兼容

parent efb0d958
......@@ -10,14 +10,14 @@ Page({
title: '首页'
})
let data = {
"startTime":"2020-01-01 00:00:00",
"endTime":"2025-12-30 23:59:59"
"startTime": "2020-01-01 00:00:00",
"endTime": "2025-12-30 23:59:59"
}
let that = this
getHomeUserSchedule(data).then(res => {
that.setData({
AllScheduleList: res.data.data
},() => {
}, () => {
let now = new Date()
let year = now.getFullYear();
let scheduleList = this.returnScheduleList(year);
......@@ -33,63 +33,62 @@ Page({
onShow() {
// 页面显示
},
returnScheduleList (year) {
returnScheduleList(year) {
let that = this
let weekList = ['周日', '周一', '周二', '周三', '周四', '周五', '周六']
let DateMap = new Map();
let isLeapYear = year % 4 == 0 && year % 100 != 0 || year % 400 ==0
let isLeapYear = year % 4 == 0 && year % 100 != 0 || year % 400 == 0
if (isLeapYear) {
let isFirstWeek = false;
for(let i = 1; i <= 366; i++) {
if (i<7 && new Date(year, 0, i).getDay() === 0) {
for (let i = 1; i <= 366; i++) {
if (i < 7 && new Date(year, 0, i).getDay() === 0) {
isFirstWeek = true
}
if (isFirstWeek) {
DateMap.set(`${new Date(year, 0, i).toLocaleDateString()}`, {
scheduleList:[]
scheduleList: []
})
}
}
let num = 6 - new Date(year, 0, 366).getDay()
for (let i = 0; i<=num;i++) {
for (let i = 0; i <= num; i++) {
DateMap.set(`${new Date(year, 0, 366 + i).toLocaleDateString()}`, {
scheduleList:[]
scheduleList: []
})
}
} else {
let isFirstWeek = false;
for(let i = 1; i <= 365; i++) {
if (i<7 && new Date(year, 0, i).getDay() === 0) {
for (let i = 1; i <= 365; i++) {
if (i < 7 && new Date(year, 0, i).getDay() === 0) {
isFirstWeek = true
}
if (isFirstWeek) {
DateMap.set(`${new Date(year, 0, i).toLocaleDateString()}`, {
scheduleList:[]
scheduleList: []
})
}
}
let num = 6 - new Date(year, 0, 366).getDate()
for (let i = 0; i<=num;i++) {
for (let i = 0; i <= num; i++) {
DateMap.set(`${new Date(year, 0, 366 + i).toLocaleDateString()}`, {
scheduleList:[]
scheduleList: []
})
}
}
for(let y=0;y<this.data.AllScheduleList.length;y++) {
let date1 = this.data.AllScheduleList[y].startTime.slice(0,10).replace(/-/g, '/')
let date2 = this.data.AllScheduleList[y].endTime.slice(0,10).replace(/-/g, '/')
for (let y = 0; y < this.data.AllScheduleList.length; y++) {
let date1 = this.data.AllScheduleList[y].startTime.slice(0, 10).replace(/-/g, '/')
let date2 = this.data.AllScheduleList[y].endTime.slice(0, 10).replace(/-/g, '/')
let count = this.count(date1, date2)
if(count == 0) {
if (count == 0) {
DateMap.get(`${new Date(this.data.AllScheduleList[y].startTime.replace(/-/g, '/')).toLocaleDateString()}`).scheduleList.push(this.data.AllScheduleList[y])
} else {
for(let j = 0;j<=count;j++) {
for (let j = 0; j <= count; j++) {
let time = new Date();
time.setDate(time.getDate()+j)
time.setDate(time.getDate() + j)
// let finalDate = day.setDate(day.getDate()+j)
console.log(`${time.getFullYear()}/${time.getMonth()+1}/${time.getDate()}`)
DateMap.get(`${time.getFullYear()}/${time.getMonth()+1}/${time.getDate()}`).scheduleList.push({
DateMap.get(new Date(time.getFullYear(), time.getMonth() + 1, time.getDate()).toLocaleDateString()).scheduleList.push({
...this.data.AllScheduleList[y],
number: j+1
number: j + 1
})
}
}
......@@ -103,13 +102,13 @@ Page({
value: year
})
DateMap.forEach(function (value, key, map) {
if (new Date(key).getDay() === 0 && that.count(new Date(key),new Date(year, 0, isLeapYear ? 366 : 365) >= 7)) {
if (new Date(key).getDay() === 0 && that.count(new Date(key), new Date(year, 0, isLeapYear ? 366 : 365) >= 7)) {
listWeek = listWeek + 1
if (new Date(key).getMonth() !== listMonth) {
listMonth = new Date(key).getMonth()
DateList.push({
type: 'month',
value: new Date(key).getMonth()+1
value: new Date(key).getMonth() + 1
})
let rangeYear1 = new Date(key).getFullYear()
let rangeMonth1 = new Date(key).getMonth()
......@@ -119,7 +118,7 @@ Page({
let rangeDay2 = new Date(rangeDate).getDate()
DateList.push({
type: 'week',
value: `第${listWeek}周,${rangeMonth1 + 1}${rangeDay1}日 - ${rangeMonth2 == rangeMonth1 ? '' : rangeMonth2 + 1+ '月'}${rangeDay2}日`,
value: `第${listWeek}周,${rangeMonth1 + 1}${rangeDay1}日 - ${rangeMonth2 == rangeMonth1 ? '' : rangeMonth2 + 1 + '月'}${rangeDay2}日`,
})
} else {
let rangeYear1 = new Date(key).getFullYear()
......@@ -130,10 +129,10 @@ Page({
let rangeDay2 = new Date(rangeDate).getDate()
DateList.push({
type: 'week',
value: `第${listWeek}周,${rangeMonth1 + 1}${rangeDay1}日 - ${rangeMonth2 == rangeMonth1 ? '' : rangeMonth2 + 1+ '月'}${rangeDay2}日`,
value: `第${listWeek}周,${rangeMonth1 + 1}${rangeDay1}日 - ${rangeMonth2 == rangeMonth1 ? '' : rangeMonth2 + 1 + '月'}${rangeDay2}日`,
})
}
} else if (new Date(key).getDay() === 0 && that.count(new Date(key),new Date(year, 0, isLeapYear ? 366 : 365) < 7)){
} else if (new Date(key).getDay() === 0 && that.count(new Date(key), new Date(year, 0, isLeapYear ? 366 : 365) < 7)) {
listWeek = 1
DateList.push({
type: 'week',
......@@ -145,7 +144,7 @@ Page({
type: 'day',
value: {
value: value.scheduleList,
day: new Date(key).getDate() < 10 ? '0'+ new Date(key).getDate() : new Date(key).getDate(),
day: new Date(key).getDate() < 10 ? '0' + new Date(key).getDate() : new Date(key).getDate(),
week: weekList[new Date(key).getDay()]
},
})
......@@ -154,10 +153,10 @@ Page({
console.log(DateList)
return DateList
},
count(date1, date2){
var date1=new Date(date1);
var date2=new Date(date2);
var date=(date2.getTime()-date1.getTime())/(1000*60*60*24);/*不用考虑闰年否*/
count(date1, date2) {
var date1 = new Date(date1);
var date2 = new Date(date2);
var date = (date2.getTime() - date1.getTime()) / (1000 * 60 * 60 * 24);/*不用考虑闰年否*/
return date
},
onHide() {
......@@ -186,7 +185,7 @@ Page({
nextPage() {
dd.navigateTo({ url: './../createOrEditSchedule/createOrEditSchedule' })
},
nextDetail (e) {
nextDetail(e) {
let id = e.target.dataset.id
dd.navigateTo({ url: `./../scheduleDetail/scheduleDetail?id=${id}` })
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment