59 lines
1.5 KiB
Vue
59 lines
1.5 KiB
Vue
<script>
|
||
import {
|
||
BASE_API_URL,
|
||
BASE_IMG_URL
|
||
} from "@/config.js";
|
||
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: BASE_API_URL + "/api/front/wechat/authorize/login",
|
||
method: "POST",
|
||
data: { code },
|
||
header: {
|
||
"Content-Type": "application/x-www-form-urlencoded", // 关键配置
|
||
},
|
||
});
|
||
if (res.data.status == 400) {
|
||
// 1. 显示无按钮的 Toast(无法关闭)
|
||
uni.showToast({
|
||
title: res.data.message,
|
||
icon: 'none',
|
||
duration: 9999999, // 极长时间,相当于不自动关闭
|
||
mask: true, // 透明遮罩层,阻止触摸
|
||
});
|
||
}
|
||
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>
|