From 752b14d2caa47ccceac328f79389fbf5e2e62ce4 Mon Sep 17 00:00:00 2001
From: gaoluyang <2820782392@qq.com>
Date: 星期三, 24 九月 2025 15:18:39 +0800
Subject: [PATCH] 分析追溯
---
src/pages/inspectionUpload/components/qrCodeFormDia.vue | 316 ++++++++++++++++++++++++++++++++++++++++++----------
1 files changed, 255 insertions(+), 61 deletions(-)
diff --git a/src/pages/inspectionUpload/components/qrCodeFormDia.vue b/src/pages/inspectionUpload/components/qrCodeFormDia.vue
index 07a94cd..bcf30ef 100644
--- a/src/pages/inspectionUpload/components/qrCodeFormDia.vue
+++ b/src/pages/inspectionUpload/components/qrCodeFormDia.vue
@@ -1,6 +1,6 @@
<template>
<u-popup
- v-model="dialogVisitable"
+ :show="dialogVisitable"
mode="center"
:round="10"
:closeable="true"
@@ -26,23 +26,32 @@
<u-input
v-model="form.location"
placeholder="璇疯緭鍏ュ湴鐐�"
- :maxlength="30"
+ :maxlength="100"
:disabled="true"
- />
+ >
+ <template #suffix>
+ <u-icon
+ name="map"
+ @click="getCurrentLocation"
+ class="location-icon"
+ :class="{ 'loading': locationLoading }"
+ />
+ </template>
+ </u-input>
</u-form-item>
<u-form-item label="闄勪欢" prop="storageBlobDTO" labelWidth="80">
- <u-upload
- :fileList="form.storageBlobDTO"
- @afterRead="afterRead"
- @delete="deleteFile"
- name="files"
- multiple
- :maxCount="10"
- :maxSize="1024 * 1024"
- accept="video/*"
- :previewFullImage="true"
- ></u-upload>
+ <view class="upload-container">
+ <ImageUpload
+ v-model="form.storageBlobDTO"
+ :limit="10"
+ :fileSize="50"
+ :fileType="['jpg', 'jpeg', 'png', 'mp4', 'mov']"
+ :maxVideoDuration="60"
+ :statusType="0"
+ @update:modelValue="handleStorageBlobUpdate"
+ />
+ </view>
</u-form-item>
<u-form-item label="宸℃浜�" prop="scannerName" labelWidth="80">
@@ -72,9 +81,10 @@
</template>
<script setup>
-import { reactive, ref, onMounted } from 'vue'
+import { reactive, ref, onMounted, onUnmounted, nextTick } from 'vue'
import { addOrEditQrCodeRecord } from '@/api/inspectionUpload/index.js'
import useUserStore from '@/store/modules/user.ts'
+import ImageUpload from '@/components/imageUpload/index.vue'
const emit = defineEmits(['closeDia'])
@@ -82,6 +92,10 @@
const formRef = ref(null)
const userStore = useUserStore()
const userInfo = ref({})
+const locationLoading = ref(false)
+
+// 璇锋眰鍙栨秷鏍囧織
+let isRequestCancelled = false
// 鑾峰彇褰撳墠鏃堕棿
function getCurrentDateTime() {
@@ -118,80 +132,204 @@
onMounted(async () => {
try {
const res = await userStore.getInfo()
- userInfo.value = res.user
- form.scannerName = userInfo.value.nickName
- form.scannerId = userInfo.value.userId
- form.scanTime = getCurrentDateTime()
+ // 妫�鏌ョ粍浠舵槸鍚﹁繕瀛樺湪
+ if (!isRequestCancelled && userInfo.value !== undefined) {
+ userInfo.value = res.user
+ form.scannerName = userInfo.value.nickName
+ form.scannerId = userInfo.value.userId
+ form.scanTime = getCurrentDateTime()
+ }
} catch (error) {
console.error('鑾峰彇鐢ㄦ埛淇℃伅澶辫触:', error)
}
})
-// 鏂囦欢涓婁紶澶勭悊
-const afterRead = (event) => {
- const { file } = event
+// 澶勭悊storageBlobDTO鏁版嵁鏇存柊
+const handleStorageBlobUpdate = (value) => {
+ form.storageBlobDTO = value || []
+}
+
+// 鑾峰彇褰撳墠浣嶇疆
+const getCurrentLocation = () => {
+ // 妫�鏌ョ粍浠舵槸鍚﹁繕瀛樺湪
+ if (isRequestCancelled) return
- // 涓婁紶鏂囦欢鍒版湇鍔″櫒
- uni.uploadFile({
- url: '/api/upload', // 鏇挎崲涓哄疄闄呯殑涓婁紶鎺ュ彛
- filePath: file.url,
- name: 'file',
+ locationLoading.value = true
+ uni.showLoading({ title: '鑾峰彇浣嶇疆涓�...' })
+
+ uni.getLocation({
+ type: 'gcj02',
success: (res) => {
- const data = JSON.parse(res.data)
- if (data.code === 200) {
- const fileItem = {
- url: data.data.url,
- name: file.name,
- status: 'success'
- }
-
- form.storageBlobDTO.push(fileItem)
-
- uni.showToast({
- title: '涓婁紶鎴愬姛',
- icon: 'success'
- })
- } else {
- uni.showToast({
- title: '涓婁紶澶辫触',
- icon: 'error'
- })
+ // 妫�鏌ョ粍浠舵槸鍚﹁繕瀛樺湪
+ if (isRequestCancelled) {
+ uni.hideLoading()
+ return
}
+
+ // 浣跨敤閫嗗湴鐞嗙紪鐮佽幏鍙栧湴鍧�淇℃伅
+ uni.request({
+ url: `https://restapi.amap.com/v3/geocode/regeo?key=c120a5dc69a9f61839f7763e6057005f&location=${res.longitude},${res.latitude}&radius=1000&extensions=all`,
+ success: (geoRes) => {
+ // 妫�鏌ョ粍浠舵槸鍚﹁繕瀛樺湪
+ if (isRequestCancelled) {
+ uni.hideLoading()
+ return
+ }
+
+ uni.hideLoading()
+ locationLoading.value = false
+
+ if (geoRes.data.status === '1' && geoRes.data.regeocode) {
+ const regeocode = geoRes.data.regeocode
+ const address = regeocode.formatted_address
+
+ // 浼樺厛鏄剧ず璇︾粏鍦板潃
+ if (address) {
+ form.location = address
+ uni.showToast({
+ title: '浣嶇疆鑾峰彇鎴愬姛',
+ icon: 'success'
+ })
+ } else {
+ // 濡傛灉娌℃湁璇︾粏鍦板潃锛屽皾璇曠粍鍚堝湴鍧�淇℃伅
+ const addressComponent = regeocode.addressComponent
+ const combinedAddress = `${addressComponent.province}${addressComponent.city}${addressComponent.district}${addressComponent.township}`
+ form.location = combinedAddress
+ uni.showToast({
+ title: '浣嶇疆鑾峰彇鎴愬姛',
+ icon: 'success'
+ })
+ }
+ } else {
+ // API璋冪敤鎴愬姛浣嗘病鏈夎繑鍥炲湴鍧�淇℃伅
+ const fallbackAddress = `浣嶇疆: ${res.latitude.toFixed(4)}, ${res.longitude.toFixed(4)}`
+ form.location = fallbackAddress
+ uni.showToast({
+ title: '鑾峰彇鍒颁綅缃紝浣嗗湴鍧�瑙f瀽澶辫触',
+ icon: 'none'
+ })
+ }
+ },
+ fail: (err) => {
+ // 妫�鏌ョ粍浠舵槸鍚﹁繕瀛樺湪
+ if (isRequestCancelled) {
+ uni.hideLoading()
+ return
+ }
+
+ uni.hideLoading()
+ locationLoading.value = false
+ console.error('閫嗗湴鐞嗙紪鐮佸け璐�:', err)
+
+ // 閫嗗湴鐞嗙紪鐮佸け璐ユ椂锛屾樉绀虹畝鍖栫殑浣嶇疆淇℃伅
+ const fallbackAddress = `浣嶇疆: ${res.latitude.toFixed(4)}, ${res.longitude.toFixed(4)}`
+ form.location = fallbackAddress
+ uni.showToast({
+ title: '浣嶇疆鑾峰彇鎴愬姛锛屼絾鍦板潃瑙f瀽澶辫触',
+ icon: 'none'
+ })
+ }
+ })
},
- fail: () => {
+ fail: (err) => {
+ // 妫�鏌ョ粍浠舵槸鍚﹁繕瀛樺湪
+ if (isRequestCancelled) {
+ uni.hideLoading()
+ return
+ }
+
+ uni.hideLoading()
+ locationLoading.value = false
uni.showToast({
- title: '涓婁紶澶辫触',
+ title: '鑾峰彇浣嶇疆澶辫触锛岃妫�鏌ュ畾浣嶆潈闄�',
icon: 'error'
})
+ console.error('鑾峰彇浣嶇疆澶辫触:', err)
+
+ // 澶辫触鏃舵樉绀洪敊璇俊鎭�
+ form.location = '浣嶇疆鑾峰彇澶辫触'
}
})
}
-// 鍒犻櫎鏂囦欢
-const deleteFile = (event) => {
- const { index } = event
- form.storageBlobDTO.splice(index, 1)
-}
-
// 鎵撳紑寮规
const openDialog = async (row) => {
+ console.log('寮规鎺ユ敹鍒扮殑鏁版嵁:', row)
dialogVisitable.value = true
form.deviceName = row.deviceName || ''
form.location = row.location || ''
- form.qrCodeId = row.qrCodeId || row.id || ''
+ form.qrCodeId = row.qrCodeId
form.storageBlobDTO = []
+ console.log('寮规琛ㄥ崟鏁版嵁:', form)
+
+ // 寮哄埗鏇存柊瑙嗗浘
+ await nextTick()
+ console.log('nextTick鍚庡脊妗嗙姸鎬�:', dialogVisitable.value)
}
// 鎻愪氦琛ㄥ崟
const submitForm = async () => {
try {
+ // 妫�鏌ョ粍浠舵槸鍚﹁繕瀛樺湪
+ if (isRequestCancelled) return
+
+ console.log('寮�濮嬫彁浜よ〃鍗曪紝褰撳墠琛ㄥ崟鏁版嵁:', form)
+
// 琛ㄥ崟楠岃瘉
- const valid = await formRef.value.validate()
- if (!valid) return
+ if (formRef.value) {
+ const valid = await formRef.value.validate()
+ if (!valid) {
+ console.log('琛ㄥ崟楠岃瘉澶辫触')
+ return
+ }
+ }
- form.qrCode.id = form.qrCodeId
+ // 妫�鏌ュ繀濉瓧娈�
+ if (!form.deviceName) {
+ uni.showToast({
+ title: '璇疯緭鍏ヨ澶囧悕绉�',
+ icon: 'error'
+ })
+ return
+ }
- await addOrEditQrCodeRecord({ ...form })
+ if (!form.location) {
+ uni.showToast({
+ title: '璇疯幏鍙栦綅缃俊鎭�',
+ icon: 'error'
+ })
+ return
+ }
+
+ // 鍑嗗鎻愪氦鏁版嵁
+ const submitData = {
+ deviceName: form.deviceName,
+ location: form.location,
+ scannerName: form.scannerName,
+ scannerId: form.scannerId,
+ scanTime: form.scanTime,
+ storageBlobDTO: form.storageBlobDTO.map(file => ({
+ id: file.id, // 娣诲姞id瀛楁
+ url: file.url,
+ bucketFilename: file.bucketFilename || file.name,
+ downloadUrl: file.downloadUrl || file.url,
+ type: 0,
+ size: file.size,
+ createTime: file.createTime || new Date().getTime()
+ })),
+ qrCode: {
+ id: form.qrCodeId
+ }
+ }
+
+ console.log('鍑嗗鎻愪氦鐨勬暟鎹�:', submitData)
+
+ const response = await addOrEditQrCodeRecord(submitData)
+
+ // 妫�鏌ョ粍浠舵槸鍚﹁繕瀛樺湪
+ if (isRequestCancelled) return
+
+ console.log('鎻愪氦鍝嶅簲:', response)
uni.showToast({
title: '鎻愪氦鎴愬姛',
@@ -200,10 +338,23 @@
cancel()
} catch (error) {
+ // 妫�鏌ョ粍浠舵槸鍚﹁繕瀛樺湪
+ if (isRequestCancelled) return
+
console.error('鎻愪氦澶辫触:', error)
+
+ // 鏄剧ず鏇磋缁嗙殑閿欒淇℃伅
+ let errorMessage = '鎻愪氦澶辫触'
+ if (error.response) {
+ errorMessage = error.response.data?.message || `鏈嶅姟鍣ㄩ敊璇�: ${error.response.status}`
+ } else if (error.message) {
+ errorMessage = error.message
+ }
+
uni.showToast({
- title: '鎻愪氦澶辫触',
- icon: 'error'
+ title: errorMessage,
+ icon: 'error',
+ duration: 3000
})
}
}
@@ -213,6 +364,25 @@
dialogVisitable.value = false
emit('closeDia')
}
+
+// 缁勪欢閿�姣佹椂鐨勬竻鐞�
+onUnmounted(() => {
+ // 璁剧疆鍙栨秷鏍囧織锛岄樆姝㈠悗缁殑寮傛鎿嶄綔
+ isRequestCancelled = true
+
+ // 娓呯悊鐘舵��
+ if (locationLoading.value) {
+ locationLoading.value = false
+ }
+
+ // 鍏抽棴寮圭獥
+ if (dialogVisitable.value) {
+ dialogVisitable.value = false
+ }
+
+ // 闅愯棌鍙兘鏄剧ず鐨勫姞杞芥彁绀�
+ uni.hideLoading()
+})
defineExpose({ openDialog })
</script>
@@ -251,4 +421,28 @@
border-top: 1px solid #f0f0f0;
background-color: #fafafa;
}
+
+.location-icon {
+ color: #1890ff;
+ cursor: pointer;
+ transition: all 0.3s ease;
+}
+
+.location-icon:hover {
+ color: #40a9ff;
+}
+
+.location-icon.loading {
+ color: #999;
+ animation: spin 1s linear infinite;
+}
+
+@keyframes spin {
+ from { transform: rotate(0deg); }
+ to { transform: rotate(360deg); }
+}
+
+.upload-container {
+ width: 100%;
+}
</style>
--
Gitblit v1.9.3