소스 검색

update 上传逻辑,组件电脑端适配

linweizeng 2 년 전
부모
커밋
be823a7b3f
7개의 변경된 파일160개의 추가작업 그리고 143개의 파일을 삭제
  1. 1 1
      common/service/http.js
  2. 91 0
      common/util/upload.js
  3. 2 0
      main.js
  4. 9 66
      pages/communication/communication.vue
  5. 4 4
      pages/jiance/list/specimen.vue
  6. 19 0
      pages/jiance/order/meth.js
  7. 34 72
      pages/jiance/tousu.vue

+ 1 - 1
common/service/http.js

@@ -4,7 +4,7 @@ let apiHosp = 'http://120.78.154.31/'
 
 // let apiHosp = 'http://192.168.2.247/'
 
-// let apiHosp = 'http://172.16.40.184/'
+//let apiHosp = 'http://172.16.40.184/'
 // let apiHosp = 'http://172.16.40.182/'
 
 export default {

+ 91 - 0
common/util/upload.js

@@ -0,0 +1,91 @@
+import {
+	ACCESS_TOKEN,
+	USER_NAME,
+	USER_INFO
+} from "@/common/util/constants" // 拉取登录token,userName,userInfo
+import http from '@/common/service/http.js'
+
+function uploaditem(item) {
+	let token = uni.getStorageSync(ACCESS_TOKEN)
+	return new Promise((resolve, reject) => {
+		const path = item
+		uni.uploadFile({
+			// url: http.apiHosp + 'ibps/platform/v3/file/upload/mobile', //仅为示例,非真实的接口地址
+			url: http.apiHosp + '/ibps/platform/v3/file/upload', //仅为示例,非真实的接口地址
+			filePath: path,
+			name: 'file',
+			formData: {
+				'ext': '.jpg'
+			},
+			header: {
+				'X-Authorization-access_token': token,
+				'X-Authorization-systemid': ''
+			},
+			success: (uploadFileRes) => {
+				let data = JSON.parse(uploadFileRes.data)
+				let obj = {
+					id: data.data.id,
+					name: data.data.fileName + '.' + data.data.ext,
+					ext: data.data.ext,
+					uuid: data.data.id
+				}
+				resolve(obj)
+			}
+		})
+	})
+}
+
+function selectUpload(file) {
+	return new Promise((resolve, reject) => {
+		let list = []
+		//读取文件大小
+		var fileSize = file.size;
+		if (fileSize > 1048576) {
+			that.$message({
+				type: 'error',
+				showClose: true,
+				duration: 3000,
+				message: '文件大于1M!'
+			});
+			return
+		}
+		let that = this
+		let eList = []
+		file.tempFilePaths.forEach(item => {
+			eList.push(uploaditem(item))
+		})
+		Promise.all(eList).then((res3) => {
+			resolve(res3)
+		})
+
+	})
+}
+
+function getFilesList(ids, that = this) {
+	return new Promise((resolve, reject) => {
+		let lists = ids.split(",")
+		let params = {}
+		params.ids = lists
+		that.$http.post("/ibps/platform/v3/file/attachment/transfer", params).then(res => {
+			if (res.data.state == 200) {
+				const data = res.data.data
+				let list = []
+				lists.forEach(item => {
+					let obj = {
+						id: item,
+						name: data[item].fileName + '.' + data[item].ext,
+						ext: data[item].ext,
+						uuid: item
+					}
+					list.push(obj)
+				})
+				resolve(list)
+			}
+		})
+	})
+}
+
+export default {
+	getFilesList,
+	selectUpload
+}

+ 2 - 0
main.js

@@ -32,6 +32,7 @@ import linPopup from '@/components/lin-popup/index.vue'
 import dayjs from "dayjs" //封装dayjs
 import showToast from "@/common/util/showToast.js"
 import methCommon from "@/common/util/meth.js"
+import uploades from "@/common/util/upload.js"
 
 //ui框架
 import uView from "uview-ui";
@@ -49,6 +50,7 @@ Vue.prototype.$http = http
 Vue.prototype.$dayjs = dayjs
 Vue.prototype.$showToast = showToast
 Vue.prototype.$methCommon = methCommon
+Vue.prototype.$uploades = uploades
 Vue.component('home', home)
 Vue.component('people', people)
 Vue.component('mySelect', mySelect)

+ 9 - 66
pages/communication/communication.vue

@@ -278,52 +278,11 @@
 			},
 			// 获取上传状态
 			select(file) {
-				//读取文件大小
-				var fileSize = file.size;
-				let token = uni.getStorageSync(ACCESS_TOKEN)
-				if (fileSize > 1048576) {
-					that.$message({
-						type: 'error',
-						showClose: true,
-						duration: 3000,
-						message: '文件大于1M!'
-					});
-					return
-				}
-				let that = this
-				uni.showToast({
-					title: '上传中',
-					mask: true
+				this.$uploades.selectUpload(file).then(res => {
+					res.forEach(item => {
+						this.fuJianShangChuanArray.push(item)
+					})
 				})
-				for (let e in file.tempFilePaths) {
-					var extName = file.tempFiles[e].file.name.substring(file.tempFiles[e].file.name.lastIndexOf(
-						'.'));
-					const path = file.tempFilePaths[e];
-					uni.uploadFile({
-						// url: http.apiHosp + 'ibps/platform/v3/file/upload/mobile', //仅为示例,非真实的接口地址
-						url: http.apiHosp + '/ibps/platform/v3/file/upload', //仅为示例,非真实的接口地址
-						filePath: path,
-						name: 'file',
-						formData: {
-							'ext': '.jpg'
-						},
-						header: {
-							'X-Authorization-access_token': token,
-							'X-Authorization-systemid': ''
-						},
-						success: (uploadFileRes) => {
-							let data = JSON.parse(uploadFileRes.data)
-							let obj = {
-								id: data.data.id,
-								name: data.data.fileName + '.' + data.data.ext,
-								ext: data.data.ext,
-								uuid: file.tempFiles[e].file.uuid
-							}
-							this.fuJianShangChuanArray.push(obj)
-							uni.hideLoading()
-						}
-					});
-				}
 			},
 			// 删除
 			deleteMe(id) {
@@ -440,24 +399,8 @@
 				})
 			},
 			getFileList(ids) {
-				let lists = ids.split(",")
-				let params = {}
-				params.ids = lists
-				this.$http.post("/ibps/platform/v3/file/attachment/transfer", params).then(res => {
-					if (res.data.state == 200) {
-						const data = res.data.data
-						let list = []
-						lists.forEach(item => {
-							let obj = {
-								id: item,
-								name: data[item].fileName + '.' + data[item].ext,
-								ext: data[item].ext,
-								uuid: item
-							}
-							list.push(obj)
-						})
-						this.fuJianShangChuanArray = JSON.parse(JSON.stringify(list))
-					}
+				this.$uploades.getFilesList(ids, this).then(res => {
+					this.fuJianShangChuanArray = res
 				})
 			},
 			onSubmit() {
@@ -491,9 +434,9 @@
 					}
 				}
 				let tmpArray = []
-				for (let e in this.fuJianShangChuanArray) {
-					tmpArray.push(this.fuJianShangChuanArray[e].uploadid)
-				}
+				this.fuJianShangChuanArray.forEach((item) => {
+					tmpArray.push(item.id)
+				})
 
 				let info = uni.getStorageSync(USER_INFO);
 				let useId = info.user.id

+ 4 - 4
pages/jiance/list/specimen.vue

@@ -110,7 +110,7 @@
 						</u-button>
 					</u-form-item>
 					<u-form-item label="数量①" required>
-						<u-number-box v-model="form.shu_liang_"></u-number-box>
+						<uni-number-box v-model="form.shu_liang_"></uni-number-box>
 					</u-form-item>
 					<u-form-item label="样品规格①" required>
 						<u-input v-model="form.yang_pin_gui_ge_" />
@@ -141,7 +141,7 @@
 						</u-button>
 					</u-form-item>
 					<u-form-item label="数量②" required>
-						<u-number-box v-model="form.shu_liang_er_"> </u-number-box>
+						<uni-number-box v-model="form.shu_liang_er_"></uni-number-box>
 					</u-form-item>
 					<u-form-item label="样品规格②" required>
 						<u-input v-model="form.yang_pin_gui_ge_e" />
@@ -172,7 +172,7 @@
 						</u-button>
 					</u-form-item>
 					<u-form-item label="数量③" required>
-						<u-number-box v-model="form.shu_liang_san_"></u-number-box>
+						<uni-number-box v-model="form.shu_liang_san_"></uni-number-box>
 					</u-form-item>
 					<u-form-item label="样品规格③" required>
 						<u-input v-model="form.yang_pin_gui_ge_s" />
@@ -203,7 +203,7 @@
 						</u-button>
 					</u-form-item>
 					<u-form-item label="数量④" required>
-						<u-number-box v-model="form.shu_liang_si_"></u-number-box>
+						<uni-number-box v-model="form.shu_liang_si_"></uni-number-box>
 					</u-form-item>
 					<u-form-item label="样品规格④" required>
 						<u-input v-model="form.yang_pin_gui_si_" />

+ 19 - 0
pages/jiance/order/meth.js

@@ -322,17 +322,30 @@ export default {
 			this.getPrompt('至少填写一组样品类型信息')
 			return false
 		}
+		if (!form.showBoolean1) {
+			this.getFormNull(order.showBooleanList1, form)
+		}
 		if (form.showBoolean1 && !this.getEstimate(order.showBooleanList1, form)) {
 			return false
 		}
+
+		if (!form.showBoolean2) {
+			this.getFormNull(order.showBooleanList2, form)
+		}
 		if (form.showBoolean2 && !this.getEstimate(order.showBooleanList2, form)) {
 			return false
 		}
 
+		if (!form.showBoolean3) {
+			this.getFormNull(order.showBooleanList3, form)
+		}
 		if (form.showBoolean3 && !this.getEstimate(order.showBooleanList3, form)) {
 			return false
 		}
 
+		if (!form.showBoolean4) {
+			this.getFormNull(order.showBooleanList4, form)
+		}
 		if (form.showBoolean4 && !this.getEstimate(order.showBooleanList4, form)) {
 			return false
 		}
@@ -357,6 +370,12 @@ export default {
 		}
 		return true
 	},
