i0110 commited on
Commit
33ab2dd
·
verified ·
1 Parent(s): e158e46

Update public/index.html

Browse files
Files changed (1) hide show
  1. public/index.html +30 -4
public/index.html CHANGED
@@ -797,6 +797,7 @@
797
  document.getElementById('loginButton').style.display = 'none';
798
  document.getElementById('logoutButton').style.display = 'block';
799
  updateActionButtons(true);
 
800
  } else {
801
  console.log('登录失败:', data.message);
802
  loginError.textContent = data.message || '登录失败';
@@ -831,6 +832,7 @@
831
  document.getElementById('loginButton').style.display = 'block';
832
  document.getElementById('logoutButton').style.display = 'none';
833
  updateActionButtons(false);
 
834
  })
835
  .catch(error => {
836
  hideLoading();
@@ -840,6 +842,7 @@
840
  document.getElementById('loginButton').style.display = 'block';
841
  document.getElementById('logoutButton').style.display = 'none';
842
  updateActionButtons(false);
 
843
  });
844
  } else {
845
  console.log('本地无 token,直接设置为未登录');
@@ -847,6 +850,7 @@
847
  document.getElementById('loginButton').style.display = 'block';
848
  document.getElementById('logoutButton').style.display = 'none';
849
  updateActionButtons(false);
 
850
  }
851
  }
852
 
@@ -878,7 +882,7 @@
878
  console.log('页面加载完成,开始检查登录状态');
879
  await checkLoginStatus();
880
  console.log('登录状态检查完成,初始化数据');
881
- initialize();
882
  };
883
 
884
  // 二次确认弹窗逻辑
@@ -911,7 +915,13 @@
911
  async function getUsernames() {
912
  try {
913
  showLoading();
914
- const response = await fetch('/api/config');
 
 
 
 
 
 
915
  const config = await response.json();
916
  hideLoading();
917
  const usernamesList = config.usernames ? config.usernames.split(',').map(name => name.trim()).filter(name => name) : [];
@@ -937,13 +947,26 @@
937
  async function fetchInstances() {
938
  try {
939
  showLoading();
940
- const response = await fetch('/api/proxy/spaces');
 
 
 
 
 
 
 
 
941
  const instances = await response.json();
 
942
  hideLoading();
 
 
 
943
  return instances;
944
  } catch (error) {
945
  hideLoading();
946
  console.error("获取实例列表失败:", error);
 
947
  return [];
948
  }
949
  }
@@ -962,7 +985,10 @@
962
 
963
  this.subscribedInstances = new Set(subscribedInstances);
964
  const instancesParam = Array.from(this.subscribedInstances).join(',');
965
- const url = `/api/proxy/live-metrics-stream?instances=${encodeURIComponent(instancesParam)}`;
 
 
 
966
  this.eventSource = new EventSource(url);
967
 
968
  this.eventSource.addEventListener("metric", (event) => {
 
797
  document.getElementById('loginButton').style.display = 'none';
798
  document.getElementById('logoutButton').style.display = 'block';
799
  updateActionButtons(true);
800
+ refreshData(); // 登录成功后刷新数据以显示所有实例包括 private
801
  } else {
802
  console.log('登录失败:', data.message);
803
  loginError.textContent = data.message || '登录失败';
 
832
  document.getElementById('loginButton').style.display = 'block';
833
  document.getElementById('logoutButton').style.display = 'none';
834
  updateActionButtons(false);
835
+ refreshData(); // 登出后刷新数据以隐藏 private 实例
836
  })
837
  .catch(error => {
838
  hideLoading();
 
842
  document.getElementById('loginButton').style.display = 'block';
843
  document.getElementById('logoutButton').style.display = 'none';
844
  updateActionButtons(false);
845
+ refreshData(); // 登出后刷新数据以隐藏 private 实例
846
  });
847
  } else {
848
  console.log('本地无 token,直接设置为未登录');
 
850
  document.getElementById('loginButton').style.display = 'block';
851
  document.getElementById('logoutButton').style.display = 'none';
852
  updateActionButtons(false);
853
+ refreshData(); // 登出后刷新数据以隐藏 private 实例
854
  }
855
  }
856
 
 
882
  console.log('页面加载完成,开始检查登录状态');
883
  await checkLoginStatus();
884
  console.log('登录状态检查完成,初始化数据');
885
+ await initialize();
886
  };
887
 
888
  // 二次确认弹窗逻辑
 
915
  async function getUsernames() {
916
  try {
917
  showLoading();
918
+ const token = localStorage.getItem('authToken');
919
+ const headers = {};
920
+ if (token) {
921
+ headers['Authorization'] = `Bearer ${token}`;
922
+ console.log('getUsernames 请求中附加 Token:', token.slice(0, 8) + '...');
923
+ }
924
+ const response = await fetch('/api/config', { headers });
925
  const config = await response.json();
926
  hideLoading();
927
  const usernamesList = config.usernames ? config.usernames.split(',').map(name => name.trim()).filter(name => name) : [];
 
947
  async function fetchInstances() {
948
  try {
949
  showLoading();
950
+ const token = localStorage.getItem('authToken');
951
+ const headers = {};
952
+ if (token) {
953
+ headers['Authorization'] = `Bearer ${token}`;
954
+ console.log('fetchInstances 请求中附加 Token:', token.slice(0, 8) + '...');
955
+ } else {
956
+ console.log('无可用 Token,未附加 Authorization 头');
957
+ }
958
+ const response = await fetch('/api/proxy/spaces', { headers });
959
  const instances = await response.json();
960
+ console.log('从后端获取的实例列表:', instances);
961
  hideLoading();
962
+ if (instances.length === 0) {
963
+ alert('未获取到实例数据,可能是网络问题或数据暂不可用。');
964
+ }
965
  return instances;
966
  } catch (error) {
967
  hideLoading();
968
  console.error("获取实例列表失败:", error);
969
+ alert('获取实例列表失败,请稍后重试。');
970
  return [];
971
  }
972
  }
 
985
 
986
  this.subscribedInstances = new Set(subscribedInstances);
987
  const instancesParam = Array.from(this.subscribedInstances).join(',');
988
+ const token = localStorage.getItem('authToken');
989
+ // 由于 EventSource 不支持直接设置 Authorization 头,这里通过查询参数传递 token
990
+ const url = `/api/proxy/live-metrics-stream?instances=${encodeURIComponent(instancesParam)}&token=${encodeURIComponent(token || '')}`;
991
+ console.log('SSE 连接 URL:', url.split('&token=')[0] + (token ? '&token=... (隐藏)' : '&token=空'));
992
  this.eventSource = new EventSource(url);
993
 
994
  this.eventSource.addEventListener("metric", (event) => {