aigems commited on
Commit
618974d
·
1 Parent(s): 8801327
Files changed (1) hide show
  1. public/js/main.js +9 -2
public/js/main.js CHANGED
@@ -15,6 +15,7 @@ async function executeCommand() {
15
  if (!command.trim()) return;
16
 
17
  showLoading(true);
 
18
  appendToOutput('$ ' + command, 'text-blue-400');
19
  appendToOutput('正在执行命令...', 'text-yellow-400');
20
 
@@ -49,11 +50,15 @@ async function executeCommand() {
49
  }
50
 
51
  const data = await response.json();
 
 
52
  appendToOutput(data.output || data.error || '命令执行成功,但没有输出。', 'text-green-400');
53
  commandInput.value = '';
54
  loadCommandHistory();
55
  } catch (error) {
56
  console.error('执行命令时出错:', error);
 
 
57
  appendToOutput('错误: ' + (error.message || '未知错误'), 'text-red-500');
58
  if (error.message.includes('Token 刷新失败')) {
59
  showNotification('访问被拒绝。请重新登录。', 'error');
@@ -67,6 +72,10 @@ async function executeCommand() {
67
  }
68
  }
69
 
 
 
 
 
70
  function appendToOutput(text, className = 'text-green-400') {
71
  const lines = text.split('\n');
72
  lines.forEach((line, index) => {
@@ -86,7 +95,6 @@ async function loadCommandHistory() {
86
  }
87
  });
88
  const data = await response.json();
89
- console.log('命令历史数据:', data); // 添加调试信息
90
  history.innerHTML = '';
91
  data.reverse().forEach(item => {
92
  const li = document.createElement('li');
@@ -98,7 +106,6 @@ async function loadCommandHistory() {
98
  `;
99
  li.className = 'cursor-pointer';
100
  li.onclick = () => {
101
- console.log(`Clicked on command: ${item.command}`); // 添加调试信息
102
  commandInput.value = item.command;
103
  commandInput.focus();
104
  };
 
15
  if (!command.trim()) return;
16
 
17
  showLoading(true);
18
+ clearOutput();
19
  appendToOutput('$ ' + command, 'text-blue-400');
20
  appendToOutput('正在执行命令...', 'text-yellow-400');
21
 
 
50
  }
51
 
52
  const data = await response.json();
53
+ clearOutput();
54
+ appendToOutput('$ ' + command, 'text-blue-400');
55
  appendToOutput(data.output || data.error || '命令执行成功,但没有输出。', 'text-green-400');
56
  commandInput.value = '';
57
  loadCommandHistory();
58
  } catch (error) {
59
  console.error('执行命令时出错:', error);
60
+ clearOutput();
61
+ appendToOutput('$ ' + command, 'text-blue-400');
62
  appendToOutput('错误: ' + (error.message || '未知错误'), 'text-red-500');
63
  if (error.message.includes('Token 刷新失败')) {
64
  showNotification('访问被拒绝。请重新登录。', 'error');
 
72
  }
73
  }
74
 
75
+ function clearOutput() {
76
+ output.innerHTML = '';
77
+ }
78
+
79
  function appendToOutput(text, className = 'text-green-400') {
80
  const lines = text.split('\n');
81
  lines.forEach((line, index) => {
 
95
  }
96
  });
97
  const data = await response.json();
 
98
  history.innerHTML = '';
99
  data.reverse().forEach(item => {
100
  const li = document.createElement('li');
 
106
  `;
107
  li.className = 'cursor-pointer';
108
  li.onclick = () => {
 
109
  commandInput.value = item.command;
110
  commandInput.focus();
111
  };