go-view/src/views/preview/hooks/useScale.hook.ts
2022-03-17 10:53:18 +08:00

32 lines
706 B
TypeScript

import { onUnmounted, ref, nextTick, computed } from 'vue'
import { usePreviewScale } from '@/hooks/index'
import type { ChartEditStorageType } from '..'
export const useScale = (localStorageInfo: ChartEditStorageType) => {
const previewRef = ref()
const width = ref(localStorageInfo?.editCanvasConfig.width)
const height = ref(localStorageInfo?.editCanvasConfig.height)
// 屏幕适配
nextTick(() => {
const { calcRate, windowResize, unWindowResize } = usePreviewScale(
width.value as number,
height.value as number,
previewRef.value
)
calcRate()
windowResize()
onUnmounted(() => {
unWindowResize()
})
})
return {
previewRef
}
}