update new version

This commit is contained in:
2025-12-29 22:19:48 +08:00
parent fb2603c6f0
commit b26a339d5c
18 changed files with 1113 additions and 293 deletions
+10 -12
View File
@@ -3,11 +3,11 @@ import 'package:intl/intl.dart';
class ClockInRecord {
final int? clockInId;
final int? userId;
final String? userId; // 改為 String 以對應一般工號格式
final DateTime? dateTime;
final double? latitude;
final double? longitude;
final String? type; // 上班/下班/加班...
final String? type;
final String? storeId;
ClockInRecord({
@@ -23,7 +23,7 @@ class ClockInRecord {
factory ClockInRecord.fromJson(Map<String, dynamic> json) {
return ClockInRecord(
clockInId: json['ClockInId'] as int?,
userId: json['ClockInUserId'] as int?,
userId: json['ClockInUserId']?.toString(),
dateTime: json['ClockInDateTime'] != null ? DateTime.tryParse(json['ClockInDateTime']) : null,
latitude: double.tryParse(json['ClockInLatitude']?.toString() ?? '0'),
longitude: double.tryParse(json['ClockInLongitude']?.toString() ?? '0'),
@@ -32,11 +32,9 @@ class ClockInRecord {
);
}
// Helper: 格式化顯示時間
String get formattedTime => dateTime != null ? DateFormat('HH:mm:ss').format(dateTime!) : '--:--';
String get formattedDate => dateTime != null ? DateFormat('yyyy-MM-dd').format(dateTime!) : 'N/A';
// Helper: 根據打卡類型回傳顏色
Color get typeColor {
if (type == '上班') return Colors.blue;
if (type == '下班') return Colors.orange;
@@ -50,7 +48,7 @@ class ClockInStore {
final String? storeAddress;
final double latitude;
final double longitude;
final int distance; // 允許打卡公尺數
final int distance;
ClockInStore({
required this.storeId,
@@ -63,13 +61,13 @@ class ClockInStore {
factory ClockInStore.fromJson(Map<String, dynamic> json) {
return ClockInStore(
storeId: json['StoreId'] as String,
storeName: json['StoreName'] as String? ?? '',
storeId: json['StoreId'] as String? ?? '',
storeName: json['StoreName'] as String? ?? '未知店點',
storeAddress: json['StoreAddress'] as String?,
// 強制將 decimal/String 轉為 double
latitude: double.tryParse(json['StoreLatitude'].toString()) ?? 0.0,
longitude: double.tryParse(json['StoreLongitude'].toString()) ?? 0.0,
distance: int.tryParse(json['Distance'].toString()) ?? 100,
// 關鍵:處理 Decimal 轉 Double
latitude: double.tryParse(json['StoreLatitude']?.toString() ?? '0') ?? 0.0,
longitude: double.tryParse(json['StoreLongitude']?.toString() ?? '0') ?? 0.0,
distance: int.tryParse(json['Distance']?.toString() ?? '100') ?? 100,
);
}
}