diff --git a/global.types/components.d.ts b/global.types/components.d.ts index c6c9f73..e7d0f23 100644 --- a/global.types/components.d.ts +++ b/global.types/components.d.ts @@ -53,5 +53,6 @@ declare module 'vue' { } export interface GlobalDirectives { vInfiniteScroll: typeof import('element-plus/es')['ElInfiniteScroll'] + vLoading: typeof import('element-plus/es')['ElLoadingDirective'] } } diff --git a/src/views/engineering/config/index.vue b/src/views/engineering/config/index.vue index 09bca7a..ffec9f1 100644 --- a/src/views/engineering/config/index.vue +++ b/src/views/engineering/config/index.vue @@ -43,7 +43,12 @@ 上一步 - + 下一步 完成保存配置
-
+
{ } } +const nextStepLoading = ref(false) + const nextStep = async () => { + nextStepLoading.value = true const index = steps.indexOf(currentStep.value) if (currentStep.value === 'channel') { await saveChannelList() @@ -207,12 +219,16 @@ const nextStep = async () => { if (currentComponentRef.value?.checkBeforeLeave) { const canLeave = await currentComponentRef.value.checkBeforeLeave() - if (!canLeave) return + if (!canLeave) { + nextStepLoading.value = false + return + } } if (index < steps.length - 1) { currentStep.value = steps[index + 1] } + nextStepLoading.value = false } /* @@ -288,11 +304,13 @@ async function loadDeviceList() { if (isObject(res.data)) devices.value = res.data } +const pageLoading = ref(true) onMounted(async () => { if (!isCreate.value) { await loadChannelList() await loadDeviceList() await loadCategoryList() + pageLoading.value = false } }) diff --git a/src/views/engineering/index.vue b/src/views/engineering/index.vue index 6286d91..2afc0ed 100644 --- a/src/views/engineering/index.vue +++ b/src/views/engineering/index.vue @@ -82,18 +82,43 @@ function enterEngineering(item: IEngineeringOV) { }) } -function handleDownload(item: IEngineeringOV) { +// function handleDownload(item: IEngineeringOV) { +// if (!item.downloadPath) { +// ElMessage.warning('下载地址为空') +// return +// } +// const link = document.createElement('a') +// link.style.display = 'none' +// link.href = item.downloadPath +// link.setAttribute('download', item.name) +// document.body.appendChild(link) +// link.click() +// document.body.removeChild(link) +// } + +async function handleDownload(item: IEngineeringOV) { if (!item.downloadPath) { - ElMessage.warning('下载地址为空') + ElMessage.warning('请完成工程配置!') return } - const link = document.createElement('a') - link.style.display = 'none' - link.href = item.downloadPath - link.setAttribute('download', item.name) - document.body.appendChild(link) - link.click() - document.body.removeChild(link) + try { + const res = await fetch(item.downloadPath) + if (!res.ok) { + throw new Error('Network response was not ok') + } + const blob = await res.blob() + const link = document.createElement('a') + link.style.display = 'none' + link.href = URL.createObjectURL(blob) + link.download = item.name + document.body.appendChild(link) + link.click() + document.body.removeChild(link) + URL.revokeObjectURL(link.href) + } catch (error) { + ElMessage.error('下载失败,请检查网络或联系管理员') + console.error('Download failed:', error) + } }