feat(api): 重构新闻API请求方式并添加测试环境配置

- 将拼接字符串的请求方式改为对象配置方式
- 添加对测试环境API地址的支持
- 增加baseURL配置以支持不同环境

refactor(news): 优化多个组件的代码结构和错误处理

- 修复数据为空时的访问错误,添加安全检查
- 限制股票显示数量为前两个
- 优化API响应数据的安全访问

style(article): 调整样式和注释相关修改

- 注释掉不需要的底部填充样式
- 隐藏分割线和评论组件
- 更新星级评分的显示方式
This commit is contained in:
傅光孟 2026-02-11 12:01:41 +08:00
parent c1f96448f8
commit 0154e114d9
8 changed files with 65 additions and 19 deletions

View File

@ -23,7 +23,15 @@ export const getTopNewsDay = (data: any) => {
// 概念标签贴标
export const getTopNews = (data: any) => {
return request.get("/top_news_h5_period?start_date=" + data.start_date + "&end_date=" + data.end_date + "&limit_num=" + data.limit_num, data);
return request.get(
"/top_news_h5_period?start_date=" +
data.start_date +
"&end_date=" +
data.end_date +
"&limit_num=" +
data.limit_num,
data,
);
// return request.get("/top_news_h5_d", data);
};
// 概念标签贴标
@ -48,14 +56,44 @@ export const getNews_cnt_d = (data: any) => {
// 热门标签某时间段内topN列表左边第一个
export const getTopConceptPeriod = (data: any) => {
return request.get("/top_concept_period?start_date=" + data.start_time + "&end_date=" + data.end_time + "&limit_num=" + data.limit_num, data);
// return request.get("/top_concept_period?start_date=" + data.start_time + "&end_date=" + data.end_time + "&limit_num=" + data.limit_num, data);
console.log("output >>>>> ", import.meta.env.MODE);
return request({
baseURL: import.meta.env.VITE_API_TEST_DATAV_URL,
url: "/top_concept_period",
method: "get",
params: {
start_date: data.start_time,
end_date: data.end_time,
limit_num: data.limit_num,
},
});
};
// 热门行业某时间段内topN列表中间第二个
export const getTopIndustryPeriod = (data: any) => {
return request.get("/top_industry_period?start_date=" + data.start_time + "&end_date=" + data.end_time + "&limit_num=" + data.limit_num, data);
// return request.get("/top_industry_period?start_date=" + data.start_time + "&end_date=" + data.end_time + "&limit_num=" + data.limit_num, data);
return request({
baseURL: import.meta.env.VITE_API_TEST_DATAV_URL,
url: "/top_industry_period",
method: "get",
params: {
start_date: data.start_time,
end_date: data.end_time,
limit_num: data.limit_num,
},
});
};
// 热门标签某时间段内topN列表右边
export const getTopSourcePeriod = (data: any) => {
return request.get("/top_source_period?start_date=" + data.start_time + "&end_date=" + data.end_time + "&limit_num=" + data.limit_num, data);
return request.get(
"/top_source_period?start_date=" +
data.start_time +
"&end_date=" +
data.end_time +
"&limit_num=" +
data.limit_num,
data,
);
};

View File

@ -340,7 +340,7 @@ const getMoreNews = () => {
<style lang="scss" scoped>
.page-container {
background-color: #f3f5f8;
padding-bottom: 80rpx;
// padding-bottom: 80rpx;
}
.main {
position: relative;

View File

@ -18,7 +18,7 @@
/>
<!-- 分割 -->
<view class="line"></view>
<!-- <view class="line"></view> -->
<!-- 推荐栏目 -->
<!-- <Column
:data="columnList"
@ -28,11 +28,11 @@
/> -->
<!-- 底部栏 评论 / 收藏 -->
<Comment
<!-- <Comment
:data="data"
@handleClickLike="handleClickLike"
@handleClickStar="handleClickStar"
/>
/> -->
</view>
</template>

View File

@ -64,10 +64,12 @@
<text class="tag">{{ news.companyName }}</text>
</view>
<view class="stocks" v-if="news.stocks?.length > 0">
<view class="stock" v-for="(stock, index) in news.stocks" :key="index">
<template v-for="(stock, index) in news.stocks" :key="index">
<view class="stock" v-if="index < 2">
<text class="name">{{ stock.name }}</text>
<text class="code">{{ stock.code }}</text>
</view>
</template>
</view>
</view>
</view>

View File

@ -45,7 +45,7 @@ async function getList() {
//
let { code, data } = await getListByTag({ name });
if (code == 200) {
oneData.value = data[0];
oneData.value = data && data.length > 0 ? data[0] : {};
}
}
@ -55,6 +55,7 @@ function goDetail(item: any) {
emit("onShow");
return;
}
if (!item.id) return;
uni.navigateTo({
url: `/pages/detail/indexNewsInfo?id=${item.id}`,
});

View File

@ -63,7 +63,7 @@ async function getList() {
//
let { code, data } = await getListByTagIndustry({ name });
if (code == 200) {
oneData.value = data[0];
oneData.value = data && data.length > 0 ? data[0] : {};
}
}
@ -73,6 +73,7 @@ function goDetail(item: any) {
emit("onShow");
return;
}
if (!item.id) return;
uni.navigateTo({
url: `/pages/detail/indexNewsInfo?id=${item.id}`,
});

View File

@ -54,7 +54,7 @@
<view class="news-top">
<view class="time">{{ news.timeStr }}</view>
<view class="source">
<view class="star" v-if="news.rating" :style="{ width: `${(news.rating/2) * 20}rpx` }"></view>
<view class="star" v-if="news.rating">{{ news.rating }}</view>
<view class="t-1">来自</view>
<view class="t-2">中国证券报</view>
</view>
@ -409,10 +409,14 @@ onMounted(async () => {
}
.star {
height: 20rpx;
margin-right: 6rpx;
background: url("@/assets/images/page/star_icon@2x.png");
// height: 20rpx;
margin-right: 10rpx;
padding-right: 24rpx;
background: url("@/assets/images/page/star_icon@2x.png") no-repeat center right;
background-size: 20rpx 20rpx;
font-size: 24rpx;
line-height: 24rpx;
color: #222222;
}
}
}

View File

@ -23,7 +23,7 @@ service.interceptors.request.use(
// 在发送请求之前做些什么 token
if (Session.get("token")) {
config.headers!["auth-token"] = `${Session.get("token")}`;
config.headers!["phone"] = `${Session.get("userPhone")}`;
config.headers!["phone"] = `${Session.get("userInfos").phone}`;
}
return config;
},