diff --git a/src/api/index.js b/src/api/index.js index 523120b..bcead86 100644 --- a/src/api/index.js +++ b/src/api/index.js @@ -88,4 +88,8 @@ export function updatePhoto(photo) { export function deletePhoto(id) { return apiClient.delete('/deletephoto/'+id+'/') +} + +export function cropPhoto(id, mode) { + return apiClient.get('/cropphoto/'+id+'/?mode='+mode) } \ No newline at end of file diff --git a/src/components/PhotoCropper.vue b/src/components/PhotoCropper.vue index d251701..f5d4e80 100644 --- a/src/components/PhotoCropper.vue +++ b/src/components/PhotoCropper.vue @@ -1,13 +1,28 @@ @@ -28,15 +43,48 @@ export default { }, data() { return { - + preview_data_url: null, + lock_aspect_ratio: true, + bbox: [] } }, - mounted() { - console.log(this.src) + computed: { + aspect_ratio() { + if (this.lock_aspect_ratio) { + return { + aspectRatio: 1/1.41421356 + } + } + return {} + } }, methods: { + coordinates_to_bbox(coordinates) { + let top_left = [ + coordinates.left, + coordinates.top + ] + let top_right = [ + coordinates.left + coordinates.width, + coordinates.top + ] + let bottom_right = [ + coordinates.left + coordinates.width, + coordinates.top + coordinates.height + ] + let bottom_left = [ + coordinates.left, + coordinates.top + coordinates.height + ] + + return [top_left, top_right, bottom_right, bottom_left] + }, change({ coordinates, canvas }) { - console.log(coordinates, canvas) + this.preview_data_url = canvas.toDataURL() + this.bbox = this.coordinates_to_bbox(coordinates) + }, + getResult() { + return JSON.parse(JSON.stringify(this.bbox)) } } } @@ -48,4 +96,8 @@ export default { width: 600px; background: #DDD; } + +.preview { + max-width: 300px; +} \ No newline at end of file diff --git a/src/components/PhotoItem.vue b/src/components/PhotoItem.vue index be7f64f..069b69f 100644 --- a/src/components/PhotoItem.vue +++ b/src/components/PhotoItem.vue @@ -105,11 +105,16 @@ export default { type: Number, required: false, default: 150, - } + }, + init_selection: { + type: Boolean, + required: false, + default: false, + }, }, emits: [ 'update:select', - 'update:delet', + 'update:delete', 'update:crop', 'update:ocr', 'update:group', @@ -126,6 +131,9 @@ export default { beforeMount() { this.imgSrcObj = new Image() this.imgSrcObj.src = this.src + if (this.can_select && this.init_selection) { + this.selected = true + } }, watch: { imgSrcObj: { @@ -202,6 +210,7 @@ export default { toggleSelection() { if (this.can_select) { this.selected = !this.selected + this.$emit('update:select', this.selected) } } }, diff --git a/src/components/PhotoSelectModal.vue b/src/components/PhotoSelectModal.vue index 03aac03..4f7b022 100644 --- a/src/components/PhotoSelectModal.vue +++ b/src/components/PhotoSelectModal.vue @@ -27,18 +27,18 @@ :title="group.name" :name="group.id"> - - + :can_select="true" + :init_selection="is_photo_selected(photo.id)" + @update:select="toggle_select_photo(photo.id)" + :ref="'photoitem-'+photo.id" + /> - @@ -57,13 +57,13 @@