Skip to content

Commit 186ee72

Browse files
committed
fix(HybridRenderingView): Edit the component to make it more reusable
1 parent 7024ca1 commit 186ee72

File tree

1 file changed

+67
-0
lines changed

1 file changed

+67
-0
lines changed

components/HybridRenderingView.vue

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
<template>
2+
<ClientOnly>
3+
<div class="fill-height" style="position: relative;">
4+
<VeaseViewToolbar />
5+
<slot name="ui"></slot>
6+
<v-col
7+
ref="viewer"
8+
style="overflow: hidden; position: relative; z-index: 0;"
9+
:style="{ height: viewerHeight }"
10+
@click="get_x_y"
11+
@keydown.esc="viewer_store.toggle_picking_mode(false)"
12+
/>
13+
</div>
14+
</ClientOnly>
15+
</template>
16+
17+
<script setup>
18+
const props = defineProps({
19+
height: {
20+
type: String,
21+
default: '100%',
22+
},
23+
});
24+
25+
const container = useTemplateRef('viewer');
26+
const hybridViewerStore = useHybridViewerStore();
27+
const viewer_store = use_viewer_store();
28+
const { windowWidth, windowHeight } = useWindowSize();
29+
const { width, height } = useElementSize(container);
30+
31+
const viewerHeight = computed(() => props.height);
32+
33+
const debouncedResize = debounce(() => {
34+
hybridViewerStore.resize(width.value, height.value);
35+
}, 100);
36+
37+
watch([windowWidth, windowHeight, width, height], () => {
38+
debouncedResize();
39+
});
40+
41+
onMounted(async () => {
42+
if (import.meta.client) {
43+
await hybridViewerStore.initHybridViewer();
44+
await nextTick();
45+
hybridViewerStore.setContainer(container);
46+
debouncedResize();
47+
}
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']);
67+
</script>

0 commit comments

Comments
 (0)