|
@@ -1,17 +1,18 @@
|
|
|
<template>
|
|
<template>
|
|
|
- <view>
|
|
|
|
|
- <web-view v-if="url" :src="url" />
|
|
|
|
|
|
|
+ <view class="webview-page">
|
|
|
|
|
+ <web-view v-if="url" :key="webviewKey" :src="url" />
|
|
|
</view>
|
|
</view>
|
|
|
</template>
|
|
</template>
|
|
|
|
|
|
|
|
<script setup lang="ts">
|
|
<script setup lang="ts">
|
|
|
import { ref } from 'vue'
|
|
import { ref } from 'vue'
|
|
|
-import { onLoad } from '@dcloudio/uni-app'
|
|
|
|
|
|
|
+import { onLoad, onShow } from '@dcloudio/uni-app'
|
|
|
|
|
|
|
|
const FALLBACK_PAGE = '/pages/invoice-entry/index'
|
|
const FALLBACK_PAGE = '/pages/invoice-entry/index'
|
|
|
const MAX_DECODE_TIMES = 3
|
|
const MAX_DECODE_TIMES = 3
|
|
|
|
|
|
|
|
const url = ref('')
|
|
const url = ref('')
|
|
|
|
|
+const webviewKey = ref('')
|
|
|
|
|
|
|
|
const redirectToFallback = (): void => {
|
|
const redirectToFallback = (): void => {
|
|
|
uni.redirectTo({
|
|
uni.redirectTo({
|
|
@@ -29,11 +30,9 @@ const safeDecode = (value: string, maxTimes = MAX_DECODE_TIMES): string => {
|
|
|
for (let i = 0; i < maxTimes; i += 1) {
|
|
for (let i = 0; i < maxTimes; i += 1) {
|
|
|
try {
|
|
try {
|
|
|
const decoded = decodeURIComponent(result)
|
|
const decoded = decodeURIComponent(result)
|
|
|
-
|
|
|
|
|
if (decoded === result) {
|
|
if (decoded === result) {
|
|
|
break
|
|
break
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
result = decoded
|
|
result = decoded
|
|
|
} catch (error) {
|
|
} catch (error) {
|
|
|
console.error('decode redirect failed:', error)
|
|
console.error('decode redirect failed:', error)
|
|
@@ -44,9 +43,7 @@ const safeDecode = (value: string, maxTimes = MAX_DECODE_TIMES): string => {
|
|
|
return result
|
|
return result
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-const isHttpUrl = (value: string): boolean => {
|
|
|
|
|
- return /^https?:\/\//i.test(value)
|
|
|
|
|
-}
|
|
|
|
|
|
|
+const isHttpUrl = (value: string): boolean => /^https?:\/\//i.test(value)
|
|
|
|
|
|
|
|
const resolveRedirectUrl = (query: Record<string, unknown>): string => {
|
|
const resolveRedirectUrl = (query: Record<string, unknown>): string => {
|
|
|
const redirectRaw = getRedirectFromQuery(query)
|
|
const redirectRaw = getRedirectFromQuery(query)
|
|
@@ -65,12 +62,14 @@ const resolveRedirectUrl = (query: Record<string, unknown>): string => {
|
|
|
return ''
|
|
return ''
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- console.log('redirectRaw:', redirectRaw)
|
|
|
|
|
- console.log('redirectUrl:', redirectUrl)
|
|
|
|
|
-
|
|
|
|
|
return redirectUrl
|
|
return redirectUrl
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+const setWebviewUrl = (nextUrl: string): void => {
|
|
|
|
|
+ url.value = nextUrl
|
|
|
|
|
+ webviewKey.value = `${nextUrl}__${Date.now()}`
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
onLoad((query) => {
|
|
onLoad((query) => {
|
|
|
const redirectUrl = resolveRedirectUrl(query as Record<string, unknown>)
|
|
const redirectUrl = resolveRedirectUrl(query as Record<string, unknown>)
|
|
|
|
|
|
|
@@ -79,11 +78,24 @@ onLoad((query) => {
|
|
|
title: '链接参数错误',
|
|
title: '链接参数错误',
|
|
|
icon: 'none',
|
|
icon: 'none',
|
|
|
})
|
|
})
|
|
|
-
|
|
|
|
|
redirectToFallback()
|
|
redirectToFallback()
|
|
|
return
|
|
return
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- url.value = redirectUrl
|
|
|
|
|
|
|
+ setWebviewUrl(redirectUrl)
|
|
|
|
|
+})
|
|
|
|
|
+
|
|
|
|
|
+onShow(() => {
|
|
|
|
|
+ // 某些机型/场景下,页面返回后强制触发一次视图重建更稳
|
|
|
|
|
+ if (url.value && !webviewKey.value) {
|
|
|
|
|
+ webviewKey.value = `${url.value}__${Date.now()}`
|
|
|
|
|
+ }
|
|
|
})
|
|
})
|
|
|
</script>
|
|
</script>
|
|
|
|
|
+
|
|
|
|
|
+<style scoped>
|
|
|
|
|
+.webview-page {
|
|
|
|
|
+ width: 100%;
|
|
|
|
|
+ height: 100vh;
|
|
|
|
|
+}
|
|
|
|
|
+</style>
|