mrxy-yk 1.7.0-beta.2 → 1.7.0-beta.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -64,7 +64,8 @@ var _sfc_main = /* @__PURE__ */ defineComponent({
64
64
  emits("update:modelValue", false);
65
65
  };
66
66
  const coordinatePickupRef = shallowRef();
67
- let aMapHook = useAMapClassicHook({
67
+ const aMapHook = useAMapClassicHook({
68
+ autoLoad: false,
68
69
  el: coordinatePickupRef,
69
70
  mapStyle: props.mapStyle,
70
71
  loaderOptions: {
@@ -74,16 +75,8 @@ var _sfc_main = /* @__PURE__ */ defineComponent({
74
75
  }
75
76
  }, loadAMap);
76
77
  function initAMap() {
77
- if (aMapHook) return;
78
- aMapHook = useAMapClassicHook({
79
- el: coordinatePickupRef,
80
- mapStyle: props.mapStyle,
81
- loaderOptions: {
82
- key: mapKey,
83
- secret: mapSecret,
84
- plugins: ["AMap.PlaceSearch", "AMap.AutoComplete", "AMap.Geocoder"]
85
- }
86
- }, loadAMap);
78
+ if (aMapHook.map) return;
79
+ aMapHook.init();
87
80
  }
88
81
  function loadAMap() {
89
82
  const AMap = aMapHook.AMap;
@@ -1,6 +1,6 @@
1
1
  import AMapLoader from "@amap/amap-jsapi-loader";
2
2
  import { AMapConfig } from "../../config/index.js";
3
- import { onMounted, shallowRef, useTemplateRef, onBeforeUnmount, toValue } from "vue";
3
+ import { onMounted, onBeforeUnmount, shallowRef, useTemplateRef, toValue } from "vue";
4
4
  async function useAMapLoader(options) {
5
5
  const o = options || {};
6
6
  const win = window;
@@ -65,8 +65,8 @@ function newAMapInfoWindow(options, AMap) {
65
65
  function useAMapClassicHook(options, callback) {
66
66
  const o = options;
67
67
  const retRes = {};
68
- let map = null;
69
- onMounted(async () => {
68
+ async function initAMap() {
69
+ if (map) return;
70
70
  const mapPlugins = /* @__PURE__ */ new Set(["AMap.MarkerCluster", ...o?.plugins || [], ...o?.loaderOptions?.plugins || []]);
71
71
  const AMap = await useAMapLoader({
72
72
  ...o?.loaderOptions,
@@ -79,6 +79,10 @@ function useAMapClassicHook(options, callback) {
79
79
  } else if (o.el) {
80
80
  elRef = o.el;
81
81
  }
82
+ if (!elRef.value) {
83
+ console.warn("AMapClassicHook: Map el is required");
84
+ return;
85
+ }
82
86
  const mapOptions = typeof o?.mapOpts === "function" ? o.mapOpts() : o.mapOpts;
83
87
  map = newAMapMap({
84
88
  el: elRef.value,
@@ -111,6 +115,13 @@ function useAMapClassicHook(options, callback) {
111
115
  ...infoWindowOptions
112
116
  }, AMap);
113
117
  callback?.(retRes);
118
+ }
119
+ retRes.init = initAMap;
120
+ let map = null;
121
+ onMounted(async () => {
122
+ if (o.autoLoad !== false) {
123
+ await initAMap();
124
+ }
114
125
  });
115
126
  onBeforeUnmount(() => {
116
127
  map.destroy();
@@ -22,6 +22,8 @@ type InfoOptions = ConstructorParameters<typeof AMap.InfoWindow>[0]
22
22
  type MarkerClusterOptions = ConstructorParameters<typeof AMap.MarkerCluster>[2]
23
23
  type MapOptions = ConstructorParameters<typeof AMap.Map>[1]
24
24
  export type UseAMapHookOptions = {
25
+ // 是否自动加载地图(缺省值为true)
26
+ autoLoad?: boolean
25
27
  // 加载选项
26
28
  plugins?: PluginsType[]
27
29
  loaderOptions?: LoaderOptions
@@ -39,6 +41,7 @@ export type UseAMapHookOptions = {
39
41
  }
40
42
 
41
43
  export type UseAMapHookExample = {
44
+ init: () => Promise<void>
42
45
  map: AMap.Map
43
46
  markerCluster: AMap.MarkerCluster
44
47
  infoWindow: AMap.InfoWindow
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mrxy-yk",
3
- "version": "1.7.0-beta.2",
3
+ "version": "1.7.0-beta.3",
4
4
  "private": false,
5
5
  "type": "module",
6
6
  "description": "A collection of Vue 3 components and utilities",