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 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 }
} }

View File

@@ -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 {