收藏
回答

chooseMedia走失败回调

问题类型 API/组件名称 微信版本 基础库版本
Bug chooseMedia 8.0.72 3.16.0

addImg(index) {
			this.$refs.addImgDaw.close()
			const { fileList, fileLength, autoSave } = this
			this.$emit('addImgPopupChange', true)
			wx.chooseMedia({
				count: fileLength - fileList.length,
				mediaType: [this.mediaType],
				sourceType: index === 0 ? ['camera'] : ['album'],
				success: ({ tempFiles }) => {
					if (this.mediaType === 'image') {
						const imgList = []
						const exceedSizeList = []
						// 判断图片是否过大
						tempFiles.forEach((e, i) => {
							if (e.size / (1024 * 1024) <= 5) imgList.push(e.tempFilePath)
							else exceedSizeList.push(i + 1)
						})
						if (exceedSizeList.length > 0) {
							this.$showToast(
								'选择的第' + exceedSizeList.join(',') + '张图片的大小超过5M,不能上传!',
							)
							return
						}
						if (!autoSave) {
							this.$emit('addImg', imgList)
							return
						}
						this.ossFileUpload(imgList).then((res) => {
							this.$emit('addImg', res)
						})
					} else {
						uni.showLoading({
							mask: true,
							title: '上传中...',
						})
						const fileList = tempFiles.map((item) => item.tempFilePath)
						uni.hideLoading()
						this.$emit('addImg', fileList)
					}
				},
				complete: () => {
					this.$emit('addImgPopupChange', false)
				},
				fail: (err) => {
					errorLog.error('chooseMedia失败', err)
				}
			})
		},
回答关注问题邀请回答
收藏

1 个回答

  • 智能回答 智能回答 本次回答由AI生成
    05-27
    有用
    回复
登录 后发表内容