Merge branch 'dev' into hugo

# Conflicts:
#	.env.dev
#	.env.shared
#	backend/app/api/chat.py
This commit is contained in:
hugo committed 2026-06-08 16:11:42 +08:00
commit ee90b66ff7
63 files changed
+4786 -1422

No files matched your search

+9
View File
@@ -64,6 +64,15 @@ function resolveLocalizedErrorMessage(code?: string, fallbackMessage?: string):
if (normalizedCode === 'VALIDATION_INVALID_PARAM' && fallback && !isGenericFallback(fallback) && fallback !== localized) {
return `${localized} ${fallback}`;
}
if (
normalizedCode === 'AUTH_FORBIDDEN'
&& fallback
&& !isGenericFallback(fallback)
&& fallback.toLowerCase() !== 'forbidden'
&& fallback !== localized
) {
return fallback;
}
return localized;
}
if (fallback) return fallback;
+82 -10
View File
@@ -81,6 +81,19 @@ export interface KbJob {
finished_at?: string | null;
}
export interface KbQueuedJobResponse extends KbJob {
accepted?: boolean;
queue_result?: string;
}
export interface KbUploadVersionResponse {
accepted?: boolean;
message?: string;
queue_result?: string;
version: KbDocumentVersionItem;
clean_job?: KbJob | null;
}
export interface KbDifySettings {
DIFY_API_BASE: string;
DIFY_API_KEY: string;
@@ -339,16 +352,16 @@ export const updateKbDocumentMarkdown = async (
export const uploadKbDocumentVersion = async (
documentId: number,
file: File
): Promise<{ ok: boolean; error?: string; version?: KbDocumentVersionItem; status?: number }> => {
): Promise<{ ok: boolean; error?: string; version?: KbDocumentVersionItem; clean_job?: KbJob | null; message?: string; status?: number }> => {
try {
const formData = new FormData();
formData.append('file', file);
const version = await requestJson<KbDocumentVersionItem>(`/api/kb/documents/${documentId}/upload`, {
const payload = await requestJson<KbUploadVersionResponse>(`/api/kb/documents/${documentId}/upload`, {
method: 'POST',
...auth(),
body: formData,
});
return { ok: true, version };
return { ok: true, version: payload.version, clean_job: payload.clean_job, message: payload.message };
} catch (e) {
const err = e as BusinessError;
if (err.status === 413) {
@@ -362,9 +375,28 @@ export const uploadKbDocumentVersion = async (
}
};
export const submitKbDocumentClean = async (
documentId: number
): Promise<{ ok: boolean; error?: string; job?: KbJob | null; message?: string; status?: number }> => {
try {
const job = await requestJson<KbQueuedJobResponse>(`/api/kb/documents/${documentId}/clean`, {
method: 'POST',
...auth(),
});
return { ok: true, job, message: job.message || undefined };
} catch (e) {
const err = e as BusinessError;
return { ok: false, error: kbErrorMessage(e, '提交清洗任务失败'), status: err.status };
}
};
export const createKbPathUploadJob = async (
groupId: number,
payload: { total_files: number; selected_paths: string[] }
payload: {
total_files: number;
selected_paths: string[];
files?: Array<{ relative_path: string; original_name: string }>;
}
): Promise<{ ok: boolean; error?: string; job?: KbJob; status?: number }> => {
try {
const job = await requestJson<KbJob>(`/api/kb/groups/${groupId}/path-upload-jobs`, {
@@ -383,7 +415,7 @@ export const uploadKbPathJobFile = async (
jobId: number | string,
file: File,
relativePath: string,
): Promise<{ ok: boolean; error?: string; job?: KbJob }> => {
): Promise<{ ok: boolean; error?: string; job?: KbJob; status?: number }> => {
try {
const formData = new FormData();
formData.append('file', file);
@@ -395,7 +427,31 @@ export const uploadKbPathJobFile = async (
});
return { ok: true, job };
} catch (e) {
return { ok: false, error: kbErrorMessage(e, '上传路径文件失败') };
const err = e as BusinessError;
if (err.status === 413) {
return {
ok: false,
error: '文件过大,超过当前上传限制,请联系管理员放宽限制后重试',
status: 413,
};
}
return { ok: false, error: kbErrorMessage(e, '上传路径文件失败'), status: err.status };
}
};
export const markKbPathJobFileFailed = async (
jobId: number | string,
payload: { relative_path: string; original_name?: string; error: string }
): Promise<{ ok: boolean; error?: string; job?: KbJob }> => {
try {
const job = await requestJson<KbJob>(`/api/kb/path-upload-jobs/${jobId}/files/fail`, {
method: 'POST',
...jsonAuth(),
body: JSON.stringify(payload),
});
return { ok: true, job };
} catch (e) {
return { ok: false, error: kbErrorMessage(e, '记录路径文件失败状态失败') };
}
};
@@ -403,7 +459,7 @@ export const finalizeKbPathUploadJob = async (
jobId: number | string,
): Promise<{ ok: boolean; error?: string; job?: KbJob }> => {
try {
const job = await requestJson<KbJob>(`/api/kb/path-upload-jobs/${jobId}/finalize`, {
const job = await requestJson<KbQueuedJobResponse>(`/api/kb/path-upload-jobs/${jobId}/finalize`, {
method: 'POST',
...auth(),
});
@@ -430,15 +486,31 @@ export const retryFailedKbPathUploadJob = async (
}
};
export const deleteKbPathJobFile = async (
jobId: number | string,
relativePath: string,
): Promise<{ ok: boolean; error?: string; job?: KbJob; document_deleted?: boolean }> => {
try {
const query = new URLSearchParams({ relative_path: relativePath });
const result = await requestJson<{ ok: boolean; job: KbJob; document_deleted?: boolean }>(
`/api/kb/path-upload-jobs/${jobId}/files?${query.toString()}`,
{ method: 'DELETE', ...auth() }
);
return { ok: true, job: result.job, document_deleted: result.document_deleted };
} catch (e) {
return { ok: false, error: kbErrorMessage(e, '删除路径上传文件失败') };
}
};
export const syncKbDocumentToDify = async (
documentId: number
): Promise<{ ok: boolean; error?: string; job?: KbJob; run_result?: string }> => {
): Promise<{ ok: boolean; error?: string; job?: KbQueuedJobResponse }> => {
try {
const job = await requestJson<KbJob & { run_result?: string }>(`/api/kb/documents/${documentId}/sync`, {
const job = await requestJson<KbQueuedJobResponse>(`/api/kb/documents/${documentId}/sync`, {
method: 'POST',
...auth(),
});
return { ok: true, job, run_result: job.run_result };
return { ok: true, job };
} catch (e) {
return { ok: false, error: kbErrorMessage(e, '同步到 Dify 失败') };
}
+17 -1
View File
@@ -14,6 +14,7 @@ import { marked } from 'marked';
import * as XLSX from 'xlsx';
import VueOfficeDocx from '@vue-office/docx';
import VueOfficeExcel from '@vue-office/excel';
import VueOfficePdf from '@vue-office/pdf';
import '@vue-office/docx/lib/index.css';
import '@vue-office/excel/lib/index.css';
@@ -32,7 +33,7 @@ interface ExcelPreviewData {
truncated: boolean;
}
type OfficeKind = 'docx' | 'excel' | null;
type OfficeKind = 'docx' | 'excel' | 'pdf' | null;
type PreviewMode = 'markdown' | 'image' | 'iframe' | 'sheet' | 'office';
const props = defineProps<{
@@ -290,6 +291,15 @@ const loadPdfContent = async (): Promise<'iframe' | 'office' | 'sheet'> => {
if (ext.value === 'pdf' || ['doc', 'ppt', 'pptx'].includes(ext.value)) fallbackType = 'application/pdf';
else if (ext.value === 'docx') fallbackType = 'application/vnd.openxmlformats-officedocument.wordprocessingml.document';
const effectiveBlob = blob.type ? blob : new Blob([blob], { type: fallbackType });
if (
['doc', 'ppt', 'pptx'].includes(ext.value)
&& effectiveBlob.type.toLowerCase().includes('pdf')
) {
officeSrc.value = effectiveBlob;
officeRenderKey.value += 1;
officeKind.value = 'pdf';
return 'office';
}
officeObjectUrl.value = URL.createObjectURL(effectiveBlob);
return 'iframe';
};
@@ -525,6 +535,12 @@ watch(
:src="officeSrc"
style="height: 100%; width: 100%;"
/>
<VueOfficePdf
v-else-if="officeKind === 'pdf'"
:key="`pdf-${officeRenderKey}`"
:src="officeSrc"
style="height: 100%; width: 100%;"
/>
</div>
<div v-else-if="resolvedMode === 'image'" class="dialog-preview-frame h-full flex items-center justify-center p-2">
<img :src="imageSrc" :alt="file.name" class="max-w-full max-h-full object-contain" />
+1 -1
View File
@@ -1,5 +1,5 @@
export const config = {
appTitle: 'AI工作台',
appTitle: '和信AI智能工作台',
auth: {
// Login mode switch:
// - 'casdoor': submit username/password to backend Casdoor password-login API.
@@ -37,6 +37,8 @@ const {
resetForm,
selectAgent,
submitAgent,
addSuggestedQuestion,
removeSuggestedQuestion,
deleteAgent,
openTestModal,
runAgentTest,
@@ -133,6 +135,66 @@ onMounted(() => {
:placeholder="t('admin.agent.fields.descPlaceholder')"
/>
</div>
<div class="col-span-1 md:col-span-2 space-y-3">
<div class="flex items-center justify-between gap-3">
<label class="text-xs font-bold text-muted uppercase tracking-wider">常见问题</label>
<button
type="button"
class="inline-flex items-center gap-1 rounded-lg border border-default px-3 py-1.5 text-xs font-medium text-secondary transition-colors hover:bg-surface-soft"
@click="addSuggestedQuestion"
>
<Plus class="h-4 w-4" />
添加问题
</button>
</div>
<div class="flex items-center gap-3 text-sm">
<label class="inline-flex items-center gap-2 text-secondary">
<input v-model="form.suggested_questions_style" type="radio" value="plain" class="accent-brand-600" />
<span>无样式</span>
</label>
<label class="inline-flex items-center gap-2 text-secondary">
<input v-model="form.suggested_questions_style" type="radio" value="styled" class="accent-brand-600" />
<span>有样式</span>
</label>
</div>
<div v-if="form.suggested_questions.length === 0" class="rounded-xl border border-dashed border-default px-4 py-5 text-sm text-muted">
暂未配置常见问题,点击“添加问题”后会同步到对应 Agent 的 Chat 欢迎页。
</div>
<div v-else class="space-y-3">
<div
v-for="(item, index) in form.suggested_questions"
:key="index"
class="rounded-2xl border border-default bg-surface-soft/50 p-4"
>
<div class="grid grid-cols-1 gap-3 md:grid-cols-[1fr_220px_auto]">
<input
v-model="item.question"
type="text"
class="w-full input-field"
placeholder="请输入常见问题,例如:查询我有多少假期?"
/>
<input
v-model="item.group"
type="text"
class="w-full input-field"
:disabled="form.suggested_questions_style !== 'styled'"
:placeholder="form.suggested_questions_style === 'styled' ? '可选:分组标题,例如:考勤与休假' : '无样式下无需分组'"
/>
<button
type="button"
class="inline-flex items-center justify-center rounded-xl border border-red-200 bg-red-50 px-3 py-2 text-red-600 transition-colors hover:bg-red-100"
@click="removeSuggestedQuestion(index)"
>
<Trash2 class="h-4 w-4" />
</button>
</div>
</div>
</div>
</div>
</div>
<div class="flex justify-end">
<button type="button" class="btn-primary btn-lg" @click="submitAgent">
@@ -18,9 +18,25 @@ import {
} from '@/api/admin';
import { useMessage } from '@/composables/useMessage';
import type { AdminUserRow } from '@/features/admin/types/admin.types';
import type { AgentFormState, AgentRow, AgentTestResult } from '@/features/admin/types/agent.types';
import type { AgentFormState, AgentRow, AgentSuggestedQuestionItem, AgentTestResult } from '@/features/admin/types/agent.types';
import { createEmptyAgentForm } from '@/features/admin/types/agent.types';
const normalizeSuggestedQuestions = (value: unknown): AgentSuggestedQuestionItem[] => {
if (!Array.isArray(value)) return [];
return value
.map((item) => {
if (typeof item === 'string') {
return { question: item.trim(), group: '' };
}
if (!item || typeof item !== 'object') return null;
const question = String((item as Record<string, unknown>).question || (item as Record<string, unknown>).text || '').trim();
const group = String((item as Record<string, unknown>).group || '').trim();
if (!question) return null;
return { question, group };
})
.filter((item): item is AgentSuggestedQuestionItem => !!item);
};
export function useAgentsAdmin() {
const { t } = useI18n();
const msg = useMessage();
@@ -90,6 +106,8 @@ export function useAgentsAdmin() {
dify_app_type: agent.extra_config?.dify_app_type === 'workflow' ? 'workflow' : 'chatflow',
api_base_url: agent.api_base_url || '',
iframe_url: String(agent.extra_config?.iframe_url || ''),
suggested_questions_style: agent.extra_config?.suggested_questions_style === 'styled' ? 'styled' : 'plain',
suggested_questions: normalizeSuggestedQuestions(agent.extra_config?.suggested_questions),
is_active: agent.is_active,
};
isEditing.value = true;
@@ -132,6 +150,13 @@ export function useAgentsAdmin() {
if (form.value.type === 'api') {
extra_config.dify_app_type = form.value.dify_app_type === 'workflow' ? 'workflow' : 'chatflow';
}
extra_config.suggested_questions_style = form.value.suggested_questions_style === 'styled' ? 'styled' : 'plain';
extra_config.suggested_questions = form.value.suggested_questions
.map((item) => ({
question: String(item.question || '').trim(),
group: String(item.group || '').trim(),
}))
.filter((item) => item.question);
try {
const editingId = isEditing.value ? Number(form.value.id) : null;
@@ -149,6 +174,7 @@ export function useAgentsAdmin() {
payload.dify_api_key = form.value.dify_api_key;
}
await updateAdminAgent(form.value.id, payload);
msg.success('应用更新成功');
} else {
await createAdminAgent({
name: form.value.name,
@@ -159,6 +185,7 @@ export function useAgentsAdmin() {
api_base_url: form.value.api_base_url,
extra_config,
});
msg.success('应用创建成功');
}
await loadAgents();
@@ -176,6 +203,14 @@ export function useAgentsAdmin() {
}
};
const addSuggestedQuestion = (): void => {
form.value.suggested_questions.push({ question: '', group: '' });
};
const removeSuggestedQuestion = (index: number): void => {
form.value.suggested_questions.splice(index, 1);
};
const deleteAgent = async (id: number): Promise<void> => {
openDeleteConfirm(t('admin.agent.confirmDelete'), async () => {
try {
@@ -294,6 +329,8 @@ export function useAgentsAdmin() {
resetForm,
selectAgent,
submitAgent,
addSuggestedQuestion,
removeSuggestedQuestion,
deleteAgent,
openTestModal,
runAgentTest,
@@ -19,6 +19,11 @@ export interface AgentRow {
iframe_url?: string;
}
export interface AgentSuggestedQuestionItem {
question: string;
group: string;
}
export interface AgentTestResult {
success: boolean;
request_url: string;
@@ -38,6 +43,8 @@ export interface AgentFormState {
dify_app_type: 'chatflow' | 'workflow';
api_base_url: string;
iframe_url: string;
suggested_questions_style: 'plain' | 'styled';
suggested_questions: AgentSuggestedQuestionItem[];
is_active: boolean;
}
@@ -50,5 +57,7 @@ export const createEmptyAgentForm = (): AgentFormState => ({
dify_app_type: 'chatflow',
api_base_url: '',
iframe_url: '',
suggested_questions_style: 'plain',
suggested_questions: [],
is_active: true,
});
+4
View File
@@ -157,6 +157,7 @@ const messages = {
codes: {
AUTH_UNAUTHORIZED: 'Please log in first.',
AUTH_INCORRECT_PASSWORD: 'Incorrect password',
AUTH_INCORRECT_CURRENT_PASSWORD: 'Incorrect current password',
AUTH_USER_NOT_FOUND: 'User not found',
AUTH_ACCOUNT_DISABLED: 'Account is disabled',
AUTH_FORBIDDEN: 'You do not have permission to perform this action.',
@@ -1717,6 +1718,7 @@ const messages = {
codes: {
AUTH_UNAUTHORIZED: '请先登录。',
AUTH_INCORRECT_PASSWORD: '密码错误',
AUTH_INCORRECT_CURRENT_PASSWORD: '当前密码不正确',
AUTH_USER_NOT_FOUND: '用户不存在',
AUTH_ACCOUNT_DISABLED: '账号已禁用',
AUTH_FORBIDDEN: '你没有权限执行该操作。',
@@ -3242,6 +3244,7 @@ const messages = {
codes: {
AUTH_UNAUTHORIZED: '請先登入。',
AUTH_INCORRECT_PASSWORD: '密碼錯誤',
AUTH_INCORRECT_CURRENT_PASSWORD: '當前密碼不正確',
AUTH_USER_NOT_FOUND: '用戶不存在',
AUTH_ACCOUNT_DISABLED: '帳號已禁用',
AUTH_FORBIDDEN: '你沒有權限執行此操作。',
@@ -4577,6 +4580,7 @@ const messages = {
codes: {
AUTH_UNAUTHORIZED: 'กรุณาเข้าสู่ระบบก่อน',
AUTH_INCORRECT_PASSWORD: 'รหัสผ่านไม่ถูกต้อง',
AUTH_INCORRECT_CURRENT_PASSWORD: 'รหัสผ่านปัจจุบันไม่ถูกต้อง',
AUTH_USER_NOT_FOUND: 'ไม่พบผู้ใช้',
AUTH_ACCOUNT_DISABLED: 'บัญชีถูกปิดใช้งาน',
AUTH_FORBIDDEN: 'คุณไม่มีสิทธิ์ดำเนินการนี้',
+217 -65
View File
@@ -88,13 +88,17 @@ const currentUser = ref(getStoredAuthUser());
const showUserDropdown = ref(false);
const userMenuRef = ref<HTMLElement | null>(null);
const selectedKb = ref('企业知识库');
const DEFAULT_KB = '企业知识库';
const ERP_KB = 'ERP知识库';
const ERP_KB_ENABLED_AGENT_NAMES = new Set(['固资管理']);
const selectedKb = ref(DEFAULT_KB);
const showKbDropdown = ref(false);
const kbMenuRef = ref<HTMLElement | null>(null);
const kbOptions = ['企业知识库', 'ERP知识库'];
const kbOptions = [DEFAULT_KB, ERP_KB];
const getKbLabel = (kb: string) => {
if (kb === '企业知识库') return t('chat.kb.enterprise');
if (kb === 'ERP知识库') return t('chat.kb.erp');
if (kb === DEFAULT_KB) return t('chat.kb.enterprise');
if (kb === ERP_KB) return t('chat.kb.erp');
return kb;
};
const chatScrollContainer = ref<HTMLElement | null>(null);
@@ -682,6 +686,27 @@ const shouldShowThinkingBubble = computed(() => {
const filePreviewVisible = ref(false);
const previewFile = ref<{ name: string; url: string; actualExt?: string } | null>(null);
const getSourcePreviewExt = (file: { name?: string; url?: string; actualExt?: string }) => {
const actual = String(file?.actualExt || '').trim().toLowerCase();
if (actual) return actual;
const byName = getUrlExt(file?.name || '');
if (byName) return byName;
return getUrlExt(file?.url || '');
};
const isWeComMobileWebView = () => {
if (typeof navigator === 'undefined') return false;
const ua = navigator.userAgent || '';
return /wxwork/i.test(ua) && /mobile/i.test(ua);
};
const shouldBypassEmbeddedPreview = (file: { name?: string; url?: string; actualExt?: string }) => {
const ext = getSourcePreviewExt(file);
if (!isMobile.value || !isWeComMobileWebView()) return false;
if (!/^https?:\/\//i.test(file?.url || '')) return false;
return ['pdf', 'xls', 'xlsx'].includes(ext);
};
const resolveSourceLink = async (file: SourceFileLink): Promise<{ name: string; url: string; actualExt?: string }> => {
if (file.datasetId && file.remoteDocumentId) {
const data = await resolveChatSourceFile({
@@ -715,6 +740,10 @@ const resolveSourceLink = async (file: SourceFileLink): Promise<{ name: string;
const openPreview = async (file: SourceFileLink) => {
try {
const resolvedFile = await resolveSourceLink(file);
if (shouldBypassEmbeddedPreview(resolvedFile)) {
window.location.href = resolvedFile.url;
return;
}
previewFile.value = resolvedFile;
filePreviewVisible.value = true;
} catch (error: any) {
@@ -784,6 +813,125 @@ watch(isThinking, (thinking) => {
const currentAgent = ref<any>(null);
const userAgents = ref<Array<{ id: number; name: string; description: string; icon_url?: string; dify_app_type?: 'chatflow' | 'workflow' }>>([]);
const showGeneralFeedbackDialog = ref(false);
const LEAVE_FEATURE_AGENT_NAMES = new Set(['通用入口', '人事规章']);
const canUseLeaveFeature = computed(() => LEAVE_FEATURE_AGENT_NAMES.has(String(currentAgent.value?.name || '').trim()));
type AgentSuggestedQuestionItem = {
question: string;
group: string;
};
const DEFAULT_AGENT_DESCRIPTIONS: Record<string, string> = {
人事规章: '我是你的7x24小时专属HR政策助手。无需手动检索文档,只需用日常说话的方式提问,我能从公司最新、最全的规章制度中,为你精准提取并总结答案。',
通用入口: '我是你的7x24小时专属AI数字人。无需手动检索文档,只需用日常说话的方式提问,我能从公司最新、最全的人事规章制度中,为你精准提取并总结答案。',
};
const DEFAULT_AGENT_SUGGESTED_QUESTIONS: Record<string, { style: 'plain' | 'styled'; questions: AgentSuggestedQuestionItem[] }> = {
人事规章: {
style: 'styled',
questions: [
{ question: '查询我有多少假期?', group: '考勤与休假' },
{ question: '如何进行请假?', group: '考勤与休假' },
{ question: '查公司法定节假日?', group: '考勤与休假' },
{ question: '新员工入职须知', group: '规章与日常' },
{ question: '怎么开具在职证明?', group: '规章与日常' },
{ question: '查公司薪酬及福利待遇怎么样?', group: '规章与日常' },
],
},
通用入口: {
style: 'plain',
questions: [
{ question: '新员工入职须知', group: '' },
{ question: '查询我有多少假期?', group: '' },
{ question: '如何进行请假?', group: '' },
{ question: '查公司法定节假日?', group: '' },
{ question: '查公司薪酬及福利待遇怎么样?', group: '' },
],
},
};
const normalizeAgentSuggestedQuestions = (value: unknown): AgentSuggestedQuestionItem[] => {
if (!Array.isArray(value)) return [];
return value
.map((item) => {
if (typeof item === 'string') {
const question = item.trim();
return question ? { question, group: '' } : null;
}
if (!item || typeof item !== 'object') return null;
const record = item as Record<string, unknown>;
const question = String(record.question || record.text || '').trim();
const group = String(record.group || '').trim();
return question ? { question, group } : null;
})
.filter((item): item is AgentSuggestedQuestionItem => !!item);
};
const currentAgentName = computed(() => String(currentAgent.value?.name || '').trim());
const canSelectErpKnowledgeBase = computed(() => ERP_KB_ENABLED_AGENT_NAMES.has(currentAgentName.value));
const availableKbOptions = computed(() => (
canSelectErpKnowledgeBase.value
? kbOptions
: kbOptions.filter((option) => option !== ERP_KB)
));
const kbDropdownDisabled = computed(() => availableKbOptions.value.length <= 1);
const toggleKbDropdown = () => {
if (kbDropdownDisabled.value) {
showKbDropdown.value = false;
return;
}
showKbDropdown.value = !showKbDropdown.value;
};
const selectKb = (option: string) => {
if (!availableKbOptions.value.includes(option)) return;
selectedKb.value = option;
showKbDropdown.value = false;
};
watch(canSelectErpKnowledgeBase, (allowed) => {
if (!allowed && selectedKb.value === ERP_KB) {
selectedKb.value = DEFAULT_KB;
}
if (!allowed) {
showKbDropdown.value = false;
}
}, { immediate: true });
const agentDescription = computed(() => {
const text = String(currentAgent.value?.description || '').trim();
return text || DEFAULT_AGENT_DESCRIPTIONS[currentAgentName.value] || '';
});
const suggestedQuestionsStyle = computed<'plain' | 'styled'>(() => {
const style = String(currentAgent.value?.extra_config?.suggested_questions_style || '').trim().toLowerCase();
if (style === 'styled') return 'styled';
if (style === 'plain') return 'plain';
return DEFAULT_AGENT_SUGGESTED_QUESTIONS[currentAgentName.value]?.style || 'plain';
});
const agentSuggestedQuestions = computed<AgentSuggestedQuestionItem[]>(() => {
const configured = normalizeAgentSuggestedQuestions(
currentAgent.value?.suggested_questions ?? currentAgent.value?.extra_config?.suggested_questions,
);
if (configured.length > 0) return configured;
return DEFAULT_AGENT_SUGGESTED_QUESTIONS[currentAgentName.value]?.questions || [];
});
const styledSuggestedQuestionSections = computed(() => {
const groups = new Map<string, AgentSuggestedQuestionItem[]>();
for (const item of agentSuggestedQuestions.value) {
const groupName = String(item.group || '').trim() || '常见问题';
if (!groups.has(groupName)) {
groups.set(groupName, []);
}
groups.get(groupName)?.push(item);
}
const iconTypes: Array<'calendar' | 'building'> = ['calendar', 'building'];
return Array.from(groups.entries()).map(([title, questions], index) => ({
title,
questions,
iconType: iconTypes[index % iconTypes.length],
}));
});
const agentGuides = ref<any[]>([]);
const showGuideModal = ref(false);
@@ -800,13 +948,13 @@ const loadAgentGuides = async () => {
}
};
const showGuideSidebar = ref(false);
const showGuideSidebar = ref(true);
const openGuideModal = () => {
if (agentGuides.value.length > 0) {
activeGuideId.value = agentGuides.value[0].id;
showGuideModal.value = true;
showGuideSidebar.value = false; // 默认收起
showGuideSidebar.value = true; // 默认展开
}
};
const showDeleteConfirmDialog = ref(false);
@@ -1918,6 +2066,10 @@ const handleChatMarkdownClick = (event: MouseEvent) => {
const action = actionElement.getAttribute('data-leave-action');
if (action !== 'start-leave-flow' || isThinking.value) return;
event.preventDefault();
if (!canUseLeaveFeature.value) {
msg.warning('请在“通用入口”或“人事规章”入口使用请假功能');
return;
}
startLocalLeaveFlow('我要请假');
};
@@ -3356,7 +3508,7 @@ const handleSend = async (textOrEvent?: string | Event) => {
}
if (!trimmed || isThinking.value || isUploadingAttachments.value) return;
if (isStrongLeaveIntent(content)) {
if (canUseLeaveFeature.value && isStrongLeaveIntent(content)) {
startLocalLeaveFlow(content);
return;
}
@@ -4056,20 +4208,17 @@ const showChatRating = ref(false);
class="flex items-center gap-1.5 px-3 py-1.5 text-xs font-bold text-brand-700 bg-brand-100 border border-brand-300 rounded-lg hover:bg-brand-200 hover:border-brand-400 transition-all shadow-sm"
>
<BookOpen class="w-4 h-4" />
新手指南
学习之窗
</button>
</div>
<span v-if="currentAgent?.name === '人事规章'" class="block text-[11px] text-muted mt-1 truncate cursor-help">
我是你的7x24小时专属HR政策助手。无需手动检索文档,只需用日常说话的方式提问,我能从公司最新、最全的规章制度中,为你精准提取并总结答案。
</span>
<span v-else-if="currentAgent?.name === '通用入口'" class="block text-[11px] text-muted mt-1 truncate cursor-help">
我是你的7x24小时专属AI数字人。无需手动检索文档,只需用日常说话的方式提问,我能从公司最新、最全的人事规章制度中,为你精准提取并总结答案。
<span v-if="agentDescription" class="block text-[11px] text-muted mt-1 truncate cursor-help">
{{ agentDescription }}
</span>
<!-- 气泡提示 -->
<div v-if="currentAgent?.name === '人事规章' || currentAgent?.name === '通用入口'" class="absolute left-0 top-[calc(100%+0.25rem)] w-[20rem] p-3 bg-surface border border-default rounded-xl opacity-0 invisible group-hover:opacity-100 group-hover:visible transition-all duration-200 z-[100] shadow-xl pointer-events-none">
<div v-if="agentDescription" class="absolute left-0 top-[calc(100%+0.25rem)] w-[20rem] p-3 bg-surface border border-default rounded-xl opacity-0 invisible group-hover:opacity-100 group-hover:visible transition-all duration-200 z-[100] shadow-xl pointer-events-none">
<div class="leading-relaxed text-[11px] text-secondary">
{{ currentAgent?.name === '人事规章' ? '我是你的7x24小时专属HR政策助手。无需手动检索文档,只需用日常说话的方式提问,我能从公司最新、最全的规章制度中,为你精准提取并总结答案。' : '我是你的7x24小时专属AI数字人。无需手动检索文档,只需用日常说话的方式提问,我能从公司最新、最全的人事规章制度中,为你精准提取并总结答案。' }}
{{ agentDescription }}
</div>
</div>
</div>
@@ -4143,8 +4292,8 @@ const showChatRating = ref(false);
<!-- Bottom Icons -->
<div class="flex items-center justify-between text-muted relative" ref="userMenuRef">
<button @click="showUserDropdown = !showUserDropdown" class="flex h-8 w-8 items-center justify-center rounded-full bg-brand-600 text-sm font-bold text-white shadow-sm shadow-brand-500/20 hover:bg-brand-700 transition-colors">
{{ (currentUser?.username || 'I').charAt(0).toUpperCase() }}
<button @click="showUserDropdown = !showUserDropdown" class="flex h-10 min-w-[2.5rem] items-center justify-center rounded-full bg-brand-600 px-3 text-sm font-bold text-white shadow-sm shadow-brand-500/20 transition-colors hover:bg-brand-700">
退出
</button>
<!-- User Dropdown Menu -->
@@ -4194,7 +4343,7 @@ const showChatRating = ref(false);
class="flex items-center gap-1.5 px-3 py-1.5 text-xs font-bold text-brand-700 bg-brand-100 border border-brand-300 rounded-lg hover:bg-brand-200 hover:border-brand-400 transition-all shadow-sm ml-1"
>
<BookOpen class="w-4 h-4" />
新手指南
学习之窗
</button>
</div>
<div class="flex items-center gap-1">
@@ -4248,61 +4397,64 @@ const showChatRating = ref(false);
<div
:class="messages.length === 0 ? 'h-full' : 'flex min-h-full flex-col justify-end'"
>
<div v-if="messages.length === 0" class="flex h-full flex-col items-center justify-center py-2 md:pb-16 w-full px-4">
<template v-if="currentAgent?.name === '人事规章'">
<div class="mb-6 flex h-16 w-16 items-center justify-center rounded-2xl bg-gradient-to-br from-brand-500 via-brand-600 to-sky-600 text-2xl font-bold text-white shadow-lg shadow-brand-500/20">
HR
<div v-if="messages.length === 0" class="flex h-full min-h-0 w-full flex-col items-center px-4 pt-2 pb-2 md:pb-3">
<template v-if="suggestedQuestionsStyle === 'styled' && styledSuggestedQuestionSections.length > 0">
<div class="mb-6 mt-2 flex h-16 w-16 shrink-0 items-center justify-center rounded-2xl bg-gradient-to-br from-brand-500 via-brand-600 to-sky-600 text-2xl font-bold text-white shadow-lg shadow-brand-500/20">
{{ currentAgent?.name === '人事规章' ? 'HR' : 'AI' }}
</div>
<h2 class="text-center text-xl font-bold text-primary md:text-2xl mb-8">你好,我是人事规章 AI 助手</h2>
<div class="grid grid-cols-1 md:grid-cols-2 gap-4 w-full max-w-4xl mx-auto">
<!-- 考勤与休假 -->
<div class="bg-surface border border-default rounded-2xl p-5 hover:border-brand-300 transition-colors shadow-sm">
<div class="flex items-center gap-2 mb-3">
<div class="p-1.5 bg-brand-50 rounded-lg text-brand-600">
<CalendarDays class="h-4 w-4" />
</div>
<h3 class="font-semibold text-secondary">考勤与休假</h3>
</div>
<div class="space-y-2">
<button @click="handleSend('查询我有多少假期?')" class="w-full text-left text-xs md:text-sm text-secondary hover:text-brand-600 bg-surface-soft hover:bg-brand-50 px-3 py-2 rounded-lg transition-colors truncate">"查询我有多少假期?"</button>
<button @click="handleSend('如何进行请假?')" class="w-full text-left text-xs md:text-sm text-secondary hover:text-brand-600 bg-surface-soft hover:bg-brand-50 px-3 py-2 rounded-lg transition-colors truncate">"如何进行请假?"</button>
<button @click="handleSend('查公司法定节假日?')" class="w-full text-left text-xs md:text-sm text-secondary hover:text-brand-600 bg-surface-soft hover:bg-brand-50 px-3 py-2 rounded-lg transition-colors truncate">"查公司法定节假日?"</button>
</div>
</div>
<h2 class="mb-6 shrink-0 text-center text-xl font-bold text-primary md:text-2xl">
{{ currentAgent?.name === '人事规章' ? '你好,我是人事规章 AI 助手' : t('chat.welcomeTitle') }}
</h2>
<!-- 规章与日常 -->
<div class="bg-surface border border-default rounded-2xl p-5 hover:border-brand-300 transition-colors shadow-sm">
<div class="w-full flex-1 min-h-0 overflow-y-auto pb-2">
<div class="mx-auto grid w-full max-w-4xl grid-cols-1 gap-4 md:grid-cols-2">
<div
v-for="(section, sectionIndex) in styledSuggestedQuestionSections"
:key="`${section.title}-${sectionIndex}`"
class="w-full bg-surface border border-default rounded-2xl p-5 hover:border-brand-300 transition-colors shadow-sm"
>
<div class="flex items-center gap-2 mb-3">
<div class="p-1.5 bg-brand-50 rounded-lg text-brand-600">
<Building class="h-4 w-4" />
<CalendarDays v-if="section.iconType === 'calendar'" class="h-4 w-4" />
<Building v-else class="h-4 w-4" />
</div>
<h3 class="font-semibold text-secondary">规章与日常</h3>
<h3 class="font-semibold text-secondary">{{ section.title }}</h3>
</div>
<div class="space-y-2">
<button @click="handleSend('新员工入职须知')" class="w-full text-left text-xs md:text-sm text-secondary hover:text-brand-600 bg-surface-soft hover:bg-brand-50 px-3 py-2 rounded-lg transition-colors truncate">"新员工入职须知"</button>
<button @click="handleSend('怎么开具在职证明?')" class="w-full text-left text-xs md:text-sm text-secondary hover:text-brand-600 bg-surface-soft hover:bg-brand-50 px-3 py-2 rounded-lg transition-colors truncate">"怎么开具在职证明?"</button>
<button @click="handleSend('查公司薪酬及福利待遇怎么样?')" class="w-full text-left text-xs md:text-sm text-secondary hover:text-brand-600 bg-surface-soft hover:bg-brand-50 px-3 py-2 rounded-lg transition-colors truncate">"查公司薪酬及福利待遇怎么样?"</button>
<button
v-for="(item, questionIndex) in section.questions"
:key="`${section.title}-${questionIndex}`"
@click="handleSend(item.question)"
class="w-full text-left text-xs md:text-sm text-secondary hover:text-brand-600 bg-surface-soft hover:bg-brand-50 px-3 py-2 rounded-lg transition-colors truncate"
>
"{{ item.question }}"
</button>
</div>
</div>
</div>
</div>
</template>
<template v-else-if="currentAgent?.name === '通用入口'">
<div class="mb-6 flex h-16 w-16 items-center justify-center rounded-2xl bg-gradient-to-br from-brand-500 via-brand-600 to-sky-600 text-2xl font-bold text-white shadow-lg shadow-brand-500/20">
<template v-else-if="agentSuggestedQuestions.length > 0">
<div class="mb-6 mt-2 flex h-16 w-16 shrink-0 items-center justify-center rounded-2xl bg-gradient-to-br from-brand-500 via-brand-600 to-sky-600 text-2xl font-bold text-white shadow-lg shadow-brand-500/20">
AI
</div>
<h2 class="text-center text-xl font-medium text-primary md:text-2xl mb-8">{{ $t('chat.welcomeTitle') }}</h2>
<div class="flex flex-wrap justify-center gap-3 w-full max-w-3xl mx-auto mt-2">
<button @click="handleSend('新员工入职须知')" class="px-4 py-2 text-sm text-secondary bg-surface border border-default rounded-full hover:border-brand-300 hover:text-brand-600 hover:bg-brand-50 transition-all shadow-sm">"新员工入职须知"</button>
<button @click="handleSend('查询我有多少假期?')" class="px-4 py-2 text-sm text-secondary bg-surface border border-default rounded-full hover:border-brand-300 hover:text-brand-600 hover:bg-brand-50 transition-all shadow-sm">"查询我有多少假期?"</button>
<button @click="handleSend('如何进行请假?')" class="px-4 py-2 text-sm text-secondary bg-surface border border-default rounded-full hover:border-brand-300 hover:text-brand-600 hover:bg-brand-50 transition-all shadow-sm">"如何进行请假?"</button>
<button @click="handleSend('查公司法定节假日?')" class="px-4 py-2 text-sm text-secondary bg-surface border border-default rounded-full hover:border-brand-300 hover:text-brand-600 hover:bg-brand-50 transition-all shadow-sm">"查公司法定节假日?"</button>
<button @click="handleSend('查公司薪酬及福利待遇怎么样?')" class="px-4 py-2 text-sm text-secondary bg-surface border border-default rounded-full hover:border-brand-300 hover:text-brand-600 hover:bg-brand-50 transition-all shadow-sm">"查公司薪酬及福利待遇怎么样?"</button>
<h2 class="mb-6 shrink-0 text-center text-xl font-medium text-primary md:text-2xl">{{ $t('chat.welcomeTitle') }}</h2>
<div class="w-full flex-1 min-h-0 overflow-y-auto pb-2">
<div class="flex flex-wrap justify-center gap-3 w-full max-w-3xl mx-auto mt-2">
<button
v-for="(item, index) in agentSuggestedQuestions"
:key="`${item.question}-${index}`"
@click="handleSend(item.question)"
class="px-4 py-2 text-sm text-secondary bg-surface border border-default rounded-full hover:border-brand-300 hover:text-brand-600 hover:bg-brand-50 transition-all shadow-sm"
>
"{{ item.question }}"
</button>
</div>
</div>
</template>
<template v-else>
<div class="mb-6 flex h-16 w-16 items-center justify-center rounded-2xl bg-gradient-to-br from-brand-500 via-brand-600 to-sky-600 text-2xl font-bold text-white shadow-lg shadow-brand-500/20">
<div class="mb-6 mt-2 flex h-16 w-16 items-center justify-center rounded-2xl bg-gradient-to-br from-brand-500 via-brand-600 to-sky-600 text-2xl font-bold text-white shadow-lg shadow-brand-500/20">
AI
</div>
<h2 class="text-center text-xl font-medium text-primary md:text-2xl">{{ $t('chat.welcomeTitle') }}</h2>
@@ -4943,20 +5095,21 @@ const showChatRating = ref(false);
</div>
<div class="relative" ref="kbMenuRef">
<button
@click="showKbDropdown = !showKbDropdown"
class="flex items-center gap-1 rounded-lg border border-default px-3 py-1.5 text-xs font-medium text-secondary transition-colors hover:bg-surface-soft"
@click="toggleKbDropdown"
:disabled="kbDropdownDisabled"
class="flex items-center gap-1 rounded-lg border border-default px-3 py-1.5 text-xs font-medium text-secondary transition-colors hover:bg-surface-soft disabled:cursor-not-allowed disabled:opacity-60"
>
<Database class="h-3.5 w-3.5 text-brand-500" />
{{ getKbLabel(selectedKb) }} <ChevronDown class="h-3 w-3" />
</button>
<div
v-if="showKbDropdown"
v-if="showKbDropdown && !kbDropdownDisabled"
class="absolute bottom-full left-0 mb-2 w-36 overflow-hidden rounded-xl border border-subtle bg-surface py-1 shadow-xl animate-fade-in"
>
<button
v-for="option in kbOptions"
v-for="option in availableKbOptions"
:key="option"
@click="selectedKb = option; showKbDropdown = false"
@click="selectKb(option)"
class="flex w-full items-center justify-between px-3 py-2 text-xs text-secondary transition-colors hover:bg-surface-soft"
:class="{ 'font-bold text-brand-700': selectedKb === option }"
>
@@ -5231,13 +5384,13 @@ const showChatRating = ref(false);
/>
<Teleport to="body">
<!-- 新手指南 Modal -->
<!-- 学习之窗 Modal -->
<div v-if="showGuideModal" class="fixed inset-0 z-[9999] flex items-center justify-center p-4 bg-black/50 backdrop-blur-sm">
<div class="bg-surface rounded-2xl shadow-xl w-full max-w-4xl overflow-hidden flex flex-col h-[85vh]">
<div class="px-6 py-4 border-b border-default flex justify-between items-center bg-surface shrink-0">
<h3 class="text-lg font-bold text-primary flex items-center gap-2">
<BookOpen class="w-5 h-5 text-brand-600" />
{{ currentAgent?.name }} - 新手指南
{{ currentAgent?.name }} - 学习之窗
</h3>
<div class="flex items-center gap-3">
<button @click="showGuideSidebar = !showGuideSidebar" class="flex items-center gap-1.5 px-3 py-1.5 text-sm font-medium text-brand-600 hover:text-brand-700 hover:bg-brand-50 rounded-lg transition-colors border border-transparent hover:border-brand-100">
@@ -5279,7 +5432,6 @@ const showChatRating = ref(false);
:key="'video-' + activeGuide.id"
:src="activeGuide.file_url || activeGuide.file_path"
controls
autoplay
class="w-full h-full object-contain bg-black"
></video>
<iframe
File diff suppressed because it is too large. Load diff
+26 -4
View File
@@ -242,6 +242,8 @@ const draggedSectionIndex = ref<number | null>(null);
// Computed
const isLoggedIn = computed(() => !!currentUser.value && currentUser.value.role !== 'guest');
const hasKnowledgeBaseAccess = computed(() => String(currentUser.value?.username || '').trim().toLowerCase() === 'admin');
const KB_ACCESS_DENIED_MESSAGE = '暂无权限,请登录admin账号操作知识库!';
const favoriteAgents = computed(() => {
return agents.value.filter(a => favoriteAgentIds.value.includes(a.id));
@@ -751,8 +753,9 @@ const isProfileLoading = ref(false);
const isProfileSaving = ref(false);
const isProfileEditing = ref(false);
const showPasswordModal = ref(false);
// TODO(casdoor): set true when Casdoor change-password is ready
const CHANGE_PASSWORD_ENABLED = false;
const CHANGE_PASSWORD_ENABLED = true;
const handleChangePasswordClick = () => {
if (!CHANGE_PASSWORD_ENABLED) {
@@ -979,7 +982,15 @@ const navigateToApplications = () => openWorkspaceSection('favorites', 'applicat
const navigateToUpdates = () => openWorkspaceSection('announcements', 'updates');
const showKnowledgeBaseAccessDenied = () => {
msg.warning(KB_ACCESS_DENIED_MESSAGE);
};
const navigateToKnowledgeBase = () => {
if (!hasKnowledgeBaseAccess.value) {
showKnowledgeBaseAccessDenied();
return;
}
activeSidebarItem.value = 'knowledge_base';
};
@@ -1347,7 +1358,12 @@ onMounted(async () => {
const viewParam = route.query.view as string;
const validViews: string[] = ['profile', 'applications', 'feedback', 'updates', 'knowledge_base', 'schedule_runs', 'shipping_notice', 'history'];
if (viewParam && validViews.includes(viewParam)) {
activeSidebarItem.value = viewParam as typeof activeSidebarItem.value;
if (viewParam === 'knowledge_base' && !hasKnowledgeBaseAccess.value) {
showKnowledgeBaseAccessDenied();
activeSidebarItem.value = 'applications';
} else {
activeSidebarItem.value = viewParam as typeof activeSidebarItem.value;
}
if (viewParam === 'profile' && !profileUser.value.id) {
await fetchProfile();
}
@@ -1361,6 +1377,12 @@ onMounted(async () => {
}
});
watch(hasKnowledgeBaseAccess, (allowed) => {
if (!allowed && activeSidebarItem.value === 'knowledge_base') {
activeSidebarItem.value = 'applications';
}
});
onBeforeUnmount(() => {
window.removeEventListener('hxops:logout', onAuthLogout);
});
@@ -1524,7 +1546,7 @@ onBeforeUnmount(() => {
<div v-else>
<header v-if="isMobile" class="sticky top-0 z-30 flex items-center justify-between border-b border-default bg-surface px-4 py-2.5">
<div class="flex items-center gap-2">
<button @click="navigateToGeneralChat" class="flex h-7 w-7 items-center justify-center rounded-lg bg-gradient-to-br from-brand-500 via-brand-600 to-purple-600 text-xs font-bold text-white shadow-sm shadow-brand-500/20" :title="$t('workspace.nav.backToChat')">AI</button>
<button @click="navigateToGeneralChat" class="flex h-7 w-7 items-center justify-center rounded-lg bg-gradient-to-br from-brand-500 via-brand-600 to-purple-600 text-xs font-bold text-white shadow-sm shadow-brand-500/20" :title="$t('workspace.nav.backToChat')">返</button>
<span class="text-sm font-semibold text-primary">{{ mobileTabTitle }}</span>
</div>
</header>
@@ -2323,7 +2345,7 @@ onBeforeUnmount(() => {
</div>
</div>
<!-- Change password modal: re-enable via CHANGE_PASSWORD_ENABLED when Casdoor is ready -->
<!-- Change password modal -->
<div
v-if="CHANGE_PASSWORD_ENABLED && showPasswordModal"
class="dialog-overlay z-50 items-center"