修改webview

This commit is contained in:
tangxinyue 2026-04-30 15:26:27 +08:00
parent 1601a3e4ae
commit 3586dc4a35
5 changed files with 304 additions and 285 deletions

16
App.vue
View File

@ -1,11 +1,11 @@
<script> <script>
export default { export default {
globalData: { globalData: {
NativeEvent: true, NativeEvent: true,
recentNativeEvent: "", // recentNativeEvent: "", //
recentNativeData: 0 // recentNativeData: 0 //
}, },
onLaunch: function (options) { onLaunch: function(options) {
// console.log=()=>{} // console.log=()=>{}
// === wgt === // === wgt ===
@ -50,15 +50,15 @@ export default {
}) })
}, },
onShow: function () { onShow: function() {
console.log('App Show') console.log('App Show')
// onLaunch // onLaunch
}, },
onHide: function () { onHide: function() {
console.log('App Hide') console.log('App Hide')
}, },
onExit: function () { onExit: function() {
// //
// #ifdef APP // #ifdef APP
// plus.sqlite.closeDatabase({ name: 'zyds' }) // plus.sqlite.closeDatabase({ name: 'zyds' })
@ -183,7 +183,9 @@ export default {
// //
const devConfig = { const devConfig = {
host: "https://flaunt.batiao8.com/", host: "https://flaunt.batiao8.com/",
header: { "x-token": "da884e6e-fbd7-4d8d-ab0e-cb7b07f9f6fa" }, header: {
"x-token": "ebe42caa-845a-4cb2-a324-18abe8ced7c0"
},
decrypt: "e4rOtnF8tJjtHO7ecZeJHN1rapED5ImB", decrypt: "e4rOtnF8tJjtHO7ecZeJHN1rapED5ImB",
encrypt: "xn08hYoizXhZ1zHP8DVqfCm2yHxPmhil" encrypt: "xn08hYoizXhZ1zHP8DVqfCm2yHxPmhil"
} }
@ -195,7 +197,7 @@ export default {
console.log('默认配置初始化完成') console.log('默认配置初始化完成')
} }
} }
} }
</script> </script>
<style> <style>

View File

