sczl.vue 2.83 KB
<template>
	<view class="main">
		<view class="tp">
			<view class="item" @click="scwj">
				<image src="../static/wj.png" mode=""></image>
				<view style="margin-top: 10rpx;">上传文件</view>
			</view>
		</view>
		<view class="ws">
			<view class="ws_item" v-for="(item,index) in wjlist" :key="index">
				<view style="						width:80%;
						display: -webkit-box;
						-webkit-box-orient: vertical;
						-webkit-line-clamp: 1;
						overflow: hidden;">{{item.name}}</view>
				<image @click="delscwj(index)" class="i2" src="../static/sc.png" mode=""></image>
			</view>

		</view>
	</view>
</template>

<script>
	import BASE_URL from "@/common/config.js"
	export default {
		data() {
			return {
				BASE_URL,
				wjlist: [],
				fileContent: null,
				task: null
			}
		},
		watch: {
			wjlist: {
				deep: true,
				handler() {
					console.log('wjlist')
					console.log(this.wjlist)
					this.$emit('onchangfileJsonfile',this.wjlist);
				}
			},
		},
		methods: {
			uploadImg(url) {
				return new Promise((r, e) => {
					uni.uploadFile({
						url: this.BASE_URL + "/common/upload",
						filePath: url,
						name: "file",
						success: (d) => r(d)
					})
				})
			},
			scwj() {
				console.log("上传文件");
				var that = this
				uni.chooseMessageFile({
					success: (res) => {
						console.log("上传文件", res);
						that.addfile(res.tempFiles)

					}
				})
			},
			async addfile(e) {
				console.log(e)
				for (let i = 0; i < e.length; i++) {
					var res = await this.uploadImg(e[i].path)
					console.log(res)
					res = JSON.parse(res.data)
					this.wjlist.push({
						name: res.newFileName,
						fileId: res.newFileName,
						url: this.BASE_URL + res.fileName
					})

				}
			},
			delscwj(index) {
				this.wjlist.splice(index, 1)
			}
		}
	}
</script>

<style scoped lang="scss">
	.main {
		width: 100%;
		padding: 0rpx !important;
		background-color: #fff !important;
		margin-top: 20rpx;

		.tp {
			display: flex;
			justify-content: space-between;
			width: 100%;

			.item {
				padding: 20rpx;
				border: 1px dotted #D1D6E6;
				border-radius: 10rpx;
				width: 42%;
				display: flex;
				flex-direction: column;
				align-items: center;
				justify-content: center;
				color: #9EA5BB;
				font-size: 20rpx;

				image {
					width: 40rpx;
					height: 40rpx;
				}
			}
		}

		.ws {
			margin-top: 30rpx;

			.ws_item {
				background-color: #F9FAFF;
				border: 1px solid #EAEDF5;
				border-radius: 10rpx;
				display: flex;
				justify-content: space-between;
				align-items: center;
				padding: 15rpx;
				margin-bottom: 15rpx;
				font-size: 25rpx;

				.i2 {
					// position: absolute;
					height: 30rpx;
					width: 30rpx;
					// top: -5rpx;
					// left: 90%;
				}
			}
		}
	}
</style>