优化:用户头像上传

This commit is contained in:
jmal 2021-03-05 11:30:01 +08:00
parent 2e77870ab1
commit d155f9015a
4 changed files with 19 additions and 3 deletions

View File

@ -1,6 +1,6 @@
{ {
"name": "jmal-cloud-view", "name": "jmal-cloud-view",
"version": "2.1.7", "version": "2.1.8",
"description": "jmal cloud", "description": "jmal cloud",
"author": "Jmal <zhushilun084@163.com>", "author": "Jmal <zhushilun084@163.com>",
"license": "MIT", "license": "MIT",

View File

@ -48,6 +48,7 @@
return { return {
loading: true, loading: true,
cropper: null, cropper: null,
filename: '',
sourceImg: '' sourceImg: ''
} }
}, },
@ -100,6 +101,8 @@
} }
}, },
changImg(file) { changImg(file) {
console.log(file)
this.filename = file.name
if(file.size > 0){ if(file.size > 0){
this.loading = true this.loading = true
this.cropper.reset() this.cropper.reset()
@ -122,6 +125,7 @@
}) })
let dataURL = cro.toDataURL('image/jpeg'); let dataURL = cro.toDataURL('image/jpeg');
cro.toBlob((blob)=>{ cro.toBlob((blob)=>{
blob.name = this.filename
this.$emit('croppedCanvas', dataURL, blob) this.$emit('croppedCanvas', dataURL, blob)
}) })
}, },

View File

@ -1767,6 +1767,9 @@ export default {
}, },
// 填充数据 // 填充数据
loadData(res, onLoad) { loadData(res, onLoad) {
if (!this.$refs.fileListTable) {
return
}
if (onLoad) { if (onLoad) {
res.data.forEach((file, number) => { res.data.forEach((file, number) => {
file['index'] = (this.pagination.pageIndex - 1) * this.pagination.pageSize + number file['index'] = (this.pagination.pageIndex - 1) * this.pagination.pageSize + number

View File

@ -166,6 +166,7 @@
} }
this.fileImg = files[0] this.fileImg = files[0]
this.dialogAvatar = true this.dialogAvatar = true
this.selectedImgRow = {}
if(this.$refs.cropperDialog){ if(this.$refs.cropperDialog){
this.$refs.cropperDialog.changImg(files[0]) this.$refs.cropperDialog.changImg(files[0])
} }
@ -267,15 +268,23 @@
return data return data
}, },
// 保存头像 // 保存头像
saveAvatar(dataURL,blob) { saveAvatar(dataURL, blob) {
this.dialogAvatar = false this.dialogAvatar = false
this.srcImage = dataURL this.srcImage = dataURL
let data = new FormData(); let data = new FormData();
data.append('id', this.$store.state.user.userId) data.append('id', this.$store.state.user.userId)
data.append('avatar', dataURL) // data.append('avatar', dataURL)
console.log(this.blobToFile(blob))
data.append('blobAvatar',blob) data.append('blobAvatar',blob)
this.userUpdate(data,dataURL) this.userUpdate(data,dataURL)
}, },
blobToFile(blob){
return new window.File(
[blob],
blob.name,
{ type: blob.type }
)
},
// 保存不剪裁的头像 // 保存不剪裁的头像
saveNoCropAvatar(fileId) { saveNoCropAvatar(fileId) {
this.dialogAvatar = false this.dialogAvatar = false