From 46a58a1644b5f65b49283c8159f1fc1f5d3b44d3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BC=A0=E7=A3=8A?= <1633537611@qq.com> Date: Fri, 15 Sep 2023 15:47:48 +0800 Subject: [PATCH] =?UTF-8?q?=E8=A1=A5=E5=85=85crop=E5=B1=9E=E6=80=A7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pages/API/choose-image/choose-image.uvue | 120 +++++++++++++++++++++-- 1 file changed, 110 insertions(+), 10 deletions(-) diff --git a/pages/API/choose-image/choose-image.uvue b/pages/API/choose-image/choose-image.uvue index d825b398..2f34e0c9 100644 --- a/pages/API/choose-image/choose-image.uvue +++ b/pages/API/choose-image/choose-image.uvue @@ -1,7 +1,7 @@ @@ -77,7 +119,12 @@ sizeTypeIndex: 2, sizeType: ['压缩', '原图', '压缩或原图'], countIndex: 8, - count: [1, 2, 3, 4, 5, 6, 7, 8, 9] + count: [1, 2, 3, 4, 5, 6, 7, 8, 9], + isCrop: false, + cropPercent: 80, + cropWidth: 100, + cropHeight: 100, + cropResize: false } }, onUnload() { @@ -89,13 +136,52 @@ this.countIndex = 8 }, methods: { + cropHeightConfim(e : InputConfirmEvent) { + let value = parseInt(e.detail.value) + if (value > 0) { + this.cropHeight = value + } else { + uni.showToast({ + position: "bottom", + title: "裁剪高度需要大于0" + }) + } + }, + cropWidthConfim(e : InputConfirmEvent) { + let value = parseInt(e.detail.value) + if (value > 0) { + this.cropWidth = value + } else { + uni.showToast({ + position: "bottom", + title: "裁剪宽度需要大于0" + }) + } + }, + cropPercentConfim(e : InputConfirmEvent) { + let value = parseInt(e.detail.value) + if (value > 0 && value <= 100) { + this.cropPercent = value + } else { + uni.showToast({ + position: "bottom", + title: "请输入0~100之间的值" + }) + } + }, + cropResizeChange(e : SwitchChangeEvent) { + this.cropResize = e.detail.value + }, + switchCrop(e : SwitchChangeEvent) { + this.isCrop = e.detail.value + }, removeImage(index : number) { this.imageList.splice(index, 1) }, chooseImageSource() { uni.showActionSheet({ itemList: ['拍照', '相册', '拍照或相册'], - success(e){ + success(e) { this.sourceTypeIndex = e.tapIndex! } }) @@ -103,23 +189,24 @@ chooseImageType() { uni.showActionSheet({ itemList: ['压缩', '原图', '压缩或原图'], - success(e){ + success(e) { this.sizeTypeIndex = e.tapIndex! } }) }, - chooseImageCount(event: InputConfirmEvent) { + chooseImageCount(event : InputConfirmEvent) { let count = parseInt(event.detail.value) - 1 - if(count <=0) { + if (count < 0) { uni.showToast({ - position:"bottom", - title:"图片数量应该大于0" + position: "bottom", + title: "图片数量应该大于0" }) return } this.countIndex = count }, chooseImage: function () { + // var cropOption:ChooseImageCropOptions|null = this.isCrop ? null : new ChooseImageCropOptions( ) if (this.imageList.length >= 9) { uni.showToast({ position: "bottom", @@ -130,6 +217,7 @@ uni.chooseImage({ sourceType: sourceTypeArray[this.sourceTypeIndex], sizeType: sizeTypeArray[this.sizeTypeIndex], + crop: this.isCrop ? { "quality": this.cropPercent, "width": this.cropWidth, "height": this.cropHeight, "resize": this.cropResize } as ChooseImageCropOptions : null, count: this.imageList.length + this.count[this.countIndex] > 9 ? 9 - this.imageList.length : this.count[this.countIndex], success: (res) => { this.imageList = this.imageList.concat(res.tempFilePaths); @@ -189,4 +277,16 @@ border-radius: 25rpx; background-color: rgba(200, 200, 200, 0.8); } + + .item_width { + width: 260rpx; + } + + .crop-option { + border-top-color: lightgray; + border-width: 1rpx; + padding: 20rpx; + transition: height; + transition-duration: 300; + } -- GitLab