邓洁 : 修改个人信息接口对接

This commit is contained in:
邓洁
2023-11-16 21:42:01 +08:00
parent 00ebbba179
commit b07248d07b
4 changed files with 155 additions and 64 deletions

View File

@@ -172,17 +172,17 @@
"navigationBarTitleText": "", "navigationBarTitleText": "",
"enablePullDownRefresh": false "enablePullDownRefresh": false
} }
}, {
"path": "pages/my/edit/edit",
"style": {
"navigationBarTitleText": "修改个人信息",
"navigationBarTextStyle": "white",
"navigationBarBackgroundColor": "#339967",
"enablePullDownRefresh": false
}
} }
,{ ],
"path" : "pages/my/edit/edit",
"style" :
{
"navigationBarTitleText": "修改个人信息",
"enablePullDownRefresh": false
}
}
],
"tabBar": { "tabBar": {
"color": "#CCCCCC", "color": "#CCCCCC",
"borderStyle": "white", "borderStyle": "white",

View File

@@ -1,69 +1,146 @@
<template> <template>
<view> <view>
<view class="avatar"> <view class="avatar">
<u-avatar @click="changeAvatar()" :src="Info.avatar"></u-avatar> <u-avatar @click="changeAvatar()" size="140rpx" :src="Info.avatar"></u-avatar>
</view> </view>
<view class="name-edit"> <!-- <view class="name-edit">
<text>用户名</text> <text>用户名</text>
<u-input border="surround" v-model="Info.username"></u-input> <u-input border="surround" v-model="Info.username"></u-input>
</view> </view> -->
<view class="send"> <view class="info-name">
<u-button @click="editInfo(Info)" color="linear-gradient(to right, #E86262, #CC3333)">提交</u-button> <u--form labelPosition="left" :model="Info">
<u-form-item label="修改昵称" prop="Info.username" borderBottom>
<u--input v-model="Info.username" border="none" placeholder="请输入您的昵称"
placeholderStyle="color: #CCCCCC;font-size: 26rpx;"></u--input>
</u-form-item>
</u--form>
</view> </view>
<view style="height: 100rpx;"></view>
<u-button @click="editInfo(Info)" color="#339967">提交</u-button>
</view> </view>
</template> </template>
<script> <script>
export default { export default {
data(){ data() {
return { return {
Info:{ Info: {
avatar:[], avatar: [],
username:'' username: '',
avatarUrl: ''
} }
} }
}, },
methods: { methods: {
changeAvatar(){ //获取头像昵称
getUserInfo() {
this.$api.getUser().then(res => {
const data = res.data.data
console.log('头像昵称', res);
if (data) {
this.avatar = this.$api.imgUrl + data.avatar
this.avatarUrl = '/' + data.avatar
this.Info.username = data.nickname
}
}).finally(_ => {})
},
updatePromise(filePath) {
return new Promise((resolve, reject) => {
const token = uni.getStorageSync('loginToken')
const a = uni.uploadFile({
url: this.$api.uploadImgUrl,
filePath: filePath,
name: 'file',
header: {
"Content-Type": "multipart/form-data",
'Authorization': token
},
success: (res) => {
resolve(JSON.parse(res.data).data.url)
}
});
})
},
changeAvatar() {
uni.chooseImage({ uni.chooseImage({
count: 1, //默认选择1张图片
sizeType: ['original', 'compressed'], //original 原图compressed 压缩图,默认二者都有
success: (chooseImageRes) => { success: (chooseImageRes) => {
this.Info.avatar = chooseImageRes.tempFilePaths.toString() ; this.Info.avatar = chooseImageRes.tempFilePaths[0] //更新本地浏览头像图片
if (chooseImageRes.tempFilePaths[0]) {
const result = this.updatePromise(chooseImageRes.tempFilePaths[0]) //上传图片
result.then(value => {
this.avatarUrl = '/' + value
})
}
} }
}); });
}, },
editInfo(data){ editInfo() {
let resdata=JSON.stringify(data); // let resdata = JSON.stringify(data);
this.$api.editPersonInfo(resdata).then(res => { // this.$api.editPersonInfo(resdata).then(res => {
console.log(resdata); // console.log(resdata);
console.log(res) // console.log(res)
}) // })
this.$api.editPersonInfo({
nickname: this.Info.username,
avatar: this.avatarUrl
}).then(res => {
console.log('修改头像昵称==', res);
this.$toast.success(res.data.msg)
if (res.data.code == 1) {
uni.reLaunch({
url: '/pages/my/my'
})
}
}).finally(_ => {})
}, },
}, },
onLoad() { onLoad() {
let that = this let that = this
this.$data.Info.username = wx.getStorageSync('nickname') this.$data.Info.username = wx.getStorageSync('nickname')
this.$data.Info.avatar = wx.getStorageSync('avatar') this.$data.Info.avatar = wx.getStorageSync('avatar')
this.getUserInfo()
} }
} }
</script> </script>
<style> <style lang="scss">
.avatar{ page {
width: 100%; background-color: #f4f4f4;
height: 200rpx; }
.avatar {
margin: 60rpx 0;
/* width: 100%; */
/* height: 200rpx; */
display: flex; display: flex;
justify-content: center; justify-content: center;
align-items: center; align-items: center;
} }
.name-edit{
.name-edit {
display: flex; display: flex;
flex-direction: column; flex-direction: column;
justify-content: center; justify-content: center;
} }
.send{
width: 50%;
transform: translateX(50%) translateY(50%);
.info-name {
.u-form-item {
background-color: #fff;
}
.u-form-item__body__left {
width: 80px !important;
margin-left: 20rpx;
}
} }
</style>
.u-button {
width: 644rpx !important;
height: 86rpx !important;
background: #0EBB5B;
border-radius: 20rpx !important;
}
</style>

View File

@@ -7,8 +7,10 @@
<u-avatar :src="src"></u-avatar> <u-avatar :src="src"></u-avatar>
</view> </view>
<view class="username">{{username}}</view> <view class="username">{{username}}</view>
<view class="account">账号:{{account}} <u-icon name="edit-pen" class="edit-icon" size="20" @click="toEdit"></u-icon></view> <view class="account">账号:{{account}}
<u-icon name="edit-pen" class="edit-icon" size="20" color="#fff" @click="toEdit"></u-icon>
</view>
</view> </view>
<view class="publish"> <view class="publish">
<u-cell-group> <u-cell-group>
@@ -43,8 +45,8 @@
data() { data() {
return { return {
src: 'https://cdn.uviewui.com/uview/album/2.jpg', src: 'https://cdn.uviewui.com/uview/album/2.jpg',
account: '', account: '123',
username: '', username: '用户名',
isLoad: true isLoad: true
} }
}, },
@@ -54,8 +56,9 @@
return return
} }
this.isLoad = true this.isLoad = true
this.$data.account = wx.getStorageSync('account') // this.$data.account = wx.getStorageSync('account')
this.$data.username = wx.getStorageSync('nickname') // this.$data.username = wx.getStorageSync('nickname')
this.getInfo()
}, },
methods: { methods: {
reOnLoad() { reOnLoad() {
@@ -86,17 +89,22 @@
url: '/pages/Partnerships/Partnerships' url: '/pages/Partnerships/Partnerships'
}) })
}, },
toEdit(){ toEdit() {
uni.navigateTo({ uni.navigateTo({
url:'/pages/my/edit/edit' url: '/pages/my/edit/edit'
})
},
//---------页面调用接口示例------------
getInfo() {
this.$api.getUser().then(res => {
console.log('userInfo', res);
var data = res.data.data
if (data) {
this.src = uni.getStorageSync('img_url') + data.avatar
this.username = data.nickname
}
}) })
} }
//---------页面调用接口示例------------
// getInfo() {
// this.$api.getUserInfo().then(res => {
// console.log('userInfo', res);
// })
// }
} }
} }
</script> </script>
@@ -134,9 +142,8 @@
font-weight: 1rpx; font-weight: 1rpx;
display: flex; display: flex;
} }
.edit-icon{
.edit-icon {}
}
} }
</style> </style>

