| | |
| | | <view class="upload-buttons"> |
| | | <u-button |
| | | type="primary" |
| | | @click="chooseImage" |
| | | @click="chooseMedia('image')" |
| | | :loading="uploading" |
| | | :disabled="getCurrentFiles().length >= uploadConfig.limit" |
| | | :customStyle="{ marginRight: '10px', flex: 1 }" |
| | |
| | | </u-button> |
| | | <u-button |
| | | type="success" |
| | | @click="chooseVideo" |
| | | @click="chooseMedia('video')" |
| | | :loading="uploading" |
| | | :disabled="getCurrentFiles().length >= uploadConfig.limit" |
| | | :customStyle="{ flex: 1 }" |
| | | > |
| | | <u-icon name="video" size="18" color="#fff" style="margin-right: 5px;"></u-icon> |
| | | <uni-icons type="videocam" name="videocam" size="18" color="#fff" style="margin-right: 5px;"></uni-icons> |
| | | {{ uploading ? '上传中...' : '拍视频' }} |
| | | </u-button> |
| | | </view> |
| | |
| | | > |
| | | <view class="file-preview-container"> |
| | | <image |
| | | v-if="file.type === 'image'" |
| | | :src="file.url || file.tempFilePath || file.path" |
| | | v-if="file?.path?.fileType === 'image'" |
| | | :src="file?.url || file?.tempFilePath?.tempFilePath || file?.path?.tempFilePath" |
| | | class="file-preview" |
| | | mode="aspectFill" |
| | | /> |
| | | <view v-else class="video-preview"> |
| | | <u-icon name="video" size="24" color="#409eff"></u-icon> |
| | | <uni-icons type="videocam" name="videocam" size="18" color="#fff" style="margin-right: 5px;"></uni-icons> |
| | | <text class="video-text">视频</text> |
| | | </view> |
| | | |
| | |
| | | if (process.env.VUE_APP_BASE_API) { |
| | | baseUrl = process.env.VUE_APP_BASE_API; |
| | | } else if (process.env.NODE_ENV === 'development') { |
| | | baseUrl = 'http://192.168.1.147:9036'; |
| | | baseUrl = 'http://114.132.189.42:9068'; |
| | | } else { |
| | | baseUrl = 'http://192.168.1.147:9036'; |
| | | baseUrl = 'http://114.132.189.42:9068'; |
| | | } |
| | | |
| | | return baseUrl + uploadConfig.action; |
| | |
| | | |
| | | // 获取当前分类的文件列表 |
| | | const getCurrentFiles = () => { |
| | | console.log('currentUploadType',currentUploadType.value) |
| | | switch (currentUploadType.value) { |
| | | case 'before': |
| | | console.log('beforeModelValue',beforeModelValue.value) |
| | | return beforeModelValue.value |
| | | case 'after': |
| | | return afterModelValue.value |
| | |
| | | }) |
| | | } |
| | | |
| | | // 使用相机 |
| | | const chooseMedia = (type) => { |
| | | let mediaPamaes={ |
| | | count: 1, |
| | | mediaType:[type||'image'], |
| | | sizeType: ['compressed', 'original'], |
| | | sourceType: ['camera'], |
| | | } |
| | | uni.chooseMedia({ |
| | | ...mediaPamaes, |
| | | success: (res) => { |
| | | try { |
| | | if (!res.tempFiles || res.tempFiles.length === 0) { |
| | | throw new Error('未获取到图片文件'); |
| | | } |
| | | |
| | | const tempFilePath = res.tempFiles[0]; |
| | | const tempFile = res.tempFiles && res.tempFiles[0] ? res.tempFiles[0] : {}; |
| | | |
| | | const file = { |
| | | tempFilePath: tempFilePath, |
| | | path: tempFilePath, // 保持兼容性 |
| | | type: 'image', |
| | | name: `photo_${Date.now()}.jpg`, |
| | | size: tempFile.size || 0, |
| | | createTime: new Date().getTime(), |
| | | uid: Date.now() + Math.random() |
| | | }; |
| | | |
| | | handleBeforeUpload(file); |
| | | } catch (error) { |
| | | console.error('处理拍照结果失败:', error); |
| | | uni.showToast({ |
| | | title: '处理图片失败', |
| | | icon: 'error' |
| | | }); |
| | | } |
| | | }, |
| | | fail: (err) => { |
| | | console.error('拍照失败:', err); |
| | | uni.showToast({ |
| | | title: '拍照失败: ' + (err.errMsg || '未知错误'), |
| | | icon: 'error' |
| | | }); |
| | | } |
| | | }) |
| | | } |
| | | |
| | | // 拍照 |
| | | const chooseImage = () => { |
| | | if (uploadFiles.value.length >= uploadConfig.limit) { |
| | |
| | | return; |
| | | } |
| | | |
| | | uni.chooseImage({ |
| | | uni.chooseMedia({ |
| | | count: 1, |
| | | mediaType:['image', 'video'], |
| | | sizeType: ['compressed', 'original'], |
| | | sourceType: ['camera'], |
| | | success: (res) => { |
| | | try { |
| | | if (!res.tempFilePaths || res.tempFilePaths.length === 0) { |
| | | if (!res.tempFiles || res.tempFiles.length === 0) { |
| | | throw new Error('未获取到图片文件'); |
| | | } |
| | | |
| | | const tempFilePath = res.tempFilePaths[0]; |
| | | const tempFilePath = res.tempFiles[0]; |
| | | const tempFile = res.tempFiles && res.tempFiles[0] ? res.tempFiles[0] : {}; |
| | | |
| | | const file = { |
| | |
| | | number.value++; // 增加上传计数 |
| | | |
| | | // 确保文件路径正确 |
| | | const filePath = file.tempFilePath || file.path; |
| | | const filePath = file.tempFilePath?.tempFilePath || file.path?.tempFilePath||''; |
| | | if (!filePath) { |
| | | handleUploadError('文件路径不存在'); |
| | | return; |
| | |
| | | 'Authorization': `Bearer ${token}` |
| | | } |
| | | }; |
| | | |
| | | console.log('uploadParams',uploadParams) |
| | | const uploadTask = uni.uploadFile({ |
| | | ...uploadParams, |
| | | success: (res) => { |
| | |
| | | |
| | | // 上传成功回调 |
| | | const handleUploadSuccess = (res, file) => { |
| | | console.log(res,file) |
| | | if (res.code === 200 && res.data && Array.isArray(res.data) && res.data.length > 0) { |
| | | const uploadedFile = res.data[0]; |
| | | |