index.vue 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. <template>
  2. <view class="content">
  3. <view class="status_bar"><!-- 这里是状态栏 --></view>
  4. <web-view :src="url" :fullscreen='false'></web-view>
  5. </view>
  6. </template>
  7. <script>
  8. var wv
  9. export default {
  10. data() {
  11. return {
  12. title: 'ByteSailing',
  13. url: 'http://139.159.251.109:82/#/',
  14. //url: 'http://36.134.91.96:10008/#/',
  15. //url: 'http://36.134.91.96:10007/#/',
  16. //ehsd测试
  17. //url:'http://139.9.102.170:10009/#/',
  18. //ehsd正式
  19. //url:'http://139.9.102.170:10010/#/',
  20. //本地调试
  21. //url:'http://192.168.1.18:8088/',
  22. src: "",
  23. canBack: false,
  24. }
  25. },
  26. onBackPress() {
  27. if (wv && this.canBack) {
  28. wv.back();
  29. return true;
  30. }
  31. return false;
  32. },
  33. onReady() {
  34. // #ifdef APP-PLUS
  35. var self = this;
  36. var currentWebview = this.$scope.$getAppWebview();
  37. //此对象相当于html5plus里的plus.webview.currentWebview()。在uni-app里vue页面直接使用plus.webview.currentWebview()无效,非v3编译模式使用this.$mp.page.$getAppWebview()
  38. setTimeout(function() {
  39. wv = currentWebview.children()[0];
  40. wv.addEventListener(
  41. "progressChanged",
  42. function(e) {
  43. wv.canBack(function(e) {
  44. self.canBack = e.canBack;
  45. });
  46. },
  47. false
  48. );
  49. }, 500); //如果是页面初始化调用时,需要延时一下
  50. // #endif
  51. },
  52. onLoad() {
  53. var height = 0; //定义动态的高度变量,如高度为定值,可以直接写
  54. uni.getSystemInfo({
  55. //成功获取的回调函数,返回值为系统信息
  56. success: (sysinfo) => {
  57. height = sysinfo.windowHeight; //自行修改,自己需要的高度 此处如底部有其他内容,可以直接---(-50)这种
  58. },
  59. complete: () => {}
  60. });
  61. let info = uni.getSystemInfoSync();
  62. let top = info.statusBarHeight;
  63. var currentWebview = this.$scope.$getAppWebview(); //获取当前web-view
  64. setTimeout(function() {
  65. var wv = currentWebview.children()[0];
  66. wv.setStyle({ //设置web-view距离顶部的距离以及自己的高度,单位为px
  67. top: top, //此处是距离顶部的高度,应该是你页面的头部
  68. // bottom:0,//防止输入框被软键盘遮挡
  69. height: height - top, //webview的高度
  70. scalable: false, //webview的页面是否可以缩放,双指放大缩小
  71. })
  72. // wx.setTitleNViewButtonStyle({
  73. // index:0,
  74. // styles:{
  75. // type:'back'
  76. // }
  77. // })
  78. }, 1000);
  79. methods: {
  80. }
  81. }
  82. }
  83. </script>
  84. <style>
  85. .content {}
  86. .status_bar {
  87. height: var(--status-bar-height);
  88. width: 100%;
  89. }
  90. </style>sss