昵称头像授权联调

main
xuechunyuan 2 years ago
parent dc377da6bc
commit 889cd56bbc
  1. 1
      App.vue
  2. 184
      pages/pages_zhentou/myPage/myPage.vue
  3. 61
      pages/pages_zhentou/order/confirmOrder.vue

@ -99,7 +99,6 @@
method: 'POST', method: 'POST',
data: { data: {
openId: this.globalData.openId, openId: this.globalData.openId,
username: username,
phone: phone phone: phone
}, },
header: { header: {

@ -1,31 +1,39 @@
<template> <template>
<view> <view>
<view class="person_box"> <view class="person_box">
<image v-if="userInfo.avatar" :src="userInfo.avatar" class="avatar"></image> <view class="avatar_warp">
<button v-else open-type="chooseAvatar" @chooseavatar="chooseavatar" class="avatar"></button> <text>头像</text>
<view class="nickname"> <button open-type="chooseAvatar" @chooseavatar="chooseavatar" class="avatar-box">
{{userInfo.username}} <image :src="userInfo.avatar" class="avatar"></image>
</button>
</view>
<view class="nickname_warp">
<text>昵称</text>
<input @blur="formSubmit" v-model="userInfo.username" class="nickname" type="nickname" placeholder="请输入昵称" />
</view> </view>
</view> </view>
<view class="cnt-box"> <view class="cnt-box">
<view class="title">用户功能</view> <view class="title">用户功能</view>
<view class="li_box" @click="returnOrder"> <view class="li_box" @click="returnOrder">
<view class="li_left"> <view class="li_left">
<image src="../../../static/image/icon-order.png" style="width: 40rpx; height: 40rpx;margin-right: 13rpx;"></image> <image src="../../../static/image/icon-order.png" style="width: 40rpx; height: 40rpx;margin-right: 13rpx;">
</image>
我的订单 我的订单
</view> </view>
<image src="../../../static/image/icon-arrow-right.png" style="width: 40rpx; height: 40rpx;"></image> <image src="../../../static/image/icon-arrow-right.png" style="width: 40rpx; height: 40rpx;"></image>
</view> </view>
<view class="li_box" @click="returnAddress"> <view class="li_box" @click="returnAddress">
<view class="li_left"> <view class="li_left">
<image src="../../../static/image/icon-address.png" style="width: 40rpx; height: 40rpx;margin-right: 13rpx;"></image> <image src="../../../static/image/icon-address.png" style="width: 40rpx; height: 40rpx;margin-right: 13rpx;">
</image>
收货地址管理 收货地址管理
</view> </view>
<image src="../../../static/image/icon-arrow-right.png" style="width: 40rpx; height: 40rpx;"></image> <image src="../../../static/image/icon-arrow-right.png" style="width: 40rpx; height: 40rpx;"></image>
</view> </view>
<view class="li_box" @click="returnContact"> <view class="li_box" @click="returnContact">
<view class="li_left"> <view class="li_left">
<image src="../../../static/image/icon-contact.png" style="width: 40rpx; height: 40rpx;margin-right: 13rpx;"></image> <image src="../../../static/image/icon-contact.png" style="width: 40rpx; height: 40rpx;margin-right: 13rpx;">
</image>
售后服务 售后服务
</view> </view>
<image src="../../../static/image/icon-arrow-right.png" style="width: 40rpx; height: 40rpx;"></image> <image src="../../../static/image/icon-arrow-right.png" style="width: 40rpx; height: 40rpx;"></image>
@ -38,6 +46,7 @@
export default { export default {
data() { data() {
return { return {
avatarUrl: 'https://mmbiz.qpic.cn/mmbiz/icTdbqWNOwNRna42FI242Lcia07jQodd2FJGIYQfG0LAJGFxM4FbnQP6yfMxBgJ0F3YRqJCJ1aPAK2dQagdusBZg/0',
userInfo: { userInfo: {
username: '', username: '',
avatar: '' avatar: ''
@ -48,13 +57,87 @@
let userInfo = uni.getStorageSync('userInfo'); let userInfo = uni.getStorageSync('userInfo');
if (userInfo) { if (userInfo) {
this.userInfo = JSON.parse(userInfo); this.userInfo = JSON.parse(userInfo);
this.userInfo.avatar = this.userInfo.avatar ? this.userInfo.avatar : this.avatarUrl;
} else {
this.userInfo.avatar = this.avatarUrl;
} }
}, },
methods: { methods: {
formSubmit(e) {
console.log(e.detail)
if(e.detail.value) {
this.updateNickname(e.detail.value);
}
},
// //
chooseavatar() { chooseavatar(e) {
const { avatarUrl } = e.detail console.log(e);
uni.uploadFile({
url: getApp().globalData.baseUrl + '/blade-resource/oss/endpoint/put-file',
filePath: e.detail.avatarUrl,
name: "file",
fileType: 'image',
header: {
'Blade-Auth': 'bearer ' + uni.getStorageSync('token')
},
success: (res) => {
if (res.data.code == 200) {
this.updateAvatar(res.data.link);
}
}
})
},
updateAvatar(avatarUrl) {
uni.request({
url: getApp().globalData.baseUrl + '/weChatUser/update',
method: 'POST',
data: {
id: this.userInfo.id,
avatar: avatarUrl,
},
header: {
'Blade-Auth': 'bearer ' + uni.getStorageSync('token')
},
success: (res) => {
if (res.data.code == 200) {
this.userInfo.avatar = avatarUrl; this.userInfo.avatar = avatarUrl;
uni.setStorageSync('userInfo', JSON.stringify(this.userInfo));
} else if (res.data.code == 401) {
this.doLogin();
} else {
uni.showToast({
title: res.data.msg,
icon: 'none'
})
}
}
})
},
updateNickname(nickName) {
uni.request({
url: getApp().globalData.baseUrl + '/weChatUser/update',
method: 'POST',
data: {
id: this.userInfo.id,
username: nickName,
},
header: {
'Blade-Auth': 'bearer ' + uni.getStorageSync('token')
},
success: (res) => {
if (res.data.code == 200) {
this.userInfo.username = nickName;
uni.setStorageSync('userInfo', JSON.stringify(this.userInfo));
} else if (res.data.code == 401) {
this.doLogin();
} else {
uni.showToast({
title: res.data.msg,
icon: 'none'
})
}
}
})
}, },
returnOrder() { returnOrder() {
uni.navigateTo({ uni.navigateTo({
@ -71,37 +154,100 @@
url: "/pages/pages_zhentou/myPage/address" url: "/pages/pages_zhentou/myPage/address"
}) })
}, },
//
doLogin() {
uni.showLoading({
title: '登录中',
mask: true
});
uni.request({
url: getApp().globalData.baseUrl + '/blade-auth/getToken',
method: 'POST',
data: {
openId: getApp().globalData.openId,
phone: this.userInfo.phone
},
header: {
'Authorization': 'Basic c2FiZXI6c2FiZXJfc2VjcmV0'
},
success: (res) => {
if (res.data.code == 200) {
uni.setStorageSync('token', res.data.data.access_token);
} else {
uni.showToast({
title: res.data.msg,
icon: 'none'
})
}
},
complete: () => {
uni.hideLoading();
}
})
}
} }
} }
</script> </script>
<style lang="scss" scoped> <style lang="scss" scoped>
.person_box { .person_box {
display: flex;
align-items: center;
margin: 30rpx; margin: 30rpx;
padding: 30rpx; padding: 30rpx;
font-size: 26rpx;
font-family: PingFang SC-Bold, PingFang SC;
font-weight: bold;
color: #333333;
background-color: #fff; background-color: #fff;
border-radius: 30rpx; border-radius: 30rpx;
.avatar_warp {
display: flex;
justify-content: space-between;
align-items: center;
button::after {
border: 0;
border-radius: 20rpx;
}
button {
width: 100rpx;
height: 100rpx;
background-color: none;
padding: 0;
}
.avatar-box {
margin: 0;
overflow: hidden;
.avatar { .avatar {
width: 100rpx; width: 100rpx;
height: 100rpx; height: 100rpx;
background: #D6D6D6;
border-radius: 20rpx;
margin-right: 30rpx;
} }
}
}
.nickname_warp {
display: flex;
justify-content: space-between;
align-items: center;
margin-top: 40rpx;
.nickname { .nickname {
color: #333; width: 554rpx;
font-size: 32rpx; text-align: right;
font-weight: bold; border: 0;
font-family: PingFang SC-Bold, PingFang SC;
} }
} }
}
.cnt-box { .cnt-box {
min-height: calc(100vh - 220rpx - 30rpx); min-height: calc(100vh - 220rpx - 30rpx);
background-color: #fff; background-color: #fff;
margin: 0 30rpx; margin: 0 30rpx;
border-radius: 30rpx; border-radius: 30rpx;
.title { .title {
font-size: 28rpx; font-size: 28rpx;
font-family: PingFang SC-Bold, PingFang SC; font-family: PingFang SC-Bold, PingFang SC;
@ -111,6 +257,7 @@
padding: 30rpx 30rpx 42rpx 30rpx; padding: 30rpx 30rpx 42rpx 30rpx;
} }
} }
.li_box { .li_box {
display: flex; display: flex;
align-items: center; align-items: center;
@ -121,6 +268,7 @@
color: #333333; color: #333333;
line-height: 37rpx; line-height: 37rpx;
margin: 0 16rpx 52rpx 30rpx; margin: 0 16rpx 52rpx 30rpx;
.li_left { .li_left {
display: flex; display: flex;
align-items: center; align-items: center;

@ -132,7 +132,7 @@
}, },
success: (res) => { success: (res) => {
if (res.data.code == 200) { if (res.data.code == 200) {
console.log('下单成功'); this.address = JSON.stringify(res.data.data) == '{}' ? null : res.data.data;
} else if (res.data.code == 401) { } else if (res.data.code == 401) {
this.doLogin(); this.doLogin();
} else { } else {
@ -146,13 +146,13 @@
}, },
// //
submitOrder() { submitOrder() {
if(!this.address) { // if(!this.address) {
uni.showToast({ // uni.showToast({
title: '请填写收货地址', // title: '',
icon: 'none' // icon: 'none'
}) // })
return; // return;
} // }
uni.request({ uni.request({
url: getApp().globalData.baseUrl + '/blade-desk/order/save', url: getApp().globalData.baseUrl + '/blade-desk/order/save',
method: 'POST', method: 'POST',
@ -167,7 +167,7 @@
}, },
success: (res) => { success: (res) => {
if (res.data.code == 200) { if (res.data.code == 200) {
this.address = JSON.stringify(res.data.data) == '{}' ? null : res.data.data; this.goPay(res.data.data);
} else if (res.data.code == 401) { } else if (res.data.code == 401) {
this.doLogin(); this.doLogin();
} else if (res.data.code == 1001) { } else if (res.data.code == 1001) {
@ -193,6 +193,48 @@
} }
}) })
}, },
//
goPay(orderInfo) {
uni.request({
url: getApp().globalData.baseUrl + '/app/createOrder',
method: 'POST',
data: {
openId: getApp().globalData.openId,
outTradeNo: orderInfo.orderNo
},
header: {
'Blade-Auth': 'bearer ' + uni.getStorageSync('token')
},
success: (res) => {
console.log(res)
if (res.data.code == 200) {
uni.requestPayment({
provider: 'wxpay',
orderInfo: orderInfo,
timeStamp: res.data.data.timeStamp,
nonceStr: res.data.data.nonceStr,
package: res.data.data.package,
signType: res.data.data.signType,
paySign: res.data.data.paySign,
success: (res1) => {
console.log(res1)
},
fail: (res2) => {
console.log(res2)
}
})
} else {
uni.showToast({
title: res.data.msg,
icon: 'none'
})
}
},
complete: () => {
uni.hideLoading();
}
})
},
// //
doLogin() { doLogin() {
uni.showLoading({ uni.showLoading({
@ -204,7 +246,6 @@
method: 'POST', method: 'POST',
data: { data: {
openId: getApp().globalData.openId, openId: getApp().globalData.openId,
username: this.userInfo.username,
phone: this.phone phone: this.phone
}, },
header: { header: {

Loading…
Cancel
Save