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:
Tim
2025-07-07 13:21:20 +08:00
committed by GitHub
2 changed files with 15 additions and 6 deletions

View File

@@ -130,7 +130,9 @@ const CommentItem = {
}
const copyCommentLink = () => {
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 }
}

View File

@@ -89,7 +89,7 @@
</template>
<script>
import { ref, computed, onMounted } from 'vue'
import { ref, computed, onMounted, nextTick } from 'vue'
import { useRoute } from 'vue-router'
import CommentItem from '../components/CommentItem.vue'
import CommentEditor from '../components/CommentEditor.vue'
@@ -200,15 +200,16 @@ export default {
}
const copyPostLink = () => {
navigator.clipboard.writeText(location.href.split('#')[0])
navigator.clipboard.writeText(location.href.split('#')[0]).then(() => {
toast.success('已复制')
})
}
onMounted(() => {
fetchPost()
updateCurrentIndex()
const jumpToHashComment = async () => {
const hash = location.hash
if (hash.startsWith('#comment-')) {
const id = hash.substring('#comment-'.length)
await nextTick()
const el = document.getElementById('comment-' + id)
if (el && mainContainer.value) {
mainContainer.value.scrollTo({ top: el.offsetTop, behavior: 'instant' })
@@ -216,6 +217,12 @@ export default {
setTimeout(() => el.classList.remove('comment-highlight'), 2000)
}
}
}
onMounted(async () => {
await fetchPost()
updateCurrentIndex()
await jumpToHashComment()
})
return {