refactor(frontend): 重构前端第二版
This commit is contained in:
1 parent
2631f78b00
commit
4b562cfa82
205 files changed
+15399
-12015
No files matched your search
@@ -0,0 +1,207 @@
|
||||
<script setup lang="ts">
|
||||
/**
|
||||
* shared/components/GeneralFeedbackDialog.vue
|
||||
* 通用意见反馈提交弹窗。
|
||||
*/
|
||||
|
||||
import { computed, ref, watch } from 'vue';
|
||||
import { useI18n } from 'vue-i18n';
|
||||
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 { t, locale } = useI18n({ useScope: 'global' });
|
||||
|
||||
const typeOptions = computed(() => [
|
||||
t('feedback.type.featureSuggestion'),
|
||||
t('feedback.type.issueReport'),
|
||||
t('feedback.type.experienceOptimization'),
|
||||
]);
|
||||
|
||||
const moduleOptions = computed(() => [
|
||||
t('feedback.module.knowledgeBase'),
|
||||
t('feedback.module.general'),
|
||||
t('feedback.module.workflow'),
|
||||
t('feedback.module.accountPermission'),
|
||||
]);
|
||||
|
||||
const selectedType = ref<string>(t('feedback.type.featureSuggestion'));
|
||||
const selectedModule = ref<string>(t('feedback.module.knowledgeBase'));
|
||||
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 = t('feedback.type.featureSuggestion');
|
||||
selectedModule.value = t('feedback.module.knowledgeBase');
|
||||
content.value = '';
|
||||
error.value = '';
|
||||
submitting.value = false;
|
||||
};
|
||||
|
||||
watch(
|
||||
() => props.modelValue,
|
||||
(visible) => {
|
||||
if (visible) resetForm();
|
||||
},
|
||||
);
|
||||
|
||||
watch(locale, () => {
|
||||
if (props.modelValue) {
|
||||
resetForm();
|
||||
}
|
||||
});
|
||||
|
||||
const submitFeedback = async () => {
|
||||
if (!canSubmit.value) {
|
||||
error.value = t('feedback.msg.fillContent');
|
||||
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 || t('feedback.msg.submitFailed');
|
||||
return;
|
||||
}
|
||||
|
||||
emit('submitted');
|
||||
closeDialog();
|
||||
} catch {
|
||||
error.value = t('feedback.msg.submitFailed');
|
||||
} finally {
|
||||
submitting.value = false;
|
||||
}
|
||||
};
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div
|
||||
v-if="modelValue"
|
||||
class="dialog-overlay dialog-overlay--z80"
|
||||
>
|
||||
<div class="dialog-panel max-w-2xl max-h-[92vh]">
|
||||
<div class="dialog-header">
|
||||
<h3 class="section-title text-2xl">{{ t('feedback.title') }}</h3>
|
||||
<button
|
||||
type="button"
|
||||
class="btn-icon-ds"
|
||||
aria-label="Close"
|
||||
@click="closeDialog"
|
||||
>
|
||||
<X class="h-5 w-5" />
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<div class="dialog-body space-y-5">
|
||||
<div class="space-y-1.5">
|
||||
<label class="label-field block">{{ t('feedback.labels.type') }}</label>
|
||||
<div class="segment-control segment-control--cols-3 segment-control--md" role="radiogroup" :aria-label="t('feedback.labels.type')">
|
||||
<button
|
||||
v-for="item in typeOptions"
|
||||
:key="item"
|
||||
type="button"
|
||||
role="radio"
|
||||
:aria-checked="selectedType === item"
|
||||
class="segment-item"
|
||||
:class="selectedType === item ? 'segment-item--active' : ''"
|
||||
@click="selectedType = item"
|
||||
>
|
||||
{{ item }}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="space-y-1.5">
|
||||
<label class="label-field block">{{ t('feedback.labels.module') }}</label>
|
||||
<select v-model="selectedModule" class="input-field text-base">
|
||||
<option v-for="item in moduleOptions" :key="item" :value="item">{{ item }}</option>
|
||||
</select>
|
||||
</div>
|
||||
|
||||
<div class="space-y-1.5">
|
||||
<label class="label-field block">
|
||||
{{ t('feedback.labels.content') }}<span class="ml-0.5 text-red-500">*</span>
|
||||
</label>
|
||||
<textarea
|
||||
v-model="content"
|
||||
rows="5"
|
||||
maxlength="2000"
|
||||
class="input-field resize-none text-base"
|
||||
:placeholder="t('feedback.placeholder.content')"
|
||||
/>
|
||||
<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-muted"> </div>
|
||||
<div class="text-base text-muted">{{ content.length }}/2000</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="dialog-footer">
|
||||
<button
|
||||
type="button"
|
||||
class="btn-ghost"
|
||||
:disabled="submitting"
|
||||
@click="closeDialog"
|
||||
>
|
||||
{{ t('feedback.cancel') }}
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
class="btn-primary"
|
||||
:disabled="!canSubmit"
|
||||
@click="submitFeedback"
|
||||
>
|
||||
<MessageSquareText class="h-5 w-5" />
|
||||
{{ submitting ? t('feedback.submitting') : t('feedback.submit') }}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
Reference in new issue
Block a user