api路径更改

This commit is contained in:
WindowBird 2025-10-13 09:07:28 +08:00
parent ae691c6db9
commit dac7e6f727
3 changed files with 111 additions and 111 deletions

View File

@ -41,7 +41,7 @@ const props = withDefaults(defineProps<Props>(), {
})
// API
const API_BASE_URL = 'http://192.168.2.26:4101'
const API_BASE_URL = 'http://192.168.2.77:4101'
// 使
const internalArticleData = ref({
@ -355,9 +355,9 @@ const loadCSSFiles = () => {
class="sy_news animated" data-wow-delay="200ms"
style="visibility: visible; animation-delay: 200ms; animation-name: fadeInDown;">
<RecommendedArticles
:show-types="['solution', 'developKnowledge', 'industryTrend']"
:articles-per-type="3"
:show-title="false"
:articles-per-type="3"
:show-title="false"
:show-types="['solution', 'developKnowledge', 'industryTrend']"
/>
</div>
</aside><!-- 右边部分 -->

View File

@ -1,30 +1,30 @@
// 文章API服务
export interface Article {
id: string
title: string
brief: string | null
content: string | null
createTime: string
code: string | null
status: string | null
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[]
msg: string
code: number
data: Article[]
}
export interface ArticleListParams {
code?: string // 文章类型solution、developKnowledge、industryTrend
orderByColumn?: string
isAsc?: string
pageNum?: number
pageSize?: number
code?: string // 文章类型solution、developKnowledge、industryTrend
orderByColumn?: string
isAsc?: string
pageNum?: number
pageSize?: number
}
// API基础地址
const API_BASE_URL = 'http://192.168.2.26:4101'
const API_BASE_URL = 'http://192.168.2.77:4101'
/**
*
@ -32,35 +32,35 @@ const API_BASE_URL = 'http://192.168.2.26:4101'
* @returns Promise<ArticleListResponse>
*/
export const fetchArticleList = async (params: ArticleListParams = {}): Promise<ArticleListResponse> => {
try {
// 构建查询参数
const queryParams = new URLSearchParams()
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())
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 url = `${API_BASE_URL}/app/owArticle/list?${queryParams.toString()}`
const response = await fetch(url, {
method: 'GET',
headers: {
'Content-Type': 'application/json',
},
})
const response = await fetch(url, {
method: 'GET',
headers: {
'Content-Type': 'application/json',
},
})
if (!response.ok) {
throw new Error(`HTTP error! status: ${response.status}`)
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
}
const result: ArticleListResponse = await response.json()
return result
} catch (error) {
console.error('获取文章列表失败:', error)
throw error
}
}
/**
@ -70,46 +70,46 @@ export const fetchArticleList = async (params: ArticleListParams = {}): Promise<
* @returns Promise<Record<string, Article[]>>
*/
export const fetchRecommendedArticles = async (
types: string[] = ['solution', 'developKnowledge', 'industryTrend'],
pageSize: number = 5
types: string[] = ['solution', 'developKnowledge', 'industryTrend'],
pageSize: number = 5
): Promise<Record<string, Article[]>> => {
try {
const result: Record<string, Article[]> = {}
try {
const result: Record<string, Article[]> = {}
// 并发获取各类型文章
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 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)
const responses = await Promise.all(promises)
// 整理结果
responses.forEach(({ type, articles }) => {
result[type] = articles
})
// 整理结果
responses.forEach(({type, articles}) => {
result[type] = articles
})
return result
} catch (error) {
console.error('获取推荐文章失败:', error)
throw error
}
return result
} catch (error) {
console.error('获取推荐文章失败:', error)
throw error
}
}
/**
*
*/
export const ARTICLE_TYPE_MAP: Record<string, string> = {
'solution': '解决方案',
'developKnowledge': '开发知识',
'industryTrend': '行业动态',
'aboutUs': '关于我们'
'solution': '解决方案',
'developKnowledge': '开发知识',
'industryTrend': '行业动态',
'aboutUs': '关于我们'
}
/**
@ -118,7 +118,7 @@ export const ARTICLE_TYPE_MAP: Record<string, string> = {
* @returns
*/
export const getArticleTypeName = (code: string): string => {
return ARTICLE_TYPE_MAP[code] || '未知类型'
return ARTICLE_TYPE_MAP[code] || '未知类型'
}
/**
@ -126,37 +126,37 @@ export const getArticleTypeName = (code: string): string => {
* @returns API相关方法
*/
export const useArticleApi = () => {
/**
*
* @param params
* @returns Promise<Article[]>
*/
const getArticles = async (params: ArticleListParams = {}): Promise<Article[]> => {
try {
const response = await fetchArticleList(params)
return response.data || []
} catch (error) {
console.error('获取文章列表失败:', error)
return []
/**
*
* @param params
* @returns Promise<Article[]>
*/
const getArticles = async (params: ArticleListParams = {}): Promise<Article[]> => {
try {
const response = await fetchArticleList(params)
return response.data || []
} catch (error) {
console.error('获取文章列表失败:', error)
return []
}
}
}
/**
*
* @param types
* @param pageSize
* @returns Promise<Record<string, Article[]>>
*/
const getRecommendedArticles = async (
types: string[] = ['solution', 'developKnowledge', 'industryTrend'],
pageSize: number = 5
): Promise<Record<string, Article[]>> => {
return await fetchRecommendedArticles(types, pageSize)
}
/**
*
* @param types
* @param pageSize
* @returns Promise<Record<string, Article[]>>
*/
const getRecommendedArticles = async (
types: string[] = ['solution', 'developKnowledge', 'industryTrend'],
pageSize: number = 5
): Promise<Record<string, Article[]>> => {
return await fetchRecommendedArticles(types, pageSize)
}
return {
getArticles,
getRecommendedArticles,
getArticleTypeName
}
return {
getArticles,
getRecommendedArticles,
getArticleTypeName
}
}

View File

@ -29,7 +29,7 @@ const loading = ref(true)
const error = ref('')
// API
const API_BASE_URL = 'http://192.168.2.26:4101'
const API_BASE_URL = 'http://192.168.2.77:4101'
//
const fetchArticle = async (id: string) => {
@ -98,7 +98,7 @@ watch(() => route.params.id, (newId) => {
<template>
<view>
<NewsNew :article-data="articleData" :loading="loading" :error="error" />
<NewsNew :article-data="articleData" :error="error" :loading="loading"/>
</view>
</template>