Files
toutoukan_front/miniprogram/pages/user-login/user-login.ts

38 lines
1.1 KiB
TypeScript
Raw Normal View History

2025-08-09 17:41:14 +08:00
Component({
data: {
image: 'https://tdesign.gtimg.com/mobile/demos/avatar1.png',
},
methods: {
wxPhone(e: { detail: any; }){
console.log("授权回调结果:", e.detail);
if (e.detail.errMsg === "getPhoneNumber:ok") {
const { encryptedData, iv, code } = e.detail;
wx.request({
url: "http://localhost:9096/user/login",
method: "POST",
data: {
encryptedData,
iv,
code,
},
success(res) {
if (res.data.success) {
// 登录成功,存储用户信息并跳转首页
wx.setStorageSync("userInfo", res.data.userInfo);
wx.navigateTo({ url: "/pages/index/index" });
} else {
wx.showToast({ title: "登录失败", icon: "none" });
}
},
fail() {
wx.showToast({ title: "网络错误", icon: "none" });
}
});
} else {
// 用户拒绝授权
wx.showToast({ title: "请允许授权以完成登录", icon: "none" });
}
}
},
})