新闻页面加载过慢优化

This commit is contained in:
77 2024-08-01 14:26:56 +08:00
parent fe33b9c5ad
commit d280be1928

View File

@ -1,497 +1,536 @@
<template> <template>
<div class="loading"> <div class="loading">
<div class="page_ban"> <div class="page_ban">
<div class="img compbg"></div> <div class="img compbg"></div>
<div class="content"> <div class="content">
<div class="page_nav"> <div class="page_nav">
<div class="name"> <div class="name">
<a style="padding: 0;" href="">新闻内容</a> <a style="padding: 0;" href="">新闻内容</a>
</div> </div>
<div class="list" style="bottom:-15px"> <div class="list" style="bottom:-15px">
<el-tabs v-model="activeName" @tab-click="handleClick"> <el-tabs v-model="activeName" @tab-click="handleClick">
<el-tab-pane :label="newscatagary[0]?.name" :name="newscatagary[0]?.name"></el-tab-pane> <el-tab-pane :label="newscatagary[0]?.name" :name="newscatagary[0]?.name"></el-tab-pane>
<el-tab-pane :label="newscatagary[1]?.name" :name="newscatagary[1]?.name"></el-tab-pane> <el-tab-pane :label="newscatagary[1]?.name" :name="newscatagary[1]?.name"></el-tab-pane>
</el-tabs> </el-tabs>
</div> </div>
</div> </div>
</div> </div>
</div> </div>
<div style="height: 80px;"></div> <div style="height: 80px;"></div>
<div style="width: 80%;margin: auto;"> <div style="width: 80%;margin: auto;">
<el-row style="display: flex;flex-wrap: wrap;"> <el-row style="display: flex;flex-wrap: wrap;">
<el-col :span="8" v-for="item in newshow" :key="item.id" class="colitem" style="cursor: pointer;" > <el-col :span="8" v-for="item in newshow" :key="item.id" class="colitem" style="cursor: pointer;">
<div @click="changeto(item.id)"> <div @click="changeto(item.id)">
<el-card :body-style="{ padding: '0px' }" > <el-card :body-style="{ padding: '0px' }">
<div class="card_img1 mark" :style="{ 'background-image': 'url(' + item.pic + ')' }" > <div class="card_img1 mark" :style="{ 'background-image': 'url(' + item.pic + ')' }">
<!-- <div class="date">{{item.releaseTime}}</div> --> <!-- <div class="date">{{item.releaseTime}}</div> -->
</div> </div>
<div> <div>
<div class="news_li_con"><div class="title">{{item.name}}</div> <div class="introduction" v-html="item.content"></div> </div> <div class="news_li_con">
<div class="title">{{item.name}}</div>
<div class="introduction" v-html="item.content"></div>
</div>
</div> </div>
</el-card> </el-card>
</div> </div>
</el-col> </el-col>
</el-row> </el-row>
</div> </div>
<div style="width: 80%;margin: auto;"> <div style="width: 80%;margin: auto;">
<div v-for="item in rest" class="newsitem" style="overflow: hidden; padding: 30px 0 24px;position: relative;cursor: pointer;display: flex;" @click="changeto(item.id)"> <div v-for="item in rest" class="newsitem"
<div class="date1" style=""><img :src="item.pic" style="width: 236px;height: 157px;"></img></div> style="overflow: hidden; padding: 30px 0 24px;position: relative;cursor: pointer;display: flex;"
<div class="" style=" margin-left: 35px;overflow: hidden;"> @click="changeto(item.id)">
<div style=" font-size: 18px; <div class="date1" style=""><img :src="item.pic" style="width: 236px;height: 157px;"></img></div>
<div class="" style=" margin-left: 35px;overflow: hidden;">
<div style=" font-size: 18px;
color: #000; color: #000;
font-weight: bold; font-weight: bold;
margin-top: 15px;"> margin-top: 15px;">
{{item.name}} {{item.name}}
</div> </div>
<!-- <div style="font-size: 14px; <!-- <div style="font-size: 14px;
margin-top: 7px; margin-top: 7px;
color: #ababab;"> color: #ababab;">
{{item.releaseTime}} {{item.releaseTime}}
</div> --> </div> -->
<div style="font-size: 14px; <div style="font-size: 14px;
color: #666666; color: #666666;
height: 79px; height: 79px;
overflow: hidden; overflow: hidden;
-webkit-box-orient:vertical; -webkit-box-orient:vertical;
margin-top: 10px;" v-html="item.content"> margin-top: 10px;" v-html="item.content">
</div> </div>
</div> </div>
</div> </div>
<div style="height: 40px;"></div> <div style="height: 40px;"></div>
<div class="page_more wow fadeInUp animated" data-wow-delay=".2s" id="More" style="visibility: visible; animation-delay: 0.2s; animation-name: fadeInUp;" @click="addnews"> <div class="page_more wow fadeInUp animated" data-wow-delay=".2s" id="More"
<em>更多新闻</em> style="visibility: visible; animation-delay: 0.2s; animation-name: fadeInUp;" @click="addnews">
</div> <em>更多新闻</em>
<div style="height: 60px;"></div> </div>
</div> <div style="height: 60px;"></div>
</div> </div>
</div>
</template> </template>
<script> <script>
import '@/assets/images/news1.png' import '@/assets/images/news1.png'
import { getnews,getmsg,NewCategary} from '@/api'; import {
import { Loading } from 'element-ui'; getnews,
export default{ getmsg,
data(){ NewCategary
return{ } from '@/api';
activeName:'企业新闻', import {
newshow:[], Loading
rest:[], } from 'element-ui';
newslist:[], export default {
newscatagary:[], data() {
page:0, return {
content:'' activeName: '企业新闻',
} newshow: [],
}, rest: [],
mounted(){ newslist: [],
newscatagary: [],
page: 0,
content: ''
}
},
mounted() {
let loadingInstance = Loading.service('loading'); let loadingInstance = Loading.service('loading');
NewCategary().then((res)=>{ NewCategary().then((res) => {
this.newscatagary=res.data this.newscatagary = res.data
}) })
getnews({'page':0,'articleType':this.activeName}).then((res)=>{ getnews({
'page': 0,
'articleType': this.activeName
}).then((res) => {
loadingInstance.close();
// richText
res.data.content.forEach(item => {
//
item.content = item.content?.replace(/<[^>]+>/g, '').trim();
});
this.newslist = res.data.content
let arr = this.newslist.slice(0, 3)
this.newshow = arr
})
},
methods: {
handleClick() {
this.page = 0;
console.log(1111)
this.rest = []
let loadingInstance = Loading.service('loading');
// if(this.activeName==''){
getmsg({
'page': 0,
'articleType': this.activeName
}).then((res) => {
// richText
res.data.content.forEach(item => {
//
item.content = item.content?.replace(/<[^>]+>/g, '').trim();
});
this.newslist = res.data.content
let arr = this.newslist.slice(0, 3)
this.newshow = arr
loadingInstance.close();
})
// }else if(this.activeName==''){
// getnews({'page':0,'articleType':activeName}).then((res)=>{
// res.data.content.forEach(item => {
// richText // item.content = item.content?.replace(/<[^>]+>/g, '').trim();
res.data.content.forEach(item => { // });
// // this.newslist=res.data.content
item.content = item.content?.replace(/<[^>]+>/g, '').trim();
});
this.newslist=res.data.content
let arr=this.newslist.slice(0,3) // let arr=this.newslist.slice(0,3)
this.newshow=arr // this.newshow=arr
loadingInstance.close(); // loadingInstance.close();
}) // })
}, // }
methods:{ },
handleClick(){ addnews() {
this.page = 0; this.page = this.page + 1
console.log(1111) // if(this.activeName==''){
this.rest=[] getmsg({
let loadingInstance = Loading.service('loading'); 'page': this.page,
// if(this.activeName==''){ 'articleType': this.activeName
}).then((res) => {
// console.log(res)
for (let i = 0; i < res.data.content.length; i++) {
res.data.content[i].content = res.data.content[i].content?.replace(/<[^>]+>/g, '').trim();
getmsg({'page':0,'articleType':this.activeName}).then((res)=>{ res.data.content[i].day = res.data.content[i].releaseTime.slice(-2)
res.data.content[i].year = res.data.content[i].releaseTime.slice(0, 7)
this.rest.push(res.data.content[i])
}
// richText })
res.data.content.forEach(item => { // }else if(this.activeName==''){
// // getnews({'page':this.page}).then((res)=>{
item.content = item.content?.replace(/<[^>]+>/g, '').trim(); // // console.log(res)
}); // for(let i=0;i<res.data.content.length;i++){
this.newslist=res.data.content // res.data.content[i].content= res.data.content[i].content?.replace(/<[^>]+>/g, '').trim();
let arr=this.newslist.slice(0,3) // res.data.content[i].day=res.data.content[i].releaseTime.slice(-2)
this.newshow=arr // res.data.content[i].year=res.data.content[i].releaseTime.slice(0,7)
loadingInstance.close(); // this.rest.push(res.data.content[i])
}) // }
// }else if(this.activeName==''){
// getnews({'page':0,'articleType':activeName}).then((res)=>{
// })
// }
// res.data.content.forEach(item => { },
changeto(id) {
// if(this.activeName==''){
this.$router.push({
path: '/detail?type=' + this.activeName + '&&id=' + id
})
// }else if(this.activeName==''){
// this.$router.push({
// path:'/detail?type=2&&id='+id
// })
// }
// item.content = item.content?.replace(/<[^>]+>/g, '').trim(); }
// }); }
// this.newslist=res.data.content }
// let arr=this.newslist.slice(0,3)
// this.newshow=arr
// loadingInstance.close();
// })
// }
},
addnews(){
this.page=this.page+1
// if(this.activeName==''){
getmsg({'page':this.page,'articleType':this.activeName}).then((res)=>{
// console.log(res)
for(let i=0;i<res.data.content.length;i++){
res.data.content[i].content= res.data.content[i].content?.replace(/<[^>]+>/g, '').trim();
res.data.content[i].day=res.data.content[i].releaseTime.slice(-2)
res.data.content[i].year=res.data.content[i].releaseTime.slice(0,7)
this.rest.push(res.data.content[i])
}
})
// }else if(this.activeName==''){
// getnews({'page':this.page}).then((res)=>{
// // console.log(res)
// for(let i=0;i<res.data.content.length;i++){
// res.data.content[i].content= res.data.content[i].content?.replace(/<[^>]+>/g, '').trim();
// res.data.content[i].day=res.data.content[i].releaseTime.slice(-2)
// res.data.content[i].year=res.data.content[i].releaseTime.slice(0,7)
// this.rest.push(res.data.content[i])
// }
// })
// }
},
changeto(id){
// if(this.activeName==''){
this.$router.push({
path:'/detail?type='+this.activeName+'&&id='+id
})
// }else if(this.activeName==''){
// this.$router.push({
// path:'/detail?type=2&&id='+id
// })
// }
}
}
}
</script> </script>
<style scoped> <style scoped>
.compbg { .compbg {
background-image: url('../assets/images/banner.png'); background-image: url('../assets/images/banner.png');
} }
.page_ban { .page_ban {
height: 404px; height: 404px;
position: relative; position: relative;
text-align: center; text-align: center;
z-index: 101; z-index: 101;
} }
.page_ban .img { .page_ban .img {
width: 100%; width: 100%;
height: 100%; height: 100%;
background-size: cover; background-size: cover;
position: absolute; position: absolute;
left: 0; left: 0;
top: 0; top: 0;
z-index: -1; z-index: -1;
} }
.date{
font-size: 26px; .date {
color: #dfd4c3;
line-height: 1;
position: absolute;
left: 0;
bottom: 20px;
padding: 0 30px;
width: 100%;
}
.page_ban .content {
position: relative;
height: 100%;
}
.content {
width: 80%;
margin: 0 auto;
}
.page_nav { font-size: 26px;
width: 100%; color: #dfd4c3;
position: absolute; line-height: 1;
left: 0; position: absolute;
bottom: 0; left: 0;
} bottom: 20px;
div, padding: 0 30px;
li { width: 100%;
box-sizing: border-box; }
}
.page_nav .name { .page_ban .content {
float: left; position: relative;
} height: 100%;
}
.page_nav .list { .content {
position: relative; width: 80%;
float: right; margin: 0 auto;
margin-right: -35px; }
}
.page_nav a { .page_nav {
float: left; width: 100%;
line-height: 76px; position: absolute;
position: relative; left: 0;
font-size: 14.5px; bottom: 0;
}
color: white; div,
font-weight: bold; li {
text-decoration: none; box-sizing: border-box;
} }
.page_nav .name a { .page_nav .name {
padding-left: 30px; float: left;
/* background: url() no-repeat left 30px; */ }
}
.page_nav .list { .page_nav .list {
position: relative; position: relative;
float: right; float: right;
margin-right: -35px; margin-right: -35px;
} }
.page_nav .list a { .page_nav a {
color: #e7dfd2; float: left;
color: rgba(231, 223, 210, .7); line-height: 76px;
margin-right: 35px; position: relative;
} font-size: 14.5px;
.page_nav a { color: white;
float: left; font-weight: bold;
line-height: 76px; text-decoration: none;
position: relative; }
font-size: 14.5px;
color: rgba(255, 255, 255, 0.8); .page_nav .name a {
font-weight: bold; padding-left: 30px;
} /* background: url() no-repeat left 30px; */
}
.page_nav .inner_bor { .page_nav .list {
height: 4px; position: relative;
background: #f23c39; float: right;
position: absolute; margin-right: -35px;
bottom: -4px; }
left: 0;
display: block;
}
::v-deep .el-tabs__item { .page_nav .list a {
color: #e7dfd2;
color: rgba(231, 223, 210, .7);
margin-right: 35px;
}
color: rgba(255, 255, 255, 0.8); .page_nav a {
border: none; float: left;
} line-height: 76px;
position: relative;
font-size: 14.5px;
::v-deep .el-tabs__nav-wrap::after { color: rgba(255, 255, 255, 0.8);
background-color: transparent; font-weight: bold;
} }
.card_img1{
border-radius: 14px;
position: relative; .page_nav .inner_bor {
width: 100%; height: 4px;
height: 307px; background: #f23c39;
position: absolute;
bottom: -4px;
left: 0;
display: block;
}
background-size: cover; ::v-deep .el-tabs__item {
margin-bottom: 16px;
border-radius: 14px;
}
.card_img2{
border-radius: 14px;
background-image: url('../assets/images/news2.png');
position: relative;
width: 100%;
height: 307px;
background-size: cover; color: rgba(255, 255, 255, 0.8);
margin-bottom: 16px; border: none;
border-radius: 14px; }
}
.card_img3{
border-radius: 14px;
background-image: url('../assets/images/news3.png');
position: relative;
width: 100%;
height: 307px;
background-size: cover; ::v-deep .el-tabs__nav-wrap::after {
margin-bottom: 16px; background-color: transparent;
border-radius: 14px; }
}
.colitem{
display: inline-block;
float: none;
}
.mark::before{
content: ''; .card_img1 {
width: 100%; border-radius: 14px;
height: 100%;
background-color: #000;
position: absolute;
bottom: 0;
left: 0;
opacity: .25;
filter: alpha(opacity = 25);
-webkit-filter: alpha(opacity = 25);
border-radius: 14px;
} position: relative;
::v-deep .el-card.is-always-shadow{ width: 100%;
border-radius: 14px; height: 307px;
box-shadow: initial;
} background-size: cover;
::v-deep el-card{ margin-bottom: 16px;
border:none border-radius: 14px;
} }
.news_li_con {
position: relative; .card_img2 {
padding-left: 28px; border-radius: 14px;
height: 150px; background-image: url('../assets/images/news2.png');
overflow: hidden; position: relative;
} width: 100%;
.news_li_con:before { height: 307px;
content: '';
width: 6px; background-size: cover;
height: 21px; margin-bottom: 16px;
background-color: rgb(48,113,183); border-radius: 14px;
position: absolute; }
top: 4px;
left: 0; .card_img3 {
} border-radius: 14px;
.title { background-image: url('../assets/images/news3.png');
font-size: 22px; position: relative;
color: #3c3c48; width: 100%;
color: rgba(60, 60, 72, .7); height: 307px;
line-height: 30px;
font-weight: bold; background-size: cover;
max-width: 77%; margin-bottom: 16px;
overflow: hidden; border-radius: 14px;
text-overflow: ellipsis; }
white-space: nowrap;
transition: all .4s; .colitem {
-webkit-transition: all .4s; display: inline-block;
-moz-transition: all .4s; float: none;
-ms-transition: all .4s; }
-o-transition: all .4s;
} .mark::before {
.introduction {
min-height: 72px; content: '';
font-size: 14.5px; width: 100%;
color: #848484; height: 100%;
color: rgba(132, 132, 132, .7); background-color: #000;
line-height: 24px; position: absolute;
margin: 8px 0 14px; bottom: 0;
display: -webkit-box; left: 0;
overflow: hidden; opacity: .25;
-webkit-line-clamp: 3; filter: alpha(opacity=25);
-webkit-box-orient: vertical; -webkit-filter: alpha(opacity=25);
} border-radius: 14px;
.more {
position:absolute; }
bottom: 0;
font-size: 18px; ::v-deep .el-card.is-always-shadow {
color: #3958cd; border-radius: 14px;
line-height: 1; box-shadow: initial;
text-transform: uppercase; }
letter-spacing: -.4px;
} ::v-deep el-card {
div{ border: none
box-sizing: border-box; }
}
.el-col{ .news_li_con {
padding: 0px 8px; position: relative;
} padding-left: 28px;
.newsitem::before{ height: 150px;
content: ''; overflow: hidden;
width: 100%; }
height: 2px;
background-color: #ebebeb; .news_li_con:before {
position: absolute; content: '';
bottom: 0; width: 6px;
left: 0; height: 21px;
} background-color: rgb(48, 113, 183);
.newsitem .date1{ position: absolute;
width: 236px; top: 4px;
float: left; left: 0;
font-family: 'Rajdhani'; }
font-size: 26px;
color: rgb(48,113,183); .title {
line-height: 1; font-size: 22px;
} color: #3c3c48;
.title1{ color: rgba(60, 60, 72, .7);
font-size: 20px; line-height: 30px;
color: #3c3c48; font-weight: bold;
color: rgba(60, 60, 72, .7); max-width: 77%;
line-height: 24px; overflow: hidden;
font-weight: bold; text-overflow: ellipsis;
margin-bottom: 10px; white-space: nowrap;
max-width: 77%; transition: all .4s;
overflow: hidden; -webkit-transition: all .4s;
text-overflow: ellipsis; -moz-transition: all .4s;
white-space: nowrap; -ms-transition: all .4s;
transition: all .4s; -o-transition: all .4s;
-webkit-transition: all .4s; }
-moz-transition: all .4s;
-ms-transition: all .4s; .introduction {
-o-transition: all .4s; min-height: 72px;
} font-size: 14.5px;
.newsitem .introduction1{ color: #848484;
font-size: 14.5px; color: rgba(132, 132, 132, .7);
color: #848484; line-height: 24px;
color: rgba(132, 132, 132, .7); margin: 8px 0 14px;
line-height: 24px; display: -webkit-box;
display: -webkit-box; overflow: hidden;
overflow: hidden; -webkit-line-clamp: 3;
-webkit-line-clamp: 2; -webkit-box-orient: vertical;
-webkit-box-orient: vertical; }
}
.page_more { .more {
position: relative; position: absolute;
font-size: 18px; bottom: 0;
color: #ffffff; font-size: 18px;
line-height: 70px; color: #3958cd;
background-color: rgb(48,113,183); line-height: 1;
text-align: center; text-transform: uppercase;
cursor: pointer; letter-spacing: -.4px;
border-radius: 14px; }
-webkit-border-radius: 14px;
-moz-border-radius: 14px; div {
-ms-border-radius: 14px; box-sizing: border-box;
-o-border-radius: 14px; }
}
::v-deep .el-card{ .el-col {
border: none; padding: 0px 8px;
} }
.newsitem::before {
content: '';
width: 100%;
height: 2px;
background-color: #ebebeb;
position: absolute;
bottom: 0;
left: 0;
}
.newsitem .date1 {
width: 236px;
float: left;
font-family: 'Rajdhani';
font-size: 26px;
color: rgb(48, 113, 183);
line-height: 1;
}
.title1 {
font-size: 20px;
color: #3c3c48;
color: rgba(60, 60, 72, .7);
line-height: 24px;
font-weight: bold;
margin-bottom: 10px;
max-width: 77%;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
transition: all .4s;
-webkit-transition: all .4s;
-moz-transition: all .4s;
-ms-transition: all .4s;
-o-transition: all .4s;
}
.newsitem .introduction1 {
font-size: 14.5px;
color: #848484;
color: rgba(132, 132, 132, .7);
line-height: 24px;
display: -webkit-box;
overflow: hidden;
-webkit-line-clamp: 2;
-webkit-box-orient: vertical;
}
.page_more {
position: relative;
font-size: 18px;
color: #ffffff;
line-height: 70px;
background-color: rgb(48, 113, 183);
text-align: center;
cursor: pointer;
border-radius: 14px;
-webkit-border-radius: 14px;
-moz-border-radius: 14px;
-ms-border-radius: 14px;
-o-border-radius: 14px;
}
::v-deep .el-card {
border: none;
}
</style> </style>