Browse Source

调整loading时机

cxmo 1 year ago
parent
commit
9443f683ae
1 changed files with 9 additions and 2 deletions
  1. 9 2
      src/views/report/PreviewPDF.vue

+ 9 - 2
src/views/report/PreviewPDF.vue

@@ -6,6 +6,7 @@ import { ElMessage,ElMessageBox, ElLoading } from 'element-plus';
 import {apiGetPDFDetail} from '@/api/report.js';
 import {apiUserInfo} from '@/api/user.js';
 import {useStore} from "vuex"
+import { fa } from 'element-plus/es/locale';
 
 const store = useStore()
 const route = useRoute();
@@ -17,15 +18,18 @@ const pdfState = reactive({
     pdf_name:''
 })
 let showHint = ref(true)
-let hasRight = ref(false)
+let hasRight = ref(true)
+let isLoading = ref(false)
 let hintText = ref('')
 const loadingFailed = ()=>{
     LOADING.close()
+    isLoading.value = false
     ElMessage.error('加载PDF失败!')
     showHint.value = true
 }
 const loadedPDF=()=>{
     LOADING.close()
+    isLoading.value = false
     showHint.value = false
     hintText.value = ''
 }
@@ -34,6 +38,7 @@ const getPDFDetail = (pdf_id)=>{
         ElMessage.error('未找到PDF')
         hintText.value="获取PDF失败"
         LOADING&&LOADING.close()
+        isLoading.value = false
         return
     }
     apiGetPDFDetail({pdf_id}).then(res=>{
@@ -64,6 +69,7 @@ const checkRight = async()=>{
         hasRight.value = true
     }else{
         LOADING&&LOADING.close()
+        isLoading.isLoading = false
         hasRight.value = false
     }
 }
@@ -100,6 +106,7 @@ onMounted(async ()=>{
         target:'.preview-pdf-wrap',
         text:'正在加载PDF'
     })
+    isLoading.value = true
     await checkRight()
     getPDFDetail(Number(route.query.pdf_id))
     //handleDataToXcx()
@@ -117,7 +124,7 @@ onMounted(async ()=>{
                 <span class="global-main-btn btn" @click="handleApply">立即申请</span>
             </div>
         </template>
-        <template v-else-if="pdfState.pdf_url.length">
+        <template v-else-if="pdfState.pdf_url.length&&!isLoading">
             <vue-pdf-embed :source="pdfState.pdf_url" @loading-failed="loadingFailed" @loaded="loadedPDF"/>
             <p v-if="showHint" class="hint">加载PDF失败!</p>
         </template>