|
|
@ -196,16 +196,14 @@ |
|
|
|
<tr> |
|
|
|
<td>@group.Ip</td> |
|
|
|
<td>@group.Port</td> |
|
|
|
<td>@group.Key</td> |
|
|
|
<td class="apn-cell" data-ip="@group.Ip"> |
|
|
|
<!-- 异步加载 --> |
|
|
|
</td> |
|
|
|
<td class="band-cell" data-ip="@group.Ip"> |
|
|
|
<!-- 异步加载 --> |
|
|
|
</td> |
|
|
|
<td class="comment-cell" data-ip="@group.Ip"> |
|
|
|
<!-- 异步加载 --> |
|
|
|
<td> |
|
|
|
<select class="form-control form-control-sm network-key-select" data-ip="@group.Ip" data-port="@group.Port" onchange="onKeyChange(this, '@group.Ip')"> |
|
|
|
<option value="">加载中...</option> |
|
|
|
</select> |
|
|
|
</td> |
|
|
|
<td class="apn-cell" data-ip="@group.Ip"></td> |
|
|
|
<td class="band-cell" data-ip="@group.Ip"></td> |
|
|
|
<td class="comment-cell" data-ip="@group.Ip"></td> |
|
|
|
<td> |
|
|
|
@if (group.State == "运行") |
|
|
|
{ |
|
|
@ -401,61 +399,54 @@ |
|
|
|
}); |
|
|
|
|
|
|
|
function loadAllNetworkConfigs() { |
|
|
|
$('.network-config-select').each(function() { |
|
|
|
var select = $(this); |
|
|
|
var ip = select.data('ip'); |
|
|
|
var port = select.data('port'); |
|
|
|
|
|
|
|
// 从服务器获取当前保存的Key |
|
|
|
$('.network-key-select').each(function() { |
|
|
|
const select = $(this); |
|
|
|
const ip = select.data('ip'); |
|
|
|
const port = select.data('port'); |
|
|
|
$.ajax({ |
|
|
|
url: '/api/ipgroup/key/' + encodeURIComponent(ip), |
|
|
|
url: '/api/ipgroup/network-config', |
|
|
|
type: 'GET', |
|
|
|
timeout: 5000, // 5秒超时 |
|
|
|
success: function(keyResponse) { |
|
|
|
var currentKey = keyResponse.key || ''; |
|
|
|
loadNetworkConfigs(select, ip, port, currentKey); |
|
|
|
data: { ip, port }, |
|
|
|
success: function(res) { |
|
|
|
select.empty(); |
|
|
|
if (res.isSuccess && res.data && res.data.length > 0) { |
|
|
|
select.append('<option value="">请选择Key</option>'); |
|
|
|
res.data.forEach(function(cfg) { |
|
|
|
select.append('<option value="' + cfg.configKey + '">' + cfg.configKey + '</option>'); |
|
|
|
}); |
|
|
|
} else { |
|
|
|
select.append('<option value="">无可用Key</option>'); |
|
|
|
} |
|
|
|
}, |
|
|
|
error: function() { |
|
|
|
// 如果获取Key失败,使用空字符串 |
|
|
|
loadNetworkConfigs(select, ip, port, ''); |
|
|
|
select.empty(); |
|
|
|
select.append('<option value="">加载失败</option>'); |
|
|
|
} |
|
|
|
}); |
|
|
|
}); |
|
|
|
} |
|
|
|
|
|
|
|
function loadNetworkConfigs(selectElement, ip, port, currentKey) { |
|
|
|
function onKeyChange(select, ip) { |
|
|
|
const key = $(select).val(); |
|
|
|
const port = $(select).data('port'); |
|
|
|
if (!key) { |
|
|
|
$('.apn-cell[data-ip="' + ip + '"]').text(''); |
|
|
|
$('.band-cell[data-ip="' + ip + '"]').text(''); |
|
|
|
$('.comment-cell[data-ip="' + ip + '"]').text(''); |
|
|
|
return; |
|
|
|
} |
|
|
|
// 联动显示apn/band/comment |
|
|
|
$.ajax({ |
|
|
|
url: '/api/ipgroup/network-config', |
|
|
|
type: 'GET', |
|
|
|
data: { ip: ip, port: port }, |
|
|
|
timeout: 10000, // 10秒超时 |
|
|
|
success: function(response) { |
|
|
|
if (response.isSuccess && response.data) { |
|
|
|
// 清空现有选项并设置默认选项 |
|
|
|
selectElement.empty(); |
|
|
|
selectElement.append('<option value="">请选择Key</option>'); |
|
|
|
|
|
|
|
// 添加网络配置选项 |
|
|
|
response.data.forEach(function(config) { |
|
|
|
var selected = config.configKey === currentKey ? 'selected' : ''; |
|
|
|
selectElement.append('<option value="' + config.configKey + '" ' + selected + '>' + config.configKey + '</option>'); |
|
|
|
}); |
|
|
|
|
|
|
|
// 如果有当前选中的Key,更新对应的apn、band、comment |
|
|
|
if (currentKey) { |
|
|
|
updateNetworkConfigDisplay(ip, currentKey); |
|
|
|
} |
|
|
|
} else { |
|
|
|
// 如果加载失败,显示错误状态 |
|
|
|
selectElement.empty(); |
|
|
|
selectElement.append('<option value="">加载失败</option>'); |
|
|
|
success: function(res) { |
|
|
|
if (res.isSuccess && res.data) { |
|
|
|
const cfg = res.data.find(x => x.configKey === key); |
|
|
|
$('.apn-cell[data-ip="' + ip + '"]').text(cfg ? (cfg.apn || '') : ''); |
|
|
|
$('.band-cell[data-ip="' + ip + '"]').text(cfg && cfg.band ? cfg.band.join(',') : ''); |
|
|
|
$('.comment-cell[data-ip="' + ip + '"]').text(cfg ? (cfg.comment || '') : ''); |
|
|
|
} |
|
|
|
}, |
|
|
|
error: function(xhr, status, error) { |
|
|
|
console.warn('加载网络配置失败:', ip + ':' + port, error); |
|
|
|
// 显示加载失败状态 |
|
|
|
selectElement.empty(); |
|
|
|
selectElement.append('<option value="">加载失败</option>'); |
|
|
|
} |
|
|
|
}); |
|
|
|
} |
|
|
@ -507,72 +498,22 @@ |
|
|
|
}); |
|
|
|
} |
|
|
|
|
|
|
|
function updateNetworkConfigDisplay(ip, key) { |
|
|
|
// 获取当前行的端口信息 |
|
|
|
var row = $('tr').filter(function() { |
|
|
|
return $(this).find('td:first').text().trim() === ip; |
|
|
|
}); |
|
|
|
|
|
|
|
var port = row.find('td:eq(1)').text().trim(); // 第二列是端口 |
|
|
|
|
|
|
|
// 根据IP和端口获取网络配置数据 |
|
|
|
$.ajax({ |
|
|
|
url: '/api/ipgroup/network-config', |
|
|
|
type: 'GET', |
|
|
|
data: { ip: ip, port: port }, |
|
|
|
timeout: 10000, // 10秒超时 |
|
|
|
success: function(response) { |
|
|
|
if (response.isSuccess && response.data) { |
|
|
|
var selectedConfig = response.data.find(function(config) { |
|
|
|
return config.configKey === key; |
|
|
|
}); |
|
|
|
|
|
|
|
if (selectedConfig) { |
|
|
|
// 更新apn列 |
|
|
|
$('.apn-cell[data-ip="' + ip + '"]').text(selectedConfig.apn || ''); |
|
|
|
|
|
|
|
// 更新band列 |
|
|
|
var bandText = selectedConfig.band ? selectedConfig.band.join(',') : ''; |
|
|
|
$('.band-cell[data-ip="' + ip + '"]').text(bandText); |
|
|
|
|
|
|
|
// 更新comment列 |
|
|
|
$('.comment-cell[data-ip="' + ip + '"]').text(selectedConfig.comment || ''); |
|
|
|
} |
|
|
|
} |
|
|
|
}, |
|
|
|
error: function(xhr, status, error) { |
|
|
|
console.warn('更新网络配置显示失败:', ip + ':' + port, error); |
|
|
|
// 清空显示内容 |
|
|
|
$('.apn-cell[data-ip="' + ip + '"]').text(''); |
|
|
|
$('.band-cell[data-ip="' + ip + '"]').text(''); |
|
|
|
$('.comment-cell[data-ip="' + ip + '"]').text(''); |
|
|
|
} |
|
|
|
}); |
|
|
|
} |
|
|
|
|
|
|
|
function startIpGroup(ip) { |
|
|
|
// 获取当前行的端口信息 |
|
|
|
var row = $('tr').filter(function() { |
|
|
|
return $(this).find('td:first').text().trim() === ip; |
|
|
|
}); |
|
|
|
|
|
|
|
var port = row.find('td:eq(1)').text().trim(); // 第二列是端口 |
|
|
|
var keySelect = row.find('select'); |
|
|
|
var key = keySelect.val(); |
|
|
|
|
|
|
|
var port = row.find('td:eq(1)').text().trim(); |
|
|
|
var key = row.find('.network-key-select').val(); |
|
|
|
if (!key) { |
|
|
|
alert('请先选择网络Key!'); |
|
|
|
keySelect.focus(); |
|
|
|
return; |
|
|
|
} |
|
|
|
|
|
|
|
if (!confirm('确定要启动该网络吗?')) return; |
|
|
|
|
|
|
|
$.ajax({ |
|
|
|
url: '/api/ipgroup/start', |
|
|
|
type: 'POST', |
|
|
|
contentType: 'application/json', |
|
|
|
data: JSON.stringify({ ip: ip, port: port }), |
|
|
|
data: JSON.stringify({ ip: ip, port: port, key: key }), |
|
|
|
success: function(response) { |
|
|
|
showToast('网络启动成功', 'success'); |
|
|
|
setTimeout(() => location.reload(), 2000); |
|
|
@ -591,20 +532,21 @@ |
|
|
|
} |
|
|
|
|
|
|
|
function stopIpGroup(ip) { |
|
|
|
// 获取当前行的端口信息 |
|
|
|
var row = $('tr').filter(function() { |
|
|
|
return $(this).find('td:first').text().trim() === ip; |
|
|
|
}); |
|
|
|
|
|
|
|
var port = row.find('td:eq(1)').text().trim(); // 第二列是端口 |
|
|
|
|
|
|
|
var port = row.find('td:eq(1)').text().trim(); |
|
|
|
var key = row.find('.network-key-select').val(); |
|
|
|
if (!key) { |
|
|
|
alert('请先选择网络Key!'); |
|
|
|
return; |
|
|
|
} |
|
|
|
if (!confirm('确定要停止该网络吗?')) return; |
|
|
|
|
|
|
|
$.ajax({ |
|
|
|
url: '/api/ipgroup/stop', |
|
|
|
type: 'POST', |
|
|
|
contentType: 'application/json', |
|
|
|
data: JSON.stringify({ ip: ip, port: port }), |
|
|
|
data: JSON.stringify({ ip: ip, port: port, key: key }), |
|
|
|
success: function(response) { |
|
|
|
showToast('网络停止成功', 'success'); |
|
|
|
setTimeout(() => location.reload(), 2000); |
|
|
|