修改拍照上传逻辑,避免平板不可以调用照相机
This commit is contained in:
@ -376,11 +376,11 @@
|
||||
|
||||
|
||||
<el-dialog v-model="dialogVisibleImage" append-to-body width="50%"><img style="width: 100%" :src="dialogImageUrl" alt="Preview Image" /></el-dialog>
|
||||
<el-dialog v-model="cameraDialogVisible" title="拍照上传" width="500px" append-to-body destroy-on-close>
|
||||
<el-dialog v-model="cameraDialogVisible" title="拍照上传" width="500px" append-to-body destroy-on-close :close-on-click-modal="false">
|
||||
<WebRtcCamera
|
||||
ref="cameraRef"
|
||||
@confirm="handleCameraConfirm"
|
||||
@cancel="cameraDialogVisible = false"
|
||||
ref="cameraRef"
|
||||
@photo-submit="handleCameraConfirm"
|
||||
@cancel="cameraDialogVisible = false"
|
||||
/>
|
||||
</el-dialog>
|
||||
|
||||
@ -402,7 +402,8 @@
|
||||
<script setup lang="ts">
|
||||
import {ref, reactive, onMounted, watch} from 'vue'
|
||||
import {Plus, Setting, Refresh, Search, Lock, Box, House, InfoFilled, Link, Printer, Camera, Delete, Picture} from '@element-plus/icons-vue'
|
||||
import {ElMessage, ElMessageBox} from 'element-plus'
|
||||
// 修改:引入 ElLoading
|
||||
import {ElMessage, ElMessageBox, ElLoading} from 'element-plus'
|
||||
import dayjs from 'dayjs'
|
||||
import {
|
||||
getBuyList,
|
||||
@ -790,40 +791,59 @@ const triggerCamera = (field: 'arrival_photo' | 'inspection_report') => {
|
||||
currentCameraField.value = field;
|
||||
cameraDialogVisible.value = true;
|
||||
}
|
||||
|
||||
// ----------------------------------------------------
|
||||
// 【修复核心】:处理拍照上传
|
||||
// ----------------------------------------------------
|
||||
const handleCameraConfirm = async (file: File) => {
|
||||
console.log('✅ 父组件收到照片:', file.name, file.size)
|
||||
|
||||
if (!beforeAvatarUpload(file)) {
|
||||
cameraDialogVisible.value = false;
|
||||
return;
|
||||
return
|
||||
}
|
||||
const formData = new FormData();
|
||||
formData.append('file', file);
|
||||
const loadingMsg = ElMessage.loading({ message: '照片上传中...', duration: 0 });
|
||||
let success = false;
|
||||
|
||||
// 修复点:使用 ElLoading.service 替代报错的 ElMessage.loading
|
||||
const loadingInstance = ElLoading.service({
|
||||
lock: true,
|
||||
text: '照片上传中,请稍候...',
|
||||
background: 'rgba(0, 0, 0, 0.7)',
|
||||
})
|
||||
|
||||
try {
|
||||
const res: any = await uploadFile(formData);
|
||||
const formData = new FormData()
|
||||
formData.append('file', file)
|
||||
|
||||
console.log('🚀 开始上传...')
|
||||
const res: any = await uploadFile(formData)
|
||||
console.log('📡 上传结果:', res)
|
||||
|
||||
if (res.code === 200) {
|
||||
const newUrl = res.data.url;
|
||||
const field = currentCameraField.value;
|
||||
form[field].push(newUrl);
|
||||
const newUrl = res.data.url
|
||||
const field = currentCameraField.value // 'arrival_photo' 或 'inspection_report'
|
||||
|
||||
// 更新表单数据
|
||||
form[field].push(newUrl)
|
||||
|
||||
// 更新文件展示列表
|
||||
if (field === 'arrival_photo') {
|
||||
arrivalFileList.value.push({ name: newUrl.split('/').pop(), url: getImageUrl(newUrl) });
|
||||
arrivalFileList.value.push({ name: newUrl.split('/').pop(), url: getImageUrl(newUrl) })
|
||||
} else if (field === 'inspection_report') {
|
||||
reportFileList.value.push({ name: newUrl.split('/').pop(), url: getImageUrl(newUrl) });
|
||||
reportFileList.value.push({ name: newUrl.split('/').pop(), url: getImageUrl(newUrl) })
|
||||
}
|
||||
ElMessage.success('拍照上传成功');
|
||||
success = true;
|
||||
|
||||
ElMessage.success('拍照上传成功')
|
||||
cameraDialogVisible.value = false // 成功才关闭弹窗
|
||||
} else {
|
||||
ElMessage.error(res.msg || '上传失败');
|
||||
ElMessage.error(res.msg || '上传失败')
|
||||
}
|
||||
} catch (e) {
|
||||
ElMessage.error('网络错误,上传失败');
|
||||
} catch (e: any) {
|
||||
console.error('上传异常:', e)
|
||||
ElMessage.error('网络错误,上传失败')
|
||||
} finally {
|
||||
loadingMsg.close();
|
||||
if (success) {
|
||||
cameraDialogVisible.value = false;
|
||||
}
|
||||
loadingInstance.close() // 关闭加载状态
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
const handleDelete = async (row: any) => { try { await deleteBuyInbound(row.id); ElMessage.success('删除成功'); fetchData() } catch (e) { ElMessage.error('删除失败') } }
|
||||
const handlePrint = async (row: any) => {
|
||||
printVisible.value = true; printLoading.value = true; previewUrl.value = ''
|
||||
@ -843,7 +863,6 @@ onMounted(() => fetchData())
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
/* 样式部分保持不变,直接复用原有代码 */
|
||||
.buy-module { background: #f5f7fa; padding: 20px; min-height: 100vh; }
|
||||
.header-tools { display: flex; justify-content: space-between; align-items: center; margin-bottom: 20px; background: #fff; padding: 15px 20px; border-radius: 8px; box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.05); }
|
||||
.left-tools { display: flex; gap: 10px; align-items: center; flex: 1; }
|
||||
@ -898,4 +917,4 @@ onMounted(() => fetchData())
|
||||
.camera-card:hover { border-color: #409EFF; color: #409EFF; }
|
||||
.camera-card .text { font-size: 12px; margin-top: 5px; }
|
||||
.camera-card .el-icon { font-size: 24px; }
|
||||
</style>
|
||||
</style>
|
||||
Reference in New Issue
Block a user