更新分享
This commit is contained in:
29
lib/common/color/ServiceConstant.dart
Normal file
29
lib/common/color/ServiceConstant.dart
Normal file
@@ -0,0 +1,29 @@
|
||||
class ServiceConstant {
|
||||
static const String baseHost = "vsbs-test.he-info.cn";//服务地址
|
||||
static const String service_address = "http://$baseHost";
|
||||
|
||||
static String server_service = "/vsbs_app_server";//服务名称
|
||||
|
||||
static String send_code = "/api/verifycode/send";//发送验证码
|
||||
static String login = "/api/user/login";//登录
|
||||
static String get_bluetooth_device_status = "/api/device/status/info";//设备绑定状态
|
||||
static String device_bind = "/api/device/bind";//设备绑定
|
||||
static String device_type = "/api/device/type/list";//设备类型
|
||||
static String upload_file = "/api/file/info";//上传文件
|
||||
static String user_info = "/api/user/info";//更新用户资料,查询用户信息
|
||||
static String device_list = "/api/device/list";//绑定设备列表
|
||||
static String person_info = "/api/personnel/info";//用户资料
|
||||
static String sleep_report = "/api/device/sleep/data";//睡眠报告
|
||||
static String device_share = "/api/device/share";//分享设备
|
||||
static String message_list = "/api/mesasge/list";//消息列表
|
||||
static String device_show = "/api/device/bind";//更新设备绑定
|
||||
static String disease_list = "/api/personnel/disease/list";//获取疾病类型
|
||||
|
||||
|
||||
|
||||
static String logService = "$service_address/vsbs_log";
|
||||
static const String webSocketService = "wss://$baseHost/vsbs_ws_gateway/ws";
|
||||
static const String sleep_token = "HdAMjzqiYQKsmHRyEFKhfRGQ";
|
||||
static const String sleep_report_url = "https://alltoone.he-info.cn/h5/#/mattress/sleep/sleep";
|
||||
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
87
lib/common/util/DailyLogUtils.dart
Normal file
87
lib/common/util/DailyLogUtils.dart
Normal file
@@ -0,0 +1,87 @@
|
||||
import 'dart:io';
|
||||
import 'package:path_provider/path_provider.dart';
|
||||
import 'package:intl/intl.dart';
|
||||
|
||||
class DailyLogUtils {
|
||||
// 获取日志文件路径(按日期命名)
|
||||
static Future<File> _getLogFile() async {
|
||||
final dir = await getApplicationDocumentsDirectory();
|
||||
final date = DateFormat('yyyy-MM-dd').format(DateTime.now());
|
||||
final filePath = '${dir.path}/$date.log';
|
||||
final file = File(filePath);
|
||||
if (!await file.exists()) {
|
||||
await file.create(recursive: true);
|
||||
}
|
||||
return file;
|
||||
}
|
||||
|
||||
// 写入日志核心方法,带日志等级
|
||||
static Future<void> _writeLogWithLevel(String level, String content) async {
|
||||
final file = await _getLogFile();
|
||||
final now = DateTime.now();
|
||||
final time = DateFormat('HH:mm:ss').format(now);
|
||||
final logLine = '[$time][$level] $content\n';
|
||||
await file.writeAsString(logLine, mode: FileMode.append);
|
||||
}
|
||||
|
||||
// 写入 info 日志(原 writeLog 保留)
|
||||
static Future<void> writeLog(String content) async {
|
||||
await _writeLogWithLevel('INFO', content);
|
||||
}
|
||||
|
||||
// 写入 warning 日志
|
||||
static Future<void> writeWarning(String content) async {
|
||||
await _writeLogWithLevel('WARNING', content);
|
||||
}
|
||||
|
||||
// 写入 error 日志
|
||||
static Future<void> writeError(String content) async {
|
||||
await _writeLogWithLevel('ERROR', content);
|
||||
}
|
||||
|
||||
// 写入 debug 日志
|
||||
static Future<void> writeDebug(String content) async {
|
||||
await _writeLogWithLevel('DEBUG', content);
|
||||
}
|
||||
|
||||
// 读取当天日志
|
||||
static Future<String> readTodayLog() async {
|
||||
final file = await _getLogFile();
|
||||
return await file.readAsString();
|
||||
}
|
||||
|
||||
// 获取所有日志文件(返回 File 列表)
|
||||
static Future<List<FileSystemEntity>> listLogFiles() async {
|
||||
final dir = await getApplicationDocumentsDirectory();
|
||||
final files = dir.listSync();
|
||||
return files.where((f) => f.path.endsWith('.log')).toList();
|
||||
}
|
||||
|
||||
// 清除所有日志
|
||||
static Future<void> clearAllLogs() async {
|
||||
final files = await listLogFiles();
|
||||
for (final f in files) {
|
||||
await File(f.path).delete();
|
||||
}
|
||||
}
|
||||
|
||||
/// 获取指定日期范围内的日志文件(包含起止日期)
|
||||
static Future<List<File>> getLogsBetween(
|
||||
DateTime fromDate, DateTime toDate) async {
|
||||
final dir = await getApplicationDocumentsDirectory();
|
||||
final logFiles = <File>[];
|
||||
final dateFormat = DateFormat('yyyy-MM-dd');
|
||||
|
||||
for (DateTime date = fromDate;
|
||||
!date.isAfter(toDate);
|
||||
date = date.add(Duration(days: 1))) {
|
||||
final fileName = '${dateFormat.format(date)}.log';
|
||||
final file = File('${dir.path}/$fileName');
|
||||
if (await file.exists()) {
|
||||
logFiles.add(file);
|
||||
}
|
||||
}
|
||||
|
||||
return logFiles;
|
||||
}
|
||||
}
|
||||
@@ -118,6 +118,57 @@ class MyUtils {
|
||||
curve: Curves.easeInOut,
|
||||
);
|
||||
}
|
||||
|
||||
static String formatBindTime(DateTime d) {
|
||||
final DateFormat formatter = DateFormat('yyyy/MM/dd');
|
||||
return formatter.format(d);
|
||||
}
|
||||
|
||||
static DateTime? formatBirthdayTime(String? device) {
|
||||
if (device == null || device.isEmpty) return null;
|
||||
|
||||
try {
|
||||
return DateTime.parse(device.replaceAll('/', '-')); // 替换为标准格式
|
||||
} catch (e) {
|
||||
return null; // 解析失败时返回 null
|
||||
}
|
||||
}
|
||||
|
||||
static int getAgeByDate(DateTime? formatBirthdayTime) {
|
||||
if (formatBirthdayTime == null) return 0;
|
||||
|
||||
final now = DateTime.now();
|
||||
int age = now.year - formatBirthdayTime.year;
|
||||
|
||||
// 如果还没到今年生日,减一岁
|
||||
if (now.month < formatBirthdayTime.month ||
|
||||
(now.month == formatBirthdayTime.month &&
|
||||
now.day < formatBirthdayTime.day)) {
|
||||
age--;
|
||||
}
|
||||
|
||||
return age;
|
||||
}
|
||||
|
||||
static String formatDateTimeWeek(DateTime date) {
|
||||
DateTime now = DateTime.now();
|
||||
// 去除时间部分,仅比较年月日
|
||||
DateTime today = DateTime(now.year, now.month, now.day);
|
||||
DateTime target = DateTime(date.year, date.month, date.day);
|
||||
|
||||
if (target == today) {
|
||||
return '今日';
|
||||
}
|
||||
|
||||
const List<String> weekdays = ['周日', '周一', '周二', '周三', '周四', '周五', '周六'];
|
||||
return weekdays[date.weekday % 7]; // Dart中星期日是7,要映射到索引0
|
||||
}
|
||||
|
||||
/// 返回 MM/dd 格式
|
||||
static String formatDateTimeDay(DateTime date) {
|
||||
String twoDigits(int n) => n.toString().padLeft(2, '0');
|
||||
return '${twoDigits(date.month)}/${twoDigits(date.day)}';
|
||||
}
|
||||
}
|
||||
|
||||
Color stringToColor(String hexColor) {
|
||||
|
||||
Reference in New Issue
Block a user