dev2 #1

Open
panjunjie wants to merge 174 commits from dev2 into main
2 changed files with 43 additions and 57 deletions
Showing only changes of commit cbad034315 - Show all commits

View File

@ -10,16 +10,17 @@ prop:
<el-autocomplete
v-model="key"
:fetch-suggestions="querySearchAsync"
placeholder="请输入内容"
:style="{ width: '100%' }"
@change="change"
placeholder="请输入地址关键字"
style="width:100%"
@select="getAddress"
/>
<baidu-map>
<!-- 地图只是为了让 LocalSearch 活着可以不显示 -->
<baidu-map style="height:0px">
<bm-local-search
:auto-viewport="true"
ref="localSearch"
:keyword="key"
:location="location"
:location="location || '北京'"
:auto-viewport="false"
:panel="false"
@searchcomplete="searchcomplete"
/>
@ -30,67 +31,50 @@ prop:
<script>
export default {
props: {
keyword: {
type: String,
default: '',
},
location: {
type: String,
default: '',
},
keyword: { type: String, default: '' },
location: { type: String, default: '' }
},
data() {
return {
key: '',
addressList: [],
loading: false,
selectAddress: {},
timer: null
}
},
watch: {
keyword(newVal, oldVal) {
this.key = newVal
},
// key(newVal, oldVal) {
// this.getAddress({
// value: newVal,
// })
// },
keyword(val) { this.key = val }
},
methods: {
searchcomplete(results) {
if (results && results.as) {
this.addressList = results.as
} else {
this.addressList = {}
}
},
querySearchAsync(queryString, cb) {
clearTimeout(this.timeout)
this.timeout = setTimeout(() => {
cb(this.createStateFilter())
}, 500)
},
createStateFilter() {
let addressList = this.addressList
if (this.addressList.length > 0) {
return addressList.map((address) => {
return {
value: address.address,
lat: address.point.lat,
lng: address.point.lng,
}
})
} else {
return []
}
},
/* 百度检索完成回调:兼容各种字段名变化 */
searchcomplete(res) {
/* 空值保护,防止百度没返回结果时报错 */
if (!res) {
this.addressList = []
return
}
/* 新版 JS-API 把 POI 结果放在 suggestions 字段 */
const arr = res && (res.Rr || res.Hr || res.Ir || res.Kr || res.As || res.suggestions || [])
this.addressList = Array.isArray(arr) ? arr : []
},
querySearchAsync(query, cb) {
clearTimeout(this.timer)
if (!query) return cb([])
this.timer = setTimeout(() => {
/* 1. 把百度返回的字段统一转成 el-autocomplete 要的格式 */
const list = (this.addressList || []).map(item => ({
value: (item.title || '') + (item.address || ''), // value
lat: item.point.lat,
lng: item.point.lng
}))
/* 2. 再过滤一次空 value防止百度返回空地址导致下拉消失 */
const filter = list.filter(i => i.value.trim())
cb(filter)
}, 300)
},
getAddress(item) {
this.$emit('getAddress', item)
},
change(val) {
this.$emit('change', val)
},
},
}
}
}
</script>
</script>

View File

@ -134,6 +134,7 @@
<el-input
v-model="form.chain_lng"
:placeholder="__('经度')"
readonly
style="width: 315px"
/>
</el-form-item>
@ -141,6 +142,7 @@
<el-input
v-model="form.chain_lat"
:placeholder="__('纬度')"
readonly
style="width: 300px"
/>
</el-form-item>