|
@@ -152,6 +152,39 @@ export const fetchVideoContent = async (lang: number): Promise<ApiResponse> => {
|
|
|
}
|
|
}
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
|
|
+// 获取游轮航线数据
|
|
|
|
|
+export const fetchCruiseRoutes = async (lang: number = 1): Promise<ApiResponse> => {
|
|
|
|
|
+ try {
|
|
|
|
|
+ const baseUrl = import.meta.env.VITE_SHIP_API_BASE_URL || 'http://localhost:48080';
|
|
|
|
|
+ const apiPath = import.meta.env.VITE_SHIP_API_PATH || '/ship-api';
|
|
|
|
|
+ const url = `${baseUrl}${apiPath}/cms/article/portal/page-list`;
|
|
|
|
|
+ const params = {
|
|
|
|
|
+ lang,
|
|
|
|
|
+ 'type.id': '1955559122615775234'
|
|
|
|
|
+ };
|
|
|
|
|
+
|
|
|
|
|
+ // 生成缓存键
|
|
|
|
|
+ const cacheKey = generateCacheKey(url, params);
|
|
|
|
|
+
|
|
|
|
|
+ // 检查缓存
|
|
|
|
|
+ const cachedData = getCachedData(cacheKey);
|
|
|
|
|
+ if (cachedData) {
|
|
|
|
|
+ return cachedData;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 发起API请求
|
|
|
|
|
+ const response = await axios.get<ApiResponse>(url, { params });
|
|
|
|
|
+
|
|
|
|
|
+ // 缓存响应数据
|
|
|
|
|
+ setCachedData(cacheKey, response.data);
|
|
|
|
|
+
|
|
|
|
|
+ return response.data;
|
|
|
|
|
+ } catch (error) {
|
|
|
|
|
+ console.error('Failed to fetch cruise routes:', error);
|
|
|
|
|
+ throw error;
|
|
|
|
|
+ }
|
|
|
|
|
+};
|
|
|
|
|
+
|
|
|
// 从文章数据中提取视频内容
|
|
// 从文章数据中提取视频内容
|
|
|
export const extractVideoContentFromArticles = (articlesData: ApiResponse): {
|
|
export const extractVideoContentFromArticles = (articlesData: ApiResponse): {
|
|
|
title: string;
|
|
title: string;
|
|
@@ -177,3 +210,73 @@ export const extractVideoContentFromArticles = (articlesData: ApiResponse): {
|
|
|
video: videoArticle.video || undefined
|
|
video: videoArticle.video || undefined
|
|
|
};
|
|
};
|
|
|
};
|
|
};
|
|
|
|
|
+
|
|
|
|
|
+// 定义subContent条目的接口
|
|
|
|
|
+interface SubContentItem {
|
|
|
|
|
+ tid: number;
|
|
|
|
|
+ title: string;
|
|
|
|
|
+ content: string;
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+// 解析subContent字段
|
|
|
|
|
+export const parseSubContent = (subContent: string | null): Record<string, string> => {
|
|
|
|
|
+ if (!subContent) {
|
|
|
|
|
+ return {};
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ try {
|
|
|
|
|
+ const parsedItems: SubContentItem[] = JSON.parse(subContent);
|
|
|
|
|
+ const result: Record<string, string> = {};
|
|
|
|
|
+
|
|
|
|
|
+ // 从每个条目提取内容(去除HTML标签)
|
|
|
|
|
+ parsedItems.forEach(item => {
|
|
|
|
|
+ // 去除HTML标签并保留文本内容
|
|
|
|
|
+ const textContent = item.content.replace(/<[^>]*>/g, '').trim();
|
|
|
|
|
+ result[item.title] = textContent;
|
|
|
|
|
+ });
|
|
|
|
|
+
|
|
|
|
|
+ return result;
|
|
|
|
|
+ } catch (error) {
|
|
|
|
|
+ console.error('Failed to parse subContent:', error);
|
|
|
|
|
+ return {};
|
|
|
|
|
+ }
|
|
|
|
|
+};
|
|
|
|
|
+
|
|
|
|
|
+// 从文章数据中提取游轮航线信息
|
|
|
|
|
+export const extractCruiseRoutesFromArticles = (articlesData: ApiResponse): any[] => {
|
|
|
|
|
+ // 检查API响应是否成功
|
|
|
|
|
+ if (articlesData.code !== 0 || !articlesData.data || !articlesData.data.list) {
|
|
|
|
|
+ return [];
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 转换文章数据为游轮航线格式
|
|
|
|
|
+ return articlesData.data.list.map(article => {
|
|
|
|
|
+ // 解析subContent获取详细信息
|
|
|
|
|
+ const subContentData = parseSubContent(article.subContent);
|
|
|
|
|
+
|
|
|
|
|
+ // 提取天数信息(从title或summary中尝试提取)
|
|
|
|
|
+ let days = 0;
|
|
|
|
|
+ const daysMatch = article.title.match(/\d+天/) || article.summary.match(/\d+天/);
|
|
|
|
|
+ if (daysMatch) {
|
|
|
|
|
+ days = parseInt(daysMatch[0]);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 构建游轮航线对象
|
|
|
|
|
+ return {
|
|
|
|
|
+ id: article.id,
|
|
|
|
|
+ title: article.title || '',
|
|
|
|
|
+ days,
|
|
|
|
|
+ price: subContentData['价格'] || '价格待定',
|
|
|
|
|
+ image: article.coverUrl || '',
|
|
|
|
|
+ video: article.video || undefined,
|
|
|
|
|
+ route: subContentData['目的地'] || '',
|
|
|
|
|
+ description: article.summary || '',
|
|
|
|
|
+ highlights: [
|
|
|
|
|
+ // 从summary中提取亮点,或者使用默认值
|
|
|
|
|
+ ...(article.summary ? [article.summary] : [])
|
|
|
|
|
+ ],
|
|
|
|
|
+ itinerary: [], // 默认空行程,可能需要从content字段进一步解析
|
|
|
|
|
+ schedule: subContentData['航期'] || ''
|
|
|
|
|
+ };
|
|
|
|
|
+ });
|
|
|
|
|
+};
|