index.vue 2.6 KB

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