BUG修复:添加分离式刷新按钮
This commit is contained in:
1 parent
ec5c2db848
commit
00617621f9
4 files changed
+287
-141
No files matched your search
@@ -87,8 +87,52 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
||||
$errorMsg = $result['error'] ?? $result['msg'] ?? '未知错误';
|
||||
$message = '<div class="error-message"><h3>❌ 操作失败</h3><p>' . htmlspecialchars($errorMsg) . '</p></div>';
|
||||
}
|
||||
} elseif ($action === 'refresh_single_config') {
|
||||
// 单独刷新某个配置
|
||||
$configId = intval($_POST['config_id'] ?? 0);
|
||||
|
||||
if ($configId > 0) {
|
||||
$configDb = getVpsDB();
|
||||
$config = $configDb->queryOne('SELECT * FROM configs WHERE id = ?', [$configId]);
|
||||
|
||||
if ($config) {
|
||||
$success = false;
|
||||
$typeName = '';
|
||||
|
||||
if ($config['site_type'] === 'mofang') {
|
||||
require_once __DIR__ . '/mofangidc.php';
|
||||
$success = refreshVpsListForConfig($configId);
|
||||
$typeName = '魔方平台';
|
||||
} elseif ($config['site_type'] === 'tencent') {
|
||||
require_once __DIR__ . '/tencentcloud.php';
|
||||
// 同时刷新CVM和轻量
|
||||
$cvmSuccess = refreshTencentCvmListForConfig($configId);
|
||||
$lhSuccess = refreshTencentLighthouseListForConfig($configId);
|
||||
$success = $cvmSuccess || $lhSuccess;
|
||||
$typeName = '腾讯云';
|
||||
} elseif ($config['site_type'] === 'aliyun') {
|
||||
require_once __DIR__ . '/aliyun.php';
|
||||
$success = refreshAliyunEcsListForConfig($configId);
|
||||
$typeName = '阿里云ECS';
|
||||
} elseif ($config['site_type'] === 'aliyun_swas') {
|
||||
require_once __DIR__ . '/aliyun.php';
|
||||
$success = refreshAliyunSwasListForConfig($configId);
|
||||
$typeName = '阿里云轻量';
|
||||
}
|
||||
|
||||
if ($success) {
|
||||
$message = '<div class="success-message"><h3>✅ 刷新成功</h3><p>已刷新配置「' . htmlspecialchars($config['api_label']) . '」(' . $typeName . ')的VPS列表</p></div>';
|
||||
} else {
|
||||
$message = '<div class="error-message"><h3>❌ 刷新失败</h3><p>配置「' . htmlspecialchars($config['api_label']) . '」刷新失败,请检查API凭证和网络连接</p></div>';
|
||||
}
|
||||
} else {
|
||||
$message = '<div class="error-message">❌ 配置不存在</div>';
|
||||
}
|
||||
} else {
|
||||
$message = '<div class="error-message">❌ 无效的配置ID</div>';
|
||||
}
|
||||
} elseif ($action === 'refresh_vps_list') {
|
||||
// 手动刷新VPS列表
|
||||
// 手动刷新VPS列表(全部)
|
||||
$count = 0;
|
||||
|
||||
// 刷新魔方平台的VPS列表
|
||||
@@ -201,6 +245,12 @@ foreach ($vpsList as $vps) {
|
||||
$vpsByApiLabel[$apiLabel][] = $vps;
|
||||
}
|
||||
|
||||
// 构建api_label到config_id的映射(用于单独刷新)
|
||||
$apiLabelToConfigId = [];
|
||||
foreach ($configs as $config) {
|
||||
$apiLabelToConfigId[$config['api_label']] = $config['id'];
|
||||
}
|
||||
|
||||
// 统计信息
|
||||
$totalCount = count($vpsList);
|
||||
$runningCount = 0;
|
||||
@@ -245,6 +295,11 @@ foreach ($vpsList as $vps) {
|
||||
.btn-refresh:hover {
|
||||
background-color: #0056b3;
|
||||
}
|
||||
.config-title {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
}
|
||||
/* 消息自动消失动画 */
|
||||
.success-message, .error-message {
|
||||
transition: opacity 0.5s ease-out;
|
||||
@@ -417,9 +472,9 @@ foreach ($vpsList as $vps) {
|
||||
|
||||
<!-- 工具栏 -->
|
||||
<div class="toolbar">
|
||||
<form method="POST" style="display: inline;">
|
||||
<form method="POST" style="display: inline;" onsubmit="return confirmRefreshAll()">
|
||||
<button type="submit" name="action" value="refresh_vps_list" class="btn-refresh">
|
||||
🔄 手动刷新VPS列表
|
||||
🔄 刷新全部列表
|
||||
</button>
|
||||
</form>
|
||||
|
||||
@@ -454,13 +509,21 @@ foreach ($vpsList as $vps) {
|
||||
<?php foreach ($vpsByApiLabel as $apiLabel => $labelVps): ?>
|
||||
<div class="config-section">
|
||||
<div class="config-title">
|
||||
<?php echo htmlspecialchars($apiLabel); ?>
|
||||
- <?php echo count($labelVps); ?> 台VPS
|
||||
<span>
|
||||
<?php echo htmlspecialchars($apiLabel); ?>
|
||||
- <?php echo count($labelVps); ?> 台VPS
|
||||
</span>
|
||||
<form method="POST" style="display: inline; margin-left: 15px;" onsubmit="return confirm('确认刷新此配置的VPS列表?')">
|
||||
<input type="hidden" name="config_id" value="<?php echo $apiLabelToConfigId[$apiLabel] ?? 0; ?>">
|
||||
<button type="submit" name="action" value="refresh_single_config" class="btn-refresh" style="padding: 5px 12px; font-size: 13px;">
|
||||
🔄 刷新此配置
|
||||
</button>
|
||||
</form>
|
||||
</div>
|
||||
|
||||
<?php if (empty($labelVps)): ?>
|
||||
<div class="empty-state" style="background: white; padding: 40px;">
|
||||
<p>此配置下暂无VPS,请点击“手动刷新VPS列表”获取</p>
|
||||
<p>此配置下暂无VPS,请点击右上角“🔄 刷新此配置”按钮获取</p>
|
||||
</div>
|
||||
<?php else: ?>
|
||||
<div class="vps-grid">
|
||||
@@ -627,6 +690,17 @@ foreach ($vpsList as $vps) {
|
||||
}, 5000); // 5秒后开始淡出
|
||||
});
|
||||
});
|
||||
|
||||
// 刷新全部列表确认
|
||||
function confirmRefreshAll() {
|
||||
return confirm('⚠️ 警告:资源消耗占用较高\n\n' +
|
||||
'刷新全部列表会同时请求所有配置的API,可能会导致:\n' +
|
||||
'• 页面卡顿或响应缓慢\n' +
|
||||
'• API超时导致报错中断\n' +
|
||||
'• 部分配置刷新失败\n\n' +
|
||||
'建议优先使用分离式刷新功能(点击每个配置右上角的🔄按钮)\n\n' +
|
||||
'确定要继续刷新全部列表吗?');
|
||||
}
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
Reference in new issue
Block a user