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