47 lines
1.1 KiB
Vue
47 lines
1.1 KiB
Vue
<script>
|
||
export default {
|
||
onLaunch: function () {
|
||
console.log("App Launch");
|
||
uni.login({
|
||
success: (res) => {
|
||
if (res.code) {
|
||
this.loginWithPhoneNumber(res.code);
|
||
}
|
||
},
|
||
});
|
||
},
|
||
onShow: function () {
|
||
console.log("App Show");
|
||
},
|
||
onHide: function () {
|
||
console.log("App Hide");
|
||
},
|
||
methods: {
|
||
async loginWithPhoneNumber (code) {
|
||
try {
|
||
const res = await uni.request({
|
||
url: "https://online.totustec.com/api/api/front/wechat/authorize/login",
|
||
method: "POST",
|
||
data: { code },
|
||
header: {
|
||
"Content-Type": "application/x-www-form-urlencoded", // 关键配置
|
||
},
|
||
});
|
||
|
||
if (res.statusCode == 200) {
|
||
// 存储用户信息到本地缓存(uni-app接口)
|
||
uni.setStorageSync("userInfo", res.data);
|
||
// uni.showToast({ title: "登录成功" });
|
||
}
|
||
} catch (error) {
|
||
// uni.showToast({ title: "登录失败", icon: "none" });
|
||
}
|
||
},
|
||
},
|
||
};
|
||
</script>
|
||
|
||
<style>
|
||
/*每个页面公共css */
|
||
</style>
|