diff --git a/app/components/RecommendedArticles.vue b/app/components/RecommendedArticles.vue new file mode 100644 index 0000000..48a6ea8 --- /dev/null +++ b/app/components/RecommendedArticles.vue @@ -0,0 +1,313 @@ + + + + + diff --git a/app/components/news/new.vue b/app/components/news/new.vue index ec96ba2..b6da640 100644 --- a/app/components/news/new.vue +++ b/app/components/news/new.vue @@ -305,46 +305,15 @@ const loadCSSFiles = () => { - +
-

解决方案

- -
- - -
-

开发知识

- -
- - -
-

行业动态

- +
diff --git a/app/composables/useArticleApi.ts b/app/composables/useArticleApi.ts new file mode 100644 index 0000000..5b4f81b --- /dev/null +++ b/app/composables/useArticleApi.ts @@ -0,0 +1,122 @@ +// 文章API服务 +export interface Article { + id: string + title: string + brief: string | null + content: string | null + createTime: string + code: string | null + status: string | null +} + +export interface ArticleListResponse { + msg: string + code: number + data: Article[] +} + +export interface ArticleListParams { + code?: string // 文章类型:solution、developKnowledge、industryTrend + orderByColumn?: string + isAsc?: string + pageNum?: number + pageSize?: number +} + +// API基础地址 +const API_BASE_URL = 'http://192.168.2.26:4101' + +/** + * 获取文章列表 + * @param params 查询参数 + * @returns Promise + */ +export const fetchArticleList = async (params: ArticleListParams = {}): Promise => { + try { + // 构建查询参数 + const queryParams = new URLSearchParams() + + if (params.code) queryParams.append('code', params.code) + if (params.orderByColumn) queryParams.append('orderByColumn', params.orderByColumn) + if (params.isAsc) queryParams.append('isAsc', params.isAsc) + if (params.pageNum) queryParams.append('pageNum', params.pageNum.toString()) + if (params.pageSize) queryParams.append('pageSize', params.pageSize.toString()) + + const url = `${API_BASE_URL}/app/owArticle/list?${queryParams.toString()}` + + const response = await fetch(url, { + method: 'GET', + headers: { + 'Content-Type': 'application/json', + }, + }) + + if (!response.ok) { + throw new Error(`HTTP error! status: ${response.status}`) + } + + const result: ArticleListResponse = await response.json() + return result + } catch (error) { + console.error('获取文章列表失败:', error) + throw error + } +} + +/** + * 获取推荐文章(按类型分组) + * @param types 文章类型数组 + * @param pageSize 每页数量 + * @returns Promise> + */ +export const fetchRecommendedArticles = async ( + types: string[] = ['solution', 'developKnowledge', 'industryTrend'], + pageSize: number = 5 +): Promise> => { + try { + const result: Record = {} + + // 并发获取各类型文章 + const promises = types.map(async (type) => { + const response = await fetchArticleList({ + code: type, + orderByColumn: 'createTime', + isAsc: 'descending', + pageNum: 1, + pageSize: pageSize + }) + return { type, articles: response.data } + }) + + const responses = await Promise.all(promises) + + // 整理结果 + responses.forEach(({ type, articles }) => { + result[type] = articles + }) + + return result + } catch (error) { + console.error('获取推荐文章失败:', error) + throw error + } +} + +/** + * 文章类型映射 + */ +export const ARTICLE_TYPE_MAP: Record = { + 'solution': '解决方案', + 'developKnowledge': '开发知识', + 'industryTrend': '行业动态', + 'aboutUs': '关于我们' +} + +/** + * 获取文章类型的中文名称 + * @param code 文章类型代码 + * @returns 中文名称 + */ +export const getArticleTypeName = (code: string): string => { + return ARTICLE_TYPE_MAP[code] || '未知类型' +}