昵称头像授权联调

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

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

@ -1,31 +1,39 @@
<template>
<view>
<view class="person_box">
<image v-if="userInfo.avatar" :src="userInfo.avatar" class="avatar"></image>
<button v-else open-type="chooseAvatar" @chooseavatar="chooseavatar" class="avatar"></button>
<view class="nickname">
{{userInfo.username}}
<view class="avatar_warp">
<text>头像</text>
<button open-type="chooseAvatar" @chooseavatar="chooseavatar" class="avatar-box">
<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 class="cnt-box">
<view class="title">用户功能</view>
<view class="li_box" @click="returnOrder">
<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>
<image src="../../../static/image/icon-arrow-right.png" style="width: 40rpx; height: 40rpx;"></image>
</view>
<view class="li_box" @click="returnAddress">
<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>
<image src="../../../static/image/icon-arrow-right.png" style="width: 40rpx; height: 40rpx;"></image>
</view>
<view class="li_box" @click="returnContact">
<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>
<image src="../../../static/image/icon-arrow-right.png" style="width: 40rpx; height: 40rpx;"></image>
@ -38,6 +46,7 @@
export default {
data() {
return {
avatarUrl: 'https://mmbiz.qpic.cn/mmbiz/icTdbqWNOwNRna42FI242Lcia07jQodd2FJGIYQfG0LAJGFxM4FbnQP6yfMxBgJ0F3YRqJCJ1aPAK2dQagdusBZg/0',
userInfo: {
username: '',
avatar: ''
@ -48,82 +57,221 @@
let userInfo = uni.getStorageSync('userInfo');
if (userInfo) {
this.userInfo = JSON.parse(userInfo);
this.userInfo.avatar = this.userInfo.avatar ? this.userInfo.avatar : this.avatarUrl;
} else {
this.userInfo.avatar = this.avatarUrl;
}
},
methods: {
formSubmit(e) {
console.log(e.detail)
if(e.detail.value) {
this.updateNickname(e.detail.value);
}
},
//
chooseavatar() {
const { avatarUrl } = e.detail
this.userInfo.avatar = avatarUrl;
chooseavatar(e) {
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;
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({
url:"/pages/pages_zhentou/order/order"
url: "/pages/pages_zhentou/order/order"
})
},
returnContact(){
returnContact() {
uni.navigateTo({
url:"/pages/pages_zhentou/contact/contact"
url: "/pages/pages_zhentou/contact/contact"
})
},
returnAddress(){
returnAddress() {
uni.navigateTo({
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>
<style lang="scss" scoped>
.person_box{
display: flex;
align-items: center;
margin: 30rpx;
padding: 30rpx;
background-color: #fff;
border-radius: 30rpx;
.avatar{
width: 100rpx;
height: 100rpx;
background: #D6D6D6;
border-radius: 20rpx;
margin-right: 30rpx;
}
.nickname{
color: #333;
font-size: 32rpx;
font-weight: bold;
font-family: PingFang SC-Bold, PingFang SC;
}
}
.cnt-box{
min-height: calc(100vh - 220rpx - 30rpx);
background-color: #fff;
margin: 0 30rpx;
border-radius: 30rpx;
.title{
font-size: 28rpx;
.person_box {
margin: 30rpx;
padding: 30rpx;
font-size: 26rpx;
font-family: PingFang SC-Bold, PingFang SC;
font-weight: bold;
color: #333333;
line-height: 40rpx;
padding: 30rpx 30rpx 42rpx 30rpx;
background-color: #fff;
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 {
width: 100rpx;
height: 100rpx;
}
}
}
.nickname_warp {
display: flex;
justify-content: space-between;
align-items: center;
margin-top: 40rpx;
.nickname {
width: 554rpx;
text-align: right;
border: 0;
}
}
}
}
.li_box{
display: flex;
align-items: center;
justify-content: space-between;
font-size: 26rpx;
font-family: PingFang SC-Bold, PingFang SC;
font-weight: bold;
color: #333333;
line-height: 37rpx;
margin: 0 16rpx 52rpx 30rpx;
.li_left{
.cnt-box {
min-height: calc(100vh - 220rpx - 30rpx);
background-color: #fff;
margin: 0 30rpx;
border-radius: 30rpx;
.title {
font-size: 28rpx;
font-family: PingFang SC-Bold, PingFang SC;
font-weight: bold;
color: #333333;
line-height: 40rpx;
padding: 30rpx 30rpx 42rpx 30rpx;
}
}
.li_box {
display: flex;
align-items: center;
justify-content: space-between;
font-size: 26rpx;
font-family: PingFang SC-Bold, PingFang SC;
font-weight: bold;
color: #333333;
line-height: 37rpx;
margin: 0 16rpx 52rpx 30rpx;
.li_left {
display: flex;
align-items: center;
}
}
}
</style>
</style>

@ -132,7 +132,7 @@
},
success: (res) => {
if (res.data.code == 200) {
console.log('下单成功');
this.address = JSON.stringify(res.data.data) == '{}' ? null : res.data.data;
} else if (res.data.code == 401) {
this.doLogin();
} else {
@ -146,13 +146,13 @@
},
//
submitOrder() {
if(!this.address) {
uni.showToast({
title: '请填写收货地址',
icon: 'none'
})
return;
}
// if(!this.address) {
// uni.showToast({
// title: '',
// icon: 'none'
// })
// return;
// }
uni.request({
url: getApp().globalData.baseUrl + '/blade-desk/order/save',
method: 'POST',
@ -167,7 +167,7 @@
},
success: (res) => {
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) {
this.doLogin();
} 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() {
uni.showLoading({
@ -204,7 +246,6 @@
method: 'POST',
data: {
openId: getApp().globalData.openId,
username: this.userInfo.username,
phone: this.phone
},
header: {

Loading…
Cancel
Save