feat: 积分商城-供应商-对账-发票3

This commit is contained in:
2026-09-08 16:41:48 +08:00
parent 3abe4ce9c9
commit f42ea5b270
47 changed files with 1211 additions and 285 deletions
+10 -1
View File
@@ -1,14 +1,23 @@
import { clearAdminSession, readAdminSession } from '@/utils/auth'
const API_BASE = import.meta.env.VITE_SUPPLIED_ADMIN_API_BASE || 'http://127.0.0.1:8888/api/admin'
const normalizeBase = (base: string) => base.replace(/\/$/, '')
export const postAdmin = async <T>(name: string, body: Record<string, unknown>): Promise<T> => {
const token = readAdminSession()?.token
const response = await fetch(`${normalizeBase(API_BASE)}/${name}`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
headers: { 'Content-Type': 'application/json', ...(token ? { Authorization: `Bearer ${token}` } : {}) },
body: JSON.stringify(body)
})
const payload = await response.json().catch(() => ({}))
if (response.status === 401 && name !== 'login') {
clearAdminSession()
if (name !== 'admin-session' && window.location.pathname !== '/login') {
window.location.replace(`/login?redirect=${encodeURIComponent(window.location.pathname + window.location.search)}`)
}
}
if (!response.ok || payload.success === false) {
throw new Error(payload.error?.message || payload.msg || '请求失败')
}