dedsudiyu 1 week ago
parent
commit
60bef66f00
1 changed files with 43 additions and 3 deletions
  1. 43 3
      pages_basics/views/trainingSignIn.vue

+ 43 - 3
pages_basics/views/trainingSignIn.vue

@@ -118,7 +118,7 @@
 			</view>
 
 			<!-- 培训证明上传区域(学员端 + 进行中) -->
-			<view v-if="userType == 2 && !upType" class="upload-section">
+			<view v-if="userType == 2 && !upType && proofRequired" class="upload-section">
 				<view class="upload-header">
 					<text class="upload-icon">🖼️</text>
 					<text class="upload-title">上传培训证明</text>
@@ -127,7 +127,7 @@
 				<!-- 已选图片预览 -->
 				<view class="upload-preview">
 					<view v-for="(img, idx) in previewImages" :key="idx" class="preview-item">
-						<image class="preview-img" :src="img" mode="aspectFill" @click="previewImage(img)"></image>
+						<image class="preview-img" :src="baseUrl+img" mode="aspectFill" @click="previewImage(img)"></image>
 						<view class="preview-del" @click.stop="removeImage(idx)">×</view>
 					</view>
 				</view>
@@ -217,6 +217,7 @@
 </template>
 
 <script>
+	import { config } from '@/api/request/config.js'
 	import {
 		examElTrainingTaskProgressDetail,examElTrainingTaskSignInList,
 		examUserTrainingDetail,examUserTrainingSignIn,examUserTrainingProofUpload,
@@ -224,6 +225,7 @@
 	export default {
 		data() {
 			return {
+				baseUrl:config.base_url,
 				id:'',
 				userType: 0, // 1老师 2学生(后续自行调试切换)
 				detail: {},
@@ -248,6 +250,8 @@
 				signType:false,
 				//上传状态
 				upType:false,
+				//开启签到上传状态
+				proofRequired:false,
 			}
 		},
 		computed: {
@@ -347,6 +351,7 @@
 				if (data.code == 200) {
 					this.$set(this,'signType',data.data.signStatus==1?true:false);
 					this.$set(this,'upType',data.data.proofImages[0]?true:false);
+					this.$set(this,'proofRequired',data.data.proofRequired==1?true:false);
 					this.$set(this,'previewImages',data.data.proofImages);
 					
 				}
@@ -450,6 +455,7 @@
 			},
 			// 选择图片
 			chooseImage() {
+				let self = this;
 				const remaining = 5 - this.previewImages.length
 				if (remaining <= 0) {
 					uni.showToast({ title: '最多上传 5 张图片', icon: 'none' })
@@ -466,10 +472,44 @@
 							uni.showToast({ title: '图片大小不能超过 10MB', icon: 'none' })
 							return
 						}
-						this.previewImages = [...this.previewImages, ...res.tempFilePaths]
+						let tempFilePaths = res.tempFilePaths[0];
+						self.uploadImg(tempFilePaths);
 					}
 				})
 			},
+			async uploadImg(tempFilePaths){
+				let self = this;
+				uni.showLoading({
+						title: '上传中',
+						mask: true
+				});
+				uni.uploadFile({
+						url: config.base_url + '/system/file/upload', //仅为示例,非真实的接口地址
+						header:{'Authorization':uni.getStorageSync('token')},
+						filePath: tempFilePaths,
+						name: 'file',
+						formData: {
+							'user': 'test'
+						},
+						success: (uploadFileRes) => {
+							let res = JSON.parse(uploadFileRes.data);
+							if(res.code == 200){
+								this.previewImages.push(res.data.url);
+							}else{
+								uni.showToast({
+									title: res.msg,
+									icon:"none",
+									mask:true,
+									duration: 2000
+								});
+							}
+						},
+						fail: err => {},
+						complete: () => {
+								uni.hideLoading()
+						}
+				});
+			},
 			// 移除预览图
 			removeImage(idx) {
 				this.previewImages.splice(idx, 1)