mirror of
https://github.com/Tencent/tmagic-editor.git
synced 2025-09-26 19:19:59 +08:00
67 lines
1.3 KiB
Vue
67 lines
1.3 KiB
Vue
<template>
|
|
<div class="m-editor-scroll-viewer-container" ref="container">
|
|
<div ref="el" :style="style">
|
|
<slot></slot>
|
|
</div>
|
|
</div>
|
|
</template>
|
|
|
|
<script lang="ts">
|
|
import { computed, defineComponent, onMounted, onUnmounted, ref, watch } from 'vue';
|
|
|
|
import { ScrollViewer } from '@editor/utils/scroll-viewer';
|
|
|
|
export default defineComponent({
|
|
name: 'm-editor-scroll-viewer',
|
|
|
|
props: {
|
|
width: Number,
|
|
height: Number,
|
|
zoom: {
|
|
type: Number,
|
|
default: 1,
|
|
},
|
|
},
|
|
|
|
setup(props) {
|
|
const container = ref<HTMLDivElement>();
|
|
const el = ref<HTMLDivElement>();
|
|
let scrollViewer: ScrollViewer;
|
|
|
|
onMounted(() => {
|
|
if (!container.value || !el.value) return;
|
|
scrollViewer = new ScrollViewer({
|
|
container: container.value,
|
|
target: el.value,
|
|
zoom: props.zoom,
|
|
});
|
|
});
|
|
|
|
onUnmounted(() => {
|
|
scrollViewer.destroy();
|
|
});
|
|
|
|
watch(
|
|
() => props.zoom,
|
|
() => {
|
|
scrollViewer.setZoom(props.zoom);
|
|
},
|
|
);
|
|
|
|
return {
|
|
container,
|
|
el,
|
|
|
|
style: computed(
|
|
() => `
|
|
width: ${props.width}px;
|
|
height: ${(props.height || 0) - 40}px;
|
|
position: absolute;
|
|
margin-top: 30px;
|
|
`,
|
|
),
|
|
};
|
|
},
|
|
});
|
|
</script>
|