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({
......
const globalUrl = process.uniEnv || {}
const ucenterApiUrl = globalUrl.ucenterUrl.apiUrl
let commonApiFun = function(vm){ 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
...@@ -78,24 +77,19 @@ ...@@ -78,24 +77,19 @@
"minified" : true "minified" : true
}, },
"usingComponents" : true, "usingComponents" : true,
"permission" : {
"scope.userLocation" : {
"desc" : "方便查看订单与你的距离"
}
},
"requiredPrivateInfos": ["getLocation", "onLocationChange", "startLocationUpdate"],
"permission" : { "permission" : {
"scope.userLocation" : { "scope.userLocation" : {
"desc" : "你的位置信息将用于小程序获取所在地与订单地点的距离" "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>
<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> </view>
<u-gap height="480"></u-gap> <view class="code-view">
<view v-if="needAuth" @click.capture="loadLogin"> <view class="left-view"><input v-model="code" type="number" maxlength="6" clearable /></view>
<button class="loginBtn" lang="zh_CN" <view class="right-view">
@tap="getUserProfile"> <u-toast ref="uToast"></u-toast>
<text class="u-font-32 white">{{ loginTitle }}</text> <u-verification-code keep-running unique-key="binding-phone" :seconds="seconds" @end="end"
</button> @start="start" ref="uCode" @change="codeChange"></u-verification-code>
<text :class="{ active: canGetCode }" @tap="$u.throttle(handleClick, 500)">{{ tips }}</text>
</view> </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 class="bottom-vew" >
<u-button type="primary" :disabled="disabled" :customStyle="buttonStyle" :loading="loading" @click="handleClickSave">
<view class="button-text">立即绑定</view>
</u-button>
</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 {
needAuth: true, phone: '13423831191',
TimeID: -1, code: '174253',
loginTitle: '用户登录', timer: null,
bindTitle: '立即绑定', canGetCode: true,
bindPhone: '绑定手机', seconds: 60,
bindTips: '首次登录的用户需绑定手机才可接单', encryptedData: '',
code: '', iv: '',
loading: false,
weixinAuthService: null,
params: {},
tips: '',
buttonStyle: {
height: '104rpx',
backgroundColor: '#2979ff',
color: 'transparent'
} }
};
}, },
computed: { computed: {
logo() { disabled() {
return this.qnFile('logo.png') return this.code && this.phone ? false : true;
}, }
logo2() {
return this.qnFile('logo-2.png')
},
}, },
onLoad(e) { onReady() {
app.trackPage('授权登录页') this.canGetCode = this.$refs.uCode.canGetCode ? true : false;
}, },
onShow() { onLoad(options) {
// 微信授权过用户信息,则无需重复授权 console.log('-----options----', options);
if (this.vuex_auth_user && Object.keys(this.vuex_auth_user).length) {
this.needAuth = false if (options) {
let {
unionId
} = options;
if (unionId) {
this.params = options;
}
} }
}, },
methods: { methods: {
loadLogin() { handleClick() {
uni.showLoading({ if (this.phone == '') {
title: '加载中..', uni.showToast({
mask: true title: '请输入手机号',
icon: 'none',
duration: 1500
});
return;
}
var reg = /^[1][3456789][0-9]{9}$/;
if (!reg.test(this.phone)) {
uni.showToast({
icon: 'none',
title: '请输入正确的手机号'
}); });
return false;
}
this.startCode();
}, },
qnFile(src) { startCode() {
return process.uniEnv.qn_base_url + src if (this.$refs.uCode.canGetCode) {
// 模拟向后端请求验证码
this.$u.toast('正在获取验证码');
this.getCode();
}
}, },
async getCode() { async getCode() {
login.appLogin().then(res => { try {
this.code = res.code let res = await uni.$u.api.sendCode({
}) mobile: this.phone
},
// 微信授权用户信息
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();
uni.hideLoading() if (res.data) {
that.setLoginStatus() this.$u.toast('验证码已发送');
this.$refs.uCode.start();
console.log('--------发送成功----------');
} else { } else {
that.authLogin() uni.showToast({
} title: '获取验证码失败',
}, icon: 'none'
fail: function (res) {
uni.hideLoading()
uni.showModal({
title: '授权失败',
content: '请允许获取用户信息的授权',
showCancel: false
}); });
} }
}) } catch (e) {
} else { console.log(e);
uni.hideLoading() if (e.msg) {
// 可能由于账号配置,或者其他原因导致无法调起微信用户授权 uni.showToast({
uni.showModal({ title: e.msg,
title: '授权失败', icon: 'none'
content: '请确认你的用户授权是否可用',
showCancel: false
}); });
} }
}, //TODO handle the exception
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(); 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() { handleClickSave() {
uni.showLoading({ this.signup();
title: '授权中..',
mask: true
});
}, },
signupLogin(e) { signup() {
var that = this this.loading = true;
if(e && e.detail) { var reg = /^[1][3456789][0-9]{9}$/;
if(e.detail.errMsg.indexOf('user deny') > -1) { if (!reg.test(this.phone)) {
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({ uni.showToast({
title: '授权失败,请重新授权', icon: 'none',
icon: 'none' title: '请输入正确的手机号'
}); });
that.setLoginStatus(false) this.loading = false;
} return false;
}).catch(res => {
uni.hideLoading()
that.setLoginStatus(false)
})
},
fail () {
// session_key 已经失效,需要重新执行登录流程
that.toLogin(params)
} }
}) if (uni.$u.platform === '4') {
this.onAppLogin();
} else { } else {
that.toLogin(params) this.onWxLogin();
}
} else {
uni.hideLoading()
uni.showModal({
title: '提示',
showCancel: false,
content: '用户取消授权'
});
} }
} else { },
uni.hideLoading() async onWxLogin() {
uni.showModal({ try {
title: '提示', let res = await login.appLogin();
showCancel: false, let params = {
content: '授权失败,请重新授权' code: res.code,
}); // nickname: userInfo.nickName,
// avatar: userInfo.avatarUrl,
// encryptedData: this.encryptedData,
// iv: this.iv,
// verify: this.code,
};
this.onAppLogin(params)
} catch (e) {
console.log('onWxLogin:fail', e);
this.loading = false;
//TODO handle the exception
} }
this.loading = false;
}, },
toLogin(params) { async onAppLogin(paramsData={}) {
login.appLogin().then(res => { let params = {
params.code = res.code ...paramsData,
return login.signup(params); mobileCode: this.code,
}).then(res => { mobile: this.phone,
if (res) { wxAppNo:1
};
try {
let res = await uni.$u.api.newLoginWechatAuth(params);
if (res&&res.code === 200) {
login.setUserData(res.data, this) login.setUserData(res.data, this)
app.track('signup_login', {mobile: res.data.mobile}); app.track('signup_login', {mobile: res.data.mobile});
app.profileSet(this) app.profileSet(this)
app.profileAppend(this) app.profileAppend(this)
app.getBaseInfo(this) app.getBaseInfo(this)
uni.showToast({
title: '登录成功',
icon: 'none',
mask:true
});
setTimeout(() => {
this.goBackPage() this.goBackPage()
}, 1000);
} else { } else {
this.loading = false;
uni.hideLoading() uni.hideLoading()
uni.showToast({ uni.showToast({
title: '授权失败,请重新授权', title: '登录失败,请重新登录',
icon: 'none' icon: 'none'
}); });
this.setLoginStatus(false) this.setLoginStatus(false)
} }
}).catch(res => { } catch (e) {
uni.hideLoading() console.log('onAppLogin', e);
this.setLoginStatus(false) //TODO handle the exception
}) }
this.loading = false;
},
toPage(){
if (this.returnUrl) {
// 需要跳转到特定页面
var isSwitchTab = this.returnUrl.indexOf('pages/index/') != -1;
this.$u.route({
url: this.returnUrl,
type: isSwitchTab ? 'switchTab' : 'redirectTo'
});
} else {
uni.switchTab({
url: '/pages/index/index'
});
}
}, },
goBackPage() { goBackPage() {
let pages = getCurrentPages(); let pages = getCurrentPages();
...@@ -279,140 +243,108 @@ export default { ...@@ -279,140 +243,108 @@ export default {
setLoginStatus(authed = true) { setLoginStatus(authed = true) {
getApp().globalData.logout = false getApp().globalData.logout = false
this.code = '' this.code = ''
if (authed) { },
this.needAuth = false codeChange(text) {
uni.setNavigationBarTitle({ this.tips = text;
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 { .phone-view {
background-color: #FFFFFF;
width: 100%;
height: 470rpx;
display: flex; display: flex;
flex-direction: column;
align-items: center; align-items: center;
} font-weight: bold;
font-size: 28rpx;
color: #333333;
background-color: #fafafa;
border-radius: 16rpx;
height: 104rpx;
padding: 0 32rpx;
margin-bottom: 48rpx;
.noticeImage { .left-view {
background-color: #FFFFFF; width: 66rpx;
width: 386rpx; text-align: left;
height: 270rpx; flex-shrink: 0;
margin-top: 180rpx; }
}
.noticeTitleView { .middle-view {
margin-top: 80rpx; background-color: #8d8d8d;
width: 100%; width: 4rpx;
display: flex; height: 28rpx;
align-items: center; margin: 0 12rpx;
justify-content: center; flex-shrink: 0;
} }
.noticeTitle { .right-view {
width: 60%; flex: 1;
font-size: 24rpx; padding-left: 8rpx;
color: #999999; }
text-align: center; }
line-height: 40rpx;
}
.loginBtn { .code-view {
background-color: #2272FF;
font-size: 32rpx;
font-weight: 600;
color: #FFFFFF;
line-height: 104px;
width: 600rpx;
height: 104rpx;
border-radius: 52rpx;
display: flex; display: flex;
align-items: center; align-items: center;
justify-content: center; justify-content: space-between;
} font-weight: bold;
font-size: 28rpx;
.disable { color: #333333;
background-color: #2272FF !important; background-color: #fafafa;
font-size: 32rpx; border-radius: 16rpx;
font-weight: 600;
color: #FFFFFF !important;
line-height: 104px;
width: 600rpx;
height: 104rpx; height: 104rpx;
border-radius: 52rpx; padding: 0 32rpx;
display: flex; margin-bottom: 96rpx;
align-items: center;
justify-content: center;
}
.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;
} }
}
}
.bottom-vew {
.button-text {
color: #ffffff;
height: 104rpx;
line-height: 104rpx;
font-weight: bold;
font-size: 32rpx;
}
}
}
</style> </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
}) })
} else { // if(this.vuex_token) {
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