From dd7a4795fc8d5618de7cba2e50e781f3a3091f6b Mon Sep 17 00:00:00 2001 From: wangtaocs Date: Wed, 27 Nov 2024 17:51:23 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20:sparkles:=20=E5=B0=8F=E7=A8=8B?= =?UTF-8?q?=E5=BA=8F=E7=AB=AF=E5=AE=9E=E7=8E=B0=E5=BE=AE=E4=BF=A1=E7=99=BB?= =?UTF-8?q?=E5=BD=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 4 +++- src/api/auth/index.ts | 17 +++++++++++++++++ src/pages/login/index.vue | 35 +++++++++++++++++++++++++++++++++++ src/static/icons/icon_wx.png | Bin 0 -> 6285 bytes src/store/modules/user.ts | 17 +++++++++++++++++ 5 files changed, 72 insertions(+), 1 deletion(-) create mode 100644 src/static/icons/icon_wx.png 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", + }); + } +};