| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263 |
- <template>
- <view class="web-view-page">
- <web-view v-if="webViewUrl" :src="webViewUrl" />
- </view>
- </template>
- <script setup lang="ts">
- import { ref } from 'vue'
- import { onLoad } from '@dcloudio/uni-app'
- interface PageQuery {
- url?: string
- title?: string
- }
- const DEFAULT_TITLE = '详情'
- const webViewUrl = ref('')
- const safeDecodeURIComponent = (value: string): string => {
- try {
- return decodeURIComponent(value)
- } catch (error) {
- console.error('decodeURIComponent error:', error)
- return value
- }
- }
- const setPageTitle = (title?: string): void => {
- const pageTitle = title ? safeDecodeURIComponent(title) : DEFAULT_TITLE
- uni.setNavigationBarTitle({
- title: pageTitle,
- })
- }
- onLoad((query?: PageQuery) => {
- setPageTitle(query?.title)
- if (!query?.url) {
- uni.showToast({
- title: '链接地址不存在',
- icon: 'none',
- })
- uni.navigateBack({
- delta: 1,
- })
- return
- }
- webViewUrl.value = safeDecodeURIComponent(query.url)
- })
- </script>
- <style lang="scss" scoped>
- .web-view-page {
- width: 100%;
- height: 100vh;
- }
- </style>
|