Skip to content

Commit

Permalink
-修复在特殊情况下,任务时间设置错误的问题
Browse files Browse the repository at this point in the history
  • Loading branch information
QlQlqiqi committed Oct 10, 2021
1 parent 0ecd71f commit 9c290ff
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 20 deletions.
60 changes: 43 additions & 17 deletions src/components/time/time.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ Component({
* 组件的初始数据
*/
data: {
startDate: "请选择日期",
showDate: "请选择日期",
multiArray: [[], [], []],
multiIndex: [0, 0, 0],
},
Expand All @@ -31,27 +31,45 @@ Component({
let {defaultHour, defaultMinute} = this.data;
// 根据当前 hours 和 minutes 重新绘制 multiArray
let hours = [], minutes = [];
// 如果是今天,则不绘制全天的 hours 和 minutes ,否则绘制全天
if(!this.data.multiIndex[0])
([hours, minutes] = this.reloadHoursAndMinutes(defaultHour, defaultMinute));
else ([hours, minutes] = this.reloadHoursAndMinutes(0, 0));
let {multiArray, multiIndex} = this.data;
multiArray[1] = hours;
multiArray[2] = minutes;
// 设置 multiIndex
let date = new Date(this.properties.defaultTime);
// 设置 multiIndex
for(let i = 0, currentMD = date.getUTCMonth() + 1 + '-' + date.getUTCDate(); i < multiArray[0].length; i++)
if(multiArray[0][i] === currentMD) {
multiIndex[0] = i;
break;
}
multiIndex[1] = date.getUTCHours() - hours[0];
multiIndex[2] = date.getUTCMinutes() - minutes[0];
// multiIndex[2] = date.getUTCMinutes() - def
// 如果是今天,则不绘制全天的 hours 和 minutes ,否则绘制全天
let fromHour = 0, fromMinute = 0;
if(!multiIndex[0]) {
multiIndex[1] = date.getUTCHours() - defaultHour;
fromHour = defaultHour;
if(date.getUTCHours() === defaultHour) {
fromMinute = defaultMinute;
multiIndex[2] = date.getUTCMinutes() - defaultMinute;
}
else multiIndex[2] = +date.getUTCMinutes();
}
else {
multiIndex[1] = date.getUTCHours();
multiIndex[2] = date.getUTCMinutes();
}
([multiArray[1], multiArray[2]] = this.reloadHoursAndMinutes(fromHour, fromMinute));
console.log(hours, minutes);
// multiIndex[2] = date.getUTCMinutes() - minutes[0];
// multiIndex[1] = date.getUTCHours() - hours[0];
// if(!this.data.multiIndex[0] && date.getUTCHours() > hours[0]) {
// ([hours, minutes] = this.reloadHoursAndMinutes(defaultHour, 0));
// console.log(minutes)
// multiIndex[2] = 0;
// }

this.setData({
multiArray,
multiIndex
})
console.log(this.data);
},

// 根据给定的参数加载 hour 和 minute
Expand Down Expand Up @@ -81,10 +99,11 @@ Component({
}
// 改变 hour
else if(column === 1) {
console.log(multiIndex)
if(!multiIndex[0]) {
if(!multiIndex[1])
([multiArray[1], multiArray[2]] = this.reloadHoursAndMinutes(0, 0));
if(!value)
if(value)
([multiArray[1], multiArray[2]] = this.reloadHoursAndMinutes(defaultHour, 0));
else
([multiArray[1], multiArray[2]] = this.reloadHoursAndMinutes(defaultHour, defaultMinute));
}
}
Expand All @@ -93,13 +112,16 @@ Component({
multiArray,
multiIndex
})
console.log(this.data);
},

// 确定选择日期
bindStartMultiPickerChange: function (e) {
let date = new Date(this.properties.defaultTime);
let date = new Date(this.data.startTime);
let {multiArray, multiIndex} = this.data;
// date.setTime(date.getTime() + multiIndex[0] * 24 * 60 * 60 * 1000);
date.setTime(date.getTime() + multiIndex[0] * 24 * 60 * 60 * 1000);
console.log(date, multiArray, multiIndex, this.data.startTime)
date.setUTCHours(+multiArray[1][multiIndex[1]]);
date.setUTCMinutes(+multiArray[2][multiIndex[2]]);
let year = date.getUTCFullYear(),
Expand All @@ -109,7 +131,7 @@ Component({
minute = date.getUTCMinutes(),
second = date.getUTCSeconds();
this.setData({
startDate: `${month < 10? '0' + month: month}${day < 10? '0' + day: day}${hour < 10? '0' + hour: hour}:${minute < 10? '0' + minute: minute}`
showDate: `${month < 10? '0' + month: month}${day < 10? '0' + day: day}${hour < 10? '0' + hour: hour}:${minute < 10? '0' + minute: minute}`
})
let time = `${year}-${month < 10? "0" + month: month}-${day < 10? "0" + day: day}T${hour < 10? "0" + hour: hour}:${minute < 10? "0" + minute: minute}:${second < 10? "0" + second: second}Z`;
this.triggerEvent("handleChangeTime", {
Expand All @@ -118,6 +140,9 @@ Component({
}
},
lifetimes: {
show() {

},
ready: function() {
// 设置时间
let date = new Date(this.properties.defaultTime),
Expand All @@ -140,13 +165,14 @@ Component({
this.setData({
multiArray,
multiIndex,
startDate: `${month < 10? '0' + month: month}${day < 10? '0' + day: day}${hour < 10? '0' + hour: hour}:${minute < 10? '0' + minute: minute}`,
showDate: `${month < 10? '0' + month: month}${day < 10? '0' + day: day}${hour < 10? '0' + hour: hour}:${minute < 10? '0' + minute: minute}`,
defaultYear: year,
defaultMonth: month,
defaultDay: day,
defaultHour: hour,
defaultMinute: minute,
defaultSecond: second
defaultSecond: second,
startTime: this.properties.defaultTime,
})
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/components/time/time.wxml
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@
bindtap='pickerTap' bindcolumnchange="bindMultiPickerColumnChange" value="{{ multiIndex }}"
range="{{ multiArray }}"
>
{{ startDate }}
{{ showDate }}
</picker>
10 changes: 8 additions & 2 deletions src/pages/editor/editor.wxml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,11 @@
<!-- 任务内容 -->
<view style="background-color: white; position: relative; margin-top: 40rpx; margin-left: 30rpx; width: 682rpx; height: 182rpx; border: 2rpx solid rgba(187, 187, 187, 1);">
<image src="/src/image/editor-pencil.svg" mode="aspectFit" style="height: 42rpx; width: 42rpx; position: absolute; left: 44rpx; top: 60rpx;"></image>
<input class="editor-task-content" value="{{ task.content }}" bind:input="contentInput" focus="{{ true }}" placeholder="请输入任务内容......" placeholder-style="color: rgba(66, 66, 66, 0.55); font-size: 24rpx;" maxlength="25" focus="{{ true }}"></input>
<input class="editor-task-content" value="{{ task.content }}" bind:input="contentInput"
focus="{{ true }}" placeholder="请输入任务内容......"
placeholder-style="color: rgba(66, 66, 66, 0.55); font-size: 24rpx;"
maxlength="25" focus="{{ true }}"
></input>
<!-- 完成 -->
</view>

Expand All @@ -32,7 +36,9 @@
<view class="editor-time-wrap">
<image src="/src/image/editor-date.svg" mode="aspectFit" style="top: 32rpx; left: 24rpx;"></image>
<view style="display: inline-block; margin-left: 84rpx; font-weight: bold;">时间</view>
<time class="editor-time-text" defaultTime="{{ task.date }}" timeLength="{{ 180 }}" catch:handleChangeTime="handleChangeTime"></time>
<time class="editor-time-text" defaultTime="{{ task.date }}" timeLength="{{ 180 }}"
catch:handleChangeTime="handleChangeTime"
></time>
</view>

<view style="height: 2rpx; border-top: 2rpx rgba(255, 255, 255, 0.63) solid;"></view>
Expand Down

0 comments on commit 9c290ff

Please sign in to comment.