refactor(登录): 将登录接口字段改为可选并添加登录逻辑

将登录接口的 code 和 uuid 字段改为可选,为后续对接真实登录接口做准备
在登录页面添加登录函数调用逻辑,并处理错误情况
This commit is contained in:
feige996
2025-09-07 17:39:37 +08:00
parent 084f46407a
commit d7108419ad
2 changed files with 27 additions and 15 deletions

View File

@@ -7,8 +7,8 @@ import { http } from '@/http/http'
export interface ILoginForm {
username: string
password: string
code: string
uuid: string
code?: string
uuid?: string
}
/**

View File

@@ -26,23 +26,35 @@ onLoad((options) => {
const userStore = useUserStore()
const tokenStore = useTokenStore()
function doLogin() {
async function doLogin() {
if (tokenStore.hasLogin) {
uni.navigateBack()
return
}
userStore.setUserInfo({
userId: 123456,
username: 'abc123456',
nickname: '菲鸽',
avatar: 'https://oss.laf.run/ukw0y1-site/avatar.jpg',
})
// 这里用单token来模拟
tokenStore.setTokenInfo({
token: '123456',
expiresIn: 60 * 60 * 24 * 7,
})
console.log(redirectUrl.value)
try {
// 1/2 调用接口回来后设置用户信息
// const res = await login({
// username: '菲鸽',
// password: '123456',
// })
// console.log('接口拿到的登录信息:', res)
userStore.setUserInfo({
userId: 123456,
username: 'abc123456',
nickname: '菲鸽',
avatar: 'https://oss.laf.run/ukw0y1-site/avatar.jpg',
})
// 2/2 调用接口回来后设置token信息
// 这里用单token来模拟
tokenStore.setTokenInfo({
token: '123456',
expiresIn: 60 * 60 * 24 * 7,
})
console.log(redirectUrl.value)
}
catch (error) {
console.log('登录失败', error)
}
let path = redirectUrl.value
if (!path.startsWith('/')) {
path = `/${path}`