修改中心点定位

master
doublekou 1 year ago
parent 08c30cac9c
commit a649860501

@ -223,14 +223,21 @@
<!-- 高德地图 --> <!-- 高德地图 -->
<script> <script>
window._AMapSecurityConfig = { window._AMapSecurityConfig = {
securityJsCode: 'ac1232036e1e20026f1e3e95338fc9c4' securityJsCode: 'f811546a61cb67e8bbac45b371931323'
} }
// window._AMapSecurityConfig = {
// securityJsCode: 'bfba507dd2b87770ba82019567e5bd4b'
// }
</script> </script>
<!--引入高德地图JSAPI --> <!--引入高德地图JSAPI -->
<script <script
type="text/javascript" type="text/javascript"
src="https://webapi.amap.com/maps?v=2.0&key=df6e9416230b57f3c7f48be57dd2f813&plugin=AMap.Autocomplete,AMap.PlaceSearch,AMap.SearchNearBy,AMap.Geocoder,AMap.Geolocation,AMap.Marker" src="https://webapi.amap.com/maps?v=2.0&key=1d3839a0fe4ad113f7d88ec3775107b7&plugin=AMap.Autocomplete,AMap.PlaceSearch,AMap.SearchNearBy,AMap.Geocoder,AMap.Geolocation,AMap.Marker"
></script> ></script>
<!-- <script
type="text/javascript"
src="https://webapi.amap.com/maps?v=2.0&key=69f36fd863068da639e2c7db66b437bf&plugin=AMap.Autocomplete,AMap.PlaceSearch,AMap.SearchNearBy,AMap.Geocoder,AMap.Geolocation,AMap.Marker"
></script> -->
<!--引入UI组件库1.1版本) --> <!--引入UI组件库1.1版本) -->
<!-- <script src="https://webapi.amap.com/ui/1.1/main.js"></script> --> <!-- <script src="https://webapi.amap.com/ui/1.1/main.js"></script> -->
</body> </body>

