添加意见反馈

This commit is contained in:
sophie committed 2026-04-23 13:52:28 +08:00
1 parent 2bd27ed70d
commit 6b2ab65436
16 files changed
+853 -37

No files matched your search

@@ -0,0 +1,182 @@
<script setup lang="ts">
import { computed, ref, watch } from 'vue';
import { MessageSquareText, X } from 'lucide-vue-next';
interface Props {
modelValue: boolean;
authHeaders?: Record<string, string>;
sourcePage?: string;
chatLogId?: number | null;
}
const props = withDefaults(defineProps<Props>(), {
authHeaders: () => ({}),
sourcePage: 'unknown',
chatLogId: null,
});
const emit = defineEmits<{
(e: 'update:modelValue', value: boolean): void;
(e: 'submitted'): void;
}>();
const typeOptions = ['功能建议', '问题反馈', '体验优化'];
const moduleOptions = ['知识库', '通用', '工作流', '账号权限'];
const selectedType = ref<string>('功能建议');
const selectedModule = ref<string>('知识库');
const content = ref('');
const submitting = ref(false);
const error = ref('');
const canSubmit = computed(() => content.value.trim().length > 0 && !submitting.value);
const closeDialog = () => {
emit('update:modelValue', false);
};
const resetForm = () => {
selectedType.value = '功能建议';
selectedModule.value = '知识库';
content.value = '';
error.value = '';
submitting.value = false;
};
watch(
() => props.modelValue,
(visible) => {
if (visible) {
resetForm();
}
},
);
const submitFeedback = async () => {
if (!canSubmit.value) {
error.value = '请填写反馈内容';
return;
}
submitting.value = true;
error.value = '';
try {
const payload: Record<string, unknown> = {
feedback_type: selectedType.value,
feedback_module: selectedModule.value,
content: content.value.trim(),
source_page: props.sourcePage,
};
if (props.chatLogId !== null && props.chatLogId !== undefined) {
payload.chat_log_id = props.chatLogId;
}
const res = await fetch('/api/user/feedback', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
...props.authHeaders,
},
body: JSON.stringify(payload),
});
const data = await res.json().catch(() => ({}));
if (!res.ok) {
error.value = data?.error || '提交失败,请稍后重试';
return;
}
emit('submitted');
closeDialog();
} catch {
error.value = '提交失败,请稍后重试';
} finally {
submitting.value = false;
}
};
</script>
<template>
<div
v-if="modelValue"
class="fixed inset-0 z-[80] flex items-start justify-center overflow-y-auto bg-black/40 p-3 backdrop-blur-sm sm:items-center sm:p-4"
>
<div class="flex max-h-[92vh] w-full max-w-2xl flex-col rounded-2xl bg-white shadow-2xl">
<div class="flex items-center justify-between border-b border-gray-100 px-5 pb-4 pt-5 sm:px-8 sm:pb-4 sm:pt-7">
<h3 class="text-2xl font-bold text-gray-900">意见反馈</h3>
<button
@click="closeDialog"
class="rounded-lg p-1.5 text-gray-400 transition-colors hover:bg-gray-100 hover:text-gray-600"
aria-label="Close"
>
<X class="h-5 w-5" />
</button>
</div>
<div class="space-y-5 overflow-y-auto px-5 py-5 sm:px-8">
<div class="space-y-1.5">
<label class="block text-sm font-semibold text-gray-600">反馈类型</label>
<div class="flex flex-wrap gap-3">
<button
v-for="item in typeOptions"
:key="item"
@click="selectedType = item"
class="rounded-xl border px-4 py-2.5 text-base font-medium transition-colors"
:class="
selectedType === item
? 'border-blue-500 bg-blue-50 text-blue-700'
: 'border-gray-200 bg-gray-50 text-gray-700 hover:bg-gray-100'
"
>
{{ item }}
</button>
</div>
</div>
<div class="space-y-1.5">
<label class="block text-sm font-semibold text-gray-600">反馈模块</label>
<select
v-model="selectedModule"
class="w-full rounded-xl border-gray-200 bg-gray-50 px-4 py-3 text-base shadow-sm outline-none transition-all focus:border-blue-500 focus:bg-white focus:ring-2 focus:ring-blue-500/20"
>
<option v-for="item in moduleOptions" :key="item" :value="item">{{ item }}</option>
</select>
</div>
<div class="space-y-1.5">
<label class="block text-sm font-semibold text-gray-600">反馈内容<span class="ml-0.5 text-red-500">*</span></label>
<textarea
v-model="content"
rows="5"
maxlength="2000"
class="w-full resize-none rounded-xl border-gray-200 bg-gray-50 px-4 py-3 text-base shadow-sm outline-none transition-all focus:border-blue-500 focus:bg-white focus:ring-2 focus:ring-blue-500/20"
placeholder="请描述你的问题或建议,帮助我们持续优化。"
/>
<div class="mt-2 flex items-center justify-between">
<div v-if="error" class="text-base text-red-600">{{ error }}</div>
<div v-else class="text-base text-gray-400"> </div>
<div class="text-base text-gray-400">{{ content.length }}/2000</div>
</div>
</div>
</div>
<div class="flex justify-end gap-3 rounded-b-2xl border-t border-gray-100 bg-white px-5 py-4 sm:px-8">
<button
@click="closeDialog"
class="rounded-xl px-5 py-2.5 text-base font-medium text-gray-600 transition-colors hover:bg-gray-100"
:disabled="submitting"
>
取消
</button>
<button
@click="submitFeedback"
class="inline-flex items-center justify-center gap-2 rounded-xl bg-blue-600 px-5 py-2.5 text-base font-medium text-white shadow-md shadow-blue-200 transition-all hover:bg-blue-700 active:scale-95 disabled:cursor-not-allowed disabled:opacity-70"
:disabled="!canSubmit"
>
<MessageSquareText class="h-5 w-5" />
{{ submitting ? '提交中' : '提交' }}
</button>
</div>
</div>
</div>
</template>