pdf.vue 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. <template>
  2. <hc-new-card>
  3. <template #extra>
  4. <el-button type="primary" @click="goBack">
  5. <HcIcon name="close" />
  6. 关闭
  7. </el-button>
  8. </template>
  9. <hc-pdf :src="pdfUrl" :download="isDownload" :print="isPrint" />
  10. </hc-new-card>
  11. </template>
  12. <script setup>
  13. import { isNullES } from 'js-fast-way'
  14. import { onActivated, ref } from 'vue'
  15. import { useRoute } from 'vue-router'
  16. import { btnAuth, decode } from '~uti/btn-auth'
  17. import router from '~src/router/index'
  18. //初始变量
  19. const useRoutes = useRoute()
  20. const isDownload = ref(btnAuth('client-pdf-download'))
  21. const isPrint = ref(btnAuth('client-pdf-print'))
  22. defineOptions({
  23. name: 'Pdf',
  24. })
  25. //渲染完成
  26. const pdfUrl = ref('')
  27. onActivated(() => {
  28. const { url, code } = useRoutes.query
  29. //如果url和code都为空,不做处理
  30. if (isNullES(url) && isNullES(code)) {
  31. return
  32. }
  33. //如果url不为空,code为空,以url为准
  34. if (!isNullES(url) && isNullES(code)) {
  35. pdfUrl.value = url
  36. return
  37. }
  38. //如果url为空,code不为空,以code为准
  39. if (isNullES(url) && !isNullES(code)) {
  40. pdfUrl.value = decode(code ?? '')
  41. return
  42. }
  43. //两个都有的情况下,以code为准
  44. pdfUrl.value = decode(code ?? '')
  45. })
  46. const goBack = ()=>{
  47. router.back()
  48. }
  49. </script>