feat: add pool editing UI and agent guidance
This commit is contained in:
54
main.py
54
main.py
@@ -1067,6 +1067,7 @@ def index():
|
||||
<div id="poolSelectedNodes"></div>
|
||||
<div style="margin-bottom: 15px;">
|
||||
<button class="btn btn-success" onclick="createPool()" id="btnCreatePool" disabled>创建节点池</button>
|
||||
<button class="btn" onclick="resetPoolEditor()" id="btnCancelPoolEdit" style="display:none">取消修改</button>
|
||||
<span id="poolSelectedCount" style="color: #888; margin-left: 10px;">已选 0 个节点</span>
|
||||
</div>
|
||||
<h3 style="color: #00d9ff; margin-bottom: 10px;">已有节点池</h3>
|
||||
@@ -1324,6 +1325,7 @@ def index():
|
||||
// ===== 节点池管理 =====
|
||||
let poolSearchResults = [];
|
||||
let poolSelectedIds = new Set();
|
||||
let editingPoolId = null;
|
||||
|
||||
async function searchPoolNodes() {
|
||||
const q = document.getElementById('poolSearch').value.trim();
|
||||
@@ -1416,6 +1418,40 @@ def index():
|
||||
function updatePoolSelectedCount() {
|
||||
document.getElementById('poolSelectedCount').textContent = `已选 ${poolSelectedIds.size} 个节点`;
|
||||
document.getElementById('btnCreatePool').disabled = poolSelectedIds.size === 0;
|
||||
document.getElementById('btnCreatePool').textContent = editingPoolId ? '保存修改' : '创建节点池';
|
||||
document.getElementById('btnCancelPoolEdit').style.display = editingPoolId ? 'inline-block' : 'none';
|
||||
}
|
||||
|
||||
function resetPoolEditor() {
|
||||
editingPoolId = null;
|
||||
poolSelectedIds.clear();
|
||||
poolSearchResults = [];
|
||||
document.getElementById('poolName').value = '';
|
||||
document.getElementById('poolSearch').value = '';
|
||||
document.getElementById('poolSearchResults').innerHTML = '';
|
||||
document.getElementById('poolSelectedNodes').innerHTML = '';
|
||||
updatePoolSelectedCount();
|
||||
}
|
||||
|
||||
async function editPool(id) {
|
||||
try {
|
||||
const resp = await fetch('/api/pools');
|
||||
const pools = await resp.json();
|
||||
const pool = pools.find(p => p.id === id);
|
||||
if (!pool) {
|
||||
return showResult('节点池不存在', 'info');
|
||||
}
|
||||
editingPoolId = id;
|
||||
poolSelectedIds = new Set(pool.node_ids || []);
|
||||
document.getElementById('poolName').value = pool.name || '';
|
||||
document.getElementById('poolSearch').value = '';
|
||||
document.getElementById('poolSearchResults').innerHTML = '<p style="color:#888">已加载节点池,请继续搜索并调整节点选择</p>';
|
||||
renderSelectedNodes();
|
||||
updatePoolSelectedCount();
|
||||
window.scrollTo({top: document.getElementById('poolName').offsetTop - 80, behavior: 'smooth'});
|
||||
} catch (e) {
|
||||
showResult('加载节点池失败: ' + e.message);
|
||||
}
|
||||
}
|
||||
|
||||
async function createPool() {
|
||||
@@ -1423,23 +1459,20 @@ def index():
|
||||
if (!name) return showResult('请输入池名称', 'info');
|
||||
if (poolSelectedIds.size === 0) return showResult('请先搜索并选择节点', 'info');
|
||||
try {
|
||||
const resp = await fetch('/api/pools', {
|
||||
method: 'POST',
|
||||
const isEditing = !!editingPoolId;
|
||||
const url = isEditing ? `/api/pools/${encodeURIComponent(editingPoolId)}` : '/api/pools';
|
||||
const resp = await fetch(url, {
|
||||
method: isEditing ? 'PUT' : 'POST',
|
||||
headers: {'Content-Type': 'application/json'},
|
||||
body: JSON.stringify({name, node_ids: [...poolSelectedIds]})
|
||||
});
|
||||
const data = await resp.json();
|
||||
if (!resp.ok) throw new Error(data.error);
|
||||
showResult(`节点池"${name}"创建成功, ${data.node_ids.length} 个节点`, 'success');
|
||||
document.getElementById('poolName').value = '';
|
||||
document.getElementById('poolSearch').value = '';
|
||||
document.getElementById('poolSearchResults').innerHTML = '';
|
||||
document.getElementById('poolSelectedNodes').innerHTML = '';
|
||||
poolSelectedIds.clear();
|
||||
updatePoolSelectedCount();
|
||||
showResult(`节点池"${name}"${isEditing ? '修改' : '创建'}成功, ${data.node_ids.length} 个节点`, 'success');
|
||||
resetPoolEditor();
|
||||
loadPools();
|
||||
} catch (e) {
|
||||
showResult('创建失败: ' + e.message);
|
||||
showResult((editingPoolId ? '修改失败: ' : '创建失败: ') + e.message);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1488,6 +1521,7 @@ def index():
|
||||
<div class="api-url" style="margin-top:4px;font-size:12px">${apiUrl}</div>
|
||||
</div>
|
||||
<button class="btn" onclick="getRandomFromPool('${p.id}')" style="margin-left:10px;padding:8px 12px">随机获取</button>
|
||||
<button class="btn btn-success" onclick="editPool('${p.id}')" style="margin-left:5px;padding:8px 12px">修改</button>
|
||||
<button class="btn btn-danger" onclick="deletePool('${p.id}')" style="margin-left:5px;padding:8px 12px">删除</button>
|
||||
</div>`;
|
||||
}).join('');
|
||||
|
||||
Reference in New Issue
Block a user