统一甲屿云命名体系
This commit is contained in:
@@ -0,0 +1,21 @@
|
||||
const API_AUTH_FREE_PATHS = [
|
||||
'/user/send-verification-code',
|
||||
'/user/phone-login',
|
||||
'/user/check/login-shops/phone/',
|
||||
'/legal-agreement/current'
|
||||
]
|
||||
|
||||
const ADMIN_AUTH_FREE_PATHS = [
|
||||
'/auth/login',
|
||||
'/auth/login-shops/',
|
||||
'/auth/refresh'
|
||||
]
|
||||
|
||||
const matchPath = (url: string | undefined, paths: string[]): boolean => {
|
||||
const target = String(url || '')
|
||||
return paths.some(path => target === path || target.startsWith(path))
|
||||
}
|
||||
|
||||
export const isApiAuthFreePath = (url: string | undefined): boolean => matchPath(url, API_AUTH_FREE_PATHS)
|
||||
|
||||
export const isAdminAuthFreePath = (url: string | undefined): boolean => matchPath(url, ADMIN_AUTH_FREE_PATHS)
|
||||
@@ -0,0 +1,65 @@
|
||||
import { api, adminApi } from '@/api/client'
|
||||
import type { LegalAgreement, LoginResponse, LoginShopSelectionResponse } from '@/types/common'
|
||||
|
||||
export interface PasswordLoginRequest {
|
||||
account: string
|
||||
password: string
|
||||
shopId?: string | number
|
||||
agreementAccepted: boolean
|
||||
agreementVersions: Record<string, string>
|
||||
clientType: string
|
||||
}
|
||||
|
||||
export interface PhoneLoginRequest {
|
||||
phone: string
|
||||
verificationCode: string
|
||||
shopId?: string | number
|
||||
agreementAccepted: boolean
|
||||
agreementVersions: Record<string, string>
|
||||
clientType: string
|
||||
}
|
||||
|
||||
export interface RegisterRequest {
|
||||
account: string
|
||||
password: string
|
||||
nickname: string
|
||||
shopName: string
|
||||
phone: string
|
||||
verificationCode: string
|
||||
agreementAccepted: boolean
|
||||
agreementVersions: Record<string, string>
|
||||
clientType: string
|
||||
}
|
||||
|
||||
export const authApi = {
|
||||
passwordLogin(data: PasswordLoginRequest): Promise<LoginResponse> {
|
||||
return adminApi.post('/auth/login', data)
|
||||
},
|
||||
getPasswordLoginShops(account: string): Promise<LoginShopSelectionResponse> {
|
||||
return adminApi.get(`/auth/login-shops/${encodeURIComponent(account)}`)
|
||||
},
|
||||
sendRegisterCode(phone: string): Promise<boolean> {
|
||||
return api.post('/user/send-verification-code', { phone, sceneCode: 'PLANNING_MANAGER_REGISTER' })
|
||||
},
|
||||
sendLoginCode(phone: string): Promise<boolean> {
|
||||
return api.post('/user/send-verification-code', { phone, sceneCode: 'USER_LOGIN_SMS_CODE' })
|
||||
},
|
||||
phoneLogin(data: PhoneLoginRequest): Promise<LoginResponse> {
|
||||
return api.post('/user/phone-login', data)
|
||||
},
|
||||
getPhoneLoginShops(phone: string): Promise<LoginShopSelectionResponse> {
|
||||
return api.get(`/user/check/login-shops/phone/${encodeURIComponent(phone)}`)
|
||||
},
|
||||
getCurrentAgreements(): Promise<LegalAgreement[]> {
|
||||
return api.get('/legal-agreement/current')
|
||||
},
|
||||
register(data: RegisterRequest): Promise<LoginResponse> {
|
||||
return adminApi.post('/auth/register', data)
|
||||
},
|
||||
switchShop(shopId: string | number): Promise<LoginResponse> {
|
||||
return adminApi.post('/auth/switch-shop', { shopId })
|
||||
},
|
||||
logout(): Promise<boolean> {
|
||||
return adminApi.post('/auth/logout')
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,65 @@
|
||||
import axios, { type AxiosError } from 'axios'
|
||||
import router from '@/router'
|
||||
import { ADMIN_API_BASE_URL, API_BASE_URL } from '@/config/api'
|
||||
import { isAdminAuthFreePath, isApiAuthFreePath } from '@/api/auth-free-paths'
|
||||
import { attachRequestSignature } from '@/utils/request-signature'
|
||||
import { useSessionStore } from '@/stores/session'
|
||||
import { useToastStore } from '@/stores/toast'
|
||||
|
||||
const api = axios.create({
|
||||
baseURL: API_BASE_URL,
|
||||
timeout: 60000,
|
||||
headers: { 'Content-Type': 'application/json' }
|
||||
})
|
||||
|
||||
const adminApi = axios.create({
|
||||
baseURL: ADMIN_API_BASE_URL,
|
||||
timeout: 60000,
|
||||
headers: { 'Content-Type': 'application/json' }
|
||||
})
|
||||
|
||||
const normalizeResponse = <T>(response: { data: { code?: number; message?: string; data: T } }): T => {
|
||||
const payload = response.data
|
||||
if (payload && payload.code !== undefined && payload.code !== 200) {
|
||||
throw new Error(payload.message || '请求失败')
|
||||
}
|
||||
return payload.data as T
|
||||
}
|
||||
|
||||
const handleExpired = async (): Promise<void> => {
|
||||
const session = useSessionStore()
|
||||
session.clear()
|
||||
await router.replace('/login')
|
||||
}
|
||||
|
||||
api.interceptors.request.use(async config => {
|
||||
const session = useSessionStore()
|
||||
const authFree = isApiAuthFreePath(config.url)
|
||||
if (!authFree && session.accessToken) {
|
||||
config.headers.Authorization = `Bearer ${session.accessToken}`
|
||||
}
|
||||
return attachRequestSignature(config, session.accessToken, { authFree })
|
||||
})
|
||||
|
||||
adminApi.interceptors.request.use(async config => {
|
||||
const session = useSessionStore()
|
||||
const authFree = isAdminAuthFreePath(config.url)
|
||||
if (!authFree && session.accessToken) {
|
||||
config.headers.Authorization = `Bearer ${session.accessToken}`
|
||||
}
|
||||
return attachRequestSignature(config, session.accessToken, { authFree })
|
||||
})
|
||||
|
||||
const responseErrorHandler = async (error: AxiosError): Promise<never> => {
|
||||
if (error.response?.status === 401) {
|
||||
await handleExpired()
|
||||
}
|
||||
const message = (error.response?.data as { message?: string } | undefined)?.message || error.message || '请求失败'
|
||||
useToastStore().error(message)
|
||||
return Promise.reject(new Error(message))
|
||||
}
|
||||
|
||||
api.interceptors.response.use(response => normalizeResponse(response), responseErrorHandler)
|
||||
adminApi.interceptors.response.use(response => normalizeResponse(response), responseErrorHandler)
|
||||
|
||||
export { api, adminApi }
|
||||
@@ -0,0 +1,25 @@
|
||||
import { api, adminApi } from '@/api/client'
|
||||
|
||||
export interface ObjectStorageFile {
|
||||
id: string | number
|
||||
fileName?: string
|
||||
fileUrl?: string
|
||||
primaryUrl?: string
|
||||
}
|
||||
|
||||
export const fileApi = {
|
||||
uploadObjectFile(file: File): Promise<ObjectStorageFile> {
|
||||
const formData = new FormData()
|
||||
formData.append('file', file)
|
||||
return adminApi.post('/object-storage-file/upload', formData, {
|
||||
headers: { 'Content-Type': 'multipart/form-data' }
|
||||
})
|
||||
},
|
||||
uploadProfileImage(file: File): Promise<string> {
|
||||
const formData = new FormData()
|
||||
formData.append('file', file)
|
||||
return api.post('/user/upload-profile-image', formData, {
|
||||
headers: { 'Content-Type': 'multipart/form-data' }
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
import { adminApi } from '@/api/client'
|
||||
import type { IdType, UserInfo } from '@/types/common'
|
||||
import type { CustomerCreateRequest, CustomerPage } from '@/types/manager'
|
||||
|
||||
export interface CustomerListParams {
|
||||
page: number
|
||||
size: number
|
||||
keyword?: string
|
||||
hasOrder?: boolean
|
||||
}
|
||||
|
||||
export const managerCustomersApi = {
|
||||
list(params: CustomerListParams): Promise<CustomerPage> {
|
||||
return adminApi.get('/manager/customers', { params })
|
||||
},
|
||||
detail(id: IdType): Promise<UserInfo> {
|
||||
return adminApi.get(`/manager/customers/${id}`)
|
||||
},
|
||||
create(data: CustomerCreateRequest): Promise<IdType> {
|
||||
return adminApi.post('/manager/customers', data)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
import { adminApi } from '@/api/client'
|
||||
import type { IdType } from '@/types/common'
|
||||
import type {
|
||||
Artist,
|
||||
ArtistSchedule,
|
||||
ArtistScheduleException,
|
||||
ArtistScheduleRule,
|
||||
ArtistScheduleRuleSetting,
|
||||
EmployeeCreateRequest
|
||||
} from '@/types/manager'
|
||||
|
||||
export const managerEmployeesApi = {
|
||||
list(): Promise<Artist[]> {
|
||||
return adminApi.get('/manager/employees')
|
||||
},
|
||||
detail(userId: IdType): Promise<Artist> {
|
||||
return adminApi.get(`/manager/employees/${userId}`)
|
||||
},
|
||||
save(data: Partial<Artist>): Promise<Artist> {
|
||||
return adminApi.post('/manager/employees', data)
|
||||
},
|
||||
createUser(data: EmployeeCreateRequest): Promise<IdType> {
|
||||
return adminApi.post('/manager/employees/users', data)
|
||||
},
|
||||
schedules(params: { artistId?: IdType; startDate?: string; endDate?: string }): Promise<ArtistSchedule[]> {
|
||||
return adminApi.get('/manager/employees/schedules', { params })
|
||||
},
|
||||
saveSchedule(data: ArtistSchedule): Promise<ArtistSchedule> {
|
||||
return adminApi.post('/manager/employees/schedules', data)
|
||||
},
|
||||
scheduleRule(params: { artistId: IdType }): Promise<ArtistScheduleRuleSetting> {
|
||||
return adminApi.get('/manager/employees/schedule-rule', { params })
|
||||
},
|
||||
saveScheduleRule(data: ArtistScheduleRule): Promise<ArtistScheduleRule> {
|
||||
return adminApi.post('/manager/employees/schedule-rule', data)
|
||||
},
|
||||
saveScheduleException(data: ArtistScheduleException): Promise<ArtistScheduleException> {
|
||||
return adminApi.post('/manager/employees/schedule-exceptions', data)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
import { adminApi } from '@/api/client'
|
||||
import type { Appointment, AppointmentCreateRequest, PlanningCalendar } from '@/types/manager'
|
||||
import type { IdType } from '@/types/common'
|
||||
|
||||
export interface CalendarParams {
|
||||
startDate: string
|
||||
endDate: string
|
||||
artistId?: string | number
|
||||
}
|
||||
|
||||
export interface AppointmentMoveRequest {
|
||||
appointmentDate: string
|
||||
appointmentTime: string
|
||||
artistId: string | number
|
||||
}
|
||||
|
||||
export const managerPlanningApi = {
|
||||
calendar(params: CalendarParams): Promise<PlanningCalendar> {
|
||||
return adminApi.get('/manager/planning/calendar', { params })
|
||||
},
|
||||
createAppointment(data: AppointmentCreateRequest): Promise<Appointment> {
|
||||
return adminApi.post('/manager/planning/appointments', data)
|
||||
},
|
||||
appointment(orderItemId: IdType): Promise<Appointment> {
|
||||
return adminApi.get(`/manager/planning/appointments/${orderItemId}`)
|
||||
},
|
||||
moveAppointment(orderItemId: IdType, data: AppointmentMoveRequest): Promise<Appointment> {
|
||||
return adminApi.put(`/manager/planning/appointments/${orderItemId}/time-artist`, data)
|
||||
},
|
||||
updateStatus(orderId: IdType, status: number): Promise<boolean> {
|
||||
return adminApi.put(`/manager/planning/appointments/${orderId}/status`, { status })
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
import { adminApi } from '@/api/client'
|
||||
import type { PageResult } from '@/types/common'
|
||||
import type { Product } from '@/types/manager'
|
||||
|
||||
export const managerProductsApi = {
|
||||
list(params: { page: number; size: number; keyword?: string }): Promise<PageResult<Product> | Product[]> {
|
||||
return adminApi.get('/manager/products', { params })
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
import { adminApi } from '@/api/client'
|
||||
import type { ShopInfo } from '@/types/manager'
|
||||
|
||||
export const managerShopApi = {
|
||||
info(): Promise<ShopInfo> {
|
||||
return adminApi.get('/manager/shop')
|
||||
},
|
||||
update(data: Partial<ShopInfo>): Promise<boolean> {
|
||||
return adminApi.put('/manager/shop', data)
|
||||
},
|
||||
exportPreview(params: { type: string; startDate: string; endDate: string }): Promise<unknown> {
|
||||
return adminApi.get('/export', { params })
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
import { api } from '@/api/client'
|
||||
import type { UserInfo } from '@/types/common'
|
||||
|
||||
export const userApi = {
|
||||
info(): Promise<UserInfo> {
|
||||
return api.get('/user/info')
|
||||
},
|
||||
update(data: Partial<UserInfo>): Promise<boolean> {
|
||||
return api.put('/user/info', data)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user