webview.vue 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. <template>
  2. <view class="webview-container">
  3. <view class="webview">
  4. <web-view :src="url" id="webcon" cache-control="no-cache">
  5. </web-view>
  6. </view>
  7. </view>
  8. </template>
  9. <script>
  10. export default {
  11. data() {
  12. return {
  13. url: '',
  14. device_id: '',
  15. accessToken: ''
  16. }
  17. },
  18. onLoad(options) {
  19. this.device_id = options.device_id
  20. this.accessToken = uni.getStorageSync('session_key')
  21. console.log(this.accessToken,'accessTokenaccessToken')
  22. // 使用修改后的h52.html,支持dgp播放
  23. this.url = "https://wx.hnyfwlw.com/wexin/h52.html?device_id=" + this.device_id + "&accessToken=" + this.accessToken + "&videoType=dgp"
  24. // this.url = "https://demo.nyzhwlw.com/wechat?device_id=" + this.device_id + "&accessToken=" + this.accessToken
  25. //设置 webview 界面的状态栏的 title
  26. uni.setNavigationBarTitle({
  27. title: '监控详情'
  28. });
  29. // 监听来自webview的消息
  30. window.addEventListener('message', (event) => {
  31. console.log('收到webview消息:', event.data);
  32. if (event.data && event.data.type === 'navigate') {
  33. uni.navigateTo({
  34. url: event.data.url
  35. });
  36. }
  37. });
  38. },
  39. methods: {
  40. nativeTo(){
  41. uni.navigateTo({
  42. url: '/pages/monitor/imagelist?id=' + this.device_id
  43. })
  44. },
  45. nativeToLanch(){
  46. uni.navigateTo({
  47. url: '/pages/monitor/dgpImagelist?id=' + this.device_id
  48. })
  49. },
  50. }
  51. }
  52. </script>
  53. <style>
  54. .webview-container{
  55. height: 100vh;
  56. }
  57. .webview {
  58. width: 100vw;
  59. height: 90vh;
  60. }
  61. </style>