统一接口命名

This commit is contained in:
扫地僧 2026-01-28 23:01:38 +08:00
parent 4150203bd3
commit 037774d2f1
15 changed files with 140 additions and 46 deletions

View File

@ -3,5 +3,5 @@ NODE_ENV = 'development'
# 应用配置
VITE_APP_TITLE = '美天科技 - 官网'
# VITE_APP_API_URL = 'http://localhost:8000'
VITE_APP_API_URL = 'https://backend.yunzer.cn'
VITE_API_BASE_URL = 'http://localhost:8000'
# VITE_API_BASE_URL = 'https://backend.yunzer.cn'

View File

@ -3,4 +3,4 @@ NODE_ENV = 'production'
# 应用配置
VITE_APP_TITLE = '美天科技 - 官网'
VITE_APP_API_URL = 'https://backend.yunzer.cn' # 生产环境接口基础URL
VITE_API_BASE_URL = 'https://backend.yunzer.cn' # 生产环境接口基础URL

View File

@ -1,6 +1,6 @@
import service from '@/utils/request'
// 获取新闻中心顶部4篇文章
// 获取站点资讯顶部4篇文章
export const getNewsCenterTop4 = async () => {
const response = await service.get('index/newscentertop4')
return response.data

View File

@ -1,6 +1,6 @@
import service from '@/utils/request'
// 获取企业新闻
// 获取站点新闻
export const getCompanyNews = async (page: number = 1, limit: number = 10) => {
const response = await service.get('index/companynews', {
params: { page, limit }
@ -40,7 +40,7 @@ export const getKingdeeNewsDetail = async (id: number | string) => {
return response.data
}
// 获取企业新闻详情
// 获取站点新闻详情
export const getCompanyNewsDetail = async (id: number | string) => {
const response = await service.get(`index/companynews/detail/${id}`)
return response.data

View File

@ -36,7 +36,7 @@ export const constantRoute = [
component: () => import('@/views/components/articleDetail.vue'),
name: 'companyNewsDetail',
meta: {
title: '企业新闻详情',
title: '站点新闻详情',
hidden: true,
},
},

View File

@ -2,7 +2,7 @@ import axios from 'axios'
// 创建axios实例
const service = axios.create({
baseURL: import.meta.env.VITE_APP_API_URL,
baseURL: import.meta.env.VITE_API_BASE_URL,
timeout: 10000, // 请求超时时间
})

View File

@ -207,7 +207,7 @@ const instance = getCurrentInstance()
const proxy = instance?.proxy as any
const router = useRouter()
const contentRef = ref<HTMLElement | null>(null)
const VITE_APP_API_URL = import.meta.env.VITE_APP_API_URL
const VITE_API_BASE_URL = import.meta.env.VITE_API_BASE_URL
//
const handleCopyCode = async (e: Event) => {
@ -278,7 +278,7 @@ const imagePath = (path: string) => {
if (!path) {
return new URL('@/assets/images/noimage.png', import.meta.url).href
}
return VITE_APP_API_URL + path
return VITE_API_BASE_URL + path
}
const goToArticle = (id: number) => {

View File

@ -11,7 +11,7 @@
<ul>
<li>企业概况</li>
<li>公司证件</li>
<li>新闻中心</li>
<li>站点资讯</li>
<li>加入我们</li>
<li>联系我们</li>
</ul>

View File

@ -72,10 +72,10 @@
</div>
<main class="content-container">
<!-- 新闻中心 -->
<!-- 站点资讯 -->
<div class="newscenter">
<div class="title">
<span class="text-4xl">新闻中心</span>
<span class="text-4xl">站点资讯</span>
<span class="text-xl">&nbsp;&nbsp;/&nbsp;&nbsp;NEWS CENTER</span>
</div>
<div class="content">
@ -347,7 +347,7 @@ const fetchNewsData = async () => {
image: item.image
? item.image.startsWith('http')
? item.image
: `${import.meta.env.VITE_APP_API_URL}${item.image}`
: `${import.meta.env.VITE_API_BASE_URL}${item.image}`
: '',
}))

View File

@ -4,11 +4,45 @@
<div class="content-container">
<div class="topcontent">
<div class="top-content">
<div class="top-content-title">新闻中心 - 金蝶新闻</div>
<div class="top-content-subtitle">NEWS CENTER - KINGDEE NEWS</div>
<div class="top-content-title">站点资讯 - 站点公告</div>
<div class="top-content-subtitle">NEWS CENTER - ANNOUNCEMENT</div>
</div>
</div>
<div class="maincontent">
<!-- 筛选栏 -->
<div class="filter-panel">
<div class="filter-row">
<span class="filter-label">新闻分类</span>
<div class="filter-options">
<span
v-for="item in categoryList"
:key="item.value"
:class="[
'filter-item',
{ active: activeCategory === item.value },
]"
@click="activeCategory = item.value"
>
{{ item.label }}
</span>
</div>
</div>
<div class="filter-row">
<span class="filter-label">新闻属性</span>
<div class="filter-options">
<span
v-for="item in flagList"
:key="item.value"
:class="['filter-item', { active: activeFlag === item.value }]"
@click="activeFlag = item.value"
>
{{ item.label }}
</span>
</div>
</div>
</div>
<!-- 加载状态 -->
<div v-if="loading" class="loading-state">
<i class="fas fa-spinner fa-spin"></i>
@ -32,8 +66,8 @@
<div class="card-image" v-if="news.image">
<img :src="getImageUrl(news.image)" :alt="news.title" />
</div>
<div v-else class="card-image-placeholder card-image">
<img src="@/assets/images/noimage.png">
<div v-else class="card-image-placeholder">
<i class="fas fa-image"></i>
</div>
<div class="card-content">
<div class="card-title-container">
@ -94,13 +128,14 @@
<Footer />
</template>
<script lang="ts" setup>
import { ref, onMounted, computed } from 'vue'
import { computed, onMounted, ref } from 'vue'
import { useRouter } from 'vue-router'
import Header from '@/views/components/header.vue'
import Footer from '@/views/components/footer.vue'
import { getKingdeeNews } from '@/api/newscenter'
import { getCompanyNews } from '@/api/newscenter'
const router = useRouter()
const newsData = ref<any[]>([])
const loading = ref(false)
const loadingMore = ref(false)
@ -109,10 +144,25 @@ const currentPage = ref(1)
const pageSize = ref(12) // 12
const total = ref(0)
//
const goToDetail = (id: number) => {
router.push(`/newscenter/kingdeeNews/detail/${id}`)
}
//
const categoryList = [
{ label: '全部', value: 'all' },
{ label: '公司新闻', value: 'company' },
{ label: '行业新闻', value: 'industry' },
{ label: '媒体报道', value: 'media' },
]
const flagList = [
{ label: '全部', value: 'all' },
{ label: '置顶', value: 'top' },
{ label: '推荐', value: 'recommend' },
]
//
const activeCategory = ref('all')
const activeFlag = ref('all')
//
const hasMore = computed(() => {
@ -123,7 +173,7 @@ const hasMore = computed(() => {
const getImageUrl = (image: string) => {
if (!image) return ''
if (image.startsWith('http')) return image
return `${import.meta.env.VITE_APP_API_URL || ''}${image}`
return `${import.meta.env.VITE_API_BASE_URL || ''}${image}`
}
//
@ -137,6 +187,10 @@ const formatDate = (date: string) => {
})
}
const goToDetail = (id: number) => {
router.push(`/newscenter/companyNews/detail/${id}`)
}
//
const loadMore = async () => {
if (loadingMore.value || !hasMore.value) return
@ -145,7 +199,7 @@ const loadMore = async () => {
currentPage.value++
try {
const response = await getKingdeeNews(currentPage.value, pageSize.value)
const response = await getCompanyNews(currentPage.value, pageSize.value)
if (response.code === 200) {
//
newsData.value = [...newsData.value, ...(response.list || [])]
@ -170,7 +224,7 @@ const loadNews = async () => {
currentPage.value = 1
try {
const response = await getKingdeeNews(currentPage.value, pageSize.value)
const response = await getCompanyNews(currentPage.value, pageSize.value)
if (response.code === 200) {
newsData.value = response.list || []
total.value = response.total || 0
@ -199,11 +253,58 @@ onMounted(() => {
min-height: calc(100vh - 80px);
display: flex;
flex-direction: column;
.filter-panel {
background: #fff;
padding: 20px 30px;
margin-bottom: 40px;
border-radius: 8px;
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
.filter-row {
display: flex;
align-items: center;
padding: 12px 0;
border-bottom: 1px dashed #eee;
&:last-child {
border-bottom: none;
}
.filter-label {
width: 90px;
font-size: 14px;
font-weight: 500;
color: #333;
flex-shrink: 0;
}
.filter-options {
display: flex;
flex-wrap: wrap;
gap: 16px;
.filter-item {
font-size: 14px;
color: #666;
cursor: pointer;
transition: all 0.2s;
&:hover {
color: #1890ff;
}
&.active {
color: #1890ff;
font-weight: 600;
}
}
}
}
}
.topcontent {
height: 450px;
width: 100%;
background-image: url(@/assets/images/kingdeenews.jpg);
background-image: url(@/assets/images/newscenter.jpg);
background-size: cover;
background-position: center;
flex-shrink: 0;
@ -212,11 +313,13 @@ onMounted(() => {
padding-top: 180px;
width: 1200px;
margin: 0 auto;
.top-content-title {
font-size: 35px;
font-weight: 600;
color: #fff;
}
.top-content-subtitle {
width: 300px;
margin-top: 20px;
@ -253,6 +356,7 @@ onMounted(() => {
.error-state {
color: #f56c6c;
i {
color: #f56c6c;
}
@ -365,10 +469,6 @@ onMounted(() => {
overflow: hidden;
flex: 1;
min-width: 0;
span {
margin-right: 6px;
}
}
}

View File

@ -4,8 +4,8 @@
<div class="content-container">
<div class="topcontent">
<div class="top-content">
<div class="top-content-title">新闻中心 - 企业新闻</div>
<div class="top-content-subtitle">NEWS CENTER - COMPANY NEWS</div>
<div class="top-content-title">站点资讯 - 站点新闻</div>
<div class="top-content-subtitle">NEWS CENTER - NEWS</div>
</div>
</div>
<div class="maincontent">
@ -173,7 +173,7 @@ const hasMore = computed(() => {
const getImageUrl = (image: string) => {
if (!image) return ''
if (image.startsWith('http')) return image
return `${import.meta.env.VITE_APP_API_URL || ''}${image}`
return `${import.meta.env.VITE_API_BASE_URL || ''}${image}`
}
//

View File

@ -149,7 +149,7 @@ const hasMore = computed(() => {
const getImageUrl = (image: string, cateId?: number) => {
if (image) {
if (image.startsWith('http')) return image
return `${import.meta.env.VITE_APP_API_URL || ''}${image}`
return `${import.meta.env.VITE_API_BASE_URL || ''}${image}`
}
// 使
if (cateId) {
@ -157,7 +157,7 @@ const getImageUrl = (image: string, cateId?: number) => {
if (category?.image) {
const catImage = category.image
if (catImage.startsWith('http')) return catImage
return `${import.meta.env.VITE_APP_API_URL || ''}${catImage}`
return `${import.meta.env.VITE_API_BASE_URL || ''}${catImage}`
}
}
return ''

View File

@ -108,7 +108,7 @@ const hasMore = computed(() => {
const getImageUrl = (image: string) => {
if (!image) return ''
if (image.startsWith('http')) return image
return `${import.meta.env.VITE_APP_API_URL || ''}${image}`
return `${import.meta.env.VITE_API_BASE_URL || ''}${image}`
}
//

View File

@ -9,7 +9,7 @@ import { ElMessage } from 'element-plus'
//第一步:利用axios对象的create方法,去创建axios实例(其他的配置:基础路径、超时的时间)
let request = axios.create({
//基础路径
baseURL: import.meta.env.VITE_APP_BASE_API, //基础路径上会携带/api
baseURL: import.meta.env.VITE_API_BASE_URL, //基础路径上会携带/api
timeout: 5000, //超时的时间的设置
withCredentials: true, // 异步请求携带cookie
// headers: {

View File

@ -56,15 +56,9 @@ export default defineConfig(({ mode }: ConfigEnv): UserConfig => {
strictPort: false, // 端口被占用时尝试其他端口
// 代理配置
proxy: {
// 开发环境 API 代理
[env.VITE_APP_BASE_API]: {
target: env.VITE_APP_BASE_URL,
changeOrigin: true,
rewrite: (path) => path.replace(new RegExp(`^${env.VITE_APP_BASE_API}`), '')
},
// 本地开发 API 代理
'/api': {
target: 'http://localhost:3000', // 本地开发服务器地址
target: env.VITE_API_BASE_URL, // 后端 API 服务器地址
changeOrigin: true,
rewrite: (path) => path.replace(/^\/api/, '')
}