index.vue 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. <template>
  2. <view class="demos">
  3. <web-view @bindmessage="onMessageHandler" :src="webViewSrc"></web-view>
  4. </view>
  5. </template>
  6. <script>
  7. import httpAjax from '@/utils/https.js';
  8. import config from '@/utils/config.js';
  9. const _cDate = new Date();
  10. export default {
  11. components: {},
  12. data() {
  13. return {
  14. time: null,
  15. webViewSrc: config.webViewUrl +
  16. '?v='+_cDate.getTime()+'&objs=' +
  17. JSON.stringify(uni.getStorageSync('userInfo'))
  18. };
  19. },
  20. onReady(){
  21. wx.setNavigationBarTitle(({
  22. title: config.webViewUrl === config.webViewUrl2 ? '要素一本账' : '地块管护'
  23. }))
  24. },
  25. mounted() {
  26. this.time = setInterval(() => {
  27. this.initGetLocation();
  28. }, 3000);
  29. },
  30. methods: {
  31. initGetLocation() {
  32. let that = this;
  33. let citys = {
  34. longitude: '',
  35. latitude: '',
  36. };
  37. uni.getLocation({
  38. success: function (res) {
  39. citys.longitude = res.longitude;
  40. citys.latitude = res.latitude;
  41. that.webViewSrc =
  42. config.webViewUrl +
  43. '?objs=' +
  44. JSON.stringify(uni.getStorageSync('userInfo')) +
  45. '&city=' +
  46. JSON.stringify(citys);
  47. },
  48. });
  49. },
  50. onMessageHandler(event) {
  51. console.log(event);
  52. let res = event.detail.data;
  53. console.log('小程序接收到H5传递过了的message:', JSON.stringify(res));
  54. uni.showToast({
  55. title: '小程序接收到H5传递过了的message:' + JSON.stringify(res),
  56. icon: 'none',
  57. });
  58. },
  59. },
  60. };
  61. </script>
  62. <style lang="scss"></style>