<template>
|
<view>
|
<view class="wrap">
|
|
<image src="@/static/logo.png" mode="widthFix" class="tip_img"></image>
|
<view class="login_tip">
|
为了提供更优质的服务,需要获取您的头像和昵称。
|
</view>
|
<view class="login_btn">
|
<!-- #ifdef MP-WEIXIN || MP-QQ || MP-BAIDU -->
|
<button v-if="canIUseGetUserProfile" type="primary" class="uni-tip-button" @click="login">授权并登录</button>
|
<button v-else type="primary" open-type="getUserInfo" @getuserinfo="login"
|
class="uni-tip-button">授权并登录</button>
|
<view class="no_login" @click="back">
|
暂不授权
|
</view>
|
<!-- #endif -->
|
<checkbox-group @change="changeAgree">
|
<view class="regisiter-agreement">
|
|
<label>
|
<checkbox value="1" :checked="isChecked" color="#35A6FF" style="transform:scale(0.7)" />
|
|
已阅读并同意以下协议
|
<text class="color-base-text" @click.stop="openPopup(1)">《用户服务协议》</text>和 <text
|
class="color-base-text" @click.stop="openPopup(2)">《隐私政策》</text>
|
</label>
|
</view>
|
</checkbox-group>
|
</view>
|
<!-- <view class="mobile_login" @click="toMobileLogin">
|
同意并输入手机号登录
|
</view> -->
|
<!-- <view class="agreement_wrap">
|
<view class="agree_item">
|
<view class="item_icon" @click="isChecked = !isChecked">
|
<image v-if="!isChecked" :src="$util.img('upload/img/iconCheck.png')" mode="aspectFit"
|
class="item_select_img"></image>
|
<image v-else :src="$util.img('upload/img/publish-selected.png')" mode="aspectFit"
|
class="item_select_img"></image>
|
</view>
|
<view class="item_content">
|
首次登录自动注册运满满及货车帮账号,且已阅读并同意<text class="agreement">《用户服务协议》</text><text
|
class="agreement">《个人信息保护政策》</text><text class="agreement">《账号关联协议》</text>
|
</view>
|
</view>
|
<view class="agree_item">
|
<view class="item_icon" @click="isCheckedSan = !isCheckedSan">
|
<image v-if="!isCheckedSan" :src="$util.img('upload/img/iconCheck.png')" mode="aspectFit"
|
class="item_select_img"></image>
|
<image v-else :src="$util.img('upload/img/publish-selected.png')" mode="aspectFit"
|
class="item_select_img"></image>
|
</view>
|
<view class="item_content">
|
已阅读并同意<text class="agreement">《第三方合作清单》</text>
|
</view>
|
</view>
|
</view> -->
|
</view>
|
<u-popup ref="popup" type="center">
|
<view class="bind-wrap">
|
<!-- #ifdef MP-WEIXIN || MP-QQ || MP-BAIDU -->
|
<view class="heard">提示</view>
|
<view class="bind-tips">为了方便您接收通知消息,需要您完成授权</view>
|
<view class="auth-login ns-btn-default-all color-base-bg" @click="toWeb">
|
去授权
|
</view>
|
<!-- <button open-type="getPhoneNumber" class="auth-login ns-btn-default-all color-base-bg"
|
@getphonenumber="mobileAuthLogin"><text>点击绑定手机号码</text></button> -->
|
<!-- #endif -->
|
</view>
|
</u-popup>
|
<u-popup ref="bindMobile">
|
<view class="bind-wrap">
|
<!-- #ifdef MP-WEIXIN || MP-QQ || MP-BAIDU -->
|
<view class="heard">提示</view>
|
<view class="bind-tips">为了方便联系您,需要绑定您的手机号码</view>
|
<button open-type="getPhoneNumber" class="auth-login ns-btn-default-all color-base-bg"
|
@getphonenumber="mobileAuthLogin"><text>点击绑定手机号码</text></button>
|
<!-- #endif -->
|
</view>
|
</u-popup>
|
</view>
|
</template>
|
|
<script>
|
export default {
|
data() {
|
return {
|
isChecked: false,
|
isCheckedSan: false,
|
canIUseGetUserProfile: false
|
};
|
},
|
created() {
|
// #ifdef MP-WEIXIN
|
if (wx.getUserProfile) this.canIUseGetUserProfile = true;
|
// #endif
|
},
|
onShow() {
|
if (uni.getStorageSync('wx_openid_set') && uni.getStorageSync('wx_openid_set') == 1) {
|
uni.showLoading({
|
title: '加载中',
|
mask: true
|
})
|
this.$api.sendRequest({
|
url: '/api.php/user/info',
|
data: {
|
uid: uni.getStorageSync('authInfo').id
|
},
|
success: res => {
|
|
if (res.code == 1) {
|
// uni.hideLoading()
|
// if (res.data.openid) this.authInfo.weapp_openid = res.data.openid;
|
// if (res.data.unionid) this.authInfo.wx_unionid = res.data.unionid;
|
if (res.data.wx_openid) {
|
this.$util.showToast({
|
title: "登录成功",
|
icon: "success"
|
})
|
uni.setStorage({
|
key: 'uid',
|
data: res.data.id,
|
success: () => {
|
uni.removeStorageSync('wx_openid_set');
|
uni.removeStorageSync('source_member');
|
uni.removeStorageSync('authInfo');
|
this.$api.sendRequest({
|
url: "/api.php/user/is_perfect",
|
data: {
|
uid: res.data.id,
|
},
|
success: res => {
|
if (res.code == 1) {
|
console.log(res)
|
uni.setStorageSync(
|
'is_perfect_user', '1')
|
} else {
|
uni.setStorageSync(
|
'is_perfect_user', res.code
|
)
|
}
|
},
|
fail: res => {
|
this.$util.showToast({
|
title: "接口错误"
|
});
|
}
|
});
|
// this.$store.dispatch('getCartNumber');
|
setTimeout(() => {
|
this.$util.redirectTo(
|
'/pages/index/index', {},
|
'tabbar')
|
}, 1000)
|
}
|
});
|
} else {
|
this.$util.showToast({
|
title: '授权失败'
|
});
|
}
|
if (this.$refs.loadingCover) this.$refs.loadingCover.hide();
|
} else {
|
uni.removeStorageSync('uid')
|
this.$forceUpdate()
|
this.$util.showToast({
|
title: res.msg
|
});
|
if (this.$refs.loadingCover) this.$refs.loadingCover.hide();
|
}
|
}
|
})
|
}
|
},
|
methods: {
|
openPopup(type) {
|
this.$util.redirectTo('/otherPages/member/webView/webView', {
|
link: type
|
})
|
},
|
changeAgree(e) {
|
console.log(e)
|
if (e.detail.value.length > 0) {
|
this.isChecked = true
|
} else {
|
this.isChecked = false
|
}
|
},
|
toWeb() {
|
if (!this.isChecked) {
|
return this.$util.showToast({
|
title: "请先同意协议"
|
})
|
}
|
uni.setStorageSync('wx_openid_set', 1)
|
this.$util.redirectTo('/otherPages/member/webView/webView', {
|
uid: uni.getStorageSync('authInfo').id
|
})
|
},
|
back() {
|
uni.navigateBack()
|
},
|
toMobileLogin() {
|
if (!this.isChecked) {
|
return this.$util.showToast({
|
title: "请先同意协议"
|
})
|
}
|
this.$util.redirectTo('/otherPages/member/mobileLogin/mobileLogin')
|
},
|
mobileAuthLogin(e) {
|
console.log(e)
|
if (!this.isChecked) {
|
return this.$util.showToast({
|
title: "请先同意协议"
|
})
|
}
|
// return
|
if (e.detail.errMsg == 'getPhoneNumber:ok') {
|
let authData = uni.getStorageSync('authInfo');
|
console.log(authData)
|
var data = {
|
code: e.detail.code,
|
uid: authData.id
|
// iv: e.detail.iv,
|
// encryptedData: e.detail.encryptedData
|
};
|
console.log(e)
|
// if (Object.keys(authData).length) {
|
// Object.assign(data, authData);
|
// }
|
// if (authData.avatarUrl) data.headimg = authData.avatarUrl;
|
// if (authData.nickName) data.nickname = authData.nickName;
|
// if (uni.getStorageSync('source_member')) data.source_member = uni.getStorageSync('source_member');
|
|
if (this.isSub) return;
|
this.isSub = true;
|
|
this.$api.sendRequest({
|
url: '/api.php/login/binding_mobile',
|
data,
|
success: res => {
|
if (res.code == 1) {
|
console.log(res)
|
|
if (res.data.wx_openid) {
|
this.$util.showToast({
|
title: "登录成功",
|
icon: "success"
|
})
|
uni.setStorage({
|
key: 'uid',
|
data: res.data.id,
|
success: () => {
|
uni.removeStorageSync('wx_openid_set');
|
uni.removeStorageSync('source_member');
|
uni.removeStorageSync('authInfo');
|
this.$api.sendRequest({
|
url: "/api.php/user/is_perfect",
|
data: {
|
uid: res.data.id,
|
},
|
success: res => {
|
if (res.code == 1) {
|
console.log(res)
|
uni.setStorageSync(
|
'is_perfect_user', '1')
|
} else {
|
uni.setStorageSync(
|
'is_perfect_user', res
|
.code)
|
}
|
},
|
fail: res => {
|
this.$util.showToast({
|
title: "接口错误"
|
});
|
}
|
});
|
// this.$store.dispatch('getCartNumber');
|
setTimeout(() => {
|
this.$util.redirectTo(
|
'/pages/index/index', {},
|
'tabbar')
|
}, 1000)
|
}
|
});
|
} else {
|
this.$refs.bindMobile.close()
|
// uni.setStorageSync('wx_openid_set',1)
|
this.$refs.popup.open()
|
}
|
|
// this.$store.commit('setToken', res.data.token);
|
// this.$refs.bindMobile.close();
|
// if (res.data.is_register && this.$refs.registerReward.getReward()) {
|
// this.$refs.registerReward.open();
|
// }
|
} else {
|
this.isSub = false;
|
this.$util.showToast({
|
title: res.msg
|
});
|
}
|
},
|
fail: res => {
|
this.isSub = false;
|
this.$util.showToast({
|
title: 'request:fail'
|
});
|
}
|
});
|
}
|
},
|
getCode(userInfo, callback) {
|
uni.login({
|
provider: 'weixin',
|
timeout: 3000,
|
success: res => {
|
console.log(res)
|
let data = {
|
code: res.code,
|
nickname: userInfo.nickName,
|
avatar: userInfo.avatarUrl,
|
|
}
|
if (uni.getStorageSync('source_member')) {
|
data.source_member = uni.getStorageSync('source_member')
|
}
|
if (res.code) {
|
this.$api.sendRequest({
|
url: '/api.php/login/wx_login',
|
data,
|
success: res => {
|
if (res.code >= 0) {
|
// if (res.data.openid) this.authInfo.weapp_openid = res.data.openid;
|
// if (res.data.unionid) this.authInfo.wx_unionid = res.data.unionid;
|
typeof callback == 'function' && callback(res);
|
} else {
|
this.$util.showToast({
|
title: '小程序配置错误'
|
});
|
}
|
}
|
})
|
}
|
},
|
fail: () => {
|
this.$util.showToast({
|
title: '请求失败'
|
});
|
}
|
})
|
},
|
login(e) {
|
if (!this.isChecked) {
|
return this.$util.showToast({
|
title: "请先同意协议"
|
})
|
}
|
// if (!this.isChecked || !this.isCheckedSan) {
|
// this.$util.showToast({
|
// title: "请勾选用户注册/登录协议和第三方合作清单"
|
// })
|
// return
|
// }
|
// #ifdef MP-WEIXIN
|
if (this.canIUseGetUserProfile) {
|
wx.getUserProfile({
|
desc: '获取用户个人信息', // 声明获取用户个人信息后的用途,后续会展示在弹窗中,请谨慎填写
|
success: (res) => {
|
console.log(res)
|
if (res.errMsg == 'getUserProfile:ok') {
|
|
// this.authInfo.nickName = res.userInfo.nickName;
|
// this.authInfo.avatarUrl = res.userInfo.avatarUrl;
|
// uni.setStorageSync('authInfo', this.authInfo)
|
|
this.getCode(res.userInfo, data => {
|
console.log(data)
|
if (data.code == 1) {
|
uni.setStorageSync('authInfo', data.data)
|
if (!data.data.mobile) {
|
this.$refs.bindMobile.open()
|
} else {
|
if (data.data.wx_openid) {
|
this.$util.showToast({
|
title: "登录成功",
|
icon: "success"
|
})
|
uni.setStorage({
|
key: 'uid',
|
data: data.data.id,
|
success: () => {
|
uni.removeStorageSync(
|
'wx_openid_set');
|
uni.removeStorageSync(
|
'source_member');
|
uni.removeStorageSync('authInfo');
|
this.$api.sendRequest({
|
url: "/api.php/user/is_perfect",
|
data: {
|
uid: data.data.id,
|
},
|
success: res => {
|
if (res.code ==
|
1) {
|
console
|
.log(
|
res
|
)
|
uni.setStorageSync(
|
'is_perfect_user',
|
'1'
|
)
|
} else {
|
uni.setStorageSync(
|
'is_perfect_user',
|
res
|
.code
|
)
|
}
|
},
|
fail: res => {
|
this.$util
|
.showToast({
|
title: "接口错误"
|
});
|
}
|
});
|
// this.$store.dispatch('getCartNumber');
|
setTimeout(() => {
|
this.$util.redirectTo(
|
'/pages/index/index', {},
|
'tabbar')
|
}, 1000)
|
}
|
});
|
} else {
|
// uni.setStorageSync('wx_openid_set',1)
|
this.$refs.popup.open()
|
}
|
|
|
}
|
}
|
return
|
// if (data) {
|
// this.authLogin(data);
|
// } else {
|
// this.$refs.auth.close();
|
// this.toLogin();
|
// }
|
});
|
}
|
}
|
})
|
} else if (e.detail.errMsg == 'getUserInfo:ok') {
|
this.getCode(data => {
|
if (data.code == 1) {
|
uni.setStorageSync('authInfo', data.data)
|
if (!data.data.mobile) {
|
this.$refs.bindMobile.open()
|
} else {
|
if (data.data.wx_openid) {
|
this.$util.showToast({
|
title: "登录成功",
|
icon: "success"
|
})
|
uni.setStorage({
|
key: 'uid',
|
data: data.data.id,
|
success: () => {
|
uni.removeStorageSync('wx_openid_set');
|
uni.removeStorageSync('source_member');
|
uni.removeStorageSync('authInfo');
|
this.$api.sendRequest({
|
url: "/api.php/user/is_perfect",
|
data: {
|
uid: data.data.id,
|
},
|
success: res => {
|
if (res.code == 1) {
|
console.log(res)
|
uni.setStorageSync(
|
'is_perfect_user', '1')
|
} else {
|
uni.setStorageSync(
|
'is_perfect_user', res.code
|
)
|
}
|
},
|
fail: res => {
|
this.$util.showToast({
|
title: "接口错误"
|
});
|
}
|
});
|
// this.$store.dispatch('getCartNumber');
|
setTimeout(() => {
|
this.$util.redirectTo(
|
'/pages/index/index', {},
|
'tabbar')
|
}, 1000)
|
}
|
});
|
} else {
|
// uni.setStorageSync('wx_openid_set',1)
|
this.$refs.popup.open()
|
}
|
|
|
}
|
}
|
});
|
}
|
// #endif
|
// if (!uni.getStorageSync('wx_openid_set')) {
|
// // #ifdef MP-QQ || MP-BAIDU
|
// if (e.detail.errMsg == 'getUserInfo:ok') {
|
// this.getCode(data => {
|
// if (data) {
|
// this.authLogin(data);
|
// } else {
|
// this.$refs.auth.close();
|
// this.toLogin();
|
// }
|
// });
|
// }
|
// // #endif
|
|
// // #ifdef MP-WEIXIN
|
// if (this.canIUseGetUserProfile) {
|
// wx.getUserProfile({
|
// desc: '获取用户个人信息', // 声明获取用户个人信息后的用途,后续会展示在弹窗中,请谨慎填写
|
// success: (res) => {
|
// if (res.errMsg == 'getUserProfile:ok') {
|
|
// // this.authInfo.nickName = res.userInfo.nickName;
|
// // this.authInfo.avatarUrl = res.userInfo.avatarUrl;
|
// // uni.setStorageSync('authInfo', this.authInfo)
|
|
// this.getCode(data => {
|
// console.log(data)
|
// return
|
// if (data) {
|
// this.authLogin(data);
|
// } else {
|
// this.$refs.auth.close();
|
// this.toLogin();
|
// }
|
// });
|
// }
|
// }
|
// })
|
// } else if (e.detail.errMsg == 'getUserInfo:ok') {
|
// this.getCode(data => {
|
// if (data) {
|
// this.authLogin(data);
|
// } else {
|
// this.$refs.auth.close();
|
// this.toLogin();
|
// }
|
// });
|
// }
|
// // #endif
|
|
// // #ifndef MP
|
// this.$refs.auth.close();
|
// this.toLogin();
|
// // #endif
|
// } else {
|
// this.$refs.auth.close();
|
// this.toLogin();
|
// }
|
},
|
}
|
}
|
</script>
|
|
<style lang="scss" scoped>
|
.wrap {
|
background: linear-gradient(to bottom, #B4DEFF, #ffffff);
|
display: flex;
|
align-items: center;
|
flex-direction: column;
|
padding: 0 80rpx;
|
height: 100vh;
|
|
.login_tip {
|
font-size: 28rpx;
|
color: #333;
|
padding: 40rpx 0;
|
width: 400rpx;
|
text-align: center;
|
}
|
|
.tip_img {
|
width: 160rpx;
|
margin-top: 300rpx;
|
}
|
|
.login_btn {
|
width: 100%;
|
|
.regisiter-agreement {
|
text-align: center;
|
margin-top: 30rpx;
|
font-size: 28rpx;
|
color: #838383;
|
line-height: 60rpx;
|
|
.color-base-text {
|
color: #35A6FF;
|
}
|
}
|
|
.uni-tip-button {
|
width: 100%;
|
font-size: 28rpx;
|
height: 70rpx;
|
line-height: 70rpx;
|
background-color: #35A6FF;
|
border-radius: 70rpx;
|
}
|
|
.no_login {
|
font-size: 28rpx;
|
height: 70rpx;
|
line-height: 70rpx;
|
border: 2rpx solid #35A6FF;
|
color: #35A6FF;
|
border-radius: 70rpx;
|
text-align: center;
|
margin-top: 30rpx;
|
}
|
}
|
|
.mobile_login {
|
margin: 40rpx 0;
|
font-size: 32rpx;
|
color: #666;
|
line-height: 1;
|
}
|
|
.agreement_wrap {
|
margin-top: 40rpx;
|
|
.agree_item {
|
display: flex;
|
margin-bottom: 30rpx;
|
|
.item_icon {
|
width: 34rpx;
|
height: 34rpx;
|
margin-right: 10rpx;
|
flex-shrink: 0;
|
|
.item_select_img {
|
width: 100%;
|
height: 100%;
|
}
|
}
|
|
.item_content {
|
font-size: 28rpx;
|
line-height: 36rpx;
|
color: #999;
|
|
.agreement {
|
color: #35A6FF;
|
}
|
}
|
}
|
}
|
}
|
|
.bind-wrap {
|
width: 600rpx;
|
background: #fff;
|
box-sizing: border-box;
|
border-radius: 20rpx;
|
overflow: hidden;
|
|
.heard {
|
font-size: 40rpx;
|
text-align: center;
|
font-weight: 600;
|
padding: 40rpx 0 0;
|
}
|
|
.footer {
|
border-top: 1px solid #eee;
|
display: flex;
|
|
view {
|
flex: 1;
|
height: 100rpx;
|
line-height: 100rpx;
|
text-align: center;
|
|
&:first-child {
|
font-size: 28rpx;
|
border-right: 1px solid #eee;
|
}
|
}
|
}
|
|
.bind-tips {
|
color: #aaa;
|
font-size: 28rpx;
|
padding: 20rpx 50rpx;
|
text-align: center;
|
}
|
|
.auth-login {
|
width: 300rpx;
|
margin: 20rpx auto 60rpx auto;
|
}
|
|
.bind-tip-icon {
|
padding-top: 80rpx;
|
width: 100%;
|
text-align: center;
|
|
image {
|
width: 300rpx;
|
}
|
}
|
}
|
|
.ns-btn-default-all {
|
width: 100%;
|
height: 70rpx;
|
border-radius: 70rpx;
|
text-align: center;
|
line-height: 70rpx;
|
font-size: 28rpx;
|
color: #ffffff;
|
background-color: #35A6FF;
|
}
|
</style>
|