Browse Source

优化面包屑导航逻辑,调整地图初始化方式,支持获取当前位置

master
parent
commit
51b32dbe2a
  1. 12
      src/layout/components/Breadcrumb/src/Breadcrumb.vue
  2. 70
      src/views/enterprises/components/getGpsByAmap.vue

12
src/layout/components/Breadcrumb/src/Breadcrumb.vue

@ -78,9 +78,15 @@ export default defineComponent({
)
return () => (
<ElBreadcrumb separator="/" class={`${prefixCls} flex items-center h-full`}>
{renderBreadcrumb()}
</ElBreadcrumb>
<section>
{currentRoute.value.meta.hidden ? (
''
) : (
<ElBreadcrumb separator="/" class={`${prefixCls} flex items-center h-full`}>
{renderBreadcrumb()}
</ElBreadcrumb>
)}
</section>
)
}
})

70
src/views/enterprises/components/getGpsByAmap.vue

@ -4,7 +4,7 @@ import position from '@/assets/imgs/position.png'
const show = ref(false)
const AMap = (window as any).AMap
let map: any = null
const center = ref()
const center = ref([121.243994, 41.539054])
const loading = ref(false)
let mapSearch: any = null
const address = ref()
@ -14,38 +14,56 @@ const message = useMessage()
const open = async (param) => {
show.value = true
await nextTick(() => {
init(param)
init()
})
if (param) {
address.value = param.name
addressInfo.value = param
addMarker()
} else {
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(
(position) => {
console.log(position)
center.value = [position.coords.longitude, position.coords.latitude]
map.setCenter(center.value)
},
(err) => {
console.log(err)
message.warning('获取当前位置失败,请手动选择')
},
{
enableHighAccuracy: true,
maximumAge: 0,
timeout: 300
}
)
} else {
message.warning('获取当前位置失败,请手动选择')
}
}
}
const emits = defineEmits(['success'])
const init = (param) => {
const init = () => {
loading.value = true
navigator.geolocation.getCurrentPosition((position) => {
center.value = [position.coords.longitude, position.coords.latitude]
map = new AMap.Map('map-container', {
center: center.value, //
zoom: 14, //
viewMode: '2D'
})
map.on('complete', () => {
const logo = document.getElementsByClassName('amap-logo')[0]
const copyRight = document.getElementsByClassName('amap-copyright')[0]
logo.setAttribute('style', 'display:none !important')
copyRight.setAttribute('style', 'display:none !important')
})
AMap.plugin('AMap.Autocomplete', () => {
mapSearch = new AMap.Autocomplete({
city: '锦州'
})
map = new AMap.Map('map-container', {
center: center.value, //
zoom: 14, //
viewMode: '2D'
})
map.on('complete', () => {
const logo = document.getElementsByClassName('amap-logo')[0]
const copyRight = document.getElementsByClassName('amap-copyright')[0]
logo.setAttribute('style', 'display:none !important')
copyRight.setAttribute('style', 'display:none !important')
loading.value = false
})
AMap.plugin('AMap.Autocomplete', () => {
mapSearch = new AMap.Autocomplete({
city: '锦州'
})
if (param) {
address.value = param.name
addressInfo.value = param
addMarker()
}
})
loading.value = false
}
const querySearchAsync = (queryString: string, cb: (arg: any) => void) => {

Loading…
Cancel
Save