优化代码
This commit is contained in:
@@ -147,7 +147,7 @@ import { isLogin, logout } from '@/utils/auth.js'
|
||||
export default {
|
||||
data() {
|
||||
return {
|
||||
userInfo: {},
|
||||
userInfo: this.$store.state.user.userInfo,
|
||||
isLogin: false,
|
||||
stats: {
|
||||
billCount: 0,
|
||||
|
||||
@@ -75,7 +75,7 @@ export default {
|
||||
async loadUserInfo() {
|
||||
try {
|
||||
// 从本地存储获取用户信息
|
||||
const userInfo = uni.getStorageSync('userInfo') || {}
|
||||
const userInfo = this.$store.state.user.userInfo || {}
|
||||
this.formData = {
|
||||
username: userInfo.username || '',
|
||||
nickname: userInfo.nickname || '',
|
||||
@@ -113,47 +113,23 @@ export default {
|
||||
title: '上传中...'
|
||||
})
|
||||
|
||||
// 调用上传接口
|
||||
uni.uploadFile({
|
||||
url: commonApi.upload.url,
|
||||
filePath: filePath,
|
||||
name: 'file',
|
||||
header: {
|
||||
'Authorization': 'Bearer ' + uni.getStorageSync('token')
|
||||
},
|
||||
success: (uploadRes) => {
|
||||
uni.hideLoading()
|
||||
try {
|
||||
const data = JSON.parse(uploadRes.data)
|
||||
if (data.code === 1) {
|
||||
this.formData.avatar = data.data.url || data.data
|
||||
uni.showToast({
|
||||
title: '上传成功',
|
||||
icon: 'success'
|
||||
})
|
||||
} else {
|
||||
uni.showToast({
|
||||
title: data.message || '上传失败',
|
||||
icon: 'none'
|
||||
})
|
||||
}
|
||||
} catch (e) {
|
||||
console.error('解析上传结果失败:', e)
|
||||
uni.showToast({
|
||||
title: '上传失败',
|
||||
icon: 'none'
|
||||
})
|
||||
}
|
||||
},
|
||||
fail: (error) => {
|
||||
uni.hideLoading()
|
||||
console.error('上传失败:', error)
|
||||
uni.showToast({
|
||||
title: '上传失败',
|
||||
icon: 'none'
|
||||
})
|
||||
}
|
||||
})
|
||||
// 调用上传接口,传递 type=avatar 参数
|
||||
const result = await this.$api.common.upload.post(filePath, { type: 'avatar' })
|
||||
|
||||
uni.hideLoading()
|
||||
|
||||
if (result && result.code === 1) {
|
||||
this.formData.avatar = result.data.url || result.data
|
||||
uni.showToast({
|
||||
title: '上传成功',
|
||||
icon: 'success'
|
||||
})
|
||||
} else {
|
||||
uni.showToast({
|
||||
title: result?.message || '上传失败',
|
||||
icon: 'none'
|
||||
})
|
||||
}
|
||||
} catch (error) {
|
||||
uni.hideLoading()
|
||||
console.error('上传头像失败:', error)
|
||||
@@ -192,7 +168,7 @@ export default {
|
||||
})
|
||||
|
||||
// 调用更新用户信息接口
|
||||
const result = await memberApi.edit.put({
|
||||
const result = await this.$api.member.edit.post({
|
||||
nickname: this.formData.nickname,
|
||||
email: this.formData.email,
|
||||
avatar: this.formData.avatar
|
||||
@@ -268,12 +244,6 @@ export default {
|
||||
</script>
|
||||
|
||||
<style lang="scss" scoped>
|
||||
.edit-profile-container {
|
||||
min-height: 100vh;
|
||||
background: #f5f5f5;
|
||||
padding-bottom: 40rpx;
|
||||
}
|
||||
|
||||
.avatar-section {
|
||||
background: #fff;
|
||||
padding: 60rpx 0;
|
||||
|
||||
@@ -91,12 +91,6 @@ export default {
|
||||
</script>
|
||||
|
||||
<style lang="scss" scoped>
|
||||
.profile-container {
|
||||
min-height: 100vh;
|
||||
background: #f5f5f5;
|
||||
padding-bottom: 40rpx;
|
||||
}
|
||||
|
||||
.user-card {
|
||||
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
|
||||
margin: 20rpx 30rpx;
|
||||
|
||||
@@ -230,12 +230,6 @@ export default {
|
||||
</script>
|
||||
|
||||
<style lang="scss" scoped>
|
||||
.password-container {
|
||||
min-height: 100vh;
|
||||
background: #f5f5f5;
|
||||
padding-bottom: 40rpx;
|
||||
}
|
||||
|
||||
.form-section {
|
||||
margin: 20rpx 30rpx;
|
||||
background: #fff;
|
||||
|
||||
Reference in New Issue
Block a user