mirror of
https://github.com/pipipi-pikachu/PPTist.git
synced 2025-04-15 02:20:00 +08:00
refactor: 修改形状、图片翻转类型定义
This commit is contained in:
parent
243e605f10
commit
47212250c8
@ -29,10 +29,7 @@ export const slides: Slide[] = [
|
||||
path: 'M 0 0 L 0 200 L 200 200 Z',
|
||||
fill: '#5b9bd5',
|
||||
fixedRatio: false,
|
||||
flip: {
|
||||
x: 180,
|
||||
y: 0,
|
||||
},
|
||||
flipH: true,
|
||||
rotate: 0
|
||||
},
|
||||
{
|
||||
|
@ -45,8 +45,8 @@ export interface PPTTextElement extends PPTBaseElement {
|
||||
}
|
||||
|
||||
export interface ImageOrShapeFlip {
|
||||
x?: number;
|
||||
y?: number;
|
||||
flipH?: boolean;
|
||||
flipV?: boolean;
|
||||
}
|
||||
export interface ImageElementFilters {
|
||||
'blur'?: string;
|
||||
@ -69,7 +69,8 @@ export interface PPTImageElement extends PPTBaseElement {
|
||||
outline?: PPTElementOutline;
|
||||
filters?: ImageElementFilters;
|
||||
clip?: ImageElementClip;
|
||||
flip?: ImageOrShapeFlip;
|
||||
flipH?: boolean;
|
||||
flipV?: boolean;
|
||||
shadow?: PPTElementShadow;
|
||||
}
|
||||
|
||||
@ -88,7 +89,8 @@ export interface PPTShapeElement extends PPTBaseElement {
|
||||
rotate: number;
|
||||
outline?: PPTElementOutline;
|
||||
opacity?: number;
|
||||
flip?: ImageOrShapeFlip;
|
||||
flipH?: boolean;
|
||||
flipV?: boolean;
|
||||
shadow?: PPTElementShadow;
|
||||
}
|
||||
|
||||
|
@ -3,13 +3,13 @@
|
||||
<CheckboxButtonGroup class="row">
|
||||
<CheckboxButton
|
||||
style="flex: 1;"
|
||||
:checked="flip.x === 180"
|
||||
@click="updateFlip({ x: flip.x === 180 ? 0 : 180, y: flip.y })"
|
||||
:checked="flipH"
|
||||
@click="updateFlip({ flipH: !flipH })"
|
||||
><IconFlipVertically /> 垂直翻转</CheckboxButton>
|
||||
<CheckboxButton
|
||||
style="flex: 1;"
|
||||
:checked="flip.y === 180"
|
||||
@click="updateFlip({ x: flip.x, y: flip.y === 180 ? 0 : 180 })"
|
||||
:checked="flipV"
|
||||
@click="updateFlip({ flipV: !flipV })"
|
||||
><IconFlipHorizontally /> 水平翻转</CheckboxButton>
|
||||
</CheckboxButtonGroup>
|
||||
</div>
|
||||
@ -18,7 +18,7 @@
|
||||
<script lang="ts">
|
||||
import { computed, defineComponent, ref, watch } from 'vue'
|
||||
import { MutationTypes, useStore } from '@/store'
|
||||
import { PPTImageElement, PPTShapeElement } from '@/types/slides'
|
||||
import { PPTImageElement, PPTShapeElement, ImageOrShapeFlip } from '@/types/slides'
|
||||
import useHistorySnapshot from '@/hooks/useHistorySnapshot'
|
||||
|
||||
export default defineComponent({
|
||||
@ -27,33 +27,26 @@ export default defineComponent({
|
||||
const store = useStore()
|
||||
const handleElement = computed<PPTImageElement | PPTShapeElement>(() => store.getters.handleElement)
|
||||
|
||||
const flip = ref({
|
||||
x: 0,
|
||||
y: 0,
|
||||
})
|
||||
const flipH = ref(false)
|
||||
const flipV = ref(false)
|
||||
|
||||
watch(handleElement, () => {
|
||||
if (!handleElement.value || !['image', 'shape'].includes(handleElement.value.type)) return
|
||||
|
||||
if (handleElement.value.flip) {
|
||||
flip.value = {
|
||||
x: handleElement.value.flip.x || 0,
|
||||
y: handleElement.value.flip.y || 0,
|
||||
}
|
||||
}
|
||||
else flip.value = { x: 0, y: 0 }
|
||||
flipH.value = !!handleElement.value.flipH
|
||||
flipV.value = !!handleElement.value.flipV
|
||||
}, { deep: true, immediate: true })
|
||||
|
||||
const { addHistorySnapshot } = useHistorySnapshot()
|
||||
|
||||
const updateFlip = (value: number) => {
|
||||
const props = { flip: value }
|
||||
store.commit(MutationTypes.UPDATE_ELEMENT, { id: handleElement.value.id, props })
|
||||
const updateFlip = (flipProps: ImageOrShapeFlip) => {
|
||||
store.commit(MutationTypes.UPDATE_ELEMENT, { id: handleElement.value.id, props: flipProps })
|
||||
addHistorySnapshot()
|
||||
}
|
||||
|
||||
return {
|
||||
flip,
|
||||
flipH,
|
||||
flipV,
|
||||
updateFlip,
|
||||
}
|
||||
},
|
||||
|
@ -66,8 +66,9 @@ export default defineComponent({
|
||||
const shadow = computed(() => props.elementInfo.shadow)
|
||||
const { shadowStyle } = useElementShadow(shadow)
|
||||
|
||||
const flip = computed(() => props.elementInfo.flip)
|
||||
const { flipStyle } = useElementFlip(flip)
|
||||
const flipH = computed(() => props.elementInfo.flipH)
|
||||
const flipV = computed(() => props.elementInfo.flipV)
|
||||
const { flipStyle } = useElementFlip(flipH, flipV)
|
||||
|
||||
const clip = computed(() => props.elementInfo.clip)
|
||||
const { clipShape, imgPosition } = useClipImage(clip)
|
||||
|
@ -97,8 +97,9 @@ export default defineComponent({
|
||||
const shadow = computed(() => props.elementInfo.shadow)
|
||||
const { shadowStyle } = useElementShadow(shadow)
|
||||
|
||||
const flip = computed(() => props.elementInfo.flip)
|
||||
const { flipStyle } = useElementFlip(flip)
|
||||
const flipH = computed(() => props.elementInfo.flipH)
|
||||
const flipV = computed(() => props.elementInfo.flipV)
|
||||
const { flipStyle } = useElementFlip(flipH, flipV)
|
||||
|
||||
const clip = computed(() => props.elementInfo.clip)
|
||||
const { clipShape, imgPosition } = useClipImage(clip)
|
||||
|
@ -82,8 +82,9 @@ export default defineComponent({
|
||||
const shadow = computed(() => props.elementInfo.shadow)
|
||||
const { shadowStyle } = useElementShadow(shadow)
|
||||
|
||||
const flip = computed(() => props.elementInfo.flip)
|
||||
const { flipStyle } = useElementFlip(flip)
|
||||
const flipH = computed(() => props.elementInfo.flipH)
|
||||
const flipV = computed(() => props.elementInfo.flipV)
|
||||
const { flipStyle } = useElementFlip(flipH, flipV)
|
||||
|
||||
return {
|
||||
shadowStyle,
|
||||
|
@ -100,8 +100,9 @@ export default defineComponent({
|
||||
const shadow = computed(() => props.elementInfo.shadow)
|
||||
const { shadowStyle } = useElementShadow(shadow)
|
||||
|
||||
const flip = computed(() => props.elementInfo.flip)
|
||||
const { flipStyle } = useElementFlip(flip)
|
||||
const flipH = computed(() => props.elementInfo.flipH)
|
||||
const flipV = computed(() => props.elementInfo.flipV)
|
||||
const { flipStyle } = useElementFlip(flipH, flipV)
|
||||
|
||||
return {
|
||||
handleSelectElement,
|
||||
|
@ -1,20 +1,15 @@
|
||||
import { computed, Ref } from 'vue'
|
||||
import { ImageOrShapeFlip } from '@/types/slides'
|
||||
|
||||
// 计算元素的翻转样式
|
||||
export default (flip: Ref<ImageOrShapeFlip | undefined>) => {
|
||||
export default (flipH: Ref<boolean | undefined>, flipV: Ref<boolean | undefined>) => {
|
||||
const flipStyle = computed(() => {
|
||||
if (flip.value) {
|
||||
let style = ''
|
||||
let style = ''
|
||||
|
||||
const { x, y } = flip.value
|
||||
if (x && y) style = `rotateX(${x}deg) rotateY(${y}deg)`
|
||||
else if (x) style = `rotateX(${x}deg)`
|
||||
else if (y) style = `rotateY(${y}deg)`
|
||||
if (flipH.value && flipV.value) style = 'rotateX(180deg) rotateY(180deg)'
|
||||
else if (flipH.value) style = 'rotateX(180deg)'
|
||||
else if (flipV.value) style = 'rotateY(180deg)'
|
||||
|
||||
return style
|
||||
}
|
||||
return ''
|
||||
return style
|
||||
})
|
||||
|
||||
return {
|
||||
|
Loading…
x
Reference in New Issue
Block a user