fix(booking): 修复日期选择逻辑和空数据情况处理
修复日期选择时未判空导致的潜在错误 处理日期数据为空时周历显示问题 添加日期索引作为循环key提高性能
Showing
1 changed file
with
16 additions
and
10 deletions
| 1 | <!-- | 1 | <!-- |
| 2 | * @Date: 2024-01-15 13:35:51 | 2 | * @Date: 2024-01-15 13:35:51 |
| 3 | * @LastEditors: hookehuyr hookehuyr@gmail.com | 3 | * @LastEditors: hookehuyr hookehuyr@gmail.com |
| 4 | - * @LastEditTime: 2026-01-22 10:56:01 | 4 | + * @LastEditTime: 2026-01-22 11:03:35 |
| 5 | * @FilePath: /git/xysBooking/src/views/booking.vue | 5 | * @FilePath: /git/xysBooking/src/views/booking.vue |
| 6 | * @Description: 预约页面 | 6 | * @Description: 预约页面 |
| 7 | --> | 7 | --> |
| ... | @@ -17,12 +17,12 @@ | ... | @@ -17,12 +17,12 @@ |
| 17 | <div v-for="day in daysOfWeek" :key="day" class="item">{{ day }}</div> | 17 | <div v-for="day in daysOfWeek" :key="day" class="item">{{ day }}</div> |
| 18 | </div> | 18 | </div> |
| 19 | <div class="weeks-wrapper"> | 19 | <div class="weeks-wrapper"> |
| 20 | - <div v-for="(week, index) in weeks" :key="week" class="weeks"> | 20 | + <div v-for="(week, index) in weeks" :key="index" class="weeks"> |
| 21 | - <div v-for="date in week" :key="date" | 21 | + <div v-for="(date, dateIndex) in week" :key="dateIndex" |
| 22 | @click="chooseDay(date)" | 22 | @click="chooseDay(date)" |
| 23 | :class="[ 'item', | 23 | :class="[ 'item', |
| 24 | - checked_day === findDatesInfo(date).date ? 'checked' : '', | 24 | + date && checked_day === findDatesInfo(date).date ? 'checked' : '', |
| 25 | - findDatesInfo(date).reserve_full === ReserveStatus.FULL || findDatesInfo(date).reserve_full === ReserveStatus.OVERDUE ? 'disabled' : '' | 25 | + date && (findDatesInfo(date).reserve_full === ReserveStatus.FULL || findDatesInfo(date).reserve_full === ReserveStatus.OVERDUE) ? 'disabled' : '' |
| 26 | ]" | 26 | ]" |
| 27 | > | 27 | > |
| 28 | <div v-if="findDatesInfo(date).date"> | 28 | <div v-if="findDatesInfo(date).date"> |
| ... | @@ -97,7 +97,7 @@ | ... | @@ -97,7 +97,7 @@ |
| 97 | </template> | 97 | </template> |
| 98 | 98 | ||
| 99 | <script setup> | 99 | <script setup> |
| 100 | -import { ref } from 'vue' | 100 | +import { ref, computed, onMounted } from 'vue' |
| 101 | import { useRoute, useRouter } from 'vue-router' | 101 | import { useRoute, useRouter } from 'vue-router' |
| 102 | import { showSuccessToast, showFailToast, showToast } from 'vant'; | 102 | import { showSuccessToast, showFailToast, showToast } from 'vant'; |
| 103 | import { Cookies, axios, storeToRefs, mainStore, Toast, useTitle } from '@/utils/generatePackage.js' | 103 | import { Cookies, axios, storeToRefs, mainStore, Toast, useTitle } from '@/utils/generatePackage.js' |
| ... | @@ -174,6 +174,7 @@ const daysOfWeek = ["周一", "周二", "周三", "周四", "周五", "周六", | ... | @@ -174,6 +174,7 @@ const daysOfWeek = ["周一", "周二", "周三", "周四", "周五", "周六", |
| 174 | * @return {array} [array] | 174 | * @return {array} [array] |
| 175 | */ | 175 | */ |
| 176 | const weeks = computed(() => { | 176 | const weeks = computed(() => { |
| 177 | + if (dates.value.length === 0) return []; | ||
| 177 | const result = []; | 178 | const result = []; |
| 178 | let currentWeek = []; | 179 | let currentWeek = []; |
| 179 | let currentDate = new Date(dates.value[0]); | 180 | let currentDate = new Date(dates.value[0]); |
| ... | @@ -203,6 +204,9 @@ const weeks = computed(() => { | ... | @@ -203,6 +204,9 @@ const weeks = computed(() => { |
| 203 | 204 | ||
| 204 | // 添加最后一行 | 205 | // 添加最后一行 |
| 205 | if (currentWeek.length > 0) { | 206 | if (currentWeek.length > 0) { |
| 207 | + while (currentWeek.length < 7) { | ||
| 208 | + currentWeek.push(''); | ||
| 209 | + } | ||
| 206 | result.push(currentWeek); | 210 | result.push(currentWeek); |
| 207 | } | 211 | } |
| 208 | 212 | ||
| ... | @@ -242,12 +246,14 @@ const QtyStatus = { | ... | @@ -242,12 +246,14 @@ const QtyStatus = { |
| 242 | } | 246 | } |
| 243 | 247 | ||
| 244 | const chooseDay = async (date) => { // 点击日期回调 | 248 | const chooseDay = async (date) => { // 点击日期回调 |
| 245 | - if (findDatesInfo(date).reserve_full === ReserveStatus.AVAILABLE || findDatesInfo(date).reserve_full === ReserveStatus.INFINITY) { // 状态 1可约 || -1不限制 | 249 | + if (!date) return; |
| 250 | + const info = findDatesInfo(date); | ||
| 251 | + if (info.reserve_full === ReserveStatus.AVAILABLE || info.reserve_full === ReserveStatus.INFINITY) { // 状态 1可约 || -1不限制 | ||
| 246 | checked_day.value = date; // 当前日期 | 252 | checked_day.value = date; // 当前日期 |
| 247 | - checked_day_reserve_full.value = findDatesInfo(date).reserve_full; // 当前状态 | 253 | + checked_day_reserve_full.value = info.reserve_full; // 当前状态 |
| 248 | - if (findDatesInfo(date).reserve_full === ReserveStatus.AVAILABLE) { | 254 | + if (info.reserve_full === ReserveStatus.AVAILABLE) { |
| 249 | // 选择日期后,查询时间段信息 | 255 | // 选择日期后,查询时间段信息 |
| 250 | - const { code, data } = await canReserveTimeListAPI({ month_date: checked_day.value}); | 256 | + const { code, data } = await canReserveTimeListAPI({ month_date: checked_day.value }); |
| 251 | if (code) { | 257 | if (code) { |
| 252 | // rest_qty >0表示有余量,可约;=0表示没有余量,不可约;<0表示不限,可约; | 258 | // rest_qty >0表示有余量,可约;=0表示没有余量,不可约;<0表示不限,可约; |
| 253 | timePeriod.value = data; | 259 | timePeriod.value = data; | ... | ... |
-
Please register or login to post a comment