date_time_info.dart 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. import 'package:fis_lib_report/converts/date_to_string_converter.dart';
  2. import 'package:fis_lib_report/converts/event_type.dart';
  3. import 'package:fis_lib_report/report/date_time_element.dart';
  4. import 'package:fis_lib_report/report_info/report_info.dart';
  5. import 'package:fis_lib_report/report_info/text_element_info.dart';
  6. class DateTimeInfo extends TextElementInfo {
  7. ///UI绑定的文本
  8. String get text => _text;
  9. set text(String v) {
  10. _text = v;
  11. final date = DateTime.tryParse(_text.trim());
  12. if (date != null) {
  13. displayValue = DateToStringConverter.dateTimeConvert(
  14. dateTimeFormat!, date.millisecondsSinceEpoch)
  15. .trim();
  16. } else {
  17. displayValue = v;
  18. }
  19. onTextChange.emit(this, v);
  20. }
  21. String displayValue = '';
  22. ///文本改变通知UI变化
  23. FEventHandler<String> onTextChange = FEventHandler<String>();
  24. ///日期格式
  25. String? dateTimeFormat = 'yyyy-MM-dd';
  26. String _text = '';
  27. DateTimeInfo.fromElement(DateTimeElement element)
  28. : super.fromElement(element) {
  29. dateTimeFormat = element.dateTimeFormat;
  30. text = DateTime.now().toString();
  31. }
  32. @override
  33. Map<String, dynamic> toJson() {
  34. final map = <String, dynamic>{};
  35. map['Key'] = id;
  36. map['Value'] = text;
  37. ReportInfo.instance.jsonItems.add(map);
  38. return map;
  39. }
  40. }