diff --git a/LTEMvcApp/Views/Home/Index.cshtml b/LTEMvcApp/Views/Home/Index.cshtml index 50b46e1..387e52d 100644 --- a/LTEMvcApp/Views/Home/Index.cshtml +++ b/LTEMvcApp/Views/Home/Index.cshtml @@ -407,33 +407,53 @@ } function startTestClient(address) { + var row = $('tr').filter(function() { + return $(this).find('td:eq(1)').text().trim() === address; + }); $.ajax({ url: '/api/testconfig/start', type: 'POST', contentType: 'application/json', data: JSON.stringify({ address: address }), success: function() { - alert('启动请求已发送!页面将在2秒后刷新。'); - setTimeout(() => location.reload(), 2000); + showToast('启动请求已发送!', 'success'); + // 更新当前行状态 + row.find('td').eq(2).html('运行'); + // 更新按钮状态 + row.find('.btn-primary').addClass('disabled'); + row.find('.btn-danger').removeClass('disabled'); + row.find('.btn-info').removeClass('disabled'); + row.find('.btn-warning').addClass('disabled'); + row.find('.btn-outline-danger').addClass('disabled'); }, error: function(xhr) { - alert('启动失败:' + xhr.responseText); + showToast('启动失败:' + xhr.responseText, 'error'); } }); } function stopTestClient(address) { + var row = $('tr').filter(function() { + return $(this).find('td:eq(1)').text().trim() === address; + }); $.ajax({ url: '/api/testconfig/stop', type: 'POST', contentType: 'application/json', data: JSON.stringify({ address: address }), success: function() { - alert('停止请求已发送!页面将在2秒后刷新。'); - setTimeout(() => location.reload(), 2000); + showToast('停止请求已发送!', 'success'); + // 更新当前行状态 + row.find('td').eq(2).html('停止'); + // 更新按钮状态 + row.find('.btn-primary').removeClass('disabled'); + row.find('.btn-danger').addClass('disabled'); + row.find('.btn-info').addClass('disabled'); + row.find('.btn-warning').removeClass('disabled'); + row.find('.btn-outline-danger').removeClass('disabled'); }, error: function(xhr) { - alert('停止失败:' + xhr.responseText); + showToast('停止失败:' + xhr.responseText, 'error'); } }); } @@ -471,9 +491,16 @@ data: JSON.stringify({ ip: ip, port: port, key: key }), success: function(response) { showToast('网络启动成功', 'success'); - // 立即更新状态列 - if (response && response.data === 1) { - row.find('td').eq(6).html('运行'); + // 解析嵌套的response字段 + if (response && response.response) { + try { + var innerResponse = JSON.parse(response.response); + if (innerResponse && innerResponse.data === 1) { + row.find('td').eq(6).html('运行'); + } + } catch (e) { + console.log('解析响应数据失败:', e); + } } loadAllNetworkConfigs(); }, @@ -508,9 +535,16 @@ data: JSON.stringify({ ip: ip, port: port, key: key }), success: function(response) { showToast('网络停止成功', 'success'); - // 只要isSuccess为true就立即更新状态 - if (response && response.isSuccess) { - row.find('td').eq(6).html('停止'); + // 解析嵌套的response字段 + if (response && response.response) { + try { + var innerResponse = JSON.parse(response.response); + if (innerResponse && innerResponse.isSuccess) { + row.find('td').eq(6).html('停止'); + } + } catch (e) { + console.log('解析响应数据失败:', e); + } } loadAllNetworkConfigs(); },