From d2b63e0c7187b50aec0d21f9ca1fde9899aabd6b Mon Sep 17 00:00:00 2001 From: xiaowang Date: Fri, 27 Mar 2026 14:55:41 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=EF=BC=9A=E5=85=A8=E5=B1=80?= =?UTF-8?q?=E6=B2=BB=E7=90=86=E9=9B=AA=E8=8A=B1ID=E7=B2=BE=E5=BA=A6?= =?UTF-8?q?=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Frontend/src/api/admin.ts | 139 +++++++++--------- Frontend/src/api/auth.ts | 7 +- Frontend/src/api/cart.ts | 7 +- Frontend/src/api/coupon.ts | 29 ++-- Frontend/src/api/file.ts | 3 +- Frontend/src/api/index.ts | 3 +- Frontend/src/api/order.ts | 15 +- Frontend/src/api/permission.ts | 15 +- Frontend/src/api/product.ts | 17 ++- Frontend/src/api/productLike.ts | 7 +- Frontend/src/api/shop.ts | 5 +- Frontend/src/api/tag.ts | 9 +- Frontend/src/api/user.ts | 21 +-- Frontend/src/api/wishlist.ts | 17 ++- Frontend/src/utils/id.ts | 20 +++ Frontend/src/views/ArtistOrderView.vue | 5 +- Frontend/src/views/AuthView.vue | 3 +- Frontend/src/views/CartView.vue | 63 +++++--- Frontend/src/views/HomeView.vue | 13 +- Frontend/src/views/OrderView.vue | 5 +- Frontend/src/views/ProductDetailView.vue | 17 ++- Frontend/src/views/ProductListView.vue | 10 +- Frontend/src/views/ShopDetailView.vue | 19 +-- Frontend/src/views/WishlistView.vue | 20 +-- Frontend/src/views/admin/AdminLoginView.vue | 7 +- Frontend/src/views/admin/OrdersView.vue | 8 +- Frontend/src/views/admin/PermissionsView.vue | 24 +-- Frontend/src/views/admin/ProductsView.vue | 32 ++-- Frontend/src/views/admin/ShopsView.vue | 30 ++-- Frontend/src/views/admin/TagsView.vue | 3 +- Frontend/src/views/admin/UsersView.vue | 10 +- .../messagehub/config/JacksonConfig.java | 18 +++ .../yuminailcore/config/JacksonConfig.java | 18 +++ docs/changes/2026-03-27-全局雪花ID精度治理.md | 95 ++++++++++++ 34 files changed, 459 insertions(+), 255 deletions(-) create mode 100644 Frontend/src/utils/id.ts create mode 100644 MessageHub/src/main/java/com/xiaowang/messagehub/config/JacksonConfig.java create mode 100644 YumiNail-Core/src/main/java/com/xiaowang/yuminailcore/config/JacksonConfig.java create mode 100644 docs/changes/2026-03-27-全局雪花ID精度治理.md diff --git a/Frontend/src/api/admin.ts b/Frontend/src/api/admin.ts index 9a09cd6b..bc45e0ba 100644 --- a/Frontend/src/api/admin.ts +++ b/Frontend/src/api/admin.ts @@ -2,6 +2,7 @@ import axios, { AxiosError, type AxiosProgressEvent } from 'axios' import router from '../router' import { message } from 'ant-design-vue' import { ADMIN_API_BASE_URL } from '../config/api' +import type { IdType } from '@/utils/id' let lastErrorTime = 0 let lastErrorMessage = '' @@ -169,7 +170,7 @@ adminApi.interceptors.response.use( export interface AdminLoginRequest { account: string password: string - shopId?: string | number + shopId?: IdType } export interface AdminLoginResponse { @@ -182,7 +183,7 @@ export interface LoginShopSelectionResponse { allowShoplessLogin: boolean message: string shops: Array<{ - id: number | string + id: IdType shopName: string }> } @@ -197,7 +198,7 @@ export const adminAuthApi = { logout: () => { return adminApi.post('/auth/logout') }, - switchShop: (shopId?: string | number) => { + switchShop: (shopId?: IdType) => { return adminApi.post('/auth/switch-shop', { shopId }) }, refreshToken: (refreshToken: string) => { @@ -206,7 +207,7 @@ export const adminAuthApi = { } export interface ObjectStorageFileVO { - id: number + id: IdType fileName: string fileSize: number contentType: string @@ -264,18 +265,18 @@ export const adminFileApi = { cancelChunkUpload: (uploadId: string) => { return adminApi.delete(`/object-storage-file/upload/${uploadId}`) }, - getSignedUrl: (id: number) => { + getSignedUrl: (id: IdType) => { return adminApi.get(`/object-storage-file/get-signed-url/${id}`) } } export interface Tag { - id: number + id: IdType tagName: string textColor?: string bgColor?: string borderColor?: string - shopId?: number + shopId?: IdType shopName?: string createTime: string updateTime: string @@ -285,33 +286,33 @@ export const adminTagApi = { listAllTags: () => { return adminApi.get('/tag/list/all') as unknown as Promise }, - listTagsByShopId: (shopId: number) => { + listTagsByShopId: (shopId: IdType) => { return adminApi.get(`/tag/list/by-shop/${shopId}`) as unknown as Promise }, - createTag: (data: { tagName: string; textColor?: string; bgColor?: string; borderColor?: string; shopId?: number }) => { - return adminApi.post('/tag/create', data) + createTag: (data: { tagName: string; textColor?: string; bgColor?: string; borderColor?: string; shopId?: IdType }) => { + return adminApi.post('/tag/create', data) }, - updateTag: (id: number, data: { tagName: string; textColor?: string; bgColor?: string; borderColor?: string; shopId?: number }) => { + updateTag: (id: IdType, data: { tagName: string; textColor?: string; bgColor?: string; borderColor?: string; shopId?: IdType }) => { return adminApi.put(`/tag/update/${id}`, data) }, - deleteTag: (id: number) => { + deleteTag: (id: IdType) => { return adminApi.delete(`/tag/delete/${id}`) } } export interface Artist { - id: number + id: IdType nickname: string account: string avatar?: string - shopId?: number + shopId?: IdType shopName?: string createTime: string updateTime: string } export const adminArtistApi = { - listArtists: (shopId?: number) => { + listArtists: (shopId?: IdType) => { const params: any = {} if (shopId) { params.shopId = shopId @@ -321,7 +322,7 @@ export const adminArtistApi = { } export interface Coupon { - id: number + id: IdType couponCode?: string couponName: string couponType: number @@ -336,7 +337,7 @@ export interface Coupon { endTime: string status?: number statusName?: string - shopId?: number + shopId?: IdType shopName?: string couponScene?: string requiredVipLevel?: string @@ -348,17 +349,17 @@ export interface Coupon { } export const adminCouponApi = { - listAllCoupons: (shopId?: number) => { + listAllCoupons: (shopId?: IdType) => { const params = shopId ? { shopId } : {} return adminApi.get('/coupon/list/all', { params }) as unknown as Promise }, createCoupon: (data: any) => { - return adminApi.post('/coupon/create', data) + return adminApi.post('/coupon/create', data) }, - updateCoupon: (id: number, data: any) => { + updateCoupon: (id: IdType, data: any) => { return adminApi.put(`/coupon/update/${id}`, data) }, - deleteCoupon: (id: number) => { + deleteCoupon: (id: IdType) => { return adminApi.delete(`/coupon/delete/${id}`) }, distributeCoupon: (data: any) => { @@ -367,8 +368,8 @@ export const adminCouponApi = { } export interface Product { - id: number - shopId: number + id: IdType + shopId: IdType shopName?: string title: string description: string @@ -388,25 +389,25 @@ export interface Product { } export const adminProductApi = { - listProducts: (params: { page: number; size: number; keyword?: string; shopId?: number }) => { + listProducts: (params: { page: number; size: number; keyword?: string; shopId?: IdType }) => { return adminApi.get<{ list: Product[]; total: number; page: number; size: number }>('/product/list', { params }) }, listAllProducts: () => { return adminApi.get('/product/list/all') }, createProduct: (data: any) => { - return adminApi.post('/product/create', data) + return adminApi.post('/product/create', data) }, - updateProduct: (id: number, data: any) => { + updateProduct: (id: IdType, data: any) => { return adminApi.put(`/product/update/${id}`, data) }, - deleteProduct: (id: number) => { + deleteProduct: (id: IdType) => { return adminApi.delete(`/product/delete/${id}`) } } export interface Shop { - id: number + id: IdType shopName: string description: string address: string @@ -438,31 +439,31 @@ export interface CreateShopRequest { } export const adminShopApi = { - listShops: (params: { page: number; size: number; keyword?: string; shopId?: number }) => { + listShops: (params: { page: number; size: number; keyword?: string; shopId?: IdType }) => { return adminApi.get('/shops/list', { params }) as unknown as Promise }, listAllShops: () => { return adminApi.get('/shops/list/all') as unknown as Promise }, createShop: (data: CreateShopRequest) => { - return adminApi.post('/shops/create', data) + return adminApi.post('/shops/create', data) }, - updateShop: (id: number, data: CreateShopRequest) => { + updateShop: (id: IdType, data: CreateShopRequest) => { return adminApi.put(`/shops/update/${id}`, data) }, - updateShopStatus: (id: number, status: number) => { + updateShopStatus: (id: IdType, status: number) => { return adminApi.put(`/shops/status/${id}`, { status }) }, - deleteShop: (id: number) => { + deleteShop: (id: IdType) => { return adminApi.delete(`/shops/delete/${id}`) } } export interface UserVO { - id: number - shopId?: number + id: IdType + shopId?: IdType shopName?: string - shopIds?: Array + shopIds?: IdType[] shopNames?: string[] nickname: string account: string @@ -471,7 +472,7 @@ export interface UserVO { signature?: string level?: string type: number - vipId?: number + vipId?: IdType createTime: string updateTime: string status?: number @@ -485,59 +486,59 @@ export interface PageResult { } export const adminUserApi = { - listUsers: (params: { page: number; size: number; keyword?: string; type?: number; shopId?: number; status?: number }) => { + listUsers: (params: { page: number; size: number; keyword?: string; type?: number; shopId?: IdType; status?: number }) => { return adminApi.get>('/user/list', { params }) as unknown as Promise> }, listAllUsers: () => { return adminApi.get('/user/list/all') as unknown as Promise }, createUser: (data: any) => { - return adminApi.post('/user/create', data) + return adminApi.post('/user/create', data) }, - updateUser: (id: number, data: any) => { + updateUser: (id: IdType, data: any) => { return adminApi.put(`/user/update/${id}`, data) }, - deleteUser: (id: number) => { + deleteUser: (id: IdType) => { return adminApi.delete(`/user/delete/${id}`) }, - unbindUser: (id: number) => { + unbindUser: (id: IdType) => { return adminApi.put(`/user/unbind/${id}`, {}) }, - updateUserStatus: (id: number, status: number) => { + updateUserStatus: (id: IdType, status: number) => { return adminApi.put(`/user/status/${id}`, { status }) }, - resetPassword: (id: number) => { + resetPassword: (id: IdType) => { return adminApi.post(`/user/reset-password/${id}`) }, getUserInfo: () => { return adminApi.get('/user/info') as unknown as Promise }, - getUserAsset: (id: number) => { + getUserAsset: (id: IdType) => { return adminApi.get(`/user/${id}/asset`) as unknown as Promise }, - getUserBalanceHistory: (id: number) => { + getUserBalanceHistory: (id: IdType) => { return adminApi.get(`/user/${id}/balance/history`) as unknown as Promise }, - changeUserBalance: (id: number, data: AdminUserBalanceChangeRequest) => { + changeUserBalance: (id: IdType, data: AdminUserBalanceChangeRequest) => { return adminApi.post(`/user/${id}/balance/change`, data) as unknown as Promise }, - overrideUserVip: (id: number, data: AdminUserVipOverrideRequest) => { + overrideUserVip: (id: IdType, data: AdminUserVipOverrideRequest) => { return adminApi.post(`/user/${id}/vip/override`, data) as unknown as Promise }, - recalculateUserVip: (id: number) => { + recalculateUserVip: (id: IdType) => { return adminApi.post(`/user/${id}/vip/recalculate`) as unknown as Promise } } export interface UserAssetVO { - userId: number + userId: IdType nickname: string balance: number totalRechargeAmount: number lastRechargeTime?: string - vipInfoId?: number + vipInfoId?: IdType vipLevel: string - benefitId?: number + benefitId?: IdType benefitInfo?: string manualOverride: boolean vipStartTime?: string @@ -545,8 +546,8 @@ export interface UserAssetVO { } export interface UserBalanceHistoryItem { - id: number - userId: number + id: IdType + userId: IdType userNickname?: string amount: number type?: string @@ -554,10 +555,10 @@ export interface UserBalanceHistoryItem { beforeBalance?: number afterBalance?: number changeScene?: string - relatedOrderId?: number + relatedOrderId?: IdType relatedOrderNo?: string externalOrderNo?: string - operatorId?: number + operatorId?: IdType remark?: string changeTime: string } @@ -565,7 +566,7 @@ export interface UserBalanceHistoryItem { export interface AdminUserBalanceChangeRequest { amount: number changeScene: string - relatedOrderId?: number + relatedOrderId?: IdType externalOrderNo?: string remark?: string } @@ -578,13 +579,13 @@ export interface AdminUserVipOverrideRequest { export const userApi = adminUserApi export interface OrderVO { - id: number + id: IdType orderNo: string - userId: number + userId: IdType userNickname?: string - shopId: number + shopId: IdType shopName?: string - artistId?: number + artistId?: IdType artistName?: string totalAmount: number discountAmount: number @@ -597,16 +598,16 @@ export interface OrderVO { } export const adminOrderApi = { - listOrders: (params: { page: number; size: number; keyword?: string; status?: number; shopId?: number }) => { + listOrders: (params: { page: number; size: number; keyword?: string; status?: number; shopId?: IdType }) => { return adminApi.get>('/order/list', { params }) }, - updateOrderStatus: (id: number, status: number) => { + updateOrderStatus: (id: IdType, status: number) => { return adminApi.put(`/order/update-status/${id}`, { status }) } } export interface HotProductVO { - id: number + id: IdType title: string price: number likeCount: number @@ -614,7 +615,7 @@ export interface HotProductVO { } export interface RecentActivityVO { - id: number + id: IdType type: string title?: string description: string @@ -638,8 +639,8 @@ export const adminDashboardApi = { } export interface NailArtistInfoVO { - id: number | string - userId: number | string + id: IdType + userId: IdType identity: string experience: number skills: string @@ -647,7 +648,7 @@ export interface NailArtistInfoVO { status: number portfolio: string nickname: string - shopId: number | string + shopId: IdType shopName: string } @@ -655,7 +656,7 @@ export const adminNailArtistApi = { listNailArtists: () => { return adminApi.get('/nail-artist/list') }, - getNailArtistInfo: (userId: number) => { + getNailArtistInfo: (userId: IdType) => { return adminApi.get(`/nail-artist/get/${userId}`) }, saveNailArtistInfo: (data: any) => { diff --git a/Frontend/src/api/auth.ts b/Frontend/src/api/auth.ts index cd65113b..d43d2405 100644 --- a/Frontend/src/api/auth.ts +++ b/Frontend/src/api/auth.ts @@ -1,4 +1,5 @@ import api from './index' +import type { IdType } from '@/utils/id' export interface SendVerificationCodeRequest { phone: string @@ -33,15 +34,15 @@ export interface LoginResponse { } export interface UserInfo { - id: number + id: IdType account: string nickname: string avatar?: string signature?: string type?: number - shopId?: number | string + shopId?: IdType shopName?: string - shopIds?: Array + shopIds?: IdType[] shopNames?: string[] createTime: string updateTime?: string diff --git a/Frontend/src/api/cart.ts b/Frontend/src/api/cart.ts index 50e1e525..4f173e1b 100644 --- a/Frontend/src/api/cart.ts +++ b/Frontend/src/api/cart.ts @@ -1,7 +1,8 @@ import api from './index' +import type { IdType } from '@/utils/id' interface CartItem { - productId: number + productId: IdType quantity: number } @@ -12,12 +13,12 @@ export const cartApi = { }, // 从购物车移除作品 - removeFromCart: (productId: number) => { + removeFromCart: (productId: IdType) => { return api.delete(`/cart/remove/${productId}`) }, // 批量从购物车移除作品 - batchRemoveFromCart: (cartItemIds: number[]) => { + batchRemoveFromCart: (cartItemIds: IdType[]) => { return api.post('/cart/batch-remove', cartItemIds) }, diff --git a/Frontend/src/api/coupon.ts b/Frontend/src/api/coupon.ts index 1b6bf03d..f718a175 100644 --- a/Frontend/src/api/coupon.ts +++ b/Frontend/src/api/coupon.ts @@ -1,7 +1,8 @@ import request from './index' +import type { IdType } from '@/utils/id' export interface Coupon { - id: number + id: IdType couponCode: string couponName: string couponType: number @@ -16,7 +17,7 @@ export interface Coupon { endTime: string status: number statusName: string - shopId?: number + shopId?: IdType couponScene?: string requiredVipLevel?: string autoMatch?: number @@ -25,13 +26,13 @@ export interface Coupon { } export interface Tag { - id: number + id: IdType tagName?: string } export interface UserCoupon { - id: number - couponId: number + id: IdType + couponId: IdType couponName: string couponType: number couponTypeName: string @@ -62,8 +63,8 @@ export interface CreateCouponRequest { couponScene?: string requiredVipLevel?: string autoMatch?: number - availableTagIds: number[] - unavailableTagIds: number[] + availableTagIds: IdType[] + unavailableTagIds: IdType[] } export interface CouponListResponse { @@ -84,7 +85,7 @@ export const couponApi = { }, // 更新优惠券 - updateCoupon: (id: number, data: CreateCouponRequest) => { + updateCoupon: (id: IdType, data: CreateCouponRequest) => { return request({ url: `/coupon/update/${id}`, method: 'put', @@ -93,7 +94,7 @@ export const couponApi = { }, // 删除优惠券 - deleteCoupon: (id: number) => { + deleteCoupon: (id: IdType) => { return request({ url: `/coupon/delete/${id}`, method: 'delete' @@ -101,7 +102,7 @@ export const couponApi = { }, // 获取优惠券详情 - getCouponById: (id: number) => { + getCouponById: (id: IdType) => { return request({ url: `/coupon/detail/${id}`, method: 'get' @@ -109,7 +110,7 @@ export const couponApi = { }, // 获取优惠券列表 - listCoupons: (params: { page: number; size: number; shopId?: number }) => { + listCoupons: (params: { page: number; size: number; shopId?: IdType }) => { return request({ url: '/coupon/list', method: 'get', @@ -118,7 +119,7 @@ export const couponApi = { }, // 为用户分配优惠券 - assignCouponToUser: (userId: number, couponId: number) => { + assignCouponToUser: (userId: IdType, couponId: IdType) => { return request({ url: '/coupon/assign', method: 'post', @@ -136,7 +137,7 @@ export const couponApi = { }, // 使用优惠券 - useCoupon: (userCouponId: number) => { + useCoupon: (userCouponId: IdType) => { return request({ url: '/coupon/use', method: 'post', @@ -145,7 +146,7 @@ export const couponApi = { }, // 获取作品可用的优惠券 - getAvailableCoupons: async (productTags: string, productPrice: number, shopId?: number): Promise => { + getAvailableCoupons: async (productTags: string, productPrice: number, shopId?: IdType): Promise => { return await request({ url: '/coupon/available', method: 'get', diff --git a/Frontend/src/api/file.ts b/Frontend/src/api/file.ts index 6d55b50c..79fbcdbd 100644 --- a/Frontend/src/api/file.ts +++ b/Frontend/src/api/file.ts @@ -1,5 +1,6 @@ import type { AxiosProgressEvent } from 'axios' import api from './index' +import type { IdType } from '@/utils/id' export interface ChunkUploadInitRequest { fileName: string @@ -53,7 +54,7 @@ export const fileApi = { return api.delete(`/user/upload-avatar/${uploadId}`) }, - getSignedUrl: (fileId: number, expiryTimeInMinutes?: number) => { + getSignedUrl: (fileId: IdType, expiryTimeInMinutes?: number) => { return api.get(`/file/get-signed-url/${fileId}`, { params: { expiryTimeInMinutes } }) diff --git a/Frontend/src/api/index.ts b/Frontend/src/api/index.ts index 84716332..c80a42ed 100644 --- a/Frontend/src/api/index.ts +++ b/Frontend/src/api/index.ts @@ -5,6 +5,7 @@ import { wishlistApi } from './wishlist' import router from '../router' import { message } from 'ant-design-vue' import { API_BASE_URL } from '../config/api' +import type { IdType } from '@/utils/id' // 防重复提示标志 let lastErrorTime = 0 @@ -223,7 +224,7 @@ api.interceptors.response.use( ) export const fileApi = { - getSignedUrl: (fileId: number, expiryTimeInMinutes?: number) => { + getSignedUrl: (fileId: IdType, expiryTimeInMinutes?: number) => { return api.get(`/file/get-signed-url/${fileId}`, { params: { expiryTimeInMinutes } }) diff --git a/Frontend/src/api/order.ts b/Frontend/src/api/order.ts index a7a8d445..a8f98eac 100644 --- a/Frontend/src/api/order.ts +++ b/Frontend/src/api/order.ts @@ -1,14 +1,15 @@ import api from './index' +import type { IdType } from '@/utils/id' interface OrderItem { - productId: number + productId: IdType quantity: number - artistId?: number + artistId?: IdType appointmentTime?: string } interface CreateOrderRequest { - couponId?: number + couponId?: IdType couponSourceType?: string items: OrderItem[] } @@ -25,12 +26,12 @@ export const orderApi = { }, // 获取订单详情 - getOrderDetail: (orderId: number) => { + getOrderDetail: (orderId: IdType) => { return api.get(`/order/detail/${orderId}`) }, // 取消订单 - cancelOrder: (orderId: number) => { + cancelOrder: (orderId: IdType) => { return api.put(`/order/cancel/${orderId}`) }, @@ -40,7 +41,7 @@ export const orderApi = { }, // 后台处理订单 - processOrder: (orderId: number, status: number) => { + processOrder: (orderId: IdType, status: number) => { return api.put(`/order/admin/process/${orderId}`, {}, { params: { status } }) @@ -51,7 +52,7 @@ export const orderApi = { return api.get('/order/artist/list') }, - completeArtistOrder: (orderId: number) => { + completeArtistOrder: (orderId: IdType) => { return api.put(`/order/artist/complete/${orderId}`) } } diff --git a/Frontend/src/api/permission.ts b/Frontend/src/api/permission.ts index 3c29616c..9302d808 100644 --- a/Frontend/src/api/permission.ts +++ b/Frontend/src/api/permission.ts @@ -1,7 +1,8 @@ import { adminApi } from './admin' +import type { IdType } from '@/utils/id' export interface PermissionVO { - id: number + id: IdType permissionCode: string permissionName: string permissionGroup: string @@ -25,15 +26,15 @@ export interface UpdatePermissionRequest { } export const permissionApi = { - getUserPermissions: (userId?: number) => { + getUserPermissions: (userId?: IdType) => { if (userId) { return adminApi.get(`/permission/user/${userId}`) } return adminApi.get('/permission/user/current') }, - getAssignablePermissionIds: (userId: number) => { - return adminApi.get(`/permission/assignable/${userId}`) + getAssignablePermissionIds: (userId: IdType) => { + return adminApi.get(`/permission/assignable/${userId}`) }, listAllPermissions: () => { @@ -44,15 +45,15 @@ export const permissionApi = { return adminApi.post('/permission/create', data) }, - updatePermission: (id: number, data: UpdatePermissionRequest) => { + updatePermission: (id: IdType, data: UpdatePermissionRequest) => { return adminApi.put(`/permission/update/${id}`, data) }, - deletePermission: (id: number) => { + deletePermission: (id: IdType) => { return adminApi.delete(`/permission/delete/${id}`) }, - assignUserPermissions: (userId: number, permissionIds: number[]) => { + assignUserPermissions: (userId: IdType, permissionIds: IdType[]) => { return adminApi.post(`/permission/assign/${userId}`, { permissionIds }) } } diff --git a/Frontend/src/api/product.ts b/Frontend/src/api/product.ts index 29b8f469..502e455e 100644 --- a/Frontend/src/api/product.ts +++ b/Frontend/src/api/product.ts @@ -1,8 +1,9 @@ import api from './index' +import type { IdType } from '@/utils/id' export interface ProductVO { - id: number - shopId: number | null + id: IdType + shopId: IdType | null shopName?: string name: string title?: string @@ -29,7 +30,7 @@ export interface ProductVO { } export interface TagInfo { - id: number + id: IdType tagName: string textColor?: string bgColor?: string @@ -50,7 +51,7 @@ export interface CreateProductRequest { estimatedTime: number category: string status: number - shopId: number | null + shopId: IdType | null } export interface UpdateProductRequest { @@ -61,7 +62,7 @@ export interface UpdateProductRequest { estimatedTime?: number category?: string status?: number - shopId?: number | null + shopId?: IdType | null } export const productApi = { @@ -69,7 +70,7 @@ export const productApi = { return await api.get('/product/list/all') as unknown as ProductVO[] }, - getProductById: async (id: number): Promise => { + getProductById: async (id: IdType): Promise => { return await api.get(`/product/get/${id}`) as unknown as ProductVO }, @@ -77,11 +78,11 @@ export const productApi = { return await api.get(`/product/list/tag/${tag}`) as unknown as ProductVO[] }, - likeProduct: async (productId: number): Promise => { + likeProduct: async (productId: IdType): Promise => { return await api.post(`/product/like/${productId}`) as unknown as boolean }, - unlikeProduct: async (productId: number): Promise => { + unlikeProduct: async (productId: IdType): Promise => { return await api.post(`/product/unlike/${productId}`) as unknown as boolean }, diff --git a/Frontend/src/api/productLike.ts b/Frontend/src/api/productLike.ts index 3a0530ae..29e7db96 100644 --- a/Frontend/src/api/productLike.ts +++ b/Frontend/src/api/productLike.ts @@ -1,11 +1,12 @@ import api from './index' +import type { IdType } from '@/utils/id' export const productLikeApi = { /** * 点赞作品 * @param productId 作品ID */ - likeProduct: (productId: number) => { + likeProduct: (productId: IdType) => { return api.post(`/product-like/like/${productId}`) }, @@ -13,7 +14,7 @@ export const productLikeApi = { * 取消点赞作品 * @param productId 作品ID */ - unlikeProduct: (productId: number) => { + unlikeProduct: (productId: IdType) => { return api.post(`/product-like/unlike/${productId}`) }, @@ -21,7 +22,7 @@ export const productLikeApi = { * 检查用户是否已点赞作品 * @param productId 作品ID */ - checkLikeStatus: (productId: number) => { + checkLikeStatus: (productId: IdType) => { return api.get(`/product-like/check/${productId}`) } } diff --git a/Frontend/src/api/shop.ts b/Frontend/src/api/shop.ts index 7230dec6..ee1aa917 100644 --- a/Frontend/src/api/shop.ts +++ b/Frontend/src/api/shop.ts @@ -1,7 +1,8 @@ import api from './index' +import type { IdType } from '@/utils/id' export interface ShopVO { - id: number + id: IdType shopName: string description: string address: string @@ -60,7 +61,7 @@ export const shopApi = { return await api.get('/shop/list/simple') as unknown as ShopSimpleVO[] }, - getShopById: async (id: number): Promise => { + getShopById: async (id: IdType): Promise => { return await api.get(`/shop/get/${id}`) as unknown as ShopVO } } diff --git a/Frontend/src/api/tag.ts b/Frontend/src/api/tag.ts index 8c531015..965b5ce9 100644 --- a/Frontend/src/api/tag.ts +++ b/Frontend/src/api/tag.ts @@ -1,7 +1,8 @@ import api from './index' +import type { IdType } from '@/utils/id' export interface TagVO { - id: number + id: IdType tagName: string textColor: string bgColor: string @@ -22,7 +23,7 @@ export const tagApi = { return api.get('/tag/list/all') }, - getTagById: (id: number) => { + getTagById: (id: IdType) => { return api.get(`/tag/get/${id}`) }, @@ -30,11 +31,11 @@ export const tagApi = { return api.post('/tag/add', data) }, - updateTag: (id: number, data: TagDTO) => { + updateTag: (id: IdType, data: TagDTO) => { return api.put(`/tag/update/${id}`, data) }, - deleteTag: (id: number) => { + deleteTag: (id: IdType) => { return api.delete(`/tag/delete/${id}`) } } diff --git a/Frontend/src/api/user.ts b/Frontend/src/api/user.ts index 6bd1e5e0..4e165063 100644 --- a/Frontend/src/api/user.ts +++ b/Frontend/src/api/user.ts @@ -1,11 +1,12 @@ import api from './index' import type { UserInfo } from './auth' +import type { IdType } from '@/utils/id' export interface UserVO extends UserInfo { - id: number - shopId?: number + id: IdType + shopId?: IdType shopName?: string - shopIds?: Array + shopIds?: IdType[] shopNames?: string[] nickname: string account: string @@ -13,7 +14,7 @@ export interface UserVO extends UserInfo { signature?: string level?: string type: number - vipId?: number + vipId?: IdType createTime: string updateTime: string status: number @@ -30,7 +31,7 @@ export interface ListUsersParams { page: number size: number keyword?: string - shopId?: number + shopId?: IdType status?: number } @@ -40,8 +41,8 @@ export interface CreateUserRequest { phone: string password: string type: number - shopId?: number - shopIds?: Array + shopId?: IdType + shopIds?: IdType[] } export interface UpdateUserRequest { @@ -49,8 +50,8 @@ export interface UpdateUserRequest { nickname?: string phone?: string type?: number - shopId?: number - shopIds?: Array + shopId?: IdType + shopIds?: IdType[] } export interface UpdatePasswordRequest { @@ -78,7 +79,7 @@ export interface LoginShopSelectionResponse { allowShoplessLogin: boolean message: string shops: Array<{ - id: number | string + id: IdType shopName: string }> } diff --git a/Frontend/src/api/wishlist.ts b/Frontend/src/api/wishlist.ts index d6a66c65..c0099324 100644 --- a/Frontend/src/api/wishlist.ts +++ b/Frontend/src/api/wishlist.ts @@ -1,12 +1,13 @@ import api from './index' +import type { IdType } from '@/utils/id' export interface WishlistItem { - id: number - userId: number - productId: number + id: IdType + userId: IdType + productId: IdType product: { - id: number - shopId: number | null + id: IdType + shopId: IdType | null shopName?: string title: string description: string @@ -27,15 +28,15 @@ export interface WishlistItem { } export const wishlistApi = { - addToWishlist: async (productId: number): Promise => { + addToWishlist: async (productId: IdType): Promise => { return await api.post('/wishlist/add', { productId }) as unknown as boolean }, - removeFromWishlist: async (productId: number): Promise => { + removeFromWishlist: async (productId: IdType): Promise => { return await api.post('/wishlist/remove', { productId }) as unknown as boolean }, - checkWishlist: async (productId: number): Promise => { + checkWishlist: async (productId: IdType): Promise => { return await api.get(`/wishlist/check?productId=${productId}`) as unknown as boolean }, diff --git a/Frontend/src/utils/id.ts b/Frontend/src/utils/id.ts new file mode 100644 index 00000000..699f9558 --- /dev/null +++ b/Frontend/src/utils/id.ts @@ -0,0 +1,20 @@ +export type IdType = string | number + +export const isEmptyId = (value: unknown): value is undefined | null | '' => { + return value === undefined || value === null || `${value}`.trim() === '' +} + +export const toIdString = (value: IdType) => String(value) + +export const toOptionalIdString = (value: unknown) => { + if (isEmptyId(value)) { + return undefined + } + return String(value).trim() +} + +export const sameId = (left: unknown, right: unknown) => { + const leftId = toOptionalIdString(left) + const rightId = toOptionalIdString(right) + return leftId !== undefined && leftId === rightId +} diff --git a/Frontend/src/views/ArtistOrderView.vue b/Frontend/src/views/ArtistOrderView.vue index 3a443076..34baa684 100644 --- a/Frontend/src/views/ArtistOrderView.vue +++ b/Frontend/src/views/ArtistOrderView.vue @@ -49,6 +49,7 @@ import { LeftOutlined } from '@ant-design/icons-vue' import { message, Modal } from 'ant-design-vue' import { fileApi } from '../api/index' import { orderApi } from '../api/order' +import type { IdType } from '@/utils/id' const router = useRouter() const orders = ref([]) @@ -69,7 +70,7 @@ const loadOrders = async () => { if (!match?.[1]) continue const imageId = match[1] try { - if (!imageIdCache.value[imageId]) imageIdCache.value[imageId] = await fileApi.getSignedUrl(Number(imageId)) as any + if (!imageIdCache.value[imageId]) imageIdCache.value[imageId] = await fileApi.getSignedUrl(imageId) as any item.productImage = imageIdCache.value[imageId] } catch { item.productImage = '' @@ -81,7 +82,7 @@ const loadOrders = async () => { } } -const completeOrder = (orderId: number) => { +const completeOrder = (orderId: IdType) => { Modal.confirm({ title: '确认完成服务', content: '确定要完成这个订单吗?', diff --git a/Frontend/src/views/AuthView.vue b/Frontend/src/views/AuthView.vue index adbd9f83..3baf6547 100644 --- a/Frontend/src/views/AuthView.vue +++ b/Frontend/src/views/AuthView.vue @@ -403,6 +403,7 @@ import { type LoginAccountCheckResponse, type LoginShopSelectionResponse } from '@/api/user' +import type { IdType } from '@/utils/id' const router = useRouter() @@ -411,7 +412,7 @@ const loginType = ref<'password' | 'phone'>('password') const loading = ref(false) const loadingShops = ref(false) const shops = ref([]) -const loginShops = ref>([]) +const loginShops = ref>([]) const countdown = ref(0) const loginAccountStatus = ref(null) const registerAccountStatus = ref(null) diff --git a/Frontend/src/views/CartView.vue b/Frontend/src/views/CartView.vue index 49248434..347343d0 100644 --- a/Frontend/src/views/CartView.vue +++ b/Frontend/src/views/CartView.vue @@ -143,7 +143,7 @@ :key="artist.id" type="button" class="artist-option" - :class="{ active: draftArtistId === artist.id }" + :class="{ active: sameId(draftArtistId, artist.id) }" @click="draftArtistId = artist.id" > @@ -183,6 +183,8 @@ import { couponApi, type UserCoupon } from '../api/coupon' import { fileApi } from '../api/index' import { orderApi } from '../api/order' import { shopApi } from '../api/shop' +import type { IdType } from '@/utils/id' +import { sameId, toOptionalIdString } from '@/utils/id' const router = useRouter() const updateCartCount = inject<() => Promise>('updateCartCount', async () => {}) @@ -190,15 +192,15 @@ const updateCartCount = inject<() => Promise>('updateCartCount', async () const NO_COUPON_KEY = 'NONE' interface ArtistOption { - id: number + id: IdType name: string avatar?: string } interface CartItem { - id: number - productId: number - shopId?: number + id: IdType + productId: IdType + shopId?: IdType productTitle: string productImage: string originalProductImage?: string @@ -214,19 +216,19 @@ interface CartItem { availableArtists?: ArtistOption[] appointmentTime?: string selected: boolean - artistId?: number + artistId?: IdType artist?: ArtistOption } interface CheckoutIssue { key: string message: string - itemId?: number + itemId?: IdType } const cartItems = ref([]) const imageIdCache = ref>({}) -const itemRefs = ref>({}) +const itemRefs = ref>({}) const availableCoupons = ref([]) const selectedCoupon = ref(null) const couponSelectionKey = ref(NO_COUPON_KEY) @@ -235,7 +237,7 @@ const showCouponModal = ref(false) const showBookingModal = ref(false) const currentItem = ref(null) const availableArtists = ref([]) -const draftArtistId = ref() +const draftArtistId = ref() const draftAppointmentTime = ref('') const currentShopHours = ref('') const editing = ref(false) @@ -269,16 +271,20 @@ const getDayBoundary = (date: Date) => { const getCouponKey = (coupon: UserCoupon) => `${coupon.sourceType || 'USER_COUPON'}:${coupon.id}` -const setItemRef = (itemId: number, element: unknown) => { +const setItemRef = (itemId: IdType, element: unknown) => { + const refKey = toOptionalIdString(itemId) + if (!refKey) { + return + } if (element && (element as any).$el) { - itemRefs.value[itemId] = (element as any).$el as HTMLElement + itemRefs.value[refKey] = (element as any).$el as HTMLElement return } if (element instanceof HTMLElement) { - itemRefs.value[itemId] = element + itemRefs.value[refKey] = element return } - delete itemRefs.value[itemId] + delete itemRefs.value[refKey] } const formatCouponDisplay = (coupon: UserCoupon) => { @@ -332,11 +338,21 @@ const checkoutIssues = computed(() => { issues.push({ key: 'expired', message: `“${firstExpiredTime.productTitle}”的预约时间已过期,请重新选择`, itemId: firstExpiredTime.id }) } - if (new Set(items.map(item => item.shopId).filter(Boolean)).size > 1) { + const selectedShopIds = new Set( + items + .map(item => toOptionalIdString(item.shopId)) + .filter((shopId): shopId is string => Boolean(shopId)) + ) + if (selectedShopIds.size > 1) { issues.push({ key: 'shop', message: '跨店铺项目请分开结算', itemId: items[0]?.id }) } - if (new Set(items.map(item => item.artistId).filter(Boolean)).size > 1) { + const selectedArtistIds = new Set( + items + .map(item => toOptionalIdString(item.artistId)) + .filter((artistId): artistId is string => Boolean(artistId)) + ) + if (selectedArtistIds.size > 1) { issues.push({ key: 'artist-mix', message: '不同美甲师的项目请分开结算', itemId: items[0]?.id }) } @@ -344,10 +360,11 @@ const checkoutIssues = computed(() => { }) const scrollToIssue = (issue?: CheckoutIssue) => { - if (!issue?.itemId) { + const itemId = toOptionalIdString(issue?.itemId) + if (!itemId) { return } - const target = itemRefs.value[issue.itemId] + const target = itemRefs.value[itemId] if (target) { target.scrollIntoView({ behavior: 'smooth', block: 'center' }) } @@ -381,7 +398,7 @@ const loadProductImages = async () => { const imageId = match[1] try { if (!imageIdCache.value[imageId]) { - imageIdCache.value[imageId] = await fileApi.getSignedUrl(Number(imageId)) as any + imageIdCache.value[imageId] = await fileApi.getSignedUrl(imageId) as any } item.productImage = imageIdCache.value[imageId] || '' } catch { @@ -464,7 +481,7 @@ const changeQuantity = async (item: CartItem, delta: number) => { const removeItem = async (item: CartItem) => { try { await cartApi.removeFromCart(item.productId) - cartItems.value = cartItems.value.filter(current => current.id !== item.id) + cartItems.value = cartItems.value.filter(current => !sameId(current.id, item.id)) await Promise.all([loadAvailableCoupons(), updateCartCount()]) message.success('作品已删除') } catch { @@ -505,18 +522,18 @@ const loadArtists = async (item: CartItem) => { ? item.availableArtists .filter(artist => artist && artist.id !== undefined && artist.id !== null) .map(artist => ({ - id: Number(artist.id), + id: artist.id, name: artist.name, avatar: artist.avatar })) : [] - if (draftArtistId.value && !availableArtists.value.some(artist => artist.id === draftArtistId.value)) { + if (draftArtistId.value && !availableArtists.value.some(artist => sameId(artist.id, draftArtistId.value))) { draftArtistId.value = undefined } } -const loadShopHours = async (shopId?: number) => { +const loadShopHours = async (shopId?: IdType) => { currentShopHours.value = '' if (!shopId) return try { @@ -571,7 +588,7 @@ const confirmBooking = () => { if (!draftAppointmentTime.value) return message.warning('请选择预约时间') if (isPastAppointment(draftAppointmentTime.value)) return message.warning('预约时间至少需要晚于当前 5 分钟') currentItem.value.artistId = draftArtistId.value - currentItem.value.artist = availableArtists.value.find(artist => artist.id === draftArtistId.value) + currentItem.value.artist = availableArtists.value.find(artist => sameId(artist.id, draftArtistId.value)) currentItem.value.appointmentTime = draftAppointmentTime.value closeBookingModal() } diff --git a/Frontend/src/views/HomeView.vue b/Frontend/src/views/HomeView.vue index 8060f21a..5b9030f9 100644 --- a/Frontend/src/views/HomeView.vue +++ b/Frontend/src/views/HomeView.vue @@ -138,17 +138,18 @@ import { productApi, type ProductVO } from '../api/product' import { shopApi, type ShopVO } from '../api/shop' import { fileApi } from '../api/file' import { DEFAULT_AVATAR, DEFAULT_PRODUCT_IMAGE } from '@/constants' +import type { IdType } from '@/utils/id' interface BannerImage { id: string - shopId: number + shopId: IdType shopName: string businessHours?: string url: string } interface ProductCardItem { - id: number + id: IdType name: string price: string meta: string @@ -187,7 +188,7 @@ const getProductCoverUrl = async (product: ProductVO): Promise => { } if (!productImageCache.value[firstImageId]) { try { - productImageCache.value[firstImageId] = await fileApi.getSignedUrl(Number(firstImageId)) as unknown as string + productImageCache.value[firstImageId] = await fileApi.getSignedUrl(firstImageId) as unknown as string } catch (error) { console.error('获取首页作品封面失败:', error) productImageCache.value[firstImageId] = DEFAULT_PRODUCT_IMAGE @@ -250,11 +251,11 @@ const loadBannerImages = async () => { .filter(Boolean) for (const id of coverIds) { try { - const url = await fileApi.getSignedUrl(Number(id)) as unknown as string + const url = await fileApi.getSignedUrl(id) as unknown as string if (url) { banners.push({ id: `${shop.id}-${id}`, - shopId: Number(shop.id), + shopId: shop.id, shopName: shop.shopName, businessHours: shop.businessHours, url @@ -339,7 +340,7 @@ const handleProductClick = (item: ProductCardItem) => { router.push(`/product/${item.id}`) } -const openShopById = (shopId: number) => { +const openShopById = (shopId: IdType) => { router.push(`/shop/${shopId}`) } diff --git a/Frontend/src/views/OrderView.vue b/Frontend/src/views/OrderView.vue index b4b81a5f..d2282f34 100644 --- a/Frontend/src/views/OrderView.vue +++ b/Frontend/src/views/OrderView.vue @@ -48,6 +48,7 @@ import { LeftOutlined } from '@ant-design/icons-vue' import { message, Modal } from 'ant-design-vue' import { fileApi } from '../api/index' import { orderApi } from '../api/order' +import type { IdType } from '@/utils/id' const router = useRouter() const orders = ref([]) @@ -68,7 +69,7 @@ const loadOrders = async () => { if (!match?.[1]) continue const imageId = match[1] try { - if (!imageIdCache.value[imageId]) imageIdCache.value[imageId] = await fileApi.getSignedUrl(Number(imageId)) as any + if (!imageIdCache.value[imageId]) imageIdCache.value[imageId] = await fileApi.getSignedUrl(imageId) as any item.productImage = imageIdCache.value[imageId] } catch { item.productImage = '' @@ -80,7 +81,7 @@ const loadOrders = async () => { } } -const cancelOrder = (orderId: number) => { +const cancelOrder = (orderId: IdType) => { Modal.confirm({ title: '确认取消订单', content: '确定要取消这个订单吗?', diff --git a/Frontend/src/views/ProductDetailView.vue b/Frontend/src/views/ProductDetailView.vue index 383292a8..2372cdf5 100644 --- a/Frontend/src/views/ProductDetailView.vue +++ b/Frontend/src/views/ProductDetailView.vue @@ -148,6 +148,8 @@ import { productLikeApi } from '@/api/productLike' import { shopApi, type ShopVO } from '@/api/shop' import { wishlistApi } from '@/api/wishlist' import { DEFAULT_PRODUCT_IMAGE } from '@/constants' +import type { IdType } from '@/utils/id' +import { toOptionalIdString } from '@/utils/id' const route = useRoute() const router = useRouter() @@ -169,8 +171,8 @@ const artistCount = computed(() => { const rawValue = product.value.bookableArtists || '' return rawValue .split(',') - .map(id => Number(id.trim())) - .filter(id => Number.isFinite(id) && id > 0).length + .map(id => id.trim()) + .filter(Boolean).length }) const artistCountText = computed(() => { if (artistCount.value > 0) { @@ -264,7 +266,7 @@ const loadProductImages = async () => { for (const id of fileIds) { try { if (!imageIdCache.value[id]) { - imageIdCache.value[id] = await fileApi.getSignedUrl(Number(id)) as unknown as string + imageIdCache.value[id] = await fileApi.getSignedUrl(id) as unknown as string } if (imageIdCache.value[id]) { urls.push(imageIdCache.value[id]) @@ -277,13 +279,13 @@ const loadProductImages = async () => { productImages.value = urls.length ? urls : [DEFAULT_PRODUCT_IMAGE] } -const loadShopInfo = async (shopId?: number | null) => { +const loadShopInfo = async (shopId?: IdType | null) => { if (!shopId) { shopInfo.value = null return } try { - const response = await shopApi.getShopById(Number(shopId)) + const response = await shopApi.getShopById(shopId) shopInfo.value = response || null } catch (error) { console.error('获取门店信息失败:', error) @@ -333,7 +335,10 @@ const resolveLoadError = (error: any) => { const fetchProductDetail = async () => { loadError.value = '' try { - const productId = Number(route.params.id) + const productId = toOptionalIdString(route.params.id) + if (!productId) { + throw new Error('作品ID不存在') + } const response = await productApi.getProductById(productId) if (!response?.id) { throw new Error('未找到对应作品') diff --git a/Frontend/src/views/ProductListView.vue b/Frontend/src/views/ProductListView.vue index 3b0829fd..42911560 100644 --- a/Frontend/src/views/ProductListView.vue +++ b/Frontend/src/views/ProductListView.vue @@ -143,7 +143,7 @@ const loading = ref(false) const showSearch = ref(false) const searchKeyword = ref('') const imageIdCache = ref>({}) -const imageUrls = ref>({}) +const imageUrls = ref>({}) const isLoggedIn = computed(() => Boolean(localStorage.getItem('accessToken') || sessionStorage.getItem('accessToken'))) const activeBannerText = computed(() => { @@ -170,7 +170,7 @@ const ensureLoginForAction = (actionText: string) => { const loadImageUrls = async (productList: ProductVO[]) => { for (const product of productList) { if (!product.imageFileIds) { - imageUrls.value[product.id] = [DEFAULT_PRODUCT_IMAGE] + imageUrls.value[String(product.id)] = [DEFAULT_PRODUCT_IMAGE] continue } @@ -180,7 +180,7 @@ const loadImageUrls = async (productList: ProductVO[]) => { for (const id of ids) { try { if (!imageIdCache.value[id]) { - imageIdCache.value[id] = await fileApi.getSignedUrl(Number(id)) as unknown as string + imageIdCache.value[id] = await fileApi.getSignedUrl(id) as unknown as string } if (imageIdCache.value[id]) { urls.push(imageIdCache.value[id]) @@ -190,11 +190,11 @@ const loadImageUrls = async (productList: ProductVO[]) => { } } - imageUrls.value[product.id] = urls.length ? urls : [DEFAULT_PRODUCT_IMAGE] + imageUrls.value[String(product.id)] = urls.length ? urls : [DEFAULT_PRODUCT_IMAGE] } } -const getProductImages = (product: ProductVO): string[] => imageUrls.value[product.id] || [DEFAULT_PRODUCT_IMAGE] +const getProductImages = (product: ProductVO): string[] => imageUrls.value[String(product.id)] || [DEFAULT_PRODUCT_IMAGE] const fetchTags = async () => { try { diff --git a/Frontend/src/views/ShopDetailView.vue b/Frontend/src/views/ShopDetailView.vue index 652eee54..f52cab28 100644 --- a/Frontend/src/views/ShopDetailView.vue +++ b/Frontend/src/views/ShopDetailView.vue @@ -70,12 +70,13 @@ import { LeftOutlined, ShopOutlined } from '@ant-design/icons-vue' import { message } from 'ant-design-vue' import { shopApi, type ShopVO } from '@/api/shop' import { fileApi } from '@/api/file' +import { toOptionalIdString } from '@/utils/id' const router = useRouter() const route = useRoute() const shopInfo = ref({ - id: 0, + id: '', shopName: '', description: '', address: '', @@ -124,13 +125,13 @@ const loadShopImages = async () => { if (imageFileIds) { const fileIds = imageFileIds.split(',').filter(id => id.trim()) const fileIdPromises = fileIds.map(idStr => { - const fileId = parseInt(idStr) - if (!isNaN(fileId)) { - return fileApi.getSignedUrl(fileId).catch(() => { - return null - }) + const fileId = idStr.trim() + if (!fileId) { + return null } - return null + return fileApi.getSignedUrl(fileId).catch(() => { + return null + }) }) const results = await Promise.all(fileIdPromises) @@ -149,14 +150,14 @@ const loadShopImages = async () => { const fetchShopDetail = async () => { try { // 从路由参数或本地存储获取店铺ID - const shopId = route.params.id || localStorage.getItem('userShopId') + const shopId = toOptionalIdString(route.params.id || localStorage.getItem('userShopId')) if (!shopId) { message.error('店铺ID不存在') router.back() return } - const response = await shopApi.getShopById(Number(shopId)) as any + const response = await shopApi.getShopById(shopId) as any shopInfo.value = response || {} // 加载店铺图片 diff --git a/Frontend/src/views/WishlistView.vue b/Frontend/src/views/WishlistView.vue index b31ef8a6..8dfa1c61 100644 --- a/Frontend/src/views/WishlistView.vue +++ b/Frontend/src/views/WishlistView.vue @@ -53,13 +53,15 @@ import { ElMessage } from 'element-plus' import { wishlistApi, type WishlistItem } from '@/api/wishlist' import { cartApi } from '@/api/cart' import { fileApi } from '@/api/file' +import type { IdType } from '@/utils/id' +import { sameId } from '@/utils/id' const router = useRouter() const updateCartCount = inject<() => Promise>('updateCartCount', async () => {}) const wishlistItems = ref([]) const imageIdCache = ref>({}) -const imageUrls = ref>({}) +const imageUrls = ref>({}) const DEFAULT_PRODUCT_IMAGE = 'data:image/svg+xml;base64,PHN2ZyB3aW0dPSJodHRwOi8vd3d3Lm9yZy8yMDAwL3N2ZyI+Pjwvc3ZnPg==' const handleBackClick = () => { @@ -87,7 +89,7 @@ const loadImageUrls = async (items: WishlistItem[]) => { if (id) { try { if (!imageIdCache.value[id]) { - const response = await fileApi.getSignedUrl(Number(id)) as any + const response = await fileApi.getSignedUrl(id.trim()) as any imageIdCache.value[id] = response } if (imageIdCache.value[id]) { @@ -100,18 +102,18 @@ const loadImageUrls = async (items: WishlistItem[]) => { } } - imageUrls.value[item.product.id] = urls + imageUrls.value[String(item.product.id)] = urls } else { - imageUrls.value[item.product.id] = [DEFAULT_PRODUCT_IMAGE] + imageUrls.value[String(item.product.id)] = [DEFAULT_PRODUCT_IMAGE] } } } const getProductImages = (product: any): string[] => { - return imageUrls.value[product.id] || [DEFAULT_PRODUCT_IMAGE] + return imageUrls.value[String(product.id)] || [DEFAULT_PRODUCT_IMAGE] } -const handleAddToCart = async (productId: number) => { +const handleAddToCart = async (productId: IdType) => { try { await cartApi.addToCart({ productId, quantity: 1 }) await updateCartCount() @@ -122,10 +124,10 @@ const handleAddToCart = async (productId: number) => { } } -const handleRemoveItem = async (productId: number) => { +const handleRemoveItem = async (productId: IdType) => { try { await wishlistApi.removeFromWishlist(productId) - wishlistItems.value = wishlistItems.value.filter(item => item.productId !== productId) + wishlistItems.value = wishlistItems.value.filter(item => !sameId(item.productId, productId)) ElMessage.success('已从收藏中移除') } catch (error) { console.error('移除收藏失败:', error) @@ -137,7 +139,7 @@ const handleBrowseProducts = () => { router.push('/products') } -const handleProductClick = (productId: number) => { +const handleProductClick = (productId: IdType) => { router.push(`/product/${productId}`) } diff --git a/Frontend/src/views/admin/AdminLoginView.vue b/Frontend/src/views/admin/AdminLoginView.vue index 0961cdf0..19298ffc 100644 --- a/Frontend/src/views/admin/AdminLoginView.vue +++ b/Frontend/src/views/admin/AdminLoginView.vue @@ -84,13 +84,14 @@ import type { FormInstance } from 'ant-design-vue' import { UserOutlined, LockOutlined } from '@ant-design/icons-vue' import { adminAuthApi, type LoginShopSelectionResponse } from '@/api/admin' import { ACCOUNT_REGEX, ACCOUNT_RULE_MESSAGE, sanitizeAccountInput } from '@/utils/account' +import type { IdType } from '@/utils/id' import { usePermission } from '@/utils/permission' const router = useRouter() const formRef = ref() const loading = ref(false) const shopLoading = ref(false) -const shops = ref>([]) +const shops = ref>([]) const allowShoplessLogin = ref(false) const loginShopMessage = ref('') const { loadUserPermissions } = usePermission() @@ -109,8 +110,8 @@ const handleAccountInput = () => { } } -const getShopIdValue = (shop: { id: number | string; shopName: string }) => String(shop.id ?? '') -const getShopLabel = (shop: { id: number | string; shopName: string }) => String(shop.shopName || `店铺 ${shop.id}`) +const getShopIdValue = (shop: { id: IdType; shopName: string }) => String(shop.id ?? '') +const getShopLabel = (shop: { id: IdType; shopName: string }) => String(shop.shopName || `店铺 ${shop.id}`) const shopOptions = computed(() => shops.value.map(shop => ({ diff --git a/Frontend/src/views/admin/OrdersView.vue b/Frontend/src/views/admin/OrdersView.vue index 454b8289..1f04d673 100644 --- a/Frontend/src/views/admin/OrdersView.vue +++ b/Frontend/src/views/admin/OrdersView.vue @@ -68,6 +68,8 @@ import { computed, onMounted, ref } from 'vue' import { message } from 'ant-design-vue' import { orderApi } from '../../api/order' import { usePermission } from '@/utils/permission' +import type { IdType } from '@/utils/id' +import { sameId } from '@/utils/id' const orders = ref([]) const loading = ref(false) @@ -133,13 +135,13 @@ const loadOrders = async () => { } } -const process = async (orderId: number, status: number) => { +const process = async (orderId: IdType, status: number) => { try { await orderApi.processOrder(orderId, status) message.success('操作成功') await loadOrders() - if (currentOrder.value?.id === orderId) { - currentOrder.value = orders.value.find(order => order.id === orderId) || null + if (sameId(currentOrder.value?.id, orderId)) { + currentOrder.value = orders.value.find(order => sameId(order.id, orderId)) || null } } catch { message.error('操作失败') diff --git a/Frontend/src/views/admin/PermissionsView.vue b/Frontend/src/views/admin/PermissionsView.vue index da991a46..87da536f 100644 --- a/Frontend/src/views/admin/PermissionsView.vue +++ b/Frontend/src/views/admin/PermissionsView.vue @@ -80,7 +80,7 @@ >