From 861eea933bab340d7600990c59007334fe068971 Mon Sep 17 00:00:00 2001 From: xiaowang Date: Sat, 23 May 2026 21:56:18 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8A=9F=E8=83=BD=EF=BC=88=E7=BD=91=E9=A1=B5?= =?UTF-8?q?=EF=BC=89=EF=BC=9A=E6=96=B0=E5=A2=9E=E5=AE=A2=E6=88=B7=E4=BD=93?= =?UTF-8?q?=E9=AA=8C=E6=B5=81=E7=A8=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- YumiNail-Frontend/src/api/admin.ts | 10 +- YumiNail-Frontend/src/api/auth-free-paths.ts | 3 + YumiNail-Frontend/src/api/nail-artist.ts | 69 +++ YumiNail-Frontend/src/api/order.ts | 66 ++- YumiNail-Frontend/src/api/product.ts | 8 + YumiNail-Frontend/src/api/shop.ts | 54 ++ YumiNail-Frontend/src/api/tag.ts | 27 + YumiNail-Frontend/src/api/wishlist.ts | 65 +++ YumiNail-Frontend/src/router/index.ts | 6 + YumiNail-Frontend/src/utils/buy-now.test.ts | 19 + YumiNail-Frontend/src/utils/buy-now.ts | 15 + .../src/utils/order-review-focus.test.ts | 89 +++ .../src/utils/order-review-focus.ts | 120 ++++ YumiNail-Frontend/src/utils/recovery.test.ts | 25 + YumiNail-Frontend/src/utils/recovery.ts | 43 ++ .../src/utils/system-message-action.test.ts | 38 ++ .../src/utils/system-message-action.ts | 72 +++ .../src/views/ArtistProfileView.vue | 552 ++++++++++++++++++ YumiNail-Frontend/src/views/CartView.vue | 205 +++++-- .../src/views/NotificationsView.vue | 9 +- YumiNail-Frontend/src/views/OrderView.vue | 280 ++++++++- .../src/views/ProductDetailView.vue | 25 +- .../src/views/ProductListView.vue | 100 +++- YumiNail-Frontend/src/views/ProfileView.vue | 40 +- .../src/views/ShopDetailView.vue | 203 ++++++- YumiNail-Frontend/src/views/WishlistView.vue | 89 ++- .../src/views/admin/ProductsView.vue | 44 ++ .../src/views/admin/TagsView.vue | 68 ++- 28 files changed, 2236 insertions(+), 108 deletions(-) create mode 100644 YumiNail-Frontend/src/api/nail-artist.ts create mode 100644 YumiNail-Frontend/src/utils/buy-now.test.ts create mode 100644 YumiNail-Frontend/src/utils/buy-now.ts create mode 100644 YumiNail-Frontend/src/utils/order-review-focus.test.ts create mode 100644 YumiNail-Frontend/src/utils/order-review-focus.ts create mode 100644 YumiNail-Frontend/src/utils/recovery.test.ts create mode 100644 YumiNail-Frontend/src/utils/recovery.ts create mode 100644 YumiNail-Frontend/src/utils/system-message-action.test.ts create mode 100644 YumiNail-Frontend/src/utils/system-message-action.ts create mode 100644 YumiNail-Frontend/src/views/ArtistProfileView.vue diff --git a/YumiNail-Frontend/src/api/admin.ts b/YumiNail-Frontend/src/api/admin.ts index 3858ad02..6262180a 100644 --- a/YumiNail-Frontend/src/api/admin.ts +++ b/YumiNail-Frontend/src/api/admin.ts @@ -491,6 +491,10 @@ export interface Tag { textColor?: string bgColor?: string borderColor?: string + sceneGroup?: string + displayName?: string + sortOrder?: number + frontVisible?: number shopId?: IdType shopName?: string type?: number @@ -524,7 +528,7 @@ export const adminTagApi = { * Call guide: supply the parameters below, await the returned Promise, and handle loading / error UI in the caller. * @param data: { tagName: string; textColor?: string; bgColor?: string; borderColor?: string; shopId?: IdType } caller-supplied value for `data: { tagName: string; textColor?: string; bgColor?: string; borderColor?: string; shopId?: IdType }` */ - createTag: (data: { tagName: string; textColor?: string; bgColor?: string; borderColor?: string; shopId?: IdType }) => { + createTag: (data: { tagName: string; textColor?: string; bgColor?: string; borderColor?: string; sceneGroup?: string; displayName?: string; sortOrder?: number; frontVisible?: number; shopId?: IdType }) => { return adminApi.post('/tag/create', data) }, /** @@ -533,7 +537,7 @@ export const adminTagApi = { * @param id: IdType caller-supplied value for `id: IdType` * @param data: { tagName: string; textColor?: string; bgColor?: string; borderColor?: string; shopId?: IdType } caller-supplied value for `data: { tagName: string; textColor?: string; bgColor?: string; borderColor?: string; shopId?: IdType }` */ - updateTag: (id: IdType, data: { tagName: string; textColor?: string; bgColor?: string; borderColor?: string; shopId?: IdType }) => { + updateTag: (id: IdType, data: { tagName: string; textColor?: string; bgColor?: string; borderColor?: string; sceneGroup?: string; displayName?: string; sortOrder?: number; frontVisible?: number; shopId?: IdType }) => { return adminApi.put(`/tag/update/${id}`, data) }, /** @@ -711,6 +715,8 @@ export interface Product { shopName?: string title: string description: string + targetAudience?: string + precautions?: string price: number approximateDuration?: string tags?: string diff --git a/YumiNail-Frontend/src/api/auth-free-paths.ts b/YumiNail-Frontend/src/api/auth-free-paths.ts index 36b2ddf9..678b1b19 100644 --- a/YumiNail-Frontend/src/api/auth-free-paths.ts +++ b/YumiNail-Frontend/src/api/auth-free-paths.ts @@ -16,10 +16,13 @@ export const WEB_API_AUTH_FREE_PATHS = [ '/product/get/', '/product/list/', '/comment/list/product/', + '/nail-artist/', '/shop/get/', + '/shop/trust-profile/', '/shop/list/public', '/shop/list/simple', '/tag/list/all', + '/tag/list/filter-options', '/file/get-signed-url/', '/admin/auth/login', '/admin/auth/login-shops/', diff --git a/YumiNail-Frontend/src/api/nail-artist.ts b/YumiNail-Frontend/src/api/nail-artist.ts new file mode 100644 index 00000000..633248fe --- /dev/null +++ b/YumiNail-Frontend/src/api/nail-artist.ts @@ -0,0 +1,69 @@ +import api from './index' +import type { IdType } from '@/utils/id' + +export interface NailArtistAvailabilityVO { + startTime: string + endTime: string + dateText: string + timeText: string + available: boolean +} + +export interface NailArtistWorkVO { + id: IdType + title?: string + description?: string + price?: number | string + coverImageUrl?: string + imageUrls?: string[] + tags?: string[] + likeCount?: number + collectCount?: number +} + +export interface NailArtistReviewVO { + id: IdType + artistId: IdType + customerId?: IdType + customerName?: string + customerAvatar?: string + productId?: IdType + productTitle?: string + rating?: number | string + content?: string + imageFileIds?: IdType[] + imageUrls?: string[] + submittedAt?: string +} + +export interface NailArtistProfileVO { + artistId: IdType + artistName?: string + avatar?: string + identity?: string + signature?: string + experience?: number + status?: number + shopId?: IdType + shopName?: string + rating?: number | string + serviceCount?: number | string + workStartTime?: string + workEndTime?: string + styleTags?: string[] + works?: NailArtistWorkVO[] + reviews?: NailArtistReviewVO[] + availability?: NailArtistAvailabilityVO[] +} + +export const nailArtistApi = { + getPublicProfile: async (artistId: IdType): Promise => { + return await api.get(`/nail-artist/profile/${artistId}`) as unknown as NailArtistProfileVO + }, + getAvailability: async (artistId: IdType): Promise => { + return await api.get(`/nail-artist/${artistId}/availability`) as unknown as NailArtistAvailabilityVO[] + }, + listReviews: async (artistId: IdType): Promise => { + return await api.get(`/nail-artist/${artistId}/reviews`) as unknown as NailArtistReviewVO[] + } +} diff --git a/YumiNail-Frontend/src/api/order.ts b/YumiNail-Frontend/src/api/order.ts index 99cf4a10..afb44f81 100644 --- a/YumiNail-Frontend/src/api/order.ts +++ b/YumiNail-Frontend/src/api/order.ts @@ -9,7 +9,7 @@ import type { IdType } from '@/utils/id' * Purpose: OrderItem supports order.ts by holding or executing the order item page or API role. * Usage: import, call, read, or update this interface from the owning page/module while preserving the surrounding loading and permission flow. */ -interface OrderItem { +export interface OrderItem { productId: IdType quantity: number artistId?: IdType @@ -20,12 +20,47 @@ interface OrderItem { * Purpose: CreateOrderRequest supports order.ts by holding or executing the create order request page or API role. * Usage: import, call, read, or update this interface from the owning page/module while preserving the surrounding loading and permission flow. */ -interface CreateOrderRequest { +export interface CreateOrderRequest { couponId?: IdType couponSourceType?: string items: OrderItem[] } +export type CheckoutPreviewRequest = CreateOrderRequest + +export interface CheckoutCouponPreview { + id: IdType + couponId?: IdType + userCouponId?: IdType + sourceType?: string + couponName: string + couponType: number + couponTypeName?: string + discountValue?: number + minAmount?: number + reduceAmount?: number + discountAmount?: number + available?: boolean + best?: boolean + vipAuto?: boolean + displayText?: string + savingText?: string + unavailableReason?: string + startTime?: string + endTime?: string +} + +export interface CheckoutPreview { + subtotalAmount: number + savedAmount: number + payableAmount: number + bestCoupon?: CheckoutCouponPreview + availableCoupons: CheckoutCouponPreview[] + unavailableCoupons: CheckoutCouponPreview[] + vipTip?: string + summaryText?: string +} + /** * Purpose: ArtistCalendarAppointment supports order.ts by holding or executing the artist calendar appointment page or API role. * Usage: import, call, read, or update this interface from the owning page/module while preserving the surrounding loading and permission flow. @@ -72,6 +107,7 @@ export interface OrderArtistReviewVO { status?: number statusText?: string submitTime?: string + reviewTime?: string createTime?: string } @@ -115,16 +151,34 @@ export interface OrderArtistChangeRequestVO { productTitle?: string shopId?: IdType userId?: IdType + customerId?: IdType originalArtistId?: IdType originalArtistName?: string requestedArtistId?: IdType requestedArtistName?: string + fromArtistId?: IdType + fromArtistName?: string + toArtistId?: IdType + toArtistName?: string + requesterId?: IdType + requesterName?: string status?: string statusText?: string reason?: string rejectReason?: string + appointmentTime?: string + timeAffected?: boolean + timeImpactText?: string + originalPrice?: number | string + newPrice?: number | string + priceAffected?: boolean + priceImpactText?: string reviewerId?: IdType + messageId?: IdType reviewTime?: string + approvedTime?: string + rejectedTime?: string + expireTime?: string createTime?: string } @@ -161,6 +215,10 @@ export const orderApi = { createOrder: (data: CreateOrderRequest) => { return api.post('/order/create', data) }, + + checkoutPreview: async (data: CheckoutPreviewRequest): Promise => { + return await api.post('/order/checkout-preview', data) as unknown as CheckoutPreview + }, // 获取订单列表 getOrderList: async (): Promise => { @@ -193,6 +251,10 @@ export const orderApi = { return await api.get('/order/artist-change/my-pending') as unknown as OrderArtistChangeRequestVO[] }, + getOrderArtistChangeRequests: async (orderId: IdType): Promise => { + return await api.get(`/order/${orderId}/artist-change/requests`) as unknown as OrderArtistChangeRequestVO[] + }, + approveArtistChange: async (requestId: IdType): Promise => { return await api.put(`/order/artist-change/${requestId}/approve`) as unknown as OrderArtistChangeRequestVO }, diff --git a/YumiNail-Frontend/src/api/product.ts b/YumiNail-Frontend/src/api/product.ts index b53d12b4..1deca5d6 100644 --- a/YumiNail-Frontend/src/api/product.ts +++ b/YumiNail-Frontend/src/api/product.ts @@ -16,6 +16,8 @@ export interface ProductVO { name: string title?: string description: string + targetAudience?: string + precautions?: string image: string imageFileIds?: string imageUrls?: string[] @@ -57,6 +59,8 @@ export interface ListProductsParams { page: number size: number keyword?: string + tag?: string + tagIds?: string } /** @@ -120,5 +124,9 @@ export const productApi = { keyword: keyword } }) as unknown as ProductVO[] + }, + + getProductPage: async (params: ListProductsParams): Promise<{ list: ProductVO[]; total: number; page: number; size: number }> => { + return await api.get('/product/list/page', { params }) as unknown as { list: ProductVO[]; total: number; page: number; size: number } } } diff --git a/YumiNail-Frontend/src/api/shop.ts b/YumiNail-Frontend/src/api/shop.ts index 39c1f6e7..0dfdba49 100644 --- a/YumiNail-Frontend/src/api/shop.ts +++ b/YumiNail-Frontend/src/api/shop.ts @@ -49,6 +49,56 @@ export interface ShopSimpleVO { name?: string } +/** + * Purpose: ShopTrustProfileVO carries public trust signals for a shop detail page. + * Usage: fetch it with getTrustProfile and render ratings, recent reviews, environment images, and booking hints. + */ +export interface ShopTrustProfileVO { + shopId: IdType + shopName?: string + businessHoursText?: string + businessStatusText?: string + locationAvailable?: boolean + distanceCapabilityText?: string + navigationAvailable?: boolean + stats?: { + averageRating?: number + reviewCount?: number + productCount?: number + recentReviewCount?: number + } + environmentImages?: string[] + featuredProducts?: Array<{ + id: IdType + title?: string + imageUrl?: string + price?: number + likeCount?: number + collectCount?: number + availableBookableArtistCount?: number + bookingHint?: string + }> + recentReviews?: Array<{ + id: IdType + productId?: IdType + productTitle?: string + ratingScore?: number + content?: string + imageUrls?: string[] + submittedAt?: string + }> + availabilitySummary?: { + available?: boolean + summaryText?: string + nextSlots?: string[] + } + contactSummary?: { + actionText?: string + phoneExposed?: boolean + phone?: string + } +} + /** * Purpose: ListShopsParams supports shop.ts by holding or executing the list shops params page or API role. * Usage: import, call, read, or update this interface from the owning page/module while preserving the surrounding loading and permission flow. @@ -124,5 +174,9 @@ export const shopApi = { getShopById: async (id: IdType): Promise => { return await api.get(`/shop/get/${id}`) as unknown as ShopVO + }, + + getTrustProfile: async (id: IdType): Promise => { + return await api.get(`/shop/trust-profile/${id}`) as unknown as ShopTrustProfileVO } } diff --git a/YumiNail-Frontend/src/api/tag.ts b/YumiNail-Frontend/src/api/tag.ts index 2136332e..1fc0f1e5 100644 --- a/YumiNail-Frontend/src/api/tag.ts +++ b/YumiNail-Frontend/src/api/tag.ts @@ -15,10 +15,23 @@ export interface TagVO { textColor: string bgColor: string borderColor: string + sceneGroup?: string + displayName?: string + sortOrder?: number + frontVisible?: number createTime: string updateTime: string } +/** + * Purpose: TagFilterGroupVO groups public tags for scene filters. + * Usage: render each group as one filter row and pass selected tag ids to product list APIs. + */ +export interface TagFilterGroupVO { + groupName: string + tags: TagVO[] +} + /** * Purpose: TagDTO supports tag.ts by holding or executing the tag dto page or API role. * Usage: import, call, read, or update this interface from the owning page/module while preserving the surrounding loading and permission flow. @@ -28,6 +41,10 @@ export interface TagDTO { textColor: string bgColor: string borderColor: string + sceneGroup?: string + displayName?: string + sortOrder?: number + frontVisible?: number } /** @@ -43,6 +60,16 @@ export const tagApi = { return api.get('/tag/list/all') }, + /** + * `getFilterOptions` API call. Use this method to load customer-facing scene filters. + * Call guide: optionally pass shopId, await the grouped tags, then query products with tagIds. + */ + getFilterOptions: (shopId?: IdType | null) => { + return api.get('/tag/list/filter-options', { + params: shopId ? { shopId } : undefined + }) + }, + /** * `getTagById` API call. Use this method from the page script to invoke the backend endpoint tied to this feature. * Call guide: supply the parameters below, await the returned Promise, and handle loading / error UI in the caller. diff --git a/YumiNail-Frontend/src/api/wishlist.ts b/YumiNail-Frontend/src/api/wishlist.ts index 866047e8..aacabd9f 100644 --- a/YumiNail-Frontend/src/api/wishlist.ts +++ b/YumiNail-Frontend/src/api/wishlist.ts @@ -13,6 +13,10 @@ export interface WishlistItem { id: IdType userId: IdType productId: IdType + groupId?: IdType | null + groupName?: string | null + note?: string | null + sortOrder?: number | null product: { id: IdType shopId: IdType | null @@ -35,6 +39,39 @@ export interface WishlistItem { } } +export interface WishlistGroup { + id: IdType + name: string + sortOrder: number + itemCount: number + items?: WishlistItem[] +} + +export interface WishlistInspiration { + total: number + groups: WishlistGroup[] +} + +export interface WishlistGroupPayload { + name: string + sortOrder?: number +} + +export interface WishlistAddWithGroupPayload { + productId: IdType + groupId?: IdType | null + note?: string + sortOrder?: number +} + +export interface WishlistMovePayload { + wishlistId?: IdType + productId?: IdType + groupId?: IdType | null + note?: string + sortOrder?: number +} + /** * wishlistApi groups all API calls for this page domain. * Call guide: pass the typed payload or identifier into the method below, and use the returned Promise in the page script. @@ -54,5 +91,33 @@ export const wishlistApi = { getWishlist: async (): Promise => { return await api.get('/wishlist/list') as unknown as WishlistItem[] + }, + + getGroups: async (): Promise => { + return await api.get('/wishlist/groups') as unknown as WishlistGroup[] + }, + + createGroup: async (payload: WishlistGroupPayload): Promise => { + return await api.post('/wishlist/groups', payload) as unknown as IdType + }, + + updateGroup: async (id: IdType, payload: WishlistGroupPayload): Promise => { + return await api.put(`/wishlist/groups/${id}`, payload) as unknown as boolean + }, + + deleteGroup: async (id: IdType): Promise => { + return await api.delete(`/wishlist/groups/${id}`) as unknown as boolean + }, + + addWithGroup: async (payload: WishlistAddWithGroupPayload): Promise => { + return await api.post('/wishlist/add-with-group', payload) as unknown as boolean + }, + + moveWishlist: async (payload: WishlistMovePayload): Promise => { + return await api.post('/wishlist/move', payload) as unknown as boolean + }, + + getInspiration: async (): Promise => { + return await api.get('/wishlist/inspiration') as unknown as WishlistInspiration } } diff --git a/YumiNail-Frontend/src/router/index.ts b/YumiNail-Frontend/src/router/index.ts index 1a296d49..dfa26ab5 100644 --- a/YumiNail-Frontend/src/router/index.ts +++ b/YumiNail-Frontend/src/router/index.ts @@ -56,6 +56,12 @@ const router = createRouter({ component: () => import('../views/ShopDetailView.vue'), meta: { requiresAuth: false, hideNav: true, isAdmin: false } }, + { + path: '/artist/:id', + name: 'artist-profile', + component: () => import('../views/ArtistProfileView.vue'), + meta: { requiresAuth: false, hideNav: true, isAdmin: false } + }, { path: '/wishlist', name: 'wishlist', diff --git a/YumiNail-Frontend/src/utils/buy-now.test.ts b/YumiNail-Frontend/src/utils/buy-now.test.ts new file mode 100644 index 00000000..0a6f7937 --- /dev/null +++ b/YumiNail-Frontend/src/utils/buy-now.test.ts @@ -0,0 +1,19 @@ +import { describe, expect, it } from 'vitest' + +import { BUY_NOW_MODE, getBuyNowProductIdFromQuery, isBuyNowCartItem } from './buy-now' + +describe('buy-now checkout mode', () => { + it('reads the target product id only when cart query is in buyNow mode', () => { + expect(getBuyNowProductIdFromQuery({ mode: BUY_NOW_MODE, productId: '1001' })).toBe('1001') + expect(getBuyNowProductIdFromQuery({ mode: 'cart', productId: '1001' })).toBe('') + }) + + it('uses the first query value when vue-router provides array values', () => { + expect(getBuyNowProductIdFromQuery({ mode: [BUY_NOW_MODE], productId: ['2002', '3003'] })).toBe('2002') + }) + + it('matches numeric and string product ids for cart selection', () => { + expect(isBuyNowCartItem(1001, '1001')).toBe(true) + expect(isBuyNowCartItem('1002', '1001')).toBe(false) + }) +}) diff --git a/YumiNail-Frontend/src/utils/buy-now.ts b/YumiNail-Frontend/src/utils/buy-now.ts new file mode 100644 index 00000000..1a3bbd2e --- /dev/null +++ b/YumiNail-Frontend/src/utils/buy-now.ts @@ -0,0 +1,15 @@ +export const BUY_NOW_MODE = 'buyNow' + +type QueryValue = string | string[] | null | undefined + +const firstQueryValue = (value: QueryValue) => Array.isArray(value) ? value[0] : value + +export const getBuyNowProductIdFromQuery = (query: Record) => { + const mode = firstQueryValue(query.mode as QueryValue) + const productId = firstQueryValue(query.productId as QueryValue) + return mode === BUY_NOW_MODE && productId ? String(productId) : '' +} + +export const isBuyNowCartItem = (itemProductId: unknown, buyNowProductId: string) => { + return Boolean(buyNowProductId) && String(itemProductId || '') === String(buyNowProductId) +} diff --git a/YumiNail-Frontend/src/utils/order-review-focus.test.ts b/YumiNail-Frontend/src/utils/order-review-focus.test.ts new file mode 100644 index 00000000..0780f011 --- /dev/null +++ b/YumiNail-Frontend/src/utils/order-review-focus.test.ts @@ -0,0 +1,89 @@ +import { describe, expect, it } from 'vitest' +import { resolveOrderReviewFocus } from './order-review-focus' + +const orders = [ + { + id: 10, + items: [ + { id: 1001, productTitle: '猫眼款' } + ] + }, + { + id: 11, + items: [ + { id: 1101, productTitle: '法式款' } + ] + } +] + +describe('resolveOrderReviewFocus', () => { + it('focuses the exact pending review from message query parameters', () => { + const result = resolveOrderReviewFocus({ + orders, + pendingReviews: [{ id: 99, orderId: 10, orderItemId: 1001 }], + orderReviews: {}, + query: { reviewId: 99 } + }) + + expect(result.status).toBe('pending') + expect(result.focusOrderId).toBe('10') + expect(result.focusOrderItemId).toBe('1001') + expect(result.focusReviewId).toBe('99') + }) + + it('reports a friendly submitted state when the reminder was already handled', () => { + const result = resolveOrderReviewFocus({ + orders, + pendingReviews: [], + orderReviews: { + 10: [{ id: 99, orderId: 10, orderItemId: 1001, status: 1 }] + }, + query: { reviewId: 99 } + }) + + expect(result.status).toBe('submitted') + expect(result.focusOrderId).toBe('10') + expect(result.focusOrderItemId).toBe('1001') + expect(result.message).toContain('已处理') + }) + + it('chooses the first pending review for profile pending-review entry', () => { + const result = resolveOrderReviewFocus({ + orders, + pendingReviews: [{ id: 88, orderId: 11, orderItemId: 1101 }], + orderReviews: {}, + query: { review: 'pending' } + }) + + expect(result.status).toBe('pending') + expect(result.focusOrderId).toBe('11') + expect(result.focusOrderItemId).toBe('1101') + expect(result.focusReviewId).toBe('88') + }) + + it('keeps an order-level focus when only orderId is provided', () => { + const result = resolveOrderReviewFocus({ + orders, + pendingReviews: [], + orderReviews: {}, + query: { orderId: 10 } + }) + + expect(result.status).toBe('order') + expect(result.focusOrderId).toBe('10') + expect(result.focusOrderItemId).toBe('') + }) + + it('keeps the order visible when a review id is stale but orderId still exists', () => { + const result = resolveOrderReviewFocus({ + orders, + pendingReviews: [], + orderReviews: {}, + query: { orderId: 10, reviewId: 404 } + }) + + expect(result.status).toBe('missing') + expect(result.focusOrderId).toBe('10') + expect(result.message).toContain('失效') + }) +}) diff --git a/YumiNail-Frontend/src/utils/order-review-focus.ts b/YumiNail-Frontend/src/utils/order-review-focus.ts new file mode 100644 index 00000000..1cd58575 --- /dev/null +++ b/YumiNail-Frontend/src/utils/order-review-focus.ts @@ -0,0 +1,120 @@ +import type { OrderArtistReviewVO } from '@/api/order' + +type QueryValue = string | number | null | undefined | Array + +interface OrderLike { + id?: unknown + items?: Array<{ id?: unknown }> +} + +interface ResolveOrderReviewFocusOptions { + orders: OrderLike[] + pendingReviews: OrderArtistReviewVO[] + orderReviews: Record + query: Record +} + +export interface OrderReviewFocusResult { + status: 'none' | 'pending' | 'submitted' | 'missing' | 'order' + focusOrderId: string + focusOrderItemId: string + focusReviewId: string + message: string +} + +const toText = (value: QueryValue | unknown) => { + if (Array.isArray(value)) { + return value[0] === undefined || value[0] === null ? '' : String(value[0]) + } + return value === undefined || value === null ? '' : String(value) +} + +const sameId = (left: unknown, right: unknown) => { + const leftText = toText(left) + const rightText = toText(right) + return leftText !== '' && leftText === rightText +} + +const flattenSubmittedReviews = (orderReviews: Record) => { + return Object.values(orderReviews).flat().filter(review => Number(review.status) === 1 || Boolean(review.rating)) +} + +const findOrder = (orders: OrderLike[], orderId: string) => { + return orders.find(order => sameId(order.id, orderId)) +} + +const buildResult = ( + status: OrderReviewFocusResult['status'], + review?: OrderArtistReviewVO, + fallbackOrderId = '', + message = '' +): OrderReviewFocusResult => ({ + status, + focusOrderId: toText(review?.orderId) || fallbackOrderId, + focusOrderItemId: toText(review?.orderItemId), + focusReviewId: toText(review?.id), + message +}) + +export const resolveOrderReviewFocus = ({ + orders, + pendingReviews, + orderReviews, + query +}: ResolveOrderReviewFocusOptions): OrderReviewFocusResult => { + const reviewId = toText(query.reviewId) + const orderId = toText(query.orderId) + const orderItemId = toText(query.orderItemId) + const reviewMode = toText(query.review) + const submittedReviews = flattenSubmittedReviews(orderReviews) + + if (reviewId) { + const pending = pendingReviews.find(review => sameId(review.id, reviewId)) + if (pending) { + return buildResult('pending', pending, '', '已为你定位到待评价订单。') + } + const submitted = submittedReviews.find(review => sameId(review.id, reviewId)) + if (submitted) { + return buildResult('submitted', submitted, '', '这条评价提醒已处理,可查看已评价内容。') + } + return { + status: 'missing', + focusOrderId: findOrder(orders, orderId) ? orderId : '', + focusOrderItemId: orderItemId, + focusReviewId: reviewId, + message: '这条评价提醒已失效,可在订单页查看最新状态。' + } + } + + if (reviewMode === 'pending') { + const firstPending = pendingReviews[0] + if (firstPending) { + return buildResult('pending', firstPending, '', '已为你定位到待评价订单。') + } + return { + status: 'missing', + focusOrderId: '', + focusOrderItemId: '', + focusReviewId: '', + message: '暂无待评价订单。' + } + } + + if (orderId && findOrder(orders, orderId)) { + return { + status: 'order', + focusOrderId: orderId, + focusOrderItemId: orderItemId, + focusReviewId: '', + message: '' + } + } + + return { + status: 'none', + focusOrderId: '', + focusOrderItemId: '', + focusReviewId: '', + message: '' + } +} diff --git a/YumiNail-Frontend/src/utils/recovery.test.ts b/YumiNail-Frontend/src/utils/recovery.test.ts new file mode 100644 index 00000000..a3895801 --- /dev/null +++ b/YumiNail-Frontend/src/utils/recovery.test.ts @@ -0,0 +1,25 @@ +import { describe, expect, it } from 'vitest' +import { buildRecoveryActions, getRecoveryMessage, recoveryRouteFor } from './recovery' + +describe('recovery utils', () => { + it('normalizes error messages with fallback text', () => { + expect(getRecoveryMessage(new Error('网络开小差了'), '请求失败')).toBe('网络开小差了') + expect(getRecoveryMessage('', '请求失败')).toBe('请求失败') + }) + + it('adds default routes and primary action state', () => { + const actions = buildRecoveryActions([ + { key: 'retry', text: '重试' }, + { key: 'orders', text: '查看订单' }, + { key: 'cart', text: '返回购物车' } + ]) + const retryAction = actions[0] + const ordersAction = actions[1] + const cartAction = actions[2] + + expect(retryAction?.primary).toBe(true) + expect(ordersAction?.route).toBe('/orders') + expect(cartAction?.route).toBe('/cart') + expect(recoveryRouteFor('products')).toBe('/products') + }) +}) diff --git a/YumiNail-Frontend/src/utils/recovery.ts b/YumiNail-Frontend/src/utils/recovery.ts new file mode 100644 index 00000000..99e45f1c --- /dev/null +++ b/YumiNail-Frontend/src/utils/recovery.ts @@ -0,0 +1,43 @@ +export type RecoveryActionKey = 'retry' | 'orders' | 'cart' | 'products' | 'profile' | 'contact' + +export interface RecoveryAction { + key: RecoveryActionKey + text: string + route?: string + primary?: boolean +} + +const DEFAULT_ROUTES: Record = { + orders: '/orders', + cart: '/cart', + products: '/products', + profile: '/profile' +} + +export const getRecoveryMessage = (error: unknown, fallbackMessage: string): string => { + if (error instanceof Error && error.message.trim()) { + return error.message.trim() + } + if (typeof error === 'string' && error.trim()) { + return error.trim() + } + if (error && typeof error === 'object' && 'message' in error) { + const message = String((error as { message?: unknown }).message || '').trim() + if (message) { + return message + } + } + return fallbackMessage +} + +export const recoveryRouteFor = (key: RecoveryActionKey): string => DEFAULT_ROUTES[key] || '' + +export const buildRecoveryActions = (actions: RecoveryAction[]): RecoveryAction[] => ( + actions + .filter(action => action.key && action.text) + .map((action, index) => ({ + ...action, + route: action.route || recoveryRouteFor(action.key), + primary: action.primary ?? index === 0 + })) +) diff --git a/YumiNail-Frontend/src/utils/system-message-action.test.ts b/YumiNail-Frontend/src/utils/system-message-action.test.ts new file mode 100644 index 00000000..d8dec753 --- /dev/null +++ b/YumiNail-Frontend/src/utils/system-message-action.test.ts @@ -0,0 +1,38 @@ +import { describe, expect, it } from 'vitest' +import { buildSystemMessageActionPath } from './system-message-action' + +describe('buildSystemMessageActionPath', () => { + it('keeps safe review action paths with order and review query parameters', () => { + expect(buildSystemMessageActionPath({ + actionPath: '/orders?orderId=10&reviewId=99&orderItemId=1001', + businessType: 'ORDER_ARTIST_REVIEW', + businessId: 99 + })).toBe('/orders?orderId=10&reviewId=99&orderItemId=1001') + }) + + it('uses reviewId fallback for review reminder messages when actionPath is absent', () => { + expect(buildSystemMessageActionPath({ + businessType: 'ORDER_ARTIST_REVIEW', + businessId: 99 + })).toBe('/orders?reviewId=99&source=message') + }) + + it('opens pending reviews when a review reminder has no business id', () => { + expect(buildSystemMessageActionPath({ + businessType: 'ORDER_ARTIST_REVIEW' + })).toBe('/orders?review=pending&source=message') + }) + + it('uses orderId fallback for generic order messages', () => { + expect(buildSystemMessageActionPath({ + businessType: 'ORDER', + businessId: 10 + })).toBe('/orders?orderId=10&source=message') + }) + + it('rejects unsafe or backend-only action paths', () => { + expect(buildSystemMessageActionPath({ actionPath: '//evil.example/orders' })).toBe('') + expect(buildSystemMessageActionPath({ actionPath: 'https://evil.example/orders' })).toBe('') + expect(buildSystemMessageActionPath({ actionPath: '/admin/users' })).toBe('') + }) +}) diff --git a/YumiNail-Frontend/src/utils/system-message-action.ts b/YumiNail-Frontend/src/utils/system-message-action.ts new file mode 100644 index 00000000..b9c01b5c --- /dev/null +++ b/YumiNail-Frontend/src/utils/system-message-action.ts @@ -0,0 +1,72 @@ +import type { SystemMessageVO } from '@/api/user' + +type MessageLike = Pick + +const USER_ACTION_PREFIXES = [ + '/orders', + '/product/', + '/shop/', + '/coupons', + '/vip-center', + '/cart', + '/notifications', + '/wishlist', + '/profile', + '/settings' +] + +const appendQuery = (path: string, query: Record) => { + const params = new URLSearchParams() + Object.entries(query).forEach(([key, value]) => { + if (value !== undefined && value !== '') { + params.set(key, String(value)) + } + }) + const queryString = params.toString() + return queryString ? `${path}?${queryString}` : path +} + +export const normalizeSystemMessageActionPath = (value?: string) => { + const actionPath = String(value || '').trim() + if (!actionPath || !actionPath.startsWith('/') || actionPath.startsWith('//') || actionPath.includes('\\')) { + return '' + } + return USER_ACTION_PREFIXES.some(prefix => actionPath === prefix || actionPath.startsWith(prefix)) + ? actionPath + : '' +} + +export const buildSystemMessageActionPath = (message: MessageLike) => { + const actionPath = normalizeSystemMessageActionPath(message.actionPath) + if (actionPath) { + return actionPath + } + + const businessType = String(message.businessType || '').toUpperCase() + const businessId = message.businessId === undefined || message.businessId === null ? '' : String(message.businessId) + if (businessType === 'ORDER_ARTIST_REVIEW') { + return businessId + ? appendQuery('/orders', { reviewId: businessId, source: 'message' }) + : appendQuery('/orders', { review: 'pending', source: 'message' }) + } + if (businessType === 'ORDER_ARTIST_CHANGE' || businessType === 'ORDER') { + return appendQuery('/orders', { orderId: businessId || undefined, source: 'message' }) + } + if (businessType === 'PRODUCT' && businessId) { + return `/product/${encodeURIComponent(businessId)}` + } + if (businessType === 'SHOP' && businessId) { + return `/shop/${encodeURIComponent(businessId)}` + } + if (businessType === 'VIP') { + return '/vip-center' + } + if (businessType === 'COUPON') { + return '/coupons' + } + if (businessType === 'CART') { + return '/cart' + } + + return '' +} diff --git a/YumiNail-Frontend/src/views/ArtistProfileView.vue b/YumiNail-Frontend/src/views/ArtistProfileView.vue new file mode 100644 index 00000000..0f3528e7 --- /dev/null +++ b/YumiNail-Frontend/src/views/ArtistProfileView.vue @@ -0,0 +1,552 @@ + + + + + diff --git a/YumiNail-Frontend/src/views/CartView.vue b/YumiNail-Frontend/src/views/CartView.vue index 54e926e3..134dfefa 100644 --- a/YumiNail-Frontend/src/views/CartView.vue +++ b/YumiNail-Frontend/src/views/CartView.vue @@ -8,8 +8,8 @@