微信登录获取头像和昵称
This commit is contained in:
parent
d556337547
commit
bd2acf6d52
@ -1,7 +1,7 @@
|
||||
<template>
|
||||
<view class="loginbox">
|
||||
<view class="logintop">
|
||||
<image :src="`${imgPath}static/userui/wxloginbj.png`" style="width: 100%; height: 240px;" />
|
||||
<image :src="`${imgPath}static/userui/wxloginbj.png`" style="width: 100%; height: 240px;" />
|
||||
</view>
|
||||
<view class="loginbotton padding flex flex-direction">
|
||||
|
||||
@ -35,7 +35,7 @@
|
||||
class="phone-login-span">———————</span></view>
|
||||
<view class="phone-login-button">
|
||||
<view class="iconborder flex justify-center align-center" @click="redirectToPhoneLogin">
|
||||
<image :src="`${imgPath}static/userui/icon/phone.png`" alt="" />
|
||||
<image :src="`${imgPath}static/userui/icon/phone.png`" alt="" />
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
@ -50,6 +50,9 @@
|
||||
} from 'vue';
|
||||
import * as api from '@/utils/api.js';
|
||||
import config from '@/utils/config';
|
||||
import {
|
||||
showModelMessage
|
||||
} from '@/utils/tools.js';
|
||||
const imgPath = config.imgPath;
|
||||
const isAgreed = ref([]); // 用来控制复选框的选中状态
|
||||
const isloading = ref(false);
|
||||
@ -67,9 +70,10 @@
|
||||
url: '/pages/user/login/terms'
|
||||
});
|
||||
};
|
||||
onMounted(() => {})
|
||||
onLoad((options) => {
|
||||
onMounted(() => {
|
||||
|
||||
})
|
||||
onLoad((options) => {
|
||||
login();
|
||||
})
|
||||
|
||||
@ -85,10 +89,14 @@
|
||||
"get")
|
||||
.then((info) => {
|
||||
isloading.value = false;
|
||||
debugger;
|
||||
if (info.code == 200) {
|
||||
openid.value = wx.data;
|
||||
uni.setStorageSync('wechat_user', info.data);
|
||||
phone.value = info.data.mobile;
|
||||
if (!info.data.nickname) {
|
||||
updateUserProfile();
|
||||
}
|
||||
} else {
|
||||
let params = {
|
||||
"openid": wx.data,
|
||||
@ -100,6 +108,7 @@
|
||||
params.userId = re.data;
|
||||
uni.setStorageSync('wechat_user',
|
||||
params);
|
||||
updateUserProfile();
|
||||
}
|
||||
});
|
||||
}
|
||||
@ -125,6 +134,23 @@
|
||||
});
|
||||
}
|
||||
|
||||
// 获取头像和昵称并更新
|
||||
const updateUserProfile = () => {
|
||||
wx.getUserInfo({
|
||||
success: function(res) {
|
||||
console.log(res.userInfo.nickName); // 昵称
|
||||
console.log(res.userInfo.avatarUrl); // 头像URL
|
||||
let wechat_user = uni.getStorageSync('wechat_user');
|
||||
const params = {
|
||||
"userId": wechat_user.userId,
|
||||
"openid": openid.value,
|
||||
"nickname": res.userInfo.nickName,
|
||||
"avatar": res.userInfo.avatarUrl
|
||||
};
|
||||
api.callOrdereApi("ebikeUser/update", params);
|
||||
}
|
||||
});
|
||||
}
|
||||
const isAgreedChoose = () => {
|
||||
// 检查是否同意条款
|
||||
if (isAgreed.value.length == 0) {
|
||||
@ -178,18 +204,33 @@
|
||||
console.log('用户拒绝授权');
|
||||
return;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// 判断账号是否已经注销
|
||||
const isAccountDeactivated = () => {
|
||||
let wechat_user = uni.getStorageSync('wechat_user');
|
||||
if (wechat_user && wechat_user.status == -1) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
const wxlogin = () => {
|
||||
// 调用 wx.login 获取登录凭证 code
|
||||
isloading.value = true;
|
||||
setTimeout(() => {
|
||||
isloading.value = false;
|
||||
uni.switchTab({
|
||||
url: "/pages/user/home/home"
|
||||
})
|
||||
}, 1000);
|
||||
if (!isAccountDeactivated()) {
|
||||
showModelMessage("您的账户已经注销,请联系管理员!");
|
||||
} else {
|
||||
// 调用 wx.login 获取登录凭证 code
|
||||
isloading.value = true;
|
||||
setTimeout(() => {
|
||||
isloading.value = false;
|
||||
uni.switchTab({
|
||||
url: "/pages/user/home/home"
|
||||
})
|
||||
}, 1000);
|
||||
}
|
||||
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
@ -45,7 +45,7 @@
|
||||
{
|
||||
icon: `${imgPath}static/userui/icon/baoxiujilu.png`,
|
||||
label: '故障反馈',
|
||||
link: '/pages/user/login/TroubleReportUser'
|
||||
link: '/pages/user/login/TroubleReportUser?bikeCode=250306001002&orderCode=12039219893712864'
|
||||
},
|
||||
{
|
||||
icon: `${imgPath}static/userui/icon/baoxiujilu.png`,
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user