totustec-unipp/App.vue
2025-07-17 10:04:27 +08:00

59 lines
1.5 KiB
Vue
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<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>