Browse Source

feat(member): 添加获取课程头日期功能并优化课表页面

- 在 member.js 中新增 getDate 方法,用于获取课程头日期
- 修改 config.js,更新 API 地址和图片域名
- 重构 timetable 页面,优化课程列表展示和签到功能
- 移除日期列表相关代码,改为使用新的课程头日期数据
master
liutong 2 years ago
parent
commit
a1bae61e34
  1. 8
      api/member.js
  2. 8
      common/config.js
  3. 112
      pages/student/timetable/index.vue

8
api/member.js

@ -50,4 +50,12 @@ export default {
return res;
})
},
//获取课程头日期
getDate(data) {
let url = '/member/get_date'
return http.get(url, data).then(res => {
return res;
})
},
}

8
common/config.js

@ -1,10 +1,10 @@
// 线上地址
// const Api_url='http://146.56.228.75:20021/api'
// const img_domian = 'http://146.56.228.75:20021/'
const Api_url='http://146.56.228.75:20021/api'
const img_domian = 'http://146.56.228.75:20021/'
//本地测试地址
const Api_url='http://zhjw.cc/api'
const img_domian = 'http://zhjw.cc/'
// const Api_url='http://zhjw.cc/api'
// const img_domian = 'http://zhjw.cc/'
const IsDemo = false

112
pages/student/timetable/index.vue

@ -10,11 +10,11 @@
<view class="section_1">
<view class="ul">
<view class="li" v-for="(v,k) in dateList" :key="k" @click="selectDate(v.date)">
<text>{{v.name}}</text>
<text>{{v.week}}</text>
<text :class="[filteredData.schedule_date == v.date ? 'today':'']">{{today == v.date ? '今':v.today}}</text>
<text :class="[today == v.date ?'select_plan':'']"></text>
<text :class="[v.status == 2 ?'select_plan':'']"></text>
</view>
</view>
</view>
@ -40,15 +40,14 @@
<view v-for="(v,k) in tableList" :key="k" class="li" @click="openViewCourseInfo({id:v.id})">
<view class="top_box">
<view class="center_box">
<view>班级:{{v.name}}</view>
<view>时间:{{v.start_date}} - {{$util.formatToDateTime(v.end_date,'H:i')}}</view>
<view>课室:{{v.address}}
</view>
<view>课程:{{v.courses_name}}
</view>
<view>班级:{{v.classes_name}}</view>
<view>时间:{{v.date}}</view>
<view>课室:{{v.address}}</view>
<view>课程:{{v.courses_name}}</view>
</view>
<view class="right_box">
<view class="tag" :style="{background: v.status === 1 ? '#1cd188' : v.status === 2 ? '#fad24e' : '#ff4d4f'}">
<!-- v.status|1=未开始,2=进行中,3=已结束-->
<view class="tag" :style="{background: v.status == 1 ? '#1cd188' : v.status == 2 ? '#fad24e' : '#ff4d4f'}">
{{ v.status === 1 ? '未开始' : v.status === 2 ? '上课中' : '已结束' }}
</view>
<!-- <view class="tag" style="background:#1cd188;">待上课</view>-->
@ -56,12 +55,12 @@
</view>
<view class="bottom_box">
<view class="hint">
已签到学生 ({{v.has_sign_count }}/{{v.max_students }})
已签到学生 ({{v.sign_list.length }}/{{v.max_students.split(',').length }})
</view>
<view class="list_box">
<view class="list">
<view class="itme" v-for="index in parseInt(v.has_sign_count) || 0" :key="index">
<image src="http://www.firstui.cn:4000/vipdoc/img/img_logo.png"></image>
<view class="itme" v-for="(item,index) in v.sign_list || 0" :key="index">
<image :src="$util.img(item.header)"></image>
</view>
</view>
<view class="btn" @click="openViewTimetableInfo(v)">
@ -114,7 +113,10 @@ export default {
dateList:[]//日期列表
}
},
onLoad() {
onLoad(options) {
if(options.venue_id){
this.filteredData.venue_id = options.venue_id
}
},
onShow() {
this.init()//初始化
@ -123,7 +125,6 @@ export default {
async onPullDownRefresh() {
//重置为第一页
let schedule_date = this.filteredData.schedule_date
console.log('eee',schedule_date)
await this.loadData()
this.filteredData.schedule_date = schedule_date
await this.getList()
@ -132,14 +133,42 @@ export default {
methods: {
//初始化
async init(){
await this.getDate()
await this.getThisDate()
await this.getHeadDate()
await this.getList()
await this.getDateList(); // 获取日期列表
console.log(1111,this.dateList)
// await this.getDateList(); // 获取日期列表
},
//获取课程头日期
async getHeadDate() {
let res = await memberApi.getDate()
if (res.code != 1){
//提示
uni.showToast({
title: res.msg,
icon: 'none',
})
return
}
this.dateList = []
res.data.forEach((v,k)=>{
let today = v.date.split("-")[2]; // "09"
this.dateList.push({
date: v.date,
status: v.status,//1是正常 2请假
week: v.week,
today: today,
})
})
console.log('xxx',res)
},
//获取当前日期
async getDate() {
async getThisDate() {
let date = new Date();
let year = date.getFullYear();
let month = String(date.getMonth() + 1).padStart(2, '0'); // 月份前补零
@ -152,39 +181,6 @@ export default {
this.today = res;
this.filteredData.schedule_date = res;
},
// 获取日期列表
async getDateList() {
const days = ['周日', '周一', '周二', '周三', '周四', '周五', '周六'];
const dateList = [];
const today = new Date(); // 获取当前日期
// 获取前2天和后4天的日期
for (let i = -2; i <= 4; i++) {
const date = new Date(today);
date.setDate(today.getDate() + i); // 计算日期
let dayOfWeek = days[date.getDay()]; // 获取星期几
let formattedDateArr = this.formatDate(date); // 格式化日期
let formattedDate = `${formattedDateArr[0]}-${formattedDateArr[1]}-${formattedDateArr[2]}`; // 格式化日期
dateList.push({
name: dayOfWeek,
date: formattedDate,
today: formattedDateArr[2],//日
});
}
this.dateList = dateList
},
// 格式化日期为 YYYY-MM-DD
formatDate(date) {
const year = date.getFullYear();
const month = String(date.getMonth() + 1).padStart(2, '0');
const day = String(date.getDate()).padStart(2, '0');
return [
year, month, day
]
},
//加载更过(下一页)
loadMoreData() {
@ -197,13 +193,10 @@ export default {
//重置为第一页
async loadData() {
this.isReachedBottom = false; // 重置状态,以便下次触发加载更多
this.filteredData = {
page:1,//当前页码
limit:10,//每页返回数据条数
total:10,//数据总条数
schedule_date:'',//日期
venue_id:'',//场地id
}
this.filteredData.page = 1//当前页码
this.filteredData.limit = 10//每页返回数据条数
this.filteredData.total = 10//数据总条数
},
//获取列表
async getList(){
@ -251,8 +244,9 @@ export default {
//打开课表详情页
openViewTimetableInfo(item){
// courses_id=课程id
uni.navigateTo({
url: `/pages/student/timetable/info?id=${item.id}`
url: `/pages/student/timetable/info?id=${item.courses_id}`
})
},
//体育馆列表

Loading…
Cancel
Save