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 | 236 ++++++++++++++++++++++------------------------------------
1 files changed, 91 insertions(+), 145 deletions(-)
diff --git a/src/pages/inspectionUpload/components/qrCodeFormDia.vue b/src/pages/inspectionUpload/components/qrCodeFormDia.vue
index 3dc83ef..bcf30ef 100644
--- a/src/pages/inspectionUpload/components/qrCodeFormDia.vue
+++ b/src/pages/inspectionUpload/components/qrCodeFormDia.vue
@@ -42,36 +42,15 @@
<u-form-item label="闄勪欢" prop="storageBlobDTO" labelWidth="80">
<view class="upload-container">
- <u-upload
- :fileList="form.storageBlobDTO"
- @afterRead="afterRead"
- @delete="deleteFile"
- name="files"
- multiple
- :maxCount="10"
- :maxSize="50 * 1024 * 1024"
- accept="image/*,video/*"
- :previewFullImage="true"
- :camera="true"
- :gallery="true"
- ></u-upload>
- <view class="upload-actions">
- <u-button
- type="primary"
- size="small"
- @click="chooseImage"
- :customStyle="{ marginRight: '10px' }"
- >
- 鎷嶇収
- </u-button>
- <u-button
- type="success"
- size="small"
- @click="chooseVideo"
- >
- 褰曞儚
- </u-button>
- </view>
+ <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>
@@ -102,9 +81,10 @@
</template>
<script setup>
-import { reactive, ref, onMounted, nextTick } 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'])
@@ -113,6 +93,9 @@
const userStore = useUserStore()
const userInfo = ref({})
const locationLoading = ref(false)
+
+// 璇锋眰鍙栨秷鏍囧織
+let isRequestCancelled = false
// 鑾峰彇褰撳墠鏃堕棿
function getCurrentDateTime() {
@@ -149,125 +132,50 @@
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
- console.log('鏂囦欢閫夋嫨:', file)
-
- // 鐩存帴娣诲姞鍒版枃浠跺垪琛紝涓嶄笂浼犲埌鏈嶅姟鍣�
- const fileItem = {
- url: file.url,
- name: file.name || `鏂囦欢_${Date.now()}`,
- status: 'success',
- size: file.size || 0,
- type: file.type || 'image/jpeg'
- }
-
- form.storageBlobDTO.push(fileItem)
-
- uni.showToast({
- title: '鏂囦欢娣诲姞鎴愬姛',
- icon: 'success'
- })
-}
-
-// 鎷嶇収
-const chooseImage = () => {
- uni.chooseImage({
- count: 1,
- sizeType: ['original', 'compressed'],
- sourceType: ['camera'],
- success: (res) => {
- console.log('鎷嶇収鎴愬姛:', res)
- const tempFilePath = res.tempFilePaths[0]
-
- const fileItem = {
- url: tempFilePath,
- name: `鐓х墖_${Date.now()}.jpg`,
- status: 'success',
- type: 'image/jpeg'
- }
-
- form.storageBlobDTO.push(fileItem)
-
- uni.showToast({
- title: '鎷嶇収鎴愬姛',
- icon: 'success'
- })
- },
- fail: (err) => {
- console.error('鎷嶇収澶辫触:', err)
- uni.showToast({
- title: '鎷嶇収澶辫触',
- icon: 'error'
- })
- }
- })
-}
-
-// 褰曞儚
-const chooseVideo = () => {
- uni.chooseVideo({
- sourceType: ['camera'],
- maxDuration: 60, // 鏈�澶�60绉�
- camera: 'back',
- success: (res) => {
- console.log('褰曞儚鎴愬姛:', res)
- const tempFilePath = res.tempFilePath
-
- const fileItem = {
- url: tempFilePath,
- name: `瑙嗛_${Date.now()}.mp4`,
- status: 'success',
- type: 'video/mp4',
- duration: res.duration,
- size: res.size
- }
-
- form.storageBlobDTO.push(fileItem)
-
- uni.showToast({
- title: '褰曞儚鎴愬姛',
- icon: 'success'
- })
- },
- fail: (err) => {
- console.error('褰曞儚澶辫触:', err)
- uni.showToast({
- title: '褰曞儚澶辫触',
- icon: 'error'
- })
- }
- })
-}
-
-// 鍒犻櫎鏂囦欢
-const deleteFile = (event) => {
- const { index } = event
- form.storageBlobDTO.splice(index, 1)
+// 澶勭悊storageBlobDTO鏁版嵁鏇存柊
+const handleStorageBlobUpdate = (value) => {
+ form.storageBlobDTO = value || []
}
// 鑾峰彇褰撳墠浣嶇疆
const getCurrentLocation = () => {
+ // 妫�鏌ョ粍浠舵槸鍚﹁繕瀛樺湪
+ if (isRequestCancelled) return
+
locationLoading.value = true
uni.showLoading({ title: '鑾峰彇浣嶇疆涓�...' })
uni.getLocation({
type: 'gcj02',
success: (res) => {
+ // 妫�鏌ョ粍浠舵槸鍚﹁繕瀛樺湪
+ 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
@@ -303,6 +211,12 @@
}
},
fail: (err) => {
+ // 妫�鏌ョ粍浠舵槸鍚﹁繕瀛樺湪
+ if (isRequestCancelled) {
+ uni.hideLoading()
+ return
+ }
+
uni.hideLoading()
locationLoading.value = false
console.error('閫嗗湴鐞嗙紪鐮佸け璐�:', err)
@@ -318,6 +232,12 @@
})
},
fail: (err) => {
+ // 妫�鏌ョ粍浠舵槸鍚﹁繕瀛樺湪
+ if (isRequestCancelled) {
+ uni.hideLoading()
+ return
+ }
+
uni.hideLoading()
locationLoading.value = false
uni.showToast({
@@ -335,15 +255,11 @@
// 鎵撳紑寮规
const openDialog = async (row) => {
console.log('寮规鎺ユ敹鍒扮殑鏁版嵁:', row)
- console.log('寮规鎵撳紑鍓嶇姸鎬�:', dialogVisitable.value)
-
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('寮规鎵撳紑鍚庣姸鎬�:', dialogVisitable.value)
console.log('寮规琛ㄥ崟鏁版嵁:', form)
// 寮哄埗鏇存柊瑙嗗浘
@@ -354,6 +270,9 @@
// 鎻愪氦琛ㄥ崟
const submitForm = async () => {
try {
+ // 妫�鏌ョ粍浠舵槸鍚﹁繕瀛樺湪
+ if (isRequestCancelled) return
+
console.log('寮�濮嬫彁浜よ〃鍗曪紝褰撳墠琛ㄥ崟鏁版嵁:', form)
// 琛ㄥ崟楠岃瘉
@@ -389,15 +308,27 @@
scannerName: form.scannerName,
scannerId: form.scannerId,
scanTime: form.scanTime,
- storageBlobDTO: form.storageBlobDTO,
+ 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 || form.qrCode.id
+ id: form.qrCodeId
}
}
console.log('鍑嗗鎻愪氦鐨勬暟鎹�:', submitData)
const response = await addOrEditQrCodeRecord(submitData)
+
+ // 妫�鏌ョ粍浠舵槸鍚﹁繕瀛樺湪
+ if (isRequestCancelled) return
+
console.log('鎻愪氦鍝嶅簲:', response)
uni.showToast({
@@ -407,6 +338,9 @@
cancel()
} catch (error) {
+ // 妫�鏌ョ粍浠舵槸鍚﹁繕瀛樺湪
+ if (isRequestCancelled) return
+
console.error('鎻愪氦澶辫触:', error)
// 鏄剧ず鏇磋缁嗙殑閿欒淇℃伅
@@ -430,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>
@@ -491,12 +444,5 @@
.upload-container {
width: 100%;
-}
-
-.upload-actions {
- display: flex;
- justify-content: flex-start;
- margin-top: 10px;
- gap: 10px;
}
</style>
--
Gitblit v1.9.3