diff --git a/pages/API/choose-image/choose-image.uvue b/pages/API/choose-image/choose-image.uvue index d825b3983285ee1eb1a83459fa923c9453345f73..2f34e0c9159cf69906efb836837dd2ceca841827 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; + }