Browse Source

feat(common): 添加时间格式转换工具函数并优化课程列表显示

- 在 common/util.js 中添加 formatToDateTime 函数,用于时间格式转换
- 更新学生端课程列表页面,使用新的时间格式转换函数- 优化课程列表的显示内容和样式,包括班级名称、上课时间、课室等信息
- 根据课程状态动态显示标签颜色和文字
- 修复已签到学生人数显示问题
master
liutong 1 year ago
parent
commit
3b5d747033
  1. 33
      common/util.js
  2. 25
      pages/student/timetable/index.vue

33
common/util.js

@ -140,6 +140,36 @@ function getDefaultImage() {
return defaultImg;
}
/**
* 时间格式转换
* @param dateTime 2024-05-01 01:10:21
* @param fmt 可选参数[Y-m-d H:i:s,Y-m-d,Y-m-d H,Y-m-d H:i,H:i:s,H:i]
* @returns {string}
*/
function formatToDateTime(dateTime, fmt = 'Y-m-d H:i:s') {
if (!dateTime) return ''; // 如果为空,返回空字符串
const date = new Date(dateTime); // 将字符串转换为 Date 对象
// 定义格式化规则
const o = {
'Y+': date.getFullYear(), // 年
'm+': String(date.getMonth() + 1).padStart(2, '0'), // 月
'd+': String(date.getDate()).padStart(2, '0'), // 日
'H+': String(date.getHours()).padStart(2, '0'), // 小时
'i+': String(date.getMinutes()).padStart(2, '0'), // 分钟
's+': String(date.getSeconds()).padStart(2, '0'), // 秒
};
// 替换格式模板中的占位符
for (const k in o) {
if (new RegExp(`(${k})`).test(fmt)) {
fmt = fmt.replace(RegExp.$1, o[k]);
}
}
return fmt;
}
//跳转首页
function openHomeView() {
@ -195,5 +225,6 @@ module.exports = {
formatLocation,
dateUtils,
hexToRgba,
img
img,
formatToDateTime
}

25
pages/student/timetable/index.vue

@ -40,34 +40,27 @@
<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>班级少年班</view>
<view>时间2020-05-25 15:30 - 17:30</view>
<view>课室302
<view>班级{{v.name}}</view>
<view>时间{{v.start_date}} - {{$util.formatToDateTime(v.end_date,'H:i')}}</view>
<view>课室{{v.address}}
</view>
<view>课程篮球少儿课
<view>课程{{v.courses_name}}
</view>
</view>
<view class="right_box">
<view class="tag" style="background:#fad24e;">上课中</view>
<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>-->
</view>
</view>
<view class="bottom_box">
<view class="hint">
已签到学生 (15/34)
已签到学生 ({{v.has_sign_count }}/{{v.max_students }})
</view>
<view class="list_box">
<view class="list">
<view class="itme">
<image src="http://www.firstui.cn:4000/vipdoc/img/img_logo.png"></image>
</view>
<view class="itme">
<image src="http://www.firstui.cn:4000/vipdoc/img/img_logo.png"></image>
</view>
<view class="itme">
<image src="http://www.firstui.cn:4000/vipdoc/img/img_logo.png"></image>
</view>
<view class="itme">
<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>
</view>

Loading…
Cancel
Save