Commit d9171718 authored by Facius's avatar Facius

fix: 【ID1001462】 【小程序-首页-学练记录】:当前月份时月份还可以切换到下个月份

parent ae546358
...@@ -111,6 +111,9 @@ ...@@ -111,6 +111,9 @@
<u-button :type="btnType" shape="circle" size="default" @click="btnFix()">确定</u-button> <u-button :type="btnType" shape="circle" size="default" @click="btnFix()">确定</u-button>
</view> </view>
</view> --> </view> -->
<view>
<u-toast ref="uToast" />
</view>
</view> </view>
<!-- </u-popup> --> <!-- </u-popup> -->
</template> </template>
...@@ -287,6 +290,11 @@ export default { ...@@ -287,6 +290,11 @@ export default {
return [] return []
}, },
}, },
// ture: 月和年切换不可超过本月;false: 不对月份限制,根据maxYear限制切换最大年份
currentMonthMax: {
type: Boolean,
default: true,
},
}, },
data() { data() {
return { return {
...@@ -427,13 +435,28 @@ export default { ...@@ -427,13 +435,28 @@ export default {
let date = new Date(`${year}/${month}/01 00:00:00`) let date = new Date(`${year}/${month}/01 00:00:00`)
return date.getDay() return date.getDay()
}, },
checkRange(year) { checkRange(year, month) {
let overstep = false let overstep = false
if (year < this.minYear || year > this.maxYear) { let now = new Date()
uni.showToast({ let mYear = this.currentMonthMax ? now.getFullYear() : this.maxYear // ture: 月和年切换不可超过本月;false: 不对月份限制,根据maxYear限制切换最大年份
console.log(year, mYear, month, now.getMonth() + 1)
if (
year < this.minYear ||
year > mYear ||
(this.currentMonthMax &&
year == mYear &&
month &&
month > now.getMonth() + 1)
) {
this.$refs.uToast.show({
title: '日期超出范围啦~', title: '日期超出范围啦~',
icon: 'none', type: 'warning',
duration: 1500,
}) })
// uni.showToast({
// title: '日期超出范围啦~',
// icon: 'none',
// })
overstep = true overstep = true
} }
return overstep return overstep
...@@ -442,7 +465,7 @@ export default { ...@@ -442,7 +465,7 @@ export default {
if (isAdd) { if (isAdd) {
let month = this.month + 1 let month = this.month + 1
let year = month > 12 ? this.year + 1 : this.year let year = month > 12 ? this.year + 1 : this.year
if (!this.checkRange(year)) { if (!this.checkRange(year, month > 12 ? 1 : month)) {
this.month = month > 12 ? 1 : month this.month = month > 12 ? 1 : month
this.year = year this.year = year
this.changeData() this.changeData()
......
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