Skip to content

Commit

Permalink
完成课表分周次显示
Browse files Browse the repository at this point in the history
  • Loading branch information
bufuchangfeng committed Nov 12, 2019
1 parent 3ce6f93 commit c58013b
Show file tree
Hide file tree
Showing 4 changed files with 185 additions and 10 deletions.
47 changes: 47 additions & 0 deletions app.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,46 @@
var util = require("./utils/util.js")
App({
onLaunch: function () {



if (wx.canIUse('getUpdateManager')) {
const updateManager = wx.getUpdateManager()
updateManager.onCheckForUpdate(function (res) {
// 请求完新版本信息的回调
if (res.hasUpdate) {
updateManager.onUpdateReady(function () {
wx.showModal({
title: '更新提示',
content: '新版本已经准备好,是否重启应用?',
success: function (res) {
if (res.confirm) {
// 新的版本已经下载好,调用 applyUpdate 应用新版本并重启
updateManager.applyUpdate()
}
}
})
})
updateManager.onUpdateFailed(function () {
// 新的版本下载失败
wx.showModal({
title: '已有新版本',
content: '检查到有新版本,但下载失败,请检查网络设置',
})
})
}
})
} else {
// 如果希望用户在最新版本的客户端上体验您的小程序,可以这样子提示
wx.showModal({
title: '提示',
content: '当前QQ版本过低,无法使用该功能,请升级到最新QQ版本后重试。'
})
}




var openid = wx.getStorageSync("openid")
if(openid == ""){
qq.login({
Expand Down Expand Up @@ -42,6 +82,13 @@ App({
})
}else{
}







},
globalData: {
}
Expand Down
132 changes: 126 additions & 6 deletions pages/curriculum/curriculum.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,96 @@ Page({
*/
data: {
colorArrays: ["#85B8CF", "#90C652", "#D8AA5A", "#FC9F9D", "#0A9A84", "#61BC69", "#12AEF3", "#E29AAD"],
wlist: []
wlist: [],
months: [],
term_start_month:8, // this need change
term_start_day:26, // this need change
current_week:null,
ifleapyear:null,
daysofmonth: [31, -1, 31, 30, 31, 30, 31,31,30,31,30,31],
wlistbkp: []
},

toLastWeek:function(){
var _cw = this.data.current_week
_cw -= 1
if(_cw < 1){
return
}
this.setData({
current_week: _cw
})
this.updateCurriculum(_cw)
},

toNextWeek:function(){
var _cw = this.data.current_week
_cw += 1
if(_cw > 20){
return
}
this.setData({
current_week: _cw
})
this.updateCurriculum(_cw)
},

timeInit:function(){
var timestamp = Date.parse(new Date());
var date = new Date(timestamp);

var year =date.getFullYear();

// console.log(year)

var dayoffebruary

if(year%4==0&&year%100!=0||year%400==0){
console.log("今年是闰年")
this.setData({
ifleapyear: true
})
dayoffebruary = 29
}
else{
this.setData({
ifleapyear: false
})
console.log("今年不是闰年")
dayoffebruary = 28
}

// 设置二月天数
var _daysofmonth = this.data.daysofmonth
_daysofmonth[1] = dayoffebruary

this.setData({
daysofmonth: _daysofmonth
})

// console.log(this.data.daysofmonth)
//计算 current week

// 获取当前月份
var month = (date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1);
//获取当日日期 
var day = date.getDate() < 10 ? '0' + date.getDate() : date.getDate();
// console.log(month, day)

// 计算学期第一天到今天的天数
var days = 0
for(var a = this.data.term_start_month + 1; a < month; a++)
{
days += _daysofmonth[a - 1];
}
days += day + _daysofmonth[this.data.term_start_month-1] - this.data.term_start_day + 1

this.setData({
current_week: Math.ceil(days/7)
})
// console.log(Math.ceil(days/7))
},

showCardView: function(e){
console.log(e.currentTarget.dataset.index)
wx.navigateTo({
Expand All @@ -20,7 +107,8 @@ Page({
/**
* 生命周期函数--监听页面加载
*/
onLoad: function (options) {
onShow: function (options) {

},

/**
Expand All @@ -33,10 +121,12 @@ Page({
/**
* 生命周期函数--监听页面显示
*/
onShow: function () {
onLoad: function () {

this.timeInit()

var that = this

var ifbind = wx.getStorageSync("ifbind")
if(ifbind == ""){
wx.showToast({
Expand All @@ -61,15 +151,45 @@ Page({
url: 'https://www.neumark.top/lesson/get',
method: "POST",
success: (res) => {
console.log(res.data)
that.setData({
wlist: res.data
wlistbkp: res.data
})
// console.log(res.data)
var _wlist = []

for(var j = 0; j < res.data.length; j++) {
for(var k = 0; k < res.data[j]['time'].length; k++){
// console.log(res.data[j]['time'][k]['上课周次'].split('、'))
if(-1 != res.data[j]['time'][k]['上课周次'].split('、').indexOf(this.data.current_week + '')){
_wlist.push(res.data[j])
break;
}
}
}

that.setData({
wlist: _wlist
})
}
})
}
},

updateCurriculum: function(current_week){
var _wlist = []
for(var j = 0; j < this.data.wlistbkp.length; j++) {
for(var k = 0; k < this.data.wlistbkp[j]['time'].length; k++){
if(-1 != this.data.wlistbkp[j]['time'][k]['上课周次'].split('、').indexOf(current_week + '')){
_wlist.push(this.data.wlistbkp[j])
break;
}
}
}
this.setData({
wlist: _wlist
})
},

/**
* 生命周期函数--监听页面隐藏
*/
Expand Down
12 changes: 10 additions & 2 deletions pages/curriculum/curriculum.wxml
Original file line number Diff line number Diff line change
@@ -1,9 +1,17 @@
<!--pages/curriculum/curriculum.wxml-->

<view class="padding text-center" style="display: flex;">
<view style="width:50%; font-size:40rpx;">第{{current_week}}周</view>

<button class="cu-btn bg-blue lg" style="width: 90%;" bindtap="toLastWeek">上一周</button>
<button class="cu-btn bg-red lg" style="width: 90%;" bindtap="toNextWeek">下一周</button>
</view>

<view class="top">
<view wx:for="{{['一','二','三','四','五','六','日']}}" class="top-text" wx:key>周{{item}}</view>
</view>
<scroll-view scroll-y="true" class="scroll">
<view style="height:1200rpx;width:730rpx;display:flex;">
<view style="height:1400rpx;width:730rpx;display:flex;">
<view style="background-color:#D2E6B3;color:#7cba23;">
<view wx:for="{{[1,2,3,4,5,6,7,8,9,10,11]}}" class="left" wx:key>
{{item}}
Expand All @@ -17,7 +25,7 @@

<!--课表-->
<view wx:for="{{wlist}}" wx:key>
<view class="flex-item kcb-item" bindtap="showCardView" data-statu="open" data-index="{{index}}" style="margin-left:{{(item.xqj-1)*100}}rpx;margin-top:{{(item.skjc-1)*100+5}}rpx;height:{{item.skcd*100-5}}rpx;background-color:{{colorArrays[index%8]}}">
<view class="flex-item kcb-item" bindtap="showCardView" data-status="open" data-index="{{index}}" style="margin-left:{{(item.xqj-1)*100}}rpx;margin-top:{{(item.skjc-1)*100+5}}rpx;height:{{item.skcd*100-5}}rpx;background-color:{{colorArrays[index%8]}}">
<view class="smalltext" >{{item.kcmc}}</view>
</view>
</view>
Expand Down
4 changes: 2 additions & 2 deletions pages/library/library.wxml
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@
</view>
</view>

<view class="padding text-center">
<!-- <view class="padding text-center">
<view class="padding-xl radius shadow-warp bg-white margin-top">
<button class="cu-btn bg-blue lg" style="width: 90%;" bindtap="navigateToLecture">素质教育签到</button>
</view>
</view>
</view> -->

<view class="padding text-center">
<view class="cu-capsule round">
Expand Down

0 comments on commit c58013b

Please sign in to comment.