atom.vue 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. <template>
  2. <div class="inject-com" :style="style" v-if="style && pos">
  3. <!-- <div class="test">{{pos}}</div> -->
  4. <component
  5. :is="custComponent"
  6. v-bind="{ ...custProps, pos, platform: sdk.isMap ? 'map' : 'scene' }"
  7. ></component>
  8. </div>
  9. </template>
  10. <script setup lang="ts">
  11. import { laserKey } from '../constant'
  12. import { inject, computed, ref, watch } from 'vue'
  13. import { Pos } from '../../index'
  14. const props = defineProps<{
  15. pos: Pos
  16. custComponent: any
  17. custProps: any
  18. }>()
  19. const screen = ref<Pos>(null)
  20. const sdk = inject(laserKey)
  21. const style = computed(
  22. () =>
  23. screen.value && {
  24. left: screen.value.x + 'px',
  25. top: screen.value.y + 'px'
  26. }
  27. )
  28. const updatePos = () => {
  29. if (props.pos) {
  30. const data = sdk.getScreenByPoint(props.pos)
  31. screen.value = data.trueSide ? data.pos : null
  32. }
  33. }
  34. sdk.on('posChange', updatePos)
  35. watch(props, updatePos)
  36. updatePos()
  37. sdk.isMap && sdk.on('mapZoomLevelChange', updatePos)
  38. </script>
  39. <style lang="scss" scoped>
  40. @import './style.scss';
  41. </style>