|
1 | 1 | <template> |
2 | 2 | <ClientOnly> |
3 | | - <div style="position: relative; width: 100%; height: calc(100vh - 75px)"> |
| 3 | + <div class="fill-height" style="position: relative"> |
4 | 4 | <VeaseViewToolbar /> |
5 | 5 | <slot name="ui"></slot> |
6 | 6 | <v-col |
7 | 7 | ref="viewer" |
8 | | - style=" |
9 | | - overflow: hidden; |
10 | | - position: relative; |
11 | | - z-index: 0; |
12 | | - height: 100%; |
13 | | - width: 100%; |
14 | | - " |
15 | | - class="pa-0" |
| 8 | + style="overflow: hidden; position: relative; z-index: 0" |
| 9 | + :style="{ height: viewerHeight }" |
16 | 10 | @click="get_x_y" |
17 | 11 | @keydown.esc="viewer_store.toggle_picking_mode(false)" |
18 | 12 | /> |
|
21 | 15 | </template> |
22 | 16 |
|
23 | 17 | <script setup> |
| 18 | + const props = defineProps({ |
| 19 | + height: { |
| 20 | + type: String, |
| 21 | + default: "100%", |
| 22 | + }, |
| 23 | + }) |
| 24 | +
|
24 | 25 | const container = useTemplateRef("viewer") |
25 | 26 | const hybridViewerStore = useHybridViewerStore() |
26 | | -
|
| 27 | + const viewer_store = use_viewer_store() |
27 | 28 | const { windowWidth, windowHeight } = useWindowSize() |
28 | 29 | const { width, height } = useElementSize(container) |
29 | 30 |
|
30 | | - watch([windowWidth, windowHeight, height, width], () => { |
| 31 | + const viewerHeight = computed(() => props.height) |
| 32 | +
|
| 33 | + const debouncedResize = debounce(() => { |
31 | 34 | hybridViewerStore.resize(width.value, height.value) |
| 35 | + }, 100) |
| 36 | +
|
| 37 | + watch([windowWidth, windowHeight, width, height], () => { |
| 38 | + debouncedResize() |
32 | 39 | }) |
33 | 40 |
|
34 | 41 | onMounted(async () => { |
35 | 42 | if (import.meta.client) { |
36 | 43 | await hybridViewerStore.initHybridViewer() |
37 | 44 | await nextTick() |
38 | 45 | hybridViewerStore.setContainer(container) |
| 46 | + debouncedResize() |
39 | 47 | } |
40 | 48 | }) |
| 49 | +
|
| 50 | + function debounce(func, wait) { |
| 51 | + let timeout |
| 52 | + return function executedFunction(...args) { |
| 53 | + const later = () => { |
| 54 | + clearTimeout(timeout) |
| 55 | + func(...args) |
| 56 | + } |
| 57 | + clearTimeout(timeout) |
| 58 | + timeout = setTimeout(later, wait) |
| 59 | + } |
| 60 | + } |
| 61 | +
|
| 62 | + function get_x_y(event) { |
| 63 | + emit("click", event) |
| 64 | + } |
| 65 | +
|
| 66 | + defineEmits(["click"]) |
41 | 67 | </script> |
0 commit comments