<!-- 头像底部弹窗 -->
<u-action-sheet :actions="list" :show="look" round="20" @select="chooseupload" @close="look=false">
</u-action-sheet>
<view class="flex-between"
style="padding:28rpx 0;box-sizing:border-box;border-bottom: 2rpx solid #F6F7FA;">
<view style="font-size: 30rpx;color: #222222;">
<text>头像</text>
</view>
<view class="flex" style="position:relative;" @click="chooseImage">
<div class="flex">
<image style="width: 80rpx;height: 80rpx;border-radius: 8rpx;" :src="userInfo.headimg"
mode="">
</image>
<u-icon name="arrow-right"></u-icon>
</div>
</view>
</view>
**// 定义数据**
list: [{
name: '拍摄',
color: 'black',
fontSize: 28
}, {
name: '从相册选择',
color: 'black',
fontSize: 28
}, {
name: '取消',
color: '#096967',
fontSize: 28
}],
**// 方法**
// 选择上传图像的方式
chooseupload(index) {
console.log("index", index);
switch (index.name) {
case "拍摄":
this.clickUp(1);
break;
case "从相册选择":
this.clickUp(0);
break;
default:
return
break;
}
},
// 显示图片
chooseImage() {
this.look = true;
},
// 上传图片
clickUp(index) {
var that = this;
let type = "";
switch (index) {
case 0:
type = "album";
break;
case 1:
type = "camera";
break;
default:
return
break;
}
uni.chooseImage({
count: 1, //默认9
sizeType: ['original', 'compressed'], //可以指定是原图还是压缩图,默认二者都有
sourceType: [type], //拍照还是相册
success: function(res) {
uni.showLoading({
title: "上传中",
mack: true
})
//用户选择或者拍照图片的临时路径
let tempPath = res.tempFilePaths[0];
//这里发送上传文件请求,然后服务器响应图片地址然后替换src,然后关闭加载动画
uni.uploadFile({
url: app.globalData.apiUrl + 'api/user/upload', //仅为示例,非真实的接口地址
filePath: tempPath,
name: 'file',
formData: {
'token': uni.getStorageSync('token')
},
success: (uploadFileRes) => {
if (JSON.parse(uploadFileRes.data).code !== 0) {
uni.$u.toast(JSON.parse(uploadFileRes.data).msg);
} else {
commonApi("api/user/update_user", {
headimg: app.globalData.apiUrl + JSON.parse(
uploadFileRes.data)
.data
}).then((res) => {
// 刷新个人信息
that.getPersionInfo();
// 修改成功提示
uni.$u.toast("修改成功");
})
}
}
});
}
});
},