Skip to content

Commit

Permalink
评论时网址和用户名的校验
Browse files Browse the repository at this point in the history
  • Loading branch information
Jerry committed May 20, 2024
1 parent 5bdcdaa commit d14ba41
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 11 deletions.
15 changes: 9 additions & 6 deletions components/Comment.vue
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@

<div class="dark:text-[#9F9F9F] ">
<span class="text-[#576b95] text-nowrap"><a class="cursor-pointer" v-if="comment.website" target="_blank"
:href="comment.website">{{
:href="website">{{
comment.username ?? '匿名' }}</a>
<span v-else>{{ comment.username ?? '匿名' }}</span>
<b v-if="comment.author"
class="border text-xs border-[#C64A4A] rounded mx-0.5 px-0.5 text-[#C64A4A]">作者</b></span>
<span v-if="comment.replyTo" class="text-nowrap mx-1">回复<span class="text-[#576b95] ml-1"><a
class="cursor-pointer" v-if="comment.replyTo" target="_blank" :href="comment.website">{{
comment.replyTo ?? '匿名' }}</a></span>
</span>
class="cursor-pointer" v-if="comment.replyTo" target="_blank" :href="website">{{
comment.replyTo ?? '匿名' }}</a></span>
</span>
<span class="mr-0.5">:</span>
<span :title="`点击回复${comment.username}`" class="inline w-full break-all cursor-pointer"
@click="toggleUserComment">{{
Expand Down Expand Up @@ -46,7 +46,7 @@ import type { Comment } from '@/lib/types';
import { Trash2 } from 'lucide-vue-next'
import { toast } from 'vue-sonner';
const emit = defineEmits(['memo-update','comment-started'])
const emit = defineEmits(['memo-update', 'comment-started'])
const token = useCookie('token')
const props = withDefaults(
Expand All @@ -55,8 +55,11 @@ const props = withDefaults(
index: number
}>(), {}
)
const showUserCommentArray = useState<Array<boolean>>('showUserCommentArray_'+props.comment.memoId)
const showUserCommentArray = useState<Array<boolean>>('showUserCommentArray_' + props.comment.memoId)
const website = computed(() => {
return props.comment.website?.startsWith('http') ? props.comment.website : `http://${props.comment.website}`
})
const refreshComment = async () => {
emit('memo-update')
Expand Down
10 changes: 5 additions & 5 deletions components/FriendsCommentInput.vue
Original file line number Diff line number Diff line change
Expand Up @@ -65,23 +65,23 @@ const pending = ref(false)
const saveComment = async () => {
if (!content.value) {
if (!content.value.trim()) {
toast.warning('先填写内容')
return
}
if (content.value.length > publicConfig.value.commentMaxLength) {
if (content.value.trim().length > publicConfig.value.commentMaxLength) {
toast.warning('内容超长')
return
}
if (!info.value.username) {
if (!info.value.username.trim()) {
toast.warning('用户名必填')
return
}
if (info.value.username.length > 10) {
if (info.value.username.trim().length > 10) {
toast.warning('用户名')
return
}
if (info.value.website.length > 100) {
if (info.value.website.trim().length > 100) {
toast.warning('网站地址超长')
return
}
Expand Down

0 comments on commit d14ba41

Please sign in to comment.