统一接口命名
This commit is contained in:
parent
4150203bd3
commit
037774d2f1
@ -3,5 +3,5 @@ NODE_ENV = 'development'
|
|||||||
|
|
||||||
# 应用配置
|
# 应用配置
|
||||||
VITE_APP_TITLE = '美天科技 - 官网'
|
VITE_APP_TITLE = '美天科技 - 官网'
|
||||||
# VITE_APP_API_URL = 'http://localhost:8000'
|
VITE_API_BASE_URL = 'http://localhost:8000'
|
||||||
VITE_APP_API_URL = 'https://backend.yunzer.cn'
|
# VITE_API_BASE_URL = 'https://backend.yunzer.cn'
|
||||||
@ -3,4 +3,4 @@ NODE_ENV = 'production'
|
|||||||
|
|
||||||
# 应用配置
|
# 应用配置
|
||||||
VITE_APP_TITLE = '美天科技 - 官网'
|
VITE_APP_TITLE = '美天科技 - 官网'
|
||||||
VITE_APP_API_URL = 'https://backend.yunzer.cn' # 生产环境接口基础URL
|
VITE_API_BASE_URL = 'https://backend.yunzer.cn' # 生产环境接口基础URL
|
||||||
@ -1,6 +1,6 @@
|
|||||||
import service from '@/utils/request'
|
import service from '@/utils/request'
|
||||||
|
|
||||||
// 获取新闻中心顶部4篇文章
|
// 获取站点资讯顶部4篇文章
|
||||||
export const getNewsCenterTop4 = async () => {
|
export const getNewsCenterTop4 = async () => {
|
||||||
const response = await service.get('index/newscentertop4')
|
const response = await service.get('index/newscentertop4')
|
||||||
return response.data
|
return response.data
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
import service from '@/utils/request'
|
import service from '@/utils/request'
|
||||||
|
|
||||||
// 获取企业新闻
|
// 获取站点新闻
|
||||||
export const getCompanyNews = async (page: number = 1, limit: number = 10) => {
|
export const getCompanyNews = async (page: number = 1, limit: number = 10) => {
|
||||||
const response = await service.get('index/companynews', {
|
const response = await service.get('index/companynews', {
|
||||||
params: { page, limit }
|
params: { page, limit }
|
||||||
@ -40,7 +40,7 @@ export const getKingdeeNewsDetail = async (id: number | string) => {
|
|||||||
return response.data
|
return response.data
|
||||||
}
|
}
|
||||||
|
|
||||||
// 获取企业新闻详情
|
// 获取站点新闻详情
|
||||||
export const getCompanyNewsDetail = async (id: number | string) => {
|
export const getCompanyNewsDetail = async (id: number | string) => {
|
||||||
const response = await service.get(`index/companynews/detail/${id}`)
|
const response = await service.get(`index/companynews/detail/${id}`)
|
||||||
return response.data
|
return response.data
|
||||||
|
|||||||
@ -36,7 +36,7 @@ export const constantRoute = [
|
|||||||
component: () => import('@/views/components/articleDetail.vue'),
|
component: () => import('@/views/components/articleDetail.vue'),
|
||||||
name: 'companyNewsDetail',
|
name: 'companyNewsDetail',
|
||||||
meta: {
|
meta: {
|
||||||
title: '企业新闻详情',
|
title: '站点新闻详情',
|
||||||
hidden: true,
|
hidden: true,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|||||||
@ -2,7 +2,7 @@ import axios from 'axios'
|
|||||||
|
|
||||||
// 创建axios实例
|
// 创建axios实例
|
||||||
const service = axios.create({
|
const service = axios.create({
|
||||||
baseURL: import.meta.env.VITE_APP_API_URL,
|
baseURL: import.meta.env.VITE_API_BASE_URL,
|
||||||
timeout: 10000, // 请求超时时间
|
timeout: 10000, // 请求超时时间
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|||||||
@ -207,7 +207,7 @@ const instance = getCurrentInstance()
|
|||||||
const proxy = instance?.proxy as any
|
const proxy = instance?.proxy as any
|
||||||
const router = useRouter()
|
const router = useRouter()
|
||||||
const contentRef = ref<HTMLElement | null>(null)
|
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) => {
|
const handleCopyCode = async (e: Event) => {
|
||||||
@ -278,7 +278,7 @@ const imagePath = (path: string) => {
|
|||||||
if (!path) {
|
if (!path) {
|
||||||
return new URL('@/assets/images/noimage.png', import.meta.url).href
|
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) => {
|
const goToArticle = (id: number) => {
|
||||||
|
|||||||
@ -11,7 +11,7 @@
|
|||||||
<ul>
|
<ul>
|
||||||
<li>企业概况</li>
|
<li>企业概况</li>
|
||||||
<li>公司证件</li>
|
<li>公司证件</li>
|
||||||
<li>新闻中心</li>
|
<li>站点资讯</li>
|
||||||
<li>加入我们</li>
|
<li>加入我们</li>
|
||||||
<li>联系我们</li>
|
<li>联系我们</li>
|
||||||
</ul>
|
</ul>
|
||||||
|
|||||||
@ -72,10 +72,10 @@
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<main class="content-container">
|
<main class="content-container">
|
||||||
<!-- 新闻中心 -->
|
<!-- 站点资讯 -->
|
||||||
<div class="newscenter">
|
<div class="newscenter">
|
||||||
<div class="title">
|
<div class="title">
|
||||||
<span class="text-4xl">新闻中心</span>
|
<span class="text-4xl">站点资讯</span>
|
||||||
<span class="text-xl"> / NEWS CENTER</span>
|
<span class="text-xl"> / NEWS CENTER</span>
|
||||||
</div>
|
</div>
|
||||||
<div class="content">
|
<div class="content">
|
||||||
@ -347,7 +347,7 @@ const fetchNewsData = async () => {
|
|||||||
image: item.image
|
image: item.image
|
||||||
? item.image.startsWith('http')
|
? item.image.startsWith('http')
|
||||||
? item.image
|
? item.image
|
||||||
: `${import.meta.env.VITE_APP_API_URL}${item.image}`
|
: `${import.meta.env.VITE_API_BASE_URL}${item.image}`
|
||||||
: '',
|
: '',
|
||||||
}))
|
}))
|
||||||
|
|
||||||
|
|||||||
@ -4,11 +4,45 @@
|
|||||||
<div class="content-container">
|
<div class="content-container">
|
||||||
<div class="topcontent">
|
<div class="topcontent">
|
||||||
<div class="top-content">
|
<div class="top-content">
|
||||||
<div class="top-content-title">新闻中心 - 金蝶新闻</div>
|
<div class="top-content-title">站点资讯 - 站点公告</div>
|
||||||
<div class="top-content-subtitle">NEWS CENTER - KINGDEE NEWS</div>
|
<div class="top-content-subtitle">NEWS CENTER - ANNOUNCEMENT</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="maincontent">
|
<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">
|
<div v-if="loading" class="loading-state">
|
||||||
<i class="fas fa-spinner fa-spin"></i>
|
<i class="fas fa-spinner fa-spin"></i>
|
||||||
@ -32,8 +66,8 @@
|
|||||||
<div class="card-image" v-if="news.image">
|
<div class="card-image" v-if="news.image">
|
||||||
<img :src="getImageUrl(news.image)" :alt="news.title" />
|
<img :src="getImageUrl(news.image)" :alt="news.title" />
|
||||||
</div>
|
</div>
|
||||||
<div v-else class="card-image-placeholder card-image">
|
<div v-else class="card-image-placeholder">
|
||||||
<img src="@/assets/images/noimage.png">
|
<i class="fas fa-image"></i>
|
||||||
</div>
|
</div>
|
||||||
<div class="card-content">
|
<div class="card-content">
|
||||||
<div class="card-title-container">
|
<div class="card-title-container">
|
||||||
@ -94,13 +128,14 @@
|
|||||||
<Footer />
|
<Footer />
|
||||||
</template>
|
</template>
|
||||||
<script lang="ts" setup>
|
<script lang="ts" setup>
|
||||||
import { ref, onMounted, computed } from 'vue'
|
import { computed, onMounted, ref } from 'vue'
|
||||||
import { useRouter } from 'vue-router'
|
import { useRouter } from 'vue-router'
|
||||||
import Header from '@/views/components/header.vue'
|
import Header from '@/views/components/header.vue'
|
||||||
import Footer from '@/views/components/footer.vue'
|
import Footer from '@/views/components/footer.vue'
|
||||||
import { getKingdeeNews } from '@/api/newscenter'
|
import { getCompanyNews } from '@/api/newscenter'
|
||||||
|
|
||||||
const router = useRouter()
|
const router = useRouter()
|
||||||
|
|
||||||
const newsData = ref<any[]>([])
|
const newsData = ref<any[]>([])
|
||||||
const loading = ref(false)
|
const loading = ref(false)
|
||||||
const loadingMore = ref(false)
|
const loadingMore = ref(false)
|
||||||
@ -109,10 +144,25 @@ const currentPage = ref(1)
|
|||||||
const pageSize = ref(12) // 每次加载12条
|
const pageSize = ref(12) // 每次加载12条
|
||||||
const total = ref(0)
|
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(() => {
|
const hasMore = computed(() => {
|
||||||
@ -123,7 +173,7 @@ const hasMore = computed(() => {
|
|||||||
const getImageUrl = (image: string) => {
|
const getImageUrl = (image: string) => {
|
||||||
if (!image) return ''
|
if (!image) return ''
|
||||||
if (image.startsWith('http')) return 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}`
|
||||||
}
|
}
|
||||||
|
|
||||||
// 格式化日期
|
// 格式化日期
|
||||||
@ -137,6 +187,10 @@ const formatDate = (date: string) => {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const goToDetail = (id: number) => {
|
||||||
|
router.push(`/newscenter/companyNews/detail/${id}`)
|
||||||
|
}
|
||||||
|
|
||||||
// 加载更多数据
|
// 加载更多数据
|
||||||
const loadMore = async () => {
|
const loadMore = async () => {
|
||||||
if (loadingMore.value || !hasMore.value) return
|
if (loadingMore.value || !hasMore.value) return
|
||||||
@ -145,7 +199,7 @@ const loadMore = async () => {
|
|||||||
currentPage.value++
|
currentPage.value++
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const response = await getKingdeeNews(currentPage.value, pageSize.value)
|
const response = await getCompanyNews(currentPage.value, pageSize.value)
|
||||||
if (response.code === 200) {
|
if (response.code === 200) {
|
||||||
// 追加新数据到现有列表
|
// 追加新数据到现有列表
|
||||||
newsData.value = [...newsData.value, ...(response.list || [])]
|
newsData.value = [...newsData.value, ...(response.list || [])]
|
||||||
@ -170,7 +224,7 @@ const loadNews = async () => {
|
|||||||
currentPage.value = 1
|
currentPage.value = 1
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const response = await getKingdeeNews(currentPage.value, pageSize.value)
|
const response = await getCompanyNews(currentPage.value, pageSize.value)
|
||||||
if (response.code === 200) {
|
if (response.code === 200) {
|
||||||
newsData.value = response.list || []
|
newsData.value = response.list || []
|
||||||
total.value = response.total || 0
|
total.value = response.total || 0
|
||||||
@ -199,11 +253,58 @@ onMounted(() => {
|
|||||||
min-height: calc(100vh - 80px);
|
min-height: calc(100vh - 80px);
|
||||||
display: flex;
|
display: flex;
|
||||||
flex-direction: column;
|
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 {
|
.topcontent {
|
||||||
height: 450px;
|
height: 450px;
|
||||||
width: 100%;
|
width: 100%;
|
||||||
background-image: url(@/assets/images/kingdeenews.jpg);
|
background-image: url(@/assets/images/newscenter.jpg);
|
||||||
background-size: cover;
|
background-size: cover;
|
||||||
background-position: center;
|
background-position: center;
|
||||||
flex-shrink: 0;
|
flex-shrink: 0;
|
||||||
@ -212,11 +313,13 @@ onMounted(() => {
|
|||||||
padding-top: 180px;
|
padding-top: 180px;
|
||||||
width: 1200px;
|
width: 1200px;
|
||||||
margin: 0 auto;
|
margin: 0 auto;
|
||||||
|
|
||||||
.top-content-title {
|
.top-content-title {
|
||||||
font-size: 35px;
|
font-size: 35px;
|
||||||
font-weight: 600;
|
font-weight: 600;
|
||||||
color: #fff;
|
color: #fff;
|
||||||
}
|
}
|
||||||
|
|
||||||
.top-content-subtitle {
|
.top-content-subtitle {
|
||||||
width: 300px;
|
width: 300px;
|
||||||
margin-top: 20px;
|
margin-top: 20px;
|
||||||
@ -253,6 +356,7 @@ onMounted(() => {
|
|||||||
|
|
||||||
.error-state {
|
.error-state {
|
||||||
color: #f56c6c;
|
color: #f56c6c;
|
||||||
|
|
||||||
i {
|
i {
|
||||||
color: #f56c6c;
|
color: #f56c6c;
|
||||||
}
|
}
|
||||||
@ -365,10 +469,6 @@ onMounted(() => {
|
|||||||
overflow: hidden;
|
overflow: hidden;
|
||||||
flex: 1;
|
flex: 1;
|
||||||
min-width: 0;
|
min-width: 0;
|
||||||
|
|
||||||
span {
|
|
||||||
margin-right: 6px;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -4,8 +4,8 @@
|
|||||||
<div class="content-container">
|
<div class="content-container">
|
||||||
<div class="topcontent">
|
<div class="topcontent">
|
||||||
<div class="top-content">
|
<div class="top-content">
|
||||||
<div class="top-content-title">新闻中心 - 企业新闻</div>
|
<div class="top-content-title">站点资讯 - 站点新闻</div>
|
||||||
<div class="top-content-subtitle">NEWS CENTER - COMPANY NEWS</div>
|
<div class="top-content-subtitle">NEWS CENTER - NEWS</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="maincontent">
|
<div class="maincontent">
|
||||||
@ -173,7 +173,7 @@ const hasMore = computed(() => {
|
|||||||
const getImageUrl = (image: string) => {
|
const getImageUrl = (image: string) => {
|
||||||
if (!image) return ''
|
if (!image) return ''
|
||||||
if (image.startsWith('http')) return 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}`
|
||||||
}
|
}
|
||||||
|
|
||||||
// 格式化日期
|
// 格式化日期
|
||||||
@ -149,7 +149,7 @@ const hasMore = computed(() => {
|
|||||||
const getImageUrl = (image: string, cateId?: number) => {
|
const getImageUrl = (image: string, cateId?: number) => {
|
||||||
if (image) {
|
if (image) {
|
||||||
if (image.startsWith('http')) return 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) {
|
if (cateId) {
|
||||||
@ -157,7 +157,7 @@ const getImageUrl = (image: string, cateId?: number) => {
|
|||||||
if (category?.image) {
|
if (category?.image) {
|
||||||
const catImage = category.image
|
const catImage = category.image
|
||||||
if (catImage.startsWith('http')) return catImage
|
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 ''
|
return ''
|
||||||
|
|||||||
@ -108,7 +108,7 @@ const hasMore = computed(() => {
|
|||||||
const getImageUrl = (image: string) => {
|
const getImageUrl = (image: string) => {
|
||||||
if (!image) return ''
|
if (!image) return ''
|
||||||
if (image.startsWith('http')) return 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}`
|
||||||
}
|
}
|
||||||
|
|
||||||
// 格式化日期
|
// 格式化日期
|
||||||
|
|||||||
@ -9,7 +9,7 @@ import { ElMessage } from 'element-plus'
|
|||||||
//第一步:利用axios对象的create方法,去创建axios实例(其他的配置:基础路径、超时的时间)
|
//第一步:利用axios对象的create方法,去创建axios实例(其他的配置:基础路径、超时的时间)
|
||||||
let request = axios.create({
|
let request = axios.create({
|
||||||
//基础路径
|
//基础路径
|
||||||
baseURL: import.meta.env.VITE_APP_BASE_API, //基础路径上会携带/api
|
baseURL: import.meta.env.VITE_API_BASE_URL, //基础路径上会携带/api
|
||||||
timeout: 5000, //超时的时间的设置
|
timeout: 5000, //超时的时间的设置
|
||||||
withCredentials: true, // 异步请求携带cookie
|
withCredentials: true, // 异步请求携带cookie
|
||||||
// headers: {
|
// headers: {
|
||||||
|
|||||||
@ -56,15 +56,9 @@ export default defineConfig(({ mode }: ConfigEnv): UserConfig => {
|
|||||||
strictPort: false, // 端口被占用时尝试其他端口
|
strictPort: false, // 端口被占用时尝试其他端口
|
||||||
// 代理配置
|
// 代理配置
|
||||||
proxy: {
|
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 代理
|
||||||
'/api': {
|
'/api': {
|
||||||
target: 'http://localhost:3000', // 本地开发服务器地址
|
target: env.VITE_API_BASE_URL, // 后端 API 服务器地址
|
||||||
changeOrigin: true,
|
changeOrigin: true,
|
||||||
rewrite: (path) => path.replace(/^\/api/, '')
|
rewrite: (path) => path.replace(/^\/api/, '')
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user