-
Notifications
You must be signed in to change notification settings - Fork 75
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
101 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
<template> | ||
<div ref="commentRef" id="comment-dom" :class="['comment-content', 'twikoo', { fill }]" /> | ||
</template> | ||
|
||
<script setup> | ||
import { jumpRedirect } from "@/utils/commonTools"; | ||
import initComments from "@/utils/initComments"; | ||
const props = defineProps({ | ||
// 填充评论区 | ||
fill: { | ||
type: [Boolean, String], | ||
default: false, | ||
}, | ||
}); | ||
const { theme } = useData(); | ||
const { comment } = theme.value; | ||
// 评论数据 | ||
const twikoo = ref(null); | ||
const commentRef = ref(null); | ||
// 初始化 Twikoo | ||
const initTwikoo = async () => { | ||
try { | ||
await nextTick(); | ||
const Twikoo = await initComments(theme.value); | ||
twikoo.value = Twikoo.init({ | ||
el: commentRef.value || "#comment-dom", | ||
envId: comment.twikoo.envId, | ||
onCommentLoaded: () => { | ||
console.log("评论已加载完毕"); | ||
if (props.fill) fillComments(props.fill); | ||
jumpRedirect(null, theme.value, true); | ||
}, | ||
}); | ||
return twikoo.value; | ||
} catch (error) { | ||
console.error("初始化评论出错:", error); | ||
} | ||
}; | ||
// 填充评论区 | ||
const fillComments = (data) => { | ||
console.log("填充评论:", data); | ||
// 获取评论元素 | ||
const commentDom = document.querySelector(".tk-input.el-textarea"); | ||
if (!commentDom) return false; | ||
// 获取输入框 | ||
const commentInput = commentDom.querySelector("textarea"); | ||
// 写入内容 | ||
commentInput.value = data + "\n\n"; | ||
commentInput.focus(); | ||
}; | ||
onMounted(() => { | ||
initTwikoo(); | ||
}); | ||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters