Commit 01078be8 authored by 刘文虎's avatar 刘文虎

更改用户授权方式-无需用户授权-code+手机验证码登录

parent 87f94581
...@@ -138,9 +138,9 @@ export default { ...@@ -138,9 +138,9 @@ export default {
this.profileSet(this) this.profileSet(this)
this.profileAppend(this) this.profileAppend(this)
} else { } else {
uni.navigateTo({ // uni.navigateTo({
url: "pages/login/index", // url: "pages/login/index",
}); // });
} }
} else { } else {
uni.showModal({ uni.showModal({
......
let commonApiFun = function(vm){ const globalUrl = process.uniEnv || {}
const ucenterApiUrl = globalUrl.ucenterUrl.apiUrl
let commonApiFun = function(vm){
/* 登录 */
let loginWechatAuth = async (params = {}) => await vm.$u.post('/wxh-support-rest/rest/ssoinfo/wxapp/unify/authorization', params, {'content-type': 'application/x-www-form-urlencoded'}); let loginWechatAuth = async (params = {}) => await vm.$u.post('/wxh-support-rest/rest/ssoinfo/wxapp/unify/authorization', params, {'content-type': 'application/x-www-form-urlencoded'});
/* 2023-04-18 新版登录 */
let newLoginWechatAuth = async (params = {}) => await vm.$u.post('/wxh-support-rest/rest/ssoinfo/wxapp/unify/authorization/v2', params, {'content-type': 'application/x-www-form-urlencoded'});
/* 发送验证码 */
let sendCode = async (params = {}) => await vm.$u.post('/wxh-support-rest/rest/ssoinfo/wxapp/sendMessage', params, {'content-type': 'application/x-www-form-urlencoded'});
// 水印-查询用户自定义设置 // 水印-查询用户自定义设置
let getUserWatermark = async (params = {}) => await vm.$u.post('http://apidoc.banshouhui.com:3000/mock/89/getUserWatermark', params); let getUserWatermark = async (params = {}) => await vm.$u.post('http://apidoc.banshouhui.com:3000/mock/89/getUserWatermark', params);
// 水印-保存用户自定义设置 // 水印-保存用户自定义设置
...@@ -9,6 +16,8 @@ let commonApiFun = function(vm){ ...@@ -9,6 +16,8 @@ let commonApiFun = function(vm){
const commonApi = { const commonApi = {
loginWechatAuth, loginWechatAuth,
newLoginWechatAuth,
sendCode,
getUserWatermark, getUserWatermark,
saveUserWatermark, saveUserWatermark,
saveImage saveImage
......
{ {
"name" : "自营平台", "name" : "扳手会",
"appid" : "__UNI__05F3AA2", "appid" : "__UNI__05F3AA2",
"description" : "", "description" : "",
"versionName" : "1.0.0", "versionName" : "1.0.0",
"versionCode" : "100", "versionCode" : "100",
"transformPx" : false, "transformPx" : false,
"networkTimeout" : { "networkTimeout" : {
"connectSocket": 100000, "connectSocket" : 100000,
"uploadFile": 100000, "uploadFile" : 100000,
"downloadFile": 100000 "downloadFile" : 100000
}, },
"app-plus" : { "app-plus" : {
"optimization" : { "optimization" : {
...@@ -67,7 +67,6 @@ ...@@ -67,7 +67,6 @@
"quickapp" : {}, "quickapp" : {},
/* 快应用特有相关 */ /* 快应用特有相关 */
"mp-weixin" : { "mp-weixin" : {
/* 微信小程序特有相关 */
"appid" : "wx402a711597dddbaf", "appid" : "wx402a711597dddbaf",
"optimization" : { "optimization" : {
"subPackages" : true "subPackages" : true
...@@ -80,22 +79,17 @@ ...@@ -80,22 +79,17 @@
"usingComponents" : true, "usingComponents" : true,
"permission" : { "permission" : {
"scope.userLocation" : { "scope.userLocation" : {
"desc" : "方便查看订单与你的距离" "desc" : "你的位置信息将用于小程序获取所在地与订单地点的距离"
}
},
"requiredPrivateInfos": ["getLocation", "onLocationChange", "startLocationUpdate"],
"permission" : {
"scope.userLocation" : {
"desc" : "你的位置信息将用于小程序获取所在地与订单地点的距离"
} }
}, },
"requiredPrivateInfos" : [ "getLocation", "onLocationChange", "startLocationUpdate" ],
"uniStatistics" : { "uniStatistics" : {
"enable" : true "enable" : true
}, },
"plugins": { "plugins" : {
"contactPlugin": { "contactPlugin" : {
"version": "1.4.4", "version" : "1.4.4",
"provider": "wx104a1a20c3f81ec2" "provider" : "wx104a1a20c3f81ec2"
} }
} }
}, },
......
...@@ -40,7 +40,7 @@ ...@@ -40,7 +40,7 @@
{ {
"path": "pages/login/index", "path": "pages/login/index",
"style": { "style": {
// "navigationBarTitleText": "授权登录", "navigationBarTitleText": "绑定手机",
"navigationBarBackgroundColor": "#FFFFFF", "navigationBarBackgroundColor": "#FFFFFF",
"disableScroll": true "disableScroll": true
} }
......
...@@ -205,6 +205,10 @@ export default { ...@@ -205,6 +205,10 @@ export default {
this.loaded = true; this.loaded = true;
} else { } else {
this.loaded = true; this.loaded = true;
if (this.freshing) {
this.triggered = false;
this.freshing = false;
}
} }
}, },
loadMessageList() { loadMessageList() {
......
...@@ -787,6 +787,13 @@ export default { ...@@ -787,6 +787,13 @@ export default {
}, },
//跳转到assessment页面 //跳转到assessment页面
aaa(index) { aaa(index) {
if (!this.vuex_token) {
uni.showToast({
icon:'none',
title:"请先登录"
})
return false;
}
//examStatus 用户考试状态 0考试中 1考试完成 2未参与 //examStatus 用户考试状态 0考试中 1考试完成 2未参与
//考试完成分成通过、未通过 //考试完成分成通过、未通过
getApp().globalData.questionTime = this.examList[index].questionTime; getApp().globalData.questionTime = this.examList[index].questionTime;
......
...@@ -272,7 +272,11 @@ export default { ...@@ -272,7 +272,11 @@ export default {
app.getBaseInfo(self); app.getBaseInfo(self);
}, },
handleClick(path, isWarehouse) { handleClick(path, isWarehouse) {
if (this.vuex_token) { if(path==='about/about'){
this.$u.route({
url: 'pages/mine/' + path
});
}else if (this.vuex_token) {
// 没入驻不能进入仓配相关页面 // 没入驻不能进入仓配相关页面
if (isWarehouse && this.needSettled) { if (isWarehouse && this.needSettled) {
this.$refs.uToast.show({ this.$refs.uToast.show({
......
<template>
<view class="">
<!-- <w-navbar></w-navbar> -->
<view class="backView">
<view class="login-block" v-if="needAuth">
<u-image :fade="false" class="u-flex u-row-center logo" :src="logo" width="200" height="200">
<u-loading slot="loading"></u-loading>
<view slot="error" style="font-size: 24rpx;">加载失败</view>
</u-image>
<u-image :fade="false" class="u-flex u-row-center logo2" :src="logo2" width="214" height="60">
<u-loading slot="loading"></u-loading>
<view slot="error" style="font-size: 24rpx;">加载失败</view>
</u-image>
</view>
<view class="bind-block" v-else>
<u-image :fade="false" class="u-flex u-row-between logo" :src="logo" width="148" height="148">
<u-loading slot="loading"></u-loading>
<view slot="error" style="font-size: 24rpx;">加载失败</view>
</u-image>
<view class="bind-phone">{{ bindPhone }}</view>
<view class="bind-tips">{{ bindTips }}</view>
</view>
<u-gap height="480"></u-gap>
<view v-if="needAuth" @click.capture="loadLogin">
<button class="loginBtn" lang="zh_CN"
@tap="getUserProfile">
<text class="u-font-32 white">{{ loginTitle }}</text>
</button>
</view>
<view @click.capture="getCode" v-else>
<button class="loginBtn" open-type="getPhoneNumber"
throttle-time="1000" @getphonenumber="signupLogin">
<text class="u-font-32 white">{{ bindTitle }}</text>
</button>
</view>
</view>
</view>
</template>
<script>
import util from '@/utils/util.js'
import login from '@/utils/login.js'
const app = getApp()
export default {
data() {
return {
needAuth: true,
TimeID: -1,
loginTitle: '用户登录',
bindTitle: '立即绑定',
bindPhone: '绑定手机',
bindTips: '首次登录的用户需绑定手机才可接单',
code: '',
}
},
computed: {
logo() {
return this.qnFile('logo.png')
},
logo2() {
return this.qnFile('logo-2.png')
},
},
onLoad(e) {
app.trackPage('授权登录页')
},
onShow() {
// 微信授权过用户信息,则无需重复授权
if (this.vuex_auth_user && Object.keys(this.vuex_auth_user).length) {
this.needAuth = false
}
},
methods: {
loadLogin() {
uni.showLoading({
title: '加载中..',
mask: true
});
},
qnFile(src) {
return process.uniEnv.qn_base_url + src
},
async getCode() {
login.appLogin().then(res => {
this.code = res.code
})
},
// 微信授权用户信息
getUserProfile() {
var that = this
if(uni.getUserProfile) {
// 每次触发 uni.getUserProfile 均会弹出授权窗口,用户授权后可成功获取用户信息
uni.getUserProfile({
desc: '用于授权登录',
success: function (res) {
const userInfo = res.userInfo;
that.$u.vuex('vuex_auth_user', userInfo)
uni.showLoading({
title: '授权中..',
mask: true
});
if (getApp().globalData.logout) {
uni.hideLoading()
that.setLoginStatus()
} else {
that.authLogin()
}
},
fail: function (res) {
uni.hideLoading()
uni.showModal({
title: '授权失败',
content: '请允许获取用户信息的授权',
showCancel: false
});
}
})
} else {
uni.hideLoading()
// 可能由于账号配置,或者其他原因导致无法调起微信用户授权
uni.showModal({
title: '授权失败',
content: '请确认你的用户授权是否可用',
showCancel: false
});
}
},
authLogin() {
var that = this
let params = {
nickname: this.vuex_auth_user.nickName || '',
avatar: this.vuex_auth_user.avatarUrl || '',
}
login.appLogin().then(res => {
params.code = res.code
return login.authorization(params);
}).then(res => {
uni.hideLoading();
if (res && res.code == 200 && res.data && res.data.token) {
login.setUserData(res.data, that)
app.track('auth_login', {mobile: res.data.mobile});
app.profileSet(that)
app.profileAppend(that)
that.goBackPage()
} else {
that.setLoginStatus()
}
}).catch(res => {
uni.hideLoading()
that.setLoginStatus()
})
},
inGetAuth() {
uni.showLoading({
title: '授权中..',
mask: true
});
},
signupLogin(e) {
var that = this
if(e && e.detail) {
if(e.detail.errMsg.indexOf('user deny') > -1) {
uni.showModal({
title: '提示',
showCancel: false,
content: '用户未授权不能完成注册'
});
} else if(e.detail.encryptedData && e.detail.iv) {
let params = {
nickname: this.vuex_auth_user.nickName || '',
avatar: this.vuex_auth_user.avatarUrl || '',
encryptedData: e.detail.encryptedData,
iv: e.detail.iv,
}
if (that.code) {
that.inGetAuth()
uni.checkSession({
success () {
//session_key 未过期,并且在本生命周期一直有效
params.code = that.code
that.inGetAuth()
login.signup(params).then(res => {
that.inGetAuth()
if (res) {
login.setUserData(res.data, that)
app.track('signup_login', {mobile: res.data.mobile});
app.profileSet(that)
app.profileAppend(that)
app.getBaseInfo(that)
uni.hideLoading()
that.goBackPage()
} else {
uni.hideLoading()
uni.showToast({
title: '授权失败,请重新授权',
icon: 'none'
});
that.setLoginStatus(false)
}
}).catch(res => {
uni.hideLoading()
that.setLoginStatus(false)
})
},
fail () {
// session_key 已经失效,需要重新执行登录流程
that.toLogin(params)
}
})
} else {
that.toLogin(params)
}
} else {
uni.hideLoading()
uni.showModal({
title: '提示',
showCancel: false,
content: '用户取消授权'
});
}
} else {
uni.hideLoading()
uni.showModal({
title: '提示',
showCancel: false,
content: '授权失败,请重新授权'
});
}
},
toLogin(params) {
login.appLogin().then(res => {
params.code = res.code
return login.signup(params);
}).then(res => {
if (res) {
login.setUserData(res.data, this)
app.track('signup_login', {mobile: res.data.mobile});
app.profileSet(this)
app.profileAppend(this)
app.getBaseInfo(this)
this.goBackPage()
} else {
uni.hideLoading()
uni.showToast({
title: '授权失败,请重新授权',
icon: 'none'
});
this.setLoginStatus(false)
}
}).catch(res => {
uni.hideLoading()
this.setLoginStatus(false)
})
},
goBackPage() {
let pages = getCurrentPages();
if(pages.length) {
let index = pages.length - 1;
if(index) {
let prevPage = pages[index]; //上一个页面
if (prevPage && prevPage.$vm) {
prevPage.$vm.isRefresh = true;
}
uni.navigateBack({
delta: 1
})
} else {
uni.redirectTo({
url:'pages/index/index'
})
}
} else {
uni.reLaunch({
url: "pages/index/mine"
})
}
},
setLoginStatus(authed = true) {
getApp().globalData.logout = false
this.code = ''
if (authed) {
this.needAuth = false
uni.setNavigationBarTitle({
title: '登录页'
});
} else {
if(!this.vuex_auth_user || !Object.keys(this.vuex_auth_user).length) {
this.needAuth = true
uni.setNavigationBarTitle({
title: '授权页'
});
}
}
},
//取消点击
cancelClick: function () {
uni.navigateBack({})
},
}
}
</script>
<style lang="scss" scoped>
.backView {
background-color: #FFFFFF;
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
.login-block {
margin-top: 240rpx;
}
.bind-block {
margin-top: 202rpx;
margin-left: 50rpx;
.bind-phone {
font-size: 52rpx;
margin-top: 48rpx;
font-weight: bold;
color: #333333;
line-height: 52rpx;
margin-left: 10rpx;
}
.bind-tips {
margin: 24rpx 60rpx 14rpx 10rpx;
font-size: 28rpx;
font-weight: 400;
color: #999999;
line-height: 40rpx;
}
}
}
.logo2 {
margin-top: 28rpx;
}
.noticeView {
background-color: #FFFFFF;
width: 100%;
height: 470rpx;
display: flex;
flex-direction: column;
align-items: center;
}
.noticeImage {
background-color: #FFFFFF;
width: 386rpx;
height: 270rpx;
margin-top: 180rpx;
}
.noticeTitleView {
margin-top: 80rpx;
width: 100%;
display: flex;
align-items: center;
justify-content: center;
}
.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;
}
.disable {
background-color: #2272FF !important;
font-size: 32rpx;
font-weight: 600;
color: #FFFFFF !important;
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>
<template> <template>
<view class=""> <view class="binding-phone-view">
<!-- <w-navbar></w-navbar> --> <view class="title-view">绑定手机</view>
<view class="backView"> <view class="text-view">首次登录的用户需绑定手机</view>
<view class="login-block" v-if="needAuth"> <view class="phone-view">
<u-image :fade="false" class="u-flex u-row-center logo" :src="logo" width="200" height="200"> <view class="left-view">+86</view>
<u-loading slot="loading"></u-loading> <view class="middle-view"></view>
<view slot="error" style="font-size: 24rpx;">加载失败</view> <view class="right-view"><input v-model="phone" type="number" width="100%" maxlength="20" clearable />
</u-image>
<u-image :fade="false" class="u-flex u-row-center logo2" :src="logo2" width="214" height="60">
<u-loading slot="loading"></u-loading>
<view slot="error" style="font-size: 24rpx;">加载失败</view>
</u-image>
</view> </view>
<view class="bind-block" v-else> </view>
<u-image :fade="false" class="u-flex u-row-between logo" :src="logo" width="148" height="148"> <view class="code-view">
<u-loading slot="loading"></u-loading> <view class="left-view"><input v-model="code" type="number" maxlength="6" clearable /></view>
<view slot="error" style="font-size: 24rpx;">加载失败</view> <view class="right-view">
</u-image> <u-toast ref="uToast"></u-toast>
<view class="bind-phone">{{ bindPhone }}</view> <u-verification-code keep-running unique-key="binding-phone" :seconds="seconds" @end="end"
<view class="bind-tips">{{ bindTips }}</view> @start="start" ref="uCode" @change="codeChange"></u-verification-code>
<text :class="{ active: canGetCode }" @tap="$u.throttle(handleClick, 500)">{{ tips }}</text>
</view> </view>
<u-gap height="480"></u-gap> </view>
<view v-if="needAuth" @click.capture="loadLogin"> <view class="bottom-vew" >
<button class="loginBtn" lang="zh_CN" <u-button type="primary" :disabled="disabled" :customStyle="buttonStyle" :loading="loading" @click="handleClickSave">
@tap="getUserProfile"> <view class="button-text">立即绑定</view>
<text class="u-font-32 white">{{ loginTitle }}</text> </u-button>
</button>
</view>
<view @click.capture="getCode" v-else>
<button class="loginBtn" open-type="getPhoneNumber"
throttle-time="1000" @getphonenumber="signupLogin">
<text class="u-font-32 white">{{ bindTitle }}</text>
</button>
</view>
</view> </view>
</view> </view>
</template> </template>
<script> <script>
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 { phone: '13423831191',
needAuth: true, code: '174253',
TimeID: -1, timer: null,
loginTitle: '用户登录', canGetCode: true,
bindTitle: '立即绑定', seconds: 60,
bindPhone: '绑定手机', encryptedData: '',
bindTips: '首次登录的用户需绑定手机才可接单', iv: '',
code: '', loading: false,
} weixinAuthService: null,
}, params: {},
computed: { tips: '',
logo() { buttonStyle: {
return this.qnFile('logo.png') height: '104rpx',
backgroundColor: '#2979ff',
color: 'transparent'
}
};
}, },
logo2() { computed: {
return this.qnFile('logo-2.png') disabled() {
return this.code && this.phone ? false : true;
}
}, },
}, onReady() {
onLoad(e) { this.canGetCode = this.$refs.uCode.canGetCode ? true : false;
app.trackPage('授权登录页')
},
onShow() {
// 微信授权过用户信息,则无需重复授权
if (this.vuex_auth_user && Object.keys(this.vuex_auth_user).length) {
this.needAuth = false
}
},
methods: {
loadLogin() {
uni.showLoading({
title: '加载中..',
mask: true
});
},
qnFile(src) {
return process.uniEnv.qn_base_url + src
}, },
async getCode() { onLoad(options) {
login.appLogin().then(res => { console.log('-----options----', options);
this.code = res.code
}) if (options) {
let {
unionId
} = options;
if (unionId) {
this.params = options;
}
}
}, },
// 微信授权用户信息 methods: {
getUserProfile() { handleClick() {
var that = this if (this.phone == '') {
if(uni.getUserProfile) { uni.showToast({
// 每次触发 uni.getUserProfile 均会弹出授权窗口,用户授权后可成功获取用户信息 title: '请输入手机号',
uni.getUserProfile({ icon: 'none',
desc: '用于授权登录', duration: 1500
success: function (res) { });
const userInfo = res.userInfo; return;
that.$u.vuex('vuex_auth_user', userInfo) }
uni.showLoading({ var reg = /^[1][3456789][0-9]{9}$/;
title: '授权中..', if (!reg.test(this.phone)) {
mask: true uni.showToast({
icon: 'none',
title: '请输入正确的手机号'
});
return false;
}
this.startCode();
},
startCode() {
if (this.$refs.uCode.canGetCode) {
// 模拟向后端请求验证码
this.$u.toast('正在获取验证码');
this.getCode();
}
},
async getCode() {
try {
let res = await uni.$u.api.sendCode({
mobile: this.phone
});
uni.hideLoading();
if (res.data) {
this.$u.toast('验证码已发送');
this.$refs.uCode.start();
console.log('--------发送成功----------');
} else {
uni.showToast({
title: '获取验证码失败',
icon: 'none'
}); });
if (getApp().globalData.logout) { }
uni.hideLoading() } catch (e) {
that.setLoginStatus() console.log(e);
} else { if (e.msg) {
that.authLogin() uni.showToast({
} title: e.msg,
}, icon: 'none'
fail: function (res) {
uni.hideLoading()
uni.showModal({
title: '授权失败',
content: '请允许获取用户信息的授权',
showCancel: false
}); });
} }
}) //TODO handle the exception
} else { uni.hideLoading();
uni.hideLoading()
// 可能由于账号配置,或者其他原因导致无法调起微信用户授权
uni.showModal({
title: '授权失败',
content: '请确认你的用户授权是否可用',
showCancel: false
});
}
},
authLogin() {
var that = this
let params = {
nickname: this.vuex_auth_user.nickName || '',
avatar: this.vuex_auth_user.avatarUrl || '',
}
login.appLogin().then(res => {
params.code = res.code
return login.authorization(params);
}).then(res => {
uni.hideLoading();
if (res && res.code == 200 && res.data && res.data.token) {
login.setUserData(res.data, that)
app.track('auth_login', {mobile: res.data.mobile});
app.profileSet(that)
app.profileAppend(that)
that.goBackPage()
} else {
that.setLoginStatus()
} }
}).catch(res => { },
uni.hideLoading() handleClickSave() {
that.setLoginStatus() this.signup();
}) },
}, signup() {
inGetAuth() { this.loading = true;
uni.showLoading({ var reg = /^[1][3456789][0-9]{9}$/;
title: '授权中..', if (!reg.test(this.phone)) {
mask: true uni.showToast({
}); icon: 'none',
}, title: '请输入正确的手机号'
signupLogin(e) {
var that = this
if(e && e.detail) {
if(e.detail.errMsg.indexOf('user deny') > -1) {
uni.showModal({
title: '提示',
showCancel: false,
content: '用户未授权不能完成注册'
}); });
} else if(e.detail.encryptedData && e.detail.iv) { this.loading = false;
return false;
}
if (uni.$u.platform === '4') {
this.onAppLogin();
} else {
this.onWxLogin();
}
},
async onWxLogin() {
try {
let res = await login.appLogin();
let params = { let params = {
nickname: this.vuex_auth_user.nickName || '', code: res.code,
avatar: this.vuex_auth_user.avatarUrl || '', // nickname: userInfo.nickName,
encryptedData: e.detail.encryptedData, // avatar: userInfo.avatarUrl,
iv: e.detail.iv, // encryptedData: this.encryptedData,
} // iv: this.iv,
if (that.code) { // verify: this.code,
that.inGetAuth() };
uni.checkSession({ this.onAppLogin(params)
success () { } catch (e) {
//session_key 未过期,并且在本生命周期一直有效 console.log('onWxLogin:fail', e);
params.code = that.code this.loading = false;
that.inGetAuth() //TODO handle the exception
login.signup(params).then(res => { }
that.inGetAuth() this.loading = false;
if (res) { },
login.setUserData(res.data, that) async onAppLogin(paramsData={}) {
app.track('signup_login', {mobile: res.data.mobile}); let params = {
app.profileSet(that) ...paramsData,
app.profileAppend(that) mobileCode: this.code,
app.getBaseInfo(that) mobile: this.phone,
uni.hideLoading() wxAppNo:1
that.goBackPage() };
} else { try {
uni.hideLoading() let res = await uni.$u.api.newLoginWechatAuth(params);
uni.showToast({ if (res&&res.code === 200) {
title: '授权失败,请重新授权', login.setUserData(res.data, this)
icon: 'none' app.track('signup_login', {mobile: res.data.mobile});
}); app.profileSet(this)
that.setLoginStatus(false) app.profileAppend(this)
} app.getBaseInfo(this)
}).catch(res => { uni.showToast({
uni.hideLoading() title: '登录成功',
that.setLoginStatus(false) icon: 'none',
}) mask:true
}, });
fail () { setTimeout(() => {
// session_key 已经失效,需要重新执行登录流程 this.goBackPage()
that.toLogin(params) }, 1000);
}
})
} else { } else {
that.toLogin(params) this.loading = false;
uni.hideLoading()
uni.showToast({
title: '登录失败,请重新登录',
icon: 'none'
});
this.setLoginStatus(false)
} }
} else { } catch (e) {
uni.hideLoading() console.log('onAppLogin', e);
uni.showModal({ //TODO handle the exception
title: '提示',
showCancel: false,
content: '用户取消授权'
});
} }
} else { this.loading = false;
uni.hideLoading() },
uni.showModal({ toPage(){
title: '提示', if (this.returnUrl) {
showCancel: false, // 需要跳转到特定页面
content: '授权失败,请重新授权' var isSwitchTab = this.returnUrl.indexOf('pages/index/') != -1;
}); this.$u.route({
} url: this.returnUrl,
}, type: isSwitchTab ? 'switchTab' : 'redirectTo'
toLogin(params) { });
login.appLogin().then(res => {
params.code = res.code
return login.signup(params);
}).then(res => {
if (res) {
login.setUserData(res.data, this)
app.track('signup_login', {mobile: res.data.mobile});
app.profileSet(this)
app.profileAppend(this)
app.getBaseInfo(this)
this.goBackPage()
} else { } else {
uni.hideLoading() uni.switchTab({
uni.showToast({ url: '/pages/index/index'
title: '授权失败,请重新授权',
icon: 'none'
}); });
this.setLoginStatus(false)
} }
}).catch(res => { },
uni.hideLoading() goBackPage() {
this.setLoginStatus(false) let pages = getCurrentPages();
}) if(pages.length) {
}, let index = pages.length - 1;
goBackPage() { if(index) {
let pages = getCurrentPages(); let prevPage = pages[index]; //上一个页面
if(pages.length) { if (prevPage && prevPage.$vm) {
let index = pages.length - 1; prevPage.$vm.isRefresh = true;
if(index) { }
let prevPage = pages[index]; //上一个页面 uni.navigateBack({
if (prevPage && prevPage.$vm) { delta: 1
prevPage.$vm.isRefresh = true; })
} else {
uni.redirectTo({
url:'pages/index/index'
})
} }
uni.navigateBack({
delta: 1
})
} else { } else {
uni.redirectTo({ uni.reLaunch({
url:'pages/index/index' url: "pages/index/mine"
}) })
} }
} else {
uni.reLaunch({ },
url: "pages/index/mine" setLoginStatus(authed = true) {
}) getApp().globalData.logout = false
} this.code = ''
},
}, codeChange(text) {
setLoginStatus(authed = true) { this.tips = text;
getApp().globalData.logout = false },
this.code = ''
if (authed) {
this.needAuth = false
uni.setNavigationBarTitle({
title: '登录页'
});
} else {
if(!this.vuex_auth_user || !Object.keys(this.vuex_auth_user).length) {
this.needAuth = true
uni.setNavigationBarTitle({
title: '授权页'
});
}
}
},
//取消点击 end() {
cancelClick: function () { console.log('end');
uni.navigateBack({}) this.canGetCode = true;
}, },
} start() {
} console.log('start');
this.canGetCode = false;
},
}
};
</script> </script>
<style lang="scss" scoped> <style scoped lang="scss">
.backView { .binding-phone-view {
background-color: #FFFFFF; padding: 60rpx;
position: absolute; background-color: #ffffff;
top: 0; height: 100vh;
left: 0;
width: 100%;
height: 100%;
.login-block { .title-view {
margin-top: 240rpx;
}
.bind-block {
margin-top: 202rpx;
margin-left: 50rpx;
.bind-phone {
font-size: 52rpx; font-size: 52rpx;
margin-top: 48rpx;
font-weight: bold;
color: #333333; color: #333333;
line-height: 52rpx; font-weight: bold;
margin-left: 10rpx; margin-bottom: 24rpx;
} }
.bind-tips {
margin: 24rpx 60rpx 14rpx 10rpx; .text-view {
font-size: 28rpx; font-size: 28rpx;
font-weight: 400; color: #8d8d8d;
color: #999999; margin-bottom: 88rpx;
line-height: 40rpx;
} }
}
}
.logo2 {
margin-top: 28rpx;
}
.noticeView {
background-color: #FFFFFF;
width: 100%;
height: 470rpx;
display: flex;
flex-direction: column;
align-items: center;
}
.noticeImage { .phone-view {
background-color: #FFFFFF; display: flex;
width: 386rpx; align-items: center;
height: 270rpx; font-weight: bold;
margin-top: 180rpx; font-size: 28rpx;
} color: #333333;
background-color: #fafafa;
border-radius: 16rpx;
height: 104rpx;
padding: 0 32rpx;
margin-bottom: 48rpx;
.noticeTitleView { .left-view {
margin-top: 80rpx; width: 66rpx;
width: 100%; text-align: left;
display: flex; flex-shrink: 0;
align-items: center; }
justify-content: center;
}
.noticeTitle { .middle-view {
width: 60%; background-color: #8d8d8d;
font-size: 24rpx; width: 4rpx;
color: #999999; height: 28rpx;
text-align: center; margin: 0 12rpx;
line-height: 40rpx; flex-shrink: 0;
} }
.loginBtn { .right-view {
background-color: #2272FF; flex: 1;
font-size: 32rpx; padding-left: 8rpx;
font-weight: 600; }
color: #FFFFFF; }
line-height: 104px;
width: 600rpx;
height: 104rpx;
border-radius: 52rpx;
display: flex;
align-items: center;
justify-content: center;
}
.disable { .code-view {
background-color: #2272FF !important; display: flex;
font-size: 32rpx; align-items: center;
font-weight: 600; justify-content: space-between;
color: #FFFFFF !important; font-weight: bold;
line-height: 104px; font-size: 28rpx;
width: 600rpx; color: #333333;
height: 104rpx; background-color: #fafafa;
border-radius: 52rpx; border-radius: 16rpx;
display: flex; height: 104rpx;
align-items: center; padding: 0 32rpx;
justify-content: center; margin-bottom: 96rpx;
}
.cancelView { .left-view {
width: 100%; width: 330rpx;
margin-top: 30rpx; }
display: flex;
align-items: center;
justify-content: center;
}
.cancelText { .right-view {
color: #666666; font-weight: 400;
font-size: 32rpx;
}
.white { .active {
color: #FFFFFF; color: #3383fe;
} }
}
}
</style> .bottom-vew {
.button-text {
color: #ffffff;
height: 104rpx;
line-height: 104rpx;
font-weight: bold;
font-size: 32rpx;
}
}
}
</style>
\ No newline at end of file
...@@ -40,13 +40,14 @@ ...@@ -40,13 +40,14 @@
}, },
methods: { methods: {
handleClick(path) { handleClick(path) {
if(this.vuex_token) { this.$u.route({
this.$u.route({ url: 'pages/mine/' + path
url: 'pages/mine/' + path })
}) // if(this.vuex_token) {
} else {
this.$u.route({url: "pages/login/index"}) // } else {
} // this.$u.route({url: "pages/login/index"})
// }
}, },
} }
}; };
......
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