index.vue 4.2 KB

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