bayi пре 2 година
родитељ
комит
4d40bbac01

+ 2 - 0
api/global.js

@@ -14,4 +14,6 @@ module.exports = {
   submitTask: data => request('/v3/task', 'post', data),
   // 获取轮播图列表
   getBannerList: data => request(`/v3/banner/${data}`, 'get', data),
+  // 获取官方活动
+  getActivities: data => request('/v3/activity', 'get', data),
 }

+ 2 - 0
app.js

@@ -14,6 +14,8 @@ App({
   onLaunch() {
     this.checkIsIos()
     this.getNavbarInfo()
+    let res = wx.getLaunchOptionsSync()
+    console.log(res, 'res');
   },
   async onShow(options) {
     this.storeBindings = createStoreBindings(this, {

+ 1 - 1
app.json

@@ -1,8 +1,8 @@
 {
   "pages": [
+    "pages/index/index",
     "pages/medalStore/index",
     "pages/my/index",
-    "pages/index/index",
     "pages/pkResult/index",
     "pages/score/index",
     "pages/pkPage/index",

+ 70 - 7
components/activityList/index.js

@@ -1,20 +1,83 @@
+import {
+  getActivities
+} from '~/api/global'
 Component({
-  properties: {
-
-  },
-
+  properties: {},
   /**
    * 组件的初始数据
    */
   data: {
     //,2:邀新榜,3:热播榜,4:挑战pk榜,5,朗读赛
-    type: '4'
+    type: '4',
+    activityList: [{
+      id: 1,
+      name: '新学期限时充值活动',
+      closing: '2023-1-29 16:38:00',
+    }, {
+      id: 2,
+      name: '入学限时充值活动',
+      closing: '2023-1-30 16:38:00',
+    }],
+    dsqList: []
+  },
+  lifetimes: {
+    attached() {
+      this.getActivities()
+    },
+    detached() {
+      this.data.dsqList.forEach(item => {
+        clearInterval(item)
+      })
+    }
   },
-
   /**
    * 组件的方法列表
    */
   methods: {
-
+    async getActivities() {
+      let res = await getActivities()
+      this.data.activityList.forEach((item, index) => {
+        this.activityTimeOut(item.closing, index)
+      })
+    },
+    activityTimeOut(oTime,index) {
+      let inputTime = new Date(oTime)
+      let dsq = setInterval(() => {
+        console.log('执行呢');
+        var nowTime = new Date();
+        //把剩余时间毫秒数转化为秒
+        var times = (inputTime - nowTime) / 1000;
+        if (times <= 0) {
+          this.setData({
+            [`activityList[${index}].hour`]: '00',
+            [`activityList[${index}].minute`]: '00',
+            [`activityList[${index}].second`]: '00',
+          })
+          return clearInterval(dsq)
+        }
+        console.log(times);
+        //计算小时数 转化为整数
+        var h = parseInt(times / 60 / 60 % 24);
+        //如果小时数小于 10,要变成 0 + 数字的形式 赋值给盒子
+        let hour = h < 10 ? "0" + h : h;
+        //计算分钟数 转化为整数
+        var m = parseInt(times / 60 % 60);
+        //如果分钟数小于 10,要变成 0 + 数字的形式 赋值给盒子
+        let minute = m < 10 ? "0" + m : m;
+        //计算描述 转化为整数
+        var s = parseInt(times % 60);
+        //如果秒钟数小于 10,要变成 0 + 数字的形式 赋值给盒子
+        let second = s < 10 ? "0" + s : s;
+        this.setData({
+          [`activityList[${index}].hour`]: hour,
+          [`activityList[${index}].minute`]: minute,
+          [`activityList[${index}].second`]: second,
+        })
+        times = --times;
+      }, 1000);
+      this.setData({
+        dsqList: [...this.data.dsqList, dsq]
+      })
+    }
   }
 })

+ 23 - 1
components/activityList/index.less

@@ -265,7 +265,7 @@
   .activityBox {
     margin-bottom: 20rpx;
     width: 100%;
-    padding: 20rpx 20rpx 34rpx;
+    padding: 20rpx;
     box-sizing: border-box;
     background-color: white;
     border-radius: 30rpx;
@@ -286,11 +286,33 @@
       .info {
         .title {
           font-size: 32rpx;
+          margin-bottom: 8rpx;
         }
 
         .time {
           font-size: 26rpx;
         }
+
+        .timeOut {
+          display: flex;
+          align-items: center;
+          font-weight: bold;
+          font-size: 28rpx;
+
+          .outNum {
+            width: 46rpx;
+            font-size: 26rpx;
+            text-align: center;
+            border-radius: 10rpx;
+            background-color: #F62339;
+            color: white;
+          }
+
+          .outSplit {
+            margin: 0rpx 2rpx;
+            color: #F62339;
+          }
+        }
       }
 
       .btn {

+ 16 - 10
components/activityList/index.wxml

@@ -1,4 +1,20 @@
 <view class="activityList">
+  <view class="activityBox" wx:for="{{activityList}}" wx:key="id">
+    <image src="" class="cover" />
+    <view class="footer">
+      <view class="info">
+        <view class="title">{{item.name}}</view>
+        <view class="timeOut" wx:if="{{item.second}}">距活动结束:
+          <view class="outNum">{{item.hour}}</view>
+          <view class="outSplit">:</view>
+          <view class="outNum">{{item.minute}}</view>
+          <view class="outSplit">:</view>
+          <view class="outNum">{{item.second}}</view>
+        </view>
+      </view>
+      <view class="btn">立即参与</view>
+    </view>
+  </view>
   <view class="ranking-class-1">
     <view class="header">
       <view class="title">邀新榜TOP100</view>
@@ -91,14 +107,4 @@
       <view class="btn">立即参与</view>
     </view>
   </view>
-  <view class="activityBox">
-    <image src="" class="cover" />
-    <view class="footer">
-      <view class="info">
-        <view class="title">新学期 朗读赛</view>
-        <view class="time">2023.03.8-2023.03.14</view>
-      </view>
-      <view class="btn">立即参与</view>
-    </view>
-  </view>
 </view>

+ 20 - 1
components/activityList/index.wxss

@@ -213,7 +213,7 @@
 .activityList .activityBox {
   margin-bottom: 20rpx;
   width: 100%;
-  padding: 20rpx 20rpx 34rpx;
+  padding: 20rpx;
   box-sizing: border-box;
   background-color: white;
   border-radius: 30rpx;
@@ -232,10 +232,29 @@
 }
 .activityList .activityBox .footer .info .title {
   font-size: 32rpx;
+  margin-bottom: 8rpx;
 }
 .activityList .activityBox .footer .info .time {
   font-size: 26rpx;
 }
+.activityList .activityBox .footer .info .timeOut {
+  display: flex;
+  align-items: center;
+  font-weight: bold;
+  font-size: 28rpx;
+}
+.activityList .activityBox .footer .info .timeOut .outNum {
+  width: 46rpx;
+  font-size: 26rpx;
+  text-align: center;
+  border-radius: 10rpx;
+  background-color: #F62339;
+  color: white;
+}
+.activityList .activityBox .footer .info .timeOut .outSplit {
+  margin: 0rpx 2rpx;
+  color: #F62339;
+}
 .activityList .activityBox .footer .btn {
   padding: 10rpx 48rpx;
   background-image: linear-gradient(270deg, #33C3FF 0%, #81C7FF 100%, #14C962 100%);

+ 0 - 1
mixins/reachBottom.js

@@ -50,7 +50,6 @@ module.exports = Behavior({
 
     },
     resetData(data) {
-      console.log("触发resetData");
       if (this.data.loading) return; // 如果接口已经在请求中,则不重置数据,防止用户持续下拉刷新
       this.setData({
         loading: false,

+ 1 - 1
pages/index/index.js

@@ -20,7 +20,7 @@ Page({
   data: {
     navBarHeight: app.globalData.navBarHeight,
     background: ['demo-text-1', 'demo-text-2', 'demo-text-3'],
-    currentType: '1',
+    currentType: '3',
     // 控制一级分类是否固定
     isFixed: false,
     categoryList: []