446 lines
11 KiB
Vue
446 lines
11 KiB
Vue
<template>
|
||
<view class="containerDEghTTorsp">
|
||
|
||
<view class="wrapperDEghTTorsp">
|
||
<view class="input-contentDEghTTorsp">
|
||
<view class="cu-form-group"
|
||
style="border: 2upx solid whitesmoke;margin-bottom: 20px;border-radius: 30px">
|
||
<view class="title">手机号</view>
|
||
<input type="number" :value="mobile" placeholder="请输入手机号" maxlength="11" data-key="mobile"
|
||
@input="inputChangeDEghTTorsp" />
|
||
</view>
|
||
<view class="cu-form-group" style="border: 2upx solid whitesmoke;border-radius: 30px">
|
||
<view class="title">密
|
||
<text style="margin-left: 30rpx;">码</text>
|
||
</view>
|
||
<input type="password" placeholder="请输入密码" maxlength="20" :value="code" data-key="code"
|
||
@input="inputChangeDEghTTorsp" @confirm="toLoginDEghTTorsp" />
|
||
<text class="send-msg" @click="forgetDEghTTorsp">忘记密码</text>
|
||
</view>
|
||
</view>
|
||
<button class="confirm-btnDEghTTorsp" @click="toLoginDEghTTorsp">登录</button>
|
||
|
||
<view style="margin-top: 32px;text-align: center">
|
||
<view>
|
||
没有账号?
|
||
<text style="color: #ff7581" @click="registerDEghTTorsp()">立即注册</text>
|
||
</view>
|
||
</view>
|
||
</view>
|
||
<view class="footerDEghTTorsp">
|
||
<u-checkbox-group>
|
||
<u-checkbox v-model="checked" label-size='24upx' shape="circle" @change="radioChangeDEghTTorsp"></u-checkbox>
|
||
</u-checkbox-group>
|
||
<view>同意</view>
|
||
<!-- 协议地址 -->
|
||
<navigator url="/me/setting/mimi" open-type="navigate">《隐私政策》</navigator>
|
||
和
|
||
<navigator url="/me/setting/xieyi" open-type="navigate">《用户服务协议》</navigator>
|
||
</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
|
||
};
|
||
},
|
||
onLoad() {
|
||
if (uni.getStorageSync('isSafeView')) {
|
||
uni.showModal({
|
||
title: '提示',
|
||
content: '您正在使用无痕浏览,可能导致登录状态失效,建议切换浏览模式',
|
||
})
|
||
uni.setStorageSync("isSafeView", null)
|
||
}
|
||
},
|
||
methods: {
|
||
// 注册
|
||
registerDEghTTorsp() {
|
||
uni.navigateTo({
|
||
url: '/pages/ghtwwlkXYG/WVEtZeeghK'
|
||
});
|
||
},
|
||
// 忘记密码
|
||
forgetDEghTTorsp() {
|
||
uni.navigateTo({
|
||
url: '/pages/ghtwwlkXYG/EAkIghCGJS'
|
||
});
|
||
},
|
||
inputChangeDEghTTorsp(e) {
|
||
const key = e.currentTarget.dataset.key;
|
||
this[key] = e.detail.value;
|
||
},
|
||
radioChangeDEghTTorsp(e) {
|
||
console.log(e);
|
||
},
|
||
//第一授权获取用户信息===》按钮触发
|
||
wxGetUserInfoDEghTTorsp(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.loginDEghTTorsp(nickName, avatarUrl, sex);
|
||
} catch (e) {}
|
||
}
|
||
})
|
||
} else {
|
||
uni.showToast({
|
||
title: '请同意隐私政策和用户服务协议',
|
||
icon: 'none'
|
||
})
|
||
}
|
||
},
|
||
//登录
|
||
loginDEghTTorsp(nickName, avatarUrl, sex) {
|
||
let that = this;
|
||
// 1.wx获取登录用户code
|
||
uni.login({
|
||
provider: 'weixin',
|
||
success: function(loginRes) {
|
||
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 //别人登录进来携带你的邀请码
|
||
};
|
||
that.sendDataList = sendData;
|
||
that.flag = res.data.flag;
|
||
if (that.flag == '1') {
|
||
that.weixinPhone = true;
|
||
} else {
|
||
that.getWeixinInfoDEghTTorsp(sendData);
|
||
}
|
||
} else {
|
||
uni.showToast({
|
||
icon: 'none',
|
||
title: res.msg,
|
||
duration: 2000
|
||
});
|
||
}
|
||
})
|
||
|
||
}
|
||
});
|
||
},
|
||
//小程序微信登录后获取手机号
|
||
getPhoneNumber: function(e) {
|
||
if (e.detail.errMsg == 'getPhoneNumber:fail user deny') {
|
||
console.log('用户拒绝提供手机号');
|
||
} else {
|
||
console.log('用户同意提供手机号');
|
||
this.setPhoneByInsertDEghTTorsp(e.detail.encryptedData, e.detail.iv);
|
||
}
|
||
},
|
||
//小程序微信登录后获取手机号
|
||
setPhoneByInsertDEghTTorsp(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.getWeixinInfoDEghTTorsp(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);
|
||
}
|
||
},
|
||
sendMsgDEghTTorsp() {
|
||
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 : '请一分钟后再获取验证码'
|
||
});
|
||
}
|
||
});
|
||
}
|
||
},
|
||
toLoginDEghTTorsp() {
|
||
// this.$queue.loginClear();
|
||
// let openid = this.$queue.getData('openid');
|
||
if (!this.checked) {
|
||
return this.$refs.uToast.show({
|
||
title: '请阅读并同意《隐私政策》和《用户服务协议》',
|
||
duration: 1500
|
||
})
|
||
}
|
||
|
||
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)
|
||
//设置渠道码
|
||
if (res.user.qdCode) {
|
||
uni.setStorageSync('qdCode', res.user.qdCode)
|
||
}
|
||
// uni.setStorageSync('openId', res.user.openId)
|
||
// this.getWeixinInfoDEghTTorsp(this.sendDataList);
|
||
uni.showToast({
|
||
title: '登录成功',
|
||
icon: 'none'
|
||
})
|
||
const arr= getCurrentPages()
|
||
if(arr.length<=1){
|
||
return uni.reLaunch({
|
||
url:'/pages/index/index'
|
||
})
|
||
}
|
||
uni.navigateBack({
|
||
delta: arr.length<=2?1:2
|
||
})
|
||
} else {
|
||
uni.hideLoading();
|
||
uni.showToast({
|
||
title: res.msg,
|
||
icon: 'none',
|
||
duration: 1000
|
||
})
|
||
}
|
||
});
|
||
}
|
||
},
|
||
//获取个人信息
|
||
getWeixinInfoDEghTTorsp(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
|
||
};
|
||
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)
|
||
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">
|
||
|
||
|
||
.footerDEghTTorsp {
|
||
padding-left: 150rpx;
|
||
margin-top: 32upx;
|
||
font-size: 24upx;
|
||
color: #666666;
|
||
text-align: center;
|
||
display: flex;
|
||
}
|
||
|
||
page {
|
||
background: #ffffff;
|
||
}
|
||
|
||
.send-msg {
|
||
border-radius: 30px;
|
||
color: black;
|
||
background: white;
|
||
height: 30px;
|
||
font-size: 14px;
|
||
line-height: 30px;
|
||
}
|
||
|
||
.containerDEghTTorsp {
|
||
top: 0;
|
||
padding-top: 32upx;
|
||
position: relative;
|
||
width: 100%;
|
||
height: 100%;
|
||
overflow: hidden;
|
||
background: #ffffff;
|
||
|
||
|
||
}
|
||
|
||
.wrapperDEghTTorsp {
|
||
position: relative;
|
||
z-index: 90;
|
||
background: #ffffff;
|
||
padding-bottom: 20px;
|
||
}
|
||
|
||
|
||
.input-contentDEghTTorsp {
|
||
padding: 0 20px;
|
||
}
|
||
|
||
|
||
.confirm-btnDEghTTorsp {
|
||
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;
|
||
}
|
||
}
|
||
|
||
|
||
</style> |