Commit e1c1bcb2 authored by 高铭波's avatar 高铭波

Merge branch 'dev'

parents 2568eb05 c1ab2f2a
<template> <template>
<view class=""> <view class="">
<view class="backView"> <view class="backView">
<view class="login-block" v-if="needAuth"> <view class="login-block" v-if="needAuth">
<u-image class="u-flex u-row-center logo" :src="logo" width="200" height="200"> <u-image class="u-flex u-row-center logo" :src="logo" width="200" height="200">
<u-loading slot="loading"></u-loading> <u-loading slot="loading"></u-loading>
<view slot="error" style="font-size: 24rpx;">加载失败</view> <view slot="error" style="font-size: 24rpx;">加载失败</view>
</u-image> </u-image>
<u-image class="u-flex u-row-center logo2" :src="logo2" width="214" height="60"> <u-image class="u-flex u-row-center logo2" :src="logo2" width="214" height="60">
<u-loading slot="loading"></u-loading> <u-loading slot="loading"></u-loading>
<view slot="error" style="font-size: 24rpx;">加载失败</view> <view slot="error" style="font-size: 24rpx;">加载失败</view>
</u-image> </u-image>
</view> </view>
<view class="bind-block" v-else> <view class="bind-block" v-else>
<u-image class="u-flex u-row-between logo" :src="logo" width="148" height="148"> <u-image class="u-flex u-row-between logo" :src="logo" width="148" height="148">
<u-loading slot="loading"></u-loading> <u-loading slot="loading"></u-loading>
<view slot="error" style="font-size: 24rpx;">加载失败</view> <view slot="error" style="font-size: 24rpx;">加载失败</view>
</u-image> </u-image>
<view class="bind-phone">{{ bindPhone }}</view> <view class="bind-phone">{{ bindPhone }}</view>
<view class="bind-tips">{{ bindTips }}</view> <view class="bind-tips">{{ bindTips }}</view>
</view> </view>
<u-gap height="570"></u-gap> <u-gap height="570"></u-gap>
<button class="loginBtn" v-if="needAuth" lang="zh_CN" @tap="getUserProfile"> <button class="loginBtn" v-if="needAuth" lang="zh_CN" @tap="getUserProfile">
<text class="u-font-32 white">{{ loginTitle }}</text> <text class="u-font-32 white">{{ loginTitle }}</text>
</button> </button>
<button class="loginBtn" v-else open-type="getPhoneNumber" throttle-time="1000" <button class="loginBtn" v-else open-type="getPhoneNumber" throttle-time="1000"
@getphonenumber="signupLogin"> @getphonenumber="signupLogin">
<text class="u-font-32 white">{{ bindTitle }}</text> <text class="u-font-32 white">{{ bindTitle }}</text>
</button> </button>
</view> </view>
</view> </view>
</template> </template>
<script> <script>
import util from '@/utils/util.js' import util from '@/utils/util.js'
import login from '@/utils/login.js' import login from '@/utils/login.js'
const app = getApp() const app = getApp()
export default { export default {
data() { data() {
return { return {
qnPath: process.uniEnv.qn_base_url, qnPath: process.uniEnv.qn_base_url,
needAuth: true, needAuth: true,
TimeID: -1, TimeID: -1,
loginTitle: '用户登录', loginTitle: '用户登录',
bindTitle: '立即绑定', bindTitle: '立即绑定',
bindPhone: '绑定手机', bindPhone: '绑定手机',
bindTips: '首次登录的用户需绑定手机才可接单', bindTips: '首次登录的用户需绑定手机才可接单',
} code: ''
}, }
computed: { },
logo() { computed: {
return this.qnPath + 'logo.png' logo() {
}, return this.qnPath + 'logo.png'
logo2() { },
return this.qnPath + 'logo-2.png' logo2() {
}, return this.qnPath + 'logo-2.png'
}, },
onLoad(e) { },
app.trackPage('授权登录页') onLoad(e) {
}, app.trackPage('授权登录页')
onShow() { },
// 微信授权过用户信息,则无需重复授权 onShow() {
if (app.globalData.authUserInfo) { // 微信授权过用户信息,则无需重复授权
this.needAuth = false if (app.globalData.authUserInfo) {
} this.needAuth = false
}, }
methods: { this.getCode()
// 微信授权用户信息 },
getUserProfile() { methods: {
var that = this async getCode() {
if(uni.getUserProfile) { login.appLogin().then(res => {
// 每次触发 uni.getUserProfile 均会弹出授权窗口,用户授权后可成功获取用户信息 this.code = res.code
uni.getUserProfile({ })
desc: '用于授权登录', },
success: function (res) { // 微信授权用户信息
const userInfo = res.userInfo; getUserProfile() {
app.globalData.authUserInfo = userInfo var that = this
app.globalData.authUserInfo.nickName = app.globalData.authUserInfo.nickName || '' if(uni.getUserProfile) {
app.globalData.authUserInfo.avatarUrl = app.globalData.authUserInfo.avatarUrl || '' // 每次触发 uni.getUserProfile 均会弹出授权窗口,用户授权后可成功获取用户信息
uni.showLoading({ uni.getUserProfile({
title: '授权中..', desc: '用于授权登录',
mask: true success: function (res) {
}); const userInfo = res.userInfo;
if (getApp().globalData.logout) { app.globalData.authUserInfo = userInfo
uni.hideLoading() app.globalData.authUserInfo.nickName = app.globalData.authUserInfo.nickName || ''
that.setLoginStatus() app.globalData.authUserInfo.avatarUrl = app.globalData.authUserInfo.avatarUrl || ''
} else { uni.showLoading({
that.authLogin() title: '授权中..',
} mask: true
}, });
fail: function (res) { if (getApp().globalData.logout) {
uni.showModal({ uni.hideLoading()
title: '授权失败', that.setLoginStatus()
content: '请允许获取用户信息的授权', } else {
showCancel: false that.authLogin()
}); }
} },
}) fail: function (res) {
} else { uni.showModal({
// 可能由于账号配置,或者其他原因导致无法调起微信用户授权 title: '授权失败',
uni.showModal({ content: '请允许获取用户信息的授权',
title: '授权失败', showCancel: false
content: '请确认你的用户授权是否可用', });
showCancel: false }
}); })
} } else {
}, // 可能由于账号配置,或者其他原因导致无法调起微信用户授权
authLogin() { uni.showModal({
var that = this title: '授权失败',
let params = { content: '请确认你的用户授权是否可用',
nickname: app.globalData.authUserInfo.nickName, showCancel: false
avatar: app.globalData.authUserInfo.avatarUrl, });
} }
login.appLogin().then(res => { },
params.code = res.code authLogin() {
return login.authorization(params); var that = this
}).then(res => { let params = {
uni.hideLoading(); nickname: app.globalData.authUserInfo.nickName,
if (res && res.code == 200 && res.data && res.data.token) { avatar: app.globalData.authUserInfo.avatarUrl,
app.setUserData(res.data, that) }
that.goBackPage() login.appLogin().then(res => {
} else { params.code = res.code
that.setLoginStatus() return login.authorization(params);
} }).then(res => {
}).catch(res => { uni.hideLoading();
uni.hideLoading() if (res && res.code == 200 && res.data && res.data.token) {
that.setLoginStatus() app.setUserData(res.data, that)
}) that.goBackPage()
}, } else {
that.setLoginStatus()
signupLogin(e) { }
var that = this }).catch(res => {
if(e && e.detail) { uni.hideLoading()
if(e.detail.errMsg.indexOf('user deny') > -1) { that.setLoginStatus()
uni.showModal({ })
title: '提示', },
showCancel: false,
content: '用户未授权不能完成注册' signupLogin(e) {
}); var that = this
} else if(e.detail.encryptedData && e.detail.iv) { if(e && e.detail) {
let params = { if(e.detail.errMsg.indexOf('user deny') > -1) {
nickname: app.globalData.authUserInfo.nickName, uni.showModal({
avatar: app.globalData.authUserInfo.avatarUrl, title: '提示',
encryptedData: e.detail.encryptedData, showCancel: false,
iv: e.detail.iv, content: '用户未授权不能完成注册'
} });
login.appLogin().then(res => { } else if(e.detail.encryptedData && e.detail.iv) {
params.code = res.code let params = {
return login.signup(params); nickname: app.globalData.authUserInfo.nickName,
}).then(res => { avatar: app.globalData.authUserInfo.avatarUrl,
uni.hideLoading() encryptedData: e.detail.encryptedData,
if (res) { iv: e.detail.iv,
app.setUserData(res.data, that) }
app.getBaseInfo(that) if (that.code) {
that.goBackPage() uni.checkSession({
} else { success () {
uni.showToast({ //session_key 未过期,并且在本生命周期一直有效
title: '授权失败,请重新授权', params.code = that.code
icon: 'none' login.signup(params).then(res => {
}); uni.hideLoading()
this.setLoginStatus(false) if (res) {
} app.setUserData(res.data, that)
}).catch(res => { app.getBaseInfo(that)
uni.hideLoading() that.goBackPage()
this.setLoginStatus(false) } else {
}) uni.showToast({
} else { title: '授权失败,请重新授权',
uni.showModal({ icon: 'none'
title: '提示', });
showCancel: false, this.setLoginStatus(false)
content: e.detail.errMsg }
}); }).catch(res => {
} uni.hideLoading()
} else { this.setLoginStatus(false)
uni.showModal({ })
title: '提示', },
showCancel: false, fail () {
content: '授权失败,请重新授权' // session_key 已经失效,需要重新执行登录流程
}); that.toLogin(params)
} }
}, })
} else {
goBackPage() { this.toLogin(params)
let pages = getCurrentPages(); }
if(pages.length) { } else {
let index = pages.length - 1; uni.showModal({
if(index) { title: '提示',
let prevPage = pages[index]; //上一个页面 showCancel: false,
if (prevPage && prevPage.$vm) { content: e.detail.errMsg
prevPage.$vm.isRefresh = true; });
} }
uni.navigateBack({ } else {
delta: 1 uni.showModal({
}) title: '提示',
} else { showCancel: false,
uni.redirectTo({ content: '授权失败,请重新授权'
url:'pages/index/index' });
}) }
} },
} else { toLogin(params) {
uni.reLaunch({ login.appLogin().then(res => {
url: "pages/index/mine" params.code = res.code
}) console.log("params3", params)
} return login.signup(params);
}).then(res => {
}, uni.hideLoading()
setLoginStatus(authed = true) { if (res) {
getApp().globalData.logout = false app.setUserData(res.data, that)
if (authed) { app.getBaseInfo(that)
this.needAuth = false that.goBackPage()
uni.setNavigationBarTitle({ } else {
title: '登录页' uni.showToast({
}); title: '授权失败,请重新授权',
} else { icon: 'none'
if(!app.globalData.authUserInfo) { });
this.needAuth = true this.setLoginStatus(false)
uni.setNavigationBarTitle({ }
title: '授权页' }).catch(res => {
}); uni.hideLoading()
} this.setLoginStatus(false)
} })
}, },
goBackPage() {
//取消点击 let pages = getCurrentPages();
cancelClick: function () { if(pages.length) {
uni.navigateBack({}) let index = pages.length - 1;
}, if(index) {
} let prevPage = pages[index]; //上一个页面
} if (prevPage && prevPage.$vm) {
</script> prevPage.$vm.isRefresh = true;
}
<style lang="scss" scoped> uni.navigateBack({
.backView { delta: 1
background-color: #FFFFFF; })
position: absolute; } else {
top: 0; uni.redirectTo({
left: 0; url:'pages/index/index'
width: 100%; })
height: 100%; }
} else {
.login-block { uni.reLaunch({
margin-top: 240rpx; url: "pages/index/mine"
} })
.bind-block { }
margin-top: 202rpx;
margin-left: 50rpx; },
.bind-phone { setLoginStatus(authed = true) {
font-size: 52rpx; getApp().globalData.logout = false
margin-top: 48rpx; this.code = ''
font-weight: bold; if (authed) {
color: #333333; this.needAuth = false
line-height: 52rpx; uni.setNavigationBarTitle({
margin-left: 10rpx; title: '登录页'
} });
.bind-tips { } else {
margin: 24rpx 60rpx 14rpx 10rpx; if(!app.globalData.authUserInfo) {
font-size: 28rpx; this.needAuth = true
font-weight: 400; uni.setNavigationBarTitle({
color: #999999; title: '授权页'
line-height: 40rpx; });
} }
} }
} },
.logo2 {
margin-top: 28rpx; //取消点击
} cancelClick: function () {
uni.navigateBack({})
.noticeView { },
background-color: #FFFFFF; }
width: 100%; }
height: 470rpx; </script>
display: flex;
flex-direction: column; <style lang="scss" scoped>
align-items: center; .backView {
} background-color: #FFFFFF;
position: absolute;
.noticeImage { top: 0;
background-color: #FFFFFF; left: 0;
width: 386rpx; width: 100%;
height: 270rpx; height: 100%;
margin-top: 180rpx;
} .login-block {
margin-top: 240rpx;
.noticeTitleView { }
margin-top: 80rpx; .bind-block {
width: 100%; margin-top: 202rpx;
display: flex; margin-left: 50rpx;
align-items: center; .bind-phone {
justify-content: center; font-size: 52rpx;
} margin-top: 48rpx;
font-weight: bold;
.noticeTitle { color: #333333;
width: 60%; line-height: 52rpx;
font-size: 24rpx; margin-left: 10rpx;
color: #999999; }
text-align: center; .bind-tips {
line-height: 40rpx; margin: 24rpx 60rpx 14rpx 10rpx;
} font-size: 28rpx;
font-weight: 400;
.loginBtn { color: #999999;
background-color: #2272FF; line-height: 40rpx;
font-size: 32rpx; }
font-weight: 600; }
color: #FFFFFF; }
line-height: 104px; .logo2 {
width: 600rpx; margin-top: 28rpx;
height: 104rpx; }
border-radius: 52rpx;
display: flex; .noticeView {
align-items: center; background-color: #FFFFFF;
justify-content: center; width: 100%;
} height: 470rpx;
display: flex;
.cancelView { flex-direction: column;
width: 100%; align-items: center;
margin-top: 30rpx; }
display: flex;
align-items: center; .noticeImage {
justify-content: center; background-color: #FFFFFF;
} width: 386rpx;
height: 270rpx;
.cancelText { margin-top: 180rpx;
color: #666666; }
font-size: 32rpx;
} .noticeTitleView {
margin-top: 80rpx;
.white { width: 100%;
color: #FFFFFF; display: flex;
} align-items: center;
justify-content: center;
</style> }
.noticeTitle {
width: 60%;
font-size: 24rpx;
color: #999999;
text-align: center;
line-height: 40rpx;
}
.loginBtn {
background-color: #2272FF;
font-size: 32rpx;
font-weight: 600;
color: #FFFFFF;
line-height: 104px;
width: 600rpx;
height: 104rpx;
border-radius: 52rpx;
display: flex;
align-items: center;
justify-content: center;
}
.cancelView {
width: 100%;
margin-top: 30rpx;
display: flex;
align-items: center;
justify-content: center;
}
.cancelText {
color: #666666;
font-size: 32rpx;
}
.white {
color: #FFFFFF;
}
</style>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment