totustec-unipp/App.vue
2025-07-16 10:06:24 +08:00

51 lines
1.1 KiB
Vue
Raw 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.statusCode == 200) {
// 存储用户信息到本地缓存uni-app接口
uni.setStorageSync("userInfo", res.data);
// uni.showToast({ title: "登录成功" });
}
} catch (error) {
// uni.showToast({ title: "登录失败", icon: "none" });
}
},
},
};
</script>
<style>
/*每个页面公共css */
</style>