功能:完善订单流程和加固
This commit is contained in:
@@ -29,11 +29,13 @@ import SystemMessageCard from './components/SystemMessageCard.vue'
|
||||
import { cartApi } from './api/cart'
|
||||
import { userApi, type SystemMessageVO } from './api/user'
|
||||
import antdLocale from './config/antdv-locale'
|
||||
import { useGlobalConfirmEnter } from './composables/useConfirmEnter'
|
||||
import { useShopTheme } from './composables/useShopTheme'
|
||||
|
||||
const route = useRoute()
|
||||
const router = useRouter()
|
||||
const { currentTheme, refreshShopTheme, resetShopTheme, setupShopThemeSync } = useShopTheme()
|
||||
useGlobalConfirmEnter()
|
||||
type ButtonPropsWithClass = ButtonProps & { class?: string }
|
||||
const popupMessageOkButtonProps: ButtonPropsWithClass = { class: 'popup-message-ok-button' }
|
||||
/** routerReady is a reactive state variable used by the template and event handlers. */
|
||||
@@ -108,6 +110,22 @@ const updateCartCount = async () => {
|
||||
await loadCartCount()
|
||||
}
|
||||
|
||||
const resolveSystemMessageActionPath = (item: SystemMessageVO) => {
|
||||
const actionPath = String(item.actionPath || '').trim()
|
||||
if (!actionPath || !actionPath.startsWith('/') || actionPath.startsWith('//')) {
|
||||
return ''
|
||||
}
|
||||
return actionPath
|
||||
}
|
||||
|
||||
const openSystemMessageAction = async (item: SystemMessageVO) => {
|
||||
const actionPath = resolveSystemMessageActionPath(item)
|
||||
if (!actionPath) {
|
||||
return
|
||||
}
|
||||
await router.push(actionPath)
|
||||
}
|
||||
|
||||
/** showPopupMessage is a local helper used by this page script. */
|
||||
const showPopupMessage = (item: SystemMessageVO) => {
|
||||
return new Promise<void>((resolve) => {
|
||||
@@ -142,6 +160,7 @@ const showPopupMessage = (item: SystemMessageVO) => {
|
||||
okButtonProps: popupMessageOkButtonProps,
|
||||
async onOk() {
|
||||
await markShownAndResolve()
|
||||
await openSystemMessageAction(item)
|
||||
},
|
||||
async afterClose() {
|
||||
await markShownAndResolve()
|
||||
|
||||
@@ -8,6 +8,7 @@ import { ADMIN_API_BASE_URL } from '../config/api'
|
||||
import type { IdType } from '@/utils/id'
|
||||
import { clearAdminSessionStorage } from '@/utils/admin-session'
|
||||
import { attachRequestSignature } from '@/utils/request-signature'
|
||||
import { isAdminApiAuthFreePath } from './auth-free-paths'
|
||||
|
||||
let lastErrorTime = 0
|
||||
let lastErrorMessage = ''
|
||||
@@ -38,6 +39,25 @@ const processQueue = (error: any, token: string | null = null) => {
|
||||
failedQueue = []
|
||||
}
|
||||
|
||||
const getStoredAdminAccessToken = () => {
|
||||
return localStorage.getItem('adminAccessToken') || sessionStorage.getItem('adminAccessToken')
|
||||
}
|
||||
|
||||
const getRequestToken = (request: any) => {
|
||||
if (request?._authToken) {
|
||||
return request._authToken as string
|
||||
}
|
||||
const authHeader = request?.headers?.Authorization || request?.headers?.authorization
|
||||
if (typeof authHeader !== 'string') {
|
||||
return null
|
||||
}
|
||||
return authHeader.startsWith('Bearer ') ? authHeader.slice('Bearer '.length) : null
|
||||
}
|
||||
|
||||
const isCurrentStoredAdminToken = (token: string | null) => {
|
||||
return Boolean(token && token === getStoredAdminAccessToken())
|
||||
}
|
||||
|
||||
const showError = (msg: string) => {
|
||||
const now = Date.now()
|
||||
if (now - lastErrorTime > ERROR_DEBOUNCE_TIME || msg !== lastErrorMessage) {
|
||||
@@ -48,10 +68,14 @@ const showError = (msg: string) => {
|
||||
}
|
||||
|
||||
const isAuthFreePath = (url?: string) => {
|
||||
return Boolean(url?.includes('/auth/login') || url?.includes('/auth/login-shops/') || url?.includes('/auth/refresh'))
|
||||
return isAdminApiAuthFreePath(url)
|
||||
}
|
||||
|
||||
const handleAdminTokenExpired = () => {
|
||||
const handleAdminTokenExpired = (failedToken: string | null = null) => {
|
||||
if (!isCurrentStoredAdminToken(failedToken)) {
|
||||
return
|
||||
}
|
||||
|
||||
clearAdminSessionStorage()
|
||||
|
||||
if (Date.now() - lastErrorTime > ERROR_DEBOUNCE_TIME || lastErrorMessage !== '登录已过期,请重新登录') {
|
||||
@@ -67,14 +91,12 @@ adminApi.interceptors.request.use(
|
||||
async config => {
|
||||
let token: string | null = null
|
||||
if (!isAuthFreePath(config.url)) {
|
||||
token = localStorage.getItem('adminAccessToken')
|
||||
if (!token) {
|
||||
token = sessionStorage.getItem('adminAccessToken')
|
||||
}
|
||||
token = getStoredAdminAccessToken()
|
||||
if (token) {
|
||||
config.headers.Authorization = `Bearer ${token}`
|
||||
}
|
||||
}
|
||||
;(config as any)._authToken = token || null
|
||||
return attachRequestSignature(config, token, {
|
||||
authFree: isAuthFreePath(config.url)
|
||||
})
|
||||
@@ -100,6 +122,12 @@ adminApi.interceptors.response.use(
|
||||
const originalRequest = error.config as any
|
||||
|
||||
if (error.response?.status === 401) {
|
||||
const requestToken = getRequestToken(originalRequest)
|
||||
|
||||
if (!isCurrentStoredAdminToken(requestToken)) {
|
||||
return Promise.reject(error)
|
||||
}
|
||||
|
||||
if (!originalRequest?._retry && !isAuthFreePath(originalRequest?.url)) {
|
||||
if (isRefreshing) {
|
||||
return new Promise((resolve, reject) => {
|
||||
@@ -138,14 +166,14 @@ adminApi.interceptors.response.use(
|
||||
return adminApi(originalRequest)
|
||||
} catch (refreshError) {
|
||||
processQueue(refreshError, null)
|
||||
handleAdminTokenExpired()
|
||||
handleAdminTokenExpired(requestToken)
|
||||
return Promise.reject(refreshError)
|
||||
} finally {
|
||||
isRefreshing = false
|
||||
}
|
||||
}
|
||||
|
||||
handleAdminTokenExpired()
|
||||
handleAdminTokenExpired(requestToken)
|
||||
} else if (error.response?.status !== 403) {
|
||||
const errorMsg = (error.response?.data as any)?.message || error.message || '请求失败'
|
||||
showError(errorMsg)
|
||||
@@ -728,14 +756,6 @@ export const adminShopApi = {
|
||||
*/
|
||||
updateShopStatus: (id: IdType, status: number) => {
|
||||
return adminApi.put<boolean>(`/shops/status/${id}`, { status })
|
||||
},
|
||||
/**
|
||||
* `deleteShop` 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.
|
||||
* @param id: IdType caller-supplied value for `id: IdType`
|
||||
*/
|
||||
deleteShop: (id: IdType) => {
|
||||
return adminApi.delete<boolean>(`/shops/delete/${id}`)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,56 @@
|
||||
export const WEB_API_AUTH_FREE_PATHS = [
|
||||
'/user/login',
|
||||
'/user/register',
|
||||
'/user/check/',
|
||||
'/user/refresh-token',
|
||||
'/user/send-verification-code',
|
||||
'/user/phone-login',
|
||||
'/user/wechat-mini/',
|
||||
'/user/reset-password-by-phone',
|
||||
'/legal-agreement/current',
|
||||
'/api/legal-agreement/current',
|
||||
'/product/get/',
|
||||
'/product/list/',
|
||||
'/comment/list/product/',
|
||||
'/shop/get/',
|
||||
'/shop/list/public',
|
||||
'/shop/list/simple',
|
||||
'/tag/list/all',
|
||||
'/file/get-signed-url/',
|
||||
'/admin/auth/login',
|
||||
'/admin/auth/login-shops/',
|
||||
'/admin/auth/refresh'
|
||||
] as const
|
||||
|
||||
export const ADMIN_API_AUTH_FREE_PATHS = [
|
||||
'/auth/login',
|
||||
'/auth/login-shops/',
|
||||
'/auth/refresh'
|
||||
] as const
|
||||
|
||||
const normalizePathname = (url?: string) => {
|
||||
const raw = String(url || '')
|
||||
const withoutHash = raw.split('#')[0] || ''
|
||||
const withoutQuery = withoutHash.split('?')[0] || ''
|
||||
try {
|
||||
return new URL(withoutQuery, 'http://yuminail.local').pathname
|
||||
} catch {
|
||||
return withoutQuery.startsWith('/') ? withoutQuery : `/${withoutQuery}`
|
||||
}
|
||||
}
|
||||
|
||||
const matchesAuthFreePath = (url: string | undefined, path: string) => {
|
||||
const pathname = normalizePathname(url)
|
||||
if (path.endsWith('/')) {
|
||||
return pathname === path.slice(0, -1) || pathname.startsWith(path)
|
||||
}
|
||||
return pathname === path
|
||||
}
|
||||
|
||||
export const isApiAuthFreePath = (url?: string) => {
|
||||
return WEB_API_AUTH_FREE_PATHS.some(path => matchesAuthFreePath(url, path))
|
||||
}
|
||||
|
||||
export const isAdminApiAuthFreePath = (url?: string) => {
|
||||
return ADMIN_API_AUTH_FREE_PATHS.some(path => matchesAuthFreePath(url, path))
|
||||
}
|
||||
@@ -11,6 +11,7 @@ import { API_BASE_URL } from '../config/api'
|
||||
import type { IdType } from '@/utils/id'
|
||||
import { clearAdminSessionStorage } from '@/utils/admin-session'
|
||||
import { attachRequestSignature } from '@/utils/request-signature'
|
||||
import { isApiAuthFreePath } from './auth-free-paths'
|
||||
|
||||
// 防重复提示标志
|
||||
let lastErrorTime = 0
|
||||
@@ -31,6 +32,55 @@ let failedQueue: Array<{
|
||||
reject: (reason?: any) => void
|
||||
}> = []
|
||||
|
||||
const getStoredAccessToken = (isAdmin = false) => {
|
||||
return isAdmin
|
||||
? (localStorage.getItem('adminAccessToken') || sessionStorage.getItem('adminAccessToken'))
|
||||
: (localStorage.getItem('accessToken') || sessionStorage.getItem('accessToken'))
|
||||
}
|
||||
|
||||
const getStoredRefreshToken = (isAdmin = false) => {
|
||||
return isAdmin
|
||||
? (localStorage.getItem('adminRefreshToken') || sessionStorage.getItem('adminRefreshToken'))
|
||||
: (localStorage.getItem('refreshToken') || sessionStorage.getItem('refreshToken'))
|
||||
}
|
||||
|
||||
const getRequestToken = (request: any) => {
|
||||
if (request?._authToken) {
|
||||
return request._authToken as string
|
||||
}
|
||||
|
||||
const authHeader = request?.headers?.Authorization || request?.headers?.authorization
|
||||
if (typeof authHeader !== 'string') {
|
||||
return null
|
||||
}
|
||||
|
||||
return authHeader.startsWith('Bearer ') ? authHeader.slice('Bearer '.length) : null
|
||||
}
|
||||
|
||||
const isCurrentStoredToken = (token: string | null, isAdmin = false) => {
|
||||
return Boolean(token && token === getStoredAccessToken(isAdmin))
|
||||
}
|
||||
|
||||
const getResponseMessage = (error: AxiosError) => {
|
||||
return (error.response?.data as any)?.message || error.message || '请求失败'
|
||||
}
|
||||
|
||||
const isTokenExpiredResponse = (error: AxiosError, requestToken: string | null) => {
|
||||
const messageText = getResponseMessage(error)
|
||||
return Boolean(
|
||||
requestToken
|
||||
&& (
|
||||
messageText.includes('Token')
|
||||
|| messageText.includes('token')
|
||||
|| messageText.includes('登录态')
|
||||
|| messageText.includes('登录已过期')
|
||||
|| messageText.includes('未登录')
|
||||
|| messageText.includes('认证')
|
||||
|| messageText.includes('重新登录')
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
const processQueue = (error: any, token: string | null = null) => {
|
||||
failedQueue.forEach(prom => {
|
||||
if (error) {
|
||||
@@ -53,32 +103,14 @@ const showError = (msg: string) => {
|
||||
}
|
||||
|
||||
const isAuthFreePath = (url?: string) => {
|
||||
return [
|
||||
'/user/login',
|
||||
'/user/register',
|
||||
'/user/check/',
|
||||
'/user/refresh-token',
|
||||
'/user/send-verification-code',
|
||||
'/user/phone-login',
|
||||
'/user/wechat-mini/',
|
||||
'/user/reset-password-by-phone',
|
||||
'/legal-agreement/current',
|
||||
'/api/legal-agreement/current',
|
||||
'/product/get/',
|
||||
'/product/list/',
|
||||
'/comment/list/product/',
|
||||
'/shop/get/',
|
||||
'/shop/list/public',
|
||||
'/shop/list/simple',
|
||||
'/tag/list/all',
|
||||
'/file/get-signed-url/',
|
||||
'/admin/auth/login',
|
||||
'/admin/auth/login-shops/',
|
||||
'/admin/auth/refresh'
|
||||
].some(path => String(url || '').includes(path))
|
||||
return isApiAuthFreePath(url)
|
||||
}
|
||||
|
||||
const handleTokenExpired = (isAdmin = false) => {
|
||||
const handleTokenExpired = (isAdmin = false, failedToken: string | null = null) => {
|
||||
if (!isCurrentStoredToken(failedToken, isAdmin)) {
|
||||
return
|
||||
}
|
||||
|
||||
// 清理token和用户信息
|
||||
if (isAdmin) {
|
||||
// 清理后台管理的token
|
||||
@@ -89,6 +121,7 @@ const handleTokenExpired = (isAdmin = false) => {
|
||||
localStorage.removeItem('refreshToken')
|
||||
localStorage.removeItem('userInfo')
|
||||
sessionStorage.removeItem('accessToken')
|
||||
sessionStorage.removeItem('refreshToken')
|
||||
}
|
||||
|
||||
// 显示错误提示
|
||||
@@ -124,6 +157,7 @@ api.interceptors.request.use(
|
||||
if (token) {
|
||||
config.headers.Authorization = `Bearer ${token}`
|
||||
}
|
||||
;(config as any)._authToken = token || null
|
||||
return attachRequestSignature(config, token, {
|
||||
authFree: isAuthFreePath(config.url)
|
||||
})
|
||||
@@ -149,28 +183,23 @@ api.interceptors.response.use(
|
||||
const originalRequest = error.config as any
|
||||
|
||||
const isWhitelistedPath = (url: string) => {
|
||||
return url?.includes('/user/login') ||
|
||||
url?.includes('/user/register') ||
|
||||
url?.includes('/user/check/') ||
|
||||
url?.includes('/user/refresh-token') ||
|
||||
url?.includes('/user/send-verification-code') ||
|
||||
url?.includes('/user/phone-login') ||
|
||||
url?.includes('/legal-agreement/current') ||
|
||||
url?.includes('/product/get/') ||
|
||||
url?.includes('/product/list/') ||
|
||||
url?.includes('/comment/list/product/') ||
|
||||
url?.includes('/shop/get/') ||
|
||||
url?.includes('/shop/list/public') ||
|
||||
url?.includes('/shop/list/simple') ||
|
||||
url?.includes('/tag/list/all') ||
|
||||
url?.includes('/file/get-signed-url/') ||
|
||||
url?.includes('/admin/auth/login') ||
|
||||
url?.includes('/admin/auth/refresh')
|
||||
return isApiAuthFreePath(url)
|
||||
}
|
||||
|
||||
if (error.response?.status === 401) {
|
||||
// 检查是否是后台管理的API请求
|
||||
const isAdminRequest = originalRequest.url?.includes('/admin/') || originalRequest.url?.includes('/order/admin/')
|
||||
const requestToken = getRequestToken(originalRequest)
|
||||
const isRealTokenExpired = isTokenExpiredResponse(error, requestToken)
|
||||
|
||||
if (!isRealTokenExpired) {
|
||||
showError(getResponseMessage(error))
|
||||
return Promise.reject(error)
|
||||
}
|
||||
|
||||
if (!isCurrentStoredToken(requestToken, isAdminRequest)) {
|
||||
return Promise.reject(error)
|
||||
}
|
||||
|
||||
if (!originalRequest._retry && !isWhitelistedPath(originalRequest.url)) {
|
||||
if (isRefreshing) {
|
||||
@@ -179,6 +208,7 @@ api.interceptors.response.use(
|
||||
}).then(token => {
|
||||
if (token) {
|
||||
originalRequest.headers.Authorization = `Bearer ${token}`
|
||||
originalRequest._authToken = token
|
||||
}
|
||||
return api(originalRequest)
|
||||
}).catch(err => {
|
||||
@@ -192,9 +222,9 @@ api.interceptors.response.use(
|
||||
try {
|
||||
let refreshToken
|
||||
if (isAdminRequest) {
|
||||
refreshToken = localStorage.getItem('adminRefreshToken') || sessionStorage.getItem('adminRefreshToken')
|
||||
refreshToken = getStoredRefreshToken(true)
|
||||
} else {
|
||||
refreshToken = localStorage.getItem('refreshToken') || sessionStorage.getItem('refreshToken')
|
||||
refreshToken = getStoredRefreshToken(false)
|
||||
}
|
||||
|
||||
if (!refreshToken) {
|
||||
@@ -217,21 +247,23 @@ api.interceptors.response.use(
|
||||
localStorage.setItem('accessToken', newToken)
|
||||
localStorage.setItem('refreshToken', newRefreshToken)
|
||||
sessionStorage.setItem('accessToken', newToken)
|
||||
sessionStorage.setItem('refreshToken', newRefreshToken)
|
||||
}
|
||||
|
||||
processQueue(null, newToken)
|
||||
|
||||
originalRequest.headers.Authorization = `Bearer ${newToken}`
|
||||
originalRequest._authToken = newToken
|
||||
return api(originalRequest)
|
||||
} catch (refreshError) {
|
||||
processQueue(refreshError, null)
|
||||
handleTokenExpired(isAdminRequest)
|
||||
handleTokenExpired(isAdminRequest, requestToken)
|
||||
return Promise.reject(refreshError)
|
||||
} finally {
|
||||
isRefreshing = false
|
||||
}
|
||||
} else {
|
||||
handleTokenExpired(isAdminRequest)
|
||||
handleTokenExpired(isAdminRequest, requestToken)
|
||||
return Promise.reject(error)
|
||||
}
|
||||
} else if (error.response?.status !== 403) { // 403权限不足不提示
|
||||
|
||||
@@ -40,6 +40,77 @@ export interface ArtistCalendarAppointment {
|
||||
durationMinutes: number
|
||||
}
|
||||
|
||||
export interface OrderArtistReviewVO {
|
||||
id: IdType
|
||||
orderId: IdType
|
||||
orderItemId: IdType
|
||||
productId?: IdType
|
||||
productTitle?: string
|
||||
artistId?: IdType
|
||||
artistName?: string
|
||||
artistAvatar?: string
|
||||
userId?: IdType
|
||||
rating?: number
|
||||
content?: string
|
||||
imageFileIds?: IdType[]
|
||||
status?: number
|
||||
statusText?: string
|
||||
submitTime?: string
|
||||
createTime?: string
|
||||
}
|
||||
|
||||
export interface OrderArtistReviewSubmitRequest {
|
||||
rating: number
|
||||
content?: string
|
||||
imageFileIds: IdType[]
|
||||
}
|
||||
|
||||
export interface OrderArtistChangeOptionsVO {
|
||||
orderId: IdType
|
||||
orderItemId: IdType
|
||||
currentArtistId?: IdType
|
||||
currentArtistName?: string
|
||||
artists: Array<{
|
||||
artistId: IdType
|
||||
artistName: string
|
||||
artistAvatar?: string
|
||||
userType?: number
|
||||
participateProduction?: boolean
|
||||
}>
|
||||
}
|
||||
|
||||
export interface OrderArtistChangeRequestVO {
|
||||
id: IdType
|
||||
orderId: IdType
|
||||
orderItemId: IdType
|
||||
productId?: IdType
|
||||
productTitle?: string
|
||||
shopId?: IdType
|
||||
userId?: IdType
|
||||
originalArtistId?: IdType
|
||||
originalArtistName?: string
|
||||
requestedArtistId?: IdType
|
||||
requestedArtistName?: string
|
||||
status?: string
|
||||
statusText?: string
|
||||
reason?: string
|
||||
rejectReason?: string
|
||||
reviewerId?: IdType
|
||||
reviewTime?: string
|
||||
createTime?: string
|
||||
}
|
||||
|
||||
export interface OrderArtistChangeRequestSubmitRequest {
|
||||
orderId: IdType
|
||||
orderItemId: IdType
|
||||
requestedArtistId: IdType
|
||||
reason: string
|
||||
}
|
||||
|
||||
export interface OrderArtistChangeRejectRequest {
|
||||
rejectReason?: string
|
||||
}
|
||||
|
||||
/**
|
||||
* orderApi 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.
|
||||
@@ -59,6 +130,40 @@ export const orderApi = {
|
||||
getOrderList: async (): Promise<any[]> => {
|
||||
return await api.get<any[]>('/order/list') as unknown as any[]
|
||||
},
|
||||
|
||||
getMyPendingReviews: async (): Promise<OrderArtistReviewVO[]> => {
|
||||
return await api.get<OrderArtistReviewVO[]>('/order/review/my-pending') as unknown as OrderArtistReviewVO[]
|
||||
},
|
||||
|
||||
getOrderReviews: async (orderId: IdType): Promise<OrderArtistReviewVO[]> => {
|
||||
return await api.get<OrderArtistReviewVO[]>(`/order/${orderId}/reviews`) as unknown as OrderArtistReviewVO[]
|
||||
},
|
||||
|
||||
submitArtistReview: async (reviewId: IdType, data: OrderArtistReviewSubmitRequest): Promise<OrderArtistReviewVO> => {
|
||||
return await api.post<OrderArtistReviewVO>(`/order/review/${reviewId}/submit`, data) as unknown as OrderArtistReviewVO
|
||||
},
|
||||
|
||||
getArtistChangeOptions: async (orderId: IdType, orderItemId: IdType): Promise<OrderArtistChangeOptionsVO> => {
|
||||
return await api.get<OrderArtistChangeOptionsVO>(`/order/${orderId}/artist-change/options`, {
|
||||
params: { orderItemId }
|
||||
}) as unknown as OrderArtistChangeOptionsVO
|
||||
},
|
||||
|
||||
requestArtistChange: async (data: OrderArtistChangeRequestSubmitRequest): Promise<OrderArtistChangeRequestVO> => {
|
||||
return await api.post<OrderArtistChangeRequestVO>('/order/artist-change/request', data) as unknown as OrderArtistChangeRequestVO
|
||||
},
|
||||
|
||||
getMyPendingArtistChangeRequests: async (): Promise<OrderArtistChangeRequestVO[]> => {
|
||||
return await api.get<OrderArtistChangeRequestVO[]>('/order/artist-change/my-pending') as unknown as OrderArtistChangeRequestVO[]
|
||||
},
|
||||
|
||||
approveArtistChange: async (requestId: IdType): Promise<OrderArtistChangeRequestVO> => {
|
||||
return await api.put<OrderArtistChangeRequestVO>(`/order/artist-change/${requestId}/approve`) as unknown as OrderArtistChangeRequestVO
|
||||
},
|
||||
|
||||
rejectArtistChange: async (requestId: IdType, data?: OrderArtistChangeRejectRequest): Promise<OrderArtistChangeRequestVO> => {
|
||||
return await api.put<OrderArtistChangeRequestVO>(`/order/artist-change/${requestId}/reject`, data || {}) as unknown as OrderArtistChangeRequestVO
|
||||
},
|
||||
|
||||
// 获取订单详情
|
||||
/**
|
||||
|
||||
@@ -180,6 +180,9 @@ export interface SystemMessageVO {
|
||||
publisherName?: string
|
||||
targetType?: string
|
||||
targetTypeName?: string
|
||||
businessType?: string
|
||||
businessId?: IdType
|
||||
actionPath?: string
|
||||
popupEnabled?: number
|
||||
popupShown?: number
|
||||
readStatus?: number
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
:title="title"
|
||||
:width="mergedWidth"
|
||||
:centered="!isMobile"
|
||||
:wrap-class-name="isMobile ? 'admin-mobile-modal' : undefined"
|
||||
:wrap-class-name="mergedWrapClassName"
|
||||
:style="mergedStyle"
|
||||
:body-style="mergedBodyStyle"
|
||||
@update:open="handleOpenChange"
|
||||
@@ -25,18 +25,23 @@
|
||||
* Call guide: the template binds the reactive state below, and the methods are triggered by button clicks, lifecycle hooks, or router events.
|
||||
*/
|
||||
import type { CSSProperties } from 'vue'
|
||||
import { computed } from 'vue'
|
||||
import { computed, useAttrs } from 'vue'
|
||||
import { useAdminViewport } from '@/composables/useAdminViewport'
|
||||
import { CONFIRM_ENTER_DISABLED_CLASS } from '@/composables/useConfirmEnter'
|
||||
|
||||
let modalInstanceSeed = 0
|
||||
|
||||
const props = withDefaults(defineProps<{
|
||||
open: boolean
|
||||
title?: string
|
||||
desktopWidth?: string | number
|
||||
mobileBodyPadding?: string
|
||||
confirmOnEnter?: boolean
|
||||
}>(), {
|
||||
title: '',
|
||||
desktopWidth: 720,
|
||||
mobileBodyPadding: '16px 16px 104px'
|
||||
mobileBodyPadding: '16px 16px 104px',
|
||||
confirmOnEnter: true
|
||||
})
|
||||
|
||||
const emit = defineEmits<{
|
||||
@@ -46,6 +51,8 @@ const emit = defineEmits<{
|
||||
}>()
|
||||
|
||||
const { isMobile } = useAdminViewport()
|
||||
const attrs = useAttrs()
|
||||
const modalInstanceClass = `admin-responsive-modal-${modalInstanceSeed++}`
|
||||
|
||||
/** mergedWidth is a reactive state variable used by the template and event handlers. */
|
||||
const mergedWidth = computed(() => (isMobile.value ? '100vw' : props.desktopWidth))
|
||||
@@ -59,6 +66,16 @@ const mergedStyle = computed(() => (
|
||||
}
|
||||
: undefined
|
||||
))
|
||||
const mergedWrapClassName = computed(() => (
|
||||
[
|
||||
attrs.wrapClassName || attrs['wrap-class-name'],
|
||||
isMobile.value ? 'admin-mobile-modal' : '',
|
||||
props.confirmOnEnter ? '' : CONFIRM_ENTER_DISABLED_CLASS,
|
||||
modalInstanceClass
|
||||
]
|
||||
.filter(Boolean)
|
||||
.join(' ')
|
||||
))
|
||||
/** mergedBodyStyle is a reactive state variable used by the template and event handlers. */
|
||||
const mergedBodyStyle = computed(() => (
|
||||
isMobile.value
|
||||
|
||||
@@ -0,0 +1,238 @@
|
||||
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
|
||||
import { createApp } from 'vue'
|
||||
import { useGlobalConfirmEnter } from './useConfirmEnter'
|
||||
|
||||
const visibleRects = [{
|
||||
bottom: 100,
|
||||
height: 100,
|
||||
left: 0,
|
||||
right: 100,
|
||||
top: 0,
|
||||
width: 100,
|
||||
x: 0,
|
||||
y: 0,
|
||||
toJSON: () => ({})
|
||||
}] as DOMRect[]
|
||||
|
||||
const makeVisible = (element: HTMLElement) => {
|
||||
vi.spyOn(element, 'getClientRects').mockReturnValue(visibleRects as unknown as DOMRectList)
|
||||
}
|
||||
|
||||
const setDesktopViewport = () => {
|
||||
Object.defineProperty(window, 'innerWidth', {
|
||||
configurable: true,
|
||||
value: 1280
|
||||
})
|
||||
window.matchMedia = vi.fn().mockImplementation((query: string) => ({
|
||||
matches: query === '(pointer: coarse)' ? false : false,
|
||||
media: query,
|
||||
onchange: null,
|
||||
addEventListener: vi.fn(),
|
||||
removeEventListener: vi.fn(),
|
||||
addListener: vi.fn(),
|
||||
removeListener: vi.fn(),
|
||||
dispatchEvent: vi.fn()
|
||||
}))
|
||||
}
|
||||
|
||||
const setMobileViewport = () => {
|
||||
Object.defineProperty(window, 'innerWidth', {
|
||||
configurable: true,
|
||||
value: 640
|
||||
})
|
||||
}
|
||||
|
||||
const setCoarsePointer = () => {
|
||||
Object.defineProperty(window, 'innerWidth', {
|
||||
configurable: true,
|
||||
value: 1280
|
||||
})
|
||||
window.matchMedia = vi.fn().mockImplementation((query: string) => ({
|
||||
matches: query === '(pointer: coarse)',
|
||||
media: query,
|
||||
onchange: null,
|
||||
addEventListener: vi.fn(),
|
||||
removeEventListener: vi.fn(),
|
||||
addListener: vi.fn(),
|
||||
removeListener: vi.fn(),
|
||||
dispatchEvent: vi.fn()
|
||||
}))
|
||||
}
|
||||
|
||||
const mountGlobalConfirmEnter = () => {
|
||||
const host = document.createElement('div')
|
||||
document.body.appendChild(host)
|
||||
|
||||
const app = createApp({
|
||||
setup() {
|
||||
useGlobalConfirmEnter()
|
||||
return () => null
|
||||
}
|
||||
})
|
||||
|
||||
app.mount(host)
|
||||
|
||||
return () => {
|
||||
app.unmount()
|
||||
host.remove()
|
||||
}
|
||||
}
|
||||
|
||||
const createModal = ({
|
||||
zIndex = 1000,
|
||||
buttonClass = '',
|
||||
disabled = false,
|
||||
ariaDisabled = false,
|
||||
footerClass = 'ant-modal-footer'
|
||||
}: {
|
||||
zIndex?: number
|
||||
buttonClass?: string
|
||||
disabled?: boolean
|
||||
ariaDisabled?: boolean
|
||||
footerClass?: 'ant-modal-footer' | 'ant-modal-confirm-btns'
|
||||
} = {}) => {
|
||||
const wrap = document.createElement('div')
|
||||
wrap.className = 'ant-modal-wrap'
|
||||
wrap.style.zIndex = String(zIndex)
|
||||
|
||||
const footer = document.createElement('div')
|
||||
footer.className = footerClass
|
||||
|
||||
const button = document.createElement('button')
|
||||
button.type = 'button'
|
||||
button.className = `ant-btn ant-btn-primary ${buttonClass}`.trim()
|
||||
button.disabled = disabled
|
||||
if (ariaDisabled) {
|
||||
button.setAttribute('aria-disabled', 'true')
|
||||
}
|
||||
|
||||
const onClick = vi.fn()
|
||||
const click = vi.spyOn(button, 'click')
|
||||
button.addEventListener('click', onClick)
|
||||
|
||||
footer.appendChild(button)
|
||||
wrap.appendChild(footer)
|
||||
document.body.appendChild(wrap)
|
||||
makeVisible(wrap)
|
||||
makeVisible(button)
|
||||
|
||||
return { wrap, button, click, onClick }
|
||||
}
|
||||
|
||||
const createKeyboardEvent = () => new KeyboardEvent('keydown', {
|
||||
key: 'Enter',
|
||||
bubbles: true,
|
||||
cancelable: true
|
||||
})
|
||||
|
||||
const pressEnter = (target: EventTarget = document) => {
|
||||
const event = createKeyboardEvent()
|
||||
target.dispatchEvent(event)
|
||||
return event
|
||||
}
|
||||
|
||||
describe('useGlobalConfirmEnter', () => {
|
||||
let unmount: (() => void) | undefined
|
||||
|
||||
beforeEach(() => {
|
||||
document.body.innerHTML = ''
|
||||
setDesktopViewport()
|
||||
unmount = mountGlobalConfirmEnter()
|
||||
})
|
||||
|
||||
afterEach(() => {
|
||||
unmount?.()
|
||||
document.body.innerHTML = ''
|
||||
vi.restoreAllMocks()
|
||||
})
|
||||
|
||||
it('clicks the visible top modal primary ok button when PC users press Enter', () => {
|
||||
const { onClick } = createModal()
|
||||
|
||||
const event = pressEnter()
|
||||
|
||||
expect(onClick).toHaveBeenCalledTimes(1)
|
||||
expect(event.defaultPrevented).toBe(true)
|
||||
})
|
||||
|
||||
it('does not click the ok button when Enter starts inside textarea or contenteditable elements', () => {
|
||||
const { onClick } = createModal()
|
||||
|
||||
const textarea = document.createElement('textarea')
|
||||
document.body.appendChild(textarea)
|
||||
pressEnter(textarea)
|
||||
|
||||
const editable = document.createElement('div')
|
||||
editable.setAttribute('contenteditable', 'true')
|
||||
document.body.appendChild(editable)
|
||||
pressEnter(editable)
|
||||
|
||||
expect(onClick).not.toHaveBeenCalled()
|
||||
})
|
||||
|
||||
it.each([
|
||||
'ant-select-dropdown',
|
||||
'ant-picker-dropdown',
|
||||
'ant-dropdown',
|
||||
'ant-popover'
|
||||
])('does not click the ok button while %s is open', (dropdownClass) => {
|
||||
const { onClick } = createModal()
|
||||
const popup = document.createElement('div')
|
||||
popup.className = dropdownClass
|
||||
document.body.appendChild(popup)
|
||||
|
||||
pressEnter()
|
||||
|
||||
expect(onClick).not.toHaveBeenCalled()
|
||||
})
|
||||
|
||||
it('does not click disabled or loading ok buttons', () => {
|
||||
const disabledModal = createModal({ disabled: true })
|
||||
pressEnter()
|
||||
expect(disabledModal.click).not.toHaveBeenCalled()
|
||||
expect(disabledModal.onClick).not.toHaveBeenCalled()
|
||||
disabledModal.wrap.remove()
|
||||
|
||||
const ariaDisabledModal = createModal({ ariaDisabled: true })
|
||||
pressEnter()
|
||||
expect(ariaDisabledModal.click).not.toHaveBeenCalled()
|
||||
expect(ariaDisabledModal.onClick).not.toHaveBeenCalled()
|
||||
ariaDisabledModal.wrap.remove()
|
||||
|
||||
const loadingModal = createModal({ buttonClass: 'ant-btn-loading' })
|
||||
pressEnter()
|
||||
expect(loadingModal.click).not.toHaveBeenCalled()
|
||||
expect(loadingModal.onClick).not.toHaveBeenCalled()
|
||||
})
|
||||
|
||||
it('does not click the ok button on mobile width or coarse pointer devices', () => {
|
||||
const mobileModal = createModal()
|
||||
setMobileViewport()
|
||||
pressEnter()
|
||||
expect(mobileModal.onClick).not.toHaveBeenCalled()
|
||||
mobileModal.wrap.remove()
|
||||
|
||||
const coarsePointerModal = createModal()
|
||||
setCoarsePointer()
|
||||
pressEnter()
|
||||
expect(coarsePointerModal.onClick).not.toHaveBeenCalled()
|
||||
})
|
||||
|
||||
it('clicks only the z-index and DOM-top modal when multiple modals are visible', () => {
|
||||
const firstModal = createModal({ zIndex: 1000 })
|
||||
const secondModal = createModal({ zIndex: 1000 })
|
||||
const topZIndexModal = createModal({ zIndex: 1200 })
|
||||
|
||||
pressEnter()
|
||||
|
||||
expect(firstModal.onClick).not.toHaveBeenCalled()
|
||||
expect(secondModal.onClick).not.toHaveBeenCalled()
|
||||
expect(topZIndexModal.onClick).toHaveBeenCalledTimes(1)
|
||||
|
||||
topZIndexModal.wrap.remove()
|
||||
pressEnter()
|
||||
|
||||
expect(firstModal.onClick).not.toHaveBeenCalled()
|
||||
expect(secondModal.onClick).toHaveBeenCalledTimes(1)
|
||||
})
|
||||
})
|
||||
@@ -0,0 +1,179 @@
|
||||
import { computed, onBeforeUnmount, onMounted, type ComputedRef } from 'vue'
|
||||
|
||||
interface UseConfirmEnterOptions {
|
||||
enabled: ComputedRef<boolean>
|
||||
onConfirm: (event: KeyboardEvent) => void
|
||||
isConfirmDisabled?: () => boolean
|
||||
isTopLayer?: () => boolean
|
||||
}
|
||||
|
||||
export const CONFIRM_ENTER_DISABLED_CLASS = 'confirm-enter-disabled'
|
||||
const DESKTOP_MIN_WIDTH = 960
|
||||
|
||||
const isEditableTarget = (target: EventTarget | null) => {
|
||||
if (!(target instanceof HTMLElement)) {
|
||||
return false
|
||||
}
|
||||
|
||||
if (target.isContentEditable) {
|
||||
return true
|
||||
}
|
||||
|
||||
return target.tagName.toLowerCase() === 'textarea' || Boolean(target.closest('[contenteditable="true"]'))
|
||||
}
|
||||
|
||||
const hasOpenPickerOrDropdown = () => {
|
||||
return Boolean(document.querySelector([
|
||||
'.ant-select-dropdown:not(.ant-select-dropdown-hidden)',
|
||||
'.ant-picker-dropdown:not(.ant-picker-dropdown-hidden)',
|
||||
'.ant-cascader-dropdown:not(.ant-cascader-dropdown-hidden)',
|
||||
'.ant-dropdown:not(.ant-dropdown-hidden)',
|
||||
'.ant-popover:not(.ant-popover-hidden)'
|
||||
].join(',')))
|
||||
}
|
||||
|
||||
const isDesktopViewport = () => {
|
||||
if (typeof window === 'undefined') {
|
||||
return false
|
||||
}
|
||||
|
||||
const coarsePointer = window.matchMedia?.('(pointer: coarse)').matches ?? false
|
||||
return window.innerWidth > DESKTOP_MIN_WIDTH && !coarsePointer
|
||||
}
|
||||
|
||||
const isVisibleElement = (element: Element) => {
|
||||
if (!(element instanceof HTMLElement)) {
|
||||
return false
|
||||
}
|
||||
|
||||
const style = window.getComputedStyle(element)
|
||||
return style.display !== 'none'
|
||||
&& style.visibility !== 'hidden'
|
||||
&& style.opacity !== '0'
|
||||
&& element.getClientRects().length > 0
|
||||
}
|
||||
|
||||
const isDisabledButton = (button: HTMLButtonElement) => {
|
||||
return button.disabled
|
||||
|| button.getAttribute('aria-disabled') === 'true'
|
||||
|| button.classList.contains('ant-btn-loading')
|
||||
|| button.classList.contains('ant-btn-disabled')
|
||||
}
|
||||
|
||||
const getTopModalWrap = () => {
|
||||
const modals = Array.from(document.querySelectorAll<HTMLElement>('.ant-modal-wrap'))
|
||||
.filter(isVisibleElement)
|
||||
|
||||
if (!modals.length) {
|
||||
return null
|
||||
}
|
||||
|
||||
const sortedModals = modals
|
||||
.map((modal, index) => {
|
||||
const zIndex = Number.parseInt(window.getComputedStyle(modal).zIndex || '0', 10)
|
||||
return {
|
||||
modal,
|
||||
index,
|
||||
zIndex: Number.isNaN(zIndex) ? 0 : zIndex
|
||||
}
|
||||
})
|
||||
.sort((left, right) => left.zIndex - right.zIndex || left.index - right.index)
|
||||
|
||||
return sortedModals[sortedModals.length - 1]?.modal ?? null
|
||||
}
|
||||
|
||||
const getTopModalConfirmButton = () => {
|
||||
const topModal = getTopModalWrap()
|
||||
if (!topModal || topModal.classList.contains(CONFIRM_ENTER_DISABLED_CLASS)) {
|
||||
return null
|
||||
}
|
||||
|
||||
const button = topModal.querySelector<HTMLButtonElement>([
|
||||
'.ant-modal-confirm-btns .ant-btn-primary',
|
||||
'.ant-modal-footer .ant-btn-primary'
|
||||
].join(','))
|
||||
|
||||
if (!button || !isVisibleElement(button) || isDisabledButton(button)) {
|
||||
return null
|
||||
}
|
||||
|
||||
return button
|
||||
}
|
||||
|
||||
export const useConfirmEnter = ({
|
||||
enabled,
|
||||
onConfirm,
|
||||
isConfirmDisabled,
|
||||
isTopLayer
|
||||
}: UseConfirmEnterOptions) => {
|
||||
const canConfirm = computed(() => (
|
||||
enabled.value
|
||||
&& !(isConfirmDisabled?.() ?? false)
|
||||
&& (isTopLayer?.() ?? true)
|
||||
))
|
||||
|
||||
const handleKeydown = (event: KeyboardEvent) => {
|
||||
if (
|
||||
event.key !== 'Enter'
|
||||
|| event.defaultPrevented
|
||||
|| event.shiftKey
|
||||
|| event.ctrlKey
|
||||
|| event.altKey
|
||||
|| event.metaKey
|
||||
|| event.isComposing
|
||||
|| !canConfirm.value
|
||||
|| isEditableTarget(event.target)
|
||||
|| hasOpenPickerOrDropdown()
|
||||
) {
|
||||
return
|
||||
}
|
||||
|
||||
event.preventDefault()
|
||||
onConfirm(event)
|
||||
}
|
||||
|
||||
onMounted(() => {
|
||||
document.addEventListener('keydown', handleKeydown)
|
||||
})
|
||||
|
||||
onBeforeUnmount(() => {
|
||||
document.removeEventListener('keydown', handleKeydown)
|
||||
})
|
||||
}
|
||||
|
||||
export const useGlobalConfirmEnter = () => {
|
||||
const handleKeydown = (event: KeyboardEvent) => {
|
||||
if (
|
||||
event.key !== 'Enter'
|
||||
|| event.defaultPrevented
|
||||
|| event.shiftKey
|
||||
|| event.ctrlKey
|
||||
|| event.altKey
|
||||
|| event.metaKey
|
||||
|| event.isComposing
|
||||
|| (event as KeyboardEvent & { keyCode?: number }).keyCode === 229
|
||||
|| !isDesktopViewport()
|
||||
|| isEditableTarget(event.target)
|
||||
|| hasOpenPickerOrDropdown()
|
||||
) {
|
||||
return
|
||||
}
|
||||
|
||||
const confirmButton = getTopModalConfirmButton()
|
||||
if (!confirmButton) {
|
||||
return
|
||||
}
|
||||
|
||||
event.preventDefault()
|
||||
event.stopImmediatePropagation()
|
||||
confirmButton.click()
|
||||
}
|
||||
|
||||
onMounted(() => {
|
||||
document.addEventListener('keydown', handleKeydown)
|
||||
})
|
||||
|
||||
onBeforeUnmount(() => {
|
||||
document.removeEventListener('keydown', handleKeydown)
|
||||
})
|
||||
}
|
||||
@@ -75,6 +75,13 @@
|
||||
<div class="title">{{ item.productTitle }}</div>
|
||||
<div class="line">¥{{ item.price.toFixed(2) }} x {{ item.quantity }}</div>
|
||||
<div v-if="item.appointmentTime" class="line appointment">预约时间:{{ item.appointmentTime }}</div>
|
||||
<div v-if="pendingArtistChangeForItem(order, item)" class="change-status">
|
||||
改派申请处理中:{{ pendingArtistChangeForItem(order, item)?.requestedArtistName || '新美甲师' }}
|
||||
</div>
|
||||
<div v-else-if="canRequestArtistChange(order, item)" class="change-action">
|
||||
<span>需要更换服务美甲师</span>
|
||||
<a-button size="small" @click="openArtistChangeModal(order, item)">申请改派</a-button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -86,6 +93,38 @@
|
||||
</div>
|
||||
</a-card>
|
||||
</main>
|
||||
|
||||
<a-modal
|
||||
v-model:open="artistChangeModalOpen"
|
||||
title="申请改派"
|
||||
:confirm-loading="artistChangeSubmitting"
|
||||
@ok="submitArtistChangeRequest"
|
||||
@cancel="closeArtistChangeModal"
|
||||
>
|
||||
<a-form layout="vertical">
|
||||
<a-form-item label="当前美甲师">
|
||||
<span>{{ artistChangeOptions?.currentArtistName || activeArtistChangeItem?.artistName || '未分配' }}</span>
|
||||
</a-form-item>
|
||||
<a-form-item label="新美甲师" required>
|
||||
<a-select
|
||||
v-model:value="artistChangeForm.requestedArtistId"
|
||||
:loading="artistChangeOptionsLoading"
|
||||
placeholder="请选择新的美甲师"
|
||||
>
|
||||
<a-select-option
|
||||
v-for="artist in selectableArtistOptions"
|
||||
:key="String(artist.artistId)"
|
||||
:value="artist.artistId"
|
||||
>
|
||||
{{ artist.artistName }}
|
||||
</a-select-option>
|
||||
</a-select>
|
||||
</a-form-item>
|
||||
<a-form-item label="改派原因" required>
|
||||
<a-textarea v-model:value="artistChangeForm.reason" :rows="4" :maxlength="300" placeholder="请说明申请改派的原因" />
|
||||
</a-form-item>
|
||||
</a-form>
|
||||
</a-modal>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
@@ -101,6 +140,7 @@ import { message, Modal } from 'ant-design-vue'
|
||||
import { userApi } from '@/api/user'
|
||||
import { fileApi } from '../api/index'
|
||||
import { orderApi } from '../api/order'
|
||||
import type { OrderArtistChangeOptionsVO, OrderArtistChangeRequestVO } from '../api/order'
|
||||
import type { IdType } from '@/utils/id'
|
||||
import { runWithGlobalLoading } from '@/utils/action-loading'
|
||||
|
||||
@@ -110,6 +150,13 @@ const orders = ref<any[]>([])
|
||||
const imageIdCache = ref<Record<string, string>>({})
|
||||
const orderRefs = ref<Record<string, any>>({})
|
||||
const showCalendarEntry = ref(false)
|
||||
const currentUserId = ref<IdType>()
|
||||
const artistChangeModalOpen = ref(false)
|
||||
const artistChangeSubmitting = ref(false)
|
||||
const artistChangeOptionsLoading = ref(false)
|
||||
const artistChangeOptions = ref<OrderArtistChangeOptionsVO | null>(null)
|
||||
const activeArtistChangeOrder = ref<any | null>(null)
|
||||
const activeArtistChangeItem = ref<any | null>(null)
|
||||
const filters = reactive({
|
||||
keyword: '',
|
||||
source: 'all',
|
||||
@@ -118,6 +165,10 @@ const filters = reactive({
|
||||
minAmount: undefined as number | undefined,
|
||||
maxAmount: undefined as number | undefined
|
||||
})
|
||||
const artistChangeForm = reactive({
|
||||
requestedArtistId: undefined as IdType | undefined,
|
||||
reason: ''
|
||||
})
|
||||
|
||||
/** filteredOrders is a reactive state variable used by the template and event handlers. */
|
||||
const filteredOrders = computed(() => {
|
||||
@@ -182,11 +233,33 @@ const sourceClass = (source?: string) => {
|
||||
return 'source-service'
|
||||
}
|
||||
|
||||
const sameId = (left: unknown, right: unknown) => {
|
||||
return left !== undefined && left !== null && right !== undefined && right !== null && String(left) === String(right)
|
||||
}
|
||||
|
||||
const pendingArtistChangeForItem = (order: any, item: any): OrderArtistChangeRequestVO | undefined => {
|
||||
const itemValue = item?.pendingArtistChangeRequest as OrderArtistChangeRequestVO | undefined
|
||||
if (itemValue) return itemValue
|
||||
const orderValue = order?.pendingArtistChangeRequest as OrderArtistChangeRequestVO | undefined
|
||||
if (!orderValue) return undefined
|
||||
return sameId(orderValue.orderItemId, item.id) || (order.items || []).length === 1 ? orderValue : undefined
|
||||
}
|
||||
|
||||
/** canComplete is a local helper used by this page script. */
|
||||
const canComplete = (order: any) => {
|
||||
return order.status === 1 && order.artistOrderSource !== 'SELF'
|
||||
}
|
||||
|
||||
const canRequestArtistChange = (order: any, item: any) => {
|
||||
const assignedToCurrentUser = !currentUserId.value || !item.artistId || sameId(item.artistId, currentUserId.value)
|
||||
return order.status === 1 && item.id && assignedToCurrentUser && !pendingArtistChangeForItem(order, item)
|
||||
}
|
||||
|
||||
const selectableArtistOptions = computed(() => {
|
||||
const options = artistChangeOptions.value?.artists || []
|
||||
return options.filter(artist => !sameId(artist.artistId, artistChangeOptions.value?.currentArtistId))
|
||||
})
|
||||
|
||||
/** resetFilters is a local helper used by this page script. */
|
||||
const resetFilters = () => {
|
||||
filters.keyword = ''
|
||||
@@ -225,6 +298,7 @@ const loadCalendarAccess = async () => {
|
||||
showCalendarEntry.value = false
|
||||
try {
|
||||
const currentUser = await userApi.getUserInfo()
|
||||
currentUserId.value = currentUser.id
|
||||
if (currentUser.type === 3) {
|
||||
showCalendarEntry.value = true
|
||||
return
|
||||
@@ -234,6 +308,7 @@ const loadCalendarAccess = async () => {
|
||||
showCalendarEntry.value = Number(artistInfo?.participateProduction) === 1
|
||||
}
|
||||
} catch {
|
||||
currentUserId.value = undefined
|
||||
showCalendarEntry.value = false
|
||||
}
|
||||
}
|
||||
@@ -243,6 +318,70 @@ const handleRefreshClick = async () => {
|
||||
await runWithGlobalLoading(() => loadOrders())
|
||||
}
|
||||
|
||||
const openArtistChangeModal = async (order: any, item: any) => {
|
||||
if (!canRequestArtistChange(order, item)) return
|
||||
activeArtistChangeOrder.value = order
|
||||
activeArtistChangeItem.value = item
|
||||
artistChangeOptions.value = null
|
||||
artistChangeForm.requestedArtistId = undefined
|
||||
artistChangeForm.reason = ''
|
||||
artistChangeModalOpen.value = true
|
||||
artistChangeOptionsLoading.value = true
|
||||
try {
|
||||
artistChangeOptions.value = await orderApi.getArtistChangeOptions(order.id, item.id)
|
||||
if (!selectableArtistOptions.value.length) {
|
||||
message.warning('暂无可改派的美甲师')
|
||||
}
|
||||
} catch {
|
||||
message.error('获取可改派美甲师失败')
|
||||
closeArtistChangeModal()
|
||||
} finally {
|
||||
artistChangeOptionsLoading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
const closeArtistChangeModal = () => {
|
||||
artistChangeModalOpen.value = false
|
||||
activeArtistChangeOrder.value = null
|
||||
activeArtistChangeItem.value = null
|
||||
artistChangeOptions.value = null
|
||||
artistChangeForm.requestedArtistId = undefined
|
||||
artistChangeForm.reason = ''
|
||||
}
|
||||
|
||||
const submitArtistChangeRequest = async () => {
|
||||
if (!activeArtistChangeOrder.value || !activeArtistChangeItem.value) return
|
||||
if (!artistChangeForm.requestedArtistId) {
|
||||
message.warning('请选择新的美甲师')
|
||||
return
|
||||
}
|
||||
const reason = artistChangeForm.reason.trim()
|
||||
if (!reason) {
|
||||
message.warning('请填写改派原因')
|
||||
return
|
||||
}
|
||||
if (sameId(artistChangeForm.requestedArtistId, artistChangeOptions.value?.currentArtistId)) {
|
||||
message.warning('新美甲师不能与当前美甲师相同')
|
||||
return
|
||||
}
|
||||
artistChangeSubmitting.value = true
|
||||
try {
|
||||
await orderApi.requestArtistChange({
|
||||
orderId: activeArtistChangeOrder.value.id,
|
||||
orderItemId: activeArtistChangeItem.value.id,
|
||||
requestedArtistId: artistChangeForm.requestedArtistId,
|
||||
reason
|
||||
})
|
||||
message.success('改派申请已提交')
|
||||
closeArtistChangeModal()
|
||||
await loadOrders()
|
||||
} catch {
|
||||
message.error('提交改派申请失败')
|
||||
} finally {
|
||||
artistChangeSubmitting.value = false
|
||||
}
|
||||
}
|
||||
|
||||
/** completeOrder is a local helper used by this page script. */
|
||||
const completeOrder = (orderId: IdType) => {
|
||||
Modal.confirm({
|
||||
@@ -298,6 +437,8 @@ onMounted(async () => {
|
||||
.title { font-weight: 600; color: var(--text-primary); }
|
||||
.line { margin-top: 4px; color: var(--text-secondary); font-size: 13px; }
|
||||
.appointment { color: var(--theme-primary); }
|
||||
.change-status { margin-top: 8px; padding: 8px 10px; border-radius: 8px; background: var(--theme-primary-soft); color: var(--theme-primary); font-size: 13px; }
|
||||
.change-action { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-top: 8px; padding: 8px 10px; border-radius: 8px; background: var(--theme-primary-soft); color: var(--theme-primary); font-size: 13px; }
|
||||
|
||||
:deep(.ant-btn-primary) { background: var(--theme-primary); border-color: var(--theme-primary); }
|
||||
:deep(.ant-btn-link) { color: var(--theme-primary); }
|
||||
|
||||
@@ -925,6 +925,7 @@ const handleSubmit = async () => {
|
||||
localStorage.setItem('refreshToken', loginData.refreshToken)
|
||||
localStorage.setItem('userInfo', JSON.stringify(loginData.userInfo))
|
||||
sessionStorage.setItem('accessToken', loginData.accessToken)
|
||||
sessionStorage.setItem('refreshToken', loginData.refreshToken)
|
||||
notifyShopThemeChanged()
|
||||
|
||||
if (loginData.needSetPassword) {
|
||||
@@ -1110,6 +1111,7 @@ const handleAdminLogin = () => {
|
||||
localStorage.removeItem('adminRefreshToken')
|
||||
localStorage.removeItem('adminUserInfo')
|
||||
sessionStorage.removeItem('accessToken')
|
||||
sessionStorage.removeItem('refreshToken')
|
||||
sessionStorage.removeItem('adminAccessToken')
|
||||
|
||||
window.setTimeout(() => {
|
||||
|
||||
@@ -56,6 +56,22 @@ const currentMessage = ref<SystemMessageVO | null>(null)
|
||||
/** unreadCount is a reactive state variable used by the template and event handlers. */
|
||||
const unreadCount = computed(() => messages.value.filter(item => item.readStatus !== 1).length)
|
||||
|
||||
const resolveSystemMessageActionPath = (item: SystemMessageVO) => {
|
||||
const actionPath = String(item.actionPath || '').trim()
|
||||
if (!actionPath || !actionPath.startsWith('/') || actionPath.startsWith('//')) {
|
||||
return ''
|
||||
}
|
||||
return actionPath
|
||||
}
|
||||
|
||||
const markMessageReadIfNeeded = async (item: SystemMessageVO) => {
|
||||
if (item.readStatus === 1) {
|
||||
return
|
||||
}
|
||||
await userApi.markMessageRead(item.id)
|
||||
item.readStatus = 1
|
||||
}
|
||||
|
||||
/** loadMessages is an async page action. Trigger it from the template or lifecycle hook, then await the result. */
|
||||
const loadMessages = async () => {
|
||||
loading.value = true
|
||||
@@ -70,12 +86,21 @@ const loadMessages = async () => {
|
||||
|
||||
/** openMessage is an async page action. Trigger it from the template or lifecycle hook, then await the result. */
|
||||
const openMessage = async (item: SystemMessageVO) => {
|
||||
try {
|
||||
await markMessageReadIfNeeded(item)
|
||||
} catch (error: any) {
|
||||
message.error(error?.message || '标记已读失败')
|
||||
return
|
||||
}
|
||||
|
||||
const actionPath = resolveSystemMessageActionPath(item)
|
||||
if (actionPath) {
|
||||
await router.push(actionPath)
|
||||
return
|
||||
}
|
||||
|
||||
currentMessage.value = item
|
||||
detailVisible.value = true
|
||||
if (item.readStatus !== 1) {
|
||||
await userApi.markMessageRead(item.id)
|
||||
item.readStatus = 1
|
||||
}
|
||||
}
|
||||
|
||||
onMounted(loadMessages)
|
||||
|
||||
@@ -53,6 +53,28 @@
|
||||
<div class="line">¥{{ item.price.toFixed(2) }} x {{ item.quantity }}</div>
|
||||
<div v-if="item.artistName" class="line">美甲师:{{ item.artistName }}</div>
|
||||
<div v-if="item.appointmentTime" class="line appointment">预约时间:{{ item.appointmentTime }}</div>
|
||||
<div v-if="submittedReviewForItem(order, item)" class="review-summary">
|
||||
已评价:{{ formatRating(submittedReviewForItem(order, item)?.rating) }} 分
|
||||
<span v-if="submittedReviewForItem(order, item)?.content"> · {{ submittedReviewForItem(order, item)?.content }}</span>
|
||||
</div>
|
||||
<div v-else-if="pendingReviewForItem(order, item)" class="review-action">
|
||||
<span>待评价:{{ pendingReviewForItem(order, item)?.artistName || item.artistName || '美甲师' }}</span>
|
||||
<a-button size="small" type="primary" @click="openReviewModal(pendingReviewForItem(order, item))">评价美甲师</a-button>
|
||||
</div>
|
||||
<div v-if="pendingChangeRequestForItem(order, item)" class="change-request">
|
||||
<div class="change-info">
|
||||
<strong>待处理改派申请</strong>
|
||||
<span>
|
||||
{{ pendingChangeRequestForItem(order, item)?.originalArtistName || item.artistName || '原美甲师' }}
|
||||
→ {{ pendingChangeRequestForItem(order, item)?.requestedArtistName || '新美甲师' }}
|
||||
</span>
|
||||
<span v-if="pendingChangeRequestForItem(order, item)?.reason">原因:{{ pendingChangeRequestForItem(order, item)?.reason }}</span>
|
||||
</div>
|
||||
<div class="change-actions">
|
||||
<a-button size="small" type="primary" @click="approveArtistChange(pendingChangeRequestForItem(order, item))">同意</a-button>
|
||||
<a-button size="small" danger @click="openRejectArtistChange(pendingChangeRequestForItem(order, item))">拒绝</a-button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -62,6 +84,44 @@
|
||||
</div>
|
||||
</a-card>
|
||||
</main>
|
||||
|
||||
<a-modal
|
||||
v-model:open="reviewModalOpen"
|
||||
title="评价美甲师"
|
||||
:confirm-loading="reviewSubmitting"
|
||||
@ok="submitReview"
|
||||
@cancel="closeReviewModal"
|
||||
>
|
||||
<a-form layout="vertical">
|
||||
<a-form-item label="评分" required>
|
||||
<a-input-number
|
||||
v-model:value="reviewForm.rating"
|
||||
class="rating-input"
|
||||
:min="0.5"
|
||||
:max="5"
|
||||
:step="0.5"
|
||||
placeholder="0.5-5 分"
|
||||
/>
|
||||
</a-form-item>
|
||||
<a-form-item label="评价内容">
|
||||
<a-textarea v-model:value="reviewForm.content" :rows="4" :maxlength="500" placeholder="写下这次服务体验" />
|
||||
</a-form-item>
|
||||
</a-form>
|
||||
</a-modal>
|
||||
|
||||
<a-modal
|
||||
v-model:open="rejectModalOpen"
|
||||
title="拒绝改派申请"
|
||||
:confirm-loading="changeProcessing"
|
||||
@ok="submitRejectArtistChange"
|
||||
@cancel="closeRejectArtistChange"
|
||||
>
|
||||
<a-form layout="vertical">
|
||||
<a-form-item label="拒绝原因">
|
||||
<a-textarea v-model:value="rejectForm.rejectReason" :rows="3" :maxlength="300" placeholder="可选,请填写拒绝原因" />
|
||||
</a-form-item>
|
||||
</a-form>
|
||||
</a-modal>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
@@ -76,6 +136,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 { OrderArtistChangeRequestVO, OrderArtistReviewVO } from '../api/order'
|
||||
import { userApi } from '@/api/user'
|
||||
import type { IdType } from '@/utils/id'
|
||||
import { runWithGlobalLoading } from '@/utils/action-loading'
|
||||
@@ -83,6 +144,15 @@ import { runWithGlobalLoading } from '@/utils/action-loading'
|
||||
const router = useRouter()
|
||||
const orders = ref<any[]>([])
|
||||
const imageIdCache = ref<Record<string, string>>({})
|
||||
const pendingReviews = ref<OrderArtistReviewVO[]>([])
|
||||
const orderReviews = ref<Record<string, OrderArtistReviewVO[]>>({})
|
||||
const pendingChangeRequests = ref<OrderArtistChangeRequestVO[]>([])
|
||||
const reviewModalOpen = ref(false)
|
||||
const reviewSubmitting = ref(false)
|
||||
const activeReview = ref<OrderArtistReviewVO | null>(null)
|
||||
const rejectModalOpen = ref(false)
|
||||
const changeProcessing = ref(false)
|
||||
const activeChangeRequest = ref<OrderArtistChangeRequestVO | null>(null)
|
||||
const filters = reactive({
|
||||
keyword: '',
|
||||
status: 'all' as 'all' | number,
|
||||
@@ -90,6 +160,13 @@ const filters = reactive({
|
||||
minAmount: undefined as number | undefined,
|
||||
maxAmount: undefined as number | undefined
|
||||
})
|
||||
const reviewForm = reactive({
|
||||
rating: undefined as number | undefined,
|
||||
content: ''
|
||||
})
|
||||
const rejectForm = reactive({
|
||||
rejectReason: ''
|
||||
})
|
||||
|
||||
/** filteredOrders is a reactive state variable used by the template and event handlers. */
|
||||
const filteredOrders = computed(() => {
|
||||
@@ -124,6 +201,40 @@ const statusClass = (status: number) => {
|
||||
return 'cancelled'
|
||||
}
|
||||
|
||||
const sameId = (left: unknown, right: unknown) => {
|
||||
return left !== undefined && left !== null && right !== undefined && right !== null && String(left) === String(right)
|
||||
}
|
||||
|
||||
const embeddedForItem = <T extends { orderItemId?: IdType }>(order: any, item: any, field: string): T | undefined => {
|
||||
const itemValue = item?.[field] as T | undefined
|
||||
if (itemValue) return itemValue
|
||||
const orderValue = order?.[field] as T | undefined
|
||||
if (!orderValue) return undefined
|
||||
return sameId(orderValue.orderItemId, item.id) || (order.items || []).length === 1 ? orderValue : undefined
|
||||
}
|
||||
|
||||
const pendingReviewForItem = (order: any, item: any): OrderArtistReviewVO | undefined => {
|
||||
const embedded = embeddedForItem<OrderArtistReviewVO>(order, item, 'pendingReview')
|
||||
if (embedded) return embedded
|
||||
return pendingReviews.value.find(review => sameId(review.orderId, order.id) && sameId(review.orderItemId, item.id))
|
||||
}
|
||||
|
||||
const submittedReviewForItem = (order: any, item: any): OrderArtistReviewVO | undefined => {
|
||||
const embedded = embeddedForItem<OrderArtistReviewVO>(order, item, 'reviewSummary')
|
||||
if (embedded) return embedded
|
||||
return (orderReviews.value[String(order.id)] || []).find(review => sameId(review.orderItemId, item.id) && Number(review.status) === 1)
|
||||
}
|
||||
|
||||
const pendingChangeRequestForItem = (order: any, item: any): OrderArtistChangeRequestVO | undefined => {
|
||||
const embedded = embeddedForItem<OrderArtistChangeRequestVO>(order, item, 'pendingArtistChangeRequest')
|
||||
if (embedded) return embedded
|
||||
return pendingChangeRequests.value.find(request => sameId(request.orderId, order.id) && sameId(request.orderItemId, item.id))
|
||||
}
|
||||
|
||||
const formatRating = (rating?: number) => {
|
||||
return Number(rating || 0).toFixed(1)
|
||||
}
|
||||
|
||||
/** resetFilters is a local helper used by this page script. */
|
||||
const resetFilters = () => {
|
||||
filters.keyword = ''
|
||||
@@ -142,13 +253,49 @@ const copyOrderNo = async (orderNo: string) => {
|
||||
}
|
||||
}
|
||||
|
||||
const loadPendingReviews = async () => {
|
||||
try {
|
||||
pendingReviews.value = (await orderApi.getMyPendingReviews()) || []
|
||||
} catch {
|
||||
pendingReviews.value = []
|
||||
}
|
||||
}
|
||||
|
||||
const loadOrderReviews = async () => {
|
||||
const orderIds = orders.value.map(order => order.id).filter(Boolean)
|
||||
const entries = await Promise.all(orderIds.map(async (orderId) => {
|
||||
try {
|
||||
return [String(orderId), await orderApi.getOrderReviews(orderId)] as const
|
||||
} catch {
|
||||
return [String(orderId), []] as const
|
||||
}
|
||||
}))
|
||||
orderReviews.value = Object.fromEntries(entries)
|
||||
}
|
||||
|
||||
const loadPendingArtistChangeRequests = async () => {
|
||||
try {
|
||||
pendingChangeRequests.value = (await orderApi.getMyPendingArtistChangeRequests()) || []
|
||||
} catch {
|
||||
pendingChangeRequests.value = []
|
||||
}
|
||||
}
|
||||
|
||||
const refreshOrderExtensions = async () => {
|
||||
await Promise.all([
|
||||
loadPendingReviews(),
|
||||
loadOrderReviews(),
|
||||
loadPendingArtistChangeRequests()
|
||||
])
|
||||
}
|
||||
|
||||
/** loadOrders is an async page action. Trigger it from the template or lifecycle hook, then await the result. */
|
||||
const loadOrders = async () => {
|
||||
try {
|
||||
const userInfo = await userApi.getUserInfo()
|
||||
if (userInfo.type === 2 || userInfo.type === 3) {
|
||||
router.replace('/artist-orders')
|
||||
return
|
||||
return false
|
||||
}
|
||||
orders.value = (await orderApi.getOrderList() as unknown as any[]) || []
|
||||
for (const order of orders.value) {
|
||||
@@ -164,8 +311,104 @@ const loadOrders = async () => {
|
||||
}
|
||||
}
|
||||
}
|
||||
await refreshOrderExtensions()
|
||||
return true
|
||||
} catch {
|
||||
message.error('获取订单列表失败')
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
const openReviewModal = (review?: OrderArtistReviewVO) => {
|
||||
if (!review) return
|
||||
activeReview.value = review
|
||||
reviewForm.rating = review.rating ? Number(review.rating) : undefined
|
||||
reviewForm.content = review.content || ''
|
||||
reviewModalOpen.value = true
|
||||
}
|
||||
|
||||
const closeReviewModal = () => {
|
||||
reviewModalOpen.value = false
|
||||
activeReview.value = null
|
||||
reviewForm.rating = undefined
|
||||
reviewForm.content = ''
|
||||
}
|
||||
|
||||
const submitReview = async () => {
|
||||
if (!activeReview.value) return
|
||||
const rating = Number(reviewForm.rating)
|
||||
if (!rating || rating < 0.5 || rating > 5) {
|
||||
message.warning('请填写 0.5-5 分的评分')
|
||||
return
|
||||
}
|
||||
const normalizedRating = Math.round(rating * 2) / 2
|
||||
if (Math.abs(normalizedRating - rating) > 0.001) {
|
||||
message.warning('评分请按 0.5 分递增')
|
||||
return
|
||||
}
|
||||
reviewSubmitting.value = true
|
||||
try {
|
||||
await orderApi.submitArtistReview(activeReview.value.id, {
|
||||
rating: normalizedRating,
|
||||
content: reviewForm.content.trim() || undefined,
|
||||
imageFileIds: []
|
||||
})
|
||||
message.success('评价已提交')
|
||||
closeReviewModal()
|
||||
await Promise.all([loadPendingReviews(), loadOrderReviews()])
|
||||
} catch {
|
||||
message.error('提交评价失败')
|
||||
} finally {
|
||||
reviewSubmitting.value = false
|
||||
}
|
||||
}
|
||||
|
||||
const approveArtistChange = (request?: OrderArtistChangeRequestVO) => {
|
||||
if (!request) return
|
||||
Modal.confirm({
|
||||
title: '同意改派申请',
|
||||
content: `确定同意改派给「${request.requestedArtistName || '新美甲师'}」吗?`,
|
||||
onOk: async () => {
|
||||
try {
|
||||
await runWithGlobalLoading(async () => {
|
||||
await orderApi.approveArtistChange(request.id)
|
||||
await loadOrders()
|
||||
})
|
||||
message.success('已同意改派')
|
||||
} catch {
|
||||
message.error('处理改派申请失败')
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
const openRejectArtistChange = (request?: OrderArtistChangeRequestVO) => {
|
||||
if (!request) return
|
||||
activeChangeRequest.value = request
|
||||
rejectForm.rejectReason = ''
|
||||
rejectModalOpen.value = true
|
||||
}
|
||||
|
||||
const closeRejectArtistChange = () => {
|
||||
rejectModalOpen.value = false
|
||||
activeChangeRequest.value = null
|
||||
rejectForm.rejectReason = ''
|
||||
}
|
||||
|
||||
const submitRejectArtistChange = async () => {
|
||||
if (!activeChangeRequest.value) return
|
||||
changeProcessing.value = true
|
||||
try {
|
||||
await orderApi.rejectArtistChange(activeChangeRequest.value.id, {
|
||||
rejectReason: rejectForm.rejectReason.trim() || undefined
|
||||
})
|
||||
message.success('已拒绝改派')
|
||||
closeRejectArtistChange()
|
||||
await loadOrders()
|
||||
} catch {
|
||||
message.error('拒绝改派申请失败')
|
||||
} finally {
|
||||
changeProcessing.value = false
|
||||
}
|
||||
}
|
||||
|
||||
@@ -215,6 +458,13 @@ onMounted(loadOrders)
|
||||
.title { font-weight: 600; color: var(--text-primary); }
|
||||
.line { margin-top: 4px; color: var(--text-secondary); font-size: 13px; }
|
||||
.appointment { color: var(--theme-primary); }
|
||||
.review-summary { margin-top: 8px; padding: 8px 10px; border-radius: 8px; background: var(--theme-primary-soft); color: var(--theme-primary); font-size: 13px; }
|
||||
.review-action { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-top: 8px; padding: 8px 10px; border-radius: 8px; background: var(--theme-primary-soft); color: var(--theme-primary); font-size: 13px; }
|
||||
.change-request { display: grid; gap: 8px; margin-top: 8px; padding: 10px; border: 1px solid var(--theme-border); border-radius: 8px; background: rgba(255, 255, 255, 0.72); }
|
||||
.change-info { display: grid; gap: 4px; color: var(--text-secondary); font-size: 13px; }
|
||||
.change-info strong { color: var(--text-primary); }
|
||||
.change-actions { display: flex; gap: 8px; justify-content: flex-end; }
|
||||
.rating-input { width: 100%; }
|
||||
|
||||
:deep(.ant-btn-primary) { background: var(--theme-primary); border-color: var(--theme-primary); }
|
||||
:deep(.ant-btn-link) { color: var(--theme-primary); }
|
||||
|
||||
@@ -125,15 +125,6 @@
|
||||
<a-button v-if="hasPermission('shop:edit')" type="link" size="small" @click="showEditModal(record)">
|
||||
编辑
|
||||
</a-button>
|
||||
<a-popconfirm
|
||||
v-if="hasPermission('shop:delete')"
|
||||
title="确定要删除这个店铺吗?"
|
||||
@confirm="handleDelete(record)"
|
||||
>
|
||||
<a-button type="link" size="small" danger>
|
||||
删除
|
||||
</a-button>
|
||||
</a-popconfirm>
|
||||
</a-space>
|
||||
</template>
|
||||
</template>
|
||||
@@ -166,7 +157,14 @@
|
||||
<div class="admin-mobile-card__actions">
|
||||
<a-button size="small" @click="showViewModal(item)">查看</a-button>
|
||||
<a-button v-if="hasPermission('shop:edit')" size="small" @click="showEditModal(item)">编辑</a-button>
|
||||
<a-button v-if="hasPermission('shop:delete')" size="small" danger @click="handleDelete(item)">删除</a-button>
|
||||
<a-button
|
||||
v-if="hasPermission('shop:edit')"
|
||||
size="small"
|
||||
:disabled="!isAdmin"
|
||||
@click="handleStatusChange(item, item.status === 0)"
|
||||
>
|
||||
{{ item.status === 0 ? '启用' : '停用' }}
|
||||
</a-button>
|
||||
</div>
|
||||
</article>
|
||||
</template>
|
||||
@@ -2103,20 +2101,6 @@ const handleModalCancel = () => {
|
||||
syncUploadedThemeBackgroundId('')
|
||||
}
|
||||
|
||||
/** handleDelete is an async page action. Trigger it from the template or lifecycle hook, then await the result. */
|
||||
const handleDelete = async (record: Shop | Record<string, any>) => {
|
||||
try {
|
||||
await runWithGlobalLoading(async () => {
|
||||
const shopId = 'id' in record ? record.id : (record as any).id
|
||||
await adminShopApi.deleteShop(shopId)
|
||||
message.success('删除成功')
|
||||
await fetchShopList()
|
||||
})
|
||||
} catch (error) {
|
||||
message.error('删除失败')
|
||||
}
|
||||
}
|
||||
|
||||
/** handleStatusChange is an async page action. Trigger it from the template or lifecycle hook, then await the result. */
|
||||
const handleStatusChange = async (record: Shop | Record<string, any>, enabled: boolean) => {
|
||||
try {
|
||||
|
||||
Reference in New Issue
Block a user