web-view.uvue 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. <script setup lang='ts'>
  2. import { ref, onMounted } from 'vue'
  3. import Loading from '@/components/loading.uvue'
  4. import { router } from '@/.cool'
  5. const progress = ref(1)
  6. const webviewSrc = ref('')
  7. const showWebview = ref(false)
  8. var isLoading = ref(true)
  9. onMounted(() => {
  10. const t = Date.now()
  11. webviewSrc.value = router.query().src + '?t=' + t
  12. progress.value = router.query().progress
  13. showWebview.value = true
  14. })
  15. function handleMessage(e) {
  16. var pages = getCurrentPages();
  17. const prevPage = pages[pages.length - 2];
  18. (prevPage as any).status = "success"
  19. }
  20. function handleLoad() {
  21. isLoading.value = false
  22. }
  23. function onWebError() {
  24. const t = Date.now()
  25. webviewSrc.value = router.query().src + '?t=' + t
  26. console.log('onWebError')
  27. }
  28. // iOS WKWebView 在页面销毁后音频不会自动停止,需要先销毁 webview
  29. onUnload(() => {
  30. showWebview.value = false
  31. webviewSrc.value = ''
  32. })
  33. </script>
  34. <template>
  35. <Loading v-show="isLoading" />
  36. <web-view v-if="showWebview" :src="webviewSrc" id="web-view" class="w-full h-full" @message="handleMessage"
  37. @load="handleLoad" @error="onWebError"></web-view>
  38. </template>
  39. <style lang="less" scoped></style>