From f51994680e5d877b3e2e42adf07e0b42222872f6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=8A=B1=E5=BC=80=E5=8D=8A=E4=BA=A9=E5=9C=B0?= <2572468699@qq.com> Date: Wed, 16 Nov 2022 21:44:41 +0800 Subject: [PATCH] feat: remove map options & add callback options --- packages/hooks/useIpLocation.ts | 32 +++++++++----------------------- 1 file changed, 9 insertions(+), 23 deletions(-) diff --git a/packages/hooks/useIpLocation.ts b/packages/hooks/useIpLocation.ts index cf85bdb5..f1618c6a 100644 --- a/packages/hooks/useIpLocation.ts +++ b/packages/hooks/useIpLocation.ts @@ -1,4 +1,4 @@ -import { ref, watch } from 'vue' +import { ref, Ref } from 'vue' import { Point } from './usePoint' interface Location { @@ -9,34 +9,20 @@ interface Location { /** * ip定位 */ -export function useIpLocation(map?: any) { +export function useIpLocation(cal?: (location: Ref) => void) { const location = ref({} as Location) const isLoading = ref(true) - let mapComponentInstance: any - map && - watch( - () => map.value, - (n) => { - mapComponentInstance = n - } - ) - const init = () => { isLoading.value = true - const options: Record = {} - if (map) { - options.renderOptions = { - map: mapComponentInstance.getMapInstance() - } - } - - new BMapGL.LocalCity(options).get((res: any) => { + new BMapGL.LocalCity().get((res: any) => { isLoading.value = false - res.point = res.center - Reflect.deleteProperty(res, 'level') - Reflect.deleteProperty(res, 'center') - location.value = res + location.value = { + code: res.code, + point: res.center, + name: res.name + } + cal && cal(location) }) }