mirror of
https://github.com/nagisa77/OpenIsle.git
synced 2026-02-22 22:21:09 +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 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 }
|
||||
}
|
||||
|
||||
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user