WXL
2025-12-28 1b736033f6d01b774d58b4c2d7cd2ce8607a44fa
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
<template>
  <div class="attendance-table">
    <div class="table-actions">
      <el-button type="primary" size="small" icon="el-icon-download" @click="exportData">
        导出数据
      </el-button>
      <el-button size="small" icon="el-icon-refresh" @click="$emit('refresh')">
        刷新
      </el-button>
    </div>
 
    <el-table
      :data="tableData"
      border
      v-loading="loading"
      style="width: 100%"
      @sort-change="handleSortChange"
    >
      <el-table-column prop="id" label="ID" width="80" sortable />
      <el-table-column prop="employeeName" label="员工姓名"  sortable />
      <el-table-column prop="date" label="日期"  sortable />
      <el-table-column prop="checkIn" label="签到时间"  />
      <el-table-column prop="checkOut" label="签退时间"  />
      <el-table-column prop="workHours" label="工作时长"  sortable>
        <template #default="scope">
          <el-tag :type="getHoursType(scope.row.workHours)" size="small">
            {{ scope.row.workHours }}h
          </el-tag>
        </template>
      </el-table-column>
      <el-table-column prop="status" label="状态" >
        <template #default="scope">
          <el-tag
            :type="getStatusType(scope.row.status)"
            effect="light"
          >
            {{ scope.row.status }}
          </el-tag>
        </template>
      </el-table-column>
      <el-table-column label="操作" width="150" fixed="right">
        <template #default="scope">
          <el-button
            size="mini"
            type="text"
            @click="handleViewDetail(scope.row)"
            icon="el-icon-view"
          >
            详情
          </el-button>
          <el-button
            size="mini"
            type="text"
            @click="handleEdit(scope.row)"
            icon="el-icon-edit"
          >
            编辑
          </el-button>
        </template>
      </el-table-column>
    </el-table>
 
    <div class="pagination-container">
      <el-pagination
        :current-page="currentPage"
        :page-size="pageSize"
        :total="total"
        layout="total, sizes, prev, pager, next, jumper"
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
      />
    </div>
  </div>
</template>
 
<script>
export default {
  name: 'AttendanceTable',
  props: {
    data: {
      type: Array,
      default: () => []
    },
    loading: {
      type: Boolean,
      default: false
    }
  },
  data() {
    return {
      currentPage: 1,
      pageSize: 10,
      sortProp: '',
      sortOrder: ''
    }
  },
  computed: {
    total() {
      return this.data.length
    },
    tableData() {
      let data = [...this.data]
 
      // 排序处理
      if (this.sortProp) {
        data.sort((a, b) => {
          let aVal = a[this.sortProp]
          let bVal = b[this.sortProp]
 
          if (this.sortOrder === 'ascending') {
            return aVal > bVal ? 1 : -1
          } else {
            return aVal < bVal ? 1 : -1
          }
        })
      }
 
      // 分页处理
      const start = (this.currentPage - 1) * this.pageSize
      const end = start + this.pageSize
      return data.slice(start, end)
    }
  },
  methods: {
    getStatusType(status) {
      const typeMap = {
        '正常': 'success',
        '迟到': 'warning',
        '早退': 'warning',
        '缺勤': 'danger'
      }
      return typeMap[status] || 'info'
    },
 
    getHoursType(hours) {
      const numHours = parseFloat(hours)
      if (numHours >= 8) return 'success'
      if (numHours >= 6) return 'warning'
      return 'danger'
    },
 
    handleViewDetail(row) {
      this.$emit('view-detail', row)
    },
 
    handleEdit(row) {
      this.$message.info(`编辑出勤记录: ${row.employeeName} - ${row.date}`)
    },
 
    exportData() {
      this.$message.success('导出功能开发中')
    },
 
    handleSortChange({ prop, order }) {
      this.sortProp = prop
      this.sortOrder = order
    },
 
    handleSizeChange(size) {
      this.pageSize = size
      this.currentPage = 1
    },
 
    handleCurrentChange(page) {
      this.currentPage = page
    }
  }
}
</script>
 
<style scoped>
.attendance-table {
  padding: 20px;
}
 
.table-actions {
  margin-bottom: 16px;
  display: flex;
  gap: 10px;
}
 
.pagination-container {
  margin-top: 20px;
  display: flex;
  justify-content: flex-end;
}
</style>