统一前端共享工具入口

This commit is contained in:
yml
2026-06-09 20:50:57 +08:00
parent 684e30862d
commit 60324765c5
69 changed files with 106 additions and 1142 deletions
+1 -1
View File
@@ -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>
+16
View File
@@ -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
View File
@@ -1,5 +1,6 @@
// 通用工具函数
export * from './authStorage'
export * from './error'
export * from './imageUpload'
export * from './json'
export * from './listingDisplay'
+1 -1
View File
@@ -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) {