Files
video_app/pages/login/login - 副本.vue
2024-12-31 17:41:32 +08:00

1290 lines
35 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.
<template>
<view class="container">
<!-- 小程序状态下登录 -->
<!-- #ifdef MP-WEIXIN || MP-TOUTIAO || MP-KUAISHOU -->
<view class="mp_wxBox">
<view>
<view class="headers">
<image src="../../static/images/logo.png" style="border-radius: 50%;"></image>
</view>
<view class="content">
<view>申请获取以下权限</view>
<text>获得你的公开信息(昵称头像地区等)</text>
</view>
<button v-show="weixinPhone" style="background: #ff7581;color: #FFFFFF;" class="bottom"
open-type="getPhoneNumber" @getphonenumber="getPhoneNumber">
授权手机号
</button>
<button v-show="!weixinPhone" style="background: #ff7581;color: #FFFFFF;" class='bottom'
bindtap="getUserProfile" @tap="wxGetUserInfo">
授权登录
</button>
</view>
</view>
<!-- #endif -->
<!-- #ifdef H5 -->
<view style="text-align: center;">
<image style="width: 120upx;height: 120upx;margin-top: 140upx;border-radius:20upx"
src="../../static/images/logo.png"></image>
<button class='confirm-btn' v-if="!isopen" @click="register">手机号登录</button>
<button class='confirm-btn' v-if="isopen" @click="bingwx">微信一键登录</button>
</view>
<!-- #endif -->
<!-- #ifdef APP -->
<view style="text-align: center;">
<image style="width: 120upx;height: 120upx;margin-top: 140upx;border-radius:20upx"
src="../../static/images/logo.png"></image>
<button class='confirm-btn' v-if="!isopen" @click="register">手机号登录</button>
<button class='confirm-btn' v-if="isopen" @click="bingwx">微信一键登录</button>
</view>
<view v-if="phoneLogin || weixinLogin || CheckiosLogin"
style="display: flex;align-items: center;width: 100%;justify-content: center;margin-top: 250upx;">
<view style="width: 100rpx;height: 1rpx;background: #d1d1d1;"></view>
<view style="color: #333333;margin: 0 20rpx;">其他方式登录</view>
<view style="width: 100rpx;height: 1rpx;background: #d1d1d1;"></view>
</view>
<view style="display: flex;margin-top: 80upx;width: 750rpx;justify-content: center;">
<view style="flex: 1;text-align: center;" v-if="phoneLogin">
<image src="/static/images/me/icon_phone.png" @tap="login_phone" style="width: 90upx;height: 90upx;">
</image>
</view>
<view style="flex: 1;text-align: center;" v-if="weixinLogin">
<image src="/static/images/index/weixin.png" @tap="appweixinLo" style="width: 90upx;height: 90upx;">
</image>
</view>
<view style="flex: 1;text-align: center;" v-if="CheckiosLogin">
<image src="/static/images/me/appleid_button.png" @tap="ioslogin" style="width: 90upx;height: 90upx;">
</image>
</view>
<!-- <view style="flex: 1;text-align: center;" @tap="ioslogin" v-if="CheckiosLogin">
<image src="../../static/pw/loginphone.png" style="width: 80upx;height: 80upx;"></image>
</view> -->
</view>
<!-- #endif -->
<view class="footer" @click.stop="isCheck">
<view style="display: flex;align-items: center;justify-content: center;">
<u-checkbox-group>
<u-checkbox active-color="#ff7581" v-model="checked" label-size='24upx' shape="circle"
@change="radioChange"></u-checkbox>
</u-checkbox-group>
<view>同意</view>
<!-- 协议地址 -->
<text @click.stop="goTo('/me/setting/mimi')">隐私政策</text><text
@click.stop="goTo('/me/setting/xieyi')">用户协议</text>
</view>
</view>
<u-toast ref="uToast" />
</view>
</template>
<script>
export default {
data() {
return {
mobile: '',
code: '',
sessionkey: '',
flag: '1',
weixinPhone: false,
sending: false,
sendDataList: {},
phone: '',
sendTime: '获取验证码',
count: 60,
checked: false,
isopen: false,
qdCodeion: '',
phoneLogin: false,
CheckiosLogin: false,
weixinLogin: false
};
},
onLoad() {
// this.$u.get('/app/common/type/108').then(res => { //// 是否开启公众号自动登陆 108
// if (res.code == 0 && res.data) {
// if (res.data.value == '是') {
// // #ifdef H5
// let ua = navigator.userAgent.toLowerCase();
// if (ua.indexOf('micromessenger') !== -1) {
// this.isopen = true;
// } else {
// this.isopen = false;
// }
// // #endif
// } else {
// this.isopen = false;
// }
// }
// })
// // #ifdef H5
// this.selbindwx();
// // #endif
// #ifdef APP-PLUS
let checkWxLogin = this.$queue.getData('checkWxLogin');
if (checkWxLogin != '否') {
this.weixinLogin = true;
} else {
this.weixinLogin = false;
}
let checkPhoneLogin = this.$queue.getData('checkPhoneLogin');
if (checkPhoneLogin != '否') {
this.phoneLogin = true;
} else {
this.phoneLogin = false;
}
switch (uni.getSystemInfoSync().platform) {
case 'android':
break;
case 'ios':
let checkIosLogins = this.$queue.getData('checkIosLogin');
if (checkIosLogins != '否') {
this.CheckiosLogin = true;
} else {
this.CheckiosLogin = false;
}
break;
default:
break;
}
// #endif
//拿一下携带的渠道码
if (uni.getStorageSync('qdCodeion')) {
this.qdCodeion = uni.getStorageSync('qdCodeion')
}
},
methods: {
appweixinLo() {
if (!this.checked) {
uni.showToast({
title: '请同意隐私政策和用户服务协议',
icon: 'none'
})
return;
}
let that = this;
uni.login({
provider: 'weixin',
success: function(loginRes) {
that.$queue.showLoading('正在登录中...');
console.error(loginRes.authResult.openid);
that.$queue.setData('weixinToken', loginRes.authResult.access_token);
that.$queue.setData('unionid', loginRes.authResult.unionid);
that.$queue.setData('weixinOpenid', loginRes.authResult.openid);
that.$Request.postT('/app/Login/wxAppLogin', {
token: loginRes.authResult.access_token,
wxOpenId: loginRes.authResult.openid
})
.then(res => {
console.log(JSON.stringify(res))
if (res.code === 0) {
that.$queue.setData('token', res.token);
that.$queue.setData('userId', res.user.userId);
uni.switchTab({
url: '/pages/index/index2'
})
} else {
uni.hideLoading();
uni.showModal({
title: '提示',
content: '需要绑定手机和完善资料,是否继续',
confirmText: '继续注册',
success: function(res) {
if (res.confirm) {
console.log('用户点击确定');
uni.navigateTo({
url: '/pages/login/wxmobile'
});
} else if (res.cancel) {
console.log('用户点击取消');
}
}
});
}
});
}
});
},
login_phone() {
if (!this.checked) {
uni.showToast({
title: '请同意隐私政策和用户服务协议',
icon: 'none'
})
return;
}
let that = this;
uni.getProvider({ //获取可用的服务提供商
service: 'oauth',
success: function(res) {
console.log(res.provider) // ['weixin', qq', 'univerify']
}
});
uni.preLogin({ //预登录
provider: 'univerify', //用手机号登录
success() {
console.log('预登录成功')
uni.login({ //正式登录,弹出授权窗
provider: 'univerify',
univerifyStyle: { // 自定义登录框样式
"fullScreen": false, // 是否全屏显示true表示全屏模式false表示非全屏模式默认值为false。
"backgroundColor": "#FFFFFF", // 授权页面背景颜色,默认值:#ffffff
"icon": {
"path": "static/logo.png" // 自定义显示在授权框中的logo仅支持本地图片 默认显示App logo
},
"phoneNum": {
"color": "#000000", // 手机号文字颜色 默认值:#000000
},
"authButton": {
"normalColor": "#ff7581", // 授权按钮正常状态背景颜色 默认值:#3479f5
"highlightColor": "#ff7581", // 授权按钮按下状态背景颜色 默认值:#2861c5仅ios支持
"disabledColor": "#ff7581", // 授权按钮不可点击时背景颜色 默认值:#73aaf5仅ios支持
"textColor": "#ffffff", // 授权按钮文字颜色 默认值:#ffffff
"title": "本机号码一键登录" // 授权按钮文案 默认值:“本机号码一键登录”
}
},
success(res) { // 正式登录成功
console.log(res
.authResult); // {openid:'登录授权唯一标识',access_token:'接口返回的 token'}
// 在得到access_token后通过callfunction调用云函数
uniCloud.callFunction({
name: 'login', // 云函数名称
data: { //传给云函数的参数
'access_token': res.authResult
.access_token, // 客户端一键登录接口返回的access_token
'openid': res.authResult.openid // 客户端一键登录接口返回的openid
},
success(callRes) {
console.log('调用云函数成功' + JSON.stringify(callRes))
console.log("手机号:" + callRes.result.phoneNumber)
that.savePhoneByUser(callRes.result.phoneNumber);
},
fail(callErr) {
console.log('调用云函数出错' + callErr)
},
complete() {
uni.closeAuthView() //关闭授权登录界面
}
})
},
fail(err) { // 正式登录失败
console.log(err.errCode)
console.log(err.errMsg)
uni.closeAuthView() //关闭授权登录界面
}
})
},
fail(err) { //预登录失败
console.log(err)
console.log('错误码:' + err.errCode)
console.log(err.errMsg)
}
})
},
savePhoneByUser(phone) {
this.$queue.showLoading('登录中...')
let that = this;
that.$Request
.postT('/app/Login/phoneLogin', {
phone: phone
})
.then(ress => {
console.log(JSON.stringify(ress))
if (ress.code === 0) {
that.$queue.setData('token', ress.token);
that.$queue.setData('userId', ress.user.userId);
console.log(ress.user.userId)
console.log(ress.token)
uni.switchTab({
url: '/pages/index/index2'
})
} else {
uni.hideLoading();
uni.navigateTo({
url: './phonebind?phone=' + phone
});
}
});
},
//app苹果登录
ioslogin() {
if (!this.checked) {
uni.showToast({
title: '请同意隐私政策和用户服务协议',
icon: 'none'
})
return;
}
console.log("ioslogin")
let that = this;
uni.login({
provider: 'apple',
success: function(loginRes) {
let iosopenid = loginRes.authResult.openid
// 获取用户信息
uni.getUserInfo({
provider: 'apple',
success(ress) {
that.$queue.showLoading('登录中...');
let datas = {
identityToken: JSON.stringify(ress)
}
//在这里获取到苹果手机的ID后可以继续你的操作请求后台进行登录
that.$Request.postT('/app/Login/appleLogin', datas).then(re => {
if (re.code == 0) {
that.$queue.setData('appleId', re.data)
that.$Request.getT(
'/app/Login/insertAppleUser?appleId=' + re.data
).then(res => {
console.log(JSON.stringify(res))
if (res.code == 0) {
that.$queue.setData('token', res
.token);
that.$queue.setData('userId', res.user
.userId);
uni.switchTab({
url: '/pages/index/index2'
})
} else {
uni.hideLoading();
if (res.code == 201) {
uni.showModal({
title: '提示',
content: '需要绑定手机和完善资料,是否继续',
confirmText: '继续注册',
success: function(
res) {
if (res
.confirm) {
console
.log(
'用户点击确定'
);
uni.navigateTo({
url: './iosmobile'
});
} else if (res
.cancel) {
console
.log(
'用户点击取消'
);
}
}
});
} else if (res.code == 500) {
that.$queue.showToast(res.msg);
} else {
that.$queue.showToast(res.msg);
}
}
});
} else {
uni.hideLoading();
that.$queue.showToast(re.msg)
}
});
}
});
},
fail: function(err) {
uni.showToast({
icon: 'none',
title: err,
duration: 2000
});
}
});
},
goTo(url) {
uni.navigateTo({
url
});
},
isCheck() {
this.checked = !this.checked
},
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 (!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)
this.$Request.get('/app/Login/openid/login?openId=' + ret.data).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);
uni.setStorageSync('sex', res.user.sex)
uni.setStorageSync('openId', res.user.openId)
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/index/index2'
})
} else {
uni.navigateTo({
url: '/pages/login/bind'
});
}
});
});
}
}
}
},
// 微信公众号登录
bingwx() {
if (this.checked) {
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)
// uni.setStorageSync('openidheadimgurl', ret.data.headimgurl)
// uni.setStorageSync('openidnickname', ret.data.nickname)
this.$Request.get('/app/Login/openid/login?openId=' + ret.data).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);
uni.setStorageSync('sex', res.user.sex)
uni.setStorageSync('openId', res.user.openId)
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/index/index2'
})
} else {
uni.navigateTo({
url: '/pages/login/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/index/index2'
})
} else {
uni.navigateTo({
url: '/pages/login/bind'
});
}
});
}
}
} else {
uni.showToast({
title: '请同意隐私政策和用户服务协议',
icon: 'none'
})
}
},
// 注册
register() {
if (this.checked) {
uni.navigateTo({
url: '/pages/login/loginPhone'
});
} else {
uni.showToast({
title: '请同意隐私政策和用户服务协议',
icon: 'none'
})
}
},
// 忘记密码
forget() {
uni.navigateTo({
url: '/pages/login/forgetPwd'
});
},
inputChange(e) {
const key = e.currentTarget.dataset.key;
this[key] = e.detail.value;
},
radioChange(e) {
console.log(e);
},
//第一授权获取用户信息===》按钮触发
wxGetUserInfo(e) {
let that = this;
if (this.checked) {
// 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 {
// that.login(nickName, avatarUrl, sex);
// } catch (e) {}
// },
// fail(e) {
// console.log(e, '222222222222222')
// }
// })
let nickName = ''
// #ifdef MP-WEIXIN
nickName = '微信用户'
// #endif
// #ifdef MP-TOUTIAO
nickName = '抖音用户'
// #endif
let avatarUrl = '/static/images/logo.png'
let sex = 1
that.login(nickName, avatarUrl, sex);
} else {
this.$refs.uToast.show({
title: '请阅读并同意《隐私政策》和《用户服务协议》',
duration: 1500
})
}
},
//登录
login(nickName, avatarUrl, sex) {
let that = this;
// 1.wx获取登录用户code
uni.login({
provider: 'weixin',
success: function(loginRes) {
console.log(loginRes, 'code')
// #ifdef MP-TOUTIAO
let data = {
code: loginRes.code,
anonymous_code: loginRes.anonymousCode
}
that.$Request.post('/app/Login/dyLogin', data).then(res => {
if (res.code == 0) {
let invitationCode = '';
if (uni.getStorageSync('invitation')) {
invitationCode = uni.getStorageSync('invitation')
}
//判断是否需要绑定手机号
if (Number(res.data.flag) === 1) {
that.weixinPhone = true;
} else {
uni.showLoading({
title: '登录中...'
})
that.$Request.postJson('/app/Login/dyRegister', {
userName: nickName, //抖音名称
avatar: avatarUrl, //头像
sex: sex, //性别
// phone: '',
inviterCode: invitationCode,
dyOpenId: res.data.dyOpenId,
qdCode: that.qdCodeion
}).then(ress => {
uni.hideLoading()
if (ress.code == 0) {
uni.setStorageSync('token', ress.token)
uni.setStorageSync('userName', ress.user.userName)
uni.setStorageSync('avatar', ress.user.avatar)
uni.setStorageSync('phone', ress.user.phone)
uni.setStorageSync('invitationCode', ress.user
.invitationCode)
if (ress.user.qdCode) {
uni.setStorageSync('qdCode', ress.user.qdCode)
}
uni.setStorageSync('sex', ress.user.sex)
uni.setStorageSync('userId', ress.user.userId)
uni.setStorageSync('openId', ress.user.dyOpenId)
that.$u.api.userVip({
userId: uni.getStorageSync('userId')
}).then(rest => {
if (rest.code == 0 && rest.data && rest
.data.isVip == 2) {
uni.setStorageSync('isVIP', true)
} else {
uni.setStorageSync('isVIP', false)
}
})
uni.navigateBack();
} else {
uni.showModal({
showCancel: false,
title: '登录失败',
content: res.msg,
});
}
})
}
}
})
// #endif
// #ifdef MP-WEIXIN
let data = {
code: loginRes.code
}
that.$u.api.wxLogin(data).then(res => {
if (res.code == 0 && res.data) {
uni.setStorageSync('openId', res.data.open_id)
uni.setStorageSync('unionId', res.data.unionId)
that.sessionkey = res.data.session_key;
let invitationCode = '';
if (uni.getStorageSync('invitation')) {
invitationCode = uni.getStorageSync('invitation')
}
let sendData = {
openId: uni.getStorageSync('openId'),
unionId: uni.getStorageSync('unionId'),
userName: nickName,
avatar: avatarUrl,
sex: sex, //性别
inviterCode: invitationCode, //别人登录进来携带你的邀请码
qdCode: that.qdCodeion
};
that.sendDataList = sendData;
that.flag = res.data.flag;
if (that.flag == '1') {
that.weixinPhone = true;
} else {
that.getWeixinInfo(sendData);
}
} else {
uni.showToast({
icon: 'none',
title: res.msg,
duration: 2000
});
}
})
// #endif
// #ifdef MP-KUAISHOU
let data = {
code: loginRes.code,
}
that.$Request.post('/app/Login/ksLogin', data).then(res => {
if (res.code == 0) {
let invitationCode = '';
if (uni.getStorageSync('invitation')) {
invitationCode = uni.getStorageSync('invitation')
}
//判断是否需要绑定手机号
if (Number(res.data.flag) === 1) {
that.weixinPhone = true;
} else {
uni.showLoading({
title: '登录中...'
})
that.$Request.postJson('/app/Login/ksRegister', {
userName: nickName, //名称
avatar: avatarUrl, //头像
sex: sex, //性别
// phone: '',
inviterCode: invitationCode,
ksOpenId: res.data.ksOpenId,
qdCode: that.qdCodeion
}).then(ress => {
uni.hideLoading()
if (ress.code == 0) {
uni.setStorageSync('token', ress.token)
uni.setStorageSync('userName', ress.user.userName)
uni.setStorageSync('avatar', ress.user.avatar)
uni.setStorageSync('phone', ress.user.phone)
uni.setStorageSync('invitationCode', ress.user
.invitationCode)
if (ress.user.qdCode) {
uni.setStorageSync('qdCode', ress.user.qdCode)
}
uni.setStorageSync('sex', ress.user.sex)
uni.setStorageSync('userId', ress.user.userId)
uni.setStorageSync('openId', ress.user.ksOpenId)
that.$u.api.userVip({
userId: uni.getStorageSync('userId')
}).then(rest => {
if (rest.code == 0 && rest.data && rest
.data.isVip == 2) {
uni.setStorageSync('isVIP', true)
} else {
uni.setStorageSync('isVIP', false)
}
})
uni.navigateBack();
} else {
uni.showModal({
showCancel: false,
title: '登录失败',
content: res.msg,
});
}
})
}
} else {
uni.showToast({
title: res.msg,
icon: 'none'
})
}
})
// #endif
}
});
},
getMyPhone(code) {
let data = {
code: code
}
this.$Request.postT('/app/Login/wxPhone', data).then(res => {
if (res.code == 0) {
this.phone = res.data.phone_info.purePhoneNumber;
this.getWeixinInfo(this.sendDataList);
} else {
uni.showToast({
title: '获取手机号失败',
icon: 'none'
})
}
})
},
//小程序微信登录后获取手机号
getPhoneNumber: function(e) {
console.log(e.detail, '1111111111')
// #ifdef MP-TOUTIAO
if (e.detail.encryptedData && e.detail.iv) {
console.log('用户同意提供手机号');
// console.log('用户拒绝提供手机号');
} else {
uni.showToast({
title: '获取手机号失败',
icon: 'none'
})
// this.setPhoneByInsert(e.detail.encryptedData, e.detail.iv);
}
// #endif
// #ifdef MP-WEIXIN
if (e.detail.code) {
this.getMyPhone(e.detail.code)
} else {
uni.showToast({
title: '获取手机号失败',
icon: 'none'
})
}
// if (e.detail.errMsg == 'getPhoneNumber:fail user deny') {
// console.log('用户拒绝提供手机号');
// } else {
// console.log('用户同意提供手机号');
// this.setPhoneByInsert(e.detail.encryptedData, e.detail.iv);
// }
// #endif
// #ifdef MP-KUAISHOU
// #endif
},
//小程序微信登录后获取手机号
setPhoneByInsert(decryptData, iv) {
let data = {
decryptData: decryptData,
key: this.sessionkey,
iv: iv
};
this.$u.api.selectPhone(data).then(res => {
if (res.code == 0) {
this.phone = res.data.phoneNumber;
this.getWeixinInfo(this.sendDataList);
} else {
uni.showToast({
title: res.msg,
duration: 2000
});
}
})
},
countDown() {
const {
count
} = this;
if (count === 1) {
this.count = 60;
this.sending = false;
this.sendTime = '获取验证码'
} else {
this.count = count - 1;
this.sending = true;
this.sendTime = count - 1 + '秒后重新获取';
setTimeout(this.countDown.bind(this), 1000);
}
},
sendMsg() {
const {
mobile
} = this;
console.log(mobile)
if (!mobile) {
uni.showToast({
title: '请输入手机号',
icon: 'none',
duration: 1000
})
} else if (mobile.length !== 11) {
uni.showToast({
title: '请输入正确的手机号',
icon: 'none',
duration: 1000
})
} else {
uni.showLoading({
title: '正在发送验证码...'
})
this.$u.get('/app/Login/sendMsg/' + mobile + '/login').then(res => {
// this.$Request.getT('/appLogin/sendMsg/' + mobile + '/bind').then(res => {
if (res.code === 0) {
this.sending = true;
uni.showToast({
title: '验证码发送成功请注意查收',
icon: 'none',
duration: 1000
})
this.countDown();
uni.hideLoading();
} else {
uni.hideLoading();
uni.showModal({
showCancel: false,
title: '短信发送失败',
content: res.msg ? res.msg : '请一分钟后再获取验证码'
});
}
});
}
},
toLogin() {
// this.$queue.loginClear();
// let openid = this.$queue.getData('openid');
let openid = uni.getStorageSync('openId')
const {
mobile,
code
} = this;
if (!mobile) {
// this.$queue.showToast('请输入手机号');
uni.showToast({
title: '请输入手机号',
icon: 'none',
duration: 1000
})
} else if (mobile.length != 11) {
// this.$queue.showToast('请输入手机号');
uni.showToast({
title: '请输入正确的手机号',
icon: 'none',
duration: 1000
})
} else if (!code) {
// this.$queue.showToast('请输入密码');
uni.showToast({
title: '请输入密码',
icon: 'none',
duration: 1000
})
} else {
uni.showLoading({
title: '正在登录中...',
})
this.$u.post('/app/Login/registerCode?password=' + code + '&phone=' + mobile).then(res => {
if (res.code === 0) {
uni.setStorageSync('token', res.token)
uni.setStorageSync('userId', res.user.userId)
uni.setStorageSync('userName', res.user.userName)
uni.setStorageSync('avatar', res.user.avatar ? res.user.avatar :
'../../static/images/logo.png')
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.getWeixinInfo(this.sendDataList);
uni.showToast({
title: '登录成功',
icon: 'none'
})
setTimeout(function() {
uni.switchTab({
url: '/pages/index/index2'
});
}, 1000)
} else {
uni.hideLoading();
uni.showToast({
title: res.msg,
icon: 'none',
duration: 1000
})
}
});
}
},
//获取个人信息
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,
qdCode: sendData.qdCode
};
that.$u.api.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)
if (res.user.qdCode) {
uni.setStorageSync('qdCode', res.user.qdCode)
}
uni.setStorageSync('sex', res.user.sex)
uni.setStorageSync('userId', res.user.userId)
uni.setStorageSync('openId', res.user.openId)
let data = {
userId: uni.getStorageSync('userId')
}
that.$u.api.userVip(data).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,
});
}
})
},
}
};
</script>
<style lang="scss">
button:after {
border: none !important;
}
.headers {
text-align: center;
}
.headers>image {
width: 400upx;
height: 400upx;
}
.footer {
// padding-left: 150rpx;
margin-top: 32upx;
font-size: 24upx;
color: #666666;
// text-align: center;
display: flex;
align-items: center;
justify-content: center;
}
page {
background: #ffffff;
}
.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;
.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 {
width: 686rpx;
margin: 70rpx auto;
line-height: 80upx;
border-radius: 80upx;
height: 80upx;
font-size: 35rpx;
}
}
}
.wrapper {
position: relative;
z-index: 90;
background: #ffffff;
padding-bottom: 20px;
}
// .back-btn {
// position: absolute;
// left: 20px;
// z-index: 9999;
// padding-top: var(--status-bar-height);
// top: 20px;
// font-size: 20px;
// color: $font-color-dark;
// }
// .left-top-sign {
// font-size: 80px;
// color: $page-color-base;
// position: relative;
// }
// .right-top-sign {
// position: absolute;
// top: 40px;
// right: -15px;
// z-index: 95;
// &:before,
// &:after {
// display: block;
// content: '';
// width: 20px;
// height: 40px;
// background: #e10a07;
// }
// &:before {
// transform: rotate(50deg);
// border-radius: 0 50px 0 0;
// }
// &:after {
// position: absolute;
// right: -198px;
// top: 0;
// transform: rotate(-50deg);
// border-radius: 50px 0 0 0;
// /* background: pink; */
// }
// }
// .left-bottom-sign {
// position: absolute;
// left: -270px;
// bottom: -320px;
// /*border: 100upx solid #d0d1fd;*/
// border-radius: 50%;
// padding: 90px;
// }
// .welcome {
// position: relative;
// left: 30px;
// top: -55px;
// font-size: 28px;
// color: #555;
// text-shadow: 1px 0px 1px rgba(0, 0, 0, 0.3);
// }
.input-content {
padding: 0 20px;
}
// .input-item {
// display: flex;
// flex-direction: column;
// align-items: flex-start;
// justify-content: center;
// padding: 0 30px;
// background: $page-color-light;
// height: 64px;
// border-radius: 4px;
// margin-bottom: 30px;
// &:last-child {
// margin-bottom: 0;
// }
// .tit {
// height: 30px;
// line-height: 28px;
// font-size: $font-sm + 2upx;
// color: $font-color-base;
// }
// input {
// height: 40px;
// font-size: $font-base + 2upx;
// color: $font-color-dark;
// width: 100%;
// }
// }
.confirm-btn {
width: 300px;
height: 42px;
line-height: 42px;
border-radius: 30px;
margin-top: 40px;
// background: linear-gradient(to left, #3f5ecb 0, #5074FF 100%);
background: #ff7581;
color: #ffffff;
// font-size: $font-lg;
&:after {
border-radius: 60px;
}
}
// .confirm-btn1 {
// width: 300px;
// height: 42px;
// line-height: 42px;
// border-radius: 30px;
// margin-top: 40px;
// background: whitesmoke;
// color: grey;
// font-size: $font-lg;
// &:after {
// border-radius: 60px;
// }
// }
// .forget-section {
// font-size: $font-sm + 2upx;
// color: $font-color-spec;
// text-align: center;
// margin-top: 40px;
// }
// .register-section {
// left: 0;
// margin-top: 30px;
// bottom: 30px;
// width: 100%;
// font-size: $font-sm + 2upx;
// color: $font-color-base;
// text-align: center;
// text {
// color: $font-color-spec;
// margin-left: 10px;
// }
// }
</style>