fix: not login

This commit is contained in:
zzc
2026-06-10 00:41:11 +08:00
parent 0383ad6be2
commit d325329af4
4 changed files with 115 additions and 20 deletions

View File

@@ -24,9 +24,10 @@
</template>
<script setup>
import { ref, watch } from 'vue';
import { computed, ref, watch } from 'vue';
import ActionBadge from "@/components/ActionBadge/ActionBadge.vue";
import { topicItemCommentLike } from "@/api/topicItem";
import { useUserStore } from "@/stores/user";
const props = defineProps({
comment: {
@@ -36,6 +37,10 @@ const props = defineProps({
}
});
const emit = defineEmits(['need-login']);
const userStore = useUserStore();
const isLoggedIn = computed(() => !!userStore.token || !!userStore.userInfo?.nickName);
const isLiked = ref(props.comment.isLiked || false);
const currentLikes = ref(props.comment.likes || 0);
let isLiking = false; // 防抖标志
@@ -49,6 +54,11 @@ watch(() => props.comment.isLiked, (newVal) => {
});
const handleLike = async () => {
if (!isLoggedIn.value) {
emit('need-login');
return;
}
if (isLiking) return;
isLiking = true;
@@ -206,4 +216,4 @@ const handleLike = async () => {
line-height: 1.65;
word-break: break-all;
}
</style>
</style>