+	//字段参数改成空
+	getFormNull(list, form) {
+		for (let item of list) {
+			form[item.value] = ''
+		}
+	},
 	//数据判断是否必填
 	getEstimate(list, form) {
 		for (let item of list) {

+ 34 - 72
pages/jiance/tousu.vue

@@ -62,18 +62,23 @@
 		</view>
 
 		<uni-section title="投诉内容" type="line" padding>
-			<textarea maxlength="-1" v-model="form.content" placeholder="投诉内容" :disabled="id != '' ? true : false"></textarea>
+			<textarea maxlength="-1" auto-height v-model="form.content" placeholder="投诉内容" :disabled="id != '' ? true : false"></textarea>
 		</uni-section>
 
 		<uni-section title="上传附件" type="line">
 			<view class="example-body" v-if="id == ''">
 				<uni-file-picker limit="5" file-mediatype="all" @select="select" @progress="progress" @success="success" @fail="fail" @delete="deleteMe" :auto-upload="false" ref="uploadMe"></uni-file-picker>
 			</view>
-			<view v-else>
+			<view class="u-p-b-15">
 				<view v-for="(item,index) in fuJianShangChuanArray" :key="index" style="margin: 0 10rpx;">
-					<view style="line-height: 50rpx;color: #888888" @click="uploadClick(item.id,item.fileName,item.ext)">
-						<u-icon size="30" name="file-text-fill"></u-icon>
-						{{item.fileName + '.' + item.ext}}
+					<view class="fileBox">
+						<view @click="uploadClick(item.id,item.name)">
+							<u-icon size="30" name="file-text-fill"></u-icon>
+							{{item.name}}
+						</view>
+						<view style="width: 50rpx;" @click="deleteMe(item.id)" v-if="(type != 1 && type != 2)">
+							<u-icon size="26" name="close"></u-icon>
+						</view>
 					</view>
 				</view>
 			</view>
@@ -398,76 +403,21 @@
 				})
 			},
 			getFileList(ids) {
-				let lists = ids.split(",")
-				let params = {}
-				params.ids = lists
-				this.$http.post("/ibps/platform/v3/file/attachment/transfer", params).then(res => {
-					if (res.data.state == 200) {
-						const data = res.data.data
-						lists.forEach(item => {
-							let obj = {
-								id: item,
-								fileName: data[item].fileName,
-								ext: data[item].ext
-							}
-							this.fuJianShangChuanArray.push(obj)
-						})
-					}
+				this.$uploades.getFilesList(ids, this).then(res => {
+					this.fuJianShangChuanArray = res
 				})
 			},
 			// 获取上传状态
 			select(file) {
-				//读取文件大小
-				var fileSize = file.size;
-				let token = uni.getStorageSync(ACCESS_TOKEN)
-				if (fileSize > 1048576) {
-					that.$message({
-						type: 'error',
-						showClose: true,
-						duration: 3000,
-						message: '文件大于1M!'
-					});
-					return
-				}
-				let that = this
-				uni.showToast({
-					title: '上传中',
-					mask: true
+				this.$uploades.selectUpload(file).then(res => {
+					res.forEach(item => {
+						this.fuJianShangChuanArray.push(item)
+					})
 				})
-				for (let e in file.tempFilePaths) {
-					var extName = file.tempFiles[e].file.name.substring(file.tempFiles[e].file.name.lastIndexOf(
-						'.'));
-					const path = file.tempFilePaths[e];
-					uni.uploadFile({
-						// url: http.apiHosp + 'ibps/platform/v3/file/upload/mobile', //仅为示例,非真实的接口地址
-						url: http.apiHosp + '/ibps/platform/v3/file/upload', //仅为示例,非真实的接口地址
-						filePath: path,
-						name: 'file',
-						formData: {
-							'ext': '.jpg'
-						},
-						header: {
-							'X-Authorization-access_token': token,
-							'X-Authorization-systemid': ''
-						},
-						success: (uploadFileRes) => {
-							let data = JSON.parse(uploadFileRes.data)
-							that.fuJianShangChuanArray.push({
-								fileid: file.tempFiles[e].file.uuid,
-								uploadid: data.data.id
-							})
-							uni.hideLoading()
-						}
-					});
-				}
 			},
 			// 删除
-			deleteMe(file) {
-				for (let e in this.fuJianShangChuanArray) {
-					if (this.fuJianShangChuanArray[e].fileid == file.tempFile.uuid) {
-						this.fuJianShangChuanArray.splice(e, 1)
-					}
-				}
+			deleteMe(id) {
+				this.fuJianShangChuanArray = this.fuJianShangChuanArray.filter(item => item.id !== id)
 			},
 			// 获取上传进度
 			progress(e) {},
@@ -476,13 +426,13 @@
 			// 上传失败
 			fail(e) {},
 			onSubmit() {
-				if (this.form.guanLianYangPin) {
+				if (!this.form.guanLianYangPin) {
 					return this.$methCommon.getPrompt('请选择样品')
 				}
 				let tmpArray = []
-				for (let e in this.fuJianShangChuanArray) {
-					tmpArray.push(this.fuJianShangChuanArray[e].uploadid)
-				}
+				this.fuJianShangChuanArray.forEach((item) => {
+					tmpArray.push(item.id)
+				})
 
 				let info = uni.getStorageSync(USER_INFO);
 				let useId = info.user.id
@@ -800,4 +750,16 @@
 		font-size: 14px;
 		color: #333;
 	}
+
+	.fileBox {
+		line-height: 50rpx;
+		color: #888888;
+		display: flex;
+		align-items: center;
+		justify-content: space-between;
+		border: 1rpx solid #DDDDDD;
+		border-radius: 8rpx;
+		padding: 5rpx;
+		margin-top: 10rpx;
+	}
 </style>