View File

@@ -130,7 +130,7 @@ const apiService = {
serverHost, serverHost,
imgUrl: 'https://spsp.feashow.com/', imgUrl: 'https://spsp.feashow.com/',
key: 'ZRKBZ-Q7FWL-GVZPK-MCRBU-4XFB5-ATBDB', key: 'ZRKBZ-Q7FWL-GVZPK-MCRBU-4XFB5-ATBDB',
uploadImgUrl: serverHost + `/upload/image/`, uploadImgUrl: serverHost + '/upload/image/',
//登录接口 //登录接口
login(data) { login(data) {
const url = '/login/mnpLogin' const url = '/login/mnpLogin'
@@ -211,27 +211,34 @@ const apiService = {
resolve(service.get(url)) resolve(service.get(url))
}) })
}, },
//获取个人信息
getUser() {
const url = '/center/userinfo'
return new Promise((resolve, reject) => {
resolve(service.get(url))
})
},
//修改个人信息 //修改个人信息
editPersonInfo(data){ editPersonInfo(data) {
const url = `center/userupdate` const url = `center/userupdate`
return new Promise((resolve,reject) => { return new Promise((resolve, reject) => {
resolve(service.putWithFormData(url,data)) resolve(service.post(url, data))
}) })
}, },
//获取我的匹配 //获取我的匹配
getMyMatch(){ getMyMatch() {
const url = `/center/match/` const url = `/center/match/`
return new Promise((resolve,reject) => { return new Promise((resolve, reject) => {
resolve(service.get(url)) resolve(service.get(url))
}) })
}, },
//获取行业和业态 //获取行业和业态
getClassList(pid){ getClassList(pid) {
const url = `/home/classlist/?pid=${pid}` const url = `/home/classlist/?pid=${pid}`
return new Promise((resolve,reject) => { return new Promise((resolve, reject) => {
resolve(service.post(url)) resolve(service.post(url))
}) })
} },
} }
export { export {
apiService, apiService,