优化代码

This commit is contained in:
2026-01-19 13:07:02 +08:00
parent 51cfee33db
commit e3b7c63e5a
9 changed files with 157 additions and 67 deletions

View File

@@ -2,10 +2,13 @@ import request from '@/utils/request'
export default {
upload: {
url: '/api/system/upload',
url: '/api/system/file/upload',
name: '图片上传',
post: async function(params) {
return request.post(this.url, params)
post: async function(file, params) {
return request.upload(this.url, {
filePath: file,
params
})
}
}
}

View File

@@ -144,7 +144,7 @@ export default {
paymentMap: {
'微信': { name: '微信', icon: 'weixin', color: '#07C160' },
'支付宝': { name: '支付宝', icon: 'redo', color: '#1677FF' },
'银行卡': { name: '银行卡', icon: 'bankcard', color: '#FF6B6B' },
'银行卡': { name: '银行卡', icon: 'camera', color: '#FF6B6B' },
'现金': { name: '现金', icon: 'wallet', color: '#FFA500' },
'其他': { name: '其他', icon: 'more', color: '#999999' }
}

View File

@@ -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,

View File

@@ -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;

View File

@@ -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;

View File

@@ -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;