0xfei commited on
Commit
4e34fe9
·
verified ·
1 Parent(s): 18e3892

Upload index.html

Browse files
Files changed (1) hide show
  1. index.html +54 -6
index.html CHANGED
@@ -126,7 +126,12 @@
126
 
127
  <footer>
128
  <div class="price-info" id="live-price-text">价格预测中...</div>
129
- <div class="forecast-info" id="forecast-detail-text">---</div>
 
 
 
 
 
130
  </footer>
131
 
132
  <script>
@@ -134,39 +139,80 @@
134
  let lastFetchTimestamp = 0;
135
  const CACHE_TTL = 180; // 3分钟刷新逻辑
136
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
137
  async function fetchData() {
138
  const selectEl = document.getElementById('market-select');
139
  const market = selectEl.value;
140
  const marketUpper = market.toUpperCase();
141
 
142
- // 开启 UI 锁定
143
  const overlay = document.getElementById('loading-overlay');
144
  overlay.classList.remove('hidden');
145
  document.getElementById('loading-msg').innerText = `CALCULATING ${marketUpper} AI PATH...`;
 
146
  selectEl.disabled = true;
147
 
148
- // 更新看板标签
149
  document.getElementById('region-title').innerText = `${marketUpper} - 1h`;
150
  document.getElementById('watermark-text').innerText = `${marketUpper}`;
151
 
152
  try {
 
153
  const res = await fetch(API_BASE + market);
154
  const data = await res.json();
155
 
156
  if (data.status === "healthy" || data.status === "stale_updating") {
157
  lastFetchTimestamp = data.timestamp;
158
- updateSummaryPanel(data);
159
- renderProfessionalChart(data);
 
 
 
 
 
 
 
160
  }
161
  } catch (e) {
162
  console.error("Fetch Error:", e);
163
  document.getElementById('loading-msg').innerText = "NETWORK ERROR";
164
- } finally {
165
  overlay.classList.add('hidden');
166
  selectEl.disabled = false;
167
  }
168
  }
169
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
170
  function updateSummaryPanel(data) {
171
  // 1. 实时价格 (左侧)
172
  const hist = data.history;
@@ -277,6 +323,8 @@
277
  Plotly.newPlot('chart', traces, layout, config);
278
  }
279
 
 
 
280
  // 初始化
281
  fetchData();
282
  document.getElementById('market-select').onchange = fetchData;
 
126
 
127
  <footer>
128
  <div class="price-info" id="live-price-text">价格预测中...</div>
129
+ <div class="forecast-info">
130
+ <div id="forecast-detail-text">---</div>
131
+ <div id="ai-insight-text" style="color: var(--accent); font-size: 13px; margin-top: 4px; font-style: italic;">
132
+ AI 正在接入实时消息面进行修正...
133
+ </div>
134
+ </div>
135
  </footer>
136
 
137
  <script>
 
139
  let lastFetchTimestamp = 0;
140
  const CACHE_TTL = 180; // 3分钟刷新逻辑
141
 
142
+ // 新增:打字机效果函数,让快讯更有“生成感”
143
+ function typeWriter(text, element) {
144
+ element.innerText = "";
145
+ let i = 0;
146
+ const timer = setInterval(() => {
147
+ if (i < text.length) {
148
+ element.innerText += text.charAt(i);
149
+ i++;
150
+ } else {
151
+ clearInterval(timer);
152
+ }
153
+ }, 40); // 调整速度
154
+ }
155
+
156
  async function fetchData() {
157
  const selectEl = document.getElementById('market-select');
158
  const market = selectEl.value;
159
  const marketUpper = market.toUpperCase();
160
 
161
+ // UI 锁定与初始化状态
162
  const overlay = document.getElementById('loading-overlay');
163
  overlay.classList.remove('hidden');
164
  document.getElementById('loading-msg').innerText = `CALCULATING ${marketUpper} AI PATH...`;
165
+ document.getElementById('ai-insight-text').innerText = "AI 正在接入实时消息面进行修正...";
166
  selectEl.disabled = true;
167
 
 
168
  document.getElementById('region-title').innerText = `${marketUpper} - 1h`;
169
  document.getElementById('watermark-text').innerText = `${marketUpper}`;
170
 
171
  try {
172
+ // --- 步骤 1: 获取量化预测数据 (必须先完成) ---
173
  const res = await fetch(API_BASE + market);
174
  const data = await res.json();
175
 
176
  if (data.status === "healthy" || data.status === "stale_updating") {
177
  lastFetchTimestamp = data.timestamp;
178
+ updateSummaryPanel(data); // 更新基础统计文案
179
+ renderProfessionalChart(data); // 立即渲染图表
180
+
181
+ // 渲染完图表后,隐藏 Loading 遮罩
182
+ overlay.classList.add('hidden');
183
+ selectEl.disabled = false;
184
+
185
+ // --- 步骤 2: 异步请求 AI 快讯 (不阻塞 UI) ---
186
+ fetchAIInsight(market);
187
  }
188
  } catch (e) {
189
  console.error("Fetch Error:", e);
190
  document.getElementById('loading-msg').innerText = "NETWORK ERROR";
 
191
  overlay.classList.add('hidden');
192
  selectEl.disabled = false;
193
  }
194
  }
195
 
196
+ // 新增:独立获取 AI 洞察的函数
197
+ async function fetchAIInsight(market) {
198
+ const insightEl = document.getElementById('ai-insight-text');
199
+ try {
200
+ const res = await fetch(`/api/insight/${market}`);
201
+ const data = await res.json();
202
+
203
+ if (data.final_verdict) {
204
+ // 使用打字机效果展示生成的快讯内容
205
+ typeWriter(data.final_verdict, insightEl);
206
+ } else if (data.status === "loading") {
207
+ // 如果后端还没算完,可以短时间内重试一次
208
+ setTimeout(() => fetchAIInsight(market), 3000);
209
+ }
210
+ } catch (e) {
211
+ console.error("Insight Fetch Error:", e);
212
+ insightEl.innerText = "暂时无法获取 AI 修正建议";
213
+ }
214
+ }
215
+
216
  function updateSummaryPanel(data) {
217
  // 1. 实时价格 (左侧)
218
  const hist = data.history;
 
323
  Plotly.newPlot('chart', traces, layout, config);
324
  }
325
 
326
+
327
+
328
  // 初始化
329
  fetchData();
330
  document.getElementById('market-select').onchange = fetchData;