瀏覽代碼

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

13395952019 6 年之前
父節點
當前提交
84727a3315

+ 127 - 0
微信小程序/douban/pages/list/list.js

@@ -0,0 +1,127 @@
+// pages/list/list.js
+Page({
+
+  /**
+   * 页面的初始数据
+   */
+  data: {
+
+  },
+
+  /**
+   * 生命周期函数--监听页面加载
+   */
+  onLoad: function (options) {
+    var that = this;
+    wx.showLoading({
+      title: '正在加载中...',
+    });
+    that.setData({
+      type: options.type
+    })
+    if (options.type=='movie'){
+      //请求电影
+      wx.request({
+        url: 'https://m.douban.com/rexxar/api/v2/subject_collection/movie_showing/items',
+        success: function (res) {
+          var movies = res.data.subject_collection_items;
+
+          //设置如果最后剩下2个的情况下在添加一个空元素
+          var itemsCount = movies.length;
+          var left = itemsCount%3;
+          if(left==2){
+            movies.push(null);
+          }
+
+          that.setData({
+            movies: movies
+          })
+          wx.hideLoading();
+        }
+      })
+      //设置标题
+      wx.setNavigationBarTitle({
+        title: '电影',
+      })
+    } else if (options.type == 'tvs'){
+      //请求电视剧
+      wx.request({
+        url: 'https://m.douban.com/rexxar/api/v2/subject_collection/tv_hot/items',
+        success: function (res) {
+          var movies = res.data.subject_collection_items;
+          that.setData({
+            movies: movies
+          });
+          wx.hideLoading();
+        }
+      })
+      wx.setNavigationBarTitle({
+        title: '电视剧',
+      })
+    } else if (options.type == 'shows'){
+      //请求综艺
+      wx.request({
+        url: 'https://m.douban.com/rexxar/api/v2/subject_collection/tv_variety_show/items',
+        success: function (res) {
+          var movies = res.data.subject_collection_items;
+          that.setData({
+            movies: movies
+          });
+          wx.hideLoading();
+        }
+      })
+      wx.setNavigationBarTitle({
+        title: '综艺',
+      })
+    }
+  },
+
+  /**
+   * 生命周期函数--监听页面初次渲染完成
+   */
+  onReady: function () {
+
+  },
+
+  /**
+   * 生命周期函数--监听页面显示
+   */
+  onShow: function () {
+
+  },
+
+  /**
+   * 生命周期函数--监听页面隐藏
+   */
+  onHide: function () {
+
+  },
+
+  /**
+   * 生命周期函数--监听页面卸载
+   */
+  onUnload: function () {
+
+  },
+
+  /**
+   * 页面相关事件处理函数--监听用户下拉动作
+   */
+  onPullDownRefresh: function () {
+
+  },
+
+  /**
+   * 页面上拉触底事件的处理函数
+   */
+  onReachBottom: function () {
+
+  },
+
+  /**
+   * 用户点击右上角分享
+   */
+  onShareAppMessage: function () {
+
+  }
+})

+ 7 - 0
微信小程序/douban/pages/list/list.json

@@ -0,0 +1,7 @@
+{
+  "usingComponents": {
+    "searchbar": "/components/searchbar/searchbar",
+    "stars": "/components/stars/stars",
+    "itemview": "/components/itemview/itemview"
+  }
+}

+ 4 - 0
微信小程序/douban/pages/list/list.wxml

@@ -0,0 +1,4 @@
+<searchbar isnagigator="{{true}}"></searchbar>
+<view class='container'>
+  <itemview wx:for="{{movies}}" wx:key="{{item.title}}" item="{{item}}" itemurl="/pages/detail/detail?type={{type}}&id={{item.id}}"></itemview> 
+</view>

+ 6 - 0
微信小程序/douban/pages/list/list.wxss

@@ -0,0 +1,6 @@
+.container{
+  display: flex;
+  justify-content: space-between;
+  flex-wrap: wrap;
+  padding: 30rpx;
+}