feat 对接新闻接口

This commit is contained in:
lwh 2023-06-30 10:50:43 +08:00
parent 636d65166a
commit c6c41b7809
5 changed files with 179 additions and 110 deletions

View File

@ -19,12 +19,13 @@
.news-title:hover {
color: #f08519;
}
.news-title-active{
.news-title-active {
color: #f08519;
}
.news-title-line {
width:1px;
width: 1px;
height: 36px;
background-color: #999999;
margin: 0 30px;
@ -33,71 +34,71 @@
}
// 新闻内容盒子
.news-container-box {
.news-contianer {
margin: 0px auto;
height: 300px;
width: 80%;
display: flex;
align-items: center;
padding: 10px 35px;
transition: .4s;
cursor: pointer;
margin-bottom: 35px;
}
.news-contianer:hover {
box-shadow: 0 0 15px 1px #e5e4e4;
}
.news-content-box {
height: 65%;
width: 100%;
display: flex;
overflow: hidden;
}
.news-big-box {
width: 105%;
display: flex;
// justify-content: center;
// flex-wrap: wrap;
.news-cover-box {
overflow: hidden;
margin-right: 20px;
height: 100%;
width: 25%;
object-fit: cover;
.news-box {
padding: 20px;
transition: 0.4s;
.news-s-box {
height: 450px;
border-radius: 10px;
transition: 0.4s;
padding: 20px;
cursor: pointer;
.jump {
text-decoration: dashed;
color: black;
}
&:hover {
box-shadow: 0 0 15px 10px rgb(227, 225, 225);
}
.news-img-box {
width: 100%;
height: 70%;
overflow: hidden;
img {
width: 100%;
height: 100%;
object-fit: cover;
}
}
.news-content-box {
width: 100%;
height: 30%;
display: flex;
flex-direction: column;
justify-content: space-around;
margin-top: 10px;
.news-content-title {
font-size: 25px;
font-weight: bold;
}
.news-content-line {
width: 100%;
height: 1px;
background: rgba(204, 204, 204, 1);
}
}
}
}
img {
height: 100%;
width: 100%;
object-fit: cover;
}
}
.news-content-right-box {
width: 70%;
}
.news-title {
font-weight: normal;
font-size: 18px;
letter-spacing: 1px;
color: rgb(51, 51, 51);
}
.news-time {
font-size: 14px;
color: rgb(153, 153, 153);
margin: 15px 0px;
}
.news-intro {
overflow: hidden;
text-overflow: ellipsis;
display: -webkit-box;
-webkit-line-clamp: 2;
-webkit-box-orient: vertical;
margin-bottom: 24px;
color: rgb(102, 102, 102);
width: 100%;
text-align: justify;
line-height: 22px;
}
// ted栏

View File

@ -1,6 +1,6 @@
<template>
<Head>
<Title>{{ tdk.tdk_title }}</Title>
<Title>{{ tdkNewType }}{{ tdk.tdk_title }}</Title>
<Meta :content=tdk.tdk_keyword name="keywords" />
<Meta :content=tdk.tdk_description name="description" />
</Head>
@ -12,7 +12,8 @@
<!-- 新闻类型 -->
<div class="news-titile-pos-box">
<div class="news-title-box" v-for="(item, index) in newsTypeList" :key="index">
<div :class="active.idx === index ? 'news-title news-title-active' : 'news-title'" @click="handleClickType(index)">{{item.name}}</div>
<div :class="active.idx === index ? 'news-title news-title-active' : 'news-title'"
@click="handleClickType(index)">{{ item.dictionary_name }}</div>
<div class="news-title-line" v-if="index !== newsTypeList.length - 1"></div>
</div>
</div>
@ -23,36 +24,21 @@
<!-- 模块渲染列表 -->
<div v-if="newsList.length != 0" class="news-big-box row animate__animated animate__fadeIn">
<div class="news-box col-lg-4 col-md-6 col-sm-12" v-for="(item, index) in newsList">
<div class="news-box col-lg-12" v-for="(item, index) in newsList">
<div class="news-s-box">
<nuxt-link v-if="item.info_article_link" :to="item.info_article_link" class="jump">
<div class="news-img-box">
<img :src=item.info_article_cover alt="">
</div>
<div class="news-content-box">
<div class="news-content-title">{{ item.info_article_title }}</div>
<div class="news-content-line"></div>
<div class="news-content-sublevel">
<div class="news-content-more">现在阅读</div>
<div class="news-content-time">{{ item.info_article_create_time }}
<nuxt-link :to="getLink(item)" class="jump">
<div class="news-contianer" style="border: 1px solid #e5e4e4">
<div class="news-content-box">
<div class="news-cover-box">
<img :src=item.news_cover>
</div>
<div class="news-content-right-box">
<div class="news-title">{{ item.news_title }}</div>
<div class="news-time">{{ item.news_issue_date }}</div>
<div class="news-intro">{{ item.news_intro }}</div>
<el-button type="info">查看详情</el-button>
</div>
</div>
</div>
</nuxt-link>
<nuxt-link v-else :to="'/news/details/' + item.info_article_id" class="jump">
<div class="news-img-box">
<img :src=item.info_article_cover alt="">
</div>
<div class="news-content-box">
<div class="news-content-title">{{ item.info_article_title }}</div>
<div class="news-content-line"></div>
<div class="news-content-sublevel">
<div class="news-content-more">现在阅读</div>
<div class="news-content-time">{{ item.info_article_create_time }}
</div>
</div>
</div>
</nuxt-link>
</div>
@ -78,32 +64,27 @@
</template>
<script setup>
//
let newsList = ref(
[
// {
// info_article_id: '1',
// info_article_title: "2023",
// info_article_cover: "/img/business/nuxt/@2x.png",
// info_article_create_time: "2023-02-23",
// news_id: '1',
// news_title: "NXP i.MX~",
// news_intro: "XP~\ni.MX~(5)NXPi.MX6U558\n",
// news_cover: "/uploads/NewsImg/20230629\\b3897ad4ecce0204b2086110539ec1b3.jpg",
// news_issue_date: "2023-02-23",
// },
]
)
let newsTypeList = ref([
{
name: '公司新闻',
dictionary_name: '---',
idx: 0
},
{
name: '行业动态',
idx: 1
},
{
name: '技术分享',
idx: 2
},
])
let tdkNewType = ref()
const route = useRoute()
const router = useRouter()
@ -137,6 +118,14 @@ const handleClickType = function (index) {
router.push(String(index) + "-" + String(page))
}
const getLink = function (item) {
if (item.news_link) {
return item.news_link;
} else {
return "/news/details/" + item.news_id;
}
}
/**
* 接口对接
@ -148,11 +137,17 @@ useFetch('/api/tdk/getTdk', { params: { tdk_type: 2 } }).then(res => {
tdk.value = JSON.parse(res.data.value).data
})
//
useFetch('/api/news/getNewsType').then(res => {
newsTypeList.value = JSON.parse(res.data.value).data || []
tdkNewType.value = newsTypeList?.value[active.idx]?.dictionary_name
})
// //
// useFetch('/api/news/getinfoArticleList', { params: queryParams }).then(res => {
// total.value = JSON.parse(res.data.value).count || 0
// newsList.value = JSON.parse(res.data.value).data || []
// })
useFetch('/api/news/getNewsList', { params: queryParams }).then(res => {
total.value = JSON.parse(res.data.value).count || 0
newsList.value = JSON.parse(res.data.value).data || []
})
// // 访
// useFetch('/api/flow/addFlowRecord', { params: { flow_target: route.name } })

View File

@ -0,0 +1,25 @@
import {
readRawBody,
getQuery,
getMethod
} from 'h3'
/**
* 获取新闻列表
*/
export default defineEventHandler(async (event) => {
// 基础url
const baseURL = process.env.NUXT_PROXY_WEB_API
const method = getMethod(event).toUpperCase()
let body
if (method !== 'GET') body = await readRawBody(event)
const res = await $fetch(baseURL + "/News.News/getNewsList", {
method,
baseURL: event.context.baseUrl,
headers: event.context.headers,
params: getQuery(event),
body
})
return res
})

View File

@ -0,0 +1,24 @@
import {
readRawBody,
getQuery,
getMethod
} from 'h3'
/**
* 获取新闻类型列表
*/
export default defineEventHandler(async (event) => {
// 基础url
const baseURL = process.env.NUXT_PROXY_WEB_API
const method = getMethod(event).toUpperCase()
let body
if (method !== 'GET') body = await readRawBody(event)
const res = await $fetch(baseURL + "/News.News/getNewsType", {
method,
baseURL: event.context.baseUrl,
headers: event.context.headers,
params: getQuery(event),
body
})
return res
})

View File

@ -0,0 +1,24 @@
import {
readRawBody,
getQuery,
getMethod
} from 'h3'
/**
* 获取新闻详情
*/
export default defineEventHandler(async (event) => {
// 基础url
const baseURL = process.env.NUXT_PROXY_WEB_API
const method = getMethod(event).toUpperCase()
let body
if (method !== 'GET') body = await readRawBody(event)
const res = await $fetch(baseURL + "/ExaminationInformation.InfoArticle/getinfoArticleInfo", {
method,
baseURL: event.context.baseUrl,
headers: event.context.headers,
params: getQuery(event),
body
})
return res
})