1
This commit is contained in:
@@ -44,10 +44,6 @@ interface RegisterResponse {
|
||||
message?: string;
|
||||
}
|
||||
|
||||
interface CheckUsernameResponse {
|
||||
available: boolean;
|
||||
}
|
||||
|
||||
export const authApi = {
|
||||
// 用户登录
|
||||
login(params: LoginRequest) {
|
||||
@@ -68,7 +64,6 @@ export const authApi = {
|
||||
return http
|
||||
.get('/api/check-username', { username })
|
||||
.then(res => {
|
||||
// checkUsername 使用标准格式 {code: 200, data: boolean}
|
||||
if (res && res.code === 200) {
|
||||
return { available: res.data };
|
||||
}
|
||||
@@ -87,4 +82,32 @@ export const authApi = {
|
||||
logout(token: string) {
|
||||
return http.postVoid('/api/logout', { token });
|
||||
},
|
||||
|
||||
// 删除token缓存
|
||||
deleteTokenCache() {
|
||||
return http.postVoid('/api/cache/delete?key=token');
|
||||
},
|
||||
// 保存token到本地数据库
|
||||
saveToken(token: string) {
|
||||
return http.postVoid('/api/cache/save', { key: 'token', value: token });
|
||||
},
|
||||
|
||||
// 从本地数据库获取token
|
||||
getToken(): Promise<string | undefined> {
|
||||
return http.get<any>('/api/cache/get?key=token').then((res: any) => {
|
||||
if (typeof res === 'string') return res;
|
||||
if (res && typeof res === 'object') {
|
||||
if (typeof res.code === 'number') {
|
||||
return res.code === 0 ? (res.data as string | undefined) : undefined;
|
||||
}
|
||||
if (typeof (res as any).data === 'string') return (res as any).data as string;
|
||||
}
|
||||
return undefined;
|
||||
});
|
||||
},
|
||||
|
||||
// 会话引导:检查并恢复会话(返回体各异,这里保持 any)
|
||||
sessionBootstrap() {
|
||||
return http.get<any>('/api/session/bootstrap');
|
||||
},
|
||||
};
|
||||
@@ -1,7 +1,13 @@
|
||||
// 极简 HTTP 工具:仅封装 GET/POST,默认指向本地 8081
|
||||
// 极简 HTTP 工具:封装 GET/POST,按路径选择后端服务
|
||||
export type HttpMethod = 'GET' | 'POST';
|
||||
|
||||
const BASE_URL = 'http://localhost:8081';
|
||||
const BASE_CLIENT = 'http://localhost:8081'; // erp_client_sb
|
||||
const BASE_RUOYI = 'http://localhost:8080'; // ruoyi-admin
|
||||
|
||||
function resolveBase(path: string): string {
|
||||
if (path.startsWith('/tool/banma')) return BASE_RUOYI;
|
||||
return BASE_CLIENT;
|
||||
}
|
||||
|
||||
// 将对象转为查询字符串
|
||||
function buildQuery(params?: Record<string, unknown>): string {
|
||||
@@ -17,7 +23,7 @@ function buildQuery(params?: Record<string, unknown>): string {
|
||||
|
||||
// 统一请求入口:自动加上 BASE_URL、JSON 头与错误处理
|
||||
async function request<T>(path: string, options: RequestInit): Promise<T> {
|
||||
const res = await fetch(`${BASE_URL}${path}`, {
|
||||
const res = await fetch(`${resolveBase(path)}${path}`, {
|
||||
credentials: 'omit',
|
||||
cache: 'no-store',
|
||||
...options,
|
||||
@@ -44,9 +50,12 @@ export const http = {
|
||||
post<T>(path: string, body?: unknown) {
|
||||
return request<T>(path, { method: 'POST', body: body ? JSON.stringify(body) : undefined });
|
||||
},
|
||||
delete<T>(path: string) {
|
||||
return request<T>(path, { method: 'DELETE' });
|
||||
},
|
||||
// 用于无需读取响应体的 POST(如删除/心跳等),从根源避免读取中断
|
||||
postVoid(path: string, body?: unknown) {
|
||||
return fetch(`${BASE_URL}${path}`, {
|
||||
return fetch(`${resolveBase(path)}${path}`, {
|
||||
method: 'POST',
|
||||
body: body ? JSON.stringify(body) : undefined,
|
||||
credentials: 'omit',
|
||||
@@ -59,7 +68,7 @@ export const http = {
|
||||
},
|
||||
// 文件上传:透传 FormData,不设置 Content-Type 让浏览器自动处理
|
||||
upload<T>(path: string, form: FormData) {
|
||||
const res = fetch(`${BASE_URL}${path}`, {
|
||||
const res = fetch(`${resolveBase(path)}${path}`, {
|
||||
method: 'POST',
|
||||
body: form,
|
||||
credentials: 'omit',
|
||||
|
||||
@@ -27,23 +27,48 @@ export interface ZebraOrdersResp {
|
||||
|
||||
import { http } from './http';
|
||||
|
||||
export interface BanmaAccount {
|
||||
id?: number;
|
||||
name?: string;
|
||||
username?: string;
|
||||
token?: string;
|
||||
tokenExpireAt?: string | number;
|
||||
isDefault?: number;
|
||||
status?: number;
|
||||
remark?: string;
|
||||
}
|
||||
|
||||
// 斑马 API:与原 zebra-api.js 对齐的接口封装
|
||||
export const zebraApi = {
|
||||
getOrders(params: Record<string, unknown>) {
|
||||
return http.get<ZebraOrdersResp>('/api/banma/orders', params);
|
||||
// 账号管理(ruoyi-admin)
|
||||
getAccounts() {
|
||||
return http.get<{ code?: number; msg?: string; data: BanmaAccount[] }>('/tool/banma/accounts');
|
||||
},
|
||||
saveAccount(body: BanmaAccount) {
|
||||
return http.post<{ id: number }>('/tool/banma/accounts', body);
|
||||
},
|
||||
removeAccount(id: number) {
|
||||
// 用 postVoid 也可,但这里前端未用到,保留以备将来
|
||||
return http.delete<void>(`/tool/banma/accounts/${id}`);
|
||||
},
|
||||
|
||||
// 业务采集(仍走客户端微服务 8081)
|
||||
getShops() {
|
||||
return http.get<{ data?: { list?: Array<{ id: string; shopName: string }> } }>(
|
||||
'/api/banma/shops'
|
||||
);
|
||||
},
|
||||
getOrders(params: { startDate?: string; endDate?: string; page?: number; pageSize?: number; shopIds?: string }) {
|
||||
return http.get<ZebraOrdersResp>('/api/banma/orders', params as unknown as Record<string, unknown>);
|
||||
},
|
||||
|
||||
// 其他功能(客户端微服务)
|
||||
getOrdersByBatch(batchId: string) {
|
||||
return http.get<ZebraOrdersResp>(`/api/banma/orders/batch/${batchId}`);
|
||||
},
|
||||
getLatestOrders() {
|
||||
return http.get<ZebraOrdersResp>('/api/banma/orders/latest');
|
||||
},
|
||||
getShops() {
|
||||
return http.get<{ data?: { list?: Array<{ id: string; shopName: string }> } }>('/api/banma/shops');
|
||||
},
|
||||
refreshToken() {
|
||||
return http.post('/api/banma/refresh-token');
|
||||
},
|
||||
exportAndSaveOrders(exportData: unknown) {
|
||||
return http.post<{ filePath: string }>('/api/banma/export-and-save', exportData);
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user