top-tab.vue
2.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
<template>
<div>
<van-tabs v-model:active="active" @click-tab="onTabClick">
<van-tab
v-for="(item, index) in tabRoutes"
:title="item.title"
:key="index"
:name="item.name"
>
<slot :name="item.name"></slot>
</van-tab>
</van-tabs>
<div v-show="active === 'share'">
<share ref="shareRefs" :isShowOverlay="true">
<div id="shareContainer" class="map-container"></div>
</share>
</div>
</div>
</template>
<script>
import { defineComponent, nextTick, ref } from "vue";
import routes from "@/router/routes";
import { useRoute } from "vue-router";
import AMapLoader from "@amap/amap-jsapi-loader";
import { CONSTANT } from "../constant";
export default defineComponent({
name: "TopTab",
setup() {
const tabRoutes = ref([]);
const active = ref(null);
const route = useRoute();
let routeQuery = route.query;
let map = null;
let checkLoadedTimeoutId = "";
tabRoutes.value = routes.tabRoutes;
active.value = routeQuery.tabItem;
const onTabClick = (e) => {
if (e.name === "share") {
nextTick(() => {
console.log(active.value);
AMapLoader.load({
key: CONSTANT.MAP_KEY,
version: "1.4.8",
plugins: CONSTANT.MAP_PLUGINS,
}).then((AMap) => {
window.AMap = AMap;
if (map) return;
initMap("shareContainer");
});
});
}
};
const initMap = (id) => {
let check = () => {
checkLoadedTimeoutId && window.clearTimeout(checkLoadedTimeoutId);
let AMap = window.AMap;
if (AMap && typeof AMap.Map == "function") {
window.AMap = AMap;
init(id);
} else {
checkLoadedTimeoutId = check();
}
};
checkLoadedTimeoutId = check();
};
const init = (id) => {
console.log(id);
map = new window.AMap.Map(id);
console.log(map);
return map;
};
return {
tabRoutes,
active,
onTabClick,
};
},
});
</script>
<style lang="scss">
.van-tabs__wrap {
border-bottom: 1px solid #f0f2f5;
}
</style>