fix(app): 在确认手势内同步调起订阅,预约页首次进入定位到当前时段
微信要求授权框落在 tap 同步栈,先 await 会丢失弹层;订阅失败不再打断预约或支付。 Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -22,6 +22,8 @@
|
||||
<scroll-view
|
||||
class="slot-scroll"
|
||||
scroll-y
|
||||
:scroll-into-view="targetSlotId"
|
||||
scroll-with-animation
|
||||
refresher-enabled
|
||||
:refresher-triggered="refreshing"
|
||||
@refresherrefresh="onRefresh"
|
||||
@@ -52,14 +54,18 @@
|
||||
<text class="date-summary-text">{{ filteredSlots.length }} 个时段</text>
|
||||
</view>
|
||||
|
||||
<SlotCard
|
||||
<view
|
||||
v-for="item in filteredSlots"
|
||||
:id="`slot-${item.id}`"
|
||||
:key="item.id"
|
||||
:time-slot="item"
|
||||
@book="onBookTap"
|
||||
@cancel="onCancelTap"
|
||||
@card-tap="onSlotCardTap"
|
||||
/>
|
||||
>
|
||||
<SlotCard
|
||||
:time-slot="item"
|
||||
@book="onBookTap"
|
||||
@cancel="onCancelTap"
|
||||
@card-tap="onSlotCardTap"
|
||||
/>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<!-- Bottom padding spacer -->
|
||||
@@ -79,14 +85,14 @@
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { ref, computed, onMounted } from 'vue'
|
||||
import { ref, computed, onMounted, nextTick } from 'vue'
|
||||
import { onResize, onShareAppMessage, onShareTimeline } from '@dcloudio/uni-app'
|
||||
import type { TimeSlotWithBookingStatus, MembershipWithCardType } from '@mp-pilates/shared'
|
||||
import { BookingStatus, TIME_PERIODS } from '@mp-pilates/shared'
|
||||
import { useBookingStore } from '../../stores/booking'
|
||||
import { useUserStore } from '../../stores/user'
|
||||
import { getErrorMessage } from '../../utils/auth'
|
||||
import { formatDate } from '../../utils/format'
|
||||
import { formatDate, isSlotPast } from '../../utils/format'
|
||||
import { getSystemLayout } from '../../utils/system'
|
||||
import DateSelector from '../../components/DateSelector.vue'
|
||||
import TimePeriodFilter from '../../components/TimePeriodFilter.vue'
|
||||
@@ -105,6 +111,10 @@ const selectedPeriod = ref<PeriodKey>(null)
|
||||
const showConfirmPopup = ref(false)
|
||||
const pendingSlot = ref<TimeSlotWithBookingStatus | null>(null)
|
||||
const refreshing = ref(false)
|
||||
const targetSlotId = ref('')
|
||||
// 仅在「每次启动首次进入预约 TAB」时自动定位到当前时段及以后,
|
||||
// 切换日期/时段或下拉刷新后不再重置位置,避免打断用户的浏览位置。
|
||||
const hasAutoScrolled = ref(false)
|
||||
|
||||
// ─── 微信分享 ───────────────────────────────────────────────
|
||||
onShareAppMessage(() => {
|
||||
@@ -168,6 +178,34 @@ async function onRefresh() {
|
||||
refreshing.value = false
|
||||
}
|
||||
|
||||
// 首次进入时滚动到当天第一个未开始的课程("本时段及以后")
|
||||
async function scrollToUpcoming() {
|
||||
if (hasAutoScrolled.value) return
|
||||
|
||||
const slots = filteredSlots.value
|
||||
if (slots.length === 0) {
|
||||
// 列表还没出来(加载失败或当天无课),不要把「仅一次」用掉。
|
||||
return
|
||||
}
|
||||
|
||||
const upcoming = slots.find((slot) => !isSlotPast(slot.date, slot.startTime))
|
||||
if (!upcoming) {
|
||||
hasAutoScrolled.value = true
|
||||
return
|
||||
}
|
||||
|
||||
const dateWhenStarted = selectedDate.value
|
||||
const targetId = `slot-${upcoming.id}`
|
||||
await nextTick()
|
||||
if (hasAutoScrolled.value || selectedDate.value !== dateWhenStarted) return
|
||||
|
||||
hasAutoScrolled.value = true
|
||||
targetSlotId.value = ''
|
||||
await nextTick()
|
||||
if (selectedDate.value !== dateWhenStarted) return
|
||||
targetSlotId.value = targetId
|
||||
}
|
||||
|
||||
// ─── Event handlers ───────────────────────────────────────
|
||||
function onDateSelect(date: string) {
|
||||
selectedDate.value = date
|
||||
@@ -302,6 +340,8 @@ onMounted(async () => {
|
||||
}
|
||||
// Load today's slots
|
||||
await loadSlots(selectedDate.value)
|
||||
// 首次进入:自动定位到当天本时段及以后的第一个课程
|
||||
await scrollToUpcoming()
|
||||
})
|
||||
</script>
|
||||
|
||||
|
||||
@@ -357,7 +357,7 @@ import { get, post } from '../../utils/request'
|
||||
import { formatPrice, getCardCoverClass } from '../../utils/format'
|
||||
import { getSystemLayout } from '../../utils/system'
|
||||
import { useUserStore } from '../../stores/user'
|
||||
import { requestOrderPaidSubscriptionMessage } from '../../utils/wechat-subscription'
|
||||
import { requestBookingCreatedSubscriptionMessage } from '../../utils/wechat-subscription'
|
||||
import CustomNavBar from '../../components/CustomNavBar.vue'
|
||||
|
||||
interface MyOrderStatusResponse {
|
||||
@@ -888,9 +888,14 @@ async function doPurchase() {
|
||||
paymentRedirecting.value = false
|
||||
paymentConfirmationSession.value++
|
||||
pendingOrderId.value = ''
|
||||
uni.showLoading({ title: '创建订单...' })
|
||||
|
||||
try {
|
||||
// 必须在 tap 同步栈里调起订阅框;失败不打断支付。
|
||||
await requestBookingCreatedSubscriptionMessage().catch((error) => {
|
||||
console.warn('[subscribe] purchase pre-subscribe failed', error)
|
||||
})
|
||||
|
||||
uni.showLoading({ title: '创建订单...' })
|
||||
const result = await post<CreateOrderResponse>('/payment/create-order', {
|
||||
cardTypeId: card.value.id,
|
||||
})
|
||||
@@ -910,7 +915,6 @@ async function doPurchase() {
|
||||
})
|
||||
|
||||
pendingOrderId.value = result.order.id
|
||||
await requestOrderPaidSubscriptionMessage().catch(() => undefined)
|
||||
await settlePaidOrder(result.order.id)
|
||||
} catch (err: unknown) {
|
||||
uni.hideLoading()
|
||||
|
||||
Reference in New Issue
Block a user