| | |
| | | <template> |
| | | <view class="inspection-upload-page"> |
| | | <!-- 页面头部 --> |
| | | <PageHeader title="巡检上传" @back="goBack"/> |
| | | |
| | | <PageHeader title="设备巡检" |
| | | @back="goBack" /> |
| | | <!-- 数据列表 --> |
| | | <view class="table-section"> |
| | | <!-- 生产巡检列表 --> |
| | | <view class="task-list"> |
| | | <view |
| | | v-for="(item, index) in taskTableData" |
| | | :key="index" |
| | | class="task-item" |
| | | @click="handleAdd(item)" |
| | | > |
| | | <view v-for="(item, index) in taskTableData" |
| | | :key="index" |
| | | class="task-item"> |
| | | <view class="task-header"> |
| | | <view class="task-info"> |
| | | <text class="task-name">{{ item.taskName }}</text> |
| | | <text class="task-location">{{ item.inspectionLocation }}</text> |
| | | </view> |
| | | <view class="task-actions"> |
| | | <u-button |
| | | type="primary" |
| | | size="small" |
| | | @click.stop="handleAdd(item)" |
| | | :customStyle="{ |
| | | borderRadius: '15px', |
| | | height: '30px', |
| | | fontSize: '12px' |
| | | }" |
| | | > |
| | | 上传 |
| | | <!-- <u-button type="primary" |
| | | size="small" |
| | | @click.stop="startScanForTask(item)" |
| | | :customStyle="{ |
| | | borderRadius: '15px', |
| | | height: '30px', |
| | | fontSize: '12px', |
| | | marginRight: '8px' |
| | | }"> |
| | | 扫码上传 |
| | | </u-button> --> |
| | | <u-button type="primary" |
| | | size="small" |
| | | @click.stop="startUploadForTask(item)" |
| | | :customStyle="{ |
| | | borderRadius: '15px', |
| | | height: '30px', |
| | | fontSize: '12px', |
| | | marginRight: '8px' |
| | | }"> |
| | | 图片上传 |
| | | </u-button> |
| | | <u-button |
| | | type="info" |
| | | size="small" |
| | | @click.stop="startScanForTask(item)" |
| | | :customStyle="{ |
| | | borderRadius: '15px', |
| | | height: '30px', |
| | | fontSize: '12px' |
| | | }" |
| | | > |
| | | 扫码 |
| | | <u-button type="success" |
| | | size="small" |
| | | @click.stop="viewAttachments(item)" |
| | | :customStyle="{ |
| | | borderRadius: '15px', |
| | | height: '30px', |
| | | fontSize: '12px' |
| | | }"> |
| | | 查看附件 |
| | | </u-button> |
| | | </view> |
| | | </view> |
| | | <view class="task-details"> |
| | | <view class="detail-item"> |
| | | <text class="detail-label">任务ID</text> |
| | | <text class="detail-value">{{ item.taskId || item.id }}</text> |
| | | </view> |
| | | <view class="detail-item"> |
| | | <text class="detail-label">巡检项目</text> |
| | | <text class="detail-value">{{ item.inspectionProject || '无' }}</text> |
| | | </view> |
| | | <view class="detail-item"> |
| | | <text class="detail-label">备注</text> |
| | | <text class="detail-value">{{ item.remarks || '无' }}</text> |
| | |
| | | <text class="detail-label">执行人</text> |
| | | <text class="detail-value">{{ item.inspector }}</text> |
| | | </view> |
| | | <view class="detail-item"> |
| | | <text class="detail-label">任务下发日期</text> |
| | | <text class="detail-value">{{ item.dateStr }}</text> |
| | | </view> |
| | | <view class="detail-item"> |
| | | <text class="detail-label">巡检状态</text> |
| | | <view class="detail-value"> |
| | | <uni-tag v-if="item.fileStatus==2" |
| | | text="已完成" |
| | | size="small" |
| | | type="success" |
| | | inverted></uni-tag> |
| | | <uni-tag v-else-if="item.fileStatus==1" |
| | | text="巡检中" |
| | | size="small" |
| | | type="primary" |
| | | inverted></uni-tag> |
| | | <uni-tag v-else |
| | | text="未巡检" |
| | | size="small" |
| | | type="warning" |
| | | inverted></uni-tag> |
| | | </view> |
| | | </view> |
| | | </view> |
| | | </view> |
| | | <uni-load-more :status="loadMoreStatus"></uni-load-more> |
| | | </view> |
| | | |
| | | <!-- 空状态 --> |
| | | <view v-if="taskTableData.length === 0" class="no-data"> |
| | | <view v-if="taskTableData?.length === 0" |
| | | class="no-data"> |
| | | <text>暂无数据</text> |
| | | </view> |
| | | </view> |
| | | |
| | | <!-- 扫码区域 - 全局弹窗 --> |
| | | <view v-if="isScanning" class="qr-scan-overlay"> |
| | | <view class="qr-scan-container"> |
| | | <view class="scan-header"> |
| | | <text class="scan-title">扫描二维码</text> |
| | | <u-button |
| | | type="error" |
| | | size="small" |
| | | @click.stop="stopScan" |
| | | :customStyle="{ |
| | | borderRadius: '15px', |
| | | height: '30px', |
| | | fontSize: '12px' |
| | | }" |
| | | > |
| | | 关闭 |
| | | </u-button> |
| | | <!-- 视频预览弹窗 --> |
| | | <view v-if="showVideoDialog" |
| | | class="video-modal-overlay" |
| | | @click="closeVideoPreview"> |
| | | <view class="video-modal-container" |
| | | @click.stop> |
| | | <view class="video-modal-header"> |
| | | <text class="video-modal-title">{{ currentVideoFile?.originalFilename || '视频预览' }}</text> |
| | | <view class="close-btn-video" |
| | | @click="closeVideoPreview"> |
| | | <u-icon name="close" |
| | | size="16" |
| | | color="#fff"></u-icon> |
| | | </view> |
| | | </view> |
| | | <camera |
| | | class="qr-camera" |
| | | device-position="back" |
| | | flash="off" |
| | | @scancode="handleScanCode" |
| | | @error="handleCameraError" |
| | | ></camera> |
| | | <view class="scan-frame-wrapper"> |
| | | <view class="scan-frame"></view> |
| | | <view class="scan-tip">请将二维码放入框内</view> |
| | | <view class="video-modal-body"> |
| | | <video v-if="currentVideoFile" |
| | | :src="currentVideoFile.url || currentVideoFile.downloadUrl" |
| | | class="video-player" |
| | | controls |
| | | autoplay |
| | | @error="handleVideoError"></video> |
| | | </view> |
| | | <u-alert |
| | | v-if="cameraError" |
| | | :title="cameraError" |
| | | type="error" |
| | | :showIcon="true" |
| | | :closable="true" |
| | | @close="cameraError = ''" |
| | | :customStyle="{ |
| | | margin: '10px 0' |
| | | }" |
| | | ></u-alert> |
| | | </view> |
| | | </view> |
| | | |
| | | <!-- 弹窗组件 --> |
| | | <form-dia ref="formDia" @closeDia="handleQuery"></form-dia> |
| | | </view> |
| | | </template> |
| | | |
| | | <script setup> |
| | | import { onMounted, onUnmounted, ref, nextTick } from 'vue' |
| | | import { onShow } from '@dcloudio/uni-app' |
| | | import PageHeader from '@/components/PageHeader.vue' |
| | | import FormDia from './components/formDia.vue' |
| | | import { getLedgerById } from '@/api/equipmentManagement/ledger.js' |
| | | import {inspectionTaskList} from "@/api/inspectionManagement"; |
| | | import { onMounted, onUnmounted, ref, nextTick, computed, reactive } from "vue"; |
| | | import { onShow, onReachBottom, onPullDownRefresh } from "@dcloudio/uni-app"; |
| | | import PageHeader from "@/components/PageHeader.vue"; |
| | | import { getLedgerById } from "@/api/equipmentManagement/ledger.js"; |
| | | import { |
| | | inspectionTaskList, |
| | | uploadInspectionTask, |
| | | } from "@/api/inspectionManagement"; |
| | | import { getToken } from "@/utils/auth"; |
| | | import config from "@/config"; |
| | | |
| | | // 组件引用 |
| | | const formDia = ref() |
| | | // 组件引用已移除 |
| | | |
| | | // 加载提示方法 |
| | | const showLoadingToast = (message) => { |
| | | uni.showLoading({ |
| | | title: message, |
| | | mask: true |
| | | }) |
| | | } |
| | | const closeToast = () => { |
| | | uni.hideLoading() |
| | | } |
| | | // 加载提示方法 |
| | | const showLoadingToast = message => { |
| | | uni.showLoading({ |
| | | title: message, |
| | | mask: true, |
| | | }); |
| | | }; |
| | | const closeToast = () => { |
| | | uni.hideLoading(); |
| | | }; |
| | | |
| | | // 表格数据 |
| | | const taskTableData = ref([]) // 生产巡检数据 |
| | | // 表格数据 |
| | | const taskTableData = ref([]); // 生产巡检数据 |
| | | |
| | | // 当前扫描的任务 |
| | | const currentScanningTask = ref(null) |
| | | // 当前扫描的任务 |
| | | const currentScanningTask = ref(null); |
| | | const infoData = ref(null); |
| | | |
| | | // 请求取消标志,用于取消正在进行的请求 |
| | | let isRequestCancelled = false |
| | | // 视频预览相关状态 |
| | | const showVideoDialog = ref(false); |
| | | const currentVideoFile = ref(null); |
| | | |
| | | // 扫码相关状态 |
| | | const isScanning = ref(false) |
| | | const cameraError = ref('') |
| | | // 请求取消标志,用于取消正在进行的请求 |
| | | let isRequestCancelled = false; |
| | | |
| | | // 生命周期 |
| | | onMounted(() => { |
| | | // 延迟初始化,确保DOM已渲染 |
| | | nextTick(() => { |
| | | getList() |
| | | }) |
| | | }) |
| | | const pagesPames = reactive({ |
| | | size: 10, |
| | | current: 1, |
| | | }); |
| | | |
| | | onShow(() => { |
| | | // 页面显示时刷新数据 |
| | | getList() |
| | | }) |
| | | |
| | | // 组件销毁时的清理 |
| | | onUnmounted(() => { |
| | | // 设置取消标志,阻止后续的异步操作 |
| | | isRequestCancelled = true |
| | | |
| | | // 停止扫码 |
| | | if (isScanning.value) { |
| | | isScanning.value = false |
| | | } |
| | | }) |
| | | |
| | | // 返回上一页 |
| | | const goBack = () => { |
| | | uni.navigateBack() |
| | | } |
| | | |
| | | // 查询数据 |
| | | const handleQuery = () => { |
| | | getList() |
| | | } |
| | | |
| | | // 获取列表数据 |
| | | const getList = () => { |
| | | // 显示加载提示 |
| | | showLoadingToast('加载中...') |
| | | |
| | | // 设置取消标志 |
| | | isRequestCancelled = false |
| | | |
| | | inspectionTaskList({}).then(res => { |
| | | // 检查组件是否还存在且请求未被取消 |
| | | if (!isRequestCancelled) { |
| | | console.log('生产巡检API返回数据:', res); |
| | | |
| | | // 处理不同的数据结构 |
| | | let records = []; |
| | | if (res && res.data) { |
| | | // 尝试多种可能的数据结构 |
| | | if (Array.isArray(res.data.records)) { |
| | | records = res.data.records; |
| | | } else if (Array.isArray(res.data.rows)) { |
| | | records = res.data.rows; |
| | | } else if (Array.isArray(res.data)) { |
| | | records = res.data; |
| | | } else if (Array.isArray(res.data.list)) { |
| | | records = res.data.list; |
| | | } |
| | | } |
| | | |
| | | if (records.length > 0) { |
| | | taskTableData.value = records; |
| | | console.log('生产巡检数据设置成功,记录数:', records.length); |
| | | } else { |
| | | console.warn('生产巡检数据为空或格式不正确:', res); |
| | | taskTableData.value = []; |
| | | uni.showToast({ |
| | | title: '暂无巡检任务数据', |
| | | icon: 'none' |
| | | }); |
| | | } |
| | | const loadMoreStatus = computed(() => { |
| | | if (loading.value) { |
| | | return "loading"; |
| | | } |
| | | // 关闭加载提示 |
| | | closeToast() |
| | | }).catch(err => { |
| | | // 检查组件是否还存在且请求未被取消 |
| | | if (!isRequestCancelled) { |
| | | console.error('获取生产巡检数据失败:', err); |
| | | taskTableData.value = []; |
| | | // 添加错误提示 |
| | | uni.showToast({ |
| | | title: '获取数据失败', |
| | | icon: 'error' |
| | | if (noMore.value) { |
| | | return "noMore"; |
| | | } |
| | | return "more"; |
| | | }); |
| | | const totalSize = ref(0); |
| | | const noMore = computed(() => { |
| | | return taskTableData.value.length >= totalSize.value; |
| | | }); |
| | | const loading = ref(false); |
| | | |
| | | const reloadPage = () => { |
| | | pagesPames.current = 1; |
| | | taskTableData.value = []; |
| | | getList(); |
| | | }; |
| | | const loadPage = () => { |
| | | if (noMore.value || loading.value) return; |
| | | pagesPames.current += 1; |
| | | getList(); |
| | | }; |
| | | |
| | | // 生命周期 |
| | | onMounted(() => { |
| | | // 延迟初始化,确保DOM已渲染 |
| | | // nextTick(() => { |
| | | // getList() |
| | | // }) |
| | | }); |
| | | |
| | | onReachBottom(() => { |
| | | loadPage(); |
| | | }); |
| | | onPullDownRefresh(() => { |
| | | reloadPage(); |
| | | uni.stopPullDownRefresh(); |
| | | }); |
| | | |
| | | onShow(() => { |
| | | // 页面显示时刷新数据 |
| | | reloadPage(); |
| | | }); |
| | | |
| | | // 组件销毁时的清理 |
| | | onUnmounted(() => { |
| | | // 设置取消标志,阻止后续的异步操作 |
| | | isRequestCancelled = true; |
| | | }); |
| | | |
| | | // 返回上一页 |
| | | const goBack = () => { |
| | | uni.navigateBack(); |
| | | }; |
| | | |
| | | // 获取列表数据 |
| | | const getList = () => { |
| | | // 显示加载提示 |
| | | // showLoadingToast('加载中...') |
| | | |
| | | // 设置取消标志 |
| | | isRequestCancelled = false; |
| | | loading.value = true; |
| | | inspectionTaskList({ ...pagesPames }) |
| | | .then(res => { |
| | | // 检查组件是否还存在且请求未被取消 |
| | | if (!isRequestCancelled) { |
| | | // 处理不同的数据结构 |
| | | let records = []; |
| | | if (res && res.data) { |
| | | // 尝试多种可能的数据结构 |
| | | totalSize.value = res.data.total; |
| | | if (Array.isArray(res.data.records)) { |
| | | records = res.data.records; |
| | | } else if (Array.isArray(res.data.rows)) { |
| | | records = res.data.rows; |
| | | } else if (Array.isArray(res.data)) { |
| | | records = res.data; |
| | | } else if (Array.isArray(res.data.list)) { |
| | | records = res.data.list; |
| | | } |
| | | } |
| | | |
| | | if (records.length > 0) { |
| | | taskTableData.value = [ |
| | | ...taskTableData.value, |
| | | ...records.map(record => { |
| | | record.fileStatus = getFileStatus(record); |
| | | return record; |
| | | }), |
| | | ]; |
| | | } else { |
| | | taskTableData.value = []; |
| | | uni.showToast({ |
| | | title: "暂无巡检任务数据", |
| | | icon: "none", |
| | | }); |
| | | } |
| | | } |
| | | loading.value = false; |
| | | // 关闭加载提示 |
| | | // closeToast() |
| | | }) |
| | | } |
| | | // 关闭加载提示 |
| | | closeToast() |
| | | }) |
| | | } |
| | | |
| | | |
| | | // 上传 |
| | | const handleAdd = (row) => { |
| | | nextTick(() => { |
| | | // 检查组件是否还存在 |
| | | if (formDia.value && formDia.value.openDialog) { |
| | | formDia.value.openDialog(row) |
| | | } else { |
| | | console.error('上传组件引用不存在') |
| | | uni.showToast({ |
| | | title: '组件未准备好', |
| | | icon: 'error' |
| | | }) |
| | | } |
| | | }) |
| | | } |
| | | |
| | | // 为指定任务开始扫码 |
| | | const startScanForTask = async (task) => { |
| | | try { |
| | | // 记录当前扫描的任务 |
| | | currentScanningTask.value = task |
| | | console.log('为任务开始扫码:', task.taskName) |
| | | |
| | | // 显示扫描界面 |
| | | isScanning.value = true |
| | | |
| | | // 使用uniapp的扫码API |
| | | uni.scanCode({ |
| | | success: (res) => { |
| | | console.log('扫码成功:', res) |
| | | handleScanSuccess(res) |
| | | }, |
| | | fail: (err) => { |
| | | console.error('扫码失败:', err) |
| | | uni.showToast({ |
| | | title: '扫码失败', |
| | | icon: 'error' |
| | | }) |
| | | // 关闭扫描界面 |
| | | isScanning.value = false |
| | | }, |
| | | complete: () => { |
| | | // 扫码完成后关闭扫描界面 |
| | | setTimeout(() => { |
| | | isScanning.value = false |
| | | }, 1000) |
| | | } |
| | | }) |
| | | } catch (e) { |
| | | console.error('启动扫码失败:', e) |
| | | uni.showToast({ |
| | | title: '启动扫码失败', |
| | | icon: 'error' |
| | | }) |
| | | isScanning.value = false |
| | | } |
| | | } |
| | | |
| | | // 停止扫码 |
| | | const stopScan = () => { |
| | | isScanning.value = false |
| | | currentScanningTask.value = null |
| | | } |
| | | |
| | | // 扫码成功处理 |
| | | const handleScanSuccess = async (result) => { |
| | | try { |
| | | console.log('处理扫码结果:', result) |
| | | console.log('当前关联任务:', currentScanningTask.value?.taskName) |
| | | |
| | | uni.showToast({ |
| | | title: '识别成功', |
| | | icon: 'success' |
| | | }) |
| | | |
| | | // 解析二维码数据 |
| | | let qrData |
| | | let deviceId = '' |
| | | |
| | | try { |
| | | qrData = JSON.parse(result.result) |
| | | console.log('解析的二维码数据:', qrData) |
| | | deviceId = qrData.deviceId || qrData.qrCodeId |
| | | } catch (e) { |
| | | // 如果不是JSON格式,尝试从URL中提取deviceId |
| | | const url = result.result |
| | | |
| | | if (url.includes('deviceId=')) { |
| | | // 从URL中提取deviceId |
| | | const match = url.match(/deviceId=(\d+)/) |
| | | if (match && match[1]) { |
| | | deviceId = match[1] |
| | | } |
| | | } |
| | | |
| | | qrData = { |
| | | deviceName: deviceId ? `设备${deviceId}` : result.result, |
| | | location: '', |
| | | qrCodeId: deviceId // 使用提取的deviceId或原始结果 |
| | | } |
| | | } |
| | | |
| | | // 如果有设备ID,尝试从API获取真实的设备名称 |
| | | if (deviceId) { |
| | | try { |
| | | console.log('正在查询设备信息,设备ID:', deviceId) |
| | | const response = await getLedgerById(deviceId) |
| | | console.log('设备信息查询结果:', response) |
| | | |
| | | if (response.code === 200 && response.data) { |
| | | qrData.deviceName = response.data.deviceName || `设备${deviceId}` |
| | | qrData.location = response.data.storageLocation || '' |
| | | console.log('获取到设备名称:', qrData.deviceName) |
| | | } else { |
| | | console.warn('设备信息查询失败,使用默认名称') |
| | | qrData.deviceName = qrData.deviceName || `设备${deviceId}` |
| | | } |
| | | } catch (apiError) { |
| | | console.error('查询设备信息失败:', apiError) |
| | | // API调用失败时使用默认名称 |
| | | qrData.deviceName = qrData.deviceName || `设备${deviceId}` |
| | | } |
| | | } |
| | | |
| | | // 确保数据完整性 |
| | | if (!qrData.deviceName) { |
| | | qrData.deviceName = result.result |
| | | } |
| | | if (!qrData.qrCodeId) { |
| | | qrData.qrCodeId = deviceId || result.result |
| | | } |
| | | |
| | | // 将扫码数据与任务关联 |
| | | if (currentScanningTask.value) { |
| | | // 关联任务信息 |
| | | const taskData = { |
| | | ...currentScanningTask.value, |
| | | qrCodeData: qrData |
| | | } |
| | | |
| | | // 打开上传弹窗,传递关联后的任务数据 |
| | | nextTick(() => { |
| | | if (formDia.value && formDia.value.openDialog) { |
| | | formDia.value.openDialog(taskData) |
| | | } else { |
| | | console.error('上传组件引用不存在') |
| | | .catch(err => { |
| | | // 检查组件是否还存在且请求未被取消 |
| | | if (!isRequestCancelled) { |
| | | taskTableData.value = []; |
| | | // 添加错误提示 |
| | | uni.showToast({ |
| | | title: '组件未准备好', |
| | | icon: 'error' |
| | | }) |
| | | title: "获取数据失败", |
| | | icon: "error", |
| | | }); |
| | | } |
| | | }) |
| | | } |
| | | } catch (error) { |
| | | console.error('处理扫码结果失败:', error) |
| | | uni.showToast({ |
| | | title: error.message || '数据解析失败', |
| | | icon: 'error' |
| | | }) |
| | | } finally { |
| | | // 关闭扫描界面 |
| | | isScanning.value = false |
| | | } |
| | | } |
| | | loading.value = false; |
| | | // 关闭加载提示 |
| | | // closeToast() |
| | | }); |
| | | }; |
| | | |
| | | // 摄像头错误处理 |
| | | const handleCameraError = (error) => { |
| | | console.error('摄像头错误:', error) |
| | | cameraError.value = '摄像头访问失败,请检查权限设置' |
| | | } |
| | | const getFileStatus = record => { |
| | | let _beforeProduction = |
| | | record.beforeProduction && record.beforeProduction.length; |
| | | let _afterProduction = |
| | | record.afterProduction && record.afterProduction.length; |
| | | let _productionIssues = |
| | | record.productionIssues && record.productionIssues.length; |
| | | if (_beforeProduction && _afterProduction && _productionIssues) { |
| | | return 2; |
| | | } else if (_beforeProduction || _afterProduction || _productionIssues) { |
| | | return 1; |
| | | } else { |
| | | return 0; |
| | | } |
| | | }; |
| | | |
| | | // 为指定任务开始扫码(真机) |
| | | const startScanForTask = async task => { |
| | | try { |
| | | currentScanningTask.value = task; |
| | | uni.scanCode({ |
| | | success: res => { |
| | | handleScanSuccess(res); |
| | | }, |
| | | fail: err => { |
| | | console.error("扫码失败:", err); |
| | | uni.showToast({ |
| | | title: "扫码失败", |
| | | icon: "error", |
| | | }); |
| | | }, |
| | | }); |
| | | } catch (e) { |
| | | console.error("启动扫码失败:", e); |
| | | uni.showToast({ |
| | | title: "启动扫码失败", |
| | | icon: "error", |
| | | }); |
| | | } |
| | | }; |
| | | |
| | | // 扫码成功处理:校验后打开上传弹窗 |
| | | const handleScanSuccess = result => { |
| | | try { |
| | | // 解析二维码数据,提取deviceId |
| | | let deviceId = ""; |
| | | |
| | | if (result?.result && typeof result.result === "string") { |
| | | if (result.result.includes("deviceId=")) { |
| | | const match = result.result.match(/deviceId=(\d+)/); |
| | | if (match && match[1]) deviceId = match[1]; |
| | | } else { |
| | | try { |
| | | const qrData = JSON.parse(result.result); |
| | | deviceId = qrData.deviceId || qrData.qrCodeId || ""; |
| | | } catch (e) { |
| | | deviceId = result.result; |
| | | } |
| | | } |
| | | } |
| | | |
| | | if (!deviceId) { |
| | | uni.showToast({ title: "未识别到设备ID", icon: "error" }); |
| | | return; |
| | | } |
| | | |
| | | const currentTaskId = |
| | | currentScanningTask.value?.taskId || currentScanningTask.value?.id; |
| | | if (!currentTaskId) { |
| | | uni.showToast({ title: "任务信息缺失", icon: "error" }); |
| | | return; |
| | | } |
| | | |
| | | if (deviceId === currentTaskId.toString()) { |
| | | uni.showToast({ title: "识别成功", icon: "success" }); |
| | | openUploadDialog(currentScanningTask.value); |
| | | } else { |
| | | uni.showToast({ title: "请扫描正确的设备", icon: "error" }); |
| | | } |
| | | } catch (error) { |
| | | console.error("扫码结果处理失败:", error); |
| | | uni.showToast({ |
| | | title: error?.message || "数据解析失败", |
| | | icon: "error", |
| | | }); |
| | | } |
| | | }; |
| | | |
| | | // 打开上传页面 |
| | | const openUploadDialog = task => { |
| | | // 将任务信息传递到上传页面 |
| | | const taskData = encodeURIComponent(JSON.stringify(task)); |
| | | uni.navigateTo({ |
| | | url: `/pages/inspectionUpload/upload?taskInfo=${taskData}`, |
| | | }); |
| | | }; |
| | | |
| | | // 图片上传(可选择图片上传或者是相机拍照) |
| | | const startUploadForTask = async (task, type) => { |
| | | // 打开上传页面 |
| | | openUploadDialog(task); |
| | | }; |
| | | |
| | | // 查看附件 - 跳转到附件页面 |
| | | const viewAttachments = async task => { |
| | | const taskData = encodeURIComponent(JSON.stringify(task)); |
| | | uni.navigateTo({ |
| | | url: `/pages/inspectionUpload/attachment?taskInfo=${taskData}`, |
| | | }); |
| | | }; |
| | | |
| | | // 判断是否为图片文件 |
| | | const isImageFile = file => { |
| | | // 检查contentType字段 |
| | | if (file.contentType && file.contentType.startsWith("image/")) { |
| | | return true; |
| | | } |
| | | |
| | | // 检查原有的type字段 |
| | | if (file.type === "image") return true; |
| | | |
| | | // 检查文件扩展名 |
| | | const name = file.bucketFilename || file.originalFilename || file.name || ""; |
| | | const ext = name.split(".").pop()?.toLowerCase(); |
| | | return ["jpg", "jpeg", "png", "gif", "webp"].includes(ext); |
| | | }; |
| | | |
| | | // 文件访问基础域(后端要求前缀) |
| | | const filePreviewBase = config.fileUrl; |
| | | |
| | | // 将后端返回的文件地址规范成可访问URL |
| | | // 兼容场景: |
| | | // - 已经是 http/https:直接返回 |
| | | // - 以 / 开头:拼接 filePreviewBase |
| | | // - Windows 本地路径(如 D:\ruoyi\prod\uploads...\xx.jpg):尝试截取 prod 之后的相对路径并拼接 filePreviewBase |
| | | const normalizeFileUrl = rawUrl => { |
| | | try { |
| | | if (!rawUrl || typeof rawUrl !== "string") return ""; |
| | | const url = rawUrl.trim(); |
| | | if (!url) return ""; |
| | | if (/^https?:\/\//i.test(url)) return url; |
| | | if (url.startsWith("/")) return `${filePreviewBase}${url}`; |
| | | |
| | | // Windows path -> web path |
| | | if (/^[a-zA-Z]:\\/.test(url)) { |
| | | const normalized = url.replace(/\\/g, "/"); |
| | | const idx = normalized.indexOf("/prod/"); |
| | | if (idx >= 0) { |
| | | const relative = normalized.slice(idx + "/prod/".length); |
| | | return `${filePreviewBase}/${relative}`; |
| | | } |
| | | // 兜底:无法推断映射规则时,至少把反斜杠变成正斜杠 |
| | | return normalized; |
| | | } |
| | | |
| | | // 其他相对路径:直接用 baseUrl 拼一下 |
| | | return `${filePreviewBase}/${url.replace(/^\//, "")}`; |
| | | } catch (e) { |
| | | return rawUrl || ""; |
| | | } |
| | | }; |
| | | |
| | | // 预览附件 |
| | | const previewAttachment = file => { |
| | | if (isImageFile(file)) { |
| | | // 预览图片 |
| | | const imageUrls = getCurrentViewAttachments() |
| | | .filter(f => isImageFile(f)) |
| | | .map(f => f.url || f.downloadUrl); |
| | | |
| | | uni.previewImage({ |
| | | urls: imageUrls, |
| | | current: file.url || file.downloadUrl, |
| | | }); |
| | | } else { |
| | | // 预览视频 - 显示视频播放弹窗 |
| | | showVideoPreview(file); |
| | | } |
| | | }; |
| | | |
| | | // 显示视频预览 |
| | | const showVideoPreview = file => { |
| | | currentVideoFile.value = file; |
| | | showVideoDialog.value = true; |
| | | }; |
| | | |
| | | // 关闭视频预览 |
| | | const closeVideoPreview = () => { |
| | | showVideoDialog.value = false; |
| | | currentVideoFile.value = null; |
| | | }; |
| | | |
| | | // 视频播放错误处理 |
| | | const handleVideoError = error => { |
| | | uni.showToast({ |
| | | title: "视频播放失败", |
| | | icon: "error", |
| | | }); |
| | | }; |
| | | </script> |
| | | |
| | | <style scoped lang="scss"> |
| | | // 导入销售模块公共样式 |
| | | @import '@/styles/sales-common.scss'; |
| | | |
| | | // 页面容器样式 |
| | | .inspection-upload-page { |
| | | min-height: 100vh; |
| | | background: #f8f9fa; |
| | | position: relative; |
| | | } |
| | | |
| | | // 列表容器样式 |
| | | .table-section { |
| | | padding: 20px; |
| | | } |
| | | |
| | | // 任务列表样式 - 使用销售台账的样式规范 |
| | | .task-list { |
| | | .task-item { |
| | | background: #ffffff; |
| | | border-radius: 12px; |
| | | margin-bottom: 16px; |
| | | overflow: hidden; |
| | | box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05); |
| | | padding: 0 16px; |
| | | |
| | | &:active { |
| | | transform: scale(0.98); |
| | | box-shadow: 0 1px 4px rgba(0, 0, 0, 0.1); |
| | | } |
| | | <style scoped> |
| | | .inspection-upload-page { |
| | | min-height: 100vh; |
| | | background-color: #f5f5f5; |
| | | } |
| | | } |
| | | |
| | | // 项目头部样式 |
| | | .task-header { |
| | | padding: 16px 0; |
| | | display: flex; |
| | | align-items: center; |
| | | justify-content: space-between; |
| | | margin-bottom: 0; |
| | | } |
| | | .table-section { |
| | | padding: 15px; |
| | | } |
| | | |
| | | .task-info { |
| | | flex: 1; |
| | | } |
| | | .task-list { |
| | | display: flex; |
| | | flex-direction: column; |
| | | gap: 12px; |
| | | } |
| | | |
| | | .task-name { |
| | | font-size: 14px; |
| | | color: #333; |
| | | font-weight: 500; |
| | | margin-bottom: 0; |
| | | line-height: 1.4; |
| | | } |
| | | .task-item { |
| | | background: #fff; |
| | | border-radius: 12px; |
| | | padding: 15px; |
| | | box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1); |
| | | transition: all 0.3s ease; |
| | | } |
| | | |
| | | .task-location { |
| | | font-size: 12px; |
| | | color: #666; |
| | | margin-top: 4px; |
| | | } |
| | | .task-header { |
| | | display: flex; |
| | | justify-content: space-between; |
| | | align-items: flex-start; |
| | | margin-bottom: 12px; |
| | | } |
| | | |
| | | // 任务操作按钮样式 |
| | | .task-actions { |
| | | display: flex; |
| | | align-items: center; |
| | | gap: 8px; |
| | | margin-left: 0; |
| | | } |
| | | .task-info { |
| | | flex: 1; |
| | | display: flex; |
| | | flex-direction: column; |
| | | gap: 4px; |
| | | } |
| | | |
| | | // 任务详情样式 - 使用销售台账的详情行样式 |
| | | .task-details { |
| | | padding: 16px 0; |
| | | |
| | | .task-name { |
| | | font-size: 16px; |
| | | font-weight: 600; |
| | | color: #333; |
| | | } |
| | | |
| | | .task-location { |
| | | font-size: 14px; |
| | | color: #666; |
| | | } |
| | | |
| | | .task-actions { |
| | | display: flex; |
| | | gap: 8px; |
| | | } |
| | | |
| | | .task-details { |
| | | display: flex; |
| | | flex-direction: column; |
| | | gap: 6px; |
| | | } |
| | | |
| | | .detail-item { |
| | | display: flex; |
| | | align-items: flex-end; |
| | | justify-content: space-between; |
| | | margin-bottom: 8px; |
| | | |
| | | &:last-child { |
| | | margin-bottom: 0; |
| | | } |
| | | |
| | | .detail-label { |
| | | font-size: 12px; |
| | | color: #777777; |
| | | min-width: 60px; |
| | | flex-shrink: 0; |
| | | } |
| | | |
| | | .detail-value { |
| | | font-size: 12px; |
| | | color: #000000; |
| | | text-align: right; |
| | | flex: 1; |
| | | margin-left: 16px; |
| | | line-height: 1.4; |
| | | } |
| | | align-items: center; |
| | | } |
| | | } |
| | | |
| | | // 无数据提示样式 - 使用销售台账的样式 |
| | | .no-data { |
| | | padding: 40px 0; |
| | | text-align: center; |
| | | color: #999; |
| | | background: none; |
| | | margin: 0; |
| | | } |
| | | .detail-label { |
| | | font-size: 12px; |
| | | color: #999; |
| | | } |
| | | |
| | | .no-data text { |
| | | font-size: 14px; |
| | | color: #999; |
| | | } |
| | | .detail-value { |
| | | font-size: 12px; |
| | | color: #666; |
| | | font-weight: 500; |
| | | } |
| | | |
| | | /* 扫码弹窗样式 */ |
| | | .qr-scan-overlay { |
| | | position: fixed; |
| | | top: 0; |
| | | left: 0; |
| | | right: 0; |
| | | bottom: 0; |
| | | background-color: rgba(0, 0, 0, 0.8); |
| | | z-index: 9999; |
| | | display: flex; |
| | | flex-direction: column; |
| | | justify-content: center; |
| | | align-items: center; |
| | | padding: 20px; |
| | | } |
| | | .no-data { |
| | | text-align: center; |
| | | padding: 40px 20px; |
| | | color: #999; |
| | | font-size: 14px; |
| | | } |
| | | |
| | | .qr-scan-container { |
| | | width: 100%; |
| | | max-width: 400px; |
| | | background-color: #000; |
| | | border-radius: 12px; |
| | | overflow: hidden; |
| | | } |
| | | /* 扫码弹窗样式 */ |
| | | .qr-scan-overlay { |
| | | position: fixed; |
| | | top: 0; |
| | | left: 0; |
| | | right: 0; |
| | | bottom: 0; |
| | | background: rgba(0, 0, 0, 0.8); |
| | | z-index: 9999; |
| | | display: flex; |
| | | align-items: center; |
| | | justify-content: center; |
| | | } |
| | | |
| | | .scan-header { |
| | | display: flex; |
| | | justify-content: space-between; |
| | | align-items: center; |
| | | padding: 15px; |
| | | background-color: rgba(0, 0, 0, 0.7); |
| | | } |
| | | .qr-scan-container { |
| | | width: 90vw; |
| | | max-width: 400px; |
| | | background: #fff; |
| | | border-radius: 12px; |
| | | padding: 20px; |
| | | position: relative; |
| | | } |
| | | |
| | | .scan-title { |
| | | font-size: 18px; |
| | | font-weight: 600; |
| | | color: #fff; |
| | | } |
| | | .scan-header { |
| | | display: flex; |
| | | justify-content: space-between; |
| | | align-items: center; |
| | | margin-bottom: 15px; |
| | | } |
| | | |
| | | .qr-camera { |
| | | width: 100%; |
| | | height: 400px; |
| | | } |
| | | .scan-title { |
| | | font-size: 18px; |
| | | font-weight: 600; |
| | | color: #333; |
| | | } |
| | | |
| | | .scan-frame-wrapper { |
| | | position: relative; |
| | | width: 100%; |
| | | height: 300px; |
| | | } |
| | | .qr-camera { |
| | | width: 100%; |
| | | height: 300px; |
| | | border-radius: 8px; |
| | | overflow: hidden; |
| | | margin-bottom: 15px; |
| | | } |
| | | |
| | | .scan-frame { |
| | | position: absolute; |
| | | top: 50%; |
| | | left: 50%; |
| | | transform: translate(-50%, -50%); |
| | | width: 80%; |
| | | height: 80%; |
| | | border: 3px solid #1890ff; |
| | | border-radius: 8px; |
| | | box-shadow: 0 0 20px rgba(24, 144, 255, 0.3); |
| | | animation: pulse 2s infinite; |
| | | } |
| | | .scan-frame-wrapper { |
| | | position: relative; |
| | | display: flex; |
| | | flex-direction: column; |
| | | align-items: center; |
| | | } |
| | | |
| | | .scan-tip { |
| | | position: absolute; |
| | | bottom: 10px; |
| | | left: 50%; |
| | | transform: translateX(-50%); |
| | | color: #fff; |
| | | font-size: 14px; |
| | | text-align: center; |
| | | background-color: rgba(0, 0, 0, 0.6); |
| | | padding: 5px 15px; |
| | | border-radius: 20px; |
| | | } |
| | | .scan-frame { |
| | | width: 200px; |
| | | height: 200px; |
| | | border: 2px solid #409eff; |
| | | border-radius: 8px; |
| | | position: relative; |
| | | } |
| | | |
| | | @keyframes pulse { |
| | | 0% { opacity: 0.8; } |
| | | 50% { opacity: 0.4; } |
| | | 100% { opacity: 0.8; } |
| | | } |
| | | .scan-frame::before, |
| | | .scan-frame::after { |
| | | content: ""; |
| | | position: absolute; |
| | | width: 20px; |
| | | height: 20px; |
| | | border: 2px solid #409eff; |
| | | } |
| | | |
| | | .scan-frame::before { |
| | | top: -2px; |
| | | left: -2px; |
| | | border-right: none; |
| | | border-bottom: none; |
| | | } |
| | | |
| | | .scan-frame::after { |
| | | bottom: -2px; |
| | | right: -2px; |
| | | border-left: none; |
| | | border-top: none; |
| | | } |
| | | |
| | | .scan-tip { |
| | | margin-top: 10px; |
| | | font-size: 14px; |
| | | color: #666; |
| | | text-align: center; |
| | | } |
| | | |
| | | /* 自定义模态框样式 */ |
| | | .custom-modal-overlay { |
| | | position: fixed; |
| | | top: 0; |
| | | left: 0; |
| | | right: 0; |
| | | bottom: 0; |
| | | background: rgba(0, 0, 0, 0.5); |
| | | z-index: 10000; |
| | | display: flex; |
| | | align-items: center; |
| | | justify-content: center; |
| | | padding: 20px; |
| | | } |
| | | |
| | | .custom-modal-container { |
| | | width: 100%; |
| | | max-width: 500px; |
| | | max-height: 80vh; |
| | | display: flex; |
| | | align-items: center; |
| | | justify-content: center; |
| | | } |
| | | |
| | | /* 视频预览弹窗样式 */ |
| | | .video-modal-overlay { |
| | | position: fixed; |
| | | top: 0; |
| | | left: 0; |
| | | right: 0; |
| | | bottom: 0; |
| | | background: rgba(0, 0, 0, 0.8); |
| | | z-index: 10001; |
| | | display: flex; |
| | | align-items: center; |
| | | justify-content: center; |
| | | padding: 20px; |
| | | } |
| | | |
| | | .video-modal-container { |
| | | width: 90%; |
| | | max-width: 800px; |
| | | max-height: 80vh; |
| | | background: #000; |
| | | border-radius: 12px; |
| | | overflow: hidden; |
| | | box-shadow: 0 4px 20px rgba(0, 0, 0, 0.5); |
| | | } |
| | | |
| | | .video-modal-header { |
| | | display: flex; |
| | | justify-content: space-between; |
| | | align-items: center; |
| | | padding: 15px 20px; |
| | | background: rgba(0, 0, 0, 0.7); |
| | | color: #fff; |
| | | } |
| | | |
| | | .video-modal-title { |
| | | font-size: 16px; |
| | | font-weight: 500; |
| | | color: #fff; |
| | | } |
| | | |
| | | .close-btn-video { |
| | | width: 28px; |
| | | height: 28px; |
| | | border-radius: 50%; |
| | | background: rgba(255, 255, 255, 0.2); |
| | | display: flex; |
| | | align-items: center; |
| | | justify-content: center; |
| | | cursor: pointer; |
| | | transition: all 0.3s ease; |
| | | } |
| | | |
| | | .close-btn-video:hover { |
| | | background: rgba(255, 255, 255, 0.3); |
| | | transform: scale(1.1); |
| | | } |
| | | |
| | | .video-modal-body { |
| | | position: relative; |
| | | background: #000; |
| | | } |
| | | |
| | | .video-player { |
| | | width: 100%; |
| | | height: auto; |
| | | max-height: 60vh; |
| | | display: block; |
| | | } |
| | | </style> |