index.vue 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. <template>
  2. <view class="content">
  3. <view class="status_bar">
  4. <!-- 这里是状态栏 -->
  5. </view>
  6. <web-view :src="url" :fullscreen='false' @message="messageData"></web-view>
  7. </view>
  8. </template>
  9. <script>
  10. const jpushModule = uni.requireNativePlugin('JG-JPush')
  11. var wv
  12. export default {
  13. data() {
  14. return {
  15. title: 'wdly',
  16. // 正式
  17. url: 'http://139.9.102.170:10012/#/',
  18. // 测试
  19. // url: 'http://139.9.102.170:10011/#/',
  20. src: "",
  21. canBack: false,
  22. }
  23. },
  24. onBackPress() {
  25. if (wv && this.canBack) {
  26. wv.back();
  27. return true;
  28. }
  29. return false;
  30. },
  31. onReady() {
  32. // #ifdef APP-PLUS
  33. var self = this;
  34. var currentWebview = this.$scope.$getAppWebview();
  35. //此对象相当于html5plus里的plus.webview.currentWebview()。在uni-app里vue页面直接使用plus.webview.currentWebview()无效,非v3编译模式使用this.$mp.page.$getAppWebview()
  36. setTimeout(function() {
  37. wv = currentWebview.children()[0];
  38. wv.addEventListener(
  39. "progressChanged",
  40. function(e) {
  41. wv.canBack(function(e) {
  42. self.canBack = e.canBack;
  43. });
  44. },
  45. false
  46. );
  47. }, 500); //如果是页面初始化调用时,需要延时一下
  48. // #endif
  49. },
  50. onLoad() {
  51. var height = 0; //定义动态的高度变量,如高度为定值,可以直接写
  52. uni.getSystemInfo({
  53. //成功获取的回调函数,返回值为系统信息
  54. success: (sysinfo) => {
  55. console.log(sysinfo)
  56. height = sysinfo.windowHeight; //自行修改,自己需要的高度 此处如底部有其他内容,可以直接---(-50)这种
  57. },
  58. complete: () => {}
  59. });
  60. let info = uni.getSystemInfoSync();
  61. let top = info.statusBarHeight;
  62. console.log(info, 12312312312);
  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. // 监听极光连接状态
  80. uni.$on('connectStatusChange', (connectStatus) => {
  81. if (connectStatus) {
  82. var currentWebview = this.$scope.$getAppWebview();
  83. var wv = currentWebview.children()[0];
  84. // 取得应用程序对应的 RegistrationID。 只有当应用程序成功注册到 JPush 的服务器时才返回对应的值,否则返回空字符串
  85. jpushModule.getRegistrationID(result => {
  86. console.log(result, "注册ID.....")
  87. wv.evalJS(`getVueMessage(${JSON.stringify(result.registerID)})`);
  88. })
  89. }
  90. })
  91. },
  92. onUnload() {
  93. // 移除监听事件
  94. uni.$off('connectStatusChange')
  95. },
  96. methods: {
  97. messageData(e) {
  98. const data = e.detail.data
  99. let url = data[0].url
  100. uni.downloadFile({
  101. url: url, // 文件的下载链接
  102. success: function(res) {
  103. // 下载成功
  104. if (res.statusCode === 200) {
  105. // 打开文件
  106. uni.openDocument({
  107. filePath: res.tempFilePath,
  108. success: function(res) {},
  109. fail: function(error) {}
  110. });
  111. }
  112. },
  113. fail: function(error) {}
  114. });
  115. }
  116. }
  117. }
  118. </script>
  119. <style>
  120. .content {}
  121. .status_bar {
  122. height: var(--status-bar-height);
  123. width: 100%;
  124. }
  125. </style>sss