useCommonOperate.ts 1.8 KB

123456789101112131415161718192021222324252627282930313233
  1. import { computed, Ref } from 'vue'
  2. import { OPERATE_KEYS, OperateResizablePointTypes, OperateBorderLineTypes } from '@/types/edit'
  3. export default (scaleWidth: Ref<number>, scaleHeight: Ref<number>) => {
  4. const resizablePoints = computed(() => {
  5. return [
  6. { type: OperateResizablePointTypes.TL, direction: OPERATE_KEYS.LEFT_TOP, style: {} },
  7. { type: OperateResizablePointTypes.TC, direction: OPERATE_KEYS.TOP, style: {left: scaleWidth.value / 2 + 'px'} },
  8. { type: OperateResizablePointTypes.TR, direction: OPERATE_KEYS.RIGHT_TOP, style: {left: scaleWidth.value + 'px'} },
  9. { type: OperateResizablePointTypes.ML, direction: OPERATE_KEYS.LEFT, style: {top: scaleHeight.value / 2 + 'px'} },
  10. { type: OperateResizablePointTypes.MR, direction: OPERATE_KEYS.RIGHT, style: {left: scaleWidth.value + 'px', top: scaleHeight.value / 2 + 'px'} },
  11. { type: OperateResizablePointTypes.BL, direction: OPERATE_KEYS.LEFT_BOTTOM, style: {top: scaleHeight.value + 'px'} },
  12. { type: OperateResizablePointTypes.BC, direction: OPERATE_KEYS.BOTTOM, style: {left: scaleWidth.value / 2 + 'px', top: scaleHeight.value + 'px'} },
  13. { type: OperateResizablePointTypes.BR, direction: OPERATE_KEYS.RIGHT_BOTTOM, style: {left: scaleWidth.value + 'px', top: scaleHeight.value + 'px'} },
  14. ]
  15. })
  16. const borderLines = computed(() => {
  17. return [
  18. { type: OperateBorderLineTypes.T, style: {width: scaleWidth.value + 'px'} },
  19. { type: OperateBorderLineTypes.B, style: {top: scaleHeight.value + 'px', width: scaleWidth.value + 'px'} },
  20. { type: OperateBorderLineTypes.L, style: {height: scaleHeight.value + 'px'} },
  21. { type: OperateBorderLineTypes.R, style: {left: scaleWidth.value + 'px', height: scaleHeight.value + 'px'} },
  22. ]
  23. })
  24. return {
  25. scaleWidth,
  26. scaleHeight,
  27. resizablePoints,
  28. borderLines,
  29. }
  30. }