studentApp.vue 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. <template>
  2. <web-view :src="webviewUrl" @message="handleMessage"></web-view>
  3. </template>
  4. <script setup>
  5. import { ref } from 'vue';
  6. import { onReady } from '@dcloudio/uni-app';
  7. import config from '@/config.js'; // 引入配置文件
  8. const token = uni.getStorageSync('token') || '';
  9. const webviewUrl = ref('');
  10. const statusBarHeight = uni.getSystemInfoSync().statusBarHeight || 0;
  11. onReady(() => {
  12. getApiBaseUrl();
  13. // #ifdef APP-PLUS
  14. // fixWebviewPosition();
  15. // // 子 webview 异步创建,等它创建完再设
  16. // setTimeout(fixWebviewPosition, 800);
  17. // setTimeout(fixWebviewPosition, 1500); // 兜底防框架重置
  18. // #endif
  19. });
  20. const fixWebviewPosition = () => {
  21. const pages = getCurrentPages();
  22. const page = pages[pages.length - 1];
  23. const pageWebview = page?.$getAppWebview?.();
  24. const info = uni.getSystemInfoSync();
  25. const statusBarHeight = info.statusBarHeight || 0;
  26. const screenHeight = info.screenHeight || 0;
  27. const children = pageWebview?.children?.() || [];
  28. const wv = children[0];
  29. if (!wv) return;
  30. wv.setStyle({
  31. top: statusBarHeight,
  32. // 固定基准:webview 原本全屏,高度就是 screenHeight,只减一次状态栏
  33. height: screenHeight - statusBarHeight
  34. });
  35. };
  36. //上传接口地址
  37. const getApiBaseUrl = () => {
  38. let basUrl = config.basUrl;//${encodeURIComponent(token)}
  39. webviewUrl.value = `${basUrl}/studentapp/#/pages/login/index?appName=studentApp&statusBarHeight=${statusBarHeight}`;
  40. }
  41. const handleMessage = () => {
  42. }
  43. </script>
  44. <style>
  45. </style>