shinnosuke
2026-08-24 01070a7081891d508255d0447ee118afa4b1340e
talent-card-admin/src/views/MerchantCreateView.vue
@@ -991,6 +991,7 @@
let locationMap: any
let locationMarker: any
let amapApi: any
let browserLocationRequest: Promise<{ longitude: number; latitude: number } | undefined> | undefined
async function loadAMap() {
  if (amapApi) return amapApi
@@ -1076,6 +1077,7 @@
  activeFuelStore.value = row
  pendingLongitude.value = String(row.longitude || '')
  pendingLatitude.value = String(row.latitude || '')
  browserLocationRequest = selectedCoordinates() ? undefined : requestBrowserLocation()
  locationDialogVisible.value = true
  locationSearch.value = row.address || ''
  await initializeLocationMap()
@@ -1087,6 +1089,7 @@
  activeParkingAddress.value = row
  pendingLongitude.value = String(row.longitude || '')
  pendingLatitude.value = String(row.latitude || '')
  browserLocationRequest = selectedCoordinates() ? undefined : requestBrowserLocation()
  locationDialogVisible.value = true
  locationSearch.value = row.address || ''
  await initializeLocationMap()
@@ -1125,6 +1128,7 @@
  activeSchoolAddress.value = editingSchool
  pendingLongitude.value = String(editingSchool.longitude || '')
  pendingLatitude.value = String(editingSchool.latitude || '')
  browserLocationRequest = selectedCoordinates() ? undefined : requestBrowserLocation()
  locationDialogVisible.value = true
  locationSearch.value = editingSchool.address || ''
  await initializeLocationMap()
@@ -1199,7 +1203,39 @@
  if (!longitudeText || !latitudeText) return undefined
  const longitude = Number(longitudeText)
  const latitude = Number(latitudeText)
  // The API uses zero for an unset coordinate. Treat it as empty instead of
  // opening the map at 0,0.
  if (longitude === 0 || latitude === 0) return undefined
  return Number.isFinite(longitude) && Number.isFinite(latitude) ? { longitude, latitude } : undefined
}
function requestBrowserLocation(): Promise<{ longitude: number; latitude: number } | undefined> {
  return new Promise((resolve) => {
    const geolocation = window.navigator?.geolocation
    if (!geolocation) {
      ElMessage.info('当前浏览器不支持定位,请直接搜索或点击地图标记')
      resolve(undefined)
      return
    }
    const hostname = window.location.hostname
    if (!window.isSecureContext && hostname !== 'localhost' && hostname !== '127.0.0.1') {
      ElMessage.warning('浏览器定位需要使用 localhost 或 HTTPS 地址访问')
      resolve(undefined)
      return
    }
    geolocation.getCurrentPosition(
      (position) => {
        const longitude = position.coords.longitude
        const latitude = position.coords.latitude
        resolve(Number.isFinite(longitude) && Number.isFinite(latitude) ? { longitude, latitude } : undefined)
      },
      (error) => {
        if (error.code === error.PERMISSION_DENIED) ElMessage.info('未获得浏览器定位权限,请直接搜索或点击地图标记')
        resolve(undefined)
      },
      { enableHighAccuracy: true, timeout: 10000, maximumAge: 0 },
    )
  })
}
function setMapMarker(latitude: number, longitude: number, center = true) {
@@ -1238,6 +1274,13 @@
      reverseGeocodeLocation(latitude, longitude)
    })
    if (selected) setMapMarker(initial.latitude, initial.longitude, false)
    if (!selected) {
      const browserPosition = await (browserLocationRequest || requestBrowserLocation())
      browserLocationRequest = undefined
      if (browserPosition && locationMap && !locationMarker && !selectedCoordinates()) {
        setMapMarker(browserPosition.latitude, browserPosition.longitude)
      }
    }
    window.setTimeout(() => locationMap?.resize(), 120)
  } catch (error) {
    console.error('Failed to initialize AMap', error)
@@ -1311,6 +1354,7 @@
  locationMap?.destroy()
  locationMap = undefined
  locationMarker = undefined
  browserLocationRequest = undefined
  locationSearchResults.value = []
}
@@ -1320,6 +1364,7 @@
  activeFuelStore.value = undefined
  pendingLongitude.value = String(form.longitude || '')
  pendingLatitude.value = String(form.latitude || '')
  browserLocationRequest = selectedCoordinates() ? undefined : requestBrowserLocation()
  locationDialogVisible.value = true
  locationSearch.value = form.address || ''
  await initializeLocationMap()