| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849 |
- <template>
- <web-view :src="webviewUrl" @message="handleMessage"></web-view>
- </template>
- <script setup>
- import { ref } from 'vue';
- import { onReady } from '@dcloudio/uni-app';
- import config from '@/config.js'; // 引入配置文件
- const token = uni.getStorageSync('token') || '';
- const webviewUrl = ref('');
- const statusBarHeight = uni.getSystemInfoSync().statusBarHeight || 0;
- onReady(() => {
- getApiBaseUrl();
- // #ifdef APP-PLUS
- // fixWebviewPosition();
- // // 子 webview 异步创建,等它创建完再设
- // setTimeout(fixWebviewPosition, 800);
- // setTimeout(fixWebviewPosition, 1500); // 兜底防框架重置
- // #endif
- });
- const fixWebviewPosition = () => {
- const pages = getCurrentPages();
- const page = pages[pages.length - 1];
- const pageWebview = page?.$getAppWebview?.();
-
- const info = uni.getSystemInfoSync();
- const statusBarHeight = info.statusBarHeight || 0;
- const screenHeight = info.screenHeight || 0;
- const children = pageWebview?.children?.() || [];
- const wv = children[0];
- if (!wv) return;
- wv.setStyle({
- top: statusBarHeight,
- // 固定基准:webview 原本全屏,高度就是 screenHeight,只减一次状态栏
- height: screenHeight - statusBarHeight
- });
- };
- //上传接口地址
- const getApiBaseUrl = () => {
- let basUrl = config.basUrl;//${encodeURIComponent(token)}
- webviewUrl.value = `${basUrl}/studentapp/#/pages/login/index?appName=studentApp&statusBarHeight=${statusBarHeight}`;
- }
- const handleMessage = () => {
-
- }
- </script>
- <style>
- </style>
|