功能:完善门店能力与用户安全配置

This commit is contained in:
xiaowang
2026-05-18 10:04:57 +08:00
parent 4563dd2538
commit 3797938616
356 changed files with 24983 additions and 1858 deletions
+174 -2
View File
@@ -31,7 +31,7 @@
<a-card
v-for="item in cartItems"
:key="item.id"
:ref="element => setItemRef(item.id, element)"
:ref="(element: unknown) => setItemRef(item.id, element)"
class="item-card"
:class="{ 'issue-card': item.selected && hasItemIssue(item) }"
>
@@ -150,6 +150,7 @@
>
<img v-if="artist.avatar" :src="artist.avatar" :alt="artist.name" />
<span>{{ artist.name }}</span>
<em v-if="artist.roleLabel">{{ artist.roleLabel }}</em>
</button>
</div>
<a-empty v-else description="暂无可预约美甲师" />
@@ -160,6 +161,7 @@
<a-date-picker
v-model:value="draftAppointmentTime"
class="time-picker"
popup-class-name="yumi-date-picker-panel yumi-date-time-panel"
style="width: 100%"
format="YYYY-MM-DD HH:mm:ss"
value-format="YYYY-MM-DD HH:mm:ss"
@@ -169,6 +171,19 @@
:show-time="{ minuteStep: 30, secondStep: 60, hideDisabledOptions: true }"
placeholder="请选择预约时间"
/>
<div class="quick-time-grid">
<button
v-for="slot in quickAppointmentSlots"
:key="slot.value"
type="button"
class="quick-time"
:class="{ active: draftAppointmentTime === slot.value }"
@click="draftAppointmentTime = slot.value"
>
<span>{{ slot.label }}</span>
<strong>{{ slot.time }}</strong>
</button>
</div>
<div class="helper">{{ bookingHelperText }}</div>
</div>
</a-modal>
@@ -176,6 +191,10 @@
</template>
<script setup lang="ts">
/**
* CartView page script.
* Call guide: the template binds the reactive state below, and the methods are triggered by button clicks, lifecycle hooks, or router events.
*/
import { computed, inject, onMounted, ref } from 'vue'
import { useRouter } from 'vue-router'
import { DeleteOutlined, LeftOutlined, RightOutlined } from '@ant-design/icons-vue'
@@ -198,6 +217,9 @@ interface ArtistOption {
id: IdType
name: string
avatar?: string
userType?: number
roleLabel?: string
participateProduction?: boolean
}
interface CartItem {
@@ -234,32 +256,73 @@ const imageIdCache = ref<Record<string, string>>({})
const itemRefs = ref<Record<string, HTMLElement>>({})
const availableCoupons = ref<UserCoupon[]>([])
const selectedCoupon = ref<UserCoupon | null>(null)
/** couponSelectionKey is a reactive state variable used by the template and event handlers. */
const couponSelectionKey = ref(NO_COUPON_KEY)
/** couponSelectionTouched is a reactive state variable used by the template and event handlers. */
const couponSelectionTouched = ref(false)
/** showCouponModal is a reactive state variable used by the template and event handlers. */
const showCouponModal = ref(false)
/** showBookingModal is a reactive state variable used by the template and event handlers. */
const showBookingModal = ref(false)
const currentItem = ref<CartItem | null>(null)
const availableArtists = ref<ArtistOption[]>([])
const draftArtistId = ref<IdType>()
/** draftAppointmentTime is a reactive state variable used by the template and event handlers. */
const draftAppointmentTime = ref('')
/** currentShopHours is a reactive state variable used by the template and event handlers. */
const currentShopHours = ref('')
/** editing is a reactive state variable used by the template and event handlers. */
const editing = ref(false)
/** submittingOrder is a reactive state variable used by the template and event handlers. */
const submittingOrder = ref(false)
/** selectedItems is a reactive state variable used by the template and event handlers. */
const selectedItems = computed(() => cartItems.value.filter(item => item.selected))
/** selectedCount is a reactive state variable used by the template and event handlers. */
const selectedCount = computed(() => selectedItems.value.length)
/** totalQuantity is a reactive state variable used by the template and event handlers. */
const totalQuantity = computed(() => selectedItems.value.reduce((sum, item) => sum + item.quantity, 0))
/** subtotal is a reactive state variable used by the template and event handlers. */
const subtotal = computed(() => selectedItems.value.reduce((sum, item) => sum + Number(item.price || 0) * item.quantity, 0))
/** discountAmount is a reactive state variable used by the template and event handlers. */
const discountAmount = computed(() => calculateCouponDiscount(selectedCoupon.value, subtotal.value))
/** totalAmount is a reactive state variable used by the template and event handlers. */
const totalAmount = computed(() => Math.max(0, subtotal.value - discountAmount.value))
/** bookingTitle is a reactive state variable used by the template and event handlers. */
const bookingTitle = computed(() => currentItem.value ? `为 ${currentItem.value.productTitle} 选择预约信息` : '选择预约信息')
/** bookingHelperText is a reactive state variable used by the template and event handlers. */
const bookingHelperText = computed(() => {
const texts: string[] = []
if (currentShopHours.value) texts.push(`门店营业时间:${currentShopHours.value}`)
if (currentItem.value?.approximateDuration) texts.push(`预计时长:${currentItem.value.approximateDuration}`)
return texts.join(' · ') || '请选择至少晚于当前 5 分钟的预约时间'
})
/** quickAppointmentSlots is a reactive state variable used by the template and event handlers. */
const quickAppointmentSlots = computed(() => {
const now = getMinAppointmentDate()
const today = new Date(now)
const nextHour = new Date(now)
nextHour.setMinutes(now.getMinutes() > 30 ? 0 : 30, 0, 0)
if (nextHour.getTime() < now.getTime()) {
nextHour.setHours(nextHour.getHours() + 1)
}
const tomorrowMorning = buildAppointmentDate(1, 10, 0)
const tomorrowAfternoon = buildAppointmentDate(1, 14, 0)
const afterTomorrowAfternoon = buildAppointmentDate(2, 15, 0)
const weekendMorning = nextWeekendMorning(today)
return [nextHour, tomorrowMorning, tomorrowAfternoon, afterTomorrowAfternoon, weekendMorning]
.filter((date, index, list) => date.getTime() >= now.getTime() && list.findIndex(item => item.getTime() === date.getTime()) === index)
.slice(0, 5)
.map(date => ({
value: formatAppointmentValue(date),
label: quickDateLabel(date),
time: `${String(date.getHours()).padStart(2, '0')}:${String(date.getMinutes()).padStart(2, '0')}`
}))
})
/** getMinAppointmentDate is a local helper used by this page script. */
const getMinAppointmentDate = () => {
const date = new Date()
date.setSeconds(0, 0)
@@ -267,14 +330,52 @@ const getMinAppointmentDate = () => {
return date
}
/** getDayBoundary is a local helper used by this page script. */
const getDayBoundary = (date: Date) => {
const boundary = new Date(date)
boundary.setHours(0, 0, 0, 0)
return boundary.getTime()
}
/** buildAppointmentDate is a local helper used by this page script. */
const buildAppointmentDate = (daysFromToday: number, hour: number, minute: number) => {
const date = new Date()
date.setDate(date.getDate() + daysFromToday)
date.setHours(hour, minute, 0, 0)
return date
}
/** nextWeekendMorning is a local helper used by this page script. */
const nextWeekendMorning = (fromDate: Date) => {
const date = new Date(fromDate)
const day = date.getDay()
const offset = day === 0 ? 6 : 6 - day
date.setDate(date.getDate() + Math.max(1, offset))
date.setHours(10, 0, 0, 0)
return date
}
/** formatAppointmentValue is a local helper used by this page script. */
const formatAppointmentValue = (date: Date) => {
/** pad is a local helper used by this page script. */
const pad = (value: number) => String(value).padStart(2, '0')
return `${date.getFullYear()}-${pad(date.getMonth() + 1)}-${pad(date.getDate())} ${pad(date.getHours())}:${pad(date.getMinutes())}:00`
}
/** quickDateLabel is a local helper used by this page script. */
const quickDateLabel = (date: Date) => {
const today = new Date()
const tomorrow = new Date()
tomorrow.setDate(tomorrow.getDate() + 1)
if (date.toDateString() === today.toDateString()) return '今天'
if (date.toDateString() === tomorrow.toDateString()) return '明天'
return `${date.getMonth() + 1}月${date.getDate()}日`
}
/** getCouponKey is a local helper used by this page script. */
const getCouponKey = (coupon: UserCoupon) => `${coupon.sourceType || 'USER_COUPON'}:${coupon.id}`
/** setItemRef is a local helper used by this page script. */
const setItemRef = (itemId: IdType, element: unknown) => {
const refKey = toOptionalIdString(itemId)
if (!refKey) {
@@ -291,6 +392,7 @@ const setItemRef = (itemId: IdType, element: unknown) => {
delete itemRefs.value[refKey]
}
/** formatCouponDisplay is a local helper used by this page script. */
const formatCouponDisplay = (coupon: UserCoupon) => {
const badge = coupon.sourceType === 'SYSTEM_VIP' ? '[VIP 自动券]' : '[用户券]'
const benefit = coupon.couponType === 1
@@ -299,6 +401,7 @@ const formatCouponDisplay = (coupon: UserCoupon) => {
return `${badge} ${coupon.couponName} ${benefit}`
}
/** calculateCouponDiscount is a local helper used by this page script. */
const calculateCouponDiscount = (coupon: UserCoupon | null, amount: number) => {
if (!coupon || amount <= 0) {
return 0
@@ -313,14 +416,18 @@ const calculateCouponDiscount = (coupon: UserCoupon | null, amount: number) => {
return 0
}
/** findBestCoupon is a local helper used by this page script. */
const findBestCoupon = (coupons: UserCoupon[]) => {
return coupons
.sort((left, right) => calculateCouponDiscount(right, subtotal.value) - calculateCouponDiscount(left, subtotal.value))[0] || null
}
/** formatAppointmentDisplay is a local helper used by this page script. */
const formatAppointmentDisplay = (value?: string) => value ? value.replace('T', ' ').slice(0, 16) : '未选择预约时间'
/** isPastAppointment is a local helper used by this page script. */
const isPastAppointment = (value?: string) => !!value && new Date(value.replace(' ', 'T')).getTime() < getMinAppointmentDate().getTime()
/** hasItemIssue is a local helper used by this page script. */
const hasItemIssue = (item: CartItem) => !item.artistId || !item.appointmentTime || isPastAppointment(item.appointmentTime)
// 购物车结算口径要求单店铺、单美甲师、完整预约信息,避免后端拆单和排班出现歧义。
@@ -363,6 +470,7 @@ const checkoutIssues = computed<CheckoutIssue[]>(() => {
return issues
})
/** scrollToIssue is a local helper used by this page script. */
const scrollToIssue = (issue?: CheckoutIssue) => {
const itemId = toOptionalIdString(issue?.itemId)
if (!itemId) {
@@ -374,10 +482,12 @@ const scrollToIssue = (issue?: CheckoutIssue) => {
}
}
/** focusFirstIssue is a local helper used by this page script. */
const focusFirstIssue = () => {
scrollToIssue(checkoutIssues.value[0])
}
/** loadCartItems is an async page action. Trigger it from the template or lifecycle hook, then await the result. */
const loadCartItems = async () => {
const response = await cartApi.getCartList() as unknown as any[]
cartItems.value = (response || []).map(item => ({
@@ -394,6 +504,7 @@ const loadCartItems = async () => {
await Promise.all([loadProductImages(), loadAvailableCoupons()])
}
/** loadProductImages is an async page action. Trigger it from the template or lifecycle hook, then await the result. */
const loadProductImages = async () => {
for (const item of cartItems.value) {
if (!item.originalProductImage) continue
@@ -411,6 +522,7 @@ const loadProductImages = async () => {
}
}
/** loadAvailableCoupons is an async page action. Trigger it from the template or lifecycle hook, then await the result. */
const loadAvailableCoupons = async () => {
if (editing.value) {
return
@@ -470,10 +582,12 @@ 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())
}
/** changeQuantity is an async page action. Trigger it from the template or lifecycle hook, then await the result. */
const changeQuantity = async (item: CartItem, delta: number) => {
const next = item.quantity + delta
if (next < 1 || next > 99) return
@@ -490,6 +604,7 @@ const changeQuantity = async (item: CartItem, delta: number) => {
}
}
/** removeItem is an async page action. Trigger it from the template or lifecycle hook, then await the result. */
const removeItem = async (item: CartItem) => {
try {
await runWithGlobalLoading(async () => {
@@ -504,6 +619,7 @@ const removeItem = async (item: CartItem) => {
}
}
/** removeSelectedItems is an async page action. Trigger it from the template or lifecycle hook, then await the result. */
const removeSelectedItems = async () => {
if (!selectedItems.value.length) {
message.warning('请先勾选要删除的作品')
@@ -523,10 +639,12 @@ const removeSelectedItems = async () => {
}
}
/** openProduct is a local helper used by this page script. */
const openProduct = (item: CartItem) => {
router.push('/product/' + item.productId)
}
/** openBookingModal is an async page action. Trigger it from the template or lifecycle hook, then await the result. */
const openBookingModal = async (item: CartItem) => {
currentItem.value = item
draftArtistId.value = item.artistId
@@ -535,6 +653,7 @@ const openBookingModal = async (item: CartItem) => {
await runWithGlobalLoading(() => Promise.all([loadArtists(item), loadShopHours(item.shopId)]))
}
/** 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)
@@ -543,7 +662,10 @@ const loadArtists = async (item: CartItem) => {
.map(artist => ({
id: artist.id,
name: artist.name,
avatar: artist.avatar
avatar: artist.avatar,
userType: artist.userType,
roleLabel: artist.roleLabel,
participateProduction: artist.participateProduction
}))
: []
@@ -552,6 +674,7 @@ const loadArtists = async (item: CartItem) => {
}
}
/** loadShopHours is an async page action. Trigger it from the template or lifecycle hook, then await the result. */
const loadShopHours = async (shopId?: IdType) => {
currentShopHours.value = ''
if (!shopId) return
@@ -563,11 +686,13 @@ const loadShopHours = async (shopId?: IdType) => {
}
}
/** disablePastAppointmentDate is a local helper used by this page script. */
const disablePastAppointmentDate = (current: any) => {
if (!current) return false
return current.valueOf() < getDayBoundary(new Date())
}
/** disablePastAppointmentTime is a local helper used by this page script. */
const disablePastAppointmentTime = (current: any) => {
if (!current || typeof current.format !== 'function') {
return {}
@@ -592,6 +717,7 @@ const disablePastAppointmentTime = (current: any) => {
}
}
/** closeBookingModal is a local helper used by this page script. */
const closeBookingModal = () => {
showBookingModal.value = false
currentItem.value = null
@@ -601,6 +727,7 @@ const closeBookingModal = () => {
currentShopHours.value = ''
}
/** confirmBooking is a local helper used by this page script. */
const confirmBooking = () => {
if (!currentItem.value) return closeBookingModal()
if (!draftArtistId.value) return message.warning('请先选择美甲师')
@@ -612,11 +739,13 @@ const confirmBooking = () => {
closeBookingModal()
}
/** openCouponModal is a local helper used by this page script. */
const openCouponModal = () => {
couponSelectionKey.value = selectedCoupon.value ? getCouponKey(selectedCoupon.value) : NO_COUPON_KEY
showCouponModal.value = true
}
/** applyCouponSelection is a local helper used by this page script. */
const applyCouponSelection = () => {
couponSelectionTouched.value = true
if (couponSelectionKey.value === NO_COUPON_KEY) {
@@ -627,6 +756,7 @@ const applyCouponSelection = () => {
showCouponModal.value = false
}
/** checkout is an async page action. Trigger it from the template or lifecycle hook, then await the result. */
const checkout = async () => {
if (submittingOrder.value) {
return
@@ -822,6 +952,42 @@ onMounted(async () => {
font-size: 12px;
}
.quick-time-grid {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(104px, 1fr));
gap: 8px;
margin: 10px 0;
}
.quick-time {
display: grid;
gap: 2px;
padding: 10px 12px;
border: 1px solid #e6ecf5;
border-radius: 8px;
background: #f8fbff;
color: #273142;
text-align: left;
cursor: pointer;
transition: border-color .18s ease, background .18s ease, transform .18s ease;
}
.quick-time:hover,
.quick-time.active {
border-color: #1677ff;
background: #eef6ff;
transform: translateY(-1px);
}
.quick-time span {
color: #7a8699;
font-size: 12px;
}
.quick-time strong {
font-size: 16px;
}
.actions,
.qty,
.coupon-row,
@@ -903,6 +1069,12 @@ onMounted(async () => {
object-fit: cover;
}
.artist-option em {
color: #8a6a34;
font-size: 12px;
font-style: normal;
}
@media (max-width: 767px) {
.content {
padding: 15px 15px 140px;