webLink.vue 945 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. <route lang="json5" type="page">
  2. {
  3. layout: 'default',
  4. style: {
  5. navigationBarTitleText: '',
  6. navigationBarBackgroundColor: '#fff'
  7. }
  8. }
  9. </route>
  10. <script setup>
  11. import { t } from '@/locale'
  12. const params = ref({})
  13. function openInNewTabAndClose(url) {
  14. try {
  15. if (typeof window !== 'undefined') {
  16. const win = window.open(url, '_blank')
  17. if (!win)
  18. window.location.href = url
  19. }
  20. }
  21. finally {
  22. uni.navigateBack()
  23. }
  24. }
  25. onLoad((options) => {
  26. params.value = options
  27. params.value.link = decodeURIComponent(params.value.link)
  28. // #ifdef H5
  29. if (typeof params.value.link === 'string' && params.value.link.startsWith('http://')) {
  30. openInNewTabAndClose(params.value.link)
  31. return
  32. }
  33. // #endif
  34. uni.setNavigationBarTitle({
  35. title: decodeURIComponent(params.value.title) || t('webLink.title'),
  36. })
  37. })
  38. </script>
  39. <template>
  40. <web-view :update-title="false" :src="params.link" />
  41. </template>