|
|
|
@ -52,23 +52,23 @@ |
|
|
|
|
</template> |
|
|
|
|
|
|
|
|
|
<script> |
|
|
|
|
import $ from 'jquery'; |
|
|
|
|
import authorization from '@/utils/authorization' |
|
|
|
|
import { ref, watchEffect } from 'vue'; |
|
|
|
|
import $ from "jquery"; |
|
|
|
|
import authorization from "@/utils/authorization"; |
|
|
|
|
import { ref, watchEffect } from "vue"; |
|
|
|
|
|
|
|
|
|
export default { |
|
|
|
|
name: "CommentView", |
|
|
|
|
props: { |
|
|
|
|
article: { |
|
|
|
|
required: true, |
|
|
|
|
} |
|
|
|
|
}, |
|
|
|
|
}, |
|
|
|
|
setup(props) { |
|
|
|
|
// 所有评论 |
|
|
|
|
let comments = ref([]); |
|
|
|
|
// 评论控件绑定的文本和占位符 |
|
|
|
|
let message = ref(''); |
|
|
|
|
let placeholder = ref('说点啥吧...'); |
|
|
|
|
let message = ref(""); |
|
|
|
|
let placeholder = ref("说点啥吧..."); |
|
|
|
|
// 评论的评论 |
|
|
|
|
let parentId = ref(null); |
|
|
|
|
// 发表评论 |
|
|
|
@ -76,24 +76,24 @@ export default { |
|
|
|
|
authorization().then((response) => { |
|
|
|
|
if (response[0]) { |
|
|
|
|
$.ajax({ |
|
|
|
|
url: 'http://127.0.0.1:6789/api/comment/', |
|
|
|
|
type: 'POST', |
|
|
|
|
url: "http://127.0.0.1:6789/api/comment/", |
|
|
|
|
type: "POST", |
|
|
|
|
data: { |
|
|
|
|
content: message.value, |
|
|
|
|
article_id: props.article.id, |
|
|
|
|
parent_id: parentId.value, |
|
|
|
|
|
|
|
|
|
}, |
|
|
|
|
headers: { |
|
|
|
|
authorization: "Bearer " + localStorage.getItem('access_blog') |
|
|
|
|
authorization: |
|
|
|
|
"Bearer " + localStorage.getItem("access_blog"), |
|
|
|
|
}, |
|
|
|
|
success(resp) { |
|
|
|
|
// 将新评论添加到顶部 |
|
|
|
|
comments.value.unshift(resp); |
|
|
|
|
message.value = ''; |
|
|
|
|
message.value = ""; |
|
|
|
|
window.alert("留言成功"); |
|
|
|
|
} |
|
|
|
|
}) |
|
|
|
|
}, |
|
|
|
|
}); |
|
|
|
|
} else { |
|
|
|
|
window.alert("请登录后再评论!"); |
|
|
|
|
} |
|
|
|
@ -102,16 +102,17 @@ export default { |
|
|
|
|
|
|
|
|
|
const replyTo = (comment) => { |
|
|
|
|
parentId.value = comment.id; |
|
|
|
|
placeholder.value = '对' + comment.author.username + '说'; |
|
|
|
|
placeholder.value = "对" + comment.author.username + "说"; |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
const formatted_time = (iso_date_string) => { |
|
|
|
|
const date = new Date(iso_date_string); |
|
|
|
|
return date.toLocaleDateString() + ' ' + date.toLocaleTimeString(); |
|
|
|
|
return date.toLocaleDateString() + " " + date.toLocaleTimeString(); |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
watchEffect(() => { |
|
|
|
|
comments.value = props.article !== null ? props.article.comments : []; |
|
|
|
|
comments.value = |
|
|
|
|
props.article !== null ? props.article.comments : []; |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
return { |
|
|
|
@ -122,7 +123,7 @@ export default { |
|
|
|
|
submit, |
|
|
|
|
replyTo, |
|
|
|
|
formatted_time, |
|
|
|
|
} |
|
|
|
|
}; |
|
|
|
|
}, |
|
|
|
|
}; |
|
|
|
|
</script> |
|
|
|
|