quick-test.html 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227
  1. <!DOCTYPE html>
  2. <html lang="zh-CN">
  3. <head>
  4. <meta charset="UTF-8">
  5. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  6. <title>一键测试401跳转</title>
  7. <style>
  8. * { margin: 0; padding: 0; box-sizing: border-box; }
  9. body {
  10. font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  11. background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  12. min-height: 100vh;
  13. display: flex;
  14. align-items: center;
  15. justify-content: center;
  16. padding: 20px;
  17. }
  18. .container {
  19. background: white;
  20. border-radius: 16px;
  21. box-shadow: 0 20px 60px rgba(0,0,0,0.3);
  22. padding: 40px;
  23. max-width: 600px;
  24. width: 100%;
  25. }
  26. h1 {
  27. color: #2c3e50;
  28. margin-bottom: 10px;
  29. font-size: 28px;
  30. }
  31. .subtitle {
  32. color: #7f8c8d;
  33. margin-bottom: 30px;
  34. font-size: 14px;
  35. }
  36. .test-box {
  37. background: #f8f9fa;
  38. border-radius: 12px;
  39. padding: 25px;
  40. margin: 20px 0;
  41. border: 2px solid #e9ecef;
  42. }
  43. .test-box h3 {
  44. color: #495057;
  45. margin-bottom: 15px;
  46. font-size: 18px;
  47. }
  48. .test-box p {
  49. color: #6c757d;
  50. margin-bottom: 15px;
  51. line-height: 1.6;
  52. }
  53. button {
  54. width: 100%;
  55. padding: 16px;
  56. font-size: 16px;
  57. font-weight: 600;
  58. cursor: pointer;
  59. border: none;
  60. border-radius: 8px;
  61. transition: all 0.3s;
  62. text-transform: uppercase;
  63. letter-spacing: 0.5px;
  64. }
  65. .btn-primary {
  66. background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  67. color: white;
  68. }
  69. .btn-primary:hover {
  70. transform: translateY(-2px);
  71. box-shadow: 0 10px 20px rgba(102, 126, 234, 0.4);
  72. }
  73. .btn-success {
  74. background: linear-gradient(135deg, #11998e 0%, #38ef7d 100%);
  75. color: white;
  76. }
  77. .btn-success:hover {
  78. transform: translateY(-2px);
  79. box-shadow: 0 10px 20px rgba(17, 153, 142, 0.4);
  80. }
  81. .status {
  82. margin-top: 20px;
  83. padding: 15px;
  84. border-radius: 8px;
  85. font-size: 14px;
  86. display: none;
  87. }
  88. .status.show {
  89. display: block;
  90. }
  91. .status.info {
  92. background: #d1ecf1;
  93. color: #0c5460;
  94. border: 1px solid #bee5eb;
  95. }
  96. .status.success {
  97. background: #d4edda;
  98. color: #155724;
  99. border: 1px solid #c3e6cb;
  100. }
  101. .status.error {
  102. background: #f8d7da;
  103. color: #721c24;
  104. border: 1px solid #f5c6cb;
  105. }
  106. .countdown {
  107. font-size: 48px;
  108. font-weight: bold;
  109. text-align: center;
  110. margin: 20px 0;
  111. color: #667eea;
  112. }
  113. .steps {
  114. background: #fff3cd;
  115. border: 1px solid #ffeaa7;
  116. border-radius: 8px;
  117. padding: 15px;
  118. margin: 20px 0;
  119. }
  120. .steps h4 {
  121. color: #856404;
  122. margin-bottom: 10px;
  123. }
  124. .steps ol {
  125. margin-left: 20px;
  126. color: #856404;
  127. }
  128. .steps li {
  129. margin: 5px 0;
  130. }
  131. </style>
  132. </head>
  133. <body>
  134. <div class="container">
  135. <h1>🚀 一键测试401跳转</h1>
  136. <p class="subtitle">快速验证前端401响应处理是否正常</p>
  137. <div class="steps">
  138. <h4>⚠️ 测试前确认:</h4>
  139. <ol>
  140. <li>前端开发服务器正在运行</li>
  141. <li>已重启服务器并清除浏览器缓存</li>
  142. <li>后台服务正常运行</li>
  143. </ol>
  144. </div>
  145. <div class="test-box">
  146. <h3>测试1: 基本跳转功能</h3>
  147. <p>测试 window.location.href 是否能正常跳转到登录页</p>
  148. <button class="btn-primary" onclick="test1()">开始测试</button>
  149. <div id="status1" class="status"></div>
  150. <div id="countdown1" class="countdown"></div>
  151. </div>
  152. <div class="test-box">
  153. <h3>测试2: 完整401流程</h3>
  154. <p>设置无效token并刷新页面,测试完整的401处理流程</p>
  155. <button class="btn-success" onclick="test2()">开始测试</button>
  156. <div id="status2" class="status"></div>
  157. <div id="countdown2" class="countdown"></div>
  158. </div>
  159. </div>
  160. <script>
  161. function showStatus(id, message, type) {
  162. const status = document.getElementById(id);
  163. status.textContent = message;
  164. status.className = `status show ${type}`;
  165. }
  166. function showCountdown(id, seconds, callback) {
  167. const countdown = document.getElementById(id);
  168. countdown.textContent = seconds;
  169. const timer = setInterval(() => {
  170. seconds--;
  171. countdown.textContent = seconds;
  172. if (seconds <= 0) {
  173. clearInterval(timer);
  174. countdown.textContent = '';
  175. callback();
  176. }
  177. }, 1000);
  178. }
  179. function test1() {
  180. console.log('=== 测试1: 基本跳转功能 ===');
  181. showStatus('status1', '准备跳转到登录页...', 'info');
  182. showCountdown('countdown1', 3, () => {
  183. console.log('执行跳转: window.location.href = "/login"');
  184. showStatus('status1', '正在跳转...', 'success');
  185. window.location.href = '/login';
  186. });
  187. }
  188. function test2() {
  189. console.log('=== 测试2: 完整401流程 ===');
  190. // 设置无效token
  191. console.log('步骤1: 设置无效token');
  192. localStorage.setItem('sso_access_token', 'invalid_token_for_test_' + Date.now());
  193. showStatus('status2', '已设置无效token,准备刷新页面...', 'info');
  194. showCountdown('countdown2', 3, () => {
  195. console.log('步骤2: 刷新页面');
  196. showStatus('status2', '正在刷新页面...', 'success');
  197. console.log('页面刷新后应该自动跳转到登录页');
  198. location.reload();
  199. });
  200. }
  201. // 页面加载时的提示
  202. window.addEventListener('load', () => {
  203. console.log('=== 401跳转测试页面已加载 ===');
  204. console.log('请点击按钮开始测试');
  205. console.log('');
  206. console.log('测试1: 验证基本跳转功能');
  207. console.log('测试2: 验证完整401处理流程');
  208. console.log('');
  209. console.log('如果测试1成功但测试2失败,说明前端代码有问题');
  210. console.log('如果测试1失败,说明浏览器阻止了跳转');
  211. });
  212. </script>
  213. </body>
  214. </html>