Skip to content

Commit a03f626

Browse files
author
Yang
committedOct 18, 2023
更新界面
1 parent 975fac9 commit a03f626

20 files changed

+212
-1252
lines changed
 

‎app.json

+6-2
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@
55
"pages/login/login",
66
"pages/edit/edit",
77

8-
9-
108
"pages/topic/topic",
119
"pages/user/user",
1210
"pages/authorize/authorize",
@@ -28,6 +26,12 @@
2826
"iconPath": "/assets/images/index.png",
2927
"selectedIconPath": "/assets/images/index1.png"
3028
},
29+
{
30+
"pagePath": "pages/course/course",
31+
"text": "课表",
32+
"iconPath": "/assets/images/week1.png",
33+
"selectedIconPath": "/assets/images/week.png"
34+
},
3135
{
3236
"pagePath": "pages/topic/topic",
3337
"text": "话题",

‎assets/images/week.png

1.84 KB
Loading

‎assets/images/week1.png

1.79 KB
Loading

‎assets/images/xduLogo.png

-207 KB
Binary file not shown.

‎pages/course/course.js

+69-38
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
// pages/course/course.js
22
import utils from '../../utils/utils.js'
3+
import Dialog from '@vant/weapp/dialog/dialog';
34
const app = getApp()
45
Page({
56

@@ -8,60 +9,46 @@ Page({
89
*/
910
data: {
1011
colorArrays: ["#85B8CF", "#90C652", "#D8AA5A", "#FC9F9D", "#0A9A84", "#61BC69", "#12AEF3", "#E29AAD"],
11-
wlist: [
12-
{ "xqj": 1, "skjc": 1, "skcd": 3, "kcmc": "高等数学@教A-301" },
13-
{ "xqj": 1, "skjc": 5, "skcd": 3, "kcmc": "高等数学@教A-301" },
14-
{ "xqj": 2, "skjc": 1, "skcd": 2, "kcmc": "高等数学@教A-301" },
15-
{ "xqj": 2, "skjc": 8, "skcd": 2, "kcmc": "高等数学@教A-301" },
16-
{ "xqj": 3, "skjc": 4, "skcd": 1, "kcmc": "高等数学@教A-301" },
17-
{ "xqj": 3, "skjc": 8, "skcd": 1, "kcmc": "高等数学@教A-301" },
18-
{ "xqj": 3, "skjc": 5, "skcd": 2, "kcmc": "高等数学@教A-301" },
19-
{ "xqj": 4, "skjc": 2, "skcd": 3, "kcmc": "高等数学@教A-301" },
20-
{ "xqj": 4, "skjc": 8, "skcd": 2, "kcmc": "高等数学@教A-301" },
21-
{ "xqj": 5, "skjc": 1, "skcd": 2, "kcmc": "高等数学@教A-301" },
22-
{ "xqj": 6, "skjc": 3, "skcd": 2, "kcmc": "高等数学@教A-301" },
23-
{ "xqj": 7, "skjc": 5, "skcd": 3, "kcmc": "高等数学@教A-301" },
24-
25-
],
26-
kcb: [],
12+
kcb: null,
2713
result: null,
2814
showWeekList: false,
29-
classShow:false,
15+
classShow: false,
3016
customBar: app.globalData.CustomBar,
3117
statusBar: app.globalData.StatusBar,
3218
custom: app.globalData.Custom,
33-
selectWeek:null
19+
selectWeek: null,
20+
isLogin: false
3421

3522
},
36-
BackPage(){
23+
BackPage() {
3724
wx.navigateBack({
3825
delta: 1
39-
});
26+
});
4027

4128
},
4229
clickClass(e) {
4330
wx.vibrateShort({
4431
type: 'medium',
4532
})
4633
this.setData({
47-
classShow:true,
48-
currentClass:e.currentTarget.dataset.index
34+
classShow: true,
35+
currentClass: e.currentTarget.dataset.index
4936
})
5037
console.log(e)
5138

5239
},
53-
onClassClose(){
40+
onClassClose() {
5441
this.setData({
55-
classShow:false
42+
classShow: false
5643
})
5744
},
58-
selectWeek(e){
45+
selectWeek(e) {
5946
var week = parseInt(e.currentTarget.dataset.index) + 1;
6047
var date = utils.getWeekDates(week)
6148

6249
this.setData({
63-
selectWeek:week,
64-
date:date
50+
selectWeek: week,
51+
date: date
6552
})
6653
wx.getStorage({
6754
key: "kcb",
@@ -91,9 +78,9 @@ Page({
9178

9279
showWeekList() {
9380
wx.vibrateShort({
94-
type: 'heavy'
95-
96-
})
81+
type: 'heavy'
82+
83+
})
9784
this.setData({
9885
showWeekList: true
9986
})
@@ -104,19 +91,44 @@ Page({
10491
showWeekList: false
10592
})
10693
},
94+
isLogin() {
95+
wx.getStorage({
96+
key: "user",
97+
success: (res) => {
98+
this.setData({
99+
isLogin: true
100+
})
107101

102+
},
103+
fail: (res) => {
104+
console.log(res)
108105

109106

110-
/**
111-
* 生命周期函数--监听页面加载
112-
*/
113-
onLoad(options) {
114-
let result = utils.calcuWeek()
115-
let date = utils.getThisWeekDates()
107+
Dialog.alert({
108+
title: '提示',
109+
message: '请先授权登录',
110+
}).then(() => {
111+
112+
if (!this.data.isLogin) {
113+
wx.navigateTo({
114+
//url: '/pages/authorize/authorize',
115+
url: '/pages/login/login'
116+
})
117+
118+
}
119+
120+
121+
})
122+
123+
}
124+
})
125+
let result = utils.getCurrentWeekday()
126+
127+
let date = utils.getWeekDates(result.week)
116128
this.setData({
117129
result: result,
118130
date: date,
119-
selectWeek:result.week
131+
selectWeek: result.week
120132
})
121133
wx.getStorage({
122134
key: "kcb",
@@ -138,8 +150,18 @@ Page({
138150
})
139151

140152

141-
}
153+
},
154+
142155
})
156+
},
157+
158+
159+
/**
160+
* 生命周期函数--监听页面加载
161+
*/
162+
onLoad(options) {
163+
this.isLogin()
164+
143165

144166

145167
},
@@ -155,15 +177,24 @@ Page({
155177
* 生命周期函数--监听页面显示
156178
*/
157179
onShow() {
180+
Dialog.close()
181+
182+
if (!this.data.isLogin) {
183+
this.isLogin()
184+
} else {
185+
186+
}
158187

159188
},
160189

161190
/**
162191
* 生命周期函数--监听页面隐藏
163192
*/
164193
onHide() {
194+
console.log("hide")
165195

166196
},
197+
167198

168199
/**
169200
* 生命周期函数--监听页面卸载

‎pages/course/course.wxml

+41-38
Original file line numberDiff line numberDiff line change
@@ -15,75 +15,78 @@
1515
<text class="text-black text-lg">第 {{selectWeek}}周 </text>
1616
<text class="cuIcon-unfold text-black margin-left-xs"></text>
1717
</view>
18-
<text class=" backPage cuIcon-back text-black" bindtap="BackPage"></text>
18+
<!-- <text class=" backPage cuIcon-back text-black" bindtap="BackPage"></text> -->
1919
</view>
2020
<!-- <text class="icon-add settings text-black" style="top:{{statusBar}}px;line-height:{{customBar-statusBar}}px;height:{{customBar-statusBar}}px;transform:rotate({{showSetting?135:0}}deg)" bindtap='listDisplay'>
2121
</text> -->
2222
</view>
2323
</view>
2424

2525
<view class="top">
26-
<!-- <view wx:for="{{['一','二','三','四','五','六','日']}}" class="top-text" wx:for-item="item" wx:for-index="index" style="background-color:{{index === result.day-1 ? '#1380ff' : '#fbfbfb'}}">
26+
<!-- <view wx:for="{{['一','二','三','四','五','六','日']}}" class="top-text" wx:for-item="item" wx:for-index="index" style="background-color:{{index === result.day-1 ? '#1380ff' : '#fbfbfb'}}">
2727
周{{item}}
2828
</view> -->
2929

30-
<view wx:for="{{date}}" class="top-text" wx:for-item="item" wx:for-index="index" style="background-color:{{(index === result.day-1&&selectWeek==result.week) ? '#1380ff' : '#fbfbfb'}}; color:{{(index === result.day-1&&selectWeek==result.week) ? 'white' : 'black'}}">
31-
<view>
32-
<view>{{item.week}}</view>
33-
<view style="color:{{(index === result.day-1&&selectWeek==result.week) ? 'white' : '#95a5a6'}} ">{{item.date}}</view>
34-
</view>
35-
36-
</view>
30+
<view wx:for="{{date}}" class="top-text" wx:for-item="item" wx:for-index="index" style="background-color:{{(index === result.day&&selectWeek==result.week) ? '#1380ff' : '#fbfbfb'}}; color:{{(index === result.day&&selectWeek==result.week)? 'white' : 'black'}}">
31+
<view>
32+
<view>{{item.week}}</view>
33+
<view style="color:{{(index === result.day&&selectWeek==result.week)? 'white' : '#95a5a6'}} ">{{item.date}}</view>
34+
</view>
35+
36+
</view>
3737

3838

3939

4040
</view>
4141

4242
<scroll-view scroll-y="true" class="scroll">
43-
<view style="height:1200rpx;width:730rpx;display:flex;">
44-
<view style="background-color:#fbfbfb;color:black;">
45-
<view wx:for="{{[1,2,3,4,5,6,7,8,9,10,11]}}" class="left">
46-
{{item}}
47-
</view>
48-
</view>
49-
<view wx:for="{{[1,2,3,4,5,6,7,8,9,10,11]}}">
50-
<view style="width:750rpx;margin-top:{{(index+1)*100}}rpx; position: absolute;border-bottom:1rpx solid {{index==3?'#f6bec8':'lightgray'}};">
51-
</view>
52-
</view>
53-
54-
<!--课表-->
55-
<view wx:for="{{kcb}}">
56-
<view class="flex-item kcb-item" bindtap="clickClass" data-statu="open" data-index="{{item}}" style="margin-left:{{(item.XQ-1)*100}}rpx;margin-top:{{(item.skjc-1)*100+5}}rpx;height:{{item.skcd*100-5}}rpx;background-color:{{colorArrays[index%8]}}">
57-
<view class="smalltext">{{item.KCMC+'@'+item.JASMC}}</view>
58-
</view>
59-
</view>
43+
<view style="height:1200rpx;width:730rpx;display:flex;">
44+
<view style="background-color:#fbfbfb;color:black;">
45+
<view wx:for="{{[1,2,3,4,5,6,7,8,9,10,11]}}" class="left">
46+
{{item}}
47+
</view>
48+
</view>
49+
<view wx:for="{{[1,2,3,4,5,6,7,8,9,10,11]}}">
50+
<view style="width:750rpx;margin-top:{{(index+1)*100}}rpx; position: absolute;border-bottom:1rpx solid {{index==3?'#f6bec8':'lightgray'}};">
51+
</view>
52+
</view>
53+
54+
<!--课表-->
55+
<view wx:for="{{kcb}}">
56+
<view class="flex-item kcb-item" bindtap="clickClass" data-statu="open" data-index="{{item}}" style="margin-left:{{(item.XQ-1)*100}}rpx;margin-top:{{(item.skjc-1)*100+5}}rpx;height:{{item.skcd*100-5}}rpx;background-color:{{colorArrays[index%8]}}">
57+
<view class="smalltext">{{item.KCMC+'@'+item.JASMC}}</view>
58+
</view>
6059
</view>
60+
</view>
6161
</scroll-view>
6262

6363

6464
<van-popup show="{{showWeekList}}" bind:close="hideWeekList" position="bottom" round>
65-
<view class="week-list__popup">
66-
<view class="text-center padding text-lg">切换周数</view>
67-
<view class="week-list">
68-
<view bindtap="selectWeek" data-index="{{index}}" wx:for="{{20}}" wx:key="*this" class="week-item {{result.week == item + 1 ? 'this-week' : ''}} {{selectWeek == item + 1 ? 'active' : ''}}">
69-
<block wx:if="{{result.week == item + 1}}">本周</block>
70-
<block wx:else>{{item < 9 ? 0 : '' }}{{item + 1}}</block>
71-
</view>
65+
<view class="week-list__popup">
66+
<view class="text-center padding text-lg">切换周数</view>
67+
<view class="week-list">
68+
<view bindtap="selectWeek" data-index="{{index}}" wx:for="{{20}}" wx:key="*this" class="week-item {{result.week == item + 1 ? 'this-week' : ''}} {{selectWeek == item + 1 ? 'active' : ''}}">
69+
<block wx:if="{{result.week == item + 1}}">本周</block>
70+
<block wx:else>{{item < 9 ? 0 : '' }}{{item + 1}}</block>
7271
</view>
7372
</view>
73+
</view>
7474
</van-popup>
7575

76-
<van-popup closeable round
77-
custom-style="width:60%" show="{{ classShow }}" bind:close="onClassClose" >
76+
<van-popup closeable round custom-style="width:60%" show="{{ classShow }}" bind:close="onClassClose">
7877
<view style="margin-left: 30rpx;">
79-
<view style="text-align: left; margin-top: 70rpx; font-weight: bold;"><van-icon name="location" />{{currentClass.KCMC}}</view>
78+
<view style="text-align: left; margin-top: 70rpx; font-weight: bold;">
79+
<van-icon name="location" />{{currentClass.KCMC}}
80+
</view>
8081
<view style="text-align: left; margin-top: 20rpx; "><text style="font-weight: bold;">老师:</text>{{currentClass.JSXM}}</view>
8182
<view style="text-align: left; margin-top: 20rpx; "><text style="font-weight: bold;">教室:</text>{{currentClass.JASMC}}</view>
8283
<view style="text-align: left; margin-top: 20rpx; "><text style="font-weight: bold;">上课时间:</text>{{currentClass.JSJCDM}}</view>
8384
<view style="text-align: left; margin-top: 20rpx; margin-bottom: 50rpx; "><text style="font-weight: bold;">上课方式:</text>{{currentClass.SKFSDM_DISPLAY}}</view>
85+
</view>
8486

8587

86-
</view>
88+
</van-popup>
8789

90+
<!-- 在页面内添加对应的节点 -->
91+
<van-dialog id="van-dialog" />
8892

89-
</van-popup>

‎pages/course/course.wxss

+1
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ page{
4242
justify-content: center;
4343
display: flex;
4444
align-items: center;
45+
border-radius: 10rpx;
4546
}
4647

4748
.scroll {

‎pages/edit/edit_1.js

-662
This file was deleted.

‎pages/edit/edit_1.wxml

-67
This file was deleted.

‎pages/index/index.js

+40-9
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ Page({
2626
type: 'heavy'
2727

2828
})
29-
wx.navigateTo({
30-
url: '/pages/course/course',
29+
wx.switchTab({
30+
url: '/pages/course/course',
3131
})
3232
},
3333
bindxdu() {
@@ -128,7 +128,7 @@ Page({
128128
* 生命周期函数--监听页面显示
129129
*/
130130
onShow: function () {
131-
let result = utils.calcuWeek()
131+
let result = utils.getCurrentWeekday()
132132
this.setData({
133133
result:"第"+result.week+"周/"+utils.getWeedDay(result.day)
134134
})
@@ -137,9 +137,10 @@ Page({
137137
key: "token",
138138
success: (res) => {
139139
this.setData({
140-
token: res.data
140+
token: res.data,
141141
// userInfo: res.data
142142
})
143+
143144
}
144145
})
145146
wx.getStorage({
@@ -149,25 +150,55 @@ Page({
149150
let kcb=[]
150151
for (let index = 0; index < array.length; index++) {
151152
const element = array[index];
152-
if(element.XQ==result.day&&utils.checkWeekRange(element.ZCMC,result.week)){
153+
if(element.XQ==result.day+1&&utils.checkWeekRange(element.ZCMC,result.week)){
153154
kcb.push(element)
154155
}
155156

156157
}
157-
console.log(kcb)
158+
158159
kcb = utils.getEveryDaySchedul(kcb)
159-
console.log(kcb)
160+
160161
this.setData({
161162
kcb: kcb
162-
163-
164163
// userInfo: res.data
165164
})
166165

167166

168167
}
169168
})
170169

170+
// wx.getStorage({
171+
// key:"cookie",
172+
// success:(res)=>{
173+
// let cookie = res.data
174+
// console.log(cookie)
175+
// wx.request({
176+
// url: 'https://yjspt.xidian.edu.cn/gsapp/sys/wdkbapp/modules/xskcb/xspkjgcx.do',
177+
// method:'POST',
178+
// header:{
179+
// cookie:cookie
180+
// },
181+
182+
// data:{
183+
// "XNXQDM":"20231",
184+
// "*order":"-ZCBH"
185+
// },
186+
187+
// success:(res)=>{
188+
// console.log(res)
189+
// },
190+
// fail:(res)=>{
191+
// console.log(res)
192+
// }
193+
// })
194+
// }
195+
196+
// })
197+
198+
199+
200+
201+
171202

172203

173204
},

‎pages/index/index.wxml

-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
<my-swiper list="{{swiperList}}" bind:swiperClick="articleClick" />
1212
</view>
1313

14-
1514
<view style="width: 95%; margin:30rpx auto;">
1615
<van-cell-group>
1716
<van-cell size="large" icon="bars" title="今日课程" border="{{false}}" value="{{result}}">

‎pages/index/index_1.js

-157
This file was deleted.

‎pages/index/index_1.wxml

-42
This file was deleted.

‎pages/index/index_1.wxss

-7
This file was deleted.

‎pages/login/login.json

+6-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
{
2-
"navigationStyle": "default",
32
"navigationBarTitleText": "登录",
4-
"navigationBarBackgroundColor": "#7acfa6",
3+
"navigationStyle":"default",
54
"enablePullDownRefresh": false,
6-
"disableScroll": true
5+
"disableScroll": true,
6+
"navigationBarBackgroundColor": "#4994c4",
7+
"usingComponents": {
8+
"cu-custom": "/colorui/components/cu-custom"
9+
}
710
}

‎pages/login/login.wxml

+7-42
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<!--login.wxml-->
2+
23
<view class="container">
34
<view class="remind-box" wx:if="{{remind}}">
45
<image class="remind-img" src="https://upload-images.jianshu.io/upload_images/4697920-3401f7949a9e8b5c.gif?imageMogr2/auto-orient/strip"></image>
@@ -25,53 +26,15 @@
2526
<text class="input-label">密码</text>
2627
<input password="true" cursor-spacing="30" id="passwd" placeholder="密码" bindinput="passwdInput" bindfocus="inputFocus" bindblur="inputBlur" confirm-type="next" />
2728
</view>
28-
<!-- <view class="input-group {{vcode_focus ? 'active' : ''}}">
29-
<text class="input-label">验证码</text>
30-
<input value="{{vcode}}" cursor-spacing="30" id="vcode" bindinput="vcodeInput" bindfocus="inputFocus"
31-
bindblur="inputBlur" placeholder="输入右侧验证码" maxlength="4" confirm-type="done" />
32-
<image src="{{vcodeUrl}}" alt="教务关闭" style="width:90px;height:25px;" bindtap="getCookie" />
33-
</view> -->
34-
<!-- <view class="login-help">
35-
<view class="text-blue" bindtap="showHelp">老师亦可通过教务账号密码登录</view>
36-
<view>
37-
38-
<text class="line-blue light" bindtap="showHelp">帮助</text>
39-
<text class="cuIcon-questionfill line-blue light"></text>
40-
</view>
41-
</view> -->
29+
4230
</form>
43-
<!-- <button class="confirm-btn" bindtap="getUserInfo">
44-
<text>登 录</text>
45-
</button> -->
31+
4632
<button class="confirm-btn" bindtap="xdulogin">
4733
<text>登 录</text>
4834
</button>
4935
</view>
5036

51-
<view class="help" id="help" wx:if="{{help_status}}" bindtap="tapHelp">
52-
<view class="box">
53-
<view class="box-hd">
54-
<text class="box-title">帮助</text>
55-
<image class="box-close" src="/images/close.png" bindtap="hideHelp"></image>
56-
</view>
57-
<view class="box-bd">
58-
<view class="help-q">1、账号和密码是什么?</view>
59-
<view class="help-a">
60-
<text>账号:账号就是你的学号,老师请输入教务系统账号。</text>
61-
<text>密码:您设定的教务系统的登录密码。</text>
62-
</view>
63-
<view class="help-q">2、忘记密码?</view>
64-
<view class="help-a">
65-
<!-- <text bindtap="showResetModal" style="color:#8E54EC;">点击这里,重置教务系统密码。重置后教务系统密码也同步被修改。</text> -->
66-
<view>忘记密码请重置找回教务系统密码。找回教务系统密码后使用教务密码登录即可。<text bindtap="showDoc" style="color:#8E54EC;">(找回教务密码文档)</text></view>
67-
</view>
68-
<view class="help-q">3、大一新生?暂时还没有学号😥</view>
69-
<view class="help-a">
70-
<text>请耐心等待教务部门注册学籍,办理学生证,然后你就有学号啦。(不要企图用高考考生号登录成功)</text>
71-
</view>
72-
</view>
73-
</view>
74-
</view>
37+
7538

7639
</view>
7740
</block>
@@ -80,4 +43,6 @@
8043

8144
<van-toast id="van-toast" />
8245
<!-- 在页面内添加对应的节点 -->
83-
<van-notify id="van-notify" />
46+
<van-notify id="van-notify" />
47+
<!-- 在页面内添加对应的节点 -->
48+
<van-dialog id="van-dialog" />

‎pages/login/login.wxss

+5-5
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
/**login.wxss**/
33
@import "../../colorui/icon.wxss";
44
.container {
5-
background: #7acfa6;
5+
background: #4994c4;
66
align-items: stretch;
77
padding: 0;
88
height: 100%;
@@ -130,7 +130,7 @@ form {
130130
transition: all .25s ease-in-out;
131131
}
132132
.input-group.active {
133-
border: 2px solid #7acfa6;
133+
border: 2px solid #4994c4;
134134
}
135135

136136
.input-label {
@@ -171,7 +171,7 @@ form {
171171
font-size: 13pt;
172172
line-height: 85rpx;
173173
height: 85rpx;
174-
background: #7acfa6;
174+
background:#4994c4;
175175
color: #fff;
176176
text-align: center;
177177
border-radius: 5px;
@@ -303,9 +303,9 @@ page{
303303
font-size: 9pt;
304304
padding: 5rpx 20rpx;
305305
text-align: center;
306-
background-color: #7acfa6;
306+
background-color: #4994c4;
307307
border-radius: 3px;
308-
border-bottom: 2px solid #4fc08d;
308+
border-bottom: 2px solid #4994c4;
309309
color: #fff;
310310
}
311311

‎pages/topic/topic.wxml

+1-1
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@
7878

7979
</van-tabs>
8080

81-
<view bindtap="addTopicBtn" style="width: 120rpx; height: 120rpx;position: fixed;bottom: 50rpx;right: 20rpx;">
81+
<view wx:if="{{token!='1111111111'}}" bindtap="addTopicBtn" style="width: 120rpx; height: 120rpx;position: fixed;bottom: 50rpx;right: 20rpx;">
8282
<image style="width: 90rpx; height: 90rpx;" src="/assets/images/add.png" />
8383
</view>
8484
<van-toast id="van-toast" />

‎pages/user/user.js

+1
Original file line numberDiff line numberDiff line change
@@ -297,6 +297,7 @@ Page({
297297
* 生命周期函数--监听页面显示
298298
*/
299299
onShow() {
300+
Dialog.close()
300301
if(this.token==null){
301302
this.validLogin()
302303
}else{

‎utils/utils.js

+35-178
Original file line numberDiff line numberDiff line change
@@ -1,70 +1,43 @@
1-
function calculateWeekday(dateString) {
2-
var date = new Date(dateString);
3-
var day = date.getDay(); // 星期几(0-6,0代表星期日)
4-
var week = 1; // 初始化为第一周
5-
6-
// 获取当年的第一天
7-
var firstDayOfYear = new Date(date.getFullYear(), 0, 1);
8-
var firstWeekDay = firstDayOfYear.getDay(); // 当年第一天是星期几
9-
10-
// 计算date和当年第一天之间的天数差
11-
var diff = Math.ceil((date - firstDayOfYear) / (24 * 60 * 60 * 1000));
12-
13-
// 调整计算方式以适应设定的第一周起始日
14-
diff = diff + (7 - firstWeekDay + 1); // 第一周的起始日是设定的日期
15-
16-
// 计算周数
17-
week = Math.ceil(diff / 7);
18-
19-
// 将星期几转换为中文
20-
// var weekdayMap = {
21-
// 0: '星期日',
22-
// 1: '星期一',
23-
// 2: '星期二',
24-
// 3: '星期三',
25-
// 4: '星期四',
26-
// 5: '星期五',
27-
// 6: '星期六'
28-
// };
29-
30-
return {
31-
week: week - 37,
32-
day: day
33-
};
34-
}
35-
function calcuWeek() {
36-
var startDate = new Date(2023, 8, 4); // 设定的第一周起始日
37-
var today = new Date(); // 当前日期(月份从0开始,所以9表示十月份)
38-
var result = calculateWeekday(today);
39-
return result
401

2+
//获取当前周日
3+
function getCurrentWeekday() {
4+
// 2023年9月4号的日期
5+
const start = new Date(2023, 8, 4); // JavaScript的月份是从0开始计数的,所以8代表9月
6+
const today = new Date();
7+
8+
// 计算两个日期之间的差值(毫秒)
9+
const diff = today.getTime() - start.getTime();
10+
11+
// 将差值转换为天数
12+
const diffDays = Math.floor(diff / (1000 * 3600 * 24));
13+
14+
// 计算当前的周数和星期数
15+
const week = Math.floor(diffDays / 7) + 1;
16+
const day = diffDays % 7;
17+
18+
// 返回结果
19+
return {day: day, week: week};
4120
}
21+
//根据周获取该周日
4222
function getWeekDates(weekNumber) {
4323
var startDate = new Date(2023, 8, 4); // 设定的第一周起始日
4424
var currentDate = new Date(startDate.getTime());
4525
currentDate.setDate(currentDate.getDate() + (weekNumber - 1) * 7); // 计算指定周数的起始日期
46-
4726
var weekDates = [];
48-
27+
var weekdays = ['周一', '周二', '周三', '周四', '周五', '周六','周日'];
4928
for (var i = 0; i < 7; i++) {
5029
var date = new Date(currentDate.getTime() + i * 24 * 60 * 60 * 1000);
5130
var month = ("0" + (date.getMonth() + 1)).slice(-2); // 月份从0开始,需要加1;使用slice(-2)确保月份有两位数
5231
var day = ("0" + date.getDate()).slice(-2); // 使用slice(-2)确保日期有两位数
5332
var formattedDate = month + "-" + day;
54-
var weekday = getWeekday2(i); // 获取星期几
33+
var weekday = weekdays[i]; // 获取星期几
5534
weekDates.push({ date: formattedDate, week: weekday });
5635
}
5736

5837
return weekDates;
5938
}
6039

61-
// 获取星期几
62-
function getWeekday2(dayIndex) {
63-
var weekdays = ['周日', '周一', '周二', '周三', '周四', '周五', '周六'];
64-
return weekdays[dayIndex];
65-
}
66-
67-
40+
//获取每天课程表
6841
function getEveryDaySchedul(result) {
6942
const timetable = [
7043
{ start: '08:30', end: '09:15' },
@@ -122,7 +95,7 @@ function getEveryDaySchedul(result) {
12295
return a
12396

12497
}
125-
98+
//获取一周课程表
12699
function getWeekSchedul(result){
127100
const timetable = [
128101
{ start: '08:30', end: '09:15' },
@@ -188,22 +161,24 @@ return a
188161

189162

190163
}
164+
//转换星期几
191165
function getWeedDay(num) {
192166
//将星期几转换为中文
193167
var weekdayMap = {
194-
0: '星期日',
195-
1: '星期一',
196-
2: '星期二',
197-
3: '星期三',
198-
4: '星期四',
199-
5: '星期五',
200-
6: '星期六'
168+
169+
0: '星期一',
170+
1: '星期二',
171+
2: '星期三',
172+
3: '星期四',
173+
4: '星期五',
174+
5: '星期六',
175+
6: '星期日'
176+
201177
};
202178
return weekdayMap[num]
203179

204180
}
205-
206-
181+
//判断范围
207182
function checkWeekRange(weekString, input) {
208183
// 判断字符串是否包含逗号
209184
if (weekString.includes(',')) {
@@ -228,129 +203,11 @@ function checkWeekRange(weekString, input) {
228203

229204
return false;
230205
}
231-
function transformCourses(courses) {
232-
const timetable = [
233-
{ start: '08:30', end: '09:15' },
234-
{ start: '09:20', end: '10:05' },
235-
{ start: '10:25', end: '11:10' },
236-
{ start: '11:15', end: '12:00' },
237-
{ start: '14:00', end: '14:45' },
238-
{ start: '14:50', end: '15:35' },
239-
{ start: '15:55', end: '16:40' },
240-
{ start: '16:45', end: '17:30' },
241-
{ start: '19:00', end: '19:45' },
242-
{ start: '19:50', end: '20:35' },
243-
{ start: '20:40', end: '21:25' }
244-
];
245-
246-
// 对课程列表按照JSJCDM升序排序
247-
courses.sort((a, b) => a.JSJCDM - b.JSJCDM);
248-
249-
const mergedCourses = [];
250-
251-
for (const course of courses) {
252-
const start = timetable[course.JSJCDM - 1].start;
253-
const end = timetable[course.JSJCDM - 1].end;
254-
255-
const existingCourse = mergedCourses.find(
256-
(c) => c.XQ === course.XQ && c.KCMC === course.KCMC && c.ZCMC === course.ZCMC && c.JASMC === course.JASMC
257-
);
258-
259-
if (existingCourse) {
260-
existingCourse.JSJCDM.end = end;
261-
existingCourse.JSJCDM.skjd += 1;
262-
} else {
263-
mergedCourses.push({
264-
XQ: course.XQ,
265-
KCMC: course.KCMC,
266-
ZCMC: course.ZCMC,
267-
JASMC: course.JASMC,
268-
JSJCDM: { start, end, skjc: course.JSJCDM, skjd: 1 }
269-
});
270-
}
271-
}
272-
273-
return mergedCourses.map((course) => ({
274-
...course,
275-
JSJCDM: `${course.JSJCDM.start}~${course.JSJCDM.end}`,
276-
skjc: course.JSJCDM.skjc,
277-
skjd: course.JSJCDM.skjd
278-
}));
279-
}
280-
function convertJSJCDM(courses) {
281-
const timetable = [
282-
{ start: '08:30', end: '09:15' },
283-
{ start: '09:20', end: '10:05' },
284-
{ start: '10:25', end: '11:10' },
285-
{ start: '11:15', end: '12:00' },
286-
{ start: '14:00', end: '14:45' },
287-
{ start: '14:50', end: '15:35' },
288-
{ start: '15:55', end: '16:40' },
289-
{ start: '16:45', end: '17:30' },
290-
{ start: '19:00', end: '19:45' },
291-
{ start: '19:50', end: '20:35' },
292-
{ start: '20:40', end: '21:25' }
293-
];
294-
295-
const mergedCourses = [];
296-
297-
for (const course of courses) {
298-
const start = timetable[course.JSJCDM - 1].start;
299-
const end = timetable[course.JSJCDM - 1].end;
300-
301-
const existingCourse = mergedCourses.find(
302-
(c) => c.XQ === course.XQ && c.KCMC === course.KCMC && c.ZCMC === course.ZCMC && c.JASMC === course.JASMC
303-
);
304-
305-
if (existingCourse) {
306-
existingCourse.JSJCDM.end = end;
307-
} else {
308-
mergedCourses.push({
309-
XQ: course.XQ,
310-
KCMC: course.KCMC,
311-
ZCMC: course.ZCMC,
312-
JASMC: course.JASMC,
313-
JSJCDM: { start, end }
314-
});
315-
}
316-
}
317-
318-
return mergedCourses.map((course) => ({
319-
...course,
320-
JSJCDM: `${course.JSJCDM.start}~${course.JSJCDM.end}`
321-
}));
322-
}
323-
function getThisWeekDates() {
324-
var currentDate = new Date(); // 获取当前日期
325-
var currentDay = currentDate.getDay(); // 获取当前是星期几
326-
var daysToAdd = 1 - currentDay; // 计算需要添加的天数,使得下一个周一
327-
currentDate.setDate(currentDate.getDate() + daysToAdd); // 调整日期到下一个周一
328-
329-
var weekDates = [];
330-
var daysOfWeek = ['日', '一', '二', '三', '四', '五', '六'];
331-
for (var i = 0; i < 7; i++) {
332-
var month = currentDate.getMonth() + 1; // 注意月份是从0开始计数的,所以需要加1
333-
var day = currentDate.getDate();
334-
var formattedDate = (month < 10 ? '0' + month : month) + '-' + (day < 10 ? '0' + day : day);
335-
var week = '周' + daysOfWeek[currentDate.getDay()];
336-
var dateObj = {
337-
week: week,
338-
date: formattedDate
339-
};
340-
weekDates.push(dateObj);
341-
currentDate.setDate(currentDate.getDate() + 1); // 增加一天
342-
}
343-
344-
return weekDates;
345-
}
346206

347207
module.exports = {
348-
calcuWeek: calcuWeek,
208+
getCurrentWeekday:getCurrentWeekday,
349209
checkWeekRange: checkWeekRange,
350-
convertJSJCDM: convertJSJCDM,
351210
getWeedDay: getWeedDay,
352-
transformCourses: transformCourses,
353-
getThisWeekDates: getThisWeekDates,
354211
getEveryDaySchedul:getEveryDaySchedul,
355212
getWeekSchedul:getWeekSchedul,
356213
getWeekDates:getWeekDates

0 commit comments

Comments
 (0)
Please sign in to comment.