feat: 优化控制台交互 - 移除冗余选项、添加自动执行和任务详情功能
This commit is contained in:
47
console.html
47
console.html
@@ -91,13 +91,17 @@
|
||||
<select id="taskType">
|
||||
<option value="ephemeral">即时任务 (Ephemeral)</option>
|
||||
<option value="persistent">持久任务 (Persistent)</option>
|
||||
<option value="scheduled">定时任务 (Scheduled)</option>
|
||||
</select>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label>任务描述 (Prompt)</label>
|
||||
<textarea id="taskPrompt" placeholder="输入任务描述..."></textarea>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label>
|
||||
<input type="checkbox" id="autoExecute" checked> 创建后自动执行
|
||||
</label>
|
||||
</div>
|
||||
<button class="btn" onclick="createTask()">创建任务</button>
|
||||
</div>
|
||||
<div class="card">
|
||||
@@ -121,6 +125,10 @@
|
||||
<tbody id="tasksTable"></tbody>
|
||||
</table>
|
||||
</div>
|
||||
<div class="card" id="taskDetailPanel" style="display: none;">
|
||||
<h2>任务详情</h2>
|
||||
<div id="taskDetailContent"></div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 定时任务 -->
|
||||
@@ -161,6 +169,7 @@
|
||||
<th>ID</th>
|
||||
<th>名称</th>
|
||||
<th>Cron</th>
|
||||
<th>状态</th>
|
||||
<th>提示词</th>
|
||||
<th>操作</th>
|
||||
</tr>
|
||||
@@ -322,6 +331,7 @@
|
||||
async function createTask() {
|
||||
const type = document.getElementById('taskType').value;
|
||||
const prompt = document.getElementById('taskPrompt').value;
|
||||
const autoExecute = document.getElementById('autoExecute').checked;
|
||||
if (!prompt) return alert('请输入任务描述');
|
||||
|
||||
try {
|
||||
@@ -334,6 +344,11 @@
|
||||
addLog('创建任务: ' + task.id, 'info');
|
||||
document.getElementById('taskPrompt').value = '';
|
||||
loadTasks();
|
||||
|
||||
if (autoExecute) {
|
||||
addLog('正在自动执行任务...', 'info');
|
||||
await executeTask(task.id, type === 'persistent');
|
||||
}
|
||||
} catch (e) {
|
||||
alert('创建失败: ' + e.message);
|
||||
}
|
||||
@@ -351,6 +366,7 @@
|
||||
<td>${t.prompt.substring(0, 30)}${t.prompt.length > 30 ? '...' : ''}</td>
|
||||
<td><span class="status-badge status-${t.status}">${t.status}</span></td>
|
||||
<td class="flex">
|
||||
<button class="btn" style="padding: 5px 10px; font-size: 12px;" onclick="viewTask('${t.id}')">详情</button>
|
||||
<button class="btn" style="padding: 5px 10px; font-size: 12px;" onclick="executeTask('${t.id}', false)">执行</button>
|
||||
<button class="btn btn-success" style="padding: 5px 10px; font-size: 12px;" onclick="executeTask('${t.id}', true)">异步</button>
|
||||
<button class="btn btn-danger" style="padding: 5px 10px; font-size: 12px;" onclick="abortTask('${t.id}')">中止</button>
|
||||
@@ -362,6 +378,32 @@
|
||||
}
|
||||
}
|
||||
|
||||
async function viewTask(taskId) {
|
||||
try {
|
||||
const res = await fetch(API_BASE + '/task/' + taskId);
|
||||
const task = await res.json();
|
||||
const panel = document.getElementById('taskDetailPanel');
|
||||
const content = document.getElementById('taskDetailContent');
|
||||
panel.style.display = 'block';
|
||||
content.innerHTML = `
|
||||
<div style="display: grid; grid-template-columns: 1fr 1fr; gap: 15px;">
|
||||
<div><strong>任务ID:</strong> ${task.id}</div>
|
||||
<div><strong>类型:</strong> ${task.type}</div>
|
||||
<div><strong>状态:</strong> <span class="status-badge status-${task.status}">${task.status}</span></div>
|
||||
<div><strong>Session ID:</strong> ${task.session_id || '-'}</div>
|
||||
<div style="grid-column: 1 / -1;"><strong>提示词:</strong> <pre style="background: #0f0f23; padding: 10px; border-radius: 4px; margin-top: 5px;">${task.prompt}</pre></div>
|
||||
${task.error ? `<div style="grid-column: 1 / -1; color: #ff4757;"><strong>错误信息:</strong> ${task.error}</div>` : ''}
|
||||
<div><strong>创建时间:</strong> ${task.created_at || '-'}</div>
|
||||
<div><strong>开始时间:</strong> ${task.started_at || '-'}</div>
|
||||
<div><strong>完成时间:</strong> ${task.finished_at || '-'}</div>
|
||||
</div>
|
||||
`;
|
||||
panel.scrollIntoView({behavior: 'smooth'});
|
||||
} catch (e) {
|
||||
alert('获取详情失败: ' + e.message);
|
||||
}
|
||||
}
|
||||
|
||||
async function executeTask(taskId, async_) {
|
||||
try {
|
||||
const endpoint = async_ ? '/execute_async' : '/execute';
|
||||
@@ -418,7 +460,8 @@
|
||||
<td>${s.id}</td>
|
||||
<td>${s.name || '-'}</td>
|
||||
<td>${s.cron}</td>
|
||||
<td>${(s.prompt || '').substring(0, 30)}...</td>
|
||||
<td><span class="status-badge status-${s.enabled ? 'completed' : 'pending'}">${s.enabled ? '已启用' : '已禁用'}</span></td>
|
||||
<td>${(s.prompt || '').substring(0, 30)}${(s.prompt || '').length > 30 ? '...' : ''}</td>
|
||||
<td>
|
||||
<button class="btn btn-danger" style="padding: 5px 10px; font-size: 12px;" onclick="deleteSchedule('${s.id}')">删除</button>
|
||||
</td>
|
||||
|
||||
Reference in New Issue
Block a user