feat(feedback): 反馈弹窗整页替换 Element Plus 并支持粘贴与选图上传
This commit is contained in:
1 parent
b64ed9b792
commit
a91f26f753
7 files changed
+302
-84
No files matched your search
@@ -52,7 +52,6 @@ async function handleQueryPreviewAssetImage(assetId: string, assetName: string)
|
|||||||
/>
|
/>
|
||||||
<GeneralFeedbackDialog
|
<GeneralFeedbackDialog
|
||||||
v-model="page.showGeneralFeedbackDialog"
|
v-model="page.showGeneralFeedbackDialog"
|
||||||
:auth-headers="getAuthHeaders()"
|
|
||||||
source-page="chat"
|
source-page="chat"
|
||||||
:chat-log-id="page.currentGeneralFeedbackChatLogId"
|
:chat-log-id="page.currentGeneralFeedbackChatLogId"
|
||||||
@submitted="onFeedbackSubmitted"
|
@submitted="onFeedbackSubmitted"
|
||||||
|
|||||||
@@ -7,7 +7,6 @@ import { inject } from 'vue';
|
|||||||
import { X } from 'lucide-vue-next';
|
import { X } from 'lucide-vue-next';
|
||||||
import DeleteConfirmDialog from '@/shared/components/DeleteConfirmDialog.vue';
|
import DeleteConfirmDialog from '@/shared/components/DeleteConfirmDialog.vue';
|
||||||
import GeneralFeedbackDialog from '@/shared/components/GeneralFeedbackDialog.vue';
|
import GeneralFeedbackDialog from '@/shared/components/GeneralFeedbackDialog.vue';
|
||||||
import { getAuthHeaders } from '@/shared/utils/auth';
|
|
||||||
import { WORKSPACE_KEY } from '../composables/workspace.context';
|
import { WORKSPACE_KEY } from '../composables/workspace.context';
|
||||||
|
|
||||||
const ws = inject(WORKSPACE_KEY)! as any;
|
const ws = inject(WORKSPACE_KEY)! as any;
|
||||||
@@ -121,7 +120,6 @@ const ws = inject(WORKSPACE_KEY)! as any;
|
|||||||
/>
|
/>
|
||||||
<GeneralFeedbackDialog
|
<GeneralFeedbackDialog
|
||||||
v-model="ws.showGeneralFeedbackDialog"
|
v-model="ws.showGeneralFeedbackDialog"
|
||||||
:auth-headers="getAuthHeaders()"
|
|
||||||
source-page="workspace"
|
source-page="workspace"
|
||||||
@submitted="ws.msg.success('反馈提交成功')"
|
@submitted="ws.msg.success('反馈提交成功')"
|
||||||
/>
|
/>
|
||||||
|
|||||||
@@ -26,5 +26,14 @@
|
|||||||
},
|
},
|
||||||
"cancel": "Cancel",
|
"cancel": "Cancel",
|
||||||
"submitting": "Submitting...",
|
"submitting": "Submitting...",
|
||||||
"submit": "Submit"
|
"submit": "Submit",
|
||||||
|
"upload": {
|
||||||
|
"addImage": "Add images",
|
||||||
|
"pasteHint": "Paste a screenshot (Ctrl+V) or click to add, up to 5",
|
||||||
|
"maxCount": "Up to {count} images",
|
||||||
|
"maxSize": "Each image must be within {size}MB",
|
||||||
|
"invalidType": "Only png / jpg / jpeg / webp images are supported",
|
||||||
|
"uploadFailed": "Image upload failed, please retry",
|
||||||
|
"remove": "Remove image"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -26,5 +26,14 @@
|
|||||||
},
|
},
|
||||||
"cancel": "ยกเลิก",
|
"cancel": "ยกเลิก",
|
||||||
"submitting": "กำลังส่ง...",
|
"submitting": "กำลังส่ง...",
|
||||||
"submit": "ส่ง"
|
"submit": "ส่ง",
|
||||||
|
"upload": {
|
||||||
|
"addImage": "เพิ่มรูปภาพ",
|
||||||
|
"pasteHint": "วางภาพหน้าจอ (Ctrl+V) หรือคลิกเพื่อเพิ่ม สูงสุด 5 รูป",
|
||||||
|
"maxCount": "เพิ่มได้สูงสุด {count} รูป",
|
||||||
|
"maxSize": "รูปภาพเดียวต้องไม่เกิน {size}MB",
|
||||||
|
"invalidType": "รองรับเฉพาะไฟล์ png / jpg / jpeg / webp",
|
||||||
|
"uploadFailed": "อัปโหลดรูปภาพไม่สำเร็จ กรุณาลองอีกครั้ง",
|
||||||
|
"remove": "นำรูปภาพออก"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -26,5 +26,14 @@
|
|||||||
},
|
},
|
||||||
"cancel": "取消",
|
"cancel": "取消",
|
||||||
"submitting": "提交中...",
|
"submitting": "提交中...",
|
||||||
"submit": "提交"
|
"submit": "提交",
|
||||||
|
"upload": {
|
||||||
|
"addImage": "添加图片",
|
||||||
|
"pasteHint": "支持粘贴截图(Ctrl+V)或点击添加,最多 5 张",
|
||||||
|
"maxCount": "最多添加 {count} 张图片",
|
||||||
|
"maxSize": "单张图片不能超过 {size}MB",
|
||||||
|
"invalidType": "仅支持 png / jpg / jpeg / webp 格式图片",
|
||||||
|
"uploadFailed": "图片上传失败,请重试",
|
||||||
|
"remove": "移除图片"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -26,5 +26,14 @@
|
|||||||
},
|
},
|
||||||
"cancel": "取消",
|
"cancel": "取消",
|
||||||
"submitting": "提交中...",
|
"submitting": "提交中...",
|
||||||
"submit": "提交"
|
"submit": "提交",
|
||||||
|
"upload": {
|
||||||
|
"addImage": "添加圖片",
|
||||||
|
"pasteHint": "支援貼上截圖(Ctrl+V)或點擊新增,最多 5 張",
|
||||||
|
"maxCount": "最多新增 {count} 張圖片",
|
||||||
|
"maxSize": "單張圖片不能超過 {size}MB",
|
||||||
|
"invalidType": "僅支援 png / jpg / jpeg / webp 格式圖片",
|
||||||
|
"uploadFailed": "圖片上傳失敗,請重試",
|
||||||
|
"remove": "移除圖片"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -1,22 +1,56 @@
|
|||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
/**
|
/**
|
||||||
* shared/components/GeneralFeedbackDialog.vue
|
* shared/components/GeneralFeedbackDialog.vue
|
||||||
* 通用意见反馈提交弹窗。
|
* 通用意见反馈提交弹窗(Element Plus 版)。
|
||||||
|
* 用途:收集反馈类型/模块/内容,并支持粘贴(Ctrl+V)或点击选择图片;图片先经文件资产接口
|
||||||
|
* 上传换取 asset_no,提交时仅携带上传成功(status==='ready')的 asset_no 列表。
|
||||||
|
* 依赖:element-plus(ElDialog/ElSegmented/ElSelect/ElInput/ElButton/ElMessage)、
|
||||||
|
* shared/api/client.requestJson(自动附鉴权头,失败抛 BusinessError)、
|
||||||
|
* shared/api/file-assets.api.uploadFileAsset、vue-i18n。
|
||||||
|
* 逻辑关系:由 WorkspaceModals(workspace 入口,source_page='workspace')与
|
||||||
|
* ChatViewOverlays(chat 入口,source_page='chat' 且附 chat_log_id)挂载;
|
||||||
|
* 打开/重开与语言切换时重置表单并清理图片预览;提交成功 emit('submitted') 后关闭,
|
||||||
|
* 成功提示由父组件处理。类型/模块提交的是当前语言的展示文案(后端按 ≤32 字符字符串存储)。
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { computed, ref, watch } from 'vue';
|
import { computed, ref, watch } from 'vue';
|
||||||
import { useI18n } from 'vue-i18n';
|
import { useI18n } from 'vue-i18n';
|
||||||
import { MessageSquareText, X } from 'lucide-vue-next';
|
import { Loader2, Plus, X } from 'lucide-vue-next';
|
||||||
|
import {
|
||||||
|
ElButton,
|
||||||
|
ElDialog,
|
||||||
|
ElInput,
|
||||||
|
ElMessage,
|
||||||
|
ElOption,
|
||||||
|
ElSegmented,
|
||||||
|
ElSelect,
|
||||||
|
} from 'element-plus';
|
||||||
|
import 'element-plus/dist/index.css';
|
||||||
|
import 'element-plus/theme-chalk/dark/css-vars.css';
|
||||||
|
import { BusinessError, requestJson } from '@/shared/api/client';
|
||||||
|
import { uploadFileAsset } from '@/shared/api/file-assets.api';
|
||||||
|
|
||||||
|
/** 反馈图片数量上限(含上传中与已就绪;超过上限整批拒绝,不静默截取前 N 张)。 */
|
||||||
|
const MAX_FEEDBACK_IMAGES = 5;
|
||||||
|
/** 单张图片大小上限(MB):客户端预校验,避免超大文件先上传再被后端拒绝。 */
|
||||||
|
const MAX_FEEDBACK_IMAGE_SIZE_MB = 10;
|
||||||
|
/** 允许的图片 MIME 类型(与后端校验一致:png/jpg/jpeg/webp)。 */
|
||||||
|
const FEEDBACK_IMAGE_ACCEPT = ['image/png', 'image/jpeg', 'image/webp'];
|
||||||
|
|
||||||
|
interface PendingImage {
|
||||||
|
assetNo: string | null; // 上传成功后的 FA 编号
|
||||||
|
status: 'uploading' | 'ready';
|
||||||
|
previewUrl: string; // URL.createObjectURL(file)
|
||||||
|
filename: string;
|
||||||
|
}
|
||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
modelValue: boolean;
|
modelValue: boolean;
|
||||||
authHeaders?: Record<string, string>;
|
|
||||||
sourcePage?: string;
|
sourcePage?: string;
|
||||||
chatLogId?: number | null;
|
chatLogId?: number | null;
|
||||||
}
|
}
|
||||||
|
|
||||||
const props = withDefaults(defineProps<Props>(), {
|
const props = withDefaults(defineProps<Props>(), {
|
||||||
authHeaders: () => ({}),
|
|
||||||
sourcePage: 'unknown',
|
sourcePage: 'unknown',
|
||||||
chatLogId: null,
|
chatLogId: null,
|
||||||
});
|
});
|
||||||
@@ -28,6 +62,11 @@ const emit = defineEmits<{
|
|||||||
|
|
||||||
const { t, locale } = useI18n({ useScope: 'global' });
|
const { t, locale } = useI18n({ useScope: 'global' });
|
||||||
|
|
||||||
|
const visible = computed({
|
||||||
|
get: () => props.modelValue,
|
||||||
|
set: (v: boolean) => emit('update:modelValue', v),
|
||||||
|
});
|
||||||
|
|
||||||
const typeOptions = computed(() => [
|
const typeOptions = computed(() => [
|
||||||
t('feedback.type.featureSuggestion'),
|
t('feedback.type.featureSuggestion'),
|
||||||
t('feedback.type.issueReport'),
|
t('feedback.type.issueReport'),
|
||||||
@@ -46,8 +85,129 @@ const selectedModule = ref<string>(t('feedback.module.knowledgeBase'));
|
|||||||
const content = ref('');
|
const content = ref('');
|
||||||
const submitting = ref(false);
|
const submitting = ref(false);
|
||||||
const error = ref('');
|
const error = ref('');
|
||||||
|
const images = ref<PendingImage[]>([]);
|
||||||
|
|
||||||
const canSubmit = computed(() => content.value.trim().length > 0 && !submitting.value);
|
const hasUploadingImage = computed(() => images.value.some((i) => i.status === 'uploading'));
|
||||||
|
const canSubmit = computed(() => content.value.trim().length > 0 && !submitting.value && !hasUploadingImage.value);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 批量加入反馈图片(粘贴与文件选择共用入口)。
|
||||||
|
* [AI 触发时机] 无 —— 纯 UI 交互:由 onPaste / onFileChange 调用,AI 不得主动调用。
|
||||||
|
* 核心逻辑:
|
||||||
|
* [STEP 1] 类型过滤:MIME 不在 FEEDBACK_IMAGE_ACCEPT 内的整段提示 invalidType(该批跳过);
|
||||||
|
* [STEP 2] 数量上限:已入队(含上传中)+ 本批有效数量 > MAX_FEEDBACK_IMAGES 时整批拒绝并提示
|
||||||
|
* maxCount,在发起任何上传之前拦截(防图片没传完又超限);
|
||||||
|
* [STEP 3] 逐张校验大小:超过 MAX_FEEDBACK_IMAGE_SIZE_MB 的单张跳过并提示 maxSize;
|
||||||
|
* [STEP 4] 逐张入队 status='uploading' → uploadFileAsset 成功置 ready+assetNo;
|
||||||
|
* 失败则移除该项(同时释放预览 URL)并提示 uploadFailed。
|
||||||
|
* @param files - 待加入的图片 File 列表(调用方保证来自剪贴板或 input.files)
|
||||||
|
* @returns Promise,完成后图片状态已落定(ready 或已移除)
|
||||||
|
*/
|
||||||
|
async function addImages(files: File[]): Promise<void> {
|
||||||
|
if (files.length === 0) return;
|
||||||
|
|
||||||
|
// [STEP 1] 类型过滤:不合法的整段提示一次,避免逐张刷屏
|
||||||
|
const typeValidFiles = files.filter((f) => FEEDBACK_IMAGE_ACCEPT.includes(f.type));
|
||||||
|
if (typeValidFiles.length < files.length) {
|
||||||
|
ElMessage.error(t('feedback.upload.invalidType'));
|
||||||
|
}
|
||||||
|
if (typeValidFiles.length === 0) return;
|
||||||
|
|
||||||
|
// [STEP 2] 数量上限校验必须先于任何上传发起;计数包含上传中与已就绪的图片
|
||||||
|
if (images.value.length + typeValidFiles.length > MAX_FEEDBACK_IMAGES) {
|
||||||
|
ElMessage.error(t('feedback.upload.maxCount', { count: MAX_FEEDBACK_IMAGES }));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (const file of typeValidFiles) {
|
||||||
|
// [STEP 3] 单张大小超限:仅跳过该张,不影响同批其他图片
|
||||||
|
if (file.size > MAX_FEEDBACK_IMAGE_SIZE_MB * 1024 * 1024) {
|
||||||
|
ElMessage.error(t('feedback.upload.maxSize', { size: MAX_FEEDBACK_IMAGE_SIZE_MB }));
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
// [STEP 4] 入队即占位(缩略图立即可见,uploading 态加遮罩),上传成功后才计入提交
|
||||||
|
const item: PendingImage = {
|
||||||
|
assetNo: null,
|
||||||
|
status: 'uploading',
|
||||||
|
previewUrl: URL.createObjectURL(file),
|
||||||
|
filename: file.name,
|
||||||
|
};
|
||||||
|
images.value.push(item);
|
||||||
|
try {
|
||||||
|
const asset = await uploadFileAsset(file);
|
||||||
|
item.assetNo = asset.asset_no;
|
||||||
|
item.status = 'ready';
|
||||||
|
} catch {
|
||||||
|
// 上传失败:从队列移除并释放预览,避免提交时引用不存在的资产
|
||||||
|
const idx = images.value.indexOf(item);
|
||||||
|
if (idx !== -1) {
|
||||||
|
URL.revokeObjectURL(item.previewUrl);
|
||||||
|
images.value.splice(idx, 1);
|
||||||
|
}
|
||||||
|
ElMessage.error(t('feedback.upload.uploadFailed'));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 移除单张反馈图片。
|
||||||
|
* [AI 触发时机] 无 —— 纯 UI 交互:点击缩略图右上角 × 时调用。
|
||||||
|
* 核心逻辑:先 revoke 预览 objectURL(防内存泄漏)再从队列 splice;若该项尚在上传中,
|
||||||
|
* 其上传结果会被丢弃(indexOf 找不到已移除项,不会写回)。
|
||||||
|
* @param index - 待移除项在 images 中的下标
|
||||||
|
*/
|
||||||
|
function removeImage(index: number): void {
|
||||||
|
const item = images.value[index];
|
||||||
|
if (!item) return;
|
||||||
|
URL.revokeObjectURL(item.previewUrl);
|
||||||
|
images.value.splice(index, 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 处理弹窗内容区粘贴事件:提取剪贴板中的图片文件加入队列。
|
||||||
|
* [AI 触发时机] 无 —— 纯 UI 交互:仅在图片入队时才 preventDefault;
|
||||||
|
* 纯文本粘贴(无图片文件)不拦截,保证 textarea 文本粘贴行为不受影响。
|
||||||
|
* 核心逻辑:clipboardData.items 中 kind==='file' 且 type 以 'image/' 开头的项同步 getAsFile()
|
||||||
|
* (必须在 await 之前同步取完,剪贴板数据在事件处理后失效);未取到任何文件则直接返回。
|
||||||
|
* @param e - ClipboardEvent
|
||||||
|
*/
|
||||||
|
function onPaste(e: ClipboardEvent): void {
|
||||||
|
const items = e.clipboardData?.items;
|
||||||
|
if (!items) return;
|
||||||
|
const files: File[] = [];
|
||||||
|
for (const item of Array.from(items)) {
|
||||||
|
if (item.kind === 'file' && item.type.startsWith('image/')) {
|
||||||
|
const file = item.getAsFile();
|
||||||
|
if (file) files.push(file);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (files.length === 0) return; // 纯文本粘贴:不拦截,保留默认行为
|
||||||
|
e.preventDefault();
|
||||||
|
void addImages(files);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 处理隐藏 file input 的 change 事件。
|
||||||
|
* [AI 触发时机] 无 —— 纯 UI 交互:点击「添加图片」格子选择文件后触发。
|
||||||
|
* 核心逻辑:取 input.files 交给 addImages,随后立即清空 input.value,
|
||||||
|
* 保证再次选择同一文件也会触发 change。
|
||||||
|
* @param e - input change 事件
|
||||||
|
*/
|
||||||
|
function onFileChange(e: Event): void {
|
||||||
|
const input = e.target as HTMLInputElement;
|
||||||
|
const files = input.files ? Array.from(input.files) : [];
|
||||||
|
void addImages(files);
|
||||||
|
input.value = '';
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 清理全部待提交图片:revoke 所有预览 objectURL 并清空队列(防弹窗反复开关导致内存泄漏)。
|
||||||
|
* [AI 触发时机] 无 —— 内部生命周期函数:由 resetForm(打开/语言切换)与弹窗关闭 watch 调用。
|
||||||
|
*/
|
||||||
|
function cleanupImages(): void {
|
||||||
|
images.value.forEach((item) => URL.revokeObjectURL(item.previewUrl));
|
||||||
|
images.value = [];
|
||||||
|
}
|
||||||
|
|
||||||
const closeDialog = () => {
|
const closeDialog = () => {
|
||||||
emit('update:modelValue', false);
|
emit('update:modelValue', false);
|
||||||
@@ -59,12 +219,14 @@ const resetForm = () => {
|
|||||||
content.value = '';
|
content.value = '';
|
||||||
error.value = '';
|
error.value = '';
|
||||||
submitting.value = false;
|
submitting.value = false;
|
||||||
|
cleanupImages();
|
||||||
};
|
};
|
||||||
|
|
||||||
watch(
|
watch(
|
||||||
() => props.modelValue,
|
() => props.modelValue,
|
||||||
(visible) => {
|
(visible) => {
|
||||||
if (visible) resetForm();
|
if (visible) resetForm();
|
||||||
|
else cleanupImages();
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
@@ -74,6 +236,14 @@ watch(locale, () => {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 提交反馈(经统一 HTTP 客户端,自动附鉴权头)。
|
||||||
|
* [AI 触发时机] 无 —— 纯 UI 交互:点击提交按钮时调用。
|
||||||
|
* 核心逻辑:payload 携带 feedback_type / feedback_module(当前语言展示文案)、content、
|
||||||
|
* source_page、image_asset_nos(仅 status==='ready' 的图、按添加顺序;可为空数组,
|
||||||
|
* 后端把缺失与空数组同等对待),chat 入口另附 chat_log_id;BusinessError 的 message
|
||||||
|
* 展示在内联错误行,成功路径 emit('submitted') 后关闭(成功提示由父组件处理)。
|
||||||
|
*/
|
||||||
const submitFeedback = async () => {
|
const submitFeedback = async () => {
|
||||||
if (!canSubmit.value) {
|
if (!canSubmit.value) {
|
||||||
error.value = t('feedback.msg.fillContent');
|
error.value = t('feedback.msg.fillContent');
|
||||||
@@ -89,31 +259,25 @@ const submitFeedback = async () => {
|
|||||||
feedback_module: selectedModule.value,
|
feedback_module: selectedModule.value,
|
||||||
content: content.value.trim(),
|
content: content.value.trim(),
|
||||||
source_page: props.sourcePage,
|
source_page: props.sourcePage,
|
||||||
|
image_asset_nos: images.value
|
||||||
|
.filter((i) => i.status === 'ready')
|
||||||
|
.map((i) => i.assetNo as string),
|
||||||
};
|
};
|
||||||
|
|
||||||
if (props.chatLogId !== null && props.chatLogId !== undefined) {
|
if (props.chatLogId !== null && props.chatLogId !== undefined) {
|
||||||
payload.chat_log_id = props.chatLogId;
|
payload.chat_log_id = props.chatLogId;
|
||||||
}
|
}
|
||||||
|
|
||||||
const res = await fetch('/api/user/feedback', {
|
await requestJson<void>('/api/user/feedback', {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
headers: {
|
headers: { 'Content-Type': 'application/json' },
|
||||||
'Content-Type': 'application/json',
|
|
||||||
...props.authHeaders,
|
|
||||||
},
|
|
||||||
body: JSON.stringify(payload),
|
body: JSON.stringify(payload),
|
||||||
});
|
});
|
||||||
|
|
||||||
const data = await res.json().catch(() => ({}));
|
|
||||||
if (!res.ok) {
|
|
||||||
error.value = data?.error || t('feedback.msg.submitFailed');
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
emit('submitted');
|
emit('submitted');
|
||||||
closeDialog();
|
closeDialog();
|
||||||
} catch {
|
} catch (e) {
|
||||||
error.value = t('feedback.msg.submitFailed');
|
error.value = e instanceof BusinessError ? e.message : t('feedback.msg.submitFailed');
|
||||||
} finally {
|
} finally {
|
||||||
submitting.value = false;
|
submitting.value = false;
|
||||||
}
|
}
|
||||||
@@ -121,60 +285,88 @@ const submitFeedback = async () => {
|
|||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
<div
|
<ElDialog
|
||||||
v-if="modelValue"
|
v-model="visible"
|
||||||
class="dialog-overlay dialog-overlay--z80"
|
:title="t('feedback.title')"
|
||||||
|
width="640px"
|
||||||
|
append-to-body
|
||||||
|
:close-on-click-modal="false"
|
||||||
>
|
>
|
||||||
<div class="dialog-panel max-w-2xl max-h-[92vh]">
|
<div class="space-y-5" @paste="onPaste">
|
||||||
<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">
|
<div class="space-y-1.5">
|
||||||
<label class="label-field block">{{ t('feedback.labels.type') }}</label>
|
<div class="text-sm font-medium text-secondary">{{ t('feedback.labels.type') }}</div>
|
||||||
<div class="segment-control segment-control--cols-3 segment-control--md" role="radiogroup" :aria-label="t('feedback.labels.type')">
|
<ElSegmented v-model="selectedType" :options="typeOptions" />
|
||||||
<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>
|
||||||
|
|
||||||
<div class="space-y-1.5">
|
<div class="space-y-1.5">
|
||||||
<label class="label-field block">{{ t('feedback.labels.module') }}</label>
|
<div class="text-sm font-medium text-secondary">{{ t('feedback.labels.module') }}</div>
|
||||||
<select v-model="selectedModule" class="input-field text-base">
|
<ElSelect v-model="selectedModule" class="w-full">
|
||||||
<option v-for="item in moduleOptions" :key="item" :value="item">{{ item }}</option>
|
<ElOption v-for="item in moduleOptions" :key="item" :label="item" :value="item" />
|
||||||
</select>
|
</ElSelect>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="space-y-1.5">
|
<div class="space-y-1.5">
|
||||||
<label class="label-field block">
|
<div class="text-sm font-medium text-secondary">
|
||||||
{{ t('feedback.labels.content') }}<span class="ml-0.5 text-red-500">*</span>
|
{{ t('feedback.labels.content') }}<span class="ml-0.5 text-red-500">*</span>
|
||||||
</label>
|
</div>
|
||||||
<textarea
|
<ElInput
|
||||||
v-model="content"
|
v-model="content"
|
||||||
rows="5"
|
type="textarea"
|
||||||
maxlength="2000"
|
:rows="5"
|
||||||
class="input-field resize-none text-base"
|
:maxlength="2000"
|
||||||
|
show-word-limit
|
||||||
|
resize="none"
|
||||||
:placeholder="t('feedback.placeholder.content')"
|
:placeholder="t('feedback.placeholder.content')"
|
||||||
/>
|
/>
|
||||||
|
|
||||||
|
<div class="mt-1 flex flex-wrap items-center gap-2">
|
||||||
|
<div
|
||||||
|
v-for="(img, idx) in images"
|
||||||
|
:key="img.previewUrl"
|
||||||
|
class="relative h-12 w-12"
|
||||||
|
>
|
||||||
|
<div class="h-full w-full overflow-hidden rounded-md border border-gray-200 dark:border-gray-600">
|
||||||
|
<img
|
||||||
|
:src="img.previewUrl"
|
||||||
|
:alt="img.filename"
|
||||||
|
class="h-full w-full object-cover"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
<!-- uploading 遮罩:提交按钮在此期间禁用(hasUploadingImage) -->
|
||||||
|
<div
|
||||||
|
v-if="img.status === 'uploading'"
|
||||||
|
class="pointer-events-none absolute inset-0 flex items-center justify-center rounded-md bg-black/50"
|
||||||
|
>
|
||||||
|
<Loader2 class="h-4 w-4 animate-spin text-white" />
|
||||||
|
</div>
|
||||||
|
<ElButton
|
||||||
|
size="small"
|
||||||
|
circle
|
||||||
|
:aria-label="t('feedback.upload.remove')"
|
||||||
|
class="absolute -right-2 -top-2"
|
||||||
|
@click="removeImage(idx)"
|
||||||
|
>
|
||||||
|
<X class="h-3 w-3" />
|
||||||
|
</ElButton>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- label 包裹隐藏 file input:点击格子即唤起文件选择,无需手写按钮 -->
|
||||||
|
<label
|
||||||
|
class="flex h-12 cursor-pointer items-center gap-1.5 rounded-md border border-dashed border-gray-300 px-3 text-sm text-muted transition-colors hover:border-brand-400 hover:text-brand-600 dark:border-gray-600 dark:hover:border-brand-500"
|
||||||
|
>
|
||||||
|
<Plus class="h-4 w-4" />
|
||||||
|
<span>{{ t('feedback.upload.addImage') }}</span>
|
||||||
|
<input
|
||||||
|
type="file"
|
||||||
|
class="hidden"
|
||||||
|
multiple
|
||||||
|
accept="image/png,image/jpeg,image/webp"
|
||||||
|
@change="onFileChange"
|
||||||
|
/>
|
||||||
|
</label>
|
||||||
|
</div>
|
||||||
|
<p class="mt-1 text-xs text-muted">{{ t('feedback.upload.pasteHint') }}</p>
|
||||||
|
|
||||||
<div class="mt-2 flex items-center justify-between">
|
<div class="mt-2 flex items-center justify-between">
|
||||||
<div v-if="error" class="text-base text-red-600">{{ error }}</div>
|
<div v-if="error" class="text-base text-red-600">{{ error }}</div>
|
||||||
<div v-else class="text-base text-muted"> </div>
|
<div v-else class="text-base text-muted"> </div>
|
||||||
@@ -183,25 +375,18 @@ const submitFeedback = async () => {
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="dialog-footer">
|
<template #footer>
|
||||||
<button
|
<ElButton :disabled="submitting" @click="closeDialog">
|
||||||
type="button"
|
|
||||||
class="btn-ghost"
|
|
||||||
:disabled="submitting"
|
|
||||||
@click="closeDialog"
|
|
||||||
>
|
|
||||||
{{ t('feedback.cancel') }}
|
{{ t('feedback.cancel') }}
|
||||||
</button>
|
</ElButton>
|
||||||
<button
|
<ElButton
|
||||||
type="button"
|
type="primary"
|
||||||
class="btn-primary"
|
:loading="submitting"
|
||||||
:disabled="!canSubmit"
|
:disabled="!canSubmit"
|
||||||
@click="submitFeedback"
|
@click="submitFeedback"
|
||||||
>
|
>
|
||||||
<MessageSquareText class="h-5 w-5" />
|
|
||||||
{{ submitting ? t('feedback.submitting') : t('feedback.submit') }}
|
{{ submitting ? t('feedback.submitting') : t('feedback.submit') }}
|
||||||
</button>
|
</ElButton>
|
||||||
</div>
|
</template>
|
||||||
</div>
|
</ElDialog>
|
||||||
</div>
|
|
||||||
</template>
|
</template>
|
||||||
Reference in new issue
Block a user