feat(i18n): 将前端用户可见中文硬编码改为四语言
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
1 parent
dce915ea30
commit
ac7b53a523
105 files changed
+2928
-647
No files matched your search
@@ -377,7 +377,10 @@ export function useChat() {
|
||||
* 说明:
|
||||
* - Dify Chatflow 失败时常以 `workflow_finished + data.status=failed` 返回,HTTP 仍是 200;
|
||||
* - 若这里只按“终态成功”处理,页面会出现“没有任何响应”;
|
||||
* - 因此需要优先从 top-level / nested data / error 对象里抽取失败文案。
|
||||
* - 因此需要优先从 top-level / nested data / error 对象里抽取失败文案;
|
||||
* - 上下文过长与缺省失败文案走 chat.streamError.contextTooLong / workflowFailed。
|
||||
* @param data - SSE 事件 JSON
|
||||
* @returns 用户可读错误;非失败终态返回空串
|
||||
*/
|
||||
const extractWorkflowFailureMessage = (data: Record<string, unknown>) => {
|
||||
if (String(data.event || '') !== 'workflow_finished') return '';
|
||||
@@ -399,11 +402,11 @@ export function useChat() {
|
||||
const normalized = formatStreamError(candidate).trim();
|
||||
if (!normalized || normalized === 'Unknown error') continue;
|
||||
if (/maximum context length|input_tokens/i.test(normalized)) {
|
||||
return '当前会话上下文过长,模型无法继续回答。请新建对话后重新查询该资产编号。';
|
||||
return t('chat.streamError.contextTooLong');
|
||||
}
|
||||
return normalized;
|
||||
}
|
||||
return '工作流执行失败,请稍后重试';
|
||||
return t('chat.streamError.workflowFailed');
|
||||
};
|
||||
|
||||
const streamErrorLabels = (): StreamErrorLabels => ({
|
||||
|
||||
@@ -24,9 +24,6 @@ export type AgentSuggestedQuestionItem = {
|
||||
const DEFAULT_KB = '企业知识库';
|
||||
const ERP_KB = 'ERP知识库';
|
||||
|
||||
const TRAINING_AGENT_DESCRIPTION =
|
||||
'我是你的新人培训助手,会在同一个聊天页面内带你完成视频学习、知识点复盘、逐题考试和结果复盘。';
|
||||
|
||||
const normalizeAgentSuggestedQuestions = (value: unknown): AgentSuggestedQuestionItem[] => {
|
||||
if (!Array.isArray(value)) return [];
|
||||
return value
|
||||
@@ -114,7 +111,7 @@ export function useChatAgent(options: UseChatAgentOptions) {
|
||||
const welcome = String(currentAgent.value?.welcome_message || '').trim();
|
||||
if (welcome) return welcome;
|
||||
const text = String(currentAgent.value?.description || '').trim();
|
||||
if (!text && matchesTrainingAgent(currentAgent.value)) return TRAINING_AGENT_DESCRIPTION;
|
||||
if (!text && matchesTrainingAgent(currentAgent.value)) return t('chat.training.agentDescription');
|
||||
return text;
|
||||
});
|
||||
|
||||
@@ -148,7 +145,7 @@ export function useChatAgent(options: UseChatAgentOptions) {
|
||||
const styledSuggestedQuestionSections = computed(() => {
|
||||
const groups = new Map<string, AgentSuggestedQuestionItem[]>();
|
||||
for (const item of agentSuggestedQuestions.value) {
|
||||
const groupName = String(item.group || '').trim() || '常见问题';
|
||||
const groupName = String(item.group || '').trim() || t('chat.faqGroup');
|
||||
if (!groups.has(groupName)) {
|
||||
groups.set(groupName, []);
|
||||
}
|
||||
|
||||
@@ -1,40 +1,42 @@
|
||||
/**
|
||||
* features/chat/composables/useChatAssetHistory.ts
|
||||
* 用途:管理固定资产履历检索、友好提示与文件预览跳转。
|
||||
* 依赖:chat.api、useChatSourceFiles 暴露的 openPreview、聊天提示消息。
|
||||
* 依赖:chat.api、vue-i18n、useChatSourceFiles 暴露的 openPreview、聊天提示消息。
|
||||
* 逻辑:页面层统一持有“打开履历”动作,消息气泡/查询预览弹窗复用该入口;
|
||||
* 点击资产编号后先进入“检索中”状态,命中履历文件则直接打开最佳候选预览,未命中时仅提示用户。
|
||||
*/
|
||||
import { ref } from 'vue';
|
||||
import type { ComputedRef } from 'vue';
|
||||
import type { ComposerTranslation } from 'vue-i18n';
|
||||
import { searchAssetHistoryFiles } from '../api/chat.api';
|
||||
import type { AssetHistoryFileItem, SourceFileLink } from '../types/chat.types';
|
||||
import type { ComputedRef } from 'vue';
|
||||
|
||||
interface UseChatAssetHistoryOptions {
|
||||
agentId: ComputedRef<number>;
|
||||
openPreview: (file: SourceFileLink) => Promise<void>;
|
||||
warn: (message: string) => void;
|
||||
t: ComposerTranslation;
|
||||
}
|
||||
|
||||
/**
|
||||
* 把后端返回的技术性错误翻译成用户可理解的提示。
|
||||
* AI 触发时机:当资产履历查询失败,但原始错误包含英文配置名、共享盘术语等技术细节时调用。
|
||||
* 核心逻辑:优先识别已知的履历共享盘配置异常,返回面向业务用户的中文说明;其他错误保持原文,避免吞掉真实上下文。
|
||||
* 核心逻辑:优先识别已知的履历共享盘配置异常,返回面向业务用户的本地化说明;其他错误保持原文。
|
||||
* 参数约束:仅处理展示文案,不改变错误对象本身;返回值必须适合作为 toast/警告弹窗直接展示。
|
||||
*/
|
||||
function normalizeAssetHistoryErrorMessage(message: string): string {
|
||||
function normalizeAssetHistoryErrorMessage(message: string, t: ComposerTranslation): string {
|
||||
const normalizedMessage = String(message || '').trim();
|
||||
const lowerCaseMessage = normalizedMessage.toLowerCase();
|
||||
if (lowerCaseMessage.includes('asset history share is not configured')) {
|
||||
return '当前系统暂未配置资产履历文件目录,暂时无法查看履历,请联系管理员处理。';
|
||||
return String(t('chat.assetHistory.shareNotConfigured'));
|
||||
}
|
||||
if (lowerCaseMessage.includes('asset history share is unreachable')) {
|
||||
return '当前环境暂时无法访问资产履历共享盘,请联系管理员检查测试环境共享盘挂载或访问权限。';
|
||||
return String(t('chat.assetHistory.shareUnreachable'));
|
||||
}
|
||||
if (lowerCaseMessage.includes('asset history share is invalid')) {
|
||||
return '当前环境的资产履历目录配置无效,请联系管理员检查共享盘目录配置。';
|
||||
return String(t('chat.assetHistory.shareInvalid'));
|
||||
}
|
||||
return normalizedMessage || '检索资产履历失败';
|
||||
return normalizedMessage || String(t('chat.assetHistory.searchFailed'));
|
||||
}
|
||||
|
||||
export function useChatAssetHistory(options: UseChatAssetHistoryOptions) {
|
||||
@@ -44,6 +46,7 @@ export function useChatAssetHistory(options: UseChatAssetHistoryOptions) {
|
||||
const assetId = ref('');
|
||||
const assetName = ref('');
|
||||
const items = ref<AssetHistoryFileItem[]>([]);
|
||||
const { t } = options;
|
||||
|
||||
const close = () => {
|
||||
open.value = false;
|
||||
@@ -66,7 +69,7 @@ export function useChatAssetHistory(options: UseChatAssetHistoryOptions) {
|
||||
return;
|
||||
}
|
||||
if (!normalizedAssetId && !normalizedAssetName) {
|
||||
options.warn('当前资产缺少可用于检索履历的编号或名称');
|
||||
options.warn(String(t('chat.assetHistory.missingIdentifier')));
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -85,15 +88,15 @@ export function useChatAssetHistory(options: UseChatAssetHistoryOptions) {
|
||||
const bestMatch = items.value[0];
|
||||
if (!bestMatch) {
|
||||
const displayName = normalizedAssetId || normalizedAssetName;
|
||||
options.warn(`未找到资产 ${displayName} 的履历文件,如确认应有履历,请联系管理员补充。`);
|
||||
options.warn(String(t('chat.assetHistory.notFound', { name: displayName })));
|
||||
return;
|
||||
}
|
||||
await openHistoryFilePreview(bestMatch);
|
||||
} catch (err: unknown) {
|
||||
const rawMessage = err instanceof Error ? err.message : '检索资产履历失败';
|
||||
const message = normalizeAssetHistoryErrorMessage(rawMessage);
|
||||
const rawMessage = err instanceof Error ? err.message : String(t('chat.assetHistory.searchFailed'));
|
||||
const message = normalizeAssetHistoryErrorMessage(rawMessage, t);
|
||||
error.value = message;
|
||||
options.warn(`履历查询失败:${message}`);
|
||||
options.warn(String(t('chat.assetHistory.queryFailed', { message })));
|
||||
} finally {
|
||||
loading.value = false;
|
||||
}
|
||||
|
||||
@@ -1,11 +1,12 @@
|
||||
/**
|
||||
* features/chat/composables/useChatAssetImage.ts
|
||||
* 用途:管理固定资产图片检索、友好提示与预览跳转。
|
||||
* 依赖:chat.api、useChatSourceFiles 暴露的 openPreview、聊天提示消息。
|
||||
* 依赖:chat.api、vue-i18n、useChatSourceFiles 暴露的 openPreview、聊天提示消息。
|
||||
* 逻辑:用户点击“图片 -> 查看”后,本 composable 统一向后端索要最佳图片,再复用现有文件预览弹窗在站内展示。
|
||||
*/
|
||||
import { ref } from 'vue';
|
||||
import type { ComputedRef } from 'vue';
|
||||
import type { ComposerTranslation } from 'vue-i18n';
|
||||
import { resolveAssetImagePreview } from '../api/chat.api';
|
||||
import type { SourceFileLink } from '../types/chat.types';
|
||||
|
||||
@@ -13,37 +14,39 @@ interface UseChatAssetImageOptions {
|
||||
agentId: ComputedRef<number>;
|
||||
openPreviewGallery: (files: SourceFileLink[], initialIndex?: number) => Promise<void>;
|
||||
warn: (message: string) => void;
|
||||
t: ComposerTranslation;
|
||||
}
|
||||
|
||||
/**
|
||||
* 把后端返回的图片检索错误翻译成业务用户能看懂的提示。
|
||||
* AI 触发时机:当用户点击“图片 -> 查看”失败,但原始报错包含接口路径、外部系统术语等技术细节时调用。
|
||||
* 核心逻辑:优先识别已知的配置/检索异常并转成中文说明;未知错误保留原始文本,方便排查。
|
||||
* 核心逻辑:优先识别已知的配置/检索异常并转成本地化说明;未知错误保留原始文本,方便排查。
|
||||
* 参数与输出约束:只负责展示文案,不吞掉真实错误对象;返回值必须适合作为 toast 直接展示。
|
||||
*/
|
||||
function normalizeAssetImageErrorMessage(message: string): string {
|
||||
function normalizeAssetImageErrorMessage(message: string, t: ComposerTranslation): string {
|
||||
const normalizedMessage = String(message || '').trim();
|
||||
const lowerCaseMessage = normalizedMessage.toLowerCase();
|
||||
if (lowerCaseMessage.includes('固定资产图片文档库未配置')) {
|
||||
return '当前系统暂未配置固定资产图片文档库,暂时无法查看图片,请联系管理员处理。';
|
||||
return String(t('chat.assetImage.libraryNotConfigured'));
|
||||
}
|
||||
if (lowerCaseMessage.includes('请求的资源不存在')) {
|
||||
return '设备管理员还未上传照片~';
|
||||
return String(t('chat.assetImage.noPhotoUploaded'));
|
||||
}
|
||||
if (lowerCaseMessage.includes('未找到资产')) {
|
||||
return normalizedMessage;
|
||||
}
|
||||
return normalizedMessage || '检索固定资产图片失败';
|
||||
return normalizedMessage || String(t('chat.assetImage.searchFailed'));
|
||||
}
|
||||
|
||||
|
||||
export function useChatAssetImage(options: UseChatAssetImageOptions) {
|
||||
const loading = ref(false);
|
||||
const { t } = options;
|
||||
|
||||
/**
|
||||
* 检索固定资产图片并直接打开预览。
|
||||
* AI 触发时机:当用户点击聊天表格或 CSV 预览里的“图片 -> 查看”时调用。
|
||||
* 核心逻辑:先向后端请求全部命中的图片文件,再把图片组交给通用 FilePreviewModal 预览。
|
||||
* 核心逻辑:先向后端请求全部命中的图片文件,再把图片组交给通用 FilePreviewModal 预览。
|
||||
* 参数约束:至少要提供资产编号或资产名称之一;后端负责登录外部文档库和挑选最佳图片。
|
||||
*/
|
||||
const openImage = async (nextAssetId: string, nextAssetName = '') => {
|
||||
@@ -51,7 +54,7 @@ export function useChatAssetImage(options: UseChatAssetImageOptions) {
|
||||
const normalizedAssetName = String(nextAssetName || '').trim();
|
||||
if (loading.value) return;
|
||||
if (!normalizedAssetId && !normalizedAssetName) {
|
||||
options.warn('当前资产缺少可用于检索图片的编号或名称');
|
||||
options.warn(String(t('chat.assetImage.missingIdentifier')));
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -66,7 +69,7 @@ export function useChatAssetImage(options: UseChatAssetImageOptions) {
|
||||
: (result?.item ? [result.item] : []);
|
||||
if (!items.length) {
|
||||
const displayName = normalizedAssetId || normalizedAssetName;
|
||||
options.warn(`未找到资产 ${displayName} 的图片文件,请联系管理员补充。`);
|
||||
options.warn(String(t('chat.assetImage.notFound', { name: displayName })));
|
||||
return;
|
||||
}
|
||||
await options.openPreviewGallery(
|
||||
@@ -78,12 +81,12 @@ export function useChatAssetImage(options: UseChatAssetImageOptions) {
|
||||
0,
|
||||
);
|
||||
} catch (err: unknown) {
|
||||
const rawMessage = err instanceof Error ? err.message : '检索固定资产图片失败';
|
||||
const message = normalizeAssetImageErrorMessage(rawMessage);
|
||||
if (message === '设备管理员还未上传照片~') {
|
||||
const rawMessage = err instanceof Error ? err.message : String(t('chat.assetImage.searchFailed'));
|
||||
const message = normalizeAssetImageErrorMessage(rawMessage, t);
|
||||
if (message === String(t('chat.assetImage.noPhotoUploaded'))) {
|
||||
options.warn(message);
|
||||
} else {
|
||||
options.warn(`图片查询失败:${message}`);
|
||||
options.warn(String(t('chat.assetImage.queryFailed', { message })));
|
||||
}
|
||||
} finally {
|
||||
loading.value = false;
|
||||
|
||||
@@ -66,7 +66,7 @@ export interface UseChatAttachmentsOptions {
|
||||
|
||||
export function useChatAttachments(options: UseChatAttachmentsOptions) {
|
||||
const { deps, currentAgentId, currentAgent } = options;
|
||||
const { msg } = deps;
|
||||
const { msg, t } = deps;
|
||||
|
||||
const attachments = ref<PendingAttachment[]>([]);
|
||||
const isUploadingAttachments = ref(false);
|
||||
@@ -267,12 +267,12 @@ export function useChatAttachments(options: UseChatAttachmentsOptions) {
|
||||
const files = Array.from(fileList);
|
||||
for (const f of files) {
|
||||
if (attachmentPolicy.value.totalLimit && attachments.value.length >= attachmentPolicy.value.totalLimit) {
|
||||
msg.warning(`附件数量已达上限(${attachmentPolicy.value.totalLimit})`);
|
||||
msg.warning(t('chat.attachmentsUi.limitReached', { limit: attachmentPolicy.value.totalLimit }));
|
||||
break;
|
||||
}
|
||||
const ext = extractExt(f.name || '');
|
||||
if (attachmentPolicy.value.allowedExts && (!ext || !attachmentPolicy.value.allowedExts.has(ext))) {
|
||||
msg.warning(`不支持的附件类型:${f.name}`);
|
||||
msg.warning(t('chat.attachmentsUi.unsupportedType', { name: f.name }));
|
||||
continue;
|
||||
}
|
||||
let type = inferFileTypeFromFile(f);
|
||||
@@ -280,23 +280,23 @@ export function useChatAttachments(options: UseChatAttachmentsOptions) {
|
||||
if (attachmentPolicy.value.enabled.custom.local && !isKnownDifyExt(ext)) {
|
||||
type = 'custom';
|
||||
} else {
|
||||
msg.warning(`不支持的附件类型:${f.name}`);
|
||||
msg.warning(t('chat.attachmentsUi.unsupportedType', { name: f.name }));
|
||||
continue;
|
||||
}
|
||||
}
|
||||
const caps = attachmentPolicy.value.enabled[type];
|
||||
if (!caps?.local) {
|
||||
msg.warning(`当前应用不支持上传此类型附件:${type}`);
|
||||
msg.warning(t('chat.attachmentsUi.typeNotAllowed', { type }));
|
||||
continue;
|
||||
}
|
||||
const limit = attachmentPolicy.value.sizeLimitMb[type];
|
||||
if (limit && f.size > limit * 1024 * 1024) {
|
||||
msg.warning(`附件过大(上限 ${limit}MB):${f.name}`);
|
||||
msg.warning(t('chat.attachmentsUi.tooLarge', { limit, name: f.name }));
|
||||
continue;
|
||||
}
|
||||
const countSameType = attachments.value.filter((a) => a.type === type).length;
|
||||
if (caps.limit && countSameType >= caps.limit) {
|
||||
msg.warning(`该类型附件数量已达上限(${caps.limit})`);
|
||||
msg.warning(t('chat.attachmentsUi.typeLimitReached', { limit: caps.limit }));
|
||||
continue;
|
||||
}
|
||||
attachments.value.push({ id: `${Date.now()}_${Math.random()}`, kind: 'local', file: f, type });
|
||||
@@ -309,20 +309,20 @@ export function useChatAttachments(options: UseChatAttachmentsOptions) {
|
||||
if (!raw) return;
|
||||
const url = raw.startsWith('//') ? `${window.location.protocol}${raw}` : raw;
|
||||
if (!/^https?:\/\//i.test(url)) {
|
||||
msg.warning('仅支持 http/https URL');
|
||||
msg.warning(t('chat.attachmentsUi.httpOnly'));
|
||||
return;
|
||||
}
|
||||
if (!attachmentPolicy.value.canRemote) {
|
||||
msg.warning('当前应用不支持 URL 附件');
|
||||
msg.warning(t('chat.attachmentsUi.urlNotSupported'));
|
||||
return;
|
||||
}
|
||||
if (attachmentPolicy.value.totalLimit && attachments.value.length >= attachmentPolicy.value.totalLimit) {
|
||||
msg.warning(`附件数量已达上限(${attachmentPolicy.value.totalLimit})`);
|
||||
msg.warning(t('chat.attachmentsUi.limitReached', { limit: attachmentPolicy.value.totalLimit }));
|
||||
return;
|
||||
}
|
||||
const ext = extractExt(url);
|
||||
if (attachmentPolicy.value.allowedExts && (!ext || !attachmentPolicy.value.allowedExts.has(ext))) {
|
||||
msg.warning('不支持的 URL 附件类型');
|
||||
msg.warning(t('chat.attachmentsUi.unsupportedUrlType'));
|
||||
return;
|
||||
}
|
||||
let type = inferFileTypeFromUrl(url);
|
||||
@@ -330,18 +330,18 @@ export function useChatAttachments(options: UseChatAttachmentsOptions) {
|
||||
if (attachmentPolicy.value.enabled.custom.remote && !isKnownDifyExt(ext)) {
|
||||
type = 'custom';
|
||||
} else {
|
||||
msg.warning('不支持的 URL 附件类型');
|
||||
msg.warning(t('chat.attachmentsUi.unsupportedUrlType'));
|
||||
return;
|
||||
}
|
||||
}
|
||||
const caps = attachmentPolicy.value.enabled[type];
|
||||
if (!caps?.remote) {
|
||||
msg.warning(`当前应用不支持该类型 URL 附件:${type}`);
|
||||
msg.warning(t('chat.attachmentsUi.urlTypeNotAllowed', { type }));
|
||||
return;
|
||||
}
|
||||
const countSameType = attachments.value.filter((a) => a.type === type).length;
|
||||
if (caps.limit && countSameType >= caps.limit) {
|
||||
msg.warning(`该类型附件数量已达上限(${caps.limit})`);
|
||||
msg.warning(t('chat.attachmentsUi.typeLimitReached', { limit: caps.limit }));
|
||||
return;
|
||||
}
|
||||
attachments.value.push({ id: `${Date.now()}_${Math.random()}`, kind: 'remote', url, type });
|
||||
|
||||
@@ -120,9 +120,9 @@ export function useChatLeave(options: UseChatLeaveOptions) {
|
||||
canUseLeaveFeature,
|
||||
...oaLogin,
|
||||
...agentPicker,
|
||||
getLeaveTypeLabel,
|
||||
getLeaveTypeLabel: (val: string) => getLeaveTypeLabel(val, t),
|
||||
formatDurationLabel: (hours: number, leaveType?: string) => formatDurationLabel(hours, leaveType, t),
|
||||
formatYesNoLabel,
|
||||
formatYesNoLabel: (value: 0 | 1 | null) => formatYesNoLabel(value, t),
|
||||
syncLeaveDuration,
|
||||
getLeaveFormPayload,
|
||||
getLeaveConfirmationPayload,
|
||||
|
||||
@@ -180,11 +180,13 @@ export function useChatPage() {
|
||||
agentId: currentAgentId,
|
||||
openPreview,
|
||||
warn: (text) => msg.warning(text),
|
||||
t,
|
||||
});
|
||||
const assetImage = useChatAssetImage({
|
||||
agentId: currentAgentId,
|
||||
openPreviewGallery,
|
||||
warn: (text) => msg.warning(text),
|
||||
t,
|
||||
});
|
||||
|
||||
watch(currentAgentId, (id) => {
|
||||
|
||||
@@ -1,8 +1,11 @@
|
||||
/**
|
||||
* features/chat/composables/useChatQueryPreview.ts
|
||||
* Text2SQL 查询结果全量预览弹窗:分页加载与消息 payload 解析。
|
||||
* 用途:Text2SQL 查询结果全量预览弹窗:分页加载与消息 payload 解析。
|
||||
* 依赖:vue-i18n、chat.api.getChatQueryPreviewPage、chat.types.ChatMessage。
|
||||
* 逻辑:Chat 消息气泡触发 openDialog;文案走 chat.queryPreview.*。
|
||||
*/
|
||||
import { ref, type ComputedRef } from 'vue';
|
||||
import { useI18n } from 'vue-i18n';
|
||||
import { getChatQueryPreviewPage } from '../api/chat.api';
|
||||
import type { ChatMessage } from '../types/chat.types';
|
||||
|
||||
@@ -29,8 +32,15 @@ export interface UseChatQueryPreviewOptions {
|
||||
currentAgentId: ComputedRef<number>;
|
||||
}
|
||||
|
||||
/**
|
||||
* 组装查询结果全量预览弹窗状态与分页加载逻辑。
|
||||
* 核心逻辑:从消息 payload 判断可预览;调用 getChatQueryPreviewPage 拉取分页数据。
|
||||
* @param options.currentAgentId - 当前 Agent ID(请求预览接口必填)
|
||||
* @returns 弹窗状态、摘要文案与 open/close/changePage 操作
|
||||
*/
|
||||
export function useChatQueryPreview(options: UseChatQueryPreviewOptions) {
|
||||
const { currentAgentId } = options;
|
||||
const { t } = useI18n();
|
||||
|
||||
const show = ref(false);
|
||||
const loading = ref(false);
|
||||
@@ -46,6 +56,11 @@ export function useChatQueryPreview(options: UseChatQueryPreviewOptions) {
|
||||
total: 0,
|
||||
});
|
||||
|
||||
/**
|
||||
* 从消息中提取 text2sql 预览 payload。
|
||||
* @param msg - 聊天消息
|
||||
* @returns 预览 payload;非目标 kind 时返回 null
|
||||
*/
|
||||
const getPayload = (msg: ChatMessage): QueryPreviewPayload | null => {
|
||||
const payload = msg?.payload;
|
||||
if (!payload || typeof payload !== 'object') return null;
|
||||
@@ -53,29 +68,52 @@ export function useChatQueryPreview(options: UseChatQueryPreviewOptions) {
|
||||
return payload as QueryPreviewPayload;
|
||||
};
|
||||
|
||||
/**
|
||||
* 判断消息是否可打开全量预览。
|
||||
* @param msg - 聊天消息
|
||||
* @returns 是否可预览
|
||||
*/
|
||||
const canOpen = (msg: ChatMessage) => {
|
||||
const payload = getPayload(msg);
|
||||
return !!(payload?.previewable && Number(msg?.chat_log_id) > 0);
|
||||
};
|
||||
|
||||
/**
|
||||
* 生成“查看全部预览”摘要文案(含可选总条数)。
|
||||
* @param msg - 聊天消息
|
||||
* @returns 本地化摘要
|
||||
*/
|
||||
const getSummary = (msg: ChatMessage) => {
|
||||
const payload = getPayload(msg);
|
||||
const total = Number(payload?.total_count || 0);
|
||||
if (total > 0) return `查看全部预览(共 ${total} 条)`;
|
||||
return '查看全部预览';
|
||||
if (total > 0) return t('chat.queryPreview.viewAllWithTotal', { total });
|
||||
return t('chat.queryPreview.viewAll');
|
||||
};
|
||||
|
||||
/**
|
||||
* 按当前 pageSize 计算总页数。
|
||||
* @returns 至少为 1 的页数
|
||||
*/
|
||||
const totalPages = () =>
|
||||
Math.max(1, Math.ceil((state.value.total || 0) / (state.value.pageSize || 100)));
|
||||
|
||||
/**
|
||||
* 关闭预览弹窗并清空错误。
|
||||
*/
|
||||
const close = () => {
|
||||
show.value = false;
|
||||
error.value = '';
|
||||
};
|
||||
|
||||
/**
|
||||
* 拉取指定 chat_log 的分页预览数据。
|
||||
* 核心逻辑:Agent 未就绪时写本地化错误;成功后合并 state;失败回落 loadFailed。
|
||||
* @param chatLogId - 聊天日志 ID
|
||||
* @param page - 页码,默认 1
|
||||
*/
|
||||
const loadPage = async (chatLogId: number, page = 1) => {
|
||||
if (!currentAgentId.value) {
|
||||
error.value = '当前 Agent 未就绪,请稍后重试';
|
||||
error.value = t('chat.queryPreview.agentNotReady');
|
||||
return;
|
||||
}
|
||||
loading.value = true;
|
||||
@@ -85,10 +123,11 @@ export function useChatQueryPreview(options: UseChatQueryPreviewOptions) {
|
||||
page,
|
||||
page_size: state.value.pageSize,
|
||||
});
|
||||
const fallbackTitle = t('chat.queryPreview.title');
|
||||
state.value = {
|
||||
...state.value,
|
||||
chatLogId,
|
||||
title: String(result.query || state.value.title || '查询结果全量预览').trim() || '查询结果全量预览',
|
||||
title: String(result.query || state.value.title || fallbackTitle).trim() || fallbackTitle,
|
||||
query: String(result.query || '').trim(),
|
||||
columns: Array.isArray(result.columns) ? result.columns : [],
|
||||
rows: Array.isArray(result.rows) ? result.rows : [],
|
||||
@@ -97,20 +136,25 @@ export function useChatQueryPreview(options: UseChatQueryPreviewOptions) {
|
||||
total: Number(result.total || 0),
|
||||
};
|
||||
} catch (err: unknown) {
|
||||
error.value = (err as { message?: string })?.message || '加载全量预览失败';
|
||||
error.value = (err as { message?: string })?.message || t('chat.queryPreview.loadFailed');
|
||||
} finally {
|
||||
loading.value = false;
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* 打开预览弹窗并加载第一页。
|
||||
* @param msg - 触发预览的聊天消息
|
||||
*/
|
||||
const openDialog = async (msg: ChatMessage) => {
|
||||
const chatLogId = Number(msg?.chat_log_id || 0);
|
||||
if (!chatLogId) return;
|
||||
const payload = getPayload(msg);
|
||||
const fallbackTitle = t('chat.queryPreview.title');
|
||||
state.value = {
|
||||
...state.value,
|
||||
chatLogId,
|
||||
title: String(payload?.query || msg?.content || '查询结果全量预览').trim() || '查询结果全量预览',
|
||||
title: String(payload?.query || msg?.content || fallbackTitle).trim() || fallbackTitle,
|
||||
query: String(payload?.query || '').trim(),
|
||||
page: 1,
|
||||
total: Number(payload?.total_count || 0),
|
||||
@@ -119,6 +163,10 @@ export function useChatQueryPreview(options: UseChatQueryPreviewOptions) {
|
||||
await loadPage(chatLogId, 1);
|
||||
};
|
||||
|
||||
/**
|
||||
* 相对当前页翻页并重新加载。
|
||||
* @param delta - 页码增量(通常 ±1)
|
||||
*/
|
||||
const changePage = async (delta: number) => {
|
||||
const nextPage = state.value.page + delta;
|
||||
if (nextPage < 1 || nextPage > totalPages()) return;
|
||||
|
||||
@@ -551,6 +551,7 @@ export function useChatShipping(options: UseChatShippingOptions) {
|
||||
currentAgentId,
|
||||
refreshShippingActions,
|
||||
msg,
|
||||
t,
|
||||
});
|
||||
|
||||
/**
|
||||
@@ -659,6 +660,7 @@ export function useChatShipping(options: UseChatShippingOptions) {
|
||||
saveLocalMessageToBackend,
|
||||
refreshShippingActions,
|
||||
msg,
|
||||
t,
|
||||
});
|
||||
|
||||
const shippingIntakes = useShippingNoticeIntakes({
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
/**
|
||||
* features/chat/composables/useChatSourceFiles.ts
|
||||
* 检索来源 / 源文件链接解析与预览。
|
||||
* 用途:检索来源 / 源文件链接解析与预览。
|
||||
* 依赖:vue-i18n(t)、chat.api.resolveChatSourceFile、useMessage。
|
||||
* 逻辑:消息气泡源文件按钮调用 openPreview;缺链时抛 chat.sourcePreviewLinkMissing。
|
||||
*/
|
||||
import { ref, type ComputedRef, type Ref } from 'vue';
|
||||
import type { ComposerTranslation } from 'vue-i18n';
|
||||
@@ -389,7 +391,7 @@ export function useChatSourceFiles({ agentId, t, msg, isMobile }: UseChatSourceF
|
||||
};
|
||||
}
|
||||
}
|
||||
if (!file.url) throw new Error('当前源文件暂未返回可预览链接');
|
||||
if (!file.url) throw new Error(t('chat.sourcePreviewLinkMissing'));
|
||||
return { name: file.name, url: file.url, actualExt: file.actualExt };
|
||||
};
|
||||
|
||||
|
||||
@@ -1,4 +1,11 @@
|
||||
/**
|
||||
* features/chat/composables/useToolRunProgress.ts
|
||||
* 用途:轮询 Tool/文件检核任务进度,并在执行中锁定输入。
|
||||
* 依赖:vue-i18n、toolRunProgress.api、toolRunProgressConfig。
|
||||
* 逻辑:Chat 页 progress 卡片消费;lockMessage / queryFailed 走 chat.toolRun.*。
|
||||
*/
|
||||
import { computed, onBeforeUnmount, ref, type Ref, watch } from 'vue';
|
||||
import { useI18n } from 'vue-i18n';
|
||||
import { buildFileCheckLogProgressUrl } from '../utils/toolRunProgressConfig';
|
||||
import { getToolRunProgress, type ToolRunProgress } from '../api/toolRunProgress.api';
|
||||
import type { ToolRunProgressMatchSource } from '../types/tool-run-progress.types';
|
||||
@@ -43,11 +50,15 @@ const isTerminalStatus = (status?: string | null) => TERMINAL_STATUSES.has(Strin
|
||||
|
||||
/**
|
||||
* 轮询任务进度:有 run_id 时走 detail;或走 for-log / active。
|
||||
* 核心逻辑:按 config 选择 detail/session/active URL;running 时定时刷新;终态停表。
|
||||
* @param configRef - 进度轮询配置
|
||||
* @param options.allowEmptySessionPolls - 允许 for-session 空结果继续重试
|
||||
*/
|
||||
export function useToolRunProgress(
|
||||
configRef: Ref<ToolRunProgressConfig | null>,
|
||||
options: UseToolRunProgressOptions = {},
|
||||
) {
|
||||
const { t } = useI18n();
|
||||
const run = ref<ToolRunProgress | null>(null);
|
||||
const matchSource = ref<ToolRunProgressMatchSource | null>(null);
|
||||
const loading = ref(false);
|
||||
@@ -68,7 +79,7 @@ export function useToolRunProgress(
|
||||
|
||||
const isRunning = computed(() => run.value?.status === 'running');
|
||||
const shouldLockInput = computed(() => Boolean(configRef.value?.lock_input_when_running) && isRunning.value);
|
||||
const lockMessage = computed(() => configRef.value?.lock_message || '当前任务执行中,请等待完成');
|
||||
const lockMessage = computed(() => configRef.value?.lock_message || t('chat.toolRun.lockWaiting'));
|
||||
|
||||
const clearTimer = () => {
|
||||
if (timer !== undefined) {
|
||||
@@ -100,7 +111,7 @@ export function useToolRunProgress(
|
||||
matchSource.value = payload.match_source ?? null;
|
||||
return payload.run ?? null;
|
||||
} catch (e: unknown) {
|
||||
const message = e instanceof Error ? e.message : '任务进度查询失败';
|
||||
const message = e instanceof Error ? e.message : t('chat.toolRun.queryFailed');
|
||||
error.value = message;
|
||||
matchSource.value = null;
|
||||
clearTimer();
|
||||
|
||||
Reference in new issue
Block a user