useScaleCanvas.ts 630 B

1234567891011121314151617181920212223
  1. import { computed } from 'vue'
  2. import { useStore } from 'vuex'
  3. import { MutationTypes, State } from '@/store'
  4. export default () => {
  5. const store = useStore<State>()
  6. const canvasPercentage = computed(() => store.state.canvasPercentage)
  7. const scaleCanvas = (command: '+' | '-') => {
  8. let percentage = canvasPercentage.value
  9. const step = 5
  10. const max = 120
  11. const min = 60
  12. if(command === '+' && percentage <= max) percentage += step
  13. if(command === '-' && percentage >= min) percentage -= step
  14. store.commit(MutationTypes.SET_CANVAS_PERCENTAGE, percentage)
  15. }
  16. return {
  17. scaleCanvas,
  18. }
  19. }