update pay ui
This commit is contained in:
@@ -1,6 +1,7 @@
|
|||||||
// src/services/eventService.js
|
// src/services/eventService.js
|
||||||
|
|
||||||
import { logger } from '../utils/logger';
|
import { logger } from '../utils/logger';
|
||||||
|
import { getApiBase } from '../utils/apiConfig';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 格式化股票代码,确保包含交易所后缀
|
* 格式化股票代码,确保包含交易所后缀
|
||||||
@@ -39,11 +40,12 @@ const formatStockCode = (code) => {
|
|||||||
const apiRequest = async (url, options = {}) => {
|
const apiRequest = async (url, options = {}) => {
|
||||||
const method = options.method || 'GET';
|
const method = options.method || 'GET';
|
||||||
const requestData = options.body ? JSON.parse(options.body) : null;
|
const requestData = options.body ? JSON.parse(options.body) : null;
|
||||||
|
const fullUrl = `${getApiBase()}${url}`;
|
||||||
|
|
||||||
logger.api.request(method, url, requestData);
|
logger.api.request(method, fullUrl, requestData);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const response = await fetch(url, {
|
const response = await fetch(fullUrl, {
|
||||||
...options,
|
...options,
|
||||||
headers: {
|
headers: {
|
||||||
'Content-Type': 'application/json',
|
'Content-Type': 'application/json',
|
||||||
@@ -55,16 +57,16 @@ const apiRequest = async (url, options = {}) => {
|
|||||||
if (!response.ok) {
|
if (!response.ok) {
|
||||||
const errorText = await response.text();
|
const errorText = await response.text();
|
||||||
const error = new Error(`HTTP error! status: ${response.status}`);
|
const error = new Error(`HTTP error! status: ${response.status}`);
|
||||||
logger.api.error(method, url, error, { errorText, ...requestData });
|
logger.api.error(method, fullUrl, error, { errorText, ...requestData });
|
||||||
throw error;
|
throw error;
|
||||||
}
|
}
|
||||||
|
|
||||||
const data = await response.json();
|
const data = await response.json();
|
||||||
logger.api.response(method, url, response.status, data);
|
logger.api.response(method, fullUrl, response.status, data);
|
||||||
|
|
||||||
return data;
|
return data;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
logger.api.error(method, url, error, requestData);
|
logger.api.error(method, fullUrl, error, requestData);
|
||||||
throw error;
|
throw error;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -3,6 +3,7 @@
|
|||||||
|
|
||||||
import { createApi, fetchBaseQuery } from '@reduxjs/toolkit/query/react';
|
import { createApi, fetchBaseQuery } from '@reduxjs/toolkit/query/react';
|
||||||
import { logger } from '../../utils/logger';
|
import { logger } from '../../utils/logger';
|
||||||
|
import { getApiBase } from '../../utils/apiConfig';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Events API Slice - 使用 RTK Query 管理事件数据
|
* Events API Slice - 使用 RTK Query 管理事件数据
|
||||||
@@ -20,7 +21,8 @@ export const eventsApi = createApi({
|
|||||||
|
|
||||||
// 基础查询配置
|
// 基础查询配置
|
||||||
baseQuery: fetchBaseQuery({
|
baseQuery: fetchBaseQuery({
|
||||||
baseUrl: '/api',
|
baseUrl: `${getApiBase()}/api`,
|
||||||
|
credentials: 'include',
|
||||||
prepareHeaders: (headers) => {
|
prepareHeaders: (headers) => {
|
||||||
// 可以在这里添加认证 token
|
// 可以在这里添加认证 token
|
||||||
// const token = localStorage.getItem('token');
|
// const token = localStorage.getItem('token');
|
||||||
|
|||||||
Reference in New Issue
Block a user