feat:设备详情构建完成
This commit is contained in:
@@ -163,7 +163,8 @@ export default function DeviceDetail() {
|
|||||||
};
|
};
|
||||||
|
|
||||||
fetchDevice();
|
fetchDevice();
|
||||||
}, [id, toast]);
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||||
|
}, [id]);
|
||||||
|
|
||||||
// 获取设备关联微信账号
|
// 获取设备关联微信账号
|
||||||
const fetchRelatedAccounts = async (page = 1) => {
|
const fetchRelatedAccounts = async (page = 1) => {
|
||||||
@@ -315,10 +316,19 @@ export default function DeviceDetail() {
|
|||||||
}, 100);
|
}, 100);
|
||||||
};
|
};
|
||||||
|
|
||||||
// 功能开关处理
|
// 功能开关处理 - 只更新开关状态,不重新加载页面
|
||||||
const handleFeatureChange = async (feature: keyof Device['features'], checked: boolean) => {
|
const handleFeatureChange = async (feature: keyof Device['features'], checked: boolean) => {
|
||||||
if (!id) return;
|
if (!id) return;
|
||||||
|
|
||||||
|
// 立即更新UI状态,提供即时反馈
|
||||||
|
setDevice(prev => prev ? {
|
||||||
|
...prev,
|
||||||
|
features: {
|
||||||
|
...prev.features,
|
||||||
|
[feature]: checked
|
||||||
|
}
|
||||||
|
} : null);
|
||||||
|
|
||||||
setSavingFeatures(prev => ({ ...prev, [feature]: true }));
|
setSavingFeatures(prev => ({ ...prev, [feature]: true }));
|
||||||
|
|
||||||
try {
|
try {
|
||||||
@@ -328,19 +338,21 @@ export default function DeviceDetail() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
if (response && response.code === 200) {
|
if (response && response.code === 200) {
|
||||||
setDevice(prev => prev ? {
|
// 请求成功,显示成功提示
|
||||||
...prev,
|
|
||||||
features: {
|
|
||||||
...prev.features,
|
|
||||||
[feature]: checked
|
|
||||||
}
|
|
||||||
} : null);
|
|
||||||
|
|
||||||
toast({
|
toast({
|
||||||
title: "设置成功",
|
title: "设置成功",
|
||||||
description: `${getFeatureName(feature)}已${checked ? '启用' : '禁用'}`,
|
description: `${getFeatureName(feature)}已${checked ? '启用' : '禁用'}`,
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
|
// 请求失败,回滚UI状态
|
||||||
|
setDevice(prev => prev ? {
|
||||||
|
...prev,
|
||||||
|
features: {
|
||||||
|
...prev.features,
|
||||||
|
[feature]: !checked
|
||||||
|
}
|
||||||
|
} : null);
|
||||||
|
|
||||||
toast({
|
toast({
|
||||||
title: "设置失败",
|
title: "设置失败",
|
||||||
description: response.message || "请稍后重试",
|
description: response.message || "请稍后重试",
|
||||||
@@ -349,6 +361,16 @@ export default function DeviceDetail() {
|
|||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error("设置功能失败:", error);
|
console.error("设置功能失败:", error);
|
||||||
|
|
||||||
|
// 网络错误,回滚UI状态
|
||||||
|
setDevice(prev => prev ? {
|
||||||
|
...prev,
|
||||||
|
features: {
|
||||||
|
...prev.features,
|
||||||
|
[feature]: !checked
|
||||||
|
}
|
||||||
|
} : null);
|
||||||
|
|
||||||
toast({
|
toast({
|
||||||
title: "设置失败",
|
title: "设置失败",
|
||||||
description: "请稍后重试",
|
description: "请稍后重试",
|
||||||
|
|||||||
Reference in New Issue
Block a user