修改上传头像-使用七牛云存储
This commit is contained in:
parent
6d5924e842
commit
cb5b55badd
|
|
@ -188,35 +188,20 @@ export function submitWithdraw(data) {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 上传头像
|
* 上传头像
|
||||||
* @param {string} filePath - 文件路径
|
* @param {string} avatarUrl - 文件路径
|
||||||
* @returns {Promise} 返回上传结果
|
* @returns {Promise} 返回上传结果
|
||||||
*/
|
*/
|
||||||
export function uploadAvatar(filePath) {
|
export function uploadAvatar(avatarUrl) {
|
||||||
return uploadFile(
|
return request({
|
||||||
'/app/user/avatar',
|
url: '/app/user/avatar',
|
||||||
filePath,
|
method: 'PUT',
|
||||||
'avatarfile',
|
data: {
|
||||||
{},
|
avatarUrl: avatarUrl,
|
||||||
{
|
},
|
||||||
timeout: 60000,
|
header: {
|
||||||
}
|
'Content-Type': 'application/x-www-form-urlencoded',
|
||||||
)
|
},
|
||||||
.then(data => {
|
})
|
||||||
// 上传成功后更新本地存储
|
|
||||||
const userInfo = uni.getStorageSync('userInfo') || {}
|
|
||||||
userInfo.avatar = data.data?.avatar || data.data
|
|
||||||
uni.setStorageSync('userInfo', userInfo)
|
|
||||||
|
|
||||||
// 通知其他页面更新头像
|
|
||||||
uni.$emit('avatarUpdated', userInfo.avatar)
|
|
||||||
|
|
||||||
console.log('头像上传成功,已更新本地存储:', userInfo.avatar)
|
|
||||||
return data
|
|
||||||
})
|
|
||||||
.catch(error => {
|
|
||||||
console.error('头像上传失败:', error)
|
|
||||||
throw error
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
|
|
@ -1,24 +1,25 @@
|
||||||
<template>
|
<template>
|
||||||
<view class="page">
|
<view class="page">
|
||||||
<view class="info">
|
<view class="info">
|
||||||
<view
|
<view v-for="(item, index) in userInfoSettings" :key="index" class="info-row">
|
||||||
v-for="(item, index) in userInfoSettings"
|
|
||||||
:key="index"
|
|
||||||
class="info-row"
|
|
||||||
@click="handleItemClick(item)"
|
|
||||||
>
|
|
||||||
<view class="label">{{ item.label }}</view>
|
<view class="label">{{ item.label }}</view>
|
||||||
<view class="value">
|
<image-uploader
|
||||||
<image
|
ref="uploader"
|
||||||
v-if="item.type === 'avatar' && item.value"
|
:height="'100rpx'"
|
||||||
:src="item.value"
|
:width="'100rpx'"
|
||||||
class="avatar-preview"
|
@success="handleUploadSuccess"
|
||||||
mode="aspectFill"
|
/>
|
||||||
/>
|
<!-- <view class="value">-->
|
||||||
<text v-else-if="item.type === 'avatar'">点击设置头像</text>
|
<!-- <image-->
|
||||||
<text v-else>{{ item.value }}</text>
|
<!-- v-if="item.type === 'avatar' && item.value"-->
|
||||||
<text class="arrow">></text>
|
<!-- :src="item.value"-->
|
||||||
</view>
|
<!-- class="avatar-preview"-->
|
||||||
|
<!-- mode="aspectFill"-->
|
||||||
|
<!-- />-->
|
||||||
|
<!-- <text v-else-if="item.type === 'avatar'">点击设置头像</text>-->
|
||||||
|
<!-- <text v-else>{{ item.value }}</text>-->
|
||||||
|
<!-- <text class="arrow">></text>-->
|
||||||
|
<!-- </view>-->
|
||||||
</view>
|
</view>
|
||||||
</view>
|
</view>
|
||||||
<view class="logout-container">
|
<view class="logout-container">
|
||||||
|
|
@ -65,6 +66,15 @@ export default {
|
||||||
this.loadUserInfo()
|
this.loadUserInfo()
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
|
handleUploadSuccess(result) {
|
||||||
|
console.log('图片上传成功:', result.url)
|
||||||
|
this.userInfoSettings.value = result.url
|
||||||
|
this.uploadAvatar(this.userInfoSettings.value)
|
||||||
|
uni.showToast({
|
||||||
|
title: '上传成功',
|
||||||
|
icon: 'success',
|
||||||
|
})
|
||||||
|
},
|
||||||
// 加载用户信息
|
// 加载用户信息
|
||||||
loadUserInfo() {
|
loadUserInfo() {
|
||||||
console.log('开始加载用户信息...')
|
console.log('开始加载用户信息...')
|
||||||
|
|
@ -369,6 +379,7 @@ export default {
|
||||||
margin: 0 34rpx;
|
margin: 0 34rpx;
|
||||||
cursor: pointer;
|
cursor: pointer;
|
||||||
transition: background-color 0.2s ease;
|
transition: background-color 0.2s ease;
|
||||||
|
align-items: center;
|
||||||
|
|
||||||
&:active {
|
&:active {
|
||||||
background-color: #f5f5f5;
|
background-color: #f5f5f5;
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user