refactor(auth): 临时修改登录逻辑以支持任意输入
为了在开发阶段方便测试,暂时将登录逻辑修改为支持任意输入并模拟用户数据。此更改不影响生产环境,仅为临时解决方案。
Showing
1 changed file
with
43 additions
and
11 deletions
| ... | @@ -127,6 +127,40 @@ const password = ref('password123') | ... | @@ -127,6 +127,40 @@ const password = ref('password123') |
| 127 | const error = ref('') | 127 | const error = ref('') |
| 128 | const loading = ref(false) | 128 | const loading = ref(false) |
| 129 | 129 | ||
| 130 | +// 原登录逻辑 | ||
| 131 | +// const handleSubmit = async () => { | ||
| 132 | +// if (!email.value || !password.value) { | ||
| 133 | +// error.value = '请填写所有字段' | ||
| 134 | +// return | ||
| 135 | +// } | ||
| 136 | + | ||
| 137 | +// try { | ||
| 138 | +// error.value = '' | ||
| 139 | +// loading.value = true | ||
| 140 | + | ||
| 141 | +// // 调用登录接口 | ||
| 142 | +// const response = await loginAPI({ | ||
| 143 | +// email: email.value, | ||
| 144 | +// password: password.value | ||
| 145 | +// }) | ||
| 146 | + | ||
| 147 | +// if (response.code !== 1) { | ||
| 148 | +// error.value = response.msg || '登录失败,请检查您的凭据' | ||
| 149 | +// return | ||
| 150 | +// } | ||
| 151 | + | ||
| 152 | +// // 登录成功,更新auth状态 | ||
| 153 | +// const success = login(response.data) | ||
| 154 | + | ||
| 155 | +// if (success) { | ||
| 156 | +// // 如果有重定向参数,登录成功后跳转到对应页面 | ||
| 157 | +// const redirect = $route.query.redirect | ||
| 158 | +// router.push(redirect || '/') | ||
| 159 | +// } else { | ||
| 160 | +// error.value = '登录失败,请检查您的凭据' | ||
| 161 | +// } | ||
| 162 | + | ||
| 163 | +// 临时登录逻辑 - 支持任意输入 | ||
| 130 | const handleSubmit = async () => { | 164 | const handleSubmit = async () => { |
| 131 | if (!email.value || !password.value) { | 165 | if (!email.value || !password.value) { |
| 132 | error.value = '请填写所有字段' | 166 | error.value = '请填写所有字段' |
| ... | @@ -137,22 +171,20 @@ const handleSubmit = async () => { | ... | @@ -137,22 +171,20 @@ const handleSubmit = async () => { |
| 137 | error.value = '' | 171 | error.value = '' |
| 138 | loading.value = true | 172 | loading.value = true |
| 139 | 173 | ||
| 140 | - // 调用登录接口 | 174 | + // 构造默认用户数据 |
| 141 | - const response = await loginAPI({ | 175 | + const mockUserData = { |
| 176 | + id: 1, | ||
| 177 | + name: '测试用户', | ||
| 142 | email: email.value, | 178 | email: email.value, |
| 143 | - password: password.value | 179 | + avatar: 'https://cdn.ipadbiz.cn/mlaj/images/user-avatar-2.jpg', |
| 144 | - }) | 180 | + checkInDays: 3, |
| 145 | - | 181 | + completedCourses: 12 |
| 146 | - if (response.code !== 1) { | ||
| 147 | - error.value = response.msg || '登录失败,请检查您的凭据' | ||
| 148 | - return | ||
| 149 | } | 182 | } |
| 150 | 183 | ||
| 151 | - // 登录成功,更新auth状态 | 184 | + // 模拟登录成功 |
| 152 | - const success = login(response.data) | 185 | + const success = login(mockUserData) |
| 153 | 186 | ||
| 154 | if (success) { | 187 | if (success) { |
| 155 | - // 如果有重定向参数,登录成功后跳转到对应页面 | ||
| 156 | const redirect = $route.query.redirect | 188 | const redirect = $route.query.redirect |
| 157 | router.push(redirect || '/') | 189 | router.push(redirect || '/') |
| 158 | } else { | 190 | } else { | ... | ... |
-
Please register or login to post a comment