index.vue 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. <template>
  2. <view class='app-container'>
  3. <web-view v-if="PageCur == 'tun2D'" src="http://192.168.10.104:8088" @message="handleMessage"></web-view>
  4. <Device v-if="PageCur == 'device'"/>
  5. <filecenter
  6. :cur="PageCur"
  7. v-if="PageCur == 'filecenter'"
  8. ></filecenter>
  9. <warndata
  10. v-if="PageCur == 'warndata'"
  11. :cur="PageCur"
  12. ></warndata>
  13. <u-tabbar
  14. :value="PageCur"
  15. @change="NavChange"
  16. :fixed="true"
  17. :placeholder="true"
  18. :safeAreaInsetBottom="true"
  19. >
  20. <u-tabbar-item
  21. text="通风系统图"
  22. name="tun2D"
  23. icon="list-dot"
  24. ></u-tabbar-item>
  25. <u-tabbar-item
  26. text="设备中心"
  27. name="device"
  28. icon="calendar"
  29. ></u-tabbar-item>
  30. <u-tabbar-item
  31. text="预警分析"
  32. name="warndata"
  33. icon="plus-circle"
  34. ></u-tabbar-item>
  35. <u-tabbar-item
  36. text="文件共享"
  37. name="filecenter"
  38. icon="file-text"
  39. ></u-tabbar-item>
  40. </u-tabbar>
  41. </view>
  42. </template>
  43. <script>
  44. import Device from '../device/index.vue'
  45. export default {
  46. components: {
  47. Device,
  48. },
  49. data() {
  50. return {
  51. PageCur: "tun2D",
  52. tun3DPage: null,
  53. wv: null, // 定义(app)webview对象节点
  54. webV:{}, // 定义(H5)webview对象节点
  55. };
  56. },
  57. onLoad: function () {
  58. this.PageCur = "tun2D";
  59. },
  60. mounted:function(){
  61. this.changeWV()
  62. },
  63. onResize(){
  64. let _this = this
  65. uni.getSystemInfo({
  66. success: function(res) {
  67. if (res.windowWidth > res.windowHeight) {
  68. // 横屏
  69. // _this.isLandScape = true
  70. console.log('横屏')
  71. _this.changeWV(true)
  72. } else {
  73. // 竖屏
  74. // _this.isLandScape = false
  75. console.log('竖屏')
  76. _this.changeWV(false)
  77. }
  78. }
  79. })
  80. },
  81. methods: {
  82. NavChange: function (e) {
  83. this.PageCur = e;
  84. if(e == 'tun2D'){
  85. this.changeWV()
  86. }
  87. },
  88. handleMessage(e) {
  89. },
  90. // 发送消息到 HTML
  91. sendRequestData(res) {
  92. const _this = this
  93. let param = {type:'orientationchange'}
  94. // App端
  95. // #ifdef APP-PLUS
  96. // 页面栈最顶层就是当前webview
  97. let currentWebview = _this.$scope.$getAppWebview();
  98. _this.wv = currentWebview.children()[0]
  99. this.wv.evalJS(`requestData(${param})`);
  100. // #endif
  101. // H5端
  102. // #ifdef H5
  103. window.addEventListener('message',e => {
  104. _this.webV = e.source // window的对象
  105. console.log(e.data.data.arg,'接收h5页面发来的消息'); // 接收h5页面发来的消息(11) ====>H5端
  106. },false)
  107. if(this.webV.postMessage){
  108. this.webV.postMessage(param)
  109. }
  110. // #endif
  111. },
  112. changeWV(isLandScape) {
  113. const _this = this
  114. let height = 0; // 动态高度变量
  115. let width = 0; // 动态高度变量
  116. let statusbar = 0; // 动态状态栏高度
  117. uni.getSystemInfo({ // 获取当前设备的具体信息
  118. success: (sysinfo) => {
  119. statusbar = isLandScape ? 0 : sysinfo.statusBarHeight + 20;
  120. height = isLandScape ? sysinfo.windowHeight - sysinfo.statusBarHeight - 20 : sysinfo.windowHeight - sysinfo.statusBarHeight - sysinfo.statusBarHeight - 38;
  121. width = isLandScape ? sysinfo.windowWidth : sysinfo.windowWidth
  122. let currentWebview = _this.$scope.$getAppWebview(); // 获取当前web-view
  123. if(currentWebview){
  124. var wv = currentWebview.children()[0]; // 获取web-view的子节点(即需要设置样式的元素)
  125. wv.setStyle({ // 设置web-view距离顶部的距离以及自己的高度,单位为px
  126. top: statusbar, // 距离顶部的高度,应该是你页面的头部
  127. height: height ,// webview的高度
  128. width: width
  129. });
  130. wv.reload()
  131. console.log( width, height, statusbar)
  132. // _this.sendRequestData([], 1)
  133. }
  134. }
  135. });
  136. }
  137. },
  138. };
  139. </script>
  140. <style>
  141. .app-container{
  142. width: 100%;
  143. height: 100%;
  144. padding-left: 10rpx;
  145. padding-right: 10rpx;
  146. }
  147. .tun3D-box{
  148. }
  149. </style>