Ver Fonte

测试苹果交互退回问题

guarantee-lsq há 15 horas atrás
pai
commit
ff3ca5ed52
2 ficheiros alterados com 18 adições e 10 exclusões
  1. 9 7
      pages/catalog/web-view.uvue
  2. 9 3
      pages/programming/web-view.uvue

+ 9 - 7
pages/catalog/web-view.uvue

@@ -1,13 +1,15 @@
 <script setup lang='ts'>
-import { ref, onMounted, watchEffect } from 'vue'
+import { ref, onMounted, onUnload } from 'vue'
 import Loading from '@/components/loading.uvue'
 import { router } from '@/.cool'
 const progress = ref(1)
 const webviewSrc = ref('')
+const showWebview = ref(false)
 var isLoading = ref(true)
 onMounted(() => {
   webviewSrc.value = router.query().src
   progress.value = router.query().progress
+  showWebview.value = true
 })
 
 function handleMessage(e) {
@@ -24,15 +26,15 @@ function onWebError() {
   webviewSrc.value = router.query().src + '?t=' + t
   console.log('onWebError')
 }
-onShow(() => {
-  var pages = getCurrentPages();
-  const prevPage = pages[pages.length - 2];
-  (prevPage as any).status = "test"
+// iOS WKWebView 在页面销毁后音频不会自动停止,需要先销毁 webview
+onUnload(() => {
+  showWebview.value = false
+  webviewSrc.value = ''
 })
 </script>
 <template>
   <Loading v-show="isLoading" />
-  <web-view :src="webviewSrc" id="web-view" class="w-full h-full" @message="handleMessage" @load="handleLoad"
-    @error="onWebError"></web-view>
+  <web-view v-if="showWebview" :src="webviewSrc" id="web-view" class="w-full h-full" @message="handleMessage"
+    @load="handleLoad" @error="onWebError"></web-view>
 </template>
 <style lang="less" scoped></style>

+ 9 - 3
pages/programming/web-view.uvue

@@ -1,11 +1,11 @@
 <script setup lang='ts'>
-import { ref, onMounted, watchEffect } from 'vue'
+import { ref, onMounted, onUnload } from 'vue'
 import Loading from '@/components/loading.uvue'
 import { router, user } from '@/.cool'
-import Back from '@/components/back.uvue'
 // const baseUrl = ref('http://192.168.110.102:8601')
 const baseUrl = ref('https://oss.xiaoxiongcode.com/gui/index.html')
 const webviewSrc = ref('')
+const showWebview = ref(false)
 
 var isLoading = ref(true)
 
@@ -23,12 +23,18 @@ onMounted(() => {
   } else {
     webviewSrc.value = baseUrl.value + '?token=' + user.token + '&userId=' + user.info.value?.userInfo.userId
   }
+  showWebview.value = true
+})
 
+// iOS WKWebView 在页面销毁后音频不会自动停止,需要先销毁 webview
+onUnload(() => {
+  showWebview.value = false
+  webviewSrc.value = ''
 })
 </script>
 <template>
   <Loading v-show="isLoading" />
-  <web-view id="webView1" :src="webviewSrc" class="w-full h-full" @load="handleLoad"
+  <web-view v-if="showWebview" id="webView1" :src="webviewSrc" class="w-full h-full" @load="handleLoad"
     @message="handleMessage"></web-view>
 </template>
 <style lang="less" scoped></style>