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
39
40
41
42
43
44
45
46
47
48
49
50
51
<template>
  <PannelComponent v-if="loaded" @vnode-before-mount="onChildMounted" @vnode-unmounted="onChildUnmounted" />
</template>
<script lang="ts" setup>
/**
 * 操作面板入口
 * @copyright 火星科技 mars3d.cn
 * @author 木遥 2022-01-01
 */
import { defineAsyncComponent, h, ref, provide } from "vue"
import { getExampleId } from "@mars/utils/mars-util"
 
const modules = import.meta.glob("../../example/**/index.vue")
 
let componentName: string | null = ""
 
let PannelComponent: any
 
provide("getCurrentWidget", () => {
  console.log(`注意:${componentName}为非widget组件,通过无法获取到currentWidget`)
 
  return null
})
 
const emits = defineEmits(["childMounted", "childUnmounted"])
 
const loaded = ref(false)
const exampleId = getExampleId()
if (exampleId) {
  componentName = exampleId
  PannelComponent = defineAsyncComponent({
    loader: modules[`../../example/${componentName}/index.vue`],
    errorComponent: {
      render() {
        return h("")
      }
    }
  })
  // console.log(PannelComponent)
  loaded.value = true
}
const onChildMounted = (e: any) => {
  emits("childMounted")
}
 
const onChildUnmounted = () => {
  emits("childUnmounted")
}
</script>
 
<style scoped lang="less"></style>