diff --git a/packages/hooks/useBrowserLocation.ts b/packages/hooks/useBrowserLocation.ts index 333f7c99..b496ed94 100644 --- a/packages/hooks/useBrowserLocation.ts +++ b/packages/hooks/useBrowserLocation.ts @@ -1,4 +1,5 @@ -import { ref } from 'vue' +import { ref, Ref } from 'vue' +import { Point } from './usePoint' interface UseLocationOptions { /** @@ -36,9 +37,23 @@ const statusMap: Record = { 6: 'ERR_PERMISSION_DENIED' } -export function useBrowserLocation(options?: UseLocationOptions) { +interface Location { + accuracy: number + point: Point + address: { + country: string + city: string + city_code: string + district: string + province: string + street: string + street_number: string + } +} + +export function useBrowserLocation(options?: UseLocationOptions, cal?: (location: Ref) => void) { options = options || {} - const location = ref({}) + const location = ref({} as Location) const isLoading = ref(true) const isError = ref(false) const status = ref() @@ -64,6 +79,7 @@ export function useBrowserLocation(options?: UseLocationOptions) { }) .then((res) => { location.value = res + cal && cal(location) }) .catch(() => { isError.value = true