|
|
@@ -17,7 +17,8 @@
|
|
|
<view class="value avatarbox">
|
|
|
<button style="flex: none;" open-type="chooseAvatar" class="avatarBtn"
|
|
|
@chooseavatar="onChooseavatar">
|
|
|
- <u-avatar shape="circle" style="height: 72rpx;" size="72" :src="userInfo.imgPath"></u-avatar>
|
|
|
+ <u-avatar shape="circle" style="height: 72rpx;" size="72"
|
|
|
+ :src="userInfo.imgPath"></u-avatar>
|
|
|
</button>
|
|
|
</view>
|
|
|
</u-form-item>
|
|
|
@@ -33,12 +34,23 @@
|
|
|
<!-- 手机号 -->
|
|
|
<u-form-item label="手机号">
|
|
|
<view class="value phone-value">
|
|
|
+ <!-- #ifdef MP-WEIXIN -->
|
|
|
<button class="get-phone-btn" open-type="getPhoneNumber" @getphonenumber="getPhoneNumber">
|
|
|
<text class="common-text-2" v-if="userInfo.mobile">{{ userInfo.mobile }}</text>
|
|
|
<text class="common-text" v-else>未绑定</text>
|
|
|
<u-icon :color="arrowColor" style="margin-left: 20rpx;" size="28"
|
|
|
name="arrow-right"></u-icon>
|
|
|
</button>
|
|
|
+ <!-- #endif -->
|
|
|
+ <!-- #ifdef MP-ALIPAY -->
|
|
|
+ <button class="get-phone-btn" open-type="getAuthorize" scope="phoneNumber"
|
|
|
+ @getAuthorize="onGetAuthorize" @error="handleAuthError">
|
|
|
+ <text class="common-text-2" v-if="userInfo.mobile">{{ userInfo.mobile }}</text>
|
|
|
+ <text class="common-text" v-else>未绑定2</text>
|
|
|
+ <u-icon :color="arrowColor" style="margin-left: 20rpx;" size="28"
|
|
|
+ name="arrow-right"></u-icon>
|
|
|
+ </button>
|
|
|
+ <!-- #endif -->
|
|
|
</view>
|
|
|
</u-form-item>
|
|
|
</u-form>
|
|
|
@@ -103,10 +115,34 @@ export default {
|
|
|
// 选择并上传头像
|
|
|
async onChooseavatar(e) {
|
|
|
const tempFilePath = e.detail.avatarUrl
|
|
|
+ // http://tfs.alipayobjects.com/images/partner/TB1kQ2kXv5GDuNjHvSCXXczuXXa
|
|
|
+ console.log(tempFilePath, 'onChooseavatar')
|
|
|
if (!tempFilePath) {
|
|
|
return uni.$u.toast('获取头像失败')
|
|
|
}
|
|
|
-
|
|
|
+ // #ifdef MP-ALIPAY
|
|
|
+ // 下载支付宝头像
|
|
|
+ //将tempFilePath转换为https://tfs.alipayobjects.com/images/partner/TB1kQ2kXv5GDuNjHvSCXXczuXXa
|
|
|
+ let url = tempFilePath.indexOf('http://') > -1 ? tempFilePath.replace('http://', 'https://') : tempFilePath
|
|
|
+ my.downloadFile({
|
|
|
+ url: url,
|
|
|
+ success: (res) => {
|
|
|
+ if (res.statusCode === 200) {
|
|
|
+ let aliTempFilePath = res.tempFilePath
|
|
|
+ this.uploadAvatar(aliTempFilePath)
|
|
|
+ }
|
|
|
+ },
|
|
|
+ fail: (err) => {
|
|
|
+ console.log(err, 'downloadFile fail')
|
|
|
+ }
|
|
|
+ })
|
|
|
+ // #endif
|
|
|
+ // #ifdef MP-WEIXIN
|
|
|
+ this.uploadAvatar(tempFilePath)
|
|
|
+ // #endif
|
|
|
+ },
|
|
|
+ //上传头像
|
|
|
+ async uploadAvatar(tempFilePath){
|
|
|
try {
|
|
|
this.uploading = true
|
|
|
uni.showLoading({
|
|
|
@@ -131,6 +167,7 @@ export default {
|
|
|
}
|
|
|
},
|
|
|
|
|
|
+
|
|
|
// 文件上传方法
|
|
|
uploadFile(filePath) {
|
|
|
return new Promise((resolve, reject) => {
|
|
|
@@ -157,6 +194,42 @@ export default {
|
|
|
})
|
|
|
},
|
|
|
|
|
|
+ onGetAuthorize(e) {
|
|
|
+ console.log(e, 'onGetAuthorize')
|
|
|
+ my.getPhoneNumber({
|
|
|
+ success: (res) => {
|
|
|
+ this.getPhoneNumberApi(res.response, 'alipay')
|
|
|
+ },
|
|
|
+ fail: (err) => {
|
|
|
+ console.log('获取手机号失败', err);
|
|
|
+ }
|
|
|
+ })
|
|
|
+ },
|
|
|
+
|
|
|
+ handleAuthError(e) {
|
|
|
+ console.log(e, 'handleAuthError')
|
|
|
+ },
|
|
|
+
|
|
|
+ //获取手机号的接口
|
|
|
+ getPhoneNumberApi(code, type = 'wechat') {
|
|
|
+ let params = type === 'wechat' ? { code } : code
|
|
|
+ // 调用后端接口解密手机号
|
|
|
+ uni.$u.http.post('/token/user/wxMobileUpdate', params).then(res => {
|
|
|
+ if (res.code === 200) {
|
|
|
+ // 更新本地用户信息
|
|
|
+ this.userInfo.mobile = res.data.mobile
|
|
|
+
|
|
|
+ uni.showToast({
|
|
|
+ title: '绑定成功',
|
|
|
+ icon: 'success'
|
|
|
+ })
|
|
|
+ } else {
|
|
|
+ uni.$u.toast('手机号绑定失败')
|
|
|
+ }
|
|
|
+ })
|
|
|
+ },
|
|
|
+
|
|
|
+
|
|
|
// 获取手机号
|
|
|
async getPhoneNumber(e) {
|
|
|
if (e.detail.errMsg !== 'getPhoneNumber:ok') {
|
|
|
@@ -167,23 +240,7 @@ export default {
|
|
|
uni.showLoading({
|
|
|
title: '手机号获取中'
|
|
|
})
|
|
|
-
|
|
|
- // 调用后端接口解密手机号
|
|
|
- uni.$u.http.post('/token/user/wxMobileUpdate', {
|
|
|
- code: e.detail.code
|
|
|
- }).then(res => {
|
|
|
- if (res.code === 200) {
|
|
|
- // 更新本地用户信息
|
|
|
- this.userInfo.mobile = res.data.mobile
|
|
|
-
|
|
|
- uni.showToast({
|
|
|
- title: '绑定成功',
|
|
|
- icon: 'success'
|
|
|
- })
|
|
|
- } else {
|
|
|
- uni.$u.toast('手机号绑定失败')
|
|
|
- }
|
|
|
- })
|
|
|
+ this.getPhoneNumberApi(e.detail.code)
|
|
|
} catch (error) {
|
|
|
uni.$u.toast('手机号绑定失败')
|
|
|
} finally {
|