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

export default {
fxy060608's avatar
fxy060608 已提交
21
  name: 'SystemChooseLocation',
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 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
  components: {
    SystemHeader
  },
  data () {
    return {
      src: '',
      data: null
    }
  },
  mounted () {
    var key = 'WXTBZ-6WERU-ECCVS-BZJCK-LW5OJ-SIBOS'
    this.src = `https://apis.map.qq.com/tools/locpicker?search=1&type=1&key=${key}&referer=uniapp`
    window.addEventListener('message', (event) => {
      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
        }
      }
    }, false)
  },
  methods: {
    _choose () {
      if (this.data) {
        UniViewJSBridge.publishHandler('onChooseLocation', this.data)
        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%;
	}
fxy060608's avatar
fxy060608 已提交
84
</style>