master
git 8 years ago
parent f65a220435
commit 657fd2fb4e

@ -109,7 +109,6 @@ export default {
let cropper = new Cropper(this.$refs.editImage, { let cropper = new Cropper(this.$refs.editImage, {
aspectRatio: 1 / 1, aspectRatio: 1 / 1,
viewMode: 1, viewMode: 1,
minContainerHeight: 300,
}) })
this.cropper = cropper this.cropper = cropper
}) })
@ -123,15 +122,20 @@ export default {
}, },
methods: { methods: {
async editSave() { editSave() {
this.edit = false this.edit = false
let blob = await new Promise((resolve, reject) => {
this.cropper.getCroppedCanvas().toBlob(function (value) { let oldFile = this.files[0]
resolve(value)
}) let binStr = atob(this.cropper.getCroppedCanvas().toDataURL(oldFile.type).split(',')[1])
}) let arr = new Uint8Array(binStr.length)
let file = new File([blob], this.files[0].name, { type: blob.type }) for (let i = 0; i < binStr.length; i++) {
this.$refs.upload.update(this.files[0].id, { arr[i] = binStr.charCodeAt(i)
}
let file = new File([arr], oldFile.name, { type: oldFile.type })
this.$refs.upload.update(oldFile.id, {
file, file,
type: file.type, type: file.type,
size: file.size, size: file.size,

@ -541,7 +541,7 @@ export default {
this.$refs.upload.update(file, { error: 'edit' }) this.$refs.upload.update(file, { error: 'edit' })
}, },
async onEditorFile() { onEditorFile() {
if (!this.$refs.upload.features.html5) { if (!this.$refs.upload.features.html5) {
this.alert('Your browser does not support') this.alert('Your browser does not support')
this.editFile.show = false this.editFile.show = false
@ -552,14 +552,13 @@ export default {
name: this.editFile.name, name: this.editFile.name,
} }
if (this.editFile.cropper) { if (this.editFile.cropper) {
let blob = await new Promise((resolve, reject) => { let binStr = atob(this.editFile.cropper.getCroppedCanvas().toDataURL(this.editFile.type).split(',')[1])
this.editFile.cropper.getCroppedCanvas().toBlob(function (value) { let arr = new Uint8Array(binStr.length)
resolve(value) for (let i = 0; i < binStr.length; i++) {
}) arr[i] = binStr.charCodeAt(i)
}) }
data.file = new File([blob], data.name, { type: blob.type }) data.file = new File([arr], data.name, { type: this.editFile.type })
data.type = blob.type data.size = data.file.size
data.size = blob.size
} }
this.$refs.upload.update(this.editFile.id, data) this.$refs.upload.update(this.editFile.id, data)
this.editFile.error = '' this.editFile.error = ''

Loading…
Cancel
Save