calendar_state.dart 914 B

123456789101112131415161718192021222324252627282930
  1. import 'package:intl/intl.dart';
  2. import 'package:get/get.dart';
  3. import '../people_photo/photo_group.dart';
  4. class CalendarState {
  5. static final RxList<PhotoGroup> monthlyAlbums = <PhotoGroup>[].obs;
  6. // 格式化月份
  7. static String formatMonth(String month) {
  8. try {
  9. DateTime date = DateFormat('yyyy-MM').parse(month);
  10. return DateFormat('MMM , yyyy').format(date); // 转换为 "Nov, 2024" 格式
  11. } catch (e) {
  12. return month; // 如果解析失败,返回原始字符串
  13. }
  14. }
  15. static void removePhotosData(Set<String> selectedPhotosIds) {
  16. monthlyAlbums.removeWhere((album) {
  17. album.images
  18. .removeWhere((element) => selectedPhotosIds.contains(element.id));
  19. album.selectedPhotosIds
  20. .removeWhere((element) => selectedPhotosIds.contains(element));
  21. // 如果images为空,删除该 album
  22. return album.images.isEmpty;
  23. });
  24. }
  25. }