mirror of
https://github.com/nagisa77/OpenIsle.git
synced 2026-05-26 04:27:40 +08:00
Merge pull request #96 from nagisa77/codex/add-toast-for-link-copy-and-delay-jump-for-comments
Implement toast on copy and wait comment anchor
This commit is contained in:
@@ -130,7 +130,9 @@ const CommentItem = {
|
|||||||
}
|
}
|
||||||
const copyCommentLink = () => {
|
const copyCommentLink = () => {
|
||||||
const link = `${location.origin}${location.pathname}#comment-${props.comment.id}`
|
const link = `${location.origin}${location.pathname}#comment-${props.comment.id}`
|
||||||
navigator.clipboard.writeText(link)
|
navigator.clipboard.writeText(link).then(() => {
|
||||||
|
toast.success('已复制')
|
||||||
|
})
|
||||||
}
|
}
|
||||||
return { showReplies, toggleReplies, showEditor, toggleEditor, submitReply, copyCommentLink, renderMarkdown, isWaitingForReply }
|
return { showReplies, toggleReplies, showEditor, toggleEditor, submitReply, copyCommentLink, renderMarkdown, isWaitingForReply }
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -89,7 +89,7 @@
|
|||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
import { ref, computed, onMounted } from 'vue'
|
import { ref, computed, onMounted, nextTick } from 'vue'
|
||||||
import { useRoute } from 'vue-router'
|
import { useRoute } from 'vue-router'
|
||||||
import CommentItem from '../components/CommentItem.vue'
|
import CommentItem from '../components/CommentItem.vue'
|
||||||
import CommentEditor from '../components/CommentEditor.vue'
|
import CommentEditor from '../components/CommentEditor.vue'
|
||||||
@@ -200,15 +200,16 @@ export default {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const copyPostLink = () => {
|
const copyPostLink = () => {
|
||||||
navigator.clipboard.writeText(location.href.split('#')[0])
|
navigator.clipboard.writeText(location.href.split('#')[0]).then(() => {
|
||||||
|
toast.success('已复制')
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
onMounted(() => {
|
const jumpToHashComment = async () => {
|
||||||
fetchPost()
|
|
||||||
updateCurrentIndex()
|
|
||||||
const hash = location.hash
|
const hash = location.hash
|
||||||
if (hash.startsWith('#comment-')) {
|
if (hash.startsWith('#comment-')) {
|
||||||
const id = hash.substring('#comment-'.length)
|
const id = hash.substring('#comment-'.length)
|
||||||
|
await nextTick()
|
||||||
const el = document.getElementById('comment-' + id)
|
const el = document.getElementById('comment-' + id)
|
||||||
if (el && mainContainer.value) {
|
if (el && mainContainer.value) {
|
||||||
mainContainer.value.scrollTo({ top: el.offsetTop, behavior: 'instant' })
|
mainContainer.value.scrollTo({ top: el.offsetTop, behavior: 'instant' })
|
||||||
@@ -216,6 +217,12 @@ export default {
|
|||||||
setTimeout(() => el.classList.remove('comment-highlight'), 2000)
|
setTimeout(() => el.classList.remove('comment-highlight'), 2000)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
onMounted(async () => {
|
||||||
|
await fetchPost()
|
||||||
|
updateCurrentIndex()
|
||||||
|
await jumpToHashComment()
|
||||||
})
|
})
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
|||||||
Reference in New Issue
Block a user