diff --git a/src/api/login.ts b/src/api/login.ts index 67100c2..7691c9b 100644 --- a/src/api/login.ts +++ b/src/api/login.ts @@ -7,8 +7,6 @@ import { http } from '@/http/http' export interface ILoginForm { username: string password: string - code?: string - uuid?: string } /** diff --git a/src/pages/login/login.vue b/src/pages/login/login.vue index e68ae03..b896db6 100644 --- a/src/pages/login/login.vue +++ b/src/pages/login/login.vue @@ -32,27 +32,11 @@ async function doLogin() { return } try { - // 有的时候后端会用一个接口返回token和用户信息,有的时候会分开2个接口(各有利弊,看业务场景和系统复杂度),这里使用2个接口返回的来模拟 - // 1/2 调用接口回来后设置token信息 - // 这里用单token来模拟 - tokenStore.setTokenInfo({ - token: '123456', - expiresIn: 60 * 60 * 24 * 7, + // 调用登录接口 + await tokenStore.login({ + username: '菲鸽', + password: '123456', }) - - // 2/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', - }) - console.log(redirectUrl.value) } catch (error) { diff --git a/src/pages/me/me.vue b/src/pages/me/me.vue index a74fb6f..4e708dc 100644 --- a/src/pages/me/me.vue +++ b/src/pages/me/me.vue @@ -34,9 +34,9 @@ const { run: uploadAvatar } = useUpload( // 微信小程序下登录 async function handleLogin() { // #ifdef MP-WEIXIN - // 微信登录 await tokenStore.wxLogin() + // #endif // #ifndef MP-WEIXIN uni.navigateTo({ diff --git a/src/store/token.ts b/src/store/token.ts index 1425f23..363dc2b 100644 --- a/src/store/token.ts +++ b/src/store/token.ts @@ -1,3 +1,6 @@ +import type { + ILoginForm, +} from '@/api/login' import type { IAuthLoginRes } from '@/api/types/login' import { defineStore } from 'pinia' import { computed, ref } from 'vue' // 修复:导入 computed @@ -93,17 +96,14 @@ export const useTokenStore = defineStore( /** * 用户登录 - * @param credentials 登录参数 + * 有的时候后端会用一个接口返回token和用户信息,有的时候会分开2个接口,一个获取token,一个获取用户信息 + * (各有利弊,看业务场景和系统复杂度),这里使用2个接口返回的来模拟 + * @param loginForm 登录参数 * @returns 登录结果 */ - const login = async (credentials: { - username: string - password: string - code: string - uuid: string - }) => { + const login = async (loginForm: ILoginForm) => { try { - const res = await _login(credentials) + const res = await _login(loginForm) console.log('普通登录-res: ', res) await _postLogin(res) uni.showToast({ @@ -124,6 +124,8 @@ export const useTokenStore = defineStore( /** * 微信登录 + * 有的时候后端会用一个接口返回token和用户信息,有的时候会分开2个接口,一个获取token,一个获取用户信息 + * (各有利弊,看业务场景和系统复杂度),这里使用2个接口返回的来模拟 * @returns 登录结果 */ const wxLogin = async () => {