Skip to content

Commit d710841

Browse files
author
feige996
committed
refactor(登录): 将登录接口字段改为可选并添加登录逻辑
将登录接口的 code 和 uuid 字段改为可选,为后续对接真实登录接口做准备 在登录页面添加登录函数调用逻辑,并处理错误情况
1 parent 084f464 commit d710841

File tree

2 files changed

+27
-15
lines changed

2 files changed

+27
-15
lines changed

src/api/login.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ import { http } from '@/http/http'
77
export interface ILoginForm {
88
username: string
99
password: string
10-
code: string
11-
uuid: string
10+
code?: string
11+
uuid?: string
1212
}
1313

1414
/**

src/pages/login/login.vue

Lines changed: 25 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -26,23 +26,35 @@ onLoad((options) => {
2626
2727
const userStore = useUserStore()
2828
const tokenStore = useTokenStore()
29-
function doLogin() {
29+
async function doLogin() {
3030
if (tokenStore.hasLogin) {
3131
uni.navigateBack()
3232
return
3333
}
34-
userStore.setUserInfo({
35-
userId: 123456,
36-
username: 'abc123456',
37-
nickname: '菲鸽',
38-
avatar: 'https://oss.laf.run/ukw0y1-site/avatar.jpg',
39-
})
40-
// 这里用单token来模拟
41-
tokenStore.setTokenInfo({
42-
token: '123456',
43-
expiresIn: 60 * 60 * 24 * 7,
44-
})
45-
console.log(redirectUrl.value)
34+
try {
35+
// 1/2 调用接口回来后设置用户信息
36+
// const res = await login({
37+
// username: '菲鸽',
38+
// password: '123456',
39+
// })
40+
// console.log('接口拿到的登录信息:', res)
41+
userStore.setUserInfo({
42+
userId: 123456,
43+
username: 'abc123456',
44+
nickname: '菲鸽',
45+
avatar: 'https://oss.laf.run/ukw0y1-site/avatar.jpg',
46+
})
47+
// 2/2 调用接口回来后设置token信息
48+
// 这里用单token来模拟
49+
tokenStore.setTokenInfo({
50+
token: '123456',
51+
expiresIn: 60 * 60 * 24 * 7,
52+
})
53+
console.log(redirectUrl.value)
54+
}
55+
catch (error) {
56+
console.log('登录失败', error)
57+
}
4658
let path = redirectUrl.value
4759
if (!path.startsWith('/')) {
4860
path = `/${path}`

0 commit comments

Comments
 (0)