fix(reviews): restore modal detail review gating

This commit is contained in:
2026-05-19 12:22:52 +08:00
parent 04b0ca061b
commit fd17fc127d
9 changed files with 456 additions and 71 deletions
+28 -6
View File
@@ -56,6 +56,13 @@
登录后发表评论
</button>
<p
v-else-if="!canSubmit"
class="mb-4 text-sm text-slate-500 dark:text-slate-400"
>
安装应用后可发表评论
</p>
<form v-else class="mb-4 space-y-3" @submit.prevent="submit">
<label
class="block text-sm font-medium text-slate-600 dark:text-slate-300"
@@ -127,11 +134,15 @@ import type {
ReviewTags,
} from "@/global/typedefinition";
const props = defineProps<{
appKey: string;
tags: ReviewTags;
loggedIn: boolean;
}>();
const props = withDefaults(
defineProps<{
appKey: string;
tags: ReviewTags;
loggedIn: boolean;
canSubmit?: boolean;
}>(),
{ canSubmit: true },
);
const emit = defineEmits<{
"request-login": [message: string];
@@ -152,6 +163,16 @@ const ratingText = computed(() => {
return `${summary.value.averageRating.toFixed(1)} / 5 (${summary.value.reviewCount})`;
});
const canSubmit = computed(() => props.canSubmit);
const toReviewErrorMessage = (caught: unknown): string => {
const message = caught instanceof Error ? caught.message : "";
if (message === "Network Error") {
return "无法连接星火账号服务,请稍后重试。";
}
return message || "发表评论失败";
};
const clearReviewState = () => {
loadGeneration.value += 1;
reviews.value = [];
@@ -189,6 +210,7 @@ const loadReviews = async () => {
};
const submit = async () => {
if (!canSubmit.value) return;
const appKey = props.appKey;
const tags = props.tags;
submitting.value = true;
@@ -204,7 +226,7 @@ const submit = async () => {
await loadReviews();
} catch (caught: unknown) {
if (appKey !== props.appKey) return;
error.value = (caught as Error)?.message || "发表评论失败";
error.value = toReviewErrorMessage(caught);
} finally {
if (appKey === props.appKey) {
submitting.value = false;