mirror of
https://github.com/pipipi-pikachu/PPTist.git
synced 2025-04-15 02:20:00 +08:00
37 lines
1.1 KiB
TypeScript
37 lines
1.1 KiB
TypeScript
import { useSlidesStore } from '@/store'
|
|
import type { PPTElement, PPTElementLink } from '@/types/slides'
|
|
import useHistorySnapshot from '@/hooks/useHistorySnapshot'
|
|
import message from '@/utils/message'
|
|
|
|
export default () => {
|
|
const slidesStore = useSlidesStore()
|
|
|
|
const { addHistorySnapshot } = useHistorySnapshot()
|
|
|
|
const setLink = (handleElement: PPTElement, link: PPTElementLink) => {
|
|
const linkRegExp = /^(https?):\/\/[\w\-]+(\.[\w\-]+)+([\w\-.,@?^=%&:\/~+#]*[\w\-@?^=%&\/~+#])?$/
|
|
if (link.type === 'web' && !linkRegExp.test(link.target)) {
|
|
message.error('不是正确的网页链接地址')
|
|
return false
|
|
}
|
|
if (link.type === 'slide' && !link.target) {
|
|
message.error('请先选择链接目标')
|
|
return false
|
|
}
|
|
const props = { link }
|
|
slidesStore.updateElement({ id: handleElement.id, props })
|
|
addHistorySnapshot()
|
|
|
|
return true
|
|
}
|
|
|
|
const removeLink = (handleElement: PPTElement) => {
|
|
slidesStore.removeElementProps({ id: handleElement.id, propName: 'link' })
|
|
addHistorySnapshot()
|
|
}
|
|
|
|
return {
|
|
setLink,
|
|
removeLink,
|
|
}
|
|
} |