mirror of
https://github.com/pipipi-pikachu/PPTist.git
synced 2025-04-15 02:20:00 +08:00
完善拖拽事件相关
This commit is contained in:
parent
b68912314d
commit
b5f027465c
@ -37,7 +37,7 @@ export default () => {
|
|||||||
|
|
||||||
const createImageElement = (src: string) => {
|
const createImageElement = (src: string) => {
|
||||||
getImageSize(src).then(({ width, height }) => {
|
getImageSize(src).then(({ width, height }) => {
|
||||||
const scale = width / height
|
const scale = height / width
|
||||||
|
|
||||||
if(scale < VIEWPORT_ASPECT_RATIO && width > VIEWPORT_SIZE) {
|
if(scale < VIEWPORT_ASPECT_RATIO && width > VIEWPORT_SIZE) {
|
||||||
width = VIEWPORT_SIZE
|
width = VIEWPORT_SIZE
|
||||||
@ -117,7 +117,7 @@ export default () => {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
const createTextElement = (position: CommonElementPosition) => {
|
const createTextElement = (position: CommonElementPosition, content = '请输入内容') => {
|
||||||
const { left, top, width, height } = position
|
const { left, top, width, height } = position
|
||||||
createElement({
|
createElement({
|
||||||
type: 'text',
|
type: 'text',
|
||||||
@ -126,7 +126,7 @@ export default () => {
|
|||||||
top,
|
top,
|
||||||
width,
|
width,
|
||||||
height,
|
height,
|
||||||
content: '请输入内容',
|
content,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -4,6 +4,7 @@ import { decrypt } from '@/utils/crypto'
|
|||||||
import { PPTElement, Slide } from '@/types/slides'
|
import { PPTElement, Slide } from '@/types/slides'
|
||||||
import { createRandomCode } from '@/utils/common'
|
import { createRandomCode } from '@/utils/common'
|
||||||
import useHistorySnapshot from '@/hooks/useHistorySnapshot'
|
import useHistorySnapshot from '@/hooks/useHistorySnapshot'
|
||||||
|
import useCreateElement from '@/hooks/useCreateElement'
|
||||||
|
|
||||||
interface PasteTextClipboardDataOptions {
|
interface PasteTextClipboardDataOptions {
|
||||||
onlySlide?: boolean;
|
onlySlide?: boolean;
|
||||||
@ -15,6 +16,7 @@ export default () => {
|
|||||||
const currentSlide = computed<Slide>(() => store.getters.currentSlide)
|
const currentSlide = computed<Slide>(() => store.getters.currentSlide)
|
||||||
|
|
||||||
const { addHistorySnapshot } = useHistorySnapshot()
|
const { addHistorySnapshot } = useHistorySnapshot()
|
||||||
|
const { createTextElement } = useCreateElement()
|
||||||
|
|
||||||
const pasteElement = (elements: PPTElement[]) => {
|
const pasteElement = (elements: PPTElement[]) => {
|
||||||
const groupIdMap = {}
|
const groupIdMap = {}
|
||||||
@ -51,7 +53,12 @@ export default () => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const pasteText = (text: string) => {
|
const pasteText = (text: string) => {
|
||||||
console.log(text)
|
createTextElement({
|
||||||
|
left: 0,
|
||||||
|
top: 0,
|
||||||
|
width: 600,
|
||||||
|
height: 50,
|
||||||
|
}, text)
|
||||||
}
|
}
|
||||||
|
|
||||||
const pasteTextClipboardData = (text: string, options?: PasteTextClipboardDataOptions) => {
|
const pasteTextClipboardData = (text: string, options?: PasteTextClipboardDataOptions) => {
|
||||||
|
@ -7,7 +7,7 @@ export default (elementRef: Ref<HTMLElement | undefined>) => {
|
|||||||
const store = useStore()
|
const store = useStore()
|
||||||
const disableHotkeys = computed(() => store.state.disableHotkeys)
|
const disableHotkeys = computed(() => store.state.disableHotkeys)
|
||||||
|
|
||||||
const { createImageElement } = useCreateElement()
|
const { createImageElement, createTextElement } = useCreateElement()
|
||||||
|
|
||||||
const handleDrop = (e: DragEvent) => {
|
const handleDrop = (e: DragEvent) => {
|
||||||
if(!e.dataTransfer) return
|
if(!e.dataTransfer) return
|
||||||
@ -22,7 +22,12 @@ export default (elementRef: Ref<HTMLElement | undefined>) => {
|
|||||||
else if(dataTransferItem.kind === 'string' && dataTransferItem.type === 'text/plain') {
|
else if(dataTransferItem.kind === 'string' && dataTransferItem.type === 'text/plain') {
|
||||||
dataTransferItem.getAsString(text => {
|
dataTransferItem.getAsString(text => {
|
||||||
if(disableHotkeys.value) return
|
if(disableHotkeys.value) return
|
||||||
console.log(text)
|
createTextElement({
|
||||||
|
left: 0,
|
||||||
|
top: 0,
|
||||||
|
width: 600,
|
||||||
|
height: 50,
|
||||||
|
}, text)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -139,12 +139,12 @@ export default defineComponent({
|
|||||||
}
|
}
|
||||||
watchEffect(setLocalElementList)
|
watchEffect(setLocalElementList)
|
||||||
|
|
||||||
useDropImageOrText(viewportRef)
|
|
||||||
|
|
||||||
const canvasRef = ref<HTMLElement>()
|
const canvasRef = ref<HTMLElement>()
|
||||||
const canvasScale = computed(() => store.state.canvasScale)
|
const canvasScale = computed(() => store.state.canvasScale)
|
||||||
const { viewportStyles } = useViewportSize(canvasRef)
|
const { viewportStyles } = useViewportSize(canvasRef)
|
||||||
|
|
||||||
|
useDropImageOrText(canvasRef)
|
||||||
|
|
||||||
const { mouseSelectionState, updateMouseSelection } = useMouseSelection(elementList, viewportRef)
|
const { mouseSelectionState, updateMouseSelection } = useMouseSelection(elementList, viewportRef)
|
||||||
|
|
||||||
const { dragElement } = useDragElement(elementList, activeGroupElementId, alignmentLines)
|
const { dragElement } = useDragElement(elementList, activeGroupElementId, alignmentLines)
|
||||||
|
@ -13,16 +13,6 @@
|
|||||||
class="element-content"
|
class="element-content"
|
||||||
v-contextmenu="contextmenus"
|
v-contextmenu="contextmenus"
|
||||||
>
|
>
|
||||||
<div
|
|
||||||
class="table-mask"
|
|
||||||
:class="{ 'lock': elementInfo.lock }"
|
|
||||||
v-if="!editable || elementInfo.lock"
|
|
||||||
@dblclick="startEdit()"
|
|
||||||
@mousedown="$event => handleSelectElement($event)"
|
|
||||||
>
|
|
||||||
<div class="mask-tip" :style="{ transform: `scale(${ 1 / canvasScale })` }">双击编辑</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<EditableTable
|
<EditableTable
|
||||||
@mousedown.stop
|
@mousedown.stop
|
||||||
:data="elementInfo.data"
|
:data="elementInfo.data"
|
||||||
@ -35,6 +25,15 @@
|
|||||||
@changeColWidths="widths => updateColWidths(widths)"
|
@changeColWidths="widths => updateColWidths(widths)"
|
||||||
@changeSelectedCells="cells => updateSelectedCells(cells)"
|
@changeSelectedCells="cells => updateSelectedCells(cells)"
|
||||||
/>
|
/>
|
||||||
|
<div
|
||||||
|
class="table-mask"
|
||||||
|
:class="{ 'lock': elementInfo.lock }"
|
||||||
|
v-if="!editable || elementInfo.lock"
|
||||||
|
@dblclick="startEdit()"
|
||||||
|
@mousedown="$event => handleSelectElement($event)"
|
||||||
|
>
|
||||||
|
<div class="mask-tip" :style="{ transform: `scale(${ 1 / canvasScale })` }">双击编辑</div>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
@ -201,7 +200,6 @@ export default defineComponent({
|
|||||||
bottom: 0;
|
bottom: 0;
|
||||||
left: 0;
|
left: 0;
|
||||||
right: 0;
|
right: 0;
|
||||||
z-index: 10;
|
|
||||||
opacity: 0;
|
opacity: 0;
|
||||||
transition: opacity .2s;
|
transition: opacity .2s;
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user