统一前端共享工具入口
This commit is contained in:
@@ -93,7 +93,7 @@ import {
|
||||
getRefreshToken,
|
||||
setAuthTokens,
|
||||
type AuthScope,
|
||||
} from '@/utils/authStorage'
|
||||
} from '@/shared/utils/authStorage'
|
||||
import type { ApiResponse } from '@/shared/types/types'
|
||||
|
||||
export const apiClient = axios.create({
|
||||
|
||||
@@ -21,7 +21,7 @@ import {
|
||||
readFinalSaleRatio,
|
||||
roundMoney,
|
||||
roundRatio,
|
||||
} from '@/utils/pricing'
|
||||
} from '@/shared/utils/pricing'
|
||||
|
||||
export function usePricingCalculator(options: {
|
||||
publishOptions: Ref<ListingPublishOptions>
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
/**
|
||||
* 从错误对象中提取错误消息。
|
||||
*/
|
||||
export function readError(error: unknown, fallback: string): string {
|
||||
if (typeof error === 'object' && error && 'response' in error) {
|
||||
const response = (error as { response?: { data?: { message?: string } } }).response
|
||||
return response?.data?.message || fallback
|
||||
}
|
||||
if (error instanceof Error) {
|
||||
return error.message || fallback
|
||||
}
|
||||
if (typeof error === 'string') {
|
||||
return error
|
||||
}
|
||||
return fallback
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
// 通用工具函数
|
||||
export * from './authStorage'
|
||||
export * from './error'
|
||||
export * from './imageUpload'
|
||||
export * from './json'
|
||||
export * from './listingDisplay'
|
||||
|
||||
@@ -306,7 +306,7 @@ function roundMoney(value: number) {
|
||||
|
||||
function formatRatioNumber(value: number) {
|
||||
const rounded = roundMoney(value)
|
||||
return rounded.toFixed(1)
|
||||
return Number.isInteger(rounded) ? `${rounded}` : rounded.toFixed(2)
|
||||
}
|
||||
|
||||
function formatCompactNumber(value: number) {
|
||||
|
||||
Reference in New Issue
Block a user