You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
114 lines
2.6 KiB
114 lines
2.6 KiB
<template>
|
|
<view class="pages">
|
|
<view class="item" >
|
|
|
|
<text class="text">头像</text>
|
|
<image :src="headImage" class="img" @click="chooseImage"></image>
|
|
</view>
|
|
|
|
</view>
|
|
</template>
|
|
|
|
<script>
|
|
import config from '@/common/config.js'
|
|
export default {
|
|
data() {
|
|
return {
|
|
uploadAction: config.baseUrl + "/portal/v1/sysuser/uploadfile",
|
|
headImage: getApp().globalData.headImage
|
|
// headImage: "https://supervise.yxtsoft.com/img/user/userImage.png"
|
|
}
|
|
},
|
|
methods: {
|
|
|
|
chooseImage() {
|
|
wx.chooseImage({
|
|
count: 1, // 可选择的图片数量
|
|
sizeType: ['compressed'], // 压缩图片
|
|
sourceType: ['album', 'camera'], // 来源:相册或相机
|
|
success: (res)=> {
|
|
// 将选择的图片上传到服务器
|
|
console.log(res.tempFilePaths);
|
|
this.uploadImage(res.tempFilePaths[0]);
|
|
}
|
|
})
|
|
},
|
|
|
|
uploadImage(imagePath) {
|
|
let _this = this
|
|
wx.uploadFile({
|
|
url: _this.uploadAction, // 上传图片的接口地址
|
|
fileType: "image",
|
|
filePath: imagePath, // 图片文件路径
|
|
name: 'file', // 文件对应的 key , 开发者在服务器端通过这个 key 可以获取到文件二进制内容
|
|
success: (res) => {
|
|
// 上传成功后,将服务器返回的图片地址更新到image标签中
|
|
console.log("1111111",res.data)
|
|
|
|
let info = JSON.parse(res.data)
|
|
|
|
console.log("info", info)
|
|
console.log("data", info.data)
|
|
console.log("fullUrl",info.data.fullUrl)
|
|
_this.headImage=info.data.fullUrl
|
|
|
|
console.log("2222",_this.headImage);
|
|
|
|
getApp().globalData.headImage = _this.headImage
|
|
|
|
_this.saveImaage( _this.headImage)
|
|
},
|
|
fail: function (res) {
|
|
console.log(res);
|
|
}
|
|
})
|
|
},
|
|
saveImaage(url){
|
|
|
|
var info ={
|
|
userSid:getApp().globalData.sid,
|
|
headImage:url,
|
|
}
|
|
console.log("info",info);
|
|
this.$api.uploadHandImage(info).then((resp) => {
|
|
// if (resp.success) {
|
|
console.log('1111', resp)
|
|
|
|
}).catch(e => {
|
|
console.log('eeeee', e)
|
|
|
|
})
|
|
}
|
|
|
|
}
|
|
}
|
|
</script>
|
|
|
|
<style lang="scss">
|
|
.pages {
|
|
width: 100%;
|
|
height: 100%;
|
|
display: flex;
|
|
flex-direction: column;
|
|
|
|
.item {
|
|
background: #fff;
|
|
padding: 20px 20px;
|
|
display: flex;
|
|
flex-direction: row;
|
|
justify-content: space-between;
|
|
align-items: center;
|
|
|
|
.text {
|
|
color: #101010;
|
|
font-size: 16px;
|
|
}
|
|
|
|
.img {
|
|
width: 45px;
|
|
height:45px;
|
|
border-radius: 5px;
|
|
}
|
|
}
|
|
}
|
|
</style>
|