图片上传功能

开箱即用

<template>
<!-- 图片上传功能 -->
	<view>
		<view class="feedback-image-box">
			<view class="feedback-image-item" v-for="(item,index) in imagelist" :key="index">
				<view class="close-icon" @click="del(index)">
					<uni-icons type="closeempty" size="18" color="#ffffff"></uni-icons>
				</view>
				<view class="image-box">
					<image :src="item.url" mode="aspectFill"></image>
				</view>
			</view>
			<view class="feedback-image-item" @click="addimage" v-if="imagelist.length<5">
				<view class="image-box">
					<uni-icons type="plusempty" size="50" color="#999999"></uni-icons>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				imagelist: []
			}
		},
		methods: {
			del(index) {
				this.imagelist.splice(index, 1)
			},
			addimage() {
				let count = 5 - this.imagelist.length
				uni.chooseImage({
					count: count,
					success: (res) => {

						const tempfilepaths = res.tempFiles

						tempfilepaths.forEach((item, index) => {
							// 处理h5多选的状况
							if (index < count) {
								this.imagelist.push({
									url: item.path,
									couldpath: item.name
								})
							}

						})
					}
				})
			},
			async submit() {
				let imagePath = []
				uni.showLoading()
				for (let i = 0; i < this.imagelist.length; i++) {
					let filePath = this.imagelist[i].url
					let couldpath = this.imagelist[i].couldpath
					filePath = await this.uploadFiles(filePath, couldpath)
					imagePath.push(filePath)
				}
				const obj = {
					content: this.content,
					feedbackImage: imagePath
				}
				this.updateFeedback(obj)
			},
			async uploadFiles(filePath, couldpath) {
				const result = await uniCloud.uploadFile({
					filePath: filePath,
					cloudPath: couldpath
				})

				return result.fileID
			},
			updateFeedback(obj) {
				this.$api.update_feedback(obj).then(res => {
					uni.hideLoading()
					uni.showToast({
						title: '提交成功'
					})
					setTimeout(() => {
						uni.switchTab({
							url: '/pages/tabbar/my/my'
						})
					}, 2000)

				}).catch(err => {
					uni.hideLoading()
					uni.showToast({
						title: '提交失败',
					
					})
				})
			}
		}
	}
	https://mall.qxtmall.top/api/user/add_comment?is_json=1&unique_id=miniappFBGt5AVhr1kPF8Bn4&user_id=126910&token=d1f8c2339b4365df14c74bd28a502bee&oauth=miniapp&is_anonymous=0&goods_rank=5&service_rank=5&deliver_rank=5&content=222222&goods_id=6398&order_id=255485&rec_id=209063&item_id=&img%5Bimg%5B0%5D%5D=https%3A%2F%2Ffiles.qxtmall.top%2Ftemp%2F20220214%2F52c75e15748b21ed89787367059283a06d5ea1df.png&img%5Bimg%5B1%5D%5D=https%3A%2F%2Ffiles.qxtmall.top%2Ftemp%2F20220214%2F326a6dd1fabd6959d8010024649c540687438a51.png
</script>

<style lang="scss">
	.feedback-image-box {
		display: flex;
		flex-wrap: wrap;
		padding: 10px;

		.feedback-image-item {
			position: relative;
			width: 33.33%;
			height: 0;
			padding-top: 33.33%;
			box-sizing: border-box;

			.close-icon {
				display: flex;
				justify-content: center;
				align-items: center;
				position: absolute;
				right: 0;
				top: 0;
				width: 22px;
				height: 22px;
				border-radius: 50%;
				background-color: #ff5a5f;
				z-index: 2;
			}

			.image-box {
				display: flex;
				justify-content: center;
				align-items: center;
				position: absolute;
				left: 5px;
				right: 5px;
				bottom: 5px;
				top: 5px;
				border: 1px #eee solid;
				overflow: hidden;

				image {
					width: 100%;
					height: 100%;
				}
			}
		}
	}
</style>

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值