mirror of
https://codeup.aliyun.com/67762337eccfc218f6110e0e/vue/learning-system-mobile.git
synced 2025-12-09 19:06:46 +08:00
201 lines
4.6 KiB
Vue
201 lines
4.6 KiB
Vue
<template>
|
||
<view class="news-page-info">
|
||
<view class="tabs-info">
|
||
<u-tabs :list="listTabs" @click="click"
|
||
lineColor="#387DF7"
|
||
lineWidth="35"
|
||
lineHeight="4"
|
||
:activeStyle="{
|
||
color: '#333333',
|
||
fontWeight: '600',
|
||
transform: 'scale(1.1)'
|
||
}"
|
||
:inactiveStyle="{
|
||
color: '#666666',
|
||
}"
|
||
></u-tabs>
|
||
</view>
|
||
<view class="" v-show="tab == 0">
|
||
<system-news :items="message.list" @loadMessage="loadMessage"></system-news>
|
||
</view>
|
||
<view class="" v-show="tab == 1">
|
||
<at-my :items="data"></at-my>
|
||
</view>
|
||
<view v-if="total>query.pageSize">
|
||
<uni-load-more :status="loadStatus"></uni-load-more>
|
||
</view>
|
||
|
||
</view>
|
||
</template>
|
||
|
||
<script>
|
||
import apiQa from '@/api/modules/qa.js'
|
||
import apiComments from '../../api/modules/comments.js';
|
||
import apiUser from '@/api/system/user.js'
|
||
import apiMessage from '@/api/system/message.js';
|
||
export default {
|
||
data() {
|
||
return {
|
||
listTabs:[
|
||
{name:'系统'},
|
||
{name:'@我的'}
|
||
],
|
||
tab:0,
|
||
data:[],//拿到的数据
|
||
total:0,//总条数
|
||
loadStatus:'more',//more,loading,noMore
|
||
query:{
|
||
pageIndex:1,//当前页
|
||
type:null,//当前只限于文章
|
||
pageSize:10,//条数
|
||
},//查询条件
|
||
message:{
|
||
list:[],
|
||
total:0
|
||
},
|
||
queryData: {
|
||
pageIndex: 1,
|
||
pageSize: 10
|
||
},
|
||
}
|
||
},
|
||
onLoad() {
|
||
this.findData(true);
|
||
this.queryMessage(true);
|
||
},
|
||
onPullDownRefresh() {
|
||
this.onReachBottom();
|
||
},
|
||
onReachBottom() {
|
||
this.loadStatus='loading';//more,loading,noMore
|
||
if(this.tab == 0) {
|
||
if(this.message.list.length<this.message.total){
|
||
this.queryData.pageIndex++;
|
||
this.queryMessage(false);
|
||
this.loadStatus='more'
|
||
}else{
|
||
this.loadStatus='noMore'
|
||
}
|
||
} else {
|
||
if(this.data.length<this.total){
|
||
this.query.pageIndex++;
|
||
this.findData(false);
|
||
this.loadStatus='more'
|
||
}else{
|
||
this.loadStatus='noMore'
|
||
}
|
||
}
|
||
|
||
},
|
||
methods: {
|
||
loadMessage() {
|
||
this.queryMessage(true);
|
||
},
|
||
queryMessage(flag) {
|
||
if (flag) {
|
||
this.message.list = [];
|
||
this.queryData.pageIndex = 1;
|
||
}
|
||
uni.showLoading({ title: '加载中...' });
|
||
apiMessage.list(this.queryData).then(res => {
|
||
if (res.status == 200) {
|
||
let ids = [];
|
||
this.emptyControl=true
|
||
this.message.total = res.result.count;
|
||
if(res.result.list.length!=0){
|
||
res.result.list.forEach(item => {
|
||
item.authorInfo={avatar:'',name:'',code:'',sex:null};
|
||
ids.push(item.sendAid);
|
||
item.checked = false;
|
||
this.message.list.push(item);
|
||
});
|
||
this.loadAuthorInfo(res.result.list,ids)
|
||
}
|
||
if(this.message.list.length<this.message.total){
|
||
this.loadStatus='more'
|
||
}else{
|
||
this.loadStatus='noMore'
|
||
}
|
||
} else {
|
||
this.$refs.toast.show({ message: '获取数据失败', type: 'error' })
|
||
}
|
||
uni.hideLoading();
|
||
});
|
||
},
|
||
click(item) {
|
||
this.tab = item.index;
|
||
},
|
||
ubtab(num){
|
||
this.tab = num
|
||
},
|
||
findData(flag) {
|
||
uni.showLoading({ title: '加载中...' });
|
||
if(flag){
|
||
this.data=[]
|
||
this.pageIndex=1
|
||
}
|
||
apiComments.pagelist(this.query).then(res=>{
|
||
if (res.status == 200) {
|
||
this.total=res.result.count;
|
||
let ids = [];
|
||
if (res.result.list.length != 0) {
|
||
res.result.list.forEach(item=>{
|
||
ids.push(item.sysCreateAid);
|
||
item.authorInfo={avatar:'',name:'',code:'',sex:null};
|
||
this.data.push(item)
|
||
})
|
||
this.loadAuthorInfo(res.result.list,ids);
|
||
}
|
||
if(this.data.length<this.total){
|
||
this.loadStatus='more'
|
||
}else{
|
||
this.loadStatus='noMore'
|
||
}
|
||
}else{
|
||
this.$refs.interactToast.show({message:'加载@我的评论失败',type:'error'});
|
||
}
|
||
uni.hideLoading();
|
||
})
|
||
},
|
||
loadAuthorInfo(list, ids) {
|
||
//加载作者信息,头像,机构信息
|
||
if (ids.length == 0) {
|
||
return;
|
||
}
|
||
let $this = this;
|
||
const noReapetIds = [...new Set(ids)];
|
||
apiUser.getByIds(ids).then(res => {
|
||
if (res.status == 200) {
|
||
list.forEach((item, index) => {
|
||
res.result.some(author => {
|
||
if ($this.tab == 0 && author.aid == item.sendAid) {
|
||
item.authorInfo = author;
|
||
return true;
|
||
} else if($this.tab == 1 && author.aid == item.sysCreateAid){
|
||
item.authorInfo = author;
|
||
} else {
|
||
return false;
|
||
}
|
||
});
|
||
});
|
||
} else {
|
||
console.log('加载用户信息失败:' + res.error);
|
||
}
|
||
});
|
||
},
|
||
}
|
||
}
|
||
</script>
|
||
|
||
<style scoped lang="scss">
|
||
|
||
.news-page-info{
|
||
background-color: #fff;
|
||
.tabs-info{
|
||
padding: 0 254upx;
|
||
}
|
||
|
||
|
||
}
|
||
</style>
|