You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
172 lines
4.7 KiB
172 lines
4.7 KiB
<template> |
|
<div class="container"> |
|
<div class="news-list"> |
|
<div class="item" v-for="(item,index) in newsList" :key="item.id"> |
|
<div class="news-title" :id="index.toString()">{{ item.name }}</div> |
|
<div class="children"> |
|
<div class="son-item" v-for="obj in item.cmsArticleList" :key="obj.id" @click="toNewsDetail(obj.id)"> |
|
<div class="left"> |
|
<div class="title">{{ obj.title }}</div> |
|
<div class="content"> |
|
{{ obj.info }} |
|
</div> |
|
<div class="time"><div>{{ obj.publishTime }}</div> <div style="margin-left: 20px;">发布人:{{ obj.createBy }}</div></div> |
|
</div> |
|
<div class="right"> |
|
<img :src="setImageUrl(obj.comimg)" alt="" v-default-image/> |
|
</div> |
|
</div> |
|
<el-empty description="无新闻" v-if="item.cmsArticleList.length === 0" style="height: 200px;"/> |
|
</div> |
|
</div> |
|
</div> |
|
<!-- 右侧栏目 --> |
|
</div> |
|
<div class="right-coulom"> |
|
<div :class="active === index ? 'item active' : 'item' " @click="scrollById(index)" v-for="(item,index) in columnList" :key="item">{{ item }}</div> |
|
|
|
</div> |
|
</template> |
|
<script setup lang="ts"> |
|
import { ref, onMounted } from 'vue' |
|
import { useRouter } from 'vue-router' |
|
import { getNewsListApi } from '@/api/news' |
|
|
|
const router = useRouter() |
|
const newsList = ref<any>([]) |
|
const columnList = ref<any>([]) |
|
const active = ref(0) |
|
const getNewsListApiEvent = async () => { |
|
const res:any = await getNewsListApi() |
|
console.log(res, '212121') |
|
columnList.value = res.result.map(item => item.name) |
|
newsList.value = res.result |
|
} |
|
getNewsListApiEvent() |
|
const scrollById = (index: number) => { |
|
active.value = index |
|
const targetPosition = (document.getElementById(index.toString()) as HTMLElement).offsetTop - 120; |
|
window.scrollTo({ |
|
top: targetPosition, |
|
behavior: 'smooth', // 平滑滚动 |
|
}); |
|
} |
|
const toNewsDetail = (id: number) => { |
|
router.push({ |
|
path: '/detail/' + id |
|
}) |
|
} |
|
const setImageUrl = (url: string) => { |
|
return import.meta.env.VITE_APP_BASE_API + '/sys/common/static/' + url |
|
} |
|
</script> |
|
<style scoped lang="scss"> |
|
.container { |
|
width: 1200px; |
|
margin: auto; |
|
margin-top: 100px; |
|
.news-list { |
|
width: 100%; |
|
padding: 15px; |
|
border: 1px solid var(--border-color); |
|
background-color: var(--card-bg-color); |
|
border-radius: 5px; |
|
.item { |
|
.news-title { |
|
font-size: 24px; |
|
font-weight: 700; |
|
color: var(--text-color); |
|
} |
|
.children { |
|
margin: 20px 0; |
|
.son-item { |
|
width: 100%; |
|
height: 100px; |
|
background-color: var(--card-bg-color); |
|
padding: 15px; |
|
display: flex; |
|
border-bottom: 1px solid var(--border-color); |
|
justify-content: space-between; |
|
cursor: pointer; |
|
transition: all 0.3s; |
|
.left { |
|
width: 1000px; |
|
.title { |
|
font-size: 18px; |
|
font-weight: 700; |
|
color: var(--text-color); |
|
transition: color 0.3s; |
|
} |
|
.content { |
|
margin-top: 8px; |
|
font-size: 13px; |
|
color: var(--text-color); |
|
opacity: 0.65; |
|
display: -webkit-box; |
|
-webkit-line-clamp: 1; |
|
-webkit-box-orient: vertical; |
|
overflow: hidden; |
|
} |
|
.time { |
|
margin-top: 8px; |
|
font-size: 12px; |
|
color: var(--text-color); |
|
opacity: 0.45; |
|
display: flex; |
|
} |
|
} |
|
.right { |
|
display: flex; |
|
flex: 1; |
|
align-items: center; |
|
justify-content: center; |
|
img { |
|
width: 100%; |
|
height: 100%; |
|
border-radius: 4px; |
|
border: 1px solid var(--border-color); |
|
} |
|
} |
|
&:hover { |
|
background-color: var(--background-color); |
|
.title { |
|
color: var(--primary-color); |
|
} |
|
} |
|
} |
|
} |
|
} |
|
} |
|
} |
|
.right-coulom { |
|
position: fixed; |
|
left: 200px; |
|
top: 100px; |
|
z-index: 999; |
|
width: 150px; |
|
background-color: var(--card-bg-color); |
|
border: 1px solid var(--border-color); |
|
padding: 10px; |
|
border-radius: 5px; |
|
.item { |
|
height: 45px; |
|
line-height: 22px; |
|
font-size: 16px; |
|
padding: 10px; |
|
border-radius: 5px; |
|
cursor: pointer; |
|
margin: 5px 0; |
|
color: var(--text-color); |
|
transition: all 0.3s; |
|
&:hover { |
|
background-color: var(--primary-color); |
|
color: #ffffff; |
|
opacity: 0.8; |
|
} |
|
} |
|
.active { |
|
background-color: var(--primary-color); |
|
color: #ffffff; |
|
} |
|
} |
|
</style>
|
|
|