Commit 58c5970b by yanju

修改动态分类获取

parent dd81f5ec
......@@ -16,6 +16,7 @@ export default {
myList:'/api/my/posts',//我的动态列表
list:'/api/posts',//动态列表
otherList:'/api/user/',//别人的动态列表 +{userId}/posts
following:'/api/posts/followed',//获取我关注的人的动态
},
PostComment:{
list:'/api/post/',//获取动态评论 +{postId}/comments
......
......@@ -28,7 +28,7 @@
<span :style="{color:route==='blog'?'#00AAE6':'#666'}">博客</span>
<div class="abs-line" v-if="route==='blog'"></div>
</nuxt-link>
<nuxt-link tag="li" to="/dynamic">
<nuxt-link tag="li" to="/dynamic?type=new">
<span tag="span" to="/dynamic" :style="{color:route==='dynamic'?'#00AAE6':'#666'}">动态</span>
<div class="abs-line" v-if="route==='dynamic'"></div>
</nuxt-link>
......
......@@ -50,10 +50,6 @@
default:'over'
},
paginationReset:{
type:Boolean,
default:false
}
},
data(){
return {
......@@ -100,7 +96,10 @@
methods:{
setCurrentPage(n){
this.currentPage = n;
this.currentPage = 1;
this.paginationState='loading'
this.$emit(config.event.listenPageChange,1)
},
getElementToPageTop(el) {
......@@ -110,7 +109,6 @@
return el.offsetTop
},
//
scrollToGetNext(){
if(process.browser){
document.addEventListener('scroll',()=>{
......@@ -118,16 +116,11 @@
let pageConTop = this.getElementToPageTop (this.$refs.paginationCon);
let scrollTop = document.documentElement.scrollTop ||document.body.scrollTop;
let screenTop = scrollTop + window.innerHeight ;
if(screenTop>=pageConTop&&this.paginationState==='over'&&!this.paginationReset) {
if(screenTop>=pageConTop&&this.paginationState==='over') {
if (this.currentPage < this.pages) {
this.currentPage = this.currentPage + 1;
}
}
else if(screenTop>=pageConTop&&this.paginationState==='over'&&this.paginationReset) {
if (this.pages > 1) {
this.currentPage = 2;
}
}
else{
// this.paginationState = 'complete';
}
......
......@@ -185,31 +185,36 @@
}
},
handledContent(){
let content = this.content===null?'':this.content;
let indexArr = [];
let html=``;
let reg = /(#([^#]+?)#)/;
for (let i = 0; i <content.length ; i++) {
let index = content.indexOf("#",i);
if(index!==-1&&index===i){
indexArr.push(index)
}
}
if(indexArr.length>1){
for (let i = 0; i < indexArr.length-1; i+=2) {
let firstP = i>0?indexArr[i-1]+1:0;
html = html +`${content.substring(firstP,indexArr[i])}<a href="/topic/detail/${content.substring(indexArr[i]+1,indexArr[i+1])}">${content.substring(indexArr[i],indexArr[i+1]+1)}</a>`
}
html = html + `${ content.substring(indexArr[indexArr.length-1]+1)}`;
return html
}
else{
return content;
}
return this.content;
// let indexArr = [];
// let html=``;
// for (let i = 0; i <content.length ; i++) {
// let index = content.indexOf("#",i);
// if(index!==-1&&index===i){
// indexArr.push(index)
// }
// }
// if(indexArr.length>1){
// for (let i = 0; i < indexArr.length-1; i+=2) {
// let firstP = i>0?indexArr[i-1]+1:0;
// html = html +`${content.substring(firstP,indexArr[i])}<a href="/topic/detail/${content.substring(indexArr[i]+1,indexArr[i+1])}">${content.substring(indexArr[i],indexArr[i+1]+1)}</a>`
// }
//
// if(indexArr.length%2!==0){
// html = html + `${ content.substring(indexArr[indexArr.length-1])}`;
//
// }else{
// html = html + `${ content.substring(indexArr[indexArr.length-1]+1)}`;
//
// }
// return html
//
// }
// else{
// return content;
// }
......
......@@ -7,9 +7,9 @@
></nav-wrap>
</div>
<div class="dynamic-container__center">
<release-card @listenReleaseState="dataGetDynamic(1)"></release-card>
<social-card @listenSocialCardState="dataGetDynamic(1)" v-for="(val,index) in postList" :key="val.postId" :info="val"></social-card>
<pagination :paginationReset="paginationReset" :paginationState="paginationState" :type="2" key="container5" style="margin:20px auto;" :pages="pages" v-on:listenPageChange="changePage"></pagination>
<release-card @listenReleaseState="restartPagination()"></release-card>
<social-card @listenSocialCardState="restartPagination()" v-for="(val,index) in postList" :key="val.postId" :info="val"></social-card>
<pagination ref="pagination" :paginationState="paginationState" :type="2" key="container5" style="margin:20px auto;" :pages="pages" v-on:listenPageChange="changePage"></pagination>
</div>
<div class="dynamic-container__right">
......@@ -42,50 +42,49 @@
return{
list: [
{
label: '推荐',
label: '最新',
address: '/dynamic',
type: '推荐'
type: 'new'
},
{
label: '热门',
address: '/dynamic',
type: '热门'
type: 'hot'
},
{
label: '关注',
address: '/dynamic',
type: '关注'
type: 'following'
},
{
label: '我的',
address: '/dynamic',
type: '我的'
type: 'my'
},
{
label: '文字',
address: '/dynamic',
type: '文字'
type: 'word'
},
{
label: '视频',
address: '/dynamic',
type: '视频'
type: 'video'
},
{
label: '图片',
address: '/dynamic',
type: '图片'
type: 'picture'
}
],
postList:[],
pages:1,
paginationState:'complate',
paginationReset:true,
topicList:[],
}
},
......@@ -94,18 +93,25 @@
},
created() {
this.$router.replace({
path: '/dynamic',
query: {
type: '推荐'
}
});
this.dataGetHotTopic();
},
watch:{
$route(){
this.restartPagination();
}
},
methods:{
dataGetDynamic(currentPage){
restartPagination(){
this.postList = [];
this.pages = 1;
if(process.browser){
this.$refs.pagination.setCurrentPage(1)
}
},
dataGetNewDynamic(currentPage){
this.paginationState = 'loading';
this.$axios.$get(config.api.get.Post.list,{
......@@ -118,19 +124,167 @@
if(currentPage===1){
this.postList = response.data.dataList;
this.pages = response.data.totalPage;
this.paginationReset = true;
}else{
let list = response.data.dataList;
for(let i = 0;i<list.length;i++){
this.postList.push(list[i]);
}
this.paginationReset = false;
this.pages = response.data.totalPage;
}
})
},
dataGetHotDynamic(currentPage){
this.paginationState = 'loading';
this.$axios.$get(config.api.get.Post.list,{
params:{
page:currentPage,
size:10
}
}).then((response)=>{
this.paginationState = 'over';
if(currentPage===1){
this.postList = response.data.dataList;
this.pages = response.data.totalPage;
}else{
let list = response.data.dataList;
for(let i = 0;i<list.length;i++){
this.postList.push(list[i]);
}
this.pages = response.data.totalPage;
}
})
},
dataGetFollowDynamic(currentPage){
this.paginationState = 'loading';
this.$axios.$get(config.api.get.Post.following,{
params:{
page:currentPage,
size:10
}
}).then((response)=>{
this.paginationState = 'over';
if(currentPage===1){
this.postList = response.data.dataList;
this.pages = response.data.totalPage;
}else{
let list = response.data.dataList;
for(let i = 0;i<list.length;i++){
this.postList.push(list[i]);
}
this.pages = response.data.totalPage;
}
})
},
dataGetMyDynamic(currentPage){
this.paginationState = 'loading';
this.$axios.$get(config.api.get.Post.myList,{
params:{
page:currentPage,
size:10
}
}).then((response)=>{
this.paginationState = 'over';
if(currentPage===1){
this.postList = response.data.dataList;
this.pages = response.data.totalPage;
}else{
let list = response.data.dataList;
for(let i = 0;i<list.length;i++){
this.postList.push(list[i]);
}
this.pages = response.data.totalPage;
}
})
},
dataGetWordDynamic(currentPage){
this.paginationState = 'loading';
this.$axios.$get(config.api.get.Post.list,{
params:{
page:currentPage,
size:10,
type:0
}
}).then((response)=>{
this.paginationState = 'over';
if(currentPage===1){
this.postList = response.data.dataList;
this.pages = response.data.totalPage;
}else{
let list = response.data.dataList;
for(let i = 0;i<list.length;i++){
this.postList.push(list[i]);
}
this.pages = response.data.totalPage;
}
})
},
dataGetVideoDynamic(currentPage){
this.paginationState = 'loading';
this.$axios.$get(config.api.get.Post.list,{
params:{
page:currentPage,
size:10,
type:1
}
}).then((response)=>{
this.paginationState = 'over';
if(currentPage===1){
this.postList = response.data.dataList;
this.pages = response.data.totalPage;
}else{
let list = response.data.dataList;
for(let i = 0;i<list.length;i++){
this.postList.push(list[i]);
}
this.pages = response.data.totalPage;
}
})
},
dataGetPictureDynamic(currentPage){
this.paginationState = 'loading';
this.$axios.$get(config.api.get.Post.list,{
params:{
page:currentPage,
size:10,
type:2
}
}).then((response)=>{
this.paginationState = 'over';
if(currentPage===1){
this.postList = response.data.dataList;
this.pages = response.data.totalPage;
}else{
let list = response.data.dataList;
for(let i = 0;i<list.length;i++){
this.postList.push(list[i]);
}
this.pages = response.data.totalPage;
}
})
},
dataGetHotTopic(){
this.$axios.$get(config.api.get.Topic.hotSearch,{
......@@ -145,7 +299,33 @@
changePage(currentPage){
//返回页数 请求新的数据
this.dataGetDynamic(currentPage);
let type = this.$route.query.type;
if(type==='new'){
this.dataGetNewDynamic(currentPage);
}
if(type==='hot'){
this.dataGetHotDynamic(currentPage);
}
if(type==='following'){
this.dataGetFollowDynamic(currentPage);
}
if(type==='my'){
this.dataGetMyDynamic(currentPage);
}
if(type==='word'){
this.dataGetWordDynamic(currentPage);
}
if(type==='video'){
this.dataGetPictureDynamic(currentPage);
}
if(type==='picture'){
this.dataGetVideoDynamic(currentPage);
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment