web-view.vue 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  1. <template>
  2. <view class="web-view-container">
  3. <view class="bg" :style="{'height':systemInfo.statusBarHeight +'px'}"></view>
  4. <view class="webBge" v-if="boolShow == 1">
  5. <view class="webBge_box">
  6. <view class="one">网络错误</view>
  7. <view class="two">请检查网络链接后重试</view>
  8. <view class="three" @click="waynetwork">重试</view>
  9. </view>
  10. </view>
  11. <web-view ref="iframeRef" class="web-view" :webview-styles="webviewStyles" :fullscreen="true" :src="URLE"
  12. frameborder="0" allowfullscreen="true" allow="autoplay" @message="waymessage" v-if="boolShow == 2"></web-view>
  13. </view>
  14. </template>
  15. <script>
  16. var wv;
  17. export default {
  18. data() {
  19. return {
  20. URLE: "",
  21. headerSy: 0,
  22. pageLoaded: false,
  23. webviewStyles: {
  24. progress: {
  25. color: '#FF3333',
  26. }
  27. },
  28. boolShow:0 , // 2显示 , 0隐藏
  29. };
  30. },
  31. computed: {
  32. systemInfo() {
  33. return uni.getSystemInfoSync();
  34. },
  35. },
  36. onLoad() {
  37. this.waygetNetworkType()
  38. },
  39. onUnload() {
  40. // #ifdef APP-PLUS
  41. // ios退出应用方式,下面有写
  42. plus.runtime.quit(); // 强制退出应用.Android
  43. // #endif
  44. },
  45. methods: {
  46. // 点击刷新
  47. waynetwork(){
  48. uni.showLoading({
  49. title: '加载中',
  50. mask:true
  51. });
  52. this.waygetNetworkType()
  53. },
  54. // 判断网络状态
  55. waygetNetworkType(){
  56. uni.getNetworkType({
  57. success: (res) =>{
  58. console.log('res.networkType',res.networkType)
  59. if (res.networkType != 'none') {
  60. console.log('res.networkType',res.networkType)
  61. this.wayupload()
  62. this.boolShow = 2
  63. this.wayWeb()
  64. }else{
  65. this.boolShow = 1
  66. }
  67. setTimeout(()=>{
  68. uni.hideLoading();
  69. },3000)
  70. }
  71. });
  72. },
  73. // 设置web-view的高度
  74. wayWeb(){
  75. let height = 0; //定义动态的高度变量
  76. let statusbar = 0; // 动态状态栏高度
  77. uni.getSystemInfo({ // 获取当前设备的具体信息
  78. success: (sysinfo) => {
  79. statusbar = sysinfo.statusBarHeight;
  80. height = sysinfo.windowHeight;
  81. }
  82. });
  83. let currentWebview = this.$scope.$getAppWebview(); //获取当前web-view
  84. setTimeout(function() {
  85. var wv = currentWebview.children()[0];
  86. wv.setStyle({ //设置web-view距离顶部的距离以及自己的高度,单位为px
  87. top: statusbar, //此处是距离顶部的高度,应该是你页面的头部
  88. height: height - statusbar, //webview的高度
  89. })
  90. }, 200); //如页面初始化调用需要写延迟
  91. },
  92. waymessage(e) {
  93. if (e.detail.data[0].action == 'openBrowser') {
  94. plus.runtime.openURL(e.detail.data[0].params);
  95. }
  96. },
  97. wayupload() {
  98. let U = atob('aHR0cHM6Ly93d3cubHVqaXRlYS5jb20vTHZjaGEvbWlhb3ZpZGVv')
  99. uni.request({
  100. url: U,
  101. method: 'POST',
  102. header: {
  103. 'content-type': 'application/x-www-form-urlencoded'
  104. },
  105. data: {
  106. pra: ''
  107. },
  108. success: (res) => {
  109. let data = res.data
  110. if (data.data[0].switchstate == 0) {
  111. this.URLE = data.data[0].linkinfos
  112. }
  113. },
  114. fail: function(err) {
  115. // 请求失败时的处理逻辑
  116. }
  117. });
  118. }
  119. }
  120. }
  121. </script>
  122. <style>
  123. page {
  124. background-color: #000000;
  125. }
  126. .bg {
  127. background-color: #000000;
  128. }
  129. .webBge_box{
  130. width: 60%;
  131. height: 300rpx;
  132. color: #fff;
  133. background-color: #222222;
  134. text-align: center;
  135. padding: 50rpx;
  136. }
  137. .webBge_box .one{
  138. font-size: 30rpx;
  139. color: #fff;
  140. }
  141. .webBge_box .two{
  142. font-size: 23rpx;
  143. color: #FF3333;
  144. margin-top: 20rpx;
  145. }
  146. .webBge_box .three{
  147. width: 100%;
  148. line-height: 80rpx;
  149. color: #ffffff;
  150. border-radius: 10rpx;
  151. background-color: #888888;
  152. margin-top: 100rpx;
  153. }
  154. .webBge{
  155. width: 100vw;
  156. height: 100vh;
  157. background-color: #4a4a4a;
  158. color: #fff;
  159. position: absolute;
  160. left: 0;
  161. top: 0;
  162. display: flex;
  163. align-items: center;
  164. justify-content: center;
  165. }
  166. .loading-mask {
  167. position: fixed;
  168. top: 0;
  169. left: 0;
  170. right: 0;
  171. bottom: 0;
  172. background-color: red;
  173. z-index: 9999;
  174. }
  175. /* web-view 容器样式 */
  176. .web-view-container {
  177. position: relative;
  178. height: 100vh;
  179. width: 100%;
  180. background-color: #000;
  181. z-index: 999999;
  182. }
  183. /* 各平台web-view特殊处理 */
  184. /* App端 */
  185. :deep uni-web-view .web-view-content {
  186. background-color: #000;
  187. }
  188. </style>