Browse Source

update topic bind data

master
fanp 6 years ago
parent
commit
e1ffda0933
  1. 85
      models/topic.js
  2. 2
      pages/topics/goodIdea/cell/index.wxml
  3. 5
      pages/topics/goodIdea/index.js
  4. 2
      pages/topics/goodIdea/index.wxml
  5. 143
      pages/topics/index.js
  6. 1
      pages/topics/index.json
  7. 6
      pages/topics/index.wxml
  8. 13
      pages/topics/interactive/cell/index.js
  9. 4
      pages/topics/interactive/cell/index.wxml
  10. 1
      pages/topics/interactive/cell/index.wxss
  11. 41
      pages/topics/interactive/index.js
  12. 7
      pages/topics/interactive/index.wxml
  13. 139
      pages/topics/interactive/topicArticle/index.js
  14. 3
      pages/topics/interactive/topicArticle/index.json
  15. 10
      pages/topics/interactive/topicArticle/index.wxml
  16. 4
      pages/topics/interactive/topicArticle/index.wxss
  17. 1
      utils/http.js

85
models/topic.js

@ -1,19 +1,94 @@
import {HTTP, Method} from '../utils/http.js'
const TopicBaseUrl = {
topic_list_url:'/api/group/page',
topic_goldenList_url:'/api/comment/goldenList',
topic_detail_url:'/api/group/queryById/',
topic_detailComment_url:'/api/comment/page',
topic_collect:'/api/group/collectGroup/',
topic_commentPraise_url: '/api/comment/addSupport/',
// topic_commentUnPraise_url: '/api/comment/deleteComment/{id}',
}
class TopicModel extends HTTP {
constructor () {
super()
}
// 首页列表
getTopicList = (success) => {
// 议题列表
getTopicList(page, success) {
let params = {
url: TopicBaseUrl.topic_list_url,
method: Method.POST,
data: {
page: page,
pageSize: 10,
},
success: success
}
this.request(params)
}
getTopicDetail(id, success){
let params = {
url: TopicBaseUrl.topic_detail_url+`${id}`,
method: Method.POST,
success: success
}
this.request(params)
}
getTopicDetailComment(id, page,success) {
let params = {
url: TopicBaseUrl.topic_detailComment_url,
method: Method.POST,
data:{
groupId:id,
page: page,
pageSize: 10,
},
success: success
}
this.request(params)
}
topicCollect(id,success){
let params = {
url: '/fqsb/group/list',
sucess: success,
method: Method.GET
url: TopicBaseUrl.topic_collect + `${id}`,
method: Method.POST,
success: success
}
this.request(params)
}
topicCommentPraise(id,success){
let params = {
url: TopicBaseUrl.topic_commentPraise_url + `${id}`,
method: Method.POST,
success: success
}
this.request(params)
}
goldenList(page, success) {
let params = {
url: TopicBaseUrl.topic_goldenList_url,
method: Method.POST,
data: {
type:1,
page: page,
pageSize: 10,
},
success: success
}
this.request(params)
}
}
export {TopicModel}

2
pages/topics/goodIdea/cell/index.wxml

@ -19,7 +19,7 @@
</view>
</view>
</view>
<view style="color:#3B3B3B;font-size:14px;padding: 0 0 5px 0;">评论内容</view>
<view style="color:#3B3B3B;font-size:14px;padding: 0 0 5px 0;">{{itemData.comment}}</view>
<view class="detail">
<view class="detail-title">{{itemData.detail.title}}</view>
<view class="detail-userInfo">

5
pages/topics/goodIdea/index.js

@ -4,7 +4,10 @@ Component({
* 组件的属性列表
*/
properties: {
list: {
type: Array,
value: []
}
},
/**

2
pages/topics/goodIdea/index.wxml

@ -1,6 +1,6 @@
<!--pages/topics/goodIdea/index.wxml-->
<view class="container">
<block wx:for="{{list}}" wx:key="*this">
<block wx:for="{{list}}" wx:key="{{index}}">
<cell
itemData="{{item}}"
bind:clickListItem="clickListItem"/>

143
pages/topics/index.js

@ -1,4 +1,10 @@
// pages/topics/index.js
import dayjs from '../../utils/dayjs/index.js'
import relativeTime from '../../utils/dayjs/relativeTime.js'
dayjs.extend(relativeTime);
import { TopicModel } from '../../models/topic.js'
let topicModel = new TopicModel()
Page({
/**
@ -6,16 +12,114 @@ Page({
*/
data: {
headerTitles: ['互动区', '金点子', '留言箱'],
selectedTitle: 0
segmentIndex: 0,
currPage: 1,
topicList: [],
goodIdeaList:[]
},
/**
* 生命周期函数--监听页面加载
*/
onLoad: function (options) {
onLoad: function () {
this.fetchTopicList();
},
fetchTopicList(){
let page = this.data.currPage
topicModel.getTopicList(page,res=>{
console.log('议题列表')
console.log(res)
const datas = res.result.list
let tempDatas = []
datas.forEach(item => {
tempDatas.push({
topicId: item.id,
title: item.title,
userName: item.author,
commentNum: item.commentNum,
topicImg:item.image,
time: item.createTime,
})
})
if (page == 1) {
this.setData({
topicList: tempDatas
})
} else {
if (tempDatas.length > 0) {
const list = [...this.data.topicList, ...tempDatas]
this.setData({
topicList: list
})
} else {
const page = this.data.currPage - 1
this.setData({
currPage: page
})
wx.showToast({
title: '已加载全部',
icon: 'none'
})
}
}
console.log(this.data.topicList)
wx.stopPullDownRefresh()
})
},
fetchGoodIdeaList(){
let page = this.data.currPage
topicModel.goldenList(page, res => {
console.log('金点子列表')
console.log(res)
const datas = res.result.list
let tempDatas = []
datas.forEach(item => {
tempDatas.push({
id: item.id,
userIcon:item.image,
groupId: item.groupId,
userName: item.username,
time: item.createTime,
comment: item.comment,
praiseNum: item.supportNum,
detail:{
userIcon: item.groupAvator,
userName: item.author,
commentNum: item.commentNum,
title: item.title,
text:item.content,
}
})
})
if (page == 1) {
this.setData({
goodIdeaList: tempDatas
})
} else {
if (tempDatas.length > 0) {
const list = [...this.data.goodIdeaList, ...tempDatas]
this.setData({
goodIdeaList: list
})
} else {
const page = this.data.currPage - 1
this.setData({
currPage: page
})
wx.showToast({
title: '已加载全部',
icon: 'none'
})
}
}
console.log(this.data.goodIdeaList)
wx.stopPullDownRefresh()
})
},
/**
* 生命周期函数--监听页面初次渲染完成
*/
@ -47,14 +151,31 @@ Page({
* 页面相关事件处理函数--监听用户下拉动作
*/
onPullDownRefresh: function () {
this.setData({
currPage: 1,
})
switch (this.data.segmentIndex) {
case 0:
return this.fetchTopicList()
case 1:
return this.fetchGoodIdeaList()
}
},
/**
* 页面上拉触底事件的处理函数
*/
onReachBottom: function () {
const page = this.data.currPage + 1
this.setData({
currPage: page
})
switch (this.data.segmentIndex) {
case 0:
return this.fetchTopicList()
case 1:
return this.fetchGoodIdeaList()
}
},
/**
@ -66,9 +187,19 @@ Page({
// 定义点击标题的事件处理函数,将选中标题的id赋值给selectedTitle
tapSegment: function (e) {
console.log(e)
this.setData({
currPage:1
})
const item = e.detail;
this.setData({
selectedTitle: item.index
segmentIndex: item.index
});
switch(item.index){
case 0:
return this.fetchTopicList()
case 1:
return this.fetchGoodIdeaList()
}
}
})

1
pages/topics/index.json

@ -1,4 +1,5 @@
{
"enablePullDownRefresh": true,
"usingComponents": {
"e-segment":"/components/segment/index",
"message": "./message/index",

6
pages/topics/index.wxml

@ -1,7 +1,7 @@
<!--pages/topics/index.wxml-->
<view class="content-wrapper">
<e-segment bind:tapSegment="tapSegment" headerTitles="{{headerTitles}}" defaultSelectIndex="{{selectedTitle}}"/>
<interactive wx:if="{{selectedTitle==0}}" />
<goodIdea wx:if="{{selectedTitle==1}}" />
<message wx:if="{{selectedTitle==2}}" />
<interactive wx:if="{{segmentIndex==0}}" list="{{topicList}}" />
<goodIdea wx:if="{{segmentIndex==1}}" list="{{goodIdeaList}}" />
<message wx:if="{{segmentIndex==2}}" />
</view>

13
pages/topics/interactive/cell/index.js

@ -1,20 +1,17 @@
// pages/topics/common/interactive/common/imageCell/index.js
Component({
/**
* 组件的属性列表
*/
properties: {
articleId: String,
topicId: String,
title: String,
articleImg:String,
topicImg:String,
userIcon:String,
userName:String,
time: String,
commentNum: String,
showTop: {
type: Boolean,
value: false,
}
commentNum: Number
},
/**
@ -29,7 +26,7 @@ Component({
*/
methods: {
onTap() {
this.triggerEvent('clickListItem', { articleId: this.properties.articleId })
this.triggerEvent('clickListItem', { topicId: this.properties.topicId })
}
}
})

4
pages/topics/interactive/cell/index.wxml

@ -23,7 +23,7 @@
</view>
</view>
<view class="right" wx:if="{{articleImg.length > 0}}">
<image class="articleImg" src="./images/articleImg.png"></image>
<view class="right" wx:if="{{topicImg.length > 0}}">
<image class="articleImg" src="{{topicImg}}"></image>
</view>
</view>

1
pages/topics/interactive/cell/index.wxss

@ -61,6 +61,7 @@
width: 30%;
height: 70px;
border-radius: 5px;
background-color: #EEEEEE;
}
image{
width: 100%;

41
pages/topics/interactive/index.js

@ -4,42 +4,17 @@ Component({
* 组件的属性列表
*/
properties: {
list:{
type:Array,
value:[]
}
},
/**
* 组件的初始数据
*/
data: {
list: [
{
articleId: '1',
title: "市北区举行国际航运贸易金融创新中心核心区产业建设",
articleImg: "asdsad",
userIcon: "",
userName: "用户名",
time: "刚刚",
commentNum: "33",
},
{
articleId: "2",
title: "《大众日报》市北区举行国际航运贸易金融创新中心核心区产业建设",
articleImg: "",
userIcon: "",
userName: "用户名",
time: "1分钟前",
commentNum: "33",
},
{
articleId: "3",
title: "青岛医疗人工智能科技创新中心落户市北",
articleImg: "asdsadad",
userIcon: "",
userName: "用户名",
time: "1分钟前",
commentNum: "33",
}
]
},
/**
@ -52,11 +27,9 @@ Component({
})
},
clickListItem(e) {
const articleId = e.detail.articleId;
console.log(articleId);
const topicId = e.detail.topicId;
wx.navigateTo({
url: `/pages/topics/interactive/topicArticle/index?id=${articleId}`,
url: `/pages/topics/interactive/topicArticle/index?topicId=${topicId}`,
})
}
}

7
pages/topics/interactive/index.wxml

@ -1,14 +1,13 @@
<!--pages/topics/interactive/index.wxml-->
<view class="container">
<block wx:for="{{list}}" wx:key="*this">
<block wx:for="{{list}}" wx:key="{{index}}">
<cell
articleId="{{item.articleId}}"
topicId="{{item.topicId}}"
title="{{item.title}}"
articleImg="{{item.articleImg}}"
topicImg="{{item.topicImg}}"
userName="{{item.userName}}"
time="{{item.time}}"
commentNum="{{item.commentNum}}"
showTop="{{item.showTop}}"
bind:clickListItem="clickListItem"/>
</block>

139
pages/topics/interactive/topicArticle/index.js

@ -1,4 +1,11 @@
// pages/topics/interactive/article/index.js
import dayjs from '../../../../utils/dayjs/index.js'
import relativeTime from '../../../../utils/dayjs/relativeTime.js'
dayjs.extend(relativeTime);
import { TopicModel } from '../../../../models/topic.js'
let topicModel = new TopicModel()
Page({
/**
@ -39,14 +46,25 @@ Page({
unStar: '/images/common/star.png',
star: '/images/common/star_light.png',
isStar:true
isStar:true,
topicId:String,
currPage: 1,
commentList: [],
unPraise: '/images/common/zan.png',
praise: '/images/common/star_light.png',
commentId:String
},
/**
* 生命周期函数--监听页面加载
*/
onLoad: function (options) {
console.log(options.topicId)
this.setData({
topicId: options.topicId
})
this.fetchDetail()
this.fetchDetailComment()
},
/**
@ -88,7 +106,11 @@ Page({
* 页面上拉触底事件的处理函数
*/
onReachBottom: function () {
const page = this.data.currPage + 1
this.setData({
currPage: page
})
this.fetchDetailComment()
},
/**
@ -96,14 +118,125 @@ Page({
*/
onShareAppMessage: function () {
},
fetchDetail(){
let topicId = this.data.topicId
topicModel.getTopicDetail(topicId,res => {
console.log('议题详情')
console.log(res)
let data = res.result
this.setData({
title:data.title,
time: data.createTime,
userInfo:{
icon: data.groupAvator,
name:data.author,
company: data.company,
position: data.position,
},
detail:data.content,
imgArr: data.images.split(";").slice(0, -1)
})
console.log(this.data.imgArr)
})
},
fetchDetailComment(){
let topicId = this.data.topicId
let page = this.data.currPage
topicModel.getTopicDetailComment(topicId,page,res => {
console.log('议题评论')
console.log(res)
const datas = res.result.list
let tempDatas = []
datas.forEach(item => {
tempDatas.push({
isPraise: false,
id:item.id,
userIcon: item.commentAvator,
userName: item.username,
detail: item.comment,
time: item.createTime,
praiseNum: item.supportNum
})
})
if (page == 1) {
this.setData({
commentList: tempDatas
})
} else {
if (tempDatas.length > 0) {
const list = [...this.data.commentList, ...tempDatas]
this.setData({
commentList: list
})
} else {
const page = this.data.currPage - 1
this.setData({
currPage: page
})
wx.showToast({
title: '已加载全部',
icon: 'none'
})
}
}
console.log(this.data.commentList)
wx.stopPullDownRefresh()
})
},
fetchTopicCollect(){
let topicId = this.data.topicId
topicModel.topicCollect(topicId,res =>{
console.log('收藏')
console.log(res)
if(res.code === 200){
wx.showToast({
title: '收藏成功',
icon: 'none'
})
}
})
},
fetchTopicCommentPraise(){
let commentId = this.data.commnetId
topicModel.topicCommentPraise(commentId,res =>{
console.log(res)
if (res.code === 200) {
wx.showToast({
title: '点赞',
icon: 'none'
})
}
})
},
onClickCollect() {
this.setData({
isStar: !this.data.isStar
})
this.fetchTopicCollect()
// 收藏功能
},
onClickPraise(e){
console.log(e)
const sIndex = e.currentTarget.dataset.index
var selectItem = e.currentTarget.dataset.item
const commentList = this.data.commentList
const tempList = []
commentList.forEach( (item,index)=>{
if (sIndex === index){
item.isPraise = !item.isPraise
}
tempList.push(item)
})
this.setData({
commentList:tempList,
commentId: selectItem.id
})
this.fetchTopicCommentPraise()
// 评论点赞
},
previewImg: function (e) {
console.log(e.currentTarget.dataset.index);
var index = e.currentTarget.dataset.index;

3
pages/topics/interactive/topicArticle/index.json

@ -1,3 +1,6 @@
{
"enablePullDownRefresh": false,
"navigationBarTitleText":"议题",
"usingComponents": {}
}

10
pages/topics/interactive/topicArticle/index.wxml

@ -14,7 +14,7 @@
</view>
<view class="topic_userInfo">
<view class="user_icon">
<image src=""></image>
<image src="{{userInfo.icon}}"></image>
</view>
<view class="user_text">
<view>
@ -31,7 +31,7 @@
{{detail}}
</view>
<view class="topic_detail_imgs">
<view class='imgList-li' wx:for='{{imgArr}}'>
<view class='imgList-li' wx:for='{{imgArr}}' wx:key="{{index}}">
<image class='img' src='{{item}}' data-index='{{index}}' bindtap='previewImg'></image>
</view>
</view>
@ -41,7 +41,7 @@
<view class="topic_comment_top">
{{'评论 ' + comments.length}}
</view>
<view class="comment_info" wx:for="{{comments}}">
<view class="comment_info" wx:for="{{commentList}}" wx:key="{{index}}">
<view class="comment_info_left">
<image class="comment_icon" src=""></image>
</view>
@ -50,9 +50,9 @@
<view class="comment_info_detail">{{item.detail}}</view>
<view class="comment_info_time">
<view class="comment_info_time_left">{{item.time}}</view>
<view class="comment_info_time_right">
<view class="comment_info_time_right" bindtap="onClickPraise" data-item="{{item}}" data-index='{{index}}'>
<view class="praiseNum">{{item.praiseNum}}</view>
<image class="praiseIcon" src="/images/common/zan.png"></image>
<image class="praiseIcon" src="{{item.isPraise ? praise : unPraise}}"></image>
</view>
</view>
</view>

4
pages/topics/interactive/topicArticle/index.wxss

@ -98,13 +98,13 @@ image{
}
.topic_comment_top{
height: 40px;
border-bottom: 1px solid #E7E7E7;
/* border-bottom: 1px solid #E7E7E7; */
}
.comment_info{
padding: 10px 0;
display: flex;
flex-direction: row;
border-bottom: 1px solid #E7E7E7;
border-top: 1px solid #E7E7E7;
}
.comment_info_left{
width: 30px;

1
utils/http.js

@ -20,6 +20,7 @@ class HTTP {
}
// token 拼接到 请求体中
let data = Object.assign({ token: token }, params.data)
console.log(data)
wx.request({
url: url,
data: data,

Loading…
Cancel
Save