From 909ea3887858ddd7241cd6db28d26f1dc312b652 Mon Sep 17 00:00:00 2001
From: root <295172551@qq.com>
Date: Fri, 27 Jun 2025 00:09:19 +0800
Subject: [PATCH] =?UTF-8?q?=E5=A4=A7=E5=A4=A7=E6=92=92=E6=97=A6?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
LTEMvcApp/Views/Home/Index.cshtml | 160 ++++++++++--------------------
1 file changed, 51 insertions(+), 109 deletions(-)
diff --git a/LTEMvcApp/Views/Home/Index.cshtml b/LTEMvcApp/Views/Home/Index.cshtml
index 72acea5..ac9a03c 100644
--- a/LTEMvcApp/Views/Home/Index.cshtml
+++ b/LTEMvcApp/Views/Home/Index.cshtml
@@ -196,16 +196,14 @@
@group.Ip |
@group.Port |
- @group.Key |
-
-
- |
-
-
- |
-
+
|
+ |
+ |
+
@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('');
+ res.data.forEach(function(cfg) {
+ select.append('');
+ });
+ } else {
+ select.append('');
+ }
},
error: function() {
- // 如果获取Key失败,使用空字符串
- loadNetworkConfigs(select, ip, port, '');
+ select.empty();
+ select.append('');
}
});
});
}
- 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('');
-
- // 添加网络配置选项
- response.data.forEach(function(config) {
- var selected = config.configKey === currentKey ? 'selected' : '';
- selectElement.append('');
- });
-
- // 如果有当前选中的Key,更新对应的apn、band、comment
- if (currentKey) {
- updateNetworkConfigDisplay(ip, currentKey);
- }
- } else {
- // 如果加载失败,显示错误状态
- selectElement.empty();
- selectElement.append('');
+ 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('');
}
});
}
@@ -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);
|