Commit 62f5d469 by chenwq

feat(attendance): 新增考勤明细页面并实现跳转功能

- 创建 attendanceDetail 页面,包含用户信息、汇总数据和日历视图
- 在 attendanceList 页面中实现跳转到明细页面的功能
- 日历组件支持选择日期并显示对应考勤时间
- 使用模拟数据展示页面 UI 效果
1 parent d455f31e
// packageWorkspace/pages/attendanceStatis/attendanceDetail/attendanceDetail.js
const IMG_URL = 'https://img02.glsx.com.cn/weapp/resource/miniprogram/regional-assistant/'
Page({
/**
* 页面的初始数据
*/
data: {
IMG_URL,
detail: {
mobilePhone: "",
name: "",
positionName: "延保驻店销售",
attendanceMonth: "",
totalWorkHours: 0.0,
lateEarlyHours: 0.0,
missingPunchCount: 0,
attendanceDailyInfoDTOs: []
},
formattedMonth: "",
minDate: new Date().getTime(),
maxDate: new Date().getTime(),
selectedDate: '', // YYYY-MM-DD
currentDayInfo: null // { workTime, offWorkTime }
},
/**
* 生命周期函数--监听页面加载
*/
onLoad(options) {
// 模拟从上一页传递或接口获取数据
// 实际场景可能需要根据 options.id 去请求详情接口
// 这里直接使用 Mock 数据展示 UI
this.getDetail();
},
getDetail() {
// 模拟接口返回数据
const mockData = {
mobilePhone: "13800138000",
name: "董天天",
positionName: "延保驻店销售",
attendanceMonth: "2026-01",
totalWorkHours: 7.2,
lateEarlyHours: 0,
missingPunchCount: 0,
attendanceDailyInfoDTOs: [
{ date: "2026-01-01", workTime: "09:00", offWorkTime: "18:00" },
{ date: "2026-01-02", workTime: "08:55", offWorkTime: "18:05" },
{ date: "2026-01-05", workTime: "", offWorkTime: "18:00" }, // 缺卡示例
{ date: "2026-01-06", workTime: "09:00", offWorkTime: "" }, // 缺卡示例
{ date: "2026-01-07", workTime: "", offWorkTime: "" } // 缺卡示例
]
};
// Calculate min and max date based on attendanceMonth
let minDate = new Date().getTime();
let maxDate = new Date().getTime();
let defaultDate = new Date().getTime();
if (mockData.attendanceMonth) {
const parts = mockData.attendanceMonth.split('-');
if (parts.length === 2) {
const year = parseInt(parts[0]);
const month = parseInt(parts[1]);
// minDate: 1st day of the month
minDate = new Date(year, month - 1, 1).getTime();
// maxDate: Last day of the month
maxDate = new Date(year, month, 0).getTime();
// Default to the 5th for demo purposes as per screenshot, or minDate
defaultDate = new Date(year, month - 1, 5).getTime();
// Ensure defaultDate is within range
if (defaultDate < minDate) defaultDate = minDate;
if (defaultDate > maxDate) defaultDate = maxDate;
}
}
this.setData({
detail: mockData,
formattedMonth: this.formatMonth(mockData.attendanceMonth),
minDate,
maxDate,
defaultDate
});
// Initialize selection (simulate selecting the default date)
const dateObj = new Date(defaultDate);
this.handleDateSelect(dateObj);
},
formatMonth(monthStr) {
if (!monthStr) return "";
// 假设 monthStr 格式为 "YYYY-MM"
const parts = monthStr.split('-');
if (parts.length === 2) {
return `${parts[0]}年${parseInt(parts[1])}月`; // parseInt 去掉月份前导0
}
return monthStr;
},
onSelect(event) {
this.handleDateSelect(event.detail);
},
handleDateSelect(date) {
const year = date.getFullYear();
const month = (date.getMonth() + 1).toString().padStart(2, '0');
const day = date.getDate().toString().padStart(2, '0');
const dateStr = `${year}-${month}-${day}`;
// Find info for this date
const dayInfo = this.data.detail.attendanceDailyInfoDTOs.find(item => item.date === dateStr);
this.setData({
selectedDate: dateStr,
currentDayInfo: dayInfo || null
});
}
})
{
"usingComponents": {
"van-icon": "@vant/weapp/icon/index",
"van-calendar": "@vant/weapp/calendar/index"
},
"navigationBarTitleText": "考勤明细"
}
/* packageWorkspace/pages/attendanceStatis/attendanceDetail/attendanceDetail.wxss */
page {
background: #F2F3F7;
}
.card {
background: #FFFFFF;
border-radius: 32rpx;
margin-bottom: 16rpx;
}
.ellipsis {
overflow: hidden;
display: -webkit-box;
-webkit-line-clamp: 1;
-webkit-box-orient: vertical;
word-break: break-all;
}
/* User Card Styles */
.user-card {
display: flex;
align-items: center;
padding: 24rpx 32rpx;
border-radius: 0 0 32rpx 32rpx;
}
.avatar {
width: 76rpx;
height: 76rpx;
border-radius: 50%;
margin-right: 24rpx;
flex-shrink: 0;
}
.name {
font-size: 28rpx;
color: #222222;
margin-bottom: 8rpx;
}
.position {
font-size: 24rpx;
color: #666666;
}
/* Summary Card Styles */
.summary-card {
padding: 24rpx 32rpx;
}
.summary-title {
color: #222222;
font-size: 28rpx;
font-weight: 600;
margin-bottom: 16rpx;
}
.summary-grid {
display: flex;
justify-content: space-between;
}
.grid-item {
flex: 1;
display: flex;
flex-direction: column;
align-items: center;
text-align: center;
padding: 16rpx 28rpx;
}
.value {
color: #222222;
font-size: 40rpx;
font-weight: 600;
line-height: 1;
margin-bottom: 8rpx;
font-family: DINAlternate-Bold, "PingFang SC", sans-serif; /* Use number font if available */
}
.label {
font-size: 24rpx;
color: #666666;
}
/* Calendar Card Styles */
.calendar-card {
padding-bottom: 32rpx;
overflow: hidden; /* Ensure calendar corners are clipped */
}
/* Custom Calendar Header */
.calendar-header {
display: flex;
justify-content: center;
padding: 12rpx 0;
}
.date-pill {
width: 282rpx;
height: 64rpx;
line-height: 64rpx;
border-radius: 40rpx;
text-align: center;
background: #f2f3f5;
color: #222222;
font-size: 28rpx;
}
.calendar {
.van-calendar__header {
box-shadow: none;
}
.van-calendar__selected-day {
background-color: #2C66F7;
color: #FFFFFF;
width: 64rpx;
height: 64rpx;
border-radius: 50%;
}
.van-calendar__day {
padding: 16rpx 0;
}
}
/* Hide default month title inside van-calendar */
.calendar .van-calendar__month-title {
display: none !important;
height: 0 !important;
}
.attendance-time {
margin: 24rpx 32rpx 0;
padding-top: 46rpx;
border-top: 1rpx solid #e6e7eb;
}
.section-title {
font-size: 24rpx;
color: #666666;
margin-bottom: 24rpx;
}
.timeline-item {
position: relative;
display: flex;
align-items: flex-start;
padding-bottom: 48rpx;
}
.timeline-item:last-child {
padding-bottom: 0;
}
.dot {
box-sizing: border-box;
width: 16rpx;
height: 16rpx;
border-radius: 50%;
border: 4rpx solid #35c376;
background-color: #fff;
z-index: 1;
margin-top: 12rpx;
flex-shrink: 0;
}
.dot-green {
border-color: #00B578;
}
.dot-red {
border-color: #FA5151;
}
.line {
position: absolute;
top: 16rpx;
left: 8rpx;
width: 2rpx;
height: 100%;
background-color: #e6eaf0;
z-index: 0;
}
.content {
margin-left: 24rpx;
display: flex;
align-items: baseline;
}
.status-text {
color: #181a1f;
font-size: 28rpx;
margin-right: 24rpx;
}
.text-red {
color: #FA5151;
}
.label-text {
color: #808291;
font-size: 28rpx;
}
<!--packageWorkspace/pages/attendanceStatis/attendanceDetail/attendanceDetail.wxml-->
<view class="container">
<!-- User Info Card -->
<view class="card user-card">
<view class="avatar">
<van-icon name="manager" color="#fff" size="24px" />
</view>
<view class="user-info">
<view class="name">{{detail.name}}</view>
<view class="position">{{detail.positionName}}</view>
</view>
</view>
<!-- Summary Card -->
<view class="card summary-card">
<view class="summary-title">{{formattedMonth}}汇总</view>
<view class="summary-grid">
<view class="grid-item">
<view class="value">{{detail.totalWorkHours}}</view>
<view class="label">出勤工时 (H)</view>
</view>
<view class="grid-item">
<view class="value">{{detail.lateEarlyHours}}</view>
<view class="label">迟到早退 (H)</view>
</view>
<view class="grid-item">
<view class="value">{{detail.missingPunchCount}}</view>
<view class="label">缺卡 (次数)</view>
</view>
</view>
</view>
<!-- Calendar Card -->
<view class="card calendar-card">
<view class="calendar-header">
<view class="date-pill">{{detail.attendanceMonth}}</view>
</view>
<van-calendar
poppable="{{ false }}"
show-confirm="{{ false }}"
show-title="{{ false }}"
show-subtitle="{{ false }}"
show-mark="{{ false }}"
min-date="{{ minDate }}"
max-date="{{ maxDate }}"
default-date="{{ defaultDate }}"
class="calendar"
row-height="32"
bind:select="onSelect"
/>
<!-- Attendance Time Timeline -->
<view class="attendance-time">
<view class="section-title">考勤时间</view>
<!-- Start Work -->
<view class="timeline-item">
<view class="dot {{currentDayInfo.workTime ? 'dot-green' : 'dot-red'}}"></view>
<view class="line"></view>
<view class="content">
<text class="status-text {{currentDayInfo.workTime ? '' : 'text-red'}}">{{currentDayInfo.workTime ? currentDayInfo.workTime : '缺卡'}}</text>
<text class="label-text" wx:if="{{currentDayInfo.workTime}}"> 上班</text>
</view>
</view>
<!-- Off Work -->
<view class="timeline-item">
<view class="dot {{currentDayInfo.offWorkTime ? 'dot-green' : 'dot-red'}}"></view>
<view class="content">
<text class="status-text {{currentDayInfo.offWorkTime ? '' : 'text-red'}}">{{currentDayInfo.offWorkTime ? currentDayInfo.offWorkTime : '缺卡'}}</text>
<text class="label-text" wx:if="{{currentDayInfo.offWorkTime}}"> 下班</text>
</view>
</view>
</view>
</view>
</view>
...@@ -129,8 +129,11 @@ Page({ ...@@ -129,8 +129,11 @@ Page({
* 跳转详情 (如果有) * 跳转详情 (如果有)
*/ */
handleDetail(e) { handleDetail(e) {
const { item } = e.currentTarget.dataset; let { target } = e.currentTarget.dataset;
// TODO: Navigate to detail page wx.navigateTo({
console.log("Navigate to detail", item); url:
"/packageWorkspace/pages/attendanceStatis/attendanceDetail/attendanceDetail?id=" +
target.id,
});
}, },
}); });
...@@ -24,7 +24,7 @@ ...@@ -24,7 +24,7 @@
<view class="empty-box"></view> <view class="empty-box"></view>
<block wx:for="{{ list }}" wx:key="index"> <block wx:for="{{ list }}" wx:key="index">
<block wx:for="{{ item }}" wx:for-item="li" wx:for-index="ind" wx:key="ind"> <block wx:for="{{ item }}" wx:for-item="li" wx:for-index="ind" wx:key="ind">
<view class="item" bindtap="handleDetail" data-item="{{li}}"> <view class="item" bindtap="handleDetail" data-target="{{li}}">
<view class="item-header"> <view class="item-header">
<view class="name ellipsis">{{li.name}}</view> <view class="name ellipsis">{{li.name}}</view>
<view class="date-row"> <view class="date-row">
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!