allGardenMap.vue 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. <template>
  2. <view>
  3. <web-view src='https://feiniao-mini-h5-dev.sysuimars.cn/youwei/#/gardenMap?userId=91429'
  4. @message="handleMapEvent"></web-view>
  5. <!-- <web-view src='http://localhost:8081/#/gardenMap?userId=91754&token=034d7cf5-25fc-42d3-993e-460120419e5a'
  6. @message="handleMapEvent" @onPostMessage="handleHashChange"></web-view> -->
  7. </view>
  8. </template>
  9. <script setup>
  10. import config from "@/api/config.js"
  11. import {
  12. onMounted
  13. } from 'vue';
  14. const handleBack = () => {
  15. uni.navigateBack();
  16. };
  17. function handleHashChange(e) {
  18. console.log('handleHashChange', e)
  19. const hash = e.detail.url.split("#")[1];
  20. if (hash && hash.startsWith("jump=")) {
  21. const path = decodeURIComponent(hash.split("=")[1]);
  22. uni.navigateTo({
  23. url: path, // 如 "/pages/home/home"
  24. });
  25. }
  26. }
  27. function randomIndexName(){
  28. const randomNum = Math.floor(Math.random() * 10) + 1; // 生成1到10之间的随机数
  29. let v = new Date().getTime()
  30. let filename = `index${randomNum}.html?v=${v}`
  31. return filename;
  32. }
  33. const handleMapEvent = (e) => {
  34. console.log('地图点击坐标:', e);
  35. const data = e.detail.data;
  36. switch (data.type) {
  37. case 'map-click':
  38. console.log('地图点击坐标:', data.lat, data.lng);
  39. break;
  40. case 'marker-click':
  41. console.log('标记点点击:', data.markerId);
  42. break;
  43. }
  44. }
  45. // 动态注入 JS 监听(兼容性方案)
  46. // onMounted(() => {
  47. // window.addEventListener('message', (e) => {
  48. // alert('eee', e.data)
  49. // if (e.data && e.data.type === 'from-h5') {
  50. // console.log('H5页面消息2222:', e.data.payload);
  51. // }
  52. // });
  53. // });
  54. </script>