index.vue 2.0 KB
Newer Older
1 2
<template>
  <div class="uni-system-choose-location">
3 4 5
    <system-header
      :confirm="!!data"
      @back="_back"
6 7 8
      @confirm="_choose"
    >
      选择位置
fxy060608's avatar
fxy060608 已提交
9
    </system-header>
10
    <div class="map-content">
11 12 13 14 15
      <iframe
        :src="src"
        allow="geolocation"
        seamless
        sandbox="allow-scripts allow-same-origin allow-forms"
16
        frameborder="0"
fxy060608's avatar
fxy060608 已提交
17
      />
18 19 20 21
    </div>
  </div>
</template>
<script>
22
import SystemHeader from '../system-header'
23 24

export default {
25 26 27
  name: 'SystemChooseLocation',
  components: {
    SystemHeader
28 29
  },
  data () {
30
    const key = __uniConfig.qqMapKey
31
    return {
32
      src: `https://apis.map.qq.com/tools/locpicker?search=1&type=1&key=${key}&referer=uniapp`,
33 34 35 36
      data: null
    }
  },
  mounted () {
37
    function handler (event) {
38 39 40 41 42 43 44 45 46
      var loc = event.data
      if (loc && loc.module === 'locationPicker') {
        this.data = {
          name: loc.poiname,
          address: loc.poiaddress,
          latitude: loc.latlng.lat,
          longitude: loc.latlng.lng
        }
      }
47 48 49 50 51 52
    }
    this.__messageHandle = handler.bind(this)
    window.addEventListener('message', this.__messageHandle, false)
  },
  beforeDestroy () {
    window.removeEventListener('message', this.__messageHandle, false)
53 54 55 56
  },
  methods: {
    _choose () {
      if (this.data) {
57
        UniViewJSBridge.publishHandler('onChooseLocation', Object.assign({}, this.data))
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91
        getApp().$router.back()
      }
    },
    _back () {
      UniViewJSBridge.publishHandler('onChooseLocation', null)
      getApp().$router.back()
    }
  }
}
</script>
<style>
	.uni-system-choose-location {
		display: block;
		position: fixed;
		left: 0;
		top: 0;
		width: 100%;
		height: 100%;
		background: #f8f8f8;
	}

	.map-content {
		position: absolute;
		left: 0;
		top: 44px;
		width: 100%;
		bottom: 0;
		overflow: hidden;
	}

	.map-content>iframe {
		width: 100%;
		height: 100%;
	}
92
</style>