diff --git a/api/resources.ts b/api/resources.ts index ff05796..9b9cbe0 100644 --- a/api/resources.ts +++ b/api/resources.ts @@ -1,4 +1,5 @@ import { ApiResponse } from './common'; +import { BASE_URL } from './constants'; import { post } from './request'; // 资源列表请求参数 @@ -20,5 +21,5 @@ export interface Resource { // 获取资源列表 - 按创建者筛选 export const getResourcesList = async (data: ResourcesListRequest): Promise> => { - return post>('https://movieflow.api.huiying.video/resources/list', data); + return post>(BASE_URL+'/resources/list', data); }; \ No newline at end of file diff --git a/api/serversetting.ts b/api/serversetting.ts new file mode 100644 index 0000000..3ff8367 --- /dev/null +++ b/api/serversetting.ts @@ -0,0 +1,66 @@ +import { BASE_URL } from "./constants"; + +// 获取路演配置数据 +export const fetchRoadshowConfigs = async () => { + const controller = new AbortController(); + const timeoutId = setTimeout(() => controller.abort(), 10000); // 10秒超时 + + try { + console.log('开始请求接口数据...'); + const response = await fetch(BASE_URL + '/serversetting/roadshow-configs', { + method: 'POST', + headers: { + 'Content-Type': 'application/json', + }, + body: JSON.stringify({}), + signal: controller.signal, + }); + + clearTimeout(timeoutId); + + if (!response.ok) { + throw new Error(`接口请求失败: HTTP ${response.status} - ${response.statusText}`); + } + + const result = await response.json(); + console.log('接口返回数据:', result); + + // 验证返回数据格式 + if (result.code !== 0) { + throw new Error(`接口错误: ${result.message || '未知错误'} (code: ${result.code})`); + } + + if (!result.successful) { + throw new Error(`接口调用不成功: ${result.message || '未知原因'}`); + } + + if (!result.data || !Array.isArray(result.data) || result.data.length === 0) { + throw new Error('接口返回数据格式错误或为空'); + } + + // 验证数据结构 + let validData: any[] = []; + result.data.forEach((item: any) => { + if (item) { + validData.push(JSON.parse(item)); + } + }); + + if (validData.length === 0) { + throw new Error('接口返回的数据格式不正确'); + } + + console.log('成功获取并验证接口数据:', validData); + return validData; + + } catch (error: unknown) { + clearTimeout(timeoutId); + + if (error instanceof Error && error.name === 'AbortError') { + throw new Error('接口请求超时,请检查网络连接'); + } + + console.error('接口请求失败:', error); + throw error; + } +}; diff --git a/components/work-flow/constants.ts b/components/work-flow/constants.ts index 75240e6..6138e57 100644 --- a/components/work-flow/constants.ts +++ b/components/work-flow/constants.ts @@ -1,3 +1,5 @@ +import { fetchRoadshowConfigs } from "@/api/serversetting"; + // 5组mock数据 - 保留作为fallback数据 export const MOCK_DATA = [ { @@ -49,76 +51,10 @@ export const MOCK_DATA = [ } ]; -// 从接口获取数据的函数 -export const fetchMockDataFromAPI = async () => { - const controller = new AbortController(); - const timeoutId = setTimeout(() => controller.abort(), 10000); // 10秒超时 - - try { - console.log('开始请求接口数据...'); - const response = await fetch('https://movieflow.api.huiying.video/serversetting/roadshow-configs', { - method: 'POST', - headers: { - 'Content-Type': 'application/json', - }, - body: JSON.stringify({ - }), - signal: controller.signal, - }); - - clearTimeout(timeoutId); - - if (!response.ok) { - throw new Error(`接口请求失败: HTTP ${response.status} - ${response.statusText}`); - } - - const result = await response.json(); - console.log('接口返回数据:', result); - - // 验证返回数据格式 - if (result.code !== 0) { - throw new Error(`接口错误: ${result.message || '未知错误'} (code: ${result.code})`); - } - - if (!result.successful) { - throw new Error(`接口调用不成功: ${result.message || '未知原因'}`); - } - - if (!result.data || !Array.isArray(result.data) || result.data.length === 0) { - throw new Error('接口返回数据格式错误或为空'); - } - - // 验证数据结构 - let validData: any[] = []; - result.data.forEach((item: any) => { - if (item) { - validData.push(JSON.parse(item)); - } - }); - - if (validData.length === 0) { - throw new Error('接口返回的数据格式不正确'); - } - - console.log('成功获取并验证接口数据:', validData); - return validData; - - } catch (error: unknown) { - clearTimeout(timeoutId); - - if (error instanceof Error && error.name === 'AbortError') { - throw new Error('接口请求超时,请检查网络连接'); - } - - console.error('接口请求失败:', error); - throw error; - } -}; - // 异步获取随机数据 - 从接口或fallback到本地数据 export const getRandomMockData = async () => { try { - const apiData = await fetchMockDataFromAPI(); + const apiData = await fetchRoadshowConfigs(); const randomIndex = Math.floor(Math.random() * apiData.length); const selectedData = apiData[randomIndex]; diff --git a/lib/auth.ts b/lib/auth.ts index 0a1ded1..68e7e87 100644 --- a/lib/auth.ts +++ b/lib/auth.ts @@ -1,7 +1,9 @@ +import { BASE_URL } from "@/api/constants"; + // Mock Google OAuth configuration const GOOGLE_CLIENT_ID = '1016208801816-qtvcvki2jobmcin1g4e7u4sotr0p8g3u.apps.googleusercontent.com'; const GOOGLE_REDIRECT_URI = typeof window !== 'undefined' - ? 'https://movieflow.api.huiying.video/users/oauth/callback' + ? BASE_URL+'/users/oauth/callback' : ''; /** diff --git a/next.config.js b/next.config.js index 920e6dc..e6f7abf 100644 --- a/next.config.js +++ b/next.config.js @@ -1,3 +1,4 @@ +import { BASE_URL } from './api/constants'; /** @type {import('next').NextConfig} */ const nextConfig = { eslint: { @@ -39,7 +40,7 @@ const nextConfig = { }, { source: '/api/resources/:path*', - destination: 'https://movieflow.api.huiying.video/:path*', + destination: BASE_URL+'/:path*', }, ]; },