提交开发分支未提交代码并修正配置

This commit is contained in:
2026-06-23 15:33:06 +08:00
parent a53b27ef20
commit 0fd96d150e
141 changed files with 3624 additions and 6048 deletions
+280 -39
View File
@@ -34,7 +34,7 @@
>
<a-checkbox class="product-check" v-model:checked="item.selected" @change="handleToggleSelect" />
<button type="button" class="product-thumb" @click="openProduct(item)">
<img v-if="item.productImage" :src="item.productImage" :alt="item.productTitle" loading="lazy" decoding="async" />
<img v-if="item.productImage" :src="item.productImage" :alt="item.productTitle" loading="lazy" decoding="async" @error="handleCartImageError(item)" />
<span v-else>{{ item.productTitle?.[0] || 'Y' }}</span>
</button>
@@ -92,10 +92,11 @@
<img
v-if="item.productImage"
:src="item.productImage"
:alt="item.productTitle"
loading="lazy"
decoding="async"
/>
:alt="item.productTitle"
loading="lazy"
decoding="async"
@error="handleCartImageError(item)"
/>
<span v-else>{{ item.productTitle?.[0] || 'Y' }}</span>
</div>
<div class="service-copy">
@@ -107,11 +108,11 @@
<RightOutlined />
</button>
<div v-if="item.availableArtists?.length" class="service-artist-strip">
<div v-if="getDisplayArtists(item).length" class="service-artist-strip">
<span class="service-label">选择美甲师</span>
<div class="service-artist-list">
<button
v-for="artist in item.availableArtists"
v-for="artist in getDisplayArtists(item)"
:key="artist.id"
type="button"
class="service-artist-option"
@@ -132,7 +133,7 @@
</div>
<div class="service-time-grid">
<button
v-for="slot in getQuickAppointmentSlots(item)"
v-for="slot in getDisplayQuickAppointmentSlots(item)"
:key="`${item.id}-${slot.value}`"
type="button"
class="service-time-option"
@@ -234,14 +235,14 @@
<a-modal v-model:open="showBookingModal" :title="bookingTitle" @ok="confirmBooking" @cancel="closeBookingModal">
<div class="modal-section">
<div class="section-title">美甲师</div>
<div v-if="availableArtists.length" class="artist-list">
<div v-if="getDraftDisplayArtists().length" class="artist-list">
<button
v-for="artist in availableArtists"
v-for="artist in getDraftDisplayArtists()"
:key="artist.id"
type="button"
class="artist-option"
:class="{ active: sameId(draftArtistId, artist.id) }"
@click="draftArtistId = artist.id"
@click="selectDraftArtist(artist)"
>
<img v-if="artist.avatar" :src="artist.avatar" :alt="artist.name" loading="lazy" decoding="async" />
<span>{{ artist.name }}</span>
@@ -273,7 +274,7 @@
type="button"
class="quick-time"
:class="{ active: draftAppointmentTime === slot.value }"
@click="draftAppointmentTime = slot.value"
@click="selectDraftAppointmentTime(slot.value)"
>
<span>{{ slot.label }}</span>
<strong>{{ slot.time }}</strong>
@@ -313,7 +314,9 @@ import { sameId, toOptionalIdString } from '@/utils/id'
import { runWithGlobalLoading } from '@/utils/action-loading'
import { getBuyNowProductIdFromQuery, isBuyNowCartItem } from '@/utils/buy-now'
import { buildRecoveryActions, getRecoveryMessage } from '@/utils/recovery'
import { extractLegacyFileId, getCachedSignedImageUrl, getCachedSignedImageUrlSync } from '@/utils/signed-image-cache'
import { extractLegacyFileId } from '@/utils/signed-image-cache'
import { normalizeApiErrorMessage } from '@/api/error'
import { refreshPublicImageUrl, resolvePublicImageUrl, resolvePublicImageUrlsSync } from '@/utils/public-image-assets'
/**
* Purpose: router supports CartView.vue by holding or executing the router page or API role.
@@ -397,6 +400,19 @@ interface CheckoutIssue {
productTitle?: string
}
interface AppointmentSlotOption {
value: string
label: string
time: string
}
interface BookableOptionState {
loading: boolean
artists: ArtistOption[]
slots: AppointmentSlotOption[]
validKeys: Set<string>
}
/**
* Purpose: cartItems supports CartView.vue by holding or executing the cart items page or API role.
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
@@ -452,6 +468,7 @@ const currentShopHours = ref('')
const shopHoursById = ref<Record<string, string>>({})
/** submittingOrder is a reactive state variable used by the template and event handlers. */
const submittingOrder = ref(false)
const bookableOptionsByItemId = ref<Record<string, BookableOptionState>>({})
/** buyNowProductId limits checkout selection to the product that opened cart from "立即预约". */
const buyNowProductId = computed(() => getBuyNowProductIdFromQuery(route.query))
/** isBuyNowMode switches cart copy into a focused order-confirmation experience. */
@@ -501,12 +518,80 @@ const bookingHelperText = computed(() => {
/** quickAppointmentSlots is a reactive state variable used by the template and event handlers. */
const quickAppointmentSlots = computed(() => {
if (currentItem.value) {
return getQuickAppointmentSlots(currentItem.value)
return getDisplayQuickAppointmentSlotsForArtist(currentItem.value, draftArtistId.value)
}
return buildQuickAppointmentSlots()
})
const getItemKey = (item: CartItem) => toOptionalIdString(item.id) || toOptionalIdString(item.productId) || ''
const getBookableKey = (artistId: IdType, appointmentTime: string) => {
return `${toOptionalIdString(artistId) || ''}|${appointmentTime}`
}
const normalizeArtists = (item: CartItem): ArtistOption[] => {
return Array.isArray(item.availableArtists)
? (item.availableArtists || [])
.filter(artist => artist && artist.id !== undefined && artist.id !== null)
.map(artist => ({
id: artist.id,
name: artist.name,
avatar: artist.avatar,
userType: artist.userType,
roleLabel: artist.roleLabel,
participateProduction: artist.participateProduction
}))
: []
}
const getBookableOptionState = (item: CartItem): BookableOptionState | null => {
const itemKey = getItemKey(item)
return itemKey ? bookableOptionsByItemId.value[itemKey] || null : null
}
const getDisplayArtists = (item: CartItem) => {
const state = getBookableOptionState(item)
return state ? state.artists : normalizeArtists(item)
}
const getDisplayQuickAppointmentSlots = (item: CartItem) => {
const state = getBookableOptionState(item)
return state ? state.slots : getQuickAppointmentSlots(item)
}
const getDisplayQuickAppointmentSlotsForArtist = (item: CartItem, artistId?: IdType) => {
const state = getBookableOptionState(item)
if (!state || !artistId) {
return getDisplayQuickAppointmentSlots(item)
}
return state.slots.filter(slot => state.validKeys.has(getBookableKey(artistId, slot.value)))
}
const getDraftDisplayArtists = () => {
if (!currentItem.value || !draftAppointmentTime.value) {
return availableArtists.value
}
const state = getBookableOptionState(currentItem.value)
if (!state) {
return availableArtists.value
}
return availableArtists.value.filter(artist =>
state.validKeys.has(getBookableKey(artist.id, draftAppointmentTime.value))
)
}
const hasBookableCombination = (item: CartItem, artistId?: IdType, appointmentTime?: string) => {
if (!artistId || !appointmentTime) {
return false
}
const state = getBookableOptionState(item)
if (!state) {
return true
}
return state.validKeys.has(getBookableKey(artistId, appointmentTime))
}
const buildQuickAppointmentSlots = (item?: CartItem) => {
const now = getMinAppointmentDate()
const today = new Date(now)
@@ -537,6 +622,94 @@ const buildQuickAppointmentSlots = (item?: CartItem) => {
const getQuickAppointmentSlots = (item: CartItem) => buildQuickAppointmentSlots(item)
const isCheckoutPreviewBookable = (preview: CheckoutPreview) => {
return preview.bookingAvailable !== false && !(preview.bookingIssues || []).length
}
const checkBookableCombination = async (item: CartItem, artist: ArtistOption, slot: AppointmentSlotOption) => {
try {
const preview = await orderApi.checkoutPreview({
items: [{
productId: item.productId,
quantity: item.quantity,
artistId: artist.id,
appointmentTime: slot.value
}]
})
return isCheckoutPreviewBookable(preview)
} catch {
return false
}
}
const refreshBookableOptions = async (item: CartItem) => {
const itemKey = getItemKey(item)
if (!itemKey) {
return
}
const artists = normalizeArtists(item)
const slots = getQuickAppointmentSlots(item)
bookableOptionsByItemId.value = {
...bookableOptionsByItemId.value,
[itemKey]: { loading: true, artists: [], slots: [], validKeys: new Set<string>() }
}
const checks = await Promise.all(artists.flatMap(artist =>
slots.map(async slot => ({
artist,
slot,
valid: await checkBookableCombination(item, artist, slot)
}))
))
const validKeys = new Set(
checks
.filter(check => check.valid)
.map(check => getBookableKey(check.artist.id, check.slot.value))
)
const validArtists = artists.filter(artist =>
slots.some(slot => validKeys.has(getBookableKey(artist.id, slot.value)))
)
const validSlots = slots.filter(slot =>
artists.some(artist => validKeys.has(getBookableKey(artist.id, slot.value)))
)
bookableOptionsByItemId.value = {
...bookableOptionsByItemId.value,
[itemKey]: { loading: false, artists: validArtists, slots: validSlots, validKeys }
}
if (item.artistId && !validArtists.some(artist => sameId(artist.id, item.artistId))) {
item.artistId = undefined
item.artist = undefined
}
if (item.appointmentTime && !validSlots.some(slot => slot.value === item.appointmentTime)) {
item.appointmentTime = ''
}
}
const refreshSelectedBookableOptions = async () => {
await Promise.all(selectedItems.value.map(item => refreshBookableOptions(item)))
}
const findFirstSlotForArtist = (item: CartItem, artistId: IdType) => {
const state = getBookableOptionState(item)
return state?.slots.find(slot => state.validKeys.has(getBookableKey(artistId, slot.value)))
}
const findFirstArtistForSlot = (item: CartItem, appointmentTime: string) => {
const state = getBookableOptionState(item)
return state?.artists.find(artist => state.validKeys.has(getBookableKey(artist.id, appointmentTime)))
}
const findInvalidBookableCombination = () => {
return selectedItems.value.find(item =>
item.artistId
&& item.appointmentTime
&& !hasBookableCombination(item, item.artistId, item.appointmentTime)
)
}
/** getMinAppointmentDate is a local helper used by this page script. */
const getMinAppointmentDate = () => {
const date = new Date()
@@ -730,7 +903,7 @@ const mapApiCheckoutIssue = (issue: ApiCheckoutIssue): CheckoutIssue | null => {
return {
key: `server-${issue.code || issue.message}`,
message: issue.message,
message: normalizeApiErrorMessage(issue.message),
itemId: matchedItem?.id || issue.itemId,
productId: issue.productId,
productTitle: issue.productTitle || matchedItem?.productTitle
@@ -816,9 +989,10 @@ const isDisplayableImageSource = (value?: string | null) => {
const getInitialCartImage = (rawImage?: string, previousImage?: string) => {
const imageId = extractLegacyFileId(rawImage)
const cachedUrl = imageId ? getCachedSignedImageUrlSync(imageId) : ''
const cachedUrl = imageId ? resolvePublicImageUrlsSync({ imageFileIds: imageId }, '')[0] : ''
if (cachedUrl) return cachedUrl
if (previousImage) return previousImage
if (imageId) return ''
return isDisplayableImageSource(rawImage) ? String(rawImage) : ''
}
@@ -846,6 +1020,7 @@ const loadCartItems = async () => {
couponSelectionKey.value = NO_COUPON_KEY
selectedCoupon.value = null
await Promise.all([loadProductImages(), loadCartItemShopHours()])
await refreshSelectedBookableOptions()
await loadAvailableCoupons()
} finally {
cartLoading.value = false
@@ -866,13 +1041,18 @@ const loadProductImages = async () => {
}
continue
}
const cachedUrl = getCachedSignedImageUrlSync(imageId)
const cachedUrl = resolvePublicImageUrlsSync({ imageFileIds: imageId }, '')[0]
if (cachedUrl) item.productImage = cachedUrl
const signedUrl = await getCachedSignedImageUrl(imageId, item.productImage || item.originalProductImage)
const signedUrl = await resolvePublicImageUrl({ imageFileIds: imageId }, item.productImage || '')
if (signedUrl) item.productImage = signedUrl
}
}
const handleCartImageError = async (item: CartItem) => {
const imageId = extractLegacyFileId(item.originalProductImage)
item.productImage = imageId ? await refreshPublicImageUrl(imageId, '') : ''
}
const loadCartItemShopHours = async () => {
const shopIds = Array.from(new Set(
cartItems.value
@@ -963,7 +1143,10 @@ const loadAvailableCoupons = async () => {
/** handleToggleSelect is an async page action. Trigger it from the template or lifecycle hook, then await the result. */
const handleToggleSelect = async () => {
await runWithGlobalLoading(() => loadAvailableCoupons())
await runWithGlobalLoading(async () => {
await refreshSelectedBookableOptions()
await loadAvailableCoupons()
})
}
/** changeQuantity is an async page action. Trigger it from the template or lifecycle hook, then await the result. */
@@ -974,6 +1157,7 @@ const changeQuantity = async (item: CartItem, delta: number) => {
try {
await runWithGlobalLoading(async () => {
await cartApi.updateCartQuantity({ productId: item.productId, quantity: next })
await refreshBookableOptions(item)
await loadAvailableCoupons()
})
await updateCartCount()
@@ -1007,12 +1191,20 @@ const openProduct = (item: CartItem) => {
const selectInlineArtist = async (item: CartItem, artist: ArtistOption) => {
item.artistId = artist.id
item.artist = artist
if (!hasBookableCombination(item, artist.id, item.appointmentTime)) {
item.appointmentTime = findFirstSlotForArtist(item, artist.id)?.value || ''
}
await runWithGlobalLoading(() => loadAvailableCoupons())
}
/** selectInlineTime updates a cart item's appointment slot from the page-level service detail controls. */
const selectInlineTime = async (item: CartItem, appointmentTime: string) => {
item.appointmentTime = appointmentTime
if (!hasBookableCombination(item, item.artistId, appointmentTime)) {
const artist = findFirstArtistForSlot(item, appointmentTime)
item.artistId = artist?.id
item.artist = artist
}
await runWithGlobalLoading(() => loadAvailableCoupons())
}
@@ -1022,28 +1214,21 @@ const openBookingModal = async (item: CartItem) => {
draftArtistId.value = item.artistId
draftAppointmentTime.value = item.appointmentTime || ''
showBookingModal.value = true
await runWithGlobalLoading(() => Promise.all([loadArtists(item), loadShopHours(item.shopId)]))
await runWithGlobalLoading(async () => {
await Promise.all([refreshBookableOptions(item), loadShopHours(item.shopId)])
await loadArtists(item)
})
}
/** loadArtists is an async page action. Trigger it from the template or lifecycle hook, then await the result. */
const loadArtists = async (item: CartItem) => {
// 购物车里保存的是后端已经按作品可约范围裁剪过的美甲师列表,这里只做前端展示和 ID 保真。
availableArtists.value = Array.isArray(item.availableArtists)
? item.availableArtists
.filter(artist => artist && artist.id !== undefined && artist.id !== null)
.map(artist => ({
id: artist.id,
name: artist.name,
avatar: artist.avatar,
userType: artist.userType,
roleLabel: artist.roleLabel,
participateProduction: artist.participateProduction
}))
: []
availableArtists.value = getDisplayArtists(item)
if (draftArtistId.value && !availableArtists.value.some(artist => sameId(artist.id, draftArtistId.value))) {
draftArtistId.value = undefined
}
if (draftAppointmentTime.value && !hasBookableCombination(item, draftArtistId.value, draftAppointmentTime.value)) {
draftAppointmentTime.value = ''
}
}
/** loadShopHours is an async page action. Trigger it from the template or lifecycle hook, then await the result. */
@@ -1097,6 +1282,26 @@ const disablePastAppointmentTime = (current: any) => {
}
}
const selectDraftArtist = (artist: ArtistOption) => {
if (!currentItem.value) {
return
}
draftArtistId.value = artist.id
if (!hasBookableCombination(currentItem.value, artist.id, draftAppointmentTime.value)) {
draftAppointmentTime.value = findFirstSlotForArtist(currentItem.value, artist.id)?.value || ''
}
}
const selectDraftAppointmentTime = (appointmentTime: string) => {
if (!currentItem.value) {
return
}
draftAppointmentTime.value = appointmentTime
if (!hasBookableCombination(currentItem.value, draftArtistId.value, appointmentTime)) {
draftArtistId.value = findFirstArtistForSlot(currentItem.value, appointmentTime)?.id
}
}
/** closeBookingModal is a local helper used by this page script. */
const closeBookingModal = () => {
showBookingModal.value = false
@@ -1113,6 +1318,9 @@ const confirmBooking = async () => {
if (!draftArtistId.value) return message.warning('请先选择美甲师')
if (!draftAppointmentTime.value) return message.warning('请选择预约时间')
if (isPastAppointment(draftAppointmentTime.value)) return message.warning('预约时间至少需要晚于当前 5 分钟')
if (!hasBookableCombination(currentItem.value, draftArtistId.value, draftAppointmentTime.value)) {
return message.warning('请选择可预约的美甲师和时间')
}
currentItem.value.artistId = draftArtistId.value
currentItem.value.artist = availableArtists.value.find(artist => sameId(artist.id, draftArtistId.value))
currentItem.value.appointmentTime = draftAppointmentTime.value
@@ -1138,20 +1346,36 @@ const applyCouponSelection = async () => {
await runWithGlobalLoading(() => loadAvailableCoupons())
}
let checkoutRecoveryModal: { destroy: () => void } | null = null
const openCheckoutRecovery = (error: unknown) => {
checkoutRecoveryModal?.destroy()
checkoutRecoveryModal = null
const recoveryMessage = error instanceof Error
? normalizeApiErrorMessage(error.message)
: normalizeApiErrorMessage(getRecoveryMessage(error, '询价预约发起失败'))
const actions = buildRecoveryActions([
{ key: 'retry', text: '重试发起询价' },
{ key: 'orders', text: '查看订单' }
])
const retryAction = actions[0]
const ordersAction = actions[1]
Modal.confirm({
checkoutRecoveryModal = Modal.confirm({
title: '发起询价预约失败',
content: `${getRecoveryMessage(error, '询价预约发起失败')}。如果担心重复提交,请先查看订单;仍失败时请联系客服。`,
content: `${recoveryMessage}。如担心重复提交,请先查看订单;仍失败时请联系管理员。`,
closable: true,
okText: retryAction?.text || '重试发起询价',
cancelText: ordersAction?.text || '查看订单',
onOk: () => checkout(),
onCancel: () => router.push(ordersAction?.route || '/orders')
onOk: () => {
checkoutRecoveryModal?.destroy()
checkoutRecoveryModal = null
void checkout()
},
onCancel: () => {
checkoutRecoveryModal?.destroy()
checkoutRecoveryModal = null
void router.push(ordersAction?.route || '/orders')
}
})
}
@@ -1172,6 +1396,18 @@ const checkout = async () => {
return message.warning('请先选择要结算的作品')
}
await runWithGlobalLoading(async () => {
await refreshSelectedBookableOptions()
await loadAvailableCoupons()
})
const invalidCombination = findInvalidBookableCombination()
if (invalidCombination) {
message.warning(`"${invalidCombination.productTitle}" 当前美甲师和预约时间不可预约,请重新选择`)
scrollToIssue({ key: 'bookable-combination', message: '请选择可预约的美甲师和时间', itemId: invalidCombination.id })
return
}
const firstIssue = checkoutIssues.value[0]
if (firstIssue) {
message.warning(firstIssue.message)
@@ -1214,7 +1450,12 @@ const checkout = async () => {
}
}
} catch (error: any) {
console.error('创建订单失败:', error)
const checkoutErrorMessage = normalizeApiErrorMessage(error instanceof Error ? error.message : getRecoveryMessage(error, '询价预约发起失败'))
if (checkoutErrorMessage.includes('不可预约')) {
console.warn('询价预约被业务规则拦截:', checkoutErrorMessage)
} else {
console.error('创建订单失败:', error)
}
openCheckoutRecovery(error)
} finally {
submittingOrder.value = false