更新小e
This commit is contained in:
@@ -126,6 +126,8 @@ class DeviceListController extends GetControllerEx<DeviceListModel> {
|
||||
} else {
|
||||
msg = '删除成功'.tr;
|
||||
}
|
||||
//删除用户的自定义配置
|
||||
delDeviceSleepHabit(device);
|
||||
},
|
||||
onFailure: (res) {
|
||||
if (type == 1) {
|
||||
@@ -161,4 +163,43 @@ class DeviceListController extends GetControllerEx<DeviceListModel> {
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
void delDeviceSleepHabit(Map device) {
|
||||
String serviceAddress = ServiceConstant.service_address;
|
||||
String serviceName = ServiceConstant.server_service;
|
||||
String serviceApi = ServiceConstant.user_setting;
|
||||
String type = "sleep_habit_${formatMacAddress(device['mac'])}";
|
||||
String queryUrl =
|
||||
"${serviceAddress}${serviceName}${serviceApi}?type=${type}";
|
||||
requestWithLog(
|
||||
logTitle: "删除设备自定义配置",
|
||||
method: MyHttpMethod.delete,
|
||||
queryUrl: queryUrl,
|
||||
onSuccess: (res) {
|
||||
print(res);
|
||||
},
|
||||
onFailure: (res) {
|
||||
print(res);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
String formatMacAddress(String input) {
|
||||
if (input.isEmpty) return input;
|
||||
|
||||
// 1. 移除所有非16进制字符(去掉冒号、空格、破折号等)
|
||||
String clean = input.replaceAll(RegExp(r'[^a-fA-F0-9]'), '');
|
||||
|
||||
// 2. 如果长度不足12,左侧补0(MAC地址长度固定12)
|
||||
clean = clean.padLeft(12, '0');
|
||||
|
||||
// 3. 按2个字符一组,拼接冒号
|
||||
List<String> parts = [];
|
||||
for (int i = 0; i < 12; i += 2) {
|
||||
parts.add(clean.substring(i, i + 2).toUpperCase());
|
||||
}
|
||||
|
||||
// 4. 返回格式化字符串
|
||||
return parts.join(':');
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user