Преглед на файлове

feature: 处理banner接口数据与点击事件

Damon преди 8 месеца
родител
ревизия
58c469c6f8
променени са 2 файла, в които са добавени 17 реда и са изтрити 19 реда
  1. 15 17
      pages/index/index.js
  2. 2 2
      pages/index/index.wxml

+ 15 - 17
pages/index/index.js

@@ -23,17 +23,7 @@ Page({
       showCapsule: 0, //是否显示左上角图标   1表示显示    0表示不显示
       title: 'OhPlay', //导航栏 中间的标题
     },
-    bannerList: [
-      // {
-      //   imgUrl: 'http://img1.baidu.com/it/u=2343623234,438083234&fm=253&app=138&f=JPEG?w=684&h=1216'
-      // },
-      // {
-      //   imgUrl: 'http://img1.baidu.com/it/u=2343623234,438083234&fm=253&app=138&f=JPEG?w=684&h=1216'
-      // },
-      // {
-      //   imgUrl: 'http://img1.baidu.com/it/u=2343623234,438083234&fm=253&app=138&f=JPEG?w=684&h=1216'
-      // }
-    ],
+    bannerList: [],
     autoplay: true,
     interval: 3000, // 切换时间间隔
     duration: 500, // 滑动动画时长
@@ -67,6 +57,13 @@ Page({
 
   onLoad(options) {
     var that = this;
+
+    var bannerList = wx.getStorageSync("homeBanner") || [];
+    if (that.data.bannerList.length == 0) {
+      that.setData({
+        bannerList: bannerList
+      });
+    }
     that.onHomeLoad();
     that.onMeLoad();
   },
@@ -83,16 +80,11 @@ Page({
     that.setData({
       greeting: greeting
     });
-
     getBanner({}).then((res) => {
-      console.log("gadfadfqwwerqewqr===" + JSON.stringify(res));
       that.setData({
         bannerList: res
       });
-      wx.setStorage({
-        key: "homeBanner",
-        data: res
-      });
+      wx.setStorageSync("homeBanner", res);
     })
   },
 
@@ -731,6 +723,12 @@ Page({
     });
   },
 
+  ///点击banner事件
+  onTapBanner() {
+    var that = this;
+    var item = e.currentTarget.dataset.item;
+  },
+
   deleteDevice(e) {
     wx.showModal({
       title: '确定删除?',

+ 2 - 2
pages/index/index.wxml

@@ -13,7 +13,7 @@
       <swiper class="swiper" indicator-dots="{{bannerList.length>1}}" autoplay="{{autoplay}}" interval="{{interval}}" duration="{{duration}}" circular="{{circular}}" indicator-active-color="#FFFFFF" indicator-color="#999999">
         <block wx:for="{{bannerList}}" wx:key="index">
           <swiper-item>
-            <image class="swiper_image" src="{{item.imgUrl}}" />
+            <image class="swiper_image" src="{{item.pic}}" data-item="{{item}}" bind:tap="onTapBanner" />
           </swiper-item>
         </block>
       </swiper>
@@ -24,7 +24,7 @@
       <view style="color: white; margin-left: 8rpx; font-size: 32rpx;">添加设备</view>
     </view>
 
-    <scroll-view scroll-y="true" style="height: calc(100vh - 118rpx - 14rpx - 20rpx - 32rpx - 88rpx - 64rpx - 58rpx -  {{navBarHeight}}px);margin-top: 22rpx;padding-top: 10rpx; ">
+    <scroll-view scroll-y="true" style="height: calc(100vh - 118rpx - 14rpx - 20rpx  - 88rpx - 64rpx - 58rpx - {{bannerList.length>0?296:0}}rpx -  {{navBarHeight}}px);margin-top: 22rpx;padding-top: 10rpx; ">
 
       <view wx:if="{{deviceList}}">
         <block wx:key="key" wx:for-item="item" wx:for-index="index" wx:for="{{deviceList}}">