|
@@ -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'
|
|
|
});
|