项目初始化
This commit is contained in:
37
miniprogram/pages/user-login/user-login.ts
Normal file
37
miniprogram/pages/user-login/user-login.ts
Normal file
@@ -0,0 +1,37 @@
|
||||
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" });
|
||||
}
|
||||
}
|
||||
},
|
||||
})
|
||||
Reference in New Issue
Block a user