Commit fc843f07 authored by yaya's avatar yaya

feat:添加图片裁剪上传功能

parent 4dfb2984
<component name="InspectionProjectProfileManager">
<profile version="1.0">
<option name="myName" value="Project Default" />
<inspection_tool class="Eslint" enabled="true" level="WARNING" enabled_by_default="true" />
</profile>
</component>
\ No newline at end of file
...@@ -23,3 +23,11 @@ export function saveImageBase64(params) { ...@@ -23,3 +23,11 @@ export function saveImageBase64(params) {
data: params data: params
}) })
} }
export function saveCroppingRecord(params) {
return request({
url: '/item/saveCroppingRecord',
method: 'post',
data: params
})
}
...@@ -78,7 +78,7 @@ ...@@ -78,7 +78,7 @@
</template> </template>
<script> <script>
import { VuePictureCut, VuePictureCutMask, VuePictureCutMenu } from 'vue-picture-cut' import { VuePictureCut, VuePictureCutMask, VuePictureCutMenu, createUtils } from 'vue-picture-cut'
import SelectImageDialog from './selectImageDialog' import SelectImageDialog from './selectImageDialog'
import LamaImageDialog from './lamaImageDialog' import LamaImageDialog from './lamaImageDialog'
...@@ -101,12 +101,13 @@ export default { ...@@ -101,12 +101,13 @@ export default {
}, },
data() { data() {
return { return {
utils: null,
pictureCut: null, pictureCut: null,
// src: this.imageBase64, // src: this.imageBase64,
cutInfo: { cutInfo: {
initAngle: 0, initAngle: 0,
maxPixel: 500, maxPixel: 500,
encoderOptions: 0.8 encoderOptions: 1
}, },
mastInfo: { mastInfo: {
width: 1, width: 1,
...@@ -117,7 +118,7 @@ export default { ...@@ -117,7 +118,7 @@ export default {
menuInfo: { menuInfo: {
format: 'image/jpeg/png', format: 'image/jpeg/png',
maxPixel: 500, maxPixel: 500,
encoderOptions: 0.8 encoderOptions: 1
}, },
showLamaImageDialog: false, showLamaImageDialog: false,
imageBase64: '', imageBase64: '',
...@@ -136,7 +137,7 @@ export default { ...@@ -136,7 +137,7 @@ export default {
if (this.imageBase64) { if (this.imageBase64) {
setTimeout(() => { setTimeout(() => {
this.pictureCut = this.$refs['pictureCut'] this.pictureCut = this.$refs['pictureCut']
console.log('==7777777777==', this.pictureCut) this.utils = createUtils(this.pictureCut)
}, 1000) }, 1000)
} }
}, },
...@@ -148,11 +149,44 @@ export default { ...@@ -148,11 +149,44 @@ export default {
}, },
// 裁剪图片结果 // 裁剪图片结果
cutChange(res) { cutChange(res) {
this.handleUploadParam()
this.imageBase64 = '' this.imageBase64 = ''
this.$emit('cutEditSuccess', this.editImageUrl, res.base64) this.$emit('cutEditSuccess', this.editImageUrl, res.base64)
// console.log('=====blob', this.blob) // console.log('=====blob', this.blob)
console.log('=====base64', this.base64) console.log('=====base64', this.base64)
}, },
/**
* 上传裁剪参数
*/
handleUploadParam() {
const options = this.utils.getOptions()
// console.log('配置:', options)
if (options && options.img && options.img.showRect) {
const rectW = options.img.showRect.w // 展示图片宽
const rectH = options.img.showRect.h // 展示图片高
const rectX = options.img.showRect.x // 偏移量处理后x
const rectY = options.img.showRect.y // 偏移量处理后y
const offsetX = rectX + rectW / 2 // 偏移量x 正数右 负数左
const offsetY = rectY * 2 // 偏移量y 正数上 负数下
const { w, h } = options.mask
const obj = {
width: rectW,
height: rectH,
x: Math.ceil(rectW / 2 - w / 2 - offsetX),
y: Math.ceil(rectH / 2 - h / 2 - offsetY),
maskW: w,
maskH: h
}
const param = {
imageUrl: this.editImageUrl,
coordinate: JSON.stringify(obj)
}
// console.log('====params==', param)
this.$emit('uploadEditImage', param)
}
},
handlerGetBase64(currentImageUrl, imgUrlBase64) { handlerGetBase64(currentImageUrl, imgUrlBase64) {
this.changeImageUrl = currentImageUrl this.changeImageUrl = currentImageUrl
if (imgUrlBase64) { if (imgUrlBase64) {
......
...@@ -90,7 +90,7 @@ ...@@ -90,7 +90,7 @@
</template> </template>
<script> <script>
import { VuePictureCut, VuePictureCutMask, VuePictureCutMenu } from 'vue-picture-cut' import { VuePictureCut, VuePictureCutMask, VuePictureCutMenu, createUtils } from 'vue-picture-cut'
import SelectImageDialog from './selectImageDialog' import SelectImageDialog from './selectImageDialog'
export default { export default {
...@@ -112,20 +112,17 @@ export default { ...@@ -112,20 +112,17 @@ export default {
imageList: { imageList: {
type: Array, type: Array,
default: () => [] default: () => []
},
editImageUrl: {
type: String,
default: ''
} }
}, },
data() { data() {
return { return {
pictureCut: null, pictureCut: null,
utils: null,
// src: this.imageBase64, // src: this.imageBase64,
cutInfo: { cutInfo: {
initAngle: 0, initAngle: 0,
maxPixel: 500, maxPixel: 500,
encoderOptions: 0.8 encoderOptions: 1
}, },
mastInfo: { mastInfo: {
width: 1, width: 1,
...@@ -136,11 +133,12 @@ export default { ...@@ -136,11 +133,12 @@ export default {
menuInfo: { menuInfo: {
format: 'image/jpeg/png', format: 'image/jpeg/png',
maxPixel: 500, maxPixel: 500,
encoderOptions: 0.8 encoderOptions: 1
}, },
selectImageDialogVisible: false, selectImageDialogVisible: false,
selectType: 0, selectType: 0,
imageBase64: '' imageBase64: '',
currentImageUrl: ''
} }
}, },
watch: { watch: {
...@@ -155,6 +153,7 @@ export default { ...@@ -155,6 +153,7 @@ export default {
if (this.imageBase64) { if (this.imageBase64) {
setTimeout(() => { setTimeout(() => {
this.pictureCut = this.$refs['pictureCut'] this.pictureCut = this.$refs['pictureCut']
this.utils = createUtils(this.pictureCut)
console.log('==7777777777==', this.pictureCut) console.log('==7777777777==', this.pictureCut)
}, 1000) }, 1000)
} }
...@@ -184,13 +183,44 @@ export default { ...@@ -184,13 +183,44 @@ export default {
}, },
// 裁剪图片结果 // 裁剪图片结果
cutChange(res) { cutChange(res) {
this.handleUploadParam()
this.imageBase64 = '' this.imageBase64 = ''
this.$emit('cutSuccess', this.imageType, res) this.$emit('cutSuccess', this.imageType, res)
// console.log('=====blob', this.blob) // console.log('=====blob', this.blob)
console.log('=====base64', this.base64) console.log('=====base64', this.base64)
}, },
handleUploadParam() {
const options = this.utils.getOptions()
// console.log('配置:', options)
if (options && options.img && options.img.showRect && this.currentImageUrl) {
const rectW = options.img.showRect.w // 展示图片宽
const rectH = options.img.showRect.h // 展示图片高
const rectX = options.img.showRect.x // 偏移量处理后x
const rectY = options.img.showRect.y // 偏移量处理后y
const offsetX = rectX + rectW / 2 // 偏移量x 正数右 负数左
const offsetY = rectY * 2 // 偏移量y 正数上 负数下
const { w, h } = options.mask
const obj = {
width: rectW,
height: rectH,
x: Math.ceil(rectW / 2 - w / 2 - offsetX),
y: Math.ceil(rectH / 2 - h / 2 - offsetY),
maskW: w,
maskH: h
}
const param = {
imageUrl: this.currentImageUrl,
coordinate: JSON.stringify(obj)
}
console.log('====params==', param)
this.$emit('uploadImage', param)
}
},
handlerGetBase64(currentImageUrl, imgUrlBase64) { handlerGetBase64(currentImageUrl, imgUrlBase64) {
this.changeImageUrl = currentImageUrl this.currentImageUrl = currentImageUrl
if (imgUrlBase64) { if (imgUrlBase64) {
this.imageBase64 = imgUrlBase64 this.imageBase64 = imgUrlBase64
} else { } else {
......
...@@ -27,7 +27,7 @@ export default { ...@@ -27,7 +27,7 @@ export default {
}, },
data() { data() {
return { return {
iframeSrc: ' http://lama.wanwudezhi.work/' iframeSrc: 'https://lama.wanwudezhi.work/'
} }
}, },
mounted() { mounted() {
......
...@@ -74,26 +74,22 @@ export default { ...@@ -74,26 +74,22 @@ export default {
this.$message.error('该图片不支持该操作') this.$message.error('该图片不支持该操作')
return return
} }
this.currentImageUrl = this.imageList[this.currentPosition]
if (this.selectType === 1) { // 去水印 if (this.selectType === 1) { // 去水印
this.copyContent(this.imageList[this.currentPosition]) this.copyContent(this.imageList[this.currentPosition])
this.$message.success('复制链接成功,粘贴链接去水印吧') this.$message.success('复制链接成功,粘贴链接去水印吧')
this.showLamaImageDialog = true this.showLamaImageDialog = true
this.currentImageUrl = this.imageList[this.currentPosition]
} else { } else {
this.handleSelectSuccess(this.imageList[this.currentPosition]) this.handleSelectSuccess(this.currentImageUrl)
/* this.$emit('selectSuccess', this.imageList[this.currentPosition])
this.$emit('closeDialog')
this.currentImageUrl = ''*/
} }
}, },
handleGetImageBase64(imgUrlBase64) { handleGetImageBase64(imgUrlBase64, width, height) {
this.$emit('imageBase64Str', this.currentImageUrl, imgUrlBase64) this.$emit('imageBase64Str', this.currentImageUrl, imgUrlBase64, width, height)
this.showLamaImageDialog = false this.showLamaImageDialog = false
this.$emit('closeDialog') this.$emit('closeDialog')
}, },
// 选择线上图片后的图片链接 // 选择线上图片后的图片链接
async handleSelectSuccess(url) { async handleSelectSuccess(url) {
this.changeImageUrl = url
const base64Str = await this.getBase64Image(url) const base64Str = await this.getBase64Image(url)
this.$emit('imageBase64Str', this.currentImageUrl, base64Str) this.$emit('imageBase64Str', this.currentImageUrl, base64Str)
this.showLamaImageDialog = false this.showLamaImageDialog = false
......
...@@ -149,13 +149,15 @@ ...@@ -149,13 +149,15 @@
:image-list="imageList" :image-list="imageList"
:show-cut-dialog="cutImageDialogVisible" :show-cut-dialog="cutImageDialogVisible"
@cutImageDialogClose="cutImageDialogVisible = false" @cutImageDialogClose="cutImageDialogVisible = false"
@cutSuccess="handleCutSuccess"/> @cutSuccess="handleCutSuccess"
@uploadImage="handleUploadImage"/>
<CutEditImageDialog <CutEditImageDialog
v-if="cutEditImageDialogVisible" v-if="cutEditImageDialogVisible"
:edit-image-url="editImageUrl" :edit-image-url="editImageUrl"
:show-cut-dialog="cutImageDialogVisible" :show-cut-dialog="cutImageDialogVisible"
@cutEditImageDialogClose="cutEditImageDialogVisible = false" @cutEditImageDialogClose="cutEditImageDialogVisible = false"
@cutEditSuccess="handleSaveImageBase64"/> @cutEditSuccess="handleSaveImageBase64"
@uploadEditImage="handleUploadImage"/>
</div> </div>
</template> </template>
...@@ -165,7 +167,7 @@ import { VuePictureCut, VuePictureCutMask, VuePictureCutMenu } from 'vue-picture ...@@ -165,7 +167,7 @@ import { VuePictureCut, VuePictureCutMask, VuePictureCutMenu } from 'vue-picture
import { getToken } from '@/utils/auth' import { getToken } from '@/utils/auth'
import SelectImageDialog from './components/selectImageDialog' import SelectImageDialog from './components/selectImageDialog'
import { listCategories } from '@/api/business/goods' import { listCategories } from '@/api/business/goods'
import { detailGoods, editGoods, saveImageBase64 } from '@/api/business/goodsNew' import { detailGoods, editGoods, saveImageBase64, saveCroppingRecord } from '@/api/business/goodsNew'
import CheckLargeImageDialog from './components/CheckLargeImageDialog' import CheckLargeImageDialog from './components/CheckLargeImageDialog'
import CutImageDialog from './components/CutImageDialog' import CutImageDialog from './components/CutImageDialog'
import CutEditImageDialog from './components/CutEditImageDialog' import CutEditImageDialog from './components/CutEditImageDialog'
...@@ -394,6 +396,11 @@ export default { ...@@ -394,6 +396,11 @@ export default {
} }
}) })
}, },
handleUploadImage(param) {
param.itemId = this.currentGoodId
saveCroppingRecord(param).then((response) => {
})
},
// 裁剪工具取消 // 裁剪工具取消
cutCancel() { cutCancel() {
this.src = '' this.src = ''
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment