Bläddra i källkod

上传文件至 '微信小程序/douban/pages/comment'

13395952019 6 år sedan
förälder
incheckning
fc6fd610d2

+ 70 - 0
微信小程序/douban/pages/comment/comment.js

@@ -0,0 +1,70 @@
+// pages/comment/comment.js
+Page({
+
+  /**
+   * 页面的初始数据
+   */
+  data: {
+    start: 1,//短评开始
+    count: 10//短评显示条数
+  },
+
+  /**
+   * 生命周期函数--监听页面加载
+   */
+  onLoad: function (options) {
+    var that =this;
+    that.setData({
+      title: options.title,
+      imgUrl: options.imgUrl,
+      rate: options.rate,
+      id: options.id,
+      type: options.type
+    });
+    that.getComments(1);
+  },
+  getComments:function(start){
+    var that = this;
+    var type = that.data.type;
+    var id = that.data.id;
+    var dpurl;//短评的url
+    var count = that.data.count;//短评显示条数
+    var start = start;//短评开始
+    if (type == "movie") {
+      dpurl = 'https://m.douban.com/rexxar/api/v2/movie/' + id + '/interests?count=' + count + '&start=' + start;
+    } else if (type == "tvs" || type == "shows") {
+      dpurl = 'https://m.douban.com/rexxar/api/v2/tv/' + id + '/interests?count=' + count + '&start=' + start;
+    }
+    //获取短评信息
+    wx.request({
+      url: dpurl,
+      success: function (res) {
+        that.setData({
+          comments: res.data.interests,
+          start: start
+        });
+        wx.pageScrollTo({
+          scrollTop: 0,
+        });
+      }
+    })
+  },
+  onItemTapEvent:function(event){
+    //返回上一页
+    wx.navigateBack({})
+  },
+  upPage:function(event){
+    var that = this;
+    var start = that.data.start;
+    var count = that.data.count;
+    if (start - count > 0){
+      that.getComments(start - count);
+    }
+  },
+  nextPage: function (event) {
+    var that = this;
+    var start = that.data.start;
+    var count = that.data.count;
+    that.getComments(start + count);
+  },
+})

+ 5 - 0
微信小程序/douban/pages/comment/comment.json

@@ -0,0 +1,5 @@
+{
+  "usingComponents": {
+    "onecomment": "/components/onecomment/onecomment"
+  }
+}

+ 12 - 0
微信小程序/douban/pages/comment/comment.wxml

@@ -0,0 +1,12 @@
+<view class="container">
+  <view class='item-group' bindtap='onItemTapEvent'>
+    <image class='item-image' src='{{imgUrl}}'></image>
+    <view class='item-title'>{{title}}</view>
+    <view class='item-rate'>{{rate}}分</view>
+  </view>
+  <onecomment wx:for="{{comments}}" item="{{item}}" wx:key="*this"></onecomment>
+  <view class='btn-group'>
+    <button class='page-btn' bindtap='upPage' disabled='{{start<=1}}'>上一页</button>
+    <button class='page-btn' bindtap='nextPage'>下一页</button>
+  </view>
+</view>

+ 36 - 0
微信小程序/douban/pages/comment/comment.wxss

@@ -0,0 +1,36 @@
+.container{
+  padding: 20rpx
+} 
+.item-group{
+  display: flex;
+  justify-content: flex-start;
+  align-items: center;
+}
+.item-group .item-image{
+  width: 40rpx;
+  height: 50rpx;
+}
+.item-group .item-title{
+  font-size: 32rpx;
+  color: #41be57;
+  margin-left: 10rpx;
+  margin-right: 10rpx;
+}
+.item-group .item-rate{
+  font-size: 28rpx;
+  color: #ccc;
+}
+.btn-group{
+  display: flex;
+  margin-top: 40rpx;
+  margin-bottom: 40rpx;
+  justify-content: flex-start;
+  align-items: center;
+}
+.page-btn{
+  flex: 1;
+  height: 60rpx;
+  color: #898989;
+  border-color: #898989;
+  line-height: 60rpx;
+}