chengziding 1 giorno fa
parent
commit
bc74dd1a4a
4 ha cambiato i file con 171 aggiunte e 122 eliminazioni
  1. 145 109
      pages/checkin/index.js
  2. 9 9
      pages/checkin/index.wxml
  3. 4 3
      pages/checkin/index.wxss
  4. 13 1
      project.private.config.json

+ 145 - 109
pages/checkin/index.js

@@ -2,7 +2,6 @@
 const util = require("../../utils/util");
 const tools = require("../../utils/tool");
 const App = getApp();
-
 Page({
   /**
    * 页面的初始数据
@@ -63,9 +62,10 @@ Page({
     wx.setNavigationBarTitle({
       title: '每日签到'
     });
-    this.loadCheckinHistory();
-    this.initCalendar();
+    // this.loadCheckinHistory();
+    // this.initCalendar();
     this.getUserInfo();
+    // this.getCheckDate();
   },
 
   /**
@@ -90,52 +90,86 @@ Page({
   /**
    * 加载签到历史记录
    */
-  loadCheckinHistory() {
-    const currentDate = new Date();
-    const year = currentDate.getFullYear();
-    const month = currentDate.getMonth() + 1;
-    const storageKey = `checkin_${year}_${month}`;
-    
-    // 从本地存储加载当月签到记录
-    let checkedDates = wx.getStorageSync(storageKey) || [];
-    
-    // 确保数据是数组格式
-    if (!Array.isArray(checkedDates)) {
-      checkedDates = [];
-    }
-    
-    // 过滤掉无效的日期(大于当月最大天数)
-    const daysInMonth = new Date(year, month, 0).getDate();
-    checkedDates = checkedDates.filter(day => day >= 1 && day <= daysInMonth);
-    
-    this.setData({
-      checkedDates
-    });
-    
+  loadCheckinHistory () {
+    // const currentDate = new Date();
+    // const year = currentDate.getFullYear();
+    // const month = currentDate.getMonth() + 1;
+    // const storageKey = `checkin_${year}_${month}`;
+
+    // // 从本地存储加载当月签到记录
+    // let checkedDates = wx.getStorageSync(storageKey) || [];
+
+    // // 确保数据是数组格式
+    // if (!Array.isArray(checkedDates)) {
+    //   checkedDates = [];
+    // }
+
+    // // 过滤掉无效的日期(大于当月最大天数)
+    // const daysInMonth = new Date(year, month, 0).getDate();
+    // checkedDates = checkedDates.filter(day => day >= 1 && day <= daysInMonth);
+
+    // this.setData({
+    //   checkedDates
+    // });
+
     // TODO: 这里可以调用API从服务器获取签到记录
-    // this.getCheckinHistoryFromServer();
+    this.getCheckinHistoryFromServer();
+  },
+  //获取用户信息
+  getUserInfo () {
+    let _this = this;
+    let id = util.getUserId();
+    if (id) {
+      let parm = {
+        id,
+      };
+      App._post_form(
+        "member/apiSelectMeberInfo",
+        "application/json",
+        JSON.stringify(parm),
+        function (res) {
+          console.log(res);
+          if (res.code === 0) {
+            wx.setStorageSync("USER", res.member);
+            _this.setData({
+              userInfo: res.member,
+            });
+          } else {
+            wx.removeStorageSync("USER");
+            wx.navigateTo({
+              url: "/pages/login",
+            });
+          }
+        }
+      );
+    }
+  },
+  // 获取已签到日期
+  getCheckDate () {
+    App._get(
+      '/scoreStu/list',
+      { stuId: util.getUserId() }).then(res => {
+      });
   },
-
   /**
    * 从服务器获取签到历史(备用)
    */
-  getCheckinHistoryFromServer() {
+  getCheckinHistoryFromServer () {
     const userId = util.getUserId();
     if (!userId) return;
-    
-    const currentDate = new Date();
-    App._post_form(
-      'checkin/getMonthlyHistory',
-      'application/json',
+
+    App._get(
+      '/scoreStu/list',
       {
-        userId: userId,
-        year: currentDate.getFullYear(),
-        month: currentDate.getMonth() + 1
+        stuId: userId,
       },
       (res) => {
         if (res.code === 0) {
+          let data = res.data.map(v => {
+            return parseInt(v.substr(6, 2));
+          })
           this.setData({
-            checkedDates: res.data || []
+            checkedDates: data
           });
           this.initCalendar();
         }
@@ -146,28 +180,28 @@ Page({
   /**
    * 初始化日历
    */
-  initCalendar() {
+  initCalendar () {
     // 使用当前系统时间
     const date = new Date();
     const year = date.getFullYear();
     const month = date.getMonth();
     const today = date.getDate();
-    
+
     // 获取当月第一天是星期几
     const firstDay = new Date(year, month, 1).getDay();
     const adjustedFirstDay = firstDay === 0 ? 7 : firstDay; // 将周日从0调整为7
-    
+
     // 获取当月天数
     const daysInMonth = new Date(year, month + 1, 0).getDate();
-    
+
     // 生成日历数组
     const calendarDays = [];
-    
+
     // 添加空白格子(上个月的日期)
     for (let i = 1; i < adjustedFirstDay; i++) {
       calendarDays.push({ day: '', isEmpty: true });
     }
-    
+
     // 添加当月日期
     for (let day = 1; day <= daysInMonth; day++) {
       calendarDays.push({
@@ -177,7 +211,7 @@ Page({
         isChecked: this.data.checkedDates.includes(day)
       });
     }
-    
+    console.log('aaa', calendarDays, this.data.checkedDates.includes(26))
     this.setData({
       calendarDays,
       currentYear: year,
@@ -186,22 +220,10 @@ Page({
       isCheckedToday: this.data.checkedDates.includes(today)
     });
   },
-
-  /**
-   * 获取用户信息
-   */
-  getUserInfo() {
-    // 这里可以调用API获取用户信息
-    const userInfo = wx.getStorageSync('userInfo') || this.data.userInfo;
-    this.setData({
-      userInfo
-    });
-  },
-
   /**
    * 立即签到
    */
-  handleCheckin() {
+  handleCheckin () {
     if (this.data.isCheckedToday) {
       wx.showToast({
         title: '今日已签到',
@@ -221,20 +243,15 @@ Page({
   /**
    * 执行签到操作
    */
-  performCheckin() {
+  performCheckin () {
     const userId = util.getUserId();
-    const today = this.data.today;
     const currentDate = new Date();
-    const year = currentDate.getFullYear();
-    const month = currentDate.getMonth() + 1;
-    
     // TODO: 调用签到API
     // App._post_form(
-    //   'checkin/dailyCheckin',
+    //   '/api/scoreStu/dailyLogin',
     //   'application/json',
     //   {
     //     userId: userId,
-    //     date: `${year}-${month.toString().padStart(2, '0')}-${today.toString().padStart(2, '0')}`
     //   },
     //   (res) => {
     //     if (res.code === 0) {
@@ -248,64 +265,83 @@ Page({
     //     }
     //   }
     // );
-    
+
     // 模拟成功签到
-    setTimeout(() => {
-      this.updateCheckinSuccess(10);
-    }, 1000);
+    // setTimeout(() => {
+    this.updateCheckinSuccess(10);
+    // }, 1000);
   },
 
   /**
    * 更新签到成功状态
    */
-  updateCheckinSuccess(points = 10) {
-    wx.hideLoading();
-    
-    const today = this.data.today;
-    const checkedDates = [...this.data.checkedDates, today];
-    const calendarDays = this.data.calendarDays.map(item => {
-      if (item.day === today) {
-        return { ...item, isChecked: true };
-      }
-      return item;
-    });
+  updateCheckinSuccess (points = 10) {
+    // wx.hideLoading();
 
-    // 保存到本地存储
-    const currentDate = new Date();
-    const year = currentDate.getFullYear();
-    const month = currentDate.getMonth() + 1;
-    const storageKey = `checkin_${year}_${month}`;
-    wx.setStorageSync(storageKey, checkedDates);
+    // const today = this.data.today;
+    // const checkedDates = [...this.data.checkedDates, today];
+    // const calendarDays = this.data.calendarDays.map(item => {
+    //   if (item.day === today) {
+    //     return { ...item, isChecked: true };
+    //   }
+    //   return item;
+    // });
 
-    this.setData({
-      checkedDates,
-      calendarDays,
-      isCheckedToday: true,
-      'userInfo.points': this.data.userInfo.points + points
-    });
+    // // 保存到本地存储
+    // const currentDate = new Date();
+    // const year = currentDate.getFullYear();
+    // const month = currentDate.getMonth() + 1;
+    // const storageKey = `checkin_${year}_${month}`;
+    // wx.setStorageSync(storageKey, checkedDates);
+
+    // this.setData({
+    //   checkedDates,
+    //   calendarDays,
+    //   isCheckedToday: true,
+    //   'userInfo.points': this.data.userInfo.points + points
+    // });
+
+    // wx.showToast({
+    //   title: `签到成功,获得${points}积分`,
+    //   icon: 'success'
+    // });
 
-    wx.showToast({
-      title: `签到成功,获得${points}积分`,
-      icon: 'success'
-    });
-    
     // 统计积分(每日登录)
-    this.addScore();
+    // this.addScore();
+    if (!util.getUserId()) {
+      return;
+    }
+    let _this = this;
+    App._post_form(
+      'scoreStu/dailySign',
+      '', {
+      stuId: util.getUserId(),
+    },
+      function (res) {
+        // 积分统计完成
+        wx.showToast({
+          title: `签到成功,获得${points}积分`,
+          icon: 'success'
+        });
+        _this.loadCheckinHistory();
+        _this.initCalendar();
+      }
+    );
   },
 
   /**
    * 统计积分(每日登录)
    */
-  addScore: function() {
+  addScore: function () {
     if (!util.getUserId()) {
       return;
     }
     App._post_form(
-      'scoreStu/dailyLogin',
+      'scoreStu/dailyLogin/dailySign',
       '', {
-        stuId: util.getUserId()
-      },
-      function(res) {
+      stuId: util.getUserId(),
+    },
+      function (res) {
         // 积分统计完成
       }
     );
@@ -314,17 +350,17 @@ Page({
   /**
    * 处理任务点击
    */
-  handleTaskClick(e) {
+  handleTaskClick (e) {
     const taskId = e.currentTarget.dataset.id;
     const task = this.data.tasks.find(t => t.id == taskId);
-    
+
     wx.showToast({
       title: `点击了${task.title}`,
       icon: 'none'
     });
-    
+
     // 根据不同任务跳转到不同页面
-    switch(taskId) {
+    switch (taskId) {
       case 1:
       case 4:
         // 邀请好友
@@ -344,7 +380,7 @@ Page({
   /**
    * 邀请好友
    */
-  inviteFriend() {
+  inviteFriend () {
     wx.showModal({
       title: '邀请好友',
       content: '邀请好友注册可获得积分奖励',
@@ -364,7 +400,7 @@ Page({
   /**
    * 观看广告
    */
-  watchAd() {
+  watchAd () {
     wx.showToast({
       title: '广告功能开发中',
       icon: 'none'
@@ -374,7 +410,7 @@ Page({
   /**
    * 参与课程
    */
-  joinCourse() {
+  joinCourse () {
     wx.navigateTo({
       url: '/pages/home/index/courseDetail/courseDetail'
     });

+ 9 - 9
pages/checkin/index.wxml

@@ -2,13 +2,13 @@
   <!-- 用户信息栏 -->
   <view class="user-header">
     <view class="user-info">
-      <image class="avatar" src="{{userInfo.avatar || appAssetsUrl2 + 'new/user.png'}}" mode="aspectFill"></image>
+      <image class="avatar" src="{{userInfo.memberphoto || appAssetsUrl2 + 'new/user.png'}}" mode="aspectFill"></image>
       <view class="user-details">
-        <view class="nickname">{{userInfo.nickname}} 👑</view>
+        <view class="nickname">{{userInfo.vipname}} 👑</view>
       </view>
     </view>
     <view class="points-info">
-      <view class="points-number">{{userInfo.points}}</view>
+      <view class="points-number">{{userInfo.totalPoints||0}}</view>
       <view class="points-label">我的积分</view>
     </view>
   </view>
@@ -25,11 +25,12 @@
     <view class="weekdays">
       <view class="weekday" wx:for="{{weekdays}}" wx:key="index">{{item}}</view>
     </view>
-    
+
     <!-- 日期网格 -->
     <view class="calendar-grid">
-      <view class="calendar-day {{item.isEmpty ? 'empty' : ''}} {{item.isToday ? 'today' : ''}} {{item.isChecked ? 'checked' : ''}}" 
-            wx:for="{{calendarDays}}" wx:key="index">
+      <view
+        class="calendar-day {{item.isEmpty ? 'empty' : ''}} {{item.isToday ? 'today' : ''}} {{item.isChecked ? 'checked' : ''}}"
+        wx:for="{{calendarDays}}" wx:key="index">
         <view class="day-number" wx:if="{{!item.isEmpty}}">{{item.day}}</view>
         <view class="check-dot" wx:if="{{item.isChecked && !item.isEmpty}}"></view>
       </view>
@@ -38,9 +39,8 @@
 
   <!-- 签到按钮 -->
   <view class="checkin-btn-container">
-    <button class="checkin-btn {{isCheckedToday ? 'disabled' : ''}}" 
-            bindtap="handleCheckin" 
-            disabled="{{isCheckedToday}}">
+    <button class="checkin-btn {{isCheckedToday ? 'disabled' : ''}}" bindtap="handleCheckin"
+      disabled="{{isCheckedToday}}">
       {{isCheckedToday ? '今日已签到' : '立即签到'}}
     </button>
   </view>

+ 4 - 3
pages/checkin/index.wxss

@@ -166,7 +166,7 @@
   background: linear-gradient(135deg, #4a90e2 0%, #357abd 100%);
   border: none;
   border-radius: 48rpx;
-  color: #fff;
+  color: #fff !important;
   font-size: 32rpx;
   font-weight: 600;
   display: flex;
@@ -176,8 +176,9 @@
 }
 
 .checkin-btn.disabled {
-  background: #ccc;
-  box-shadow: none;
+  /* background: #ccc; */
+  /* color: #ccc; */
+  /* box-shadow: none; */
 }
 
 .checkin-btn::after {

+ 13 - 1
project.private.config.json

@@ -1,5 +1,17 @@
 {
-  "condition": {},
+  "condition": {
+    "miniprogram": {
+      "list": [
+        {
+          "name": "pages/checkin/index",
+          "pathName": "pages/checkin/index",
+          "query": "",
+          "scene": null,
+          "launchMode": "default"
+        }
+      ]
+    }
+  },
   "description": "项目私有配置文件。此文件中的内容将覆盖 project.config.json 中的相同字段。项目的改动优先同步到此文件中。详见文档:https://developers.weixin.qq.com/miniprogram/dev/devtools/projectconfig.html",
   "setting": {
     "urlCheck": false,