paramConfig method
Implementation
String paramConfig({
required String deviceId,
required CalendarType type,
DateTime? monthDateTime,
DateTime? startTime,
DateTime? endTime,
int? channel,
String? userId,
String? mUserid,
bool needAuth = true,
}) {
final Map<String, dynamic> jsonMap = {
'sn': deviceId,
};
if (type == CalendarType.alarmMessage) {
///消息日历无需鉴权
jsonMap['msg'] = 'alendar'; //服务器拼写错误,不要改
jsonMap['ty'] = 'MSG';
} else {
jsonMap['msg'] = needAuth ? 'alendar_user' : 'alendar'; //服务器拼写错误,不要改
jsonMap['ty'] = 'VIDEO';
}
///配置时间
if (monthDateTime != null) {
jsonMap['dt'] =
'${monthDateTime.year}-${monthDateTime.month.toString().padLeft(2, '0')}';
} else {
List<Map<String, String>> dateRange = [];
DateTime currentDate = startTime!;
while (currentDate.isBefore(endTime!) || currentDate == endTime) {
String formattedDate =
"${currentDate.year}-${currentDate.month.toString().padLeft(2, '0')}-${currentDate.day.toString().padLeft(2, '0')}";
dateRange.add({'tm': formattedDate});
currentDate = currentDate.add(const Duration(days: 1));
}
jsonMap['dt'] = dateRange;
}
if (channel != null) {
jsonMap['ch'] = channel;
}
if (userId != null) {
jsonMap['userid'] = userId;
}
if (mUserid != null) {
jsonMap['muserid'] = mUserid;
}
return jsonEncode(jsonMap);
}