diff --git a/.gitignore b/.gitignore index d8e76d9..2752e69 100644 --- a/.gitignore +++ b/.gitignore @@ -19,4 +19,6 @@ dist *.ntvs* *.njsproj *.sln -*.sw? \ No newline at end of file +*.sw? +.hbuilderx +pnpm-lock.yaml \ No newline at end of file diff --git a/src/api/auth/index.ts b/src/api/auth/index.ts index c36e587..12c7a62 100644 --- a/src/api/auth/index.ts +++ b/src/api/auth/index.ts @@ -20,6 +20,23 @@ const AuthAPI = { }); }, + /** + * 微信登录接口 + * + * @param code 微信登录code + * @returns 返回 token + */ + wxlogin(code: string): Promise { + return request({ + url: "/api/v1/auth/wxlogin", + method: "POST", + data: { code }, + header: { + "Content-Type": "application/x-www-form-urlencoded", + }, + }); + }, + /** * 登出接口 */ diff --git a/src/pages/login/index.vue b/src/pages/login/index.vue index 25791a6..da1a4c4 100644 --- a/src/pages/login/index.vue +++ b/src/pages/login/index.vue @@ -28,6 +28,12 @@ 提交 +
+
+ + 微信登录 +
+
@@ -71,6 +77,35 @@ const handleLogin = () => { } }); }; + +// 微信登录处理 +const handleWechatLogin = async () => { + try { + // 获取微信登录的临时 code + const { code } = await uni.login({ + provider: "weixin", + }); + + // 调用后端接口进行登录认证 + const result = await userStore.loginByWechat(code); + + if (result) { + // 获取用户信息 + await userStore.getInfo(); + + uni.showToast({ + title: "登录成功", + icon: "success", + }); + } + } catch (error: any) { + console.error("微信登录失败", error); + uni.showToast({ + title: error.message || "微信登录失败", + icon: "none", + }); + } +};