api路径更改
This commit is contained in:
parent
ae691c6db9
commit
dac7e6f727
|
|
@ -41,7 +41,7 @@ const props = withDefaults(defineProps<Props>(), {
|
||||||
})
|
})
|
||||||
|
|
||||||
// API基础地址
|
// API基础地址
|
||||||
const API_BASE_URL = 'http://192.168.2.26:4101'
|
const API_BASE_URL = 'http://192.168.2.77:4101'
|
||||||
|
|
||||||
// 内部文章数据(当没有外部传入时使用)
|
// 内部文章数据(当没有外部传入时使用)
|
||||||
const internalArticleData = ref({
|
const internalArticleData = ref({
|
||||||
|
|
@ -354,10 +354,10 @@ const loadCSSFiles = () => {
|
||||||
<div
|
<div
|
||||||
class="sy_news animated" data-wow-delay="200ms"
|
class="sy_news animated" data-wow-delay="200ms"
|
||||||
style="visibility: visible; animation-delay: 200ms; animation-name: fadeInDown;">
|
style="visibility: visible; animation-delay: 200ms; animation-name: fadeInDown;">
|
||||||
<RecommendedArticles
|
<RecommendedArticles
|
||||||
:show-types="['solution', 'developKnowledge', 'industryTrend']"
|
:articles-per-type="3"
|
||||||
:articles-per-type="3"
|
:show-title="false"
|
||||||
:show-title="false"
|
:show-types="['solution', 'developKnowledge', 'industryTrend']"
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
</aside><!-- 右边部分 -->
|
</aside><!-- 右边部分 -->
|
||||||
|
|
|
||||||
|
|
@ -1,30 +1,30 @@
|
||||||
// 文章API服务
|
// 文章API服务
|
||||||
export interface Article {
|
export interface Article {
|
||||||
id: string
|
id: string
|
||||||
title: string
|
title: string
|
||||||
brief: string | null
|
brief: string | null
|
||||||
content: string | null
|
content: string | null
|
||||||
createTime: string
|
createTime: string
|
||||||
code: string | null
|
code: string | null
|
||||||
status: string | null
|
status: string | null
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface ArticleListResponse {
|
export interface ArticleListResponse {
|
||||||
msg: string
|
msg: string
|
||||||
code: number
|
code: number
|
||||||
data: Article[]
|
data: Article[]
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface ArticleListParams {
|
export interface ArticleListParams {
|
||||||
code?: string // 文章类型:solution、developKnowledge、industryTrend
|
code?: string // 文章类型:solution、developKnowledge、industryTrend
|
||||||
orderByColumn?: string
|
orderByColumn?: string
|
||||||
isAsc?: string
|
isAsc?: string
|
||||||
pageNum?: number
|
pageNum?: number
|
||||||
pageSize?: number
|
pageSize?: number
|
||||||
}
|
}
|
||||||
|
|
||||||
// API基础地址
|
// 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>
|
* @returns Promise<ArticleListResponse>
|
||||||
*/
|
*/
|
||||||
export const fetchArticleList = async (params: ArticleListParams = {}): Promise<ArticleListResponse> => {
|
export const fetchArticleList = async (params: ArticleListParams = {}): Promise<ArticleListResponse> => {
|
||||||
try {
|
try {
|
||||||
// 构建查询参数
|
// 构建查询参数
|
||||||
const queryParams = new URLSearchParams()
|
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()}`
|
if (params.code) queryParams.append('code', params.code)
|
||||||
|
if (params.orderByColumn) queryParams.append('orderByColumn', params.orderByColumn)
|
||||||
const response = await fetch(url, {
|
if (params.isAsc) queryParams.append('isAsc', params.isAsc)
|
||||||
method: 'GET',
|
if (params.pageNum) queryParams.append('pageNum', params.pageNum.toString())
|
||||||
headers: {
|
if (params.pageSize) queryParams.append('pageSize', params.pageSize.toString())
|
||||||
'Content-Type': 'application/json',
|
|
||||||
},
|
|
||||||
})
|
|
||||||
|
|
||||||
if (!response.ok) {
|
const url = `${API_BASE_URL}/app/owArticle/list?${queryParams.toString()}`
|
||||||
throw new Error(`HTTP error! status: ${response.status}`)
|
|
||||||
|
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
|
||||||
}
|
}
|
||||||
|
|
||||||
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[]>>
|
* @returns Promise<Record<string, Article[]>>
|
||||||
*/
|
*/
|
||||||
export const fetchRecommendedArticles = async (
|
export const fetchRecommendedArticles = async (
|
||||||
types: string[] = ['solution', 'developKnowledge', 'industryTrend'],
|
types: string[] = ['solution', 'developKnowledge', 'industryTrend'],
|
||||||
pageSize: number = 5
|
pageSize: number = 5
|
||||||
): Promise<Record<string, Article[]>> => {
|
): Promise<Record<string, Article[]>> => {
|
||||||
try {
|
try {
|
||||||
const result: Record<string, Article[]> = {}
|
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 responses = await Promise.all(promises)
|
// 并发获取各类型文章
|
||||||
|
const promises = types.map(async (type) => {
|
||||||
// 整理结果
|
const response = await fetchArticleList({
|
||||||
responses.forEach(({ type, articles }) => {
|
code: type,
|
||||||
result[type] = articles
|
orderByColumn: 'createTime',
|
||||||
})
|
isAsc: 'descending',
|
||||||
|
pageNum: 1,
|
||||||
|
pageSize: pageSize
|
||||||
|
})
|
||||||
|
return {type, articles: response.data}
|
||||||
|
})
|
||||||
|
|
||||||
return result
|
const responses = await Promise.all(promises)
|
||||||
} catch (error) {
|
|
||||||
console.error('获取推荐文章失败:', error)
|
// 整理结果
|
||||||
throw error
|
responses.forEach(({type, articles}) => {
|
||||||
}
|
result[type] = articles
|
||||||
|
})
|
||||||
|
|
||||||
|
return result
|
||||||
|
} catch (error) {
|
||||||
|
console.error('获取推荐文章失败:', error)
|
||||||
|
throw error
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 文章类型映射
|
* 文章类型映射
|
||||||
*/
|
*/
|
||||||
export const ARTICLE_TYPE_MAP: Record<string, string> = {
|
export const ARTICLE_TYPE_MAP: Record<string, string> = {
|
||||||
'solution': '解决方案',
|
'solution': '解决方案',
|
||||||
'developKnowledge': '开发知识',
|
'developKnowledge': '开发知识',
|
||||||
'industryTrend': '行业动态',
|
'industryTrend': '行业动态',
|
||||||
'aboutUs': '关于我们'
|
'aboutUs': '关于我们'
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -118,7 +118,7 @@ export const ARTICLE_TYPE_MAP: Record<string, string> = {
|
||||||
* @returns 中文名称
|
* @returns 中文名称
|
||||||
*/
|
*/
|
||||||
export const getArticleTypeName = (code: string): string => {
|
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相关方法
|
* @returns 文章API相关方法
|
||||||
*/
|
*/
|
||||||
export const useArticleApi = () => {
|
export const useArticleApi = () => {
|
||||||
/**
|
/**
|
||||||
* 获取文章列表
|
* 获取文章列表
|
||||||
* @param params 查询参数
|
* @param params 查询参数
|
||||||
* @returns Promise<Article[]>
|
* @returns Promise<Article[]>
|
||||||
*/
|
*/
|
||||||
const getArticles = async (params: ArticleListParams = {}): Promise<Article[]> => {
|
const getArticles = async (params: ArticleListParams = {}): Promise<Article[]> => {
|
||||||
try {
|
try {
|
||||||
const response = await fetchArticleList(params)
|
const response = await fetchArticleList(params)
|
||||||
return response.data || []
|
return response.data || []
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('获取文章列表失败:', error)
|
console.error('获取文章列表失败:', error)
|
||||||
return []
|
return []
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取推荐文章(按类型分组)
|
* 获取推荐文章(按类型分组)
|
||||||
* @param types 文章类型数组
|
* @param types 文章类型数组
|
||||||
* @param pageSize 每页数量
|
* @param pageSize 每页数量
|
||||||
* @returns Promise<Record<string, Article[]>>
|
* @returns Promise<Record<string, Article[]>>
|
||||||
*/
|
*/
|
||||||
const getRecommendedArticles = async (
|
const getRecommendedArticles = async (
|
||||||
types: string[] = ['solution', 'developKnowledge', 'industryTrend'],
|
types: string[] = ['solution', 'developKnowledge', 'industryTrend'],
|
||||||
pageSize: number = 5
|
pageSize: number = 5
|
||||||
): Promise<Record<string, Article[]>> => {
|
): Promise<Record<string, Article[]>> => {
|
||||||
return await fetchRecommendedArticles(types, pageSize)
|
return await fetchRecommendedArticles(types, pageSize)
|
||||||
}
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
getArticles,
|
getArticles,
|
||||||
getRecommendedArticles,
|
getRecommendedArticles,
|
||||||
getArticleTypeName
|
getArticleTypeName
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -29,7 +29,7 @@ const loading = ref(true)
|
||||||
const error = ref('')
|
const error = ref('')
|
||||||
|
|
||||||
// API基础地址
|
// 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) => {
|
const fetchArticle = async (id: string) => {
|
||||||
|
|
@ -98,7 +98,7 @@ watch(() => route.params.id, (newId) => {
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
<view>
|
<view>
|
||||||
<NewsNew :article-data="articleData" :loading="loading" :error="error" />
|
<NewsNew :article-data="articleData" :error="error" :loading="loading"/>
|
||||||
</view>
|
</view>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user