| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664 |
- <template>
- <view class="container">
- <!-- <image @click="navBack" src="../../static/images/index/close.png" style="width: 32upx;height: 32upx;margin-left: 46upx;"></image> -->
- <!-- 小程序状态下登录 -->
- <!-- #ifdef MP-WEIXIN -->
- <view class="mp_wxBox">
- <view>
- <view class="headers">
- <image src="../../static/logo.png" style="border-radius: 50%;"></image>
- </view>
- <view class="content">
- <view>申请获取以下权限</view>
- <text>获得你的公开信息(昵称,头像、地区等)</text>
- </view>
- <button v-show="weixinPhone" style="background: #2FB57A;color: #FFFFFF;" class="bottom"
- open-type="getPhoneNumber" @getphonenumber="getPhoneNumber">
- 授权手机号
- </button>
- <button v-show="!weixinPhone" style="background: #2FB57A;color: #FFFFFF;" class='bottom'
- bindtap="getUserProfile" @tap="wxGetUserInfo">
- 授权登录
- </button>
- </view>
- </view>
- <view style="text-align: center;">
- <view class="footer">
- <image v-if="showAgree" @tap="isShowAgree"
- src="/static/image/selected.png"
- style="width: 30upx;height: 30upx;"></image>
- <image v-else @tap="isShowAgree"
- src="/static/image/noselect.png"
- style="width: 30upx;height: 30upx;"></image>
- <text style="margin-left: 10upx;margin-right: 0;" @tap="isShowAgree">同意</text>
- <!-- 协议地址 -->
- <navigator url="/my/setting/mimi" open-type="navigate">《隐私政策》</navigator>
- 和
- <navigator url="/my/setting/xieyi" open-type="navigate">《用户协议》</navigator>
- </view>
- </view>
- <!-- #endif -->
- <!-- #ifndef MP-WEIXIN -->
- <view style="text-align: center;">
- <image style="width: 144rpx;height: 144rpx;margin-top: 190rpx;border-radius:50%"
- src="../../static/logo.png"></image>
- <view style="font-weight: bold;font-size: 36rpx;color: #222222;margin-top: 32rpx;">欢迎登录上门服务</view>
-
- <!-- #ifdef APP-PLUS -->
- <button v-if="weixinLogin" class="confirm-btn" @click="weixinLo">微信登录</button>
- <button v-if="weixinLogin" class='confirm-btn-weixin' @click="register">手机号登录</button>
- <button v-if="!weixinLogin" class='confirm-btn' @click="register">手机号登录</button>
- <!-- #endif -->
- <!-- #ifdef H5 -->
- <button class='confirm-btn' v-if="isopen" @click="bingwx">微信一键登录</button>
- <button v-if="!isopen" class='confirm-btn' @click="register">登录</button>
- <!-- #endif -->
- <view style="text-align: center;margin: 30rpx 0rpx;align-items: center;">
- <view class="footer">
- <image v-if="showAgree" @tap="isShowAgree"
- src="/static/image/selected.png"
- style="width: 30upx;height: 30upx;"></image>
- <image v-else @tap="isShowAgree"
- src="/static/image/noselect.png"
- style="width: 30upx;height: 30upx;"></image>
- <text style="margin-left: 10upx;margin-right: 0;" @tap="isShowAgree">同意</text>
- <!-- 协议地址 -->
- <navigator url="/my/setting/mimi" open-type="navigate">《隐私政策》</navigator>
- 和
- <navigator url="/my/setting/xieyi" open-type="navigate">《用户协议》</navigator>
- </view>
- </view>
- </view>
- <!-- #endif -->
- </view>
- </template>
- <script>
- export default {
- data() {
- return {
- showAgree: false,
- mobile: '',
- code: '',
- weixinLogin: false,
- sending: false,
- isopen: false,
- sendTime: '获取验证码',
- count: 60,
- weixinPhone: false,
- sendDataList: {},
- sessionkey: '',
- phoneNum: false
- };
- },
- onLoad(e) {
- if (e.inviterCode) {
- this.$queue.setData('inviterCode', e.inviterCode);
- }
- this.$Request.get('/app/common/type/237').then(res => {
- if (res.code == 0) {
- if (res.data && res.data.value && res.data.value == '是') {
- // #ifdef H5
- let ua = navigator.userAgent.toLowerCase();
- if (ua.indexOf('micromessenger') !== -1) {
- this.isopen = true;
- } else {
- this.isopen = false;
- }
- // #endif
- }
- }
- });
- //微信登录开启
- this.$Request.getT('/app/common/type/53').then(res => {
- if (res.code == 0) {
- if (res.data && res.data.value && res.data.value == '是') {
- // this.weixinLogin = true;
- }
- }
- });
- this.$Request.getT('/app/common/type/188').then(res => {
- if (res.code == 0) {
- if (res.data && res.data.value && res.data.value == '是') {
- this.phoneNum = true;
- }
- }
- });
-
- // #ifdef H5
- this.selbindwx();
- // #endif
- },
- methods: {
- isShowAgree() {
- //是否选择协议
- this.showAgree = !this.showAgree;
- },
- selbindwx() {
- let ua = navigator.userAgent.toLowerCase();
- if (ua.indexOf('micromessenger') !== -1) {
- let openid = uni.getStorageSync('openid');
- let userId = uni.getStorageSync('userId');
- let that = this;
- if (window.location.href.indexOf('?code=') !== -1 || window.location.href.indexOf('&code=') !==
- -1) {
- let code;
- if (window.location.href.indexOf('?code=') !== -1) {
- code = window.location.href.split('?code=')[1].split('&')[0];
- } else {
- code = window.location.href.split('&code=')[1].split('&')[0];
- }
- this.$Request.get('/app/Login/getOpenId?code=' + code).then(ret => {
- uni.setStorageSync('openid', ret.data.openid)
- uni.setStorageSync('openidheadimgurl', ret.data.headimgurl)
- uni.setStorageSync('openidnickname', ret.data.nickname)
-
- this.$Request.get('/app/Login/openid/login?openId=' + ret.data.openid).then(res => {
- if (res.code == 0) {
- this.$queue.setData("phone", res.user.phone);
- this.$queue.setData("userId", res.user.userId);
- this.$queue.setData("token", res.token);
- this.$queue.setData("userName", res.user.userName);
- this.$queue.setData("avatar", res.user.avatar);
- this.$queue.setData("invitationCode", res.user.invitationCode);
- this.$queue.setData("inviterCode", res.user.inviterCode);
- uni.switchTab({
- url: '/pages/my/index'
- })
- } else {
- uni.navigateTo({
- url: '/pages/public/bind'
- });
- }
- });
- });
- }
- }
- },
- bingwx() {
- if (this.showAgree == false) {
- uni.showToast({
- icon: 'none',
- position: 'bottom',
- title: '请同意《用户协议》和《隐私政策》'
- });
- return false;
- }
- let ua = navigator.userAgent.toLowerCase();
- if (ua.indexOf('micromessenger') !== -1) {
- let openid = uni.getStorageSync('openid');
- let userId = uni.getStorageSync('userId');
- let that = this;
- if (!openid) {
- if (window.location.href.indexOf('?code=') !== -1 || window.location.href.indexOf('&code=') !==
- -1) {
- let code;
- if (window.location.href.indexOf('?code=') !== -1) {
- code = window.location.href.split('?code=')[1].split('&')[0];
- } else {
- code = window.location.href.split('&code=')[1].split('&')[0];
- }
- this.$Request.get('/app/Login/getOpenId?code=' + code).then(ret => {
- uni.setStorageSync('openid', ret.data.openid)
- uni.setStorageSync('openidheadimgurl', ret.data.headimgurl)
- uni.setStorageSync('openidnickname', ret.data.nickname)
-
- this.$Request.get('/app/Login/openid/login?openId=' + ret.data.openid).then(res => {
- if (res.code == 0) {
- this.$queue.setData("phone", res.user.phone);
- this.$queue.setData("userId", res.user.userId);
- this.$queue.setData("token", res.token);
- this.$queue.setData("userName", res.user.userName);
- this.$queue.setData("avatar", res.user.avatar);
- this.$queue.setData("invitationCode", res.user.invitationCode);
- this.$queue.setData("inviterCode", res.user.inviterCode);
- uni.switchTab({
- url: '/pages/my/index'
- })
- } else {
- uni.navigateTo({
- url: '/pages/public/bind'
- });
- }
- });
- });
- } else {
- window.location.href =
- 'https://open.weixin.qq.com/connect/oauth2/authorize?appid=' +
- that.$queue.getWxAppid() +
- '&redirect_uri=' +
- window.location.href.split('#')[0] +
- '&response_type=code&scope=snsapi_userinfo#wechat_redirect';
- }
- } else {
- this.$Request.get('/app/Login/openid/login?openId=' + openid).then(res => {
- if (res.code == 0) {
- this.$queue.setData("phone", res.user.phone);
- this.$queue.setData("userId", res.user.userId);
- this.$queue.setData("token", res.token);
- this.$queue.setData("userName", res.user.userName);
- this.$queue.setData("avatar", res.user.avatar);
- this.$queue.setData("invitationCode", res.user.invitationCode);
- this.$queue.setData("inviterCode", res.user.inviterCode);
- uni.switchTab({
- url: '/pages/my/index'
- })
- } else {
- uni.navigateTo({
- url: '/pages/public/bind'
- });
- }
- });
- }
- }
- },
- wxGetUserInfo(e) {
- if (this.showAgree == false) {
- uni.showToast({
- icon: 'none',
- position: 'bottom',
- title: '请先同意《隐私政策》和《用户协议》'
- });
- return;
- }
- wx.getUserProfile({
- desc: '业务需要',
- success: infoRes => {
- console.log("infoRes.encryptedData__________:" + JSON.stringify(infoRes.userInfo))
- let nickName = infoRes.userInfo.nickName; //昵称
- let avatarUrl = infoRes.userInfo.avatarUrl; //头像
- let sex = infoRes.userInfo.gender; //头像
- try {
- this.$queue.showLoading('正在登录中...');
- this.login(nickName, avatarUrl, sex);
- } catch (e) {}
- }
- })
- },
- //登录
- login(nickName, avatarUrl, sex) {
- if (this.showAgree == false) {
- uni.showToast({
- icon: 'none',
- position: 'bottom',
- title: '请先同意《隐私政策》和《用户协议》'
- });
- return;
- }
- let that = this;
- // 1.wx获取登录用户code
- uni.login({
- provider: 'weixin',
- success: function(loginRes) {
- console.log(loginRes, '************')
- let data = {
- code: loginRes.code,
- type: 2
- }
- that.$Request.get('/app/Login/wxLogin', data).then(res => {
- if (res.code == 0) {
- uni.hideLoading()
- uni.setStorageSync('openId', res.data.open_id)
- uni.setStorageSync('unionId', res.data.unionId)
- that.sessionkey = res.data.session_key;
- let inviterCode = '';
- if (uni.getStorageSync('inviterCode')) {
- inviterCode = uni.getStorageSync('inviterCode')
- }
- let sendData = {
- openId: uni.getStorageSync('openId'),
- unionId: uni.getStorageSync('unionId'),
- userName: nickName,
- avatar: avatarUrl,
- sex: sex, //性别
- inviterCode: inviterCode //别人登录进来携带你的邀请码
- };
- that.sendDataList = sendData;
- that.flag = res.data.flag;
- // 第一次登录获取手机号
- console.log(that.phoneNum)
- if (that.flag == '1' && that.phoneNum) {
- that.weixinPhone = true;
- } else {
- that.getWeixinInfo(sendData);
- }
- } else {
- uni.showToast({
- icon: 'none',
- title: res.msg,
- duration: 2000
- });
- console.log(res, '失败')
- }
- })
- }
- });
- },
- //小程序微信登录后获取手机号
- getPhoneNumber: function(e) {
- if (e.detail.errMsg == 'getPhoneNumber:fail user deny') {
- console.log('用户拒绝提供手机号');
- } else {
- console.log('用户同意提供手机号');
- console.log(e)
- this.setPhoneByInsert(e.detail.encryptedData, e.detail.iv);
- }
- },
- //小程序微信登录后获取手机号
- setPhoneByInsert(decryptData, iv) {
- let data = {
- decryptData: decryptData,
- key: this.sessionkey,
- iv: iv
- };
- if (this.showAgree == false) {
- uni.showToast({
- icon: 'none',
- position: 'bottom',
- title: '请先同意《隐私政策》和《用户协议》'
- });
- return;
- }
- this.$Request.postJson('/app/Login/selectPhone', data).then(res => {
- if (res.code == 0) {
- this.phone = res.data.phoneNumber;
- this.getWeixinInfo(this.sendDataList);
- } else {
- uni.showToast({
- title: res.msg,
- icon: 'none',
- duration: 2000
- });
- }
- })
- },
- //获取个人信息
- getWeixinInfo(sendData) {
- let that = this;
- uni.showLoading({
- title: '登录中...'
- });
- let postData = {
- openId: sendData.openId, //小程序openId
- unionId: sendData.unionId, //unionId
- userName: sendData.userName, //微信名称
- avatar: sendData.avatar, //头像
- sex: sendData.sex, //性别
- phone: that.phone,
- inviterCode: sendData.inviterCode,
- type: 2
- };
- that.$Request.postJson('/app/Login/insertWxUser', postData).then(res => {
- uni.hideLoading();
- if (res.code == 0) {
- uni.setStorageSync('token', res.token)
- uni.setStorageSync('userName', res.user.userName)
- uni.setStorageSync('avatar', res.user.avatar)
- uni.setStorageSync('phone', res.user.phone)
- uni.setStorageSync('invitationCode', res.user.invitationCode)
- uni.setStorageSync('sex', res.user.sex)
- uni.setStorageSync('userId', res.user.userId)
- uni.setStorageSync('openId', res.user.openId)
- this.$Request.get("/app/UserVip/isUserVip").then(res => {
- if (res.code == 0 && res.data && res.data.isVip == 2) {
- uni.setStorageSync('isVIP', true)
- } else {
- uni.setStorageSync('isVIP', false)
- }
- });
- uni.navigateBack();
- } else {
- uni.showModal({
- showCancel: false,
- title: '登录失败',
- content: res.msg,
- });
- }
- })
- },
- weixinLo() {
- if (this.showAgree == false) {
- uni.showToast({
- icon: 'none',
- position: 'bottom',
- title: '请先同意《隐私政策》和《用户协议》'
- });
- return;
- }
- let that = this;
- uni.login({
- provider: 'weixin',
- success: function(loginRes) {
- that.$queue.showLoading('正在登录中...');
- console.error(loginRes.authResult);
- that.$queue.setData('weixinToken', loginRes.authResult.access_token);
- that.$queue.setData('unionid', loginRes.authResult.unionid);
- that.$queue.setData('weixinOpenid', loginRes.authResult.openid);
- that.$Request.postJson('/app/login/loginApp', {
- token: loginRes.authResult.access_token,
- unionid: loginRes.authResult.unionid,
- openid: loginRes.authResult.openid
- }).then(res => {
- console.log(JSON.stringify(res))
- if (res.code === 0) {
- if (uni.getSystemInfoSync().platform == "android") {
- let clientid = plus.push.getClientInfo().clientid;
- that.$Request.postT('/app/login/updateClientId?clientId=' +
- clientid + '&userId=' + res.userId).then(res => {
- });
- }
- that.$queue.setData("token", res.uuid);
- that.$queue.setData("userId", res.userId);
- that.getUserInfo(res.userId, res.token);
- } else {
- uni.hideLoading();
- uni.navigateTo({
- url: '/pages/public/wxmobile'
- });
- }
- });
- }
- });
- },
- forget() {
- uni.navigateTo({
- url: '/pages/public/pwd'
- });
- },
- register() {
- if (this.showAgree == false) {
- uni.showToast({
- icon: 'none',
- position: 'bottom',
- title: '请先同意《隐私政策》和《用户协议》'
- });
- return;
- }
- uni.navigateTo({
- url: '/pages/public/loginphone'
- });
- },
- inputChange(e) {
- const key = e.currentTarget.dataset.key;
- this[key] = e.detail.value;
- },
- navBack() {
- uni.navigateBack();
- },
- getUserInfo(userId, token) {
- this.$Request.postJson('/app/selectUserById?userId=' + userId).then(res => {
- if (res.code === 0) {
- this.$queue.setData('token', res.data.uuid);
- this.$queue.setData('image_url', res.data.imageUrl ? res.data.imageUrl :
- '/static/img/common/logo.jpg');
- this.$queue.setData('inviterCode', res.data.inviterCode);
- this.$queue.setData('invitationCode', res.data.invitationCode);
- this.$queue.setData('grade', res.data.grade);
- this.$queue.setData('mobile', res.data.mobile);
- this.$queue.setData('isInvitation', res.data.isInvitation);
- this.$queue.setData('nickName', res.data.nickName ? res.data.nickName : res.data.phone);
- this.$queue.setData('gender', parseInt(res.data.gender));
- uni.switchTab({
- url: '/pages/index/index'
- });
- } else {
- uni.showModal({
- showCancel: false,
- title: '登录失败',
- content: res.msg
- });
- this.$queue.logout();
- }
- uni.hideLoading();
- });
- }
- }
- };
- </script>
- <style lang="scss">
- page {
- height: 100%;
- background: #FFFFFF !important;
- }
- .container {
- top: 0;
- padding-top: 50px;
- position: relative;
- width: 100%;
- height: 100%;
- overflow: hidden;
- background: #FFFFFF !important;
- color: #FFF;
- }
- .confirm-btn-weixin {
- width: 200px;
- height: 42px;
- line-height: 42px;
- border-radius: 30px;
- margin-top: 40upx;
- // background: -moz-linear-gradient(left, #f15b6c, #e10a07 100%);
- // background: -webkit-gradient(linear, left top, left right, color-stop(0, #f15b6c), color-stop(100%, #e10a07));
- // background: -webkit-linear-gradient(left, #f15b6c 0, #e10a07 100%);
- // background: -o-linear-gradient(left, #f15b6c 0, #e10a07 100%);
- // background: -ms-linear-gradient(left, #f15b6c 0, #e10a07 100%);
- // background: linear-gradient(to left, #f15b6c 0, #e10a07 100%);
- background: #2FB57A;
- color: #fff;
- font-size: 32upx;
- &:after {
- border-radius: 60px;
- }
- }
- .confirm-btn {
- width: 582rpx;
- height: 100rpx;
- line-height: 100rpx;
- text-align: center;
- background: #1EDA94;
- border-radius: 50rpx 50rpx 50rpx 50rpx;
- font-weight: bold;
- font-size: 32rpx;
- color: #222222;
- margin-top: 80rpx;
- }
- .headers {
- text-align: center;
- }
- .headers>image {
- width: 400upx;
- height: 400upx;
- }
- .footer {
- padding-left: 160upx;
- font-size: 24upx;
- color: #666666;
- text-align: center;
- display: flex;
- }
- page {
- background: #fff;
- }
- .send-msg {
- border-radius: 30px;
- color: black;
- background: white;
- height: 30px;
- font-size: 14px;
- line-height: 30px;
- }
- .container {
- top: 0;
- padding-top: 32upx;
- position: relative;
- width: 100%;
- height: 100%;
- overflow: hidden;
- background: #ffffff;
- color: #FFF;
- .mp_wxBox {
- .headers {
- margin: 35% auto 50rpx;
- text-align: center;
- border-radius: 60rpx;
- width: 650rpx;
- height: 300rpx;
- line-height: 450rpx;
- image {
- width: 300rpx;
- height: 300rpx;
- }
- }
- .content {
- text-align: center;
- }
- text {
- display: block;
- color: #9d9d9d;
- margin-top: 40rpx;
- }
- .bottom {
- line-height: 80upx;
- border-radius: 80upx;
- margin: 70rpx 50rpx 40rpx;
- height: 80upx;
- font-size: 35rpx;
- }
- }
- }
- .wrapper {
- position: relative;
- z-index: 90;
- background: #fff;
- padding-bottom: 20px;
- }
- .input-content {
- padding: 0 20px;
- }
-
- </style>
|