Files
2026-05-01 10:51:39 +08:00

136 lines
4.9 KiB
C++
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QMainWindow>
#include <QTableWidget>
#include <QPushButton>
#include <QLabel>
#include <QTimer>
#include <QComboBox>
#include <QLineEdit>
#include <QCheckBox>
#include <QDateEdit>
#include <QVector>
#include <QEvent>
#include <QDialog>
#include "AttendanceRecord.h"
#include "NetworkApiManager.h"
class MappingConfigDialog;
/**
* @brief 对话框位置限制过滤器
* 限制对话框只能在父窗口范围内移动
*/
class DialogPositionFilter : public QObject
{
Q_OBJECT
public:
explicit DialogPositionFilter(QWidget *parent = nullptr) : QObject(parent) {}
protected:
bool eventFilter(QObject *obj, QEvent *event) override;
};
/**
* @brief 考勤记录管理端主窗口(网络版)
*
* 功能:
* - 通过HTTP API从服务器获取数据
* - 显示考勤记录表格
* - 自动刷新数据(30秒)
* - 按学号、姓名、日期筛选
* - 统计信息显示
* - 服务器配置管理
*/
class MainWindow : public QMainWindow
{
Q_OBJECT
public:
explicit MainWindow(QWidget *parent = nullptr);
~MainWindow();
private slots:
// 数据操作
void loadAttendanceData(); // 从服务器加载考勤数据
void refreshData(); // 刷新数据
void filterData(); // 筛选数据
void exportToExcel(); // 导出为CSV
void exportSelectedRecords(); // 导出选中的记录
void clearFilter(); // 清除筛选条件
void deleteSelectedRecord(); // 删除选中的记录
void deleteSelectedRecords(); // 批量删除选中的记录
void toggleSelectAll(); // 全选/取消全选
void unselectAll(); // 取消选中
// 管理功能
void onClearAllRecords(); // 清空所有签到记录(调用API)
void onOpenSettings(); // 打开时间段设置
void onOpenMappingConfig(); // 打开映射配置
void onOpenFaceManage(); // 打开人脸管理
void onShowStatistics(); // 显示统计报表
void onAbout(); // 关于对话框
// 网络响应处理
void onRecordsFetched(const QVector<AttendanceRecord> &records);
void onStatisticsFetched(int total, int today, const QString &serverTime);
void onRecordsCleared(bool success);
void onRecordDeleted(bool success); // 新增:删除记录响应
void onNetworkError(const QString &error);
void onMappingConfigFetched(const QMap<QString, QString> &studentNameMap,
const QMap<QString, QString> &classNameMap);
void onMappingConfigUploaded(bool success);
private:
void setupUI(); // 设置UI界面
void setupMenuBar(); // 设置菜单栏
void setupConnections(); // 设置信号槽连接
void updateTable(const QVector<AttendanceRecord> &records); // 更新表格
void updateStatistics(int total, int today); // 更新统计信息
void showConnectionStatus(bool connected); // 显示连接状态
// UI组件
QTableWidget *m_tableWidget;
QPushButton *m_refreshButton;
QPushButton *m_exportButton;
QPushButton *m_exportSelectedButton; // 导出选中
QPushButton *m_deleteSelectedButton; // 删除选中
QPushButton *m_clearFilterButton;
QPushButton *m_settingsButton;
QPushButton *m_statsButton;
QPushButton *m_clearRecordsButton;
QCheckBox *m_selectAllCheckBox; // 全选复选框
QPushButton *m_unselectAllButton; // 取消选中按钮
QLabel *m_totalLabel;
QLabel *m_todayLabel;
QLabel *m_statusLabel;
QLabel *m_connectionLabel;
QLabel *m_selectedCountLabel; // 显示选中数量
QComboBox *m_classFilterCombo; // 班级筛选下拉框
QComboBox *m_studentFilterCombo;
QLineEdit *m_nameFilterEdit;
QComboBox *m_dateFilterCombo;
QDateEdit *m_specificDateEdit; // 特定日期选择器
QCheckBox *m_enableSpecificDateCheckBox; // 启用特定日期筛选
// 数据
QVector<AttendanceRecord> m_allRecords; // 所有记录
QVector<AttendanceRecord> m_filteredRecords; // 筛选后的记录
QSet<QString> m_selectedRecordKeys; // 保存选中记录的唯一键(timestamp+studentId)
QMap<QString, QString> m_studentNameMap; // 学号 -> 真实姓名 映射
QMap<QString, QString> m_classNameMap; // 班级编号 -> 班级名称 映射
// 辅助函数
QString getMappedStudentName(const QString &studentId, const QString &originalName) const;
QString getMappedClassName(const QString &classId) const;
void loadMappingConfigFromSettings();
void saveMappingConfigToSettings();
// 网络
NetworkApiManager *m_apiManager; // 网络API管理器
QTimer *m_autoRefreshTimer; // 自动刷新定时器
};
#endif // MAINWINDOW_H