mrxy-yk 1.5.0 → 1.6.0-beta.2
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.
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { ElDialog, ElForm, ElFormItem, ElAutocomplete, ElInput, ElButton, ElCheckbox } from "element-plus/es";
|
|
2
|
-
import { defineComponent, onMounted, watch, nextTick, computed, ref, onUnmounted, openBlock, createBlock, withCtx, createVNode, createElementVNode, toDisplayString, createElementBlock, createCommentVNode, createTextVNode } from "vue";
|
|
2
|
+
import { defineComponent, onMounted, watch, nextTick, computed, ref, shallowRef, onUnmounted, openBlock, createBlock, withCtx, createVNode, createElementVNode, toDisplayString, createElementBlock, createCommentVNode, createTextVNode } from "vue";
|
|
3
3
|
import { ElMessage } from "element-plus";
|
|
4
|
-
import {
|
|
4
|
+
import { useAMapClassicHook } from "../../utils/amap/index.js";
|
|
5
5
|
import { AMapConfig } from "../../config/index.js";
|
|
6
6
|
const _hoisted_1 = { class: "autocomplete-subtitle" };
|
|
7
7
|
const _hoisted_2 = { key: 0 };
|
|
@@ -30,14 +30,14 @@ var _sfc_main = /* @__PURE__ */ defineComponent({
|
|
|
30
30
|
const mapKey = props.mapKey || AMapConfig.mapKey;
|
|
31
31
|
const mapSecret = props.mapSecret || AMapConfig.mapSecret;
|
|
32
32
|
watch(() => props.modelValue, (nv) => {
|
|
33
|
-
if (nv && !map) {
|
|
33
|
+
if (nv && !aMapHook.value.map) {
|
|
34
34
|
nextTick(() => {
|
|
35
35
|
loadAMap();
|
|
36
36
|
});
|
|
37
37
|
} else {
|
|
38
38
|
placeSearch.clear();
|
|
39
39
|
showMarker(props.lnglat, props.address);
|
|
40
|
-
emits("open", map);
|
|
40
|
+
emits("open", aMapHook.value.map);
|
|
41
41
|
}
|
|
42
42
|
});
|
|
43
43
|
const changeDialogCustomer = computed({
|
|
@@ -63,28 +63,27 @@ var _sfc_main = /* @__PURE__ */ defineComponent({
|
|
|
63
63
|
emits("update:address", pickupForm.value.address);
|
|
64
64
|
emits("update:modelValue", false);
|
|
65
65
|
};
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
66
|
+
const coordinatePickupRef = shallowRef();
|
|
67
|
+
const aMapHook = useAMapClassicHook({
|
|
68
|
+
el: coordinatePickupRef,
|
|
69
|
+
mapStyle: props.mapStyle,
|
|
70
|
+
loaderOptions: {
|
|
71
71
|
key: mapKey,
|
|
72
72
|
secret: mapSecret,
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
});
|
|
73
|
+
plugins: ["AMap.PlaceSearch", "AMap.AutoComplete", "AMap.Geocoder"]
|
|
74
|
+
}
|
|
75
|
+
}, loadAMap);
|
|
76
|
+
function loadAMap() {
|
|
77
|
+
const AMap = aMapHook.value.AMap;
|
|
78
|
+
const map = aMapHook.value.map;
|
|
79
|
+
satelliteLayer = new AMap["TileLayer"].Satellite();
|
|
80
|
+
map.on("click", clickHandler);
|
|
81
|
+
autoComplete = new AMap["Autocomplete"]({ city: "全国" });
|
|
82
|
+
placeSearch = new AMap["PlaceSearch"]({ map, city: "全国", autoFitView: true });
|
|
83
|
+
placeSearch.on("markerClick", placeMarkerClick);
|
|
84
|
+
geocoder = new AMap["Geocoder"]();
|
|
85
|
+
showMarker(props.lnglat, props.address);
|
|
86
|
+
emits("open", { map, AMap });
|
|
88
87
|
}
|
|
89
88
|
const clickHandler = async (e) => {
|
|
90
89
|
const { lng, lat } = e.lnglat;
|
|
@@ -93,6 +92,7 @@ var _sfc_main = /* @__PURE__ */ defineComponent({
|
|
|
93
92
|
showMarker(lnglat, address);
|
|
94
93
|
};
|
|
95
94
|
onUnmounted(function() {
|
|
95
|
+
const map = aMapHook.value.map;
|
|
96
96
|
if (map) {
|
|
97
97
|
map.off("click", clickHandler);
|
|
98
98
|
map.destroy();
|
|
@@ -166,6 +166,7 @@ var _sfc_main = /* @__PURE__ */ defineComponent({
|
|
|
166
166
|
}
|
|
167
167
|
let marker = null;
|
|
168
168
|
function showMarker(lnglat, address) {
|
|
169
|
+
const { map, AMap } = aMapHook.value;
|
|
169
170
|
if (lnglat) {
|
|
170
171
|
const position = lnglat.split(",");
|
|
171
172
|
if (marker) {
|
|
@@ -185,6 +186,7 @@ var _sfc_main = /* @__PURE__ */ defineComponent({
|
|
|
185
186
|
let satelliteLayer = null;
|
|
186
187
|
const isSatelliteLayer = ref(false);
|
|
187
188
|
function setSatelliteLayer() {
|
|
189
|
+
const { map } = aMapHook.value;
|
|
188
190
|
if (isSatelliteLayer.value) {
|
|
189
191
|
map.add(satelliteLayer);
|
|
190
192
|
} else {
|
package/dist/index.js
CHANGED
|
@@ -9,7 +9,7 @@ import { useEmptyHooks } from "./components/empty/hooks/index.js";
|
|
|
9
9
|
import { MatchUnit } from "./utils/match-unit/index.js";
|
|
10
10
|
import { TransitionFade } from "./utils/transition-fade/index.js";
|
|
11
11
|
import { echarts } from "./utils/echarts/index.js";
|
|
12
|
-
import {
|
|
12
|
+
import { newAMapInfoWindow, newAMapMap, newAMapMarkerCluster, useAMapClassicHook, useAMapLoader } from "./utils/amap/index.js";
|
|
13
13
|
import { StorageUtil } from "./utils/storage/index.js";
|
|
14
14
|
import { Pages } from "./entity/Pages.js";
|
|
15
15
|
import { BigFloat } from "./entity/BigFloat.js";
|
|
@@ -49,7 +49,6 @@ var index = {
|
|
|
49
49
|
}
|
|
50
50
|
};
|
|
51
51
|
export {
|
|
52
|
-
AMapLoader,
|
|
53
52
|
AMapUtil,
|
|
54
53
|
ArrayUtil,
|
|
55
54
|
BigFloat,
|
|
@@ -105,6 +104,7 @@ export {
|
|
|
105
104
|
positiveNumberRule,
|
|
106
105
|
positiveNumberTag,
|
|
107
106
|
required,
|
|
107
|
+
useAMapClassicHook,
|
|
108
108
|
useAMapLoader,
|
|
109
109
|
useEChartsRef,
|
|
110
110
|
useEcBarOption,
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { AMapClassProxy, LoaderOptions,
|
|
1
|
+
import { AMapClassProxy, LoaderOptions, UseAMapHookExample, UseAMapHookOptions } from './type';
|
|
2
2
|
import { AMap } from './@type/index';
|
|
3
3
|
import { TemplateRef, ShallowRef } from 'vue';
|
|
4
4
|
export * from './utils';
|
|
@@ -35,4 +35,10 @@ export declare function newAMapMarkerCluster(options: {
|
|
|
35
35
|
* @param AMap { AMap } AMap存在时可以传入跳过`setAMap`过程
|
|
36
36
|
*/
|
|
37
37
|
export declare function newAMapInfoWindow(options: ConstructorParameters<typeof AMap.InfoWindow>[0], AMap?: AMap): AMapClassProxy<AMap.InfoWindow>;
|
|
38
|
-
|
|
38
|
+
/**
|
|
39
|
+
* 常用高德地图配套功能包含地图(Map),聚合标记点(MarkerCluster),信息窗口(InfoWindow)
|
|
40
|
+
* 返回的hook实例需要在onMounted之后才能使用
|
|
41
|
+
* @param options
|
|
42
|
+
* @param callback
|
|
43
|
+
*/
|
|
44
|
+
export declare function useAMapClassicHook(options: UseAMapHookOptions, callback?: (res: ShallowRef<UseAMapHookExample>) => void): ShallowRef<UseAMapHookExample>;
|
package/dist/utils/amap/index.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import
|
|
1
|
+
import AMapLoader from "@amap/amap-jsapi-loader";
|
|
2
2
|
import { AMapConfig } from "../../config/index.js";
|
|
3
|
-
import { toValue } from "vue";
|
|
3
|
+
import { shallowRef, onMounted, useTemplateRef, onBeforeUnmount, toValue } from "vue";
|
|
4
4
|
async function useAMapLoader(options) {
|
|
5
5
|
const o = options || {};
|
|
6
6
|
const win = window;
|
|
7
7
|
win._AMapSecurityConfig = { securityJsCode: o.secret || AMapConfig.mapSecret };
|
|
8
|
-
return await
|
|
8
|
+
return await AMapLoader.load({
|
|
9
9
|
key: o.key || AMapConfig.mapKey,
|
|
10
10
|
version: "2.0",
|
|
11
11
|
plugins: o.plugins,
|
|
@@ -62,26 +62,56 @@ function newAMapInfoWindow(options, AMap) {
|
|
|
62
62
|
return new AMap2.InfoWindow(o);
|
|
63
63
|
}, AMap);
|
|
64
64
|
}
|
|
65
|
-
|
|
65
|
+
function useAMapClassicHook(options, callback) {
|
|
66
66
|
const o = options;
|
|
67
|
-
const
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
67
|
+
const retRes = shallowRef({});
|
|
68
|
+
let map = null;
|
|
69
|
+
onMounted(async () => {
|
|
70
|
+
const AMap = await useAMapLoader({
|
|
71
|
+
plugins: o.plugins,
|
|
72
|
+
...o?.loaderOptions
|
|
73
|
+
});
|
|
74
|
+
let elRef = shallowRef();
|
|
75
|
+
if (typeof o.el === "string") {
|
|
76
|
+
elRef = useTemplateRef(o.el);
|
|
77
|
+
} else if (o.el) {
|
|
78
|
+
elRef = o.el;
|
|
79
|
+
}
|
|
80
|
+
map = newAMapMap({
|
|
81
|
+
el: elRef.value,
|
|
82
|
+
mapStyle: o.mapStyle,
|
|
83
|
+
opts: o.mapOpts
|
|
84
|
+
}, AMap);
|
|
85
|
+
map.destroy();
|
|
86
|
+
const markerCluster = newAMapMarkerCluster({
|
|
87
|
+
map,
|
|
88
|
+
markerClusterOptions: Object.assign({
|
|
89
|
+
renderMarker: o.renderMarker,
|
|
90
|
+
renderClusterMarker: o.renderClusterMarker
|
|
91
|
+
}, o.markerClusterOpts)
|
|
92
|
+
}, AMap);
|
|
93
|
+
const infoWindow = newAMapInfoWindow({
|
|
94
|
+
isCustom: true,
|
|
95
|
+
content: o.infoWindowContent?.value || void 0,
|
|
96
|
+
...o?.infoWindowOpts
|
|
97
|
+
}, AMap);
|
|
98
|
+
retRes.value = {
|
|
99
|
+
map,
|
|
100
|
+
markerCluster,
|
|
101
|
+
infoWindow,
|
|
102
|
+
AMap
|
|
103
|
+
};
|
|
104
|
+
callback?.(retRes);
|
|
74
105
|
});
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
...o.mapOption
|
|
106
|
+
onBeforeUnmount(() => {
|
|
107
|
+
map.destroy();
|
|
78
108
|
});
|
|
79
|
-
return
|
|
109
|
+
return retRes;
|
|
80
110
|
}
|
|
81
111
|
export {
|
|
82
|
-
AMapLoader,
|
|
83
112
|
newAMapInfoWindow,
|
|
84
113
|
newAMapMap,
|
|
85
114
|
newAMapMarkerCluster,
|
|
115
|
+
useAMapClassicHook,
|
|
86
116
|
useAMapLoader
|
|
87
117
|
};
|
|
@@ -2,7 +2,7 @@ import { AMap, AMapType } from './@type/AMap';
|
|
|
2
2
|
import { LoadOption } from './@type';
|
|
3
3
|
import { MapOptions } from './@type/Map';
|
|
4
4
|
import { RenderMarkerCallbackParams } from './@type/MarkerCluster';
|
|
5
|
-
type PluginsType = 'AMap.MarkerCluster' | 'AMap.Weather' | string
|
|
5
|
+
type PluginsType = 'AMap.MarkerCluster' | 'AMap.Weather' | 'AMap.AutoComplete' | 'AMap.Geocoder' | string
|
|
6
6
|
|
|
7
7
|
export type LoaderOptions = {
|
|
8
8
|
// key 高德地图key(缺省使用全局配置)
|
|
@@ -19,13 +19,20 @@ export type AMapClassProxy<T> = T & { setAMap (AMap: AMap): void }
|
|
|
19
19
|
|
|
20
20
|
// region useAMapHook
|
|
21
21
|
export type UseAMapHookOptions = {
|
|
22
|
-
|
|
22
|
+
// 加载选项
|
|
23
|
+
plugins?: PluginsType[]
|
|
24
|
+
loaderOptions?: LoaderOptions
|
|
25
|
+
// 地图
|
|
26
|
+
el: ShallowRef<HTMLDivElement> | string
|
|
23
27
|
mapStyle?: string
|
|
28
|
+
mapOpts?: ConstructorParameters<typeof AMap.Map>[1]
|
|
29
|
+
// 聚合标记
|
|
24
30
|
renderMarker? (e: RenderMarkerCallbackParams): void
|
|
25
31
|
renderClusterMarker? (count: number, marker: AMap.Marker): void
|
|
26
|
-
infoWindowContent: ShallowRef<HTMLDivElement>
|
|
27
|
-
mapOpts?: ConstructorParameters<typeof AMap.Map>[1]
|
|
28
32
|
markerClusterOpts?: ConstructorParameters<typeof AMap.MarkerCluster>[2]
|
|
33
|
+
// 信息窗体
|
|
34
|
+
infoWindowContent?: ShallowRef<HTMLDivElement>
|
|
35
|
+
infoWindowOpts?: ConstructorParameters<typeof AMap.InfoWindow>[0]
|
|
29
36
|
}
|
|
30
37
|
|
|
31
38
|
export type UseAMapHookExample = {
|
|
@@ -35,22 +42,3 @@ export type UseAMapHookExample = {
|
|
|
35
42
|
AMap: AMap
|
|
36
43
|
}
|
|
37
44
|
// endregion
|
|
38
|
-
|
|
39
|
-
export type LoaderOptions1 = {
|
|
40
|
-
// key 高德地图key(缺省使用全局配置)
|
|
41
|
-
key?: string,
|
|
42
|
-
// secret 高德地图secret(缺省使用全局配置)
|
|
43
|
-
secret?: string,
|
|
44
|
-
// el 地图容器元素
|
|
45
|
-
el: HTMLDivElement,
|
|
46
|
-
// plugins 插件列表
|
|
47
|
-
plugins?: string[],
|
|
48
|
-
// mapStyle 地图样式
|
|
49
|
-
mapStyle?: string,
|
|
50
|
-
// loadOption 加载选项
|
|
51
|
-
loadOption?: LoadOption,
|
|
52
|
-
// mapOption 地图选项
|
|
53
|
-
mapOption?: MapOptions
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
export type AMapResolve = { AMap: AMapType, map: AMap.Map }
|