Commit ca25dc00 authored by linwenqing's avatar linwenqing

Merge remote-tracking branch 'remotes/origin/dev-fix-auth' into test

parents 31a658e1 75016146
...@@ -21,15 +21,19 @@ function getPhoto(type, token) { ...@@ -21,15 +21,19 @@ function getPhoto(type, token) {
reject(msg) reject(msg)
}) })
}, },
complete: function() {
uni.hideLoading()
},
}) })
}) })
} }
//上传七牛 //上传七牛
function upload(filePath, token) { function upload(filePath, token) {
console.log('filePath', filePath)
console.log('token', token)
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
uni.showLoading({
title: '上传中...',
})
let key = let key =
new Date().getTime() + Math.random(1000) + filePath.split('/').pop() //key为自定义文件名 new Date().getTime() + Math.random(1000) + filePath.split('/').pop() //key为自定义文件名
uni.uploadFile({ uni.uploadFile({
......
...@@ -36,7 +36,7 @@ ...@@ -36,7 +36,7 @@
</view> </view>
</u-cell-item> </u-cell-item>
<u-cell-item title="手机号"> <u-cell-item title="手机号">
<view slot="right-icon"> <view slot="right-icon" @click.capture="refleshCode">
<button <button
open-type="getPhoneNumber" open-type="getPhoneNumber"
@getphonenumber="getPhonenumber" @getphonenumber="getPhonenumber"
...@@ -118,7 +118,6 @@ export default { ...@@ -118,7 +118,6 @@ export default {
}, },
onLoad() { onLoad() {
getApp().trackPage('我的信息') getApp().trackPage('我的信息')
this.refleshCode()
this.$u.api.getQiNiuToken({ bucketName: 'wsy-exam' }).then((res) => { this.$u.api.getQiNiuToken({ bucketName: 'wsy-exam' }).then((res) => {
this.qiToken = res this.qiToken = res
getApp().globalData.qiNiuToken = res getApp().globalData.qiNiuToken = res
...@@ -150,7 +149,12 @@ export default { ...@@ -150,7 +149,12 @@ export default {
let params = {} let params = {}
if (e && e.detail) { if (e && e.detail) {
if (e.detail.errMsg.indexOf('user deny') > -1) { if (e.detail.errMsg.indexOf('user deny') > -1) {
//拒绝授权 uni.hideLoading()
this.$refs.uToast.show({
title: '用户拒绝授权',
type: 'warning',
duration: 2000,
})
return return
} else if (e.detail.encryptedData && e.detail.iv) { } else if (e.detail.encryptedData && e.detail.iv) {
//允许授权-解析-更新手机号 //允许授权-解析-更新手机号
...@@ -159,17 +163,19 @@ export default { ...@@ -159,17 +163,19 @@ export default {
iv: e.detail.iv, iv: e.detail.iv,
} }
} else { } else {
uni.hideLoading()
this.$refs.uToast.show({ this.$refs.uToast.show({
title: e.detail.errMsg, title: '用户取消授权',
type: 'error', type: 'warning',
duration: 2000, duration: 2000,
}) })
return return
} }
} else { } else {
uni.hideLoading()
this.$refs.uToast.show({ this.$refs.uToast.show({
title: '授权失败,请重新授权', title: '授权失败,请重新授权',
type: 'error', type: 'warning',
duration: 2000, duration: 2000,
}) })
return return
...@@ -195,16 +201,23 @@ export default { ...@@ -195,16 +201,23 @@ export default {
}, },
fail() { fail() {
// session_key 已经失效,需要重新执行登录流程 // session_key 已经失效,需要重新执行登录流程
setTimeout(() => { that.toLogin()
uni.navigateTo({ },
url: 'pages/login/index',
}) })
}, 800)
}, },
inGetPhone() {
uni.showLoading({
title: '授权中...',
})
},
inUpload() {
uni.showLoading({
title: '上传中...',
}) })
}, },
refleshCode() { refleshCode() {
let that = this let that = this
this.inGetPhone()
uni.login({ uni.login({
provider: 'weixin', provider: 'weixin',
success: (code_res) => { success: (code_res) => {
...@@ -220,11 +233,13 @@ export default { ...@@ -220,11 +233,13 @@ export default {
.loginWechatAuth(params) .loginWechatAuth(params)
.then((res) => { .then((res) => {
this.student.phoneNumber = res.phoneNumber this.student.phoneNumber = res.phoneNumber
this.inGetPhone()
this.$u.api this.$u.api
.updateUserInfo({ .updateUserInfo({
phoneNumber: res.phoneNumber, phoneNumber: res.phoneNumber,
}) })
.then((ret) => { .then((ret) => {
uni.hideLoading()
this.$refs.uToast.show({ this.$refs.uToast.show({
title: '绑定成功!', title: '绑定成功!',
type: 'success', type: 'success',
...@@ -233,20 +248,11 @@ export default { ...@@ -233,20 +248,11 @@ export default {
}) })
}) })
.catch((err) => { .catch((err) => {
this.$refs.uToast.show({ this.toLogin()
title: '请登录后再绑定',
type: 'warning',
duration: 2000,
})
this.$u.route({
url: 'pages/login/index',
params: {
path: 'pages/mine/info',
},
})
}) })
}, },
changeHead() { changeHead() {
this.inUpload()
//更换头像 //更换头像
upload.getPhoto(2, this.qiToken).then((res) => { upload.getPhoto(2, this.qiToken).then((res) => {
this.student.avatarPath = process.uniEnv.qn_asset_url + res.key this.student.avatarPath = process.uniEnv.qn_asset_url + res.key
...@@ -259,10 +265,14 @@ export default { ...@@ -259,10 +265,14 @@ export default {
...params, ...params,
} }
getApp().track('changeAvatar', trackParams) getApp().track('changeAvatar', trackParams)
this.$u.api.updateUserInfo(params) this.inUpload()
this.$u.api.updateUserInfo(params).then(() => {
uni.hideLoading()
})
}) })
}, },
changeCertPhoto() { changeCertPhoto() {
this.inUpload()
//更换证件头像 //更换证件头像
upload.getPhoto(2, this.qiToken).then((res) => { upload.getPhoto(2, this.qiToken).then((res) => {
this.student.certificatePhotoPath = this.student.certificatePhotoPath =
...@@ -276,7 +286,17 @@ export default { ...@@ -276,7 +286,17 @@ export default {
...params, ...params,
} }
getApp().track('changeCertPhoto', trackParams) getApp().track('changeCertPhoto', trackParams)
this.$u.api.updateUserInfo(params) this.inUpload()
this.$u.api.updateUserInfo(params).then(() => {
uni.hideLoading()
})
})
},
userRefuseTip() {
this.$refs.uToast.show({
title: '用户拒绝授权',
type: 'warning',
duration: 2000,
}) })
}, },
toLogin() { toLogin() {
...@@ -288,6 +308,9 @@ export default { ...@@ -288,6 +308,9 @@ export default {
setTimeout(() => { setTimeout(() => {
uni.navigateTo({ uni.navigateTo({
url: 'pages/login/index', url: 'pages/login/index',
params: {
path: 'pages/mine/info',
},
}) })
}, 800) }, 800)
}, },
......
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