@ -29,7 +29,7 @@ export function createApp() {
app.config.globalProperties.$system = plus.os.name; app.config.globalProperties.$system = plus.os.name;
// #endif // #endif
app.config.globalProperties.$systemInfo = systemInfo app.config.globalProperties.$systemInfo = systemInfo
uni.setStorageSync('version', '1.0.4.sp21') uni.setStorageSync('version', '1.0.4.sp23')
app.config.globalProperties.$version = uni.getStorageSync('version') app.config.globalProperties.$version = uni.getStorageSync('version')
app.use(globalMethods); app.use(globalMethods);
return { return {

View File

@ -1,18 +1,24 @@
<!-- pages/webview/webview.vue --> <!-- pages/webview/webview.vue -->
<template> <template>
<view class="webview-container"> <view class="webview-container">
<navBar class="nav-bar" :title="pageTitle" :bgColor="data.navBar.bgColor" isBack></navBar> <navBar class="nav-bar" :title="pageTitle" :bgColor="data.navBar.bgColor" isBack>
<template v-if="isClose" v-slot:right>
<image style="width:22px;height: 22px;" src='/static/image/close.png' @click="onConfirm()"></image>
</template>
</navBar>
<web-view :src="url" :webview-styles="webviewStyles"></web-view> <web-view :src="url" :webview-styles="webviewStyles"></web-view>
</view> </view>
</template> </template>
<script setup> <script setup>
// //
// import ZdyNavbar from "@/components/navbar/navbar.vue" // import ZdyNavbar from "@/components/navbar/navbar.vue"
import navBar from '@/components/nav-bar/nav-bar.vue' import navBar from '@/components/nav-bar/nav-bar.vue'
import { util } from '@/utils/common.js' import {
util
} from '@/utils/common.js'
import { import {
ref, ref,
reactive, reactive,
watch, watch,
@ -22,14 +28,14 @@ import {
onBeforeUnmount, onBeforeUnmount,
toRefs, toRefs,
computed computed
} from "vue"; } from "vue";
import { import {
onLoad, onLoad,
onReady, onReady,
onShow onShow
} from '@dcloudio/uni-app' } from '@dcloudio/uni-app'
const data = reactive({ const data = reactive({
navBar: { navBar: {
title: "", title: "",
bgColor: '#ffffff', bgColor: '#ffffff',
@ -37,16 +43,21 @@ const data = reactive({
dark: "dark", dark: "dark",
// //
systemBarHeight: "0", systemBarHeight: "0",
}) isClose: false
})
let { let {
systemBarHeight systemBarHeight,
} = toRefs(data) isClose
} = toRefs(data)
const url = ref('') const url = ref('')
const pageTitle = ref('') const pageTitle = ref('')
onLoad((options) => { onLoad((options) => {
if (options.isClose) {
isClose.value = options.isClose
}
uni.getSystemInfo({ uni.getSystemInfo({
success: res => { success: res => {
systemBarHeight.value = res.statusBarHeight; // systemBarHeight.value = res.statusBarHeight; //
@ -70,65 +81,71 @@ onLoad((options) => {
console.log("标题", options.title); console.log("标题", options.title);
pageTitle.value = decodeURIComponent(options.title) pageTitle.value = decodeURIComponent(options.title)
} }
}) })
onShow(() => { onShow(() => {
// #ifdef APP-PLUS // #ifdef APP-PLUS
util.setAndroidSystemBarColor('#ffffff') util.setAndroidSystemBarColor('#ffffff')
setTimeout(() => { setTimeout(() => {
plus.navigator.setStatusBarStyle("dark"); plus.navigator.setStatusBarStyle("dark");
}, 500); }, 500);
// #endif // #endif
}) })
const goBack = () => { const onConfirm = () => {
uni.reLaunch({
url: '/pages/index/index'
})
}
const goBack = () => {
uni.navigateBack() uni.navigateBack()
} }
const isVideo = computed(() => { const isVideo = computed(() => {
if (!url.value) return false if (!url.value) return false
const videoExps = [/\.mp4$/i, /\.m3u8$/i, /\.flv$/i, /\.avi$/i, /\.mov$/i, /\.wmv$/i, /\.webm$/i, const videoExps = [/\.mp4$/i, /\.m3u8$/i, /\.flv$/i, /\.avi$/i, /\.mov$/i, /\.wmv$/i, /\.webm$/i,
/\.mkv$/i /\.mkv$/i
]; ];
return videoExps.some(exp => exp.test(url.value)); return videoExps.some(exp => exp.test(url.value));
}) })
const webviewStyles = computed(() => { const webviewStyles = computed(() => {
return { return {
top: `${Number(systemBarHeight.value) + 40}px`, top: `${Number(systemBarHeight.value) + 40}px`,
bottom: '0px', bottom: '0px',
'padding-bottom': '20px' 'padding-bottom': '20px'
} }
}) })
</script> </script>
<style scoped> <style scoped>
.webview-container { .webview-container {
flex: 1; flex: 1;
display: flex; display: flex;
flex-direction: column; flex-direction: column;
} }
.header { .header {
padding: 20rpx; padding: 20rpx;
background: #fff; background: #fff;
border-bottom: 1rpx solid #eee; border-bottom: 1rpx solid #eee;
} }
.title { .title {
font-size: 32rpx; font-size: 32rpx;
font-weight: bold; font-weight: bold;
text-align: center; text-align: center;
} }
.video-web { .video-web {
position: fixed; position: fixed;
width: 100%; width: 100%;
background-color: #000; background-color: #000;
} }
</style> </style>
<style> <style>
page { page {
background-color: #ffffff; background-color: #ffffff;
} }
</style> </style>

View File

@ -529,7 +529,7 @@ const clickNotice = () => {
console.log("点击公告", noticeInfo.value) console.log("点击公告", noticeInfo.value)
if (!noticeInfo.value.url) return if (!noticeInfo.value.url) return
const url = noticeInfo.value.url + `&uni_id=${userInfo.value.user_id}` const url = noticeInfo.value.url + `&uni_id=${userInfo.value.user_id}`
util.goPage(`/pages/common/webview/webview?url=${encodeURIComponent(url)}&title=${noticeInfo.value.title}`) util.goPage(`/pages/common/webview/webview?url=${encodeURIComponent(url)}&title=${noticeInfo.value.title}&isClose=${true}`)
} }
/** /**

BIN
static/image/close.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 339 B