fuchengshen
2022-07-09 3a25c05b5ab837714f30469cdcb1e2a77d8d7f6c
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
<template>
  <main-operation @childMounted="onChildMounted" />
  <template v-if="mapLoaded">
    <template v-for="comp in widgets" :key="comp.key">
      <mars-widget v-if="openAtStart.includes(comp.name) && comp.visible" v-model:visible="comp.visible" :widget="comp" />
    </template>
  </template>
</template>
 
<script setup lang="ts">
import { ref, provide, computed } from "vue"
import MainOperation from "@mars/components/mars-work/main-operation.vue"
import { useWidgetStore } from "@mars/widgets/common/store/widget"
import MarsWidget from "@mars/widgets/widget.vue"
 
const widgetStore = useWidgetStore()
 
const mapLoaded = ref(false) // map加载完成
 
const widgets = computed(() => widgetStore.state.widgets)
const openAtStart = computed(() => widgetStore.state.openAtStart)
 
let mapInstance: any = null
provide("getMapInstance", () => {
  return mapInstance
})
 
const marsOnload = (map: any) => {
  mapInstance = map
  mapLoaded.value = true
}
 
function onChildMounted() {
  window.marsEditor.useLifecycle() // 通知执行mapWork.onMounted
  marsOnload(window._mapInstance)
}
</script>
<style lang="less" scoped></style>