Your Name | 695f6a6 | 2025-05-17 00:58:04 +0800 | [diff] [blame^] | 1 | <!-- src/main/resources/static/home.html --> |
| 2 | <!DOCTYPE html> |
| 3 | <html lang="zh-CN"> |
| 4 | <head><meta charset="UTF-8"><title>首页</title></head> |
| 5 | <body> |
| 6 | <h1>欢迎访问受保护页面</h1> |
| 7 | <div id="userInfo"></div> |
| 8 | <script> |
| 9 | (async ()=>{ |
| 10 | const token = localStorage.getItem('token'); |
| 11 | if (!token) return window.location.href='login.html'; |
| 12 | const res = await fetch('/api/me', { |
| 13 | headers: { 'token': token } |
| 14 | }); |
| 15 | const json = await res.json(); |
| 16 | if (json.code!==0) { |
| 17 | return window.location.href='login.html'; |
| 18 | } |
| 19 | document.getElementById('userInfo') |
| 20 | .innerText = '当前用户:' + json.data.username; |
| 21 | })(); |
| 22 | </script> |
| 23 | </body> |
| 24 | </html> |