wangrong
2026-08-30 4c949c0dc9bcae785c281c9d8125295f09810b15
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
<script lang="ts" setup>
import { dvMainStoreWithOut } from '@/store/modules/data-visualization/dvMain'
import { onBeforeUnmount, onMounted } from 'vue'
import { useEmitt } from '@/hooks/web/useEmitt'
 
const dvMainStore = dvMainStoreWithOut()
 
const props = defineProps({
  themes: {
    type: String,
    default: 'light'
  },
  componentType: {
    type: String,
    default: 'button'
  },
  showPosition: {
    required: false,
    type: String,
    default: 'preview'
  }
})
 
const fullscreenChange = () => {
  const isFullscreen = !!document.fullscreenElement
  dvMainStore.setFullscreenFlag(isFullscreen)
 
  // 编辑界面使用
  if (props.showPosition === 'edit') {
    dvMainStore.setEditMode(isFullscreen ? 'preview' : 'edit')
  }
 
  // 大屏编辑使用
  if (props.showPosition === 'dvEdit') {
    useEmitt().emitter.emit('canvasScrollRestore')
  }
}
 
const toggleFullscreen = () => {
  const bodyNode = document.querySelector('body')
  if (!document.fullscreenElement) {
    bodyNode?.requestFullscreen()
  } else {
    document.exitFullscreen()
  }
}
 
// 针对钉钉windows版无法退出全屏问题 这里主动退出
const handleKeydown = event => {
  if (event.key === 'Escape' && document.fullscreenElement) {
    document.exitFullscreen()
  }
}
 
onMounted(() => {
  document.addEventListener('fullscreenchange', fullscreenChange)
  document.addEventListener('keydown', handleKeydown)
})
 
onBeforeUnmount(() => {
  document.removeEventListener('fullscreenchange', fullscreenChange)
  document.removeEventListener('keydown', handleKeydown)
})
 
defineExpose({
  toggleFullscreen
})
</script>
 
<template><span></span></template>
 
<style lang="less" scoped></style>