@ -189,6 +189,8 @@ export interface CustomerDTO {
distinguish?: string distinguish?: string
//详细地址 //详细地址
detailAddress?: any detailAddress?: any
//门牌号
otherAddressesInfo?: string
//半径 //半径
radius?: any radius?: any
//报名状态 //报名状态

@ -109,15 +109,22 @@
</a-col> </a-col>
<a-col :xl="10" :md="10" :sm="10"> <a-col :xl="10" :md="10" :sm="10">
<a-form-item <a-form-item
:rules="[{ required: true, message: '请输入小区名称', trigger: 'blur' }]" :rules="[{ required: true, message: '请输入小区名称', trigger: 'change' }]"
name="detailAddress" name="detailAddress"
> >
<a-input <a-input
id="tipinput" id="tipinput"
v-model:value="formModel.detailAddress" v-model:value="formModel.detailAddress"
autocomplete="off"
placeholder="请输入小区名称" placeholder="请输入小区名称"
:disabled="title === '编辑预约'" :disabled="title === '编辑预约' || title === '编辑'"
:readonly="title === '详情' || title === '分发'" class="custom-tooltip"
:title="formModel.address && formModel.address.length === 0 ? '请先选择省市区' : ''"
:readonly="
title === '详情' ||
title === '分发' ||
(formModel.address && formModel.address.length === 0)
"
/> />
</a-form-item> </a-form-item>
</a-col> </a-col>
@ -142,7 +149,7 @@
<a-button <a-button
v-if="title === '新建预约' || title === '编辑预约' || title === '编辑'" v-if="title === '新建预约' || title === '编辑预约' || title === '编辑'"
type="primary" type="primary"
@click="match" @click="match(formModel.detailAddress)"
>匹配</a-button >匹配</a-button
> >
<a-button <a-button
@ -448,6 +455,12 @@ const addressChange = (value: any) => {
formModel.economize = value[0] formModel.economize = value[0]
formModel.market = value[1] formModel.market = value[1]
formModel.distinguish = value[2] formModel.distinguish = value[2]
city.value = value[1].slice(0, -1)
cityAnddistinguish.value = value[1] + value[2]
console.log(cityAnddistinguish.value, 'cityAnddistinguish.value')
auto()
// console.log(city.value, 'city.value')
// formModel.detailAddress = value.toString() + formModel.detailAddress
} }
} }
@ -521,14 +534,14 @@ const infoWindows = ref<any>({})
//id //id
let previousId: any = null let previousId: any = null
// //
const pagingQuery = () => { const pagingQuery = (lng: number, lat: number) => {
if (circle.value) { if (circle.value) {
map.value.remove(circle.value) map.value.remove(circle.value)
} }
const color = '#DFEBF3' const color = '#DFEBF3'
// //
circle.value = new AMap.Circle({ circle.value = new AMap.Circle({
center: [lng.value, lat.value], // center: [lng, lat], //
radius: formModel.radius, // radius: formModel.radius, //
fillColor: color, // fillColor: color, //
strokeColor: '#a1ceeb', // strokeColor: '#a1ceeb', //
@ -537,92 +550,89 @@ const pagingQuery = () => {
// //
map.value.add(circle.value) map.value.add(circle.value)
doRequest( doRequest(getStoreData({ longitude: lng, latitude: lat, distance: formModel.radius }), {
getStoreData({ longitude: lng.value, latitude: lat.value, distance: formModel.radius }), onSuccess: (result: any) => {
{ if (result.code === 200) {
onSuccess: (result: any) => { if (result.data.length === 0) {
if (result.code === 200) { message.info('当前位置附近暂无相关门店')
if (result.data.length === 0) { } else {
message.info('当前位置附近暂无相关门店') const ids = formModel.customStoreEntities.map(item => item.storeId)
} else { listData.value.length = 0
const ids = formModel.customStoreEntities.map(item => item.storeId) result.data &&
listData.value.length = 0 result.data.forEach((item: any) => {
result.data && const disabled = ids.includes(Number(item.id))
result.data.forEach((item: any) => { listData.value.push({
const disabled = ids.includes(Number(item.id)) title: item.storeName,
listData.value.push({ description: item.address,
title: item.storeName, content: item.nid ? item.nid : '',
description: item.address, disabled: disabled,
content: item.nid ? item.nid : '', lat: item.latitude,
disabled: disabled, lng: item.longitude,
lat: item.latitude, id: item.id,
lng: item.longitude, index: item.index,
id: item.id, tel: item.nid ? item.nid : '',
index: item.index, reservationDate: item.reservationDate,
tel: item.nid ? item.nid : '', option: generateTimeSlots(item.tradeStartTime, item.tradeEndTime)
reservationDate: item.reservationDate,
option: generateTimeSlots(item.tradeStartTime, item.tradeEndTime)
})
})
pois.push(...listData.value)
// ,
const targetZoom = 12
//
const placeSearch_CallBack = (data: any) => {
const poiArr = data
infoWindows.value = new AMap.InfoWindow({
autoMove: true,
isCustom: true,
offset: { x: 0, y: -30 } //
}) })
//marker })
const markers = new AMap.Marker({ pois.push(...listData.value)
map: map.value, // ,
position: [poiArr.lng, poiArr.lat], const targetZoom = 12
// clickable: true,//,true
// offset: new AMap.Pixel(-90, -70), // //
zIndex: 0, // 1000 const placeSearch_CallBack = (data: any) => {
extData: { const poiArr = data
id: `${poiArr.id}` infoWindows.value = new AMap.InfoWindow({
// ... autoMove: true,
} isCustom: true,
}) offset: { x: 0, y: -30 } //
markers.on('click', function (data: any) { })
const currentId = data.target.getExtData().id //marker
const markers = new AMap.Marker({
if ( map: map.value,
infoWindows.value.getIsOpen() && position: [poiArr.lng, poiArr.lat],
(currentId === previousId || currentId === currentStoreId.value) // clickable: true,//,true
) { // offset: new AMap.Pixel(-90, -70), //
// , zIndex: 0, // 1000
currentStoreId.value = currentId extData: {
previousId = currentId id: `${poiArr.id}`
return false // ...
} }
})
infoWindows.value.open(map.value, markers.getPosition()) // markers.on('click', function (data: any) {
map.value.setZoomAndCenter(targetZoom, [data.lnglat.lng, data.lnglat.lat]) // 使 const currentId = data.target.getExtData().id
map.value.setCenter(markers.getPosition()) //
infoWindows.value.setContent(createContent(poiArr)) // if (
infoWindows.value.getIsOpen() &&
// ID (currentId === previousId || currentId === currentStoreId.value)
) {
// ,
currentStoreId.value = currentId currentStoreId.value = currentId
previousId = currentId previousId = currentId
}) return false
} }
for (let i = 0; i < pois.length; i++) {
placeSearch_CallBack(pois[i]) infoWindows.value.open(map.value, markers.getPosition()) //
} map.value.setZoomAndCenter(targetZoom, [data.lnglat.lng, data.lnglat.lat]) // 使
map.value.setCenter(markers.getPosition()) //
infoWindows.value.setContent(createContent(poiArr)) //
// ID
currentStoreId.value = currentId
previousId = currentId
})
}
for (let i = 0; i < pois.length; i++) {
placeSearch_CallBack(pois[i])
} }
} }
} }
} }
) })
} }
// //
const match = () => { const match = async (detailAddress: string) => {
const fields = ['address', 'detailAddress', 'radius'] // const fields = ['address', 'detailAddress', 'radius'] //
formRef.value formRef.value
?.validateFields(fields) ?.validateFields(fields)
@ -632,13 +642,48 @@ const match = () => {
lng.value = undefined lng.value = undefined
lat.value = undefined lat.value = undefined
map.value.clearMap() map.value.clearMap()
city.value = formModel.market?.slice(0, -1)
AMap.plugin('AMap.Geocoder', function () { AMap.plugin('AMap.Geocoder', function () {
geocoder.value = new AMap.Geocoder({ geocoder.value = new AMap.Geocoder({
city: '全国' // city adcode citycode city: city.value // city adcode citycode
}) })
}) })
// //
getCenterMarker('match') // 西180
//
const searchService = new AMap.PlaceSearch({
// API Key
key: '1d3839a0fe4ad113f7d88ec3775107b7',
//
version: '2.0'
})
const addressValue = formModel.address?.toString().split(',').join('') + detailAddress
//
// formModel.address?.toString().split(',').join('') + formModel.detailAddress
//
searchService.search(addressValue, (status: any, result: any) => {
if (status === 'complete' && result.info === 'OK') {
//
const pois = result.poiList.pois
//
console.log(pois, 'pois')
console.log(pois[0].location.lng, pois[0].location.lat, 'pois经纬度')
getCenterMarker('match', pois[0].location.lng, pois[0].location.lat)
// await getCenterMarker('match', formModel.otherAddressesInfo)
// if (type === 'match') {
// formModel.otherAddressesInfo = detailAddress
} else {
//
console.log('地点搜索失败')
}
})
// await getCenterMarker('match', formModel.otherAddressesInfo)
// // if (type === 'match') {
// pagingQuery()
// }
}) })
.catch(() => { .catch(() => {
// //
@ -824,6 +869,7 @@ const formModel = reactive<CustomerDTO>({
market: '', market: '',
distinguish: '', distinguish: '',
detailAddress: '', detailAddress: '',
otherAddressesInfo: '',
radius: '5000', radius: '5000',
enrollStatus: 1, enrollStatus: 1,
customStoreEntities: [] customStoreEntities: []
@ -905,6 +951,7 @@ defineExpose({
market, market,
distinguish, distinguish,
detailAddress, detailAddress,
otherAddressesInfo,
radius, radius,
customStoreVOList customStoreVOList
} = data } = data
@ -918,6 +965,7 @@ defineExpose({
formModel.market = market formModel.market = market
formModel.distinguish = distinguish formModel.distinguish = distinguish
formModel.detailAddress = detailAddress formModel.detailAddress = detailAddress
formModel.otherAddressesInfo = otherAddressesInfo
formModel.radius = radius formModel.radius = radius
formModel.customStoreEntities.push(...customStoreVOList) formModel.customStoreEntities.push(...customStoreVOList)
// //
@ -927,13 +975,17 @@ defineExpose({
if (opendata.type === 'audit') { if (opendata.type === 'audit') {
// isReadOnly.value = true // isReadOnly.value = true
// reservationTimeisReadOnly.value = true // reservationTimeisReadOnly.value = true
// city.value = formModel.market?.slice(0, -1)
isDisabled.value = true
handleMapInit() handleMapInit()
title.value = '编辑' title.value = '编辑'
// formModel.description = 1 // formModel.description = 1
} else if (opendata.type === 'edit') { } else if (opendata.type === 'edit') {
isDisabled.value = true isDisabled.value = true
handleMapInit() handleMapInit()
match(formModel.detailAddress)
//
// getCenterMarker('init')
title.value = '编辑预约' title.value = '编辑预约'
} }
} }
@ -966,7 +1018,7 @@ defineExpose({
else if (opendata.type === 'distribute') { else if (opendata.type === 'distribute') {
isReadOnly.value = true isReadOnly.value = true
reservationTimeisReadOnly.value = true reservationTimeisReadOnly.value = true
handleMapInit() // handleMapInit()
title.value = '分发' title.value = '分发'
formModel.description = 1 formModel.description = 1
} }
@ -984,6 +1036,7 @@ defineExpose({
// //
// import { provincesAndCitiesAndAutonomousRegions } from '@/utils/geopolitical-customers' // import { provincesAndCitiesAndAutonomousRegions } from '@/utils/geopolitical-customers'
import type { ShowSearchType } from 'ant-design-vue/es/cascader' import type { ShowSearchType } from 'ant-design-vue/es/cascader'
import { compileStyle } from 'vue/compiler-sfc'
declare const AMap: any declare const AMap: any
@ -998,68 +1051,200 @@ const autoComplete = ref()
//AMap.Marker //AMap.Marker
// Marker // Marker
const marker = ref<any>({}) const marker = ref<any>({})
// Marker
const markerCenter = ref<any>({})
const previousMarker = ref<any>({})
//AMap.Map //AMap.Map
const map = ref<any>({}) const map = ref<any>({})
//使geocoder/ //使geocoder/
// AMap.GeocodergetLocation // AMap.GeocodergetLocation
// AMap.GeocodergetAddress // AMap.GeocodergetAddress
const geocoder = ref<any>({}) const geocoder = ref<any>({})
// //
const getCenterMarker = (type: string) => { const getCenterMarker = (type: string, lng: number, lat: number) => {
const addressValue = // const addressValue = ref<string>('')
// // if (address) {
formModel.address?.toString().split(',').join('') + formModel.detailAddress // addressValue.value = address
geocoder.value.getLocation(addressValue, function (status: any, result: any) { // } else {
if (status === 'complete' && result.info === 'OK') { // addressValue.value =
// result // //
lng.value = result.geocodes[0].location.lng // formModel.address?.toString().split(',').join('') + formModel.detailAddress
lat.value = result.geocodes[0].location.lat // // console.log(addressValue, 'addressValue')
// // }
map.value.setCenter([lng.value, lat.value]) // // console.log(addressValue.value, 'addressValue.value')
if (type === 'match') {
// // 西180
map.value.setZoom(12) // 12 // geocoder.value.getLocation(addressValue.value, function (status: any, result: any) {
} // if (status === 'complete' && result.info === 'OK') {
// // result
const marker = new AMap.Marker({ // lng.value = result.geocodes[0].location.lng
position: [lng.value, lat.value], // // lat.value = result.geocodes[0].location.lat
zIndex: 100 // z-index 100
}) // lng.value = lng
// lat.value = lat
//
map.value.setCenter([lng, lat]) //
if (type === 'match' || type === 'select') {
//
map.value.setZoom(12) // 12
}
// console.log(lng.value, lat.value, 'lng.value, lat.value')
// if (previousMarker.value && type === 'select') {
marker.setIcon( map.value.remove(markerCenter.value) //
new AMap.Icon({ }
image: 'https://webapi.amap.com/theme/v1.3/markers/n/mark_r.png', // 使 URL //
size: new AMap.Size(18, 30), // markerCenter.value = new AMap.Marker({
imageSize: new AMap.Size(18, 30) // position: [lng, lat], //
}) zIndex: 100 // z-index 100
)
marker.setMap(map.value) //
}
if (type === 'match') {
pagingQuery()
}
}) })
//
markerCenter.value.setIcon(
new AMap.Icon({
image: 'https://webapi.amap.com/theme/v1.3/markers/n/mark_r.png', // 使 URL
size: new AMap.Size(18, 30), //
imageSize: new AMap.Size(18, 30) //
})
)
markerCenter.value.setMap(map.value) //
previousMarker.value = marker // previousMarker
if (type === 'match') {
console.log(type, 'type')
pagingQuery(lng, lat)
}
// }
// })
} }
// //
const performQuery = (selectedTip: any) => { const performQuery = (selectedTip: any, detailAddress: string) => {
const geocoder = new AMap.Geocoder() //
const location = selectedTip.location const searchService = new AMap.PlaceSearch({
// API Key
key: '1d3839a0fe4ad113f7d88ec3775107b7',
//
version: '2.0'
})
const addressValue = formModel.address?.toString().split(',').join('') + selectedTip.name
//
// formModel.address?.toString().split(',').join('') + formModel.detailAddress
// 使 //
geocoder.getAddress(location, function (status: any, result: any) { searchService.search(addressValue, (status: any, result: any) => {
if (status === 'complete' && result.info === 'OK') { if (status === 'complete' && result.info === 'OK') {
// //
const address = result.regeocode.formattedAddress const pois = result.poiList.pois
console.log('查询结果:', address) //
// ... console.log(pois, 'pois')
console.log(pois[0].location.lng, pois[0].location.lat, 'pois经纬度')
getCenterMarker('select', pois[0].location.lng, pois[0].location.lat)
formModel.otherAddressesInfo = `${pois[0].location.lng},${pois[0].location.lat}`
} else {
//
console.log('地点搜索失败')
} }
}) })
// const geocoder = new AMap.Geocoder()
// const location = selectedTip.location
// if (location) {
// // 使
// geocoder.getAddress(location, function (status: any, result: any) {
// if (status === 'complete' && result.info === 'OK') {
// //
// const address = result.regeocode.formattedAddress
// console.log('', address)
// console.log(detailAddress, 'detailAddress')
// // ...
// match()
// // detailAddress = detailAddress.substring(0, 14)
// // if (detailAddress === '8·') {
// // detailAddress = detailAddress.substring(0, detailAddress.indexOf('') + 1)
// // console.log(detailAddress, 'detailAddress1111')
// // //
// // getCenterMarker('select', detailAddress)
// // formModel.otherAddressesInfo = detailAddress
// // } else {
// // //
// // getCenterMarker('select', detailAddress)
// // formModel.otherAddressesInfo = detailAddress
// // }
// }
// })
// } else {
// message.info(',')
// }
}
const city = ref<string | undefined>('')
const cityAnddistinguish = ref<string | undefined>('')
const detailAddress = ref<string>('')
const auto = async () => {
await AMap.plugin('AMap.AutoComplete', function () {
// Autocomplete
// cityAnddistinguish.value
const autoOptions = {
city: '浙江省杭州市西湖区', //
input: 'tipinput',
citylimit: true,
noLocation: true //
}
console.log(cityAnddistinguish.value, 'cityAnddistinguish.value')
autoComplete.value = new AMap.AutoComplete(autoOptions)
setTimeout(() => {
// autoComplete.value?.on('beforeSearch', (e: any) => {
// const keywords = e.keywords //
// console.log(keywords, 'keywords')
// e.keywords = `${formModel.market} ${keywords}` //
// // const selectedDistrict = formModel.market //
// //
// // if (selectedDistrict && selectedDistrict !== '西') {
// // e.keywords = `${selectedDistrict} ${keywords}` //
// // }
// })
autoComplete.value?.on('select', (e: any) => {
// console.log(e.poi, 'e.poi')
// const selectedTip = e.poi //
// formModel.detailAddress = selectedTip.name // 使 v-model
// detailAddress.value = selectedTip.district + selectedTip.address
// // console.log(formModel.detailAddress, 'formModel.detailAddress')
// performQuery(selectedTip, detailAddress.value) //
const selectedTip = e.poi
if (selectedTip.district === formModel.market) {
//
formModel.detailAddress = selectedTip.name
detailAddress.value = selectedTip.district + selectedTip.address
performQuery(selectedTip, detailAddress.value)
} else {
//
message.info(`只能选择${formModel.distinguish}内的地址`)
// console.log('西')
}
})
}, 300)
AMap.plugin('AMap.Geocoder', function () {
geocoder.value = new AMap.Geocoder({
// city: '' // city adcode citycode
city: city.value
})
})
// geocoder.value = new AMap.Geocoder({
// city: '010' //
// })
})
} }
// //
const initMap = () => { const initMap = async () => {
map.value = new AMap.Map('draw-station-container', { map.value = new AMap.Map('draw-station-container', {
// center: [120.1551, 30.2741], // // center: [120.1551, 30.2741], //
zoom: 18 // zoom: 18 //
@ -1084,32 +1269,28 @@ const initMap = () => {
// } // }
// }) // })
AMap.plugin('AMap.AutoComplete', function () { // AMap.plugin('AMap.AutoComplete', function () {
// Autocomplete // // Autocomplete
const autoOptions = { // const autoOptions = {
//city // city: city.value, //
input: 'tipinput' // input: 'tipinput'
} // }
autoComplete.value = new AMap.AutoComplete(autoOptions) // autoComplete.value = new AMap.AutoComplete(autoOptions)
// geocoder.value = new AMap.Geocoder({ // // geocoder.value = new AMap.Geocoder({
// city: '010' // // // city: '010' //
// }) // // })
}) // })
setTimeout(() => { await auto()
autoComplete.value?.on('select', (e: any) => { if (title.value === '编辑预约' || title.value === '编辑') {
const selectedTip = e.poi // // city.value = formModel.market?.slice(0, -1)
formModel.detailAddress = selectedTip.name // 使 v-model //
performQuery(selectedTip) // getCenterMarker(
}) 'init',
}, 300) Number(formModel.otherAddressesInfo?.split(',')[0]),
AMap.plugin('AMap.Geocoder', function () { Number(formModel.otherAddressesInfo?.split(',')[1])
geocoder.value = new AMap.Geocoder({ )
city: '全国' // city adcode citycode }
})
})
//
getCenterMarker('init')
// map.value.add(marker.value) // map.value.add(marker.value)
} }
@ -1359,4 +1540,27 @@ const storeItemClick = (item: any, index: number) => {
::v-deep .ant-space-item { ::v-deep .ant-space-item {
width: 100% !important; width: 100% !important;
} }
//a-input
.custom-tooltip {
position: relative;
}
.custom-tooltip::before {
content: attr(title);
position: absolute;
top: 100%;
left: 0;
width: 100%;
padding: 5px;
background-color: #f8f8f8;
border: 1px solid #ccc;
border-top: none;
font-size: 14px;
color: #333;
pointer-events: none;
opacity: 0;
transition: opacity 0.2s ease-in-out;
}
.custom-tooltip:hover::before {
opacity: 1;
}
</style> </style>

@ -22,13 +22,13 @@ import { antdvStyleDeps } from './src/utils/resolvers'
//项目 //项目
// const serverAddress = 'http://admin.ballcat.cn' // const serverAddress = 'http://admin.ballcat.cn'
//xy //xy
const serverAddress = 'http://172.18.0.225:8000' // const serverAddress = 'http://172.18.0.225:8000'
//jt //jt
// const serverAddress = 'http://172.18.1.8:8000' // const serverAddress = 'http://172.18.1.8:8000'
//ts //ts
// const serverAddress = 'http://172.18.0.228:8000' // const serverAddress = 'http://172.18.0.228:8000'
//测试 //测试
// const serverAddress = 'http://39.100.77.21:8000' const serverAddress = 'http://39.100.77.21:8000'
//线上ip //线上ip
// const serverAddress = 'http://175.27.212.74:80' // const serverAddress = 'http://175.27.212.74:80'

Loading…
Cancel
Save