You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

74 lines
1.8 KiB

3 years ago
<template>
<div>
<avue-map v-model="map" placeholder="请选择地图"></avue-map>
3 years ago
<p style="zoom: .85;">{{ value }}</p>
3 years ago
</div>
</template>
<script>
export default {
props: {
value: [String, Object, Array, Number, Boolean],
resultFormat: {
type: [String, Object, Array],
3 years ago
default: () => ['longitude','latitude'] //latitude纬度longitude经度,formattedAddress地址
3 years ago
}
},
data() {
return {
map: {},
}
},
methods: {},
computed: {},
watch: {
map(newVal) {
if(!newVal) return
3 years ago
let info = {
...newVal,
2 years ago
latitude: newVal.latitude,
longitude: newVal.longitude,
3 years ago
}
3 years ago
let res = ''
if(typeof this.resultFormat === 'string') {
3 years ago
res = info[this.resultFormat]
3 years ago
}
if(this.resultFormat instanceof Array) {
3 years ago
res = this.resultFormat.map(i => info[i])?.toString()
3 years ago
}
if(typeof this.resultFormat === 'object' && (!this.resultFormat instanceof Array)) {
let obj = {}
for(let key in this.resultFormat) {
3 years ago
obj[key] = info[this.resultFormat[key]]
3 years ago
}
res = obj;
}
2 years ago
console.log(res)
3 years ago
this.$emit('input', res)
},
value(newVal) {
if(typeof this.resultFormat === 'string') {
this.map[this.resultFormat] = Number(newVal)
}
if(this.resultFormat instanceof Array && newVal) {
let valArr = newVal.split(',')
this.resultFormat.forEach((i,index) => {
this.map[i] = Number(valArr[index])
})
}
if(typeof this.resultFormat === 'object' && (!this.resultFormat instanceof Array)) {
for(let key in this.resultFormat) {
this.map[key] = Number(newVal[key])
}
}
console.log(this.map)
}
}
}
</script>
<style scoped lang="scss">
</style>