| | |
| | | <div class="login-container"> |
| | | <div class="login-box"> |
| | | <div class="login-header"> |
| | | <img src="/logo.jpg" alt="蓉易创Logo" class="logo" /> |
| | | <h2>蓉易创管理系统</h2> |
| | | <p>比赛管理平台</p> |
| | | </div> |
| | |
| | | import { useRouter } from 'vue-router' |
| | | import { ElMessage } from 'element-plus' |
| | | import type { FormInstance, FormRules } from 'element-plus' |
| | | import { loginApi } from '@/utils/graphql' |
| | | // import { loginApi } from '@/utils/graphql' |
| | | import { setToken, setUserInfo } from '@/utils/auth' |
| | | |
| | | const router = useRouter() |
| | |
| | | await loginFormRef.value.validate() |
| | | loading.value = true |
| | | |
| | | // 调用登录API |
| | | const response = await loginApi({ |
| | | phone: loginForm.phone, |
| | | password: loginForm.password |
| | | // 调用RESTful登录API |
| | | const response = await fetch('/api/auth/web-login', { |
| | | method: 'POST', |
| | | headers: { |
| | | 'Content-Type': 'application/json' |
| | | }, |
| | | body: JSON.stringify({ |
| | | phone: loginForm.phone, |
| | | password: loginForm.password |
| | | }) |
| | | }) |
| | | |
| | | console.log('Response status:', response.status) |
| | | console.log('Response headers:', response.headers) |
| | | |
| | | // 检查响应是否为空 |
| | | const responseText = await response.text() |
| | | console.log('Response text:', responseText) |
| | | |
| | | if (!responseText) { |
| | | throw new Error('服务器返回空响应') |
| | | } |
| | | |
| | | let result |
| | | try { |
| | | result = JSON.parse(responseText) |
| | | } catch (jsonError) { |
| | | console.error('JSON解析错误:', jsonError) |
| | | console.error('响应内容:', responseText) |
| | | throw new Error('服务器响应格式错误') |
| | | } |
| | | |
| | | if (!response.ok) { |
| | | throw new Error(result.message || '登录失败') |
| | | } |
| | | |
| | | // 保存token和用户信息 |
| | | setToken(response.token) |
| | | setUserInfo(response.userInfo) |
| | | setToken(result.token) |
| | | setUserInfo(result.userInfo) |
| | | |
| | | ElMessage.success('登录成功') |
| | | router.push('/') |
| | |
| | | text-align: center; |
| | | margin-bottom: 30px; |
| | | |
| | | .logo { |
| | | width: 80px; |
| | | height: 80px; |
| | | object-fit: contain; |
| | | margin-bottom: 20px; |
| | | border-radius: 8px; |
| | | } |
| | | |
| | | h2 { |
| | | color: #303133; |
| | | font-size: 24px; |