Files
syops/frontend/src/views/WorkspaceView.vue
T
hugo 63ea9d7ed7 1.修复问题同时打开多个标签页,退出登录,其它几个标签页并没有退出登录
2.点击智能体时,若当前已经打开智能体标签,则不会再打开新标签页
2026-05-26 20:58:11 +08:00

2400 lines
114 KiB
Vue
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<script setup lang="ts">
/**
* WorkspaceView.vue
* 文件用途:用户工作台,支持自定义布局、收藏、嵌入 Agent
* 引用文件:vue, vue-router, lucide-vue-next, 后端 /api/user 接口
*/
import { ref, onMounted, onBeforeUnmount, computed, watch, nextTick } from 'vue';
import { useRouter, useRoute } from 'vue-router';
import { useI18n } from 'vue-i18n';
import { config } from '../config';
import { useTheme } from '../composables/useTheme';
import type { ThemePreference } from '../composables/useTheme';
import ThemeToggleButton from '../components/ThemeToggleButton.vue';
import DeleteConfirmDialog from '../components/DeleteConfirmDialog.vue';
import GeneralFeedbackDialog from '../components/GeneralFeedbackDialog.vue';
import { useMessage } from '../composables/useMessage';
import { useIsMobile } from '../composables/useIsMobile';
import loginBg from '../assets/login-bg.png';
import {
buildWecomLoginDialogContent,
formatWecomFieldLabel,
normalizeWecomMatchRules,
type WecomLoginDialogContent,
type WecomMatchField,
} from '../utils/wecom';
import { getAuthHeaders, getStoredAuthUser, saveAuthUser, logoutAuth } from '../utils/auth';
import { getLastChatAgentId } from '../utils/lastChatAgent';
import { openAgentChatTab } from '../utils/agentTabs';
import {
Settings,
LayoutGrid,
Star,
GripVertical,
Plus,
Trash2,
Edit,
ExternalLink,
Bot,
FileText,
Lock,
User,
Mail,
Building,
CreditCard,
Globe,
LogOut,
Save,
Palette,
Megaphone,
X,
ChevronDown,
ChevronUp
} from 'lucide-vue-next';
import KbWorkspaceView from './KbWorkspaceView.vue';
import { listWorkspaceScheduleRuns, workspaceRunExcelUrl, type ScheduleRun } from '../api/schedule';
import { Clock, Download, Search, RefreshCw } from 'lucide-vue-next';
const { t, locale } = useI18n();
const msg = useMessage();
const router = useRouter();
const route = useRoute();
const { setThemePreference, appliedTheme } = useTheme();
const { isMobile } = useIsMobile();
const loginBackgroundStyle = {
backgroundImage: `url(${loginBg})`,
backgroundSize: 'cover',
backgroundPosition: 'center',
backgroundRepeat: 'no-repeat',
};
const loadLanguagePreference = () => {
const storedLang = localStorage.getItem('hxops_lang');
if (storedLang) {
locale.value = storedLang;
}
};
const saveLanguagePreference = (lang: string) => {
localStorage.setItem('hxops_lang', lang);
};
watch(locale, (newLang) => {
saveLanguagePreference(newLang);
});
// Interfaces
interface Agent {
id: number;
name: string;
description: string;
icon_url?: string;
dify_app_type?: 'chatflow' | 'workflow';
}
interface QuickQuestion {
id: number;
title: string;
question: string;
agent_id: number;
}
interface EmbeddedAgent {
id: number;
name: string;
iframe_url?: string;
}
interface LayoutSection {
id: string;
visible: boolean;
collapsed?: boolean;
title?: string;
}
interface Announcement {
id: number;
title: string;
content: string;
created_at: string;
}
interface WecomBindPromptState {
binding_token: string;
allowed_fields: WecomMatchField[];
wecom_name?: string;
field: WecomMatchField;
value: string;
submitting: boolean;
error: string;
}
interface ProfileForm {
id: number;
username: string;
real_name: string;
email: string;
phone_number: string;
department: string;
role: string;
employee_id: string;
language: string;
theme_preference: ThemePreference;
}
// State
const isLoading = ref(true);
const currentUser = ref<{ id: number; username: string; role: string; default_agent_id?: number | null } | null>(null);
const agents = ref<Agent[]>([]);
const publicAgents = ref<Agent[]>([]);
const announcements = ref<Announcement[]>([]);
const quickQuestions = ref<QuickQuestion[]>([]);
const favoriteAgentIds = ref<number[]>([]);
const embeddedAgents = ref<EmbeddedAgent[]>([]);
const SECTION_TITLE_KEY_MAP: Record<string, string> = {
announcements: 'workspace.announcements.title',
favorites: 'workspace.favorites',
quick_questions: 'workspace.quickQuestions.title',
embedded: 'workspace.embedded.title',
all_agents: 'workspace.availableAgents',
};
const layoutSections = ref<LayoutSection[]>([
{ id: 'announcements', visible: true, collapsed: false, title: 'workspace.announcements.title' },
{ id: 'favorites', visible: true, collapsed: false, title: 'workspace.favorites' },
{ id: 'quick_questions', visible: true, collapsed: false, title: 'workspace.quickQuestions.title' },
{ id: 'embedded', visible: true, collapsed: false, title: 'workspace.embedded.title' },
{ id: 'all_agents', visible: true, collapsed: false, title: 'workspace.availableAgents' },
]);
const searchQuery = ref('');
const loginUsername = ref('');
const loginPassword = ref('');
const rememberMe = ref(false);
const showRegisterModal = ref(false);
const showForgotPasswordModal = ref(false);
const showAnnouncementModal = ref(false);
const selectedAnnouncement = ref<Announcement | null>(null);
const registerForm = ref({ username: '', password: '', email: '', real_name: '', employee_id: '', phone_number: '' });
const forgotPasswordForm = ref({ email: '' });
const pendingAgentId = ref<number | null>(null);
const isWecomLoggingIn = ref(false);
const showDeleteQuickQuestionDialog = ref(false);
const pendingDeleteQuickQuestionId = ref<number | null>(null);
const showGeneralFeedbackDialog = ref(false);
const wecomEntryHint = ref('');
const wecomLoginDialog = ref<WecomLoginDialogContent | null>(null);
const wecomBindPrompt = ref<WecomBindPromptState | null>(null);
const clearWecomCallbackQuery = () => {
const nextUrl = `${window.location.pathname}${window.location.hash || ''}`;
window.history.replaceState({}, '', nextUrl);
};
const handleForgotPassword = async () => {
if (!forgotPasswordForm.value.email) {
msg.warning(t('register.emailRequired'));
return;
}
try {
const res = await fetch('/api/user/reset-password-by-email', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(forgotPasswordForm.value)
});
const data = await res.json();
if (res.ok) {
msg.success(t('login.passwordResetEmailSent'));
showForgotPasswordModal.value = false;
forgotPasswordForm.value = { email: '' };
} else {
msg.error(data.error || t('login.passwordResetRequestFailed'));
}
} catch (e) {
console.error('Password reset error', e);
msg.error(t('common.errorOccurred'));
}
};
/*
const showLoginTip = () => {
msg.warning(t('login.pleaseLoginFirst'));
};
*/
const userReport = ref<any>(null);
// Quick Question Form State
const isAddingQuestion = ref(false);
const editingQuestionId = ref<number | null>(null);
const newQuestion = ref({
title: '',
question: '',
agent_id: null as number | null
});
// Drag & Drop State
const draggedSectionIndex = ref<number | null>(null);
// Computed
const isLoggedIn = computed(() => !!currentUser.value && currentUser.value.role !== 'guest');
const favoriteAgents = computed(() => {
return agents.value.filter(a => favoriteAgentIds.value.includes(a.id));
});
const otherAgents = computed(() => {
const chatflowAgents = agents.value.filter((a) => (a.dify_app_type || 'chatflow') === 'chatflow');
if (!searchQuery.value.trim()) return chatflowAgents;
const q = searchQuery.value.toLowerCase();
return chatflowAgents.filter(
(a) => a.name.toLowerCase().includes(q) || a.description.toLowerCase().includes(q)
);
});
const filteredQuickQuestions = computed(() => {
if (!searchQuery.value.trim()) return quickQuestions.value;
const q = searchQuery.value.toLowerCase();
return quickQuestions.value.filter(
(qq) => qq.title.toLowerCase().includes(q) || qq.question.toLowerCase().includes(q)
);
});
const normalizeSectionId = (id: string) => {
if (id === 'quice_questions' || id === 'quickQuestions') return 'quick_questions';
if (id === 'allAgents') return 'all_agents';
return id;
};
const getSectionTitleKey = (sectionId: string) => {
return SECTION_TITLE_KEY_MAP[normalizeSectionId(sectionId)] || normalizeSectionId(sectionId);
};
// Methods
const fetchHome = async () => {
try {
const res = await fetch('/api/user/home', { headers: getAuthHeaders() });
if (res.status === 401) {
msg.error(t('login.loginRequired'));
handleLogout();
return;
}
const data = await res.json();
currentUser.value = {
id: data.user.id,
username: data.user.username,
role: data.user.role,
default_agent_id: data.user.default_agent_id
};
agents.value = data.agents || [];
quickQuestions.value = data.quick_questions || [];
favoriteAgentIds.value = data.favorite_agent_ids || [];
embeddedAgents.value = data.embedded_agents || [];
if (data.layout && data.layout.sections) {
const backendSections = (data.layout.sections as LayoutSection[]).map((s) => ({
...s,
id: normalizeSectionId(s.id),
}));
const defaultSections = [
{ id: 'announcements', visible: true, title: getSectionTitleKey('announcements') },
{ id: 'favorites', visible: true, title: getSectionTitleKey('favorites') },
{ id: 'quick_questions', visible: true, title: getSectionTitleKey('quick_questions') },
{ id: 'embedded', visible: true, title: getSectionTitleKey('embedded') },
{ id: 'all_agents', visible: true, title: getSectionTitleKey('all_agents') },
];
const merged: LayoutSection[] = [];
const backendIds = new Set(backendSections.map(s => s.id));
const mapKey = (id: string) => (normalizeSectionId(id) === 'quick_questions' ? 'quickQuestions' : normalizeSectionId(id) === 'all_agents' ? 'allAgents' : normalizeSectionId(id));
backendSections.forEach(s => {
const def = defaultSections.find(d => d.id === s.id);
if (config.workspace.modules[mapKey(s.id) as keyof typeof config.workspace.modules] === false) {
return;
}
merged.push({ ...def, ...s, title: getSectionTitleKey(s.id) });
});
defaultSections.forEach(d => {
if (!backendIds.has(d.id)) {
if (config.workspace.modules[mapKey(d.id) as keyof typeof config.workspace.modules] === false) {
return;
}
merged.push(d);
}
});
// Filter out sections disabled in config
const filteredSections = merged.filter(s => {
const key = mapKey(s.id) as keyof typeof config.workspace.modules;
if (config.workspace.modules[key] === false) {
return false;
}
return true;
});
layoutSections.value = filteredSections;
} else {
// Fallback for no layout data
const defaultSections = [
{ id: 'announcements', visible: true, collapsed: false, title: getSectionTitleKey('announcements') },
{ id: 'favorites', visible: true, collapsed: false, title: getSectionTitleKey('favorites') },
{ id: 'quick_questions', visible: true, collapsed: false, title: getSectionTitleKey('quick_questions') },
{ id: 'embedded', visible: true, collapsed: false, title: getSectionTitleKey('embedded') },
{ id: 'all_agents', visible: true, collapsed: false, title: getSectionTitleKey('all_agents') },
];
layoutSections.value = defaultSections.filter(s => {
const key = (s.id === 'quick_questions' ? 'quickQuestions' : s.id === 'all_agents' ? 'allAgents' : s.id) as keyof typeof config.workspace.modules;
return config.workspace.modules[key] !== false;
});
}
} catch (e) {
console.error('Failed to load user home', e);
} finally {
isLoading.value = false;
}
};
const fetchPublicAgents = async () => {
try {
const res = await fetch('/api/agents/public');
if (res.ok) {
publicAgents.value = await res.json();
} else {
publicAgents.value = [];
}
} catch (e) {
publicAgents.value = [];
}
};
const fetchAnnouncements = async () => {
try {
const res = await fetch('/api/user/announcements');
if (res.ok) {
announcements.value = await res.json();
}
} catch (e) {
console.error('Failed to load announcements', e);
}
};
const loadAuthUser = () => {
let stored = localStorage.getItem('hxops_user');
// Check if expired
if (stored) {
try {
const parsed = JSON.parse(stored);
if (parsed.expiry && new Date().getTime() > parsed.expiry) {
localStorage.removeItem('hxops_user');
stored = null;
}
} catch (e) {
// ignore
}
}
// Try session storage if local is empty
if (!stored) {
stored = sessionStorage.getItem('hxops_user');
}
if (!stored) {
currentUser.value = null;
return;
}
try {
const user = getStoredAuthUser();
if (!user) return;
currentUser.value = {
id: user.id || 0,
username: user.username || '',
role: user.role || 'user',
};
} catch (e) {
localStorage.removeItem('hxops_user');
sessionStorage.removeItem('hxops_user');
}
};
const persistLoginUser = (user: any) => {
saveAuthUser({ ...(user || {}) }, rememberMe.value);
};
const DEFAULT_POST_LOGIN_AGENT_ID = 16;
const handleLogin = async (event?: Event) => {
event?.preventDefault();
event?.stopPropagation();
if (!loginUsername.value.trim()) {
msg.warning(t('login.usernameRequired'));
return;
}
try {
const loginMode = String(config.auth?.loginMode || 'casdoor').toLowerCase();
const isCasdoorMode = loginMode === 'casdoor';
const loginApi = isCasdoorMode
? (config.auth?.casdoor?.passwordLoginApi || '/api/user/casdoor/password-login')
: '/api/user/login';
const res = await fetch(loginApi, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
username: loginUsername.value.trim(),
password: loginPassword.value
})
});
if (!res.ok) {
const err = await res.json();
// Handle specific error messages if needed, or just alert
let msg = err.error || t('login.failed');
if (isCasdoorMode) {
if (err.error_code === 'CASDOOR_USER_NOT_FOUND') {
msg = t('workspace.msg.casdoorNotMatchedContactAdmin');
} else if (err.error_code === 'ACCOUNT_DISABLED') {
msg = t('login.accountDisabled');
} else if (String(err.error || '').includes('invalid_grant')) {
msg = t('login.incorrectPassword');
}
}
if (err.error === 'User not found') msg = t('login.userNotFound');
if (err.error === 'Incorrect password') msg = t('login.incorrectPassword');
if (err.error === 'Account is disabled') msg = t('login.accountDisabled');
if (err.error === 'Database connection failed') msg = t('login.dbConnectionFailed');
if (err.error === 'Internal server error') msg = t('login.internalError');
msg.error(msg);
return;
}
const user = await res.json();
persistLoginUser(user);
await fetchHome();
pendingAgentId.value = null;
await router.replace(`/chat/${DEFAULT_POST_LOGIN_AGENT_ID}`);
} catch (e) {
console.error(e);
msg.error(t('login.requestFailed'));
}
};
const tryCasdoorCallbackLogin = async () => {
if (!config.auth?.casdoor?.enabled) return false;
const casdoorPath = config.auth.casdoor.callbackPath || '/casdoor-callback';
const path = window.location.pathname;
// Compatibility: allow temporary callback landing on /workspace during migration.
if (path !== casdoorPath && path !== '/workspace') return false;
const params = new URLSearchParams(window.location.search);
const code = params.get('code');
const state = params.get('state');
if (!code) return false;
const expectedState = sessionStorage.getItem('hxops_casdoor_state');
// Backward compatibility: old backend emitted random in-memory state
// (hxops_casdoor_*), while new backend emits signed stateless state.
// For new signed state, rely on backend signature verification instead of
// strict frontend equality check to avoid false negatives during rollout.
const shouldStrictCheck = !!expectedState && !!state && !String(state).startsWith('hxops_casdoor_v1.');
if (shouldStrictCheck && state !== expectedState) {
// Prevent CSRF/state mismatch replay.
msg.error('Invalid or expired Casdoor state');
clearWecomCallbackQuery();
return true;
}
try {
const api = config.auth.casdoor.loginApi || '/api/user/casdoor/login';
const res = await fetch(api, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ code, state }),
});
const data = await res.json();
if (!res.ok) {
const code = String(data.error_code || '');
let msg = data.error || 'Casdoor login failed';
if (code === 'CASDOOR_USER_NOT_FOUND') {
msg = t('workspace.msg.casdoorNotMatchedNeedLocalUser');
} else if (code === 'ACCOUNT_DISABLED') {
msg = t('workspace.msg.localAccountDisabled');
}
msg.error(msg);
clearWecomCallbackQuery();
return true;
}
// Persist access+refresh tokens for API auth and silent refresh.
persistLoginUser(data);
sessionStorage.removeItem('hxops_casdoor_state');
window.history.replaceState({}, '', '/workspace');
await fetchHome();
return true;
} catch (e) {
console.error(e);
msg.error('Casdoor login failed');
clearWecomCallbackQuery();
return true;
}
};
const handleWecomLogin = async () => {
if (!config.auth?.wecom?.enabled) return;
const wecomCfg = config.auth.wecom as { loginViaCasdoor?: boolean; callbackPath?: string; authorizeApi?: string };
const viaCasdoor = Boolean(wecomCfg?.loginViaCasdoor);
try {
if (viaCasdoor) {
if (!config.auth?.casdoor?.enabled) {
msg.error(t('login.wecomStartFailed'));
return;
}
const callbackPath = config.auth.casdoor.callbackPath || '/casdoor-callback';
const redirectUri = `${window.location.origin}${callbackPath}`;
const api = config.auth.casdoor.authorizeApi || '/api/user/casdoor/authorize-url';
const qs = new URLSearchParams({
redirect_uri: redirectUri,
default_provider: 'wecom',
});
const hint = (config.auth.casdoor as { wecomProviderHint?: string }).wecomProviderHint?.trim();
if (hint) {
qs.set('provider_hint', hint);
}
const res = await fetch(`${api}?${qs.toString()}`);
const data = await res.json();
if (!res.ok || !data.url) {
msg.error(data.error || t('login.wecomStartFailed'));
return;
}
if (data.state) {
sessionStorage.setItem('hxops_casdoor_state', data.state);
}
window.location.href = data.url;
return;
}
const redirectUri = `${window.location.origin}${wecomCfg.callbackPath || '/workspace'}`;
const api = wecomCfg.authorizeApi || '/api/user/wecom/authorize-url';
const res = await fetch(`${api}?redirect_uri=${encodeURIComponent(redirectUri)}`);
const data = await res.json();
if (!res.ok || !data.url) {
msg.error(data.error || t('login.wecomStartFailed'));
return;
}
if (data.state) {
sessionStorage.setItem('hxops_wecom_state', data.state);
}
window.location.href = data.url;
} catch (e) {
console.error(e);
msg.error(t('login.wecomStartFailed'));
}
};
const openWecomLoginDialog = (payload: Record<string, unknown>) => {
wecomLoginDialog.value = buildWecomLoginDialogContent(payload, t);
};
const openWecomBindPrompt = (payload: Record<string, unknown>) => {
const allowedFields = normalizeWecomMatchRules(payload.allowed_fields).fields;
const fallbackFields: WecomMatchField[] = ['employee_id', 'mobile', 'email'];
const fields: WecomMatchField[] = allowedFields.length ? allowedFields : fallbackFields;
wecomBindPrompt.value = {
binding_token: String(payload.binding_token || ''),
allowed_fields: fields,
wecom_name: String(payload.wecom_name || ''),
field: fields[0] || 'employee_id',
value: '',
submitting: false,
error: '',
};
};
const formatWecomBindPromptError = (payload: Record<string, unknown>) => {
const errorCode = String(payload.error_code || '');
if (errorCode === 'WECOM_BIND_INPUT_NOT_FOUND') return t('login.wecomBindInputNotFound');
if (errorCode === 'WECOM_BIND_INPUT_AMBIGUOUS') return t('login.wecomBindInputAmbiguous');
if (errorCode === 'WECOM_BIND_SESSION_EXPIRED') return t('login.wecomBindSessionExpired');
if (errorCode === 'WECOM_BIND_CONFLICT') return t('login.wecomBindConflict');
if (errorCode === 'WECOM_BIND_FIELD_NOT_ALLOWED') return t('login.wecomBindFieldNotAllowed');
if (errorCode === 'WECOM_BIND_INPUT_VALUE_REQUIRED') return t('login.wecomBindValueRequired');
if (String(payload.error || '').includes('Account is disabled')) return t('login.wecomAccountDisabled');
return String(payload.error || t('login.wecomLoginFailed'));
};
const submitWecomCompleteBind = async () => {
if (!wecomBindPrompt.value) return;
if (!wecomBindPrompt.value.value.trim()) {
wecomBindPrompt.value.error = t('login.wecomBindValueRequired');
return;
}
wecomBindPrompt.value.submitting = true;
wecomBindPrompt.value.error = '';
try {
const api = config.auth.wecom.completeBindApi || '/api/user/wecom/complete-bind';
const res = await fetch(api, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
binding_token: wecomBindPrompt.value.binding_token,
field: wecomBindPrompt.value.field,
value: wecomBindPrompt.value.value.trim(),
}),
});
const data = await res.json();
if (!res.ok) {
wecomBindPrompt.value.error = formatWecomBindPromptError(data);
if (String(data.error_code || '') === 'WECOM_BIND_SESSION_EXPIRED') {
openWecomLoginDialog(data);
wecomBindPrompt.value = null;
}
return;
}
wecomLoginDialog.value = null;
persistLoginUser(data);
sessionStorage.removeItem('hxops_wecom_state');
wecomBindPrompt.value = null;
window.history.replaceState({}, '', '/workspace');
await fetchHome();
} catch (e) {
console.error(e);
if (wecomBindPrompt.value) {
wecomBindPrompt.value.error = t('login.wecomLoginFailed');
}
} finally {
if (wecomBindPrompt.value) {
wecomBindPrompt.value.submitting = false;
}
}
};
const tryWecomCallbackLogin = async () => {
if (!config.auth?.wecom?.enabled) return false;
if ((config.auth.wecom as { loginViaCasdoor?: boolean }).loginViaCasdoor) {
return false;
}
const wecomPath = config.auth.wecom.callbackPath || '/workspace';
if (window.location.pathname !== wecomPath) return false;
const params = new URLSearchParams(window.location.search);
const code = params.get('code');
const state = params.get('state');
if (!code) return false;
const expectedState = sessionStorage.getItem('hxops_wecom_state');
if (expectedState && state && state !== expectedState) {
msg.error(t('login.wecomInvalidState'));
openWecomLoginDialog({ error: 'Invalid or expired WeCom state' });
clearWecomCallbackQuery();
return true;
}
isWecomLoggingIn.value = true;
try {
const api = config.auth.wecom.loginApi || '/api/user/wecom/login';
const res = await fetch(api, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ code, state }),
});
const data = await res.json();
if (!res.ok) {
const rawError = String(data.error || '');
let friendly = rawError || t('login.wecomLoginFailed');
if (rawError.includes('Invalid or expired WeCom state')) {
friendly = t('login.wecomStateExpired');
} else if (rawError.includes('bind WeCom account') || rawError.includes('No linked account found')) {
friendly = t('login.wecomBindRequired');
} else if (rawError.includes('Account is disabled')) {
friendly = t('login.wecomAccountDisabled');
}
msg.error(friendly);
sessionStorage.removeItem('hxops_wecom_state');
if (String(data.error_code || '') === 'WECOM_BIND_INPUT_REQUIRED') {
openWecomBindPrompt(data);
clearWecomCallbackQuery();
return true;
}
openWecomLoginDialog(data);
clearWecomCallbackQuery();
return true;
}
wecomLoginDialog.value = null;
persistLoginUser(data);
sessionStorage.removeItem('hxops_wecom_state');
window.history.replaceState({}, '', '/workspace');
await fetchHome();
return true;
} catch (e) {
console.error(e);
msg.error(t('login.wecomLoginFailed'));
sessionStorage.removeItem('hxops_wecom_state');
openWecomLoginDialog({ error: t('login.wecomLoginFailed') });
clearWecomCallbackQuery();
return true;
} finally {
isWecomLoggingIn.value = false;
}
};
const handleRegister = async () => {
if (!registerForm.value.username || !registerForm.value.password || !registerForm.value.real_name || !registerForm.value.employee_id || !registerForm.value.phone_number) {
msg.warning(t('register.inputError'));
return;
}
try {
const res = await fetch('/api/user/register', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(registerForm.value)
});
if (res.ok) {
msg.success(t('register.success'));
showRegisterModal.value = false;
registerForm.value = { username: '', password: '', email: '', real_name: '', employee_id: '', phone_number: '' };
} else {
const err = await res.json();
msg.error(err.error || t('register.failed'));
}
} catch (e) {
console.error('Register error:', e);
msg.error(t('register.requestFailed'));
}
};
const activeSidebarItem = ref<'profile' | 'applications' | 'feedback' | 'updates' | 'knowledge_base' | 'schedule_runs' | 'history'>('applications');
const workspaceSidebarNavActive =
'bg-brand-50 text-brand-700 shadow-sm dark:bg-brand-500/15 dark:text-brand-300 dark:shadow-none dark:ring-1 dark:ring-inset dark:ring-brand-500/25';
const workspaceSidebarNavInactive =
'text-slate-600 hover:bg-slate-50 hover:text-slate-900 dark:text-slate-400 dark:hover:bg-slate-800/80 dark:hover:text-slate-200';
const wsScheduleFilterInputClass =
'rounded-lg border border-slate-200 bg-white px-2 py-1.5 text-xs text-slate-900 outline-none transition-colors placeholder:text-slate-400 focus:border-brand-400 focus:ring-1 focus:ring-brand-500/20 dark:border-slate-700 dark:bg-slate-950/70 dark:text-slate-200 dark:placeholder:text-slate-500 dark:[color-scheme:dark]';
const isProfileLoading = ref(false);
const isProfileSaving = ref(false);
const isProfileEditing = ref(false);
const showPasswordModal = ref(false);
const profileUser = ref<ProfileForm>({
id: 0,
username: '',
real_name: '',
email: '',
phone_number: '',
department: '',
role: '',
employee_id: '',
language: 'zh-CN',
theme_preference: 'system' as ThemePreference,
});
const originalProfile = ref<ProfileForm | null>(null);
const passwordForm = ref({
current: '',
new: '',
confirm: '',
});
const themeOptions: Array<{ value: ThemePreference; label: () => string }> = [
{ value: 'light', label: () => t('theme.light') || 'Light' },
{ value: 'dark', label: () => t('theme.dark') || 'Dark' },
{ value: 'system', label: () => t('theme.system') || 'Follow System' },
];
const hasProfileUnsavedChanges = computed(() => {
if (!originalProfile.value) return false;
return (
profileUser.value.real_name !== originalProfile.value.real_name ||
profileUser.value.phone_number !== originalProfile.value.phone_number ||
profileUser.value.language !== originalProfile.value.language ||
profileUser.value.theme_preference !== originalProfile.value.theme_preference ||
profileUser.value.email !== originalProfile.value.email ||
profileUser.value.employee_id !== originalProfile.value.employee_id ||
profileUser.value.department !== originalProfile.value.department
);
});
const mobileTabActive = computed({
get: () => {
if (activeSidebarItem.value === 'profile') return 'profile';
if (activeSidebarItem.value === 'history') return 'history';
return 'applications';
},
set: (tab: 'applications' | 'profile' | 'history') => {
if (tab === 'profile') {
activeSidebarItem.value = 'profile';
if (!profileUser.value.id) fetchProfile();
} else if (tab === 'history') {
activeSidebarItem.value = 'history';
if (chatHistories.value.length === 0) loadChatHistories();
} else {
activeSidebarItem.value = 'applications';
}
},
});
const mobileTabTitle = computed(() => {
if (mobileTabActive.value === 'profile') return t('workspace.mobileTabs.me');
if (mobileTabActive.value === 'history') return t('workspace.mobileTabs.history');
return t('workspace.mobileTabs.applications');
});
const applyLoggedOutState = () => {
currentUser.value = null;
agents.value = [];
quickQuestions.value = [];
favoriteAgentIds.value = [];
embeddedAgents.value = [];
userReport.value = null;
fetchPublicAgents();
};
const handleLogout = () => {
logoutAuth();
applyLoggedOutState();
router.push('/');
};
const onAuthLogout = () => {
applyLoggedOutState();
};
const captureOriginalProfile = () => {
originalProfile.value = { ...profileUser.value };
};
const parseErrorMessage = async (res: Response) => {
try {
const data = await res.json();
return data?.error || data?.message || '';
} catch {
try {
return await res.text();
} catch {
return '';
}
}
};
const fetchProfile = async () => {
isProfileLoading.value = true;
try {
const res = await fetch('/api/user/profile', { headers: getAuthHeaders() });
if (!res.ok) {
msg.error(t('workspace.profile.msg.loadFailed'));
return;
}
const data = await res.json();
profileUser.value = { ...profileUser.value, ...data };
if (data.language) locale.value = data.language;
if (data.theme_preference) {
setThemePreference(data.theme_preference);
} else {
profileUser.value.theme_preference = appliedTheme.value;
}
captureOriginalProfile();
isProfileEditing.value = false;
} catch (e) {
console.error(e);
msg.error(t('workspace.profile.msg.loadFailed'));
} finally {
isProfileLoading.value = false;
}
};
const navigateToProfile = async () => {
activeSidebarItem.value = 'profile';
if (!profileUser.value.id) {
await fetchProfile();
}
};
const startProfileEditing = () => {
isProfileEditing.value = true;
};
const cancelProfileEditing = () => {
if (originalProfile.value) {
profileUser.value = { ...originalProfile.value };
locale.value = profileUser.value.language;
setThemePreference(profileUser.value.theme_preference);
}
isProfileEditing.value = false;
};
const saveProfile = async () => {
if (!hasProfileUnsavedChanges.value) {
isProfileEditing.value = false;
return;
}
const payload = {
real_name: profileUser.value.real_name,
phone_number: profileUser.value.phone_number,
language: profileUser.value.language,
theme_preference: profileUser.value.theme_preference,
email: profileUser.value.email,
employee_id: profileUser.value.employee_id,
department: profileUser.value.department,
};
locale.value = profileUser.value.language;
setThemePreference(profileUser.value.theme_preference);
try {
isProfileSaving.value = true;
const res = await fetch('/api/user/profile', {
method: 'PUT',
headers: { 'Content-Type': 'application/json', ...getAuthHeaders() },
body: JSON.stringify(payload),
});
if (!res.ok) {
const message = await parseErrorMessage(res);
msg.error(message || t('workspace.profile.msg.saveFailed'));
return;
}
msg.success(t('workspace.profile.msg.saved'));
captureOriginalProfile();
isProfileEditing.value = false;
} catch (e) {
console.error(e);
msg.error(t('workspace.profile.msg.saveFailed'));
} finally {
isProfileSaving.value = false;
}
};
const handleChangePassword = async () => {
if (passwordForm.value.new !== passwordForm.value.confirm) {
msg.warning(t('profile.passwordMismatch') || 'Passwords do not match');
return;
}
try {
const res = await fetch('/api/user/change-password', {
method: 'POST',
headers: { 'Content-Type': 'application/json', ...getAuthHeaders() },
body: JSON.stringify({
current_password: passwordForm.value.current,
new_password: passwordForm.value.new,
}),
});
const data = await res.json();
if (!res.ok) {
msg.error(data.error || t('workspace.profile.msg.changePasswordFailed'));
return;
}
msg.success(t('profile.passwordChanged') || 'Password changed successfully');
passwordForm.value = { current: '', new: '', confirm: '' };
showPasswordModal.value = false;
} catch (e) {
console.error(e);
msg.error(t('workspace.profile.msg.changePasswordFailed'));
}
};
const openGeneralFeedback = () => {
activeSidebarItem.value = 'feedback';
showGeneralFeedbackDialog.value = true;
};
const openWorkspaceSection = async (
sectionId: 'announcements' | 'favorites' | 'all_agents',
sidebarItem: 'applications' | 'updates',
) => {
activeSidebarItem.value = sidebarItem;
const targetSection = layoutSections.value.find((section) => section.id === sectionId);
if (targetSection) {
targetSection.collapsed = false;
}
await nextTick();
document.getElementById(`workspace-section-${sectionId}`)?.scrollIntoView({
behavior: 'smooth',
block: 'start',
});
};
const navigateToApplications = () => openWorkspaceSection('favorites', 'applications');
const navigateToUpdates = () => openWorkspaceSection('announcements', 'updates');
const navigateToKnowledgeBase = () => {
activeSidebarItem.value = 'knowledge_base';
};
const navigateToScheduleRuns = () => {
activeSidebarItem.value = 'schedule_runs';
loadWorkspaceScheduleRuns();
};
const workspaceScheduleRuns = ref<ScheduleRun[]>([]);
const workspaceScheduleLoading = ref(false);
const wsScheduleStatusFilter = ref('all');
const wsScheduleNameFilter = ref('');
const toDateTimeLocalValue = (date: Date) => {
const pad = (n: number) => String(n).padStart(2, '0');
return `${date.getFullYear()}-${pad(date.getMonth() + 1)}-${pad(date.getDate())}T${pad(date.getHours())}:${pad(date.getMinutes())}:${pad(date.getSeconds())}`;
};
const todayStartLocal = () => {
const d = new Date();
d.setHours(0, 0, 0, 0);
return toDateTimeLocalValue(d);
};
const todayEndLocal = () => {
const d = new Date();
d.setHours(23, 59, 59, 0);
return toDateTimeLocalValue(d);
};
const wsScheduleStartedAfter = ref(todayStartLocal());
const wsScheduleStartedBefore = ref(todayEndLocal());
const wsScheduleStatusOptions = [
{ value: 'all', label: t('workspace.schedule.status.all') },
{ value: 'success', label: t('workspace.schedule.status.success') },
{ value: 'partial_failed', label: t('workspace.schedule.status.partialFailed') },
{ value: 'failed', label: t('workspace.schedule.status.failed') },
{ value: 'running', label: t('workspace.schedule.status.running') },
];
const getWsScheduleStatusBadge = (status: string) => {
const map: Record<string, { cls: string; label: string }> = {
success: { cls: 'bg-emerald-100 text-emerald-700 dark:bg-emerald-500/15 dark:text-emerald-400', label: t('workspace.schedule.status.success') },
partial_failed: { cls: 'bg-blue-100 text-blue-700 dark:bg-blue-500/15 dark:text-blue-400', label: t('workspace.schedule.status.partialFailed') },
failed: { cls: 'bg-rose-100 text-rose-700 dark:bg-rose-500/15 dark:text-rose-400', label: t('workspace.schedule.status.failed') },
running: { cls: 'bg-amber-100 text-amber-700 dark:bg-amber-500/15 dark:text-amber-400', label: t('workspace.schedule.status.running') },
queued: { cls: 'bg-slate-100 text-slate-600 dark:bg-slate-700/80 dark:text-slate-300', label: t('workspace.schedule.status.queued') },
};
return map[status] || { cls: 'bg-slate-100 text-slate-600 dark:bg-slate-700/80 dark:text-slate-300', label: status };
};
const formatDateTime = (iso?: string | null) => {
if (!iso) return '-';
const d = new Date(iso);
if (isNaN(d.getTime())) return iso;
const pad = (n: number) => String(n).padStart(2, '0');
return `${d.getFullYear()}-${pad(d.getMonth() + 1)}-${pad(d.getDate())} ${pad(d.getHours())}:${pad(d.getMinutes())}:${pad(d.getSeconds())}`;
};
const loadWorkspaceScheduleRuns = async () => {
workspaceScheduleLoading.value = true;
try {
const params: { status?: string; schedule_name?: string; started_after?: string; started_before?: string } = {};
if (wsScheduleStatusFilter.value !== 'all') params.status = wsScheduleStatusFilter.value;
if (wsScheduleNameFilter.value.trim()) params.schedule_name = wsScheduleNameFilter.value.trim();
if (wsScheduleStartedAfter.value) params.started_after = new Date(wsScheduleStartedAfter.value).toISOString();
if (wsScheduleStartedBefore.value) params.started_before = new Date(wsScheduleStartedBefore.value).toISOString();
workspaceScheduleRuns.value = await listWorkspaceScheduleRuns(params);
} catch {
workspaceScheduleRuns.value = [];
} finally {
workspaceScheduleLoading.value = false;
}
};
const resetWsScheduleFilters = () => {
wsScheduleStatusFilter.value = 'all';
wsScheduleNameFilter.value = '';
wsScheduleStartedAfter.value = todayStartLocal();
wsScheduleStartedBefore.value = todayEndLocal();
loadWorkspaceScheduleRuns();
};
const downloadWsScheduleExcel = async (runId: number) => {
const res = await fetch(workspaceRunExcelUrl(runId), { headers: getAuthHeaders() });
if (!res.ok) {
msg.error(t('workspace.schedule.msg.downloadExcelFailed'));
return;
}
const blob = await res.blob();
const url = URL.createObjectURL(blob);
const a = document.createElement('a');
a.href = url;
const disposition = res.headers.get('content-disposition');
a.download = disposition?.match(/filename\*?=(?:UTF-8'')?["']?([^;"'\n]+)/)?.[1] || 'result.xlsx';
document.body.appendChild(a);
a.click();
document.body.removeChild(a);
URL.revokeObjectURL(url);
};
interface ChatHistoryItem {
id: number;
conversation_id: string;
title: string;
agent_id?: number;
agent_name?: string;
created_at: string;
}
const chatHistories = ref<ChatHistoryItem[]>([]);
const isLoadingHistories = ref(false);
const loadChatHistories = async () => {
isLoadingHistories.value = true;
try {
const res = await fetch('/api/agents', { headers: getAuthHeaders() });
if (!res.ok) { isLoadingHistories.value = false; return; }
const agentList = await res.json();
const allHistories: ChatHistoryItem[] = [];
await Promise.all(
(Array.isArray(agentList) ? agentList : []).map(async (agent: any) => {
try {
const hRes = await fetch(`/api/chat/sessions?agent_id=${agent.id}`, { headers: getAuthHeaders() });
if (hRes.ok) {
const sessions = await hRes.json();
for (const s of sessions) {
allHistories.push({ ...s, agent_id: agent.id, agent_name: agent.name });
}
}
} catch {}
})
);
allHistories.sort((a, b) => new Date(b.created_at).getTime() - new Date(a.created_at).getTime());
chatHistories.value = allHistories;
} catch {}
isLoadingHistories.value = false;
};
const navigateToGeneralChat = () => {
router.push(`/chat/${getLastChatAgentId(DEFAULT_POST_LOGIN_AGENT_ID)}`);
};
const openAdminPanel = () => {
router.push('/admin');
};
const navigateToChat = (id: number) => {
if (!isLoggedIn.value) {
pendingAgentId.value = id;
msg.warning(t('login.loginRequired'));
return;
}
const url = router.resolve(`/chat/${id}`).href;
openAgentChatTab(url, id);
};
const navigateWithQuickQuestion = (agentId: number, question: string) => {
if (!isLoggedIn.value) {
pendingAgentId.value = agentId;
msg.warning(t('login.loginRequired'));
return;
}
const url = router.resolve({
path: `/chat/${agentId}`,
query: { preset: question },
}).href;
openAgentChatTab(url, agentId);
};
const handleWecomDeeplinkContext = async () => {
const params = new URLSearchParams(window.location.search);
const traceId = params.get('wecom_trace');
const target = params.get('target');
const agentIdRaw = params.get('agent_id');
const preset = params.get('preset');
if (!traceId && !target) return;
wecomEntryHint.value = t('workspace.wecomEntryNotice');
if (traceId && isLoggedIn.value) {
try {
const api = config.auth?.wecom?.deeplinkTraceApi || '/api/user/wecom/deeplink-opened';
await fetch(api, {
method: 'POST',
headers: { 'Content-Type': 'application/json', ...getAuthHeaders() },
body: JSON.stringify({ trace_id: traceId }),
});
} catch (e) {
console.warn('Failed to mark WeCom deeplink opened', e);
}
}
if (target === 'chat' && agentIdRaw && isLoggedIn.value) {
const agentId = Number(agentIdRaw);
if (Number.isInteger(agentId) && agents.value.some((a) => a.id === agentId)) {
const url = router.resolve({
path: `/chat/${agentId}`,
query: preset ? { preset } : {},
}).href;
openAgentChatTab(url, agentId);
}
}
if (traceId || target) {
window.history.replaceState({}, '', '/workspace');
}
};
// Favorites
const toggleFavorite = async (agentId: number) => {
if (favoriteAgentIds.value.includes(agentId)) {
// Remove
await fetch(`/api/user/favorites/${agentId}`, { method: 'DELETE', headers: getAuthHeaders() });
favoriteAgentIds.value = favoriteAgentIds.value.filter(id => id !== agentId);
} else {
// Add
await fetch(`/api/user/favorites/${agentId}`, { method: 'POST', headers: getAuthHeaders() });
favoriteAgentIds.value.push(agentId);
}
};
// Quick Questions
const getAgentName = (agentId: number) => {
const agent = agents.value.find(a => a.id === agentId);
return agent ? agent.name : t('workspace.unknownAgent');
};
const openAddQuestionForm = () => {
isAddingQuestion.value = true;
editingQuestionId.value = null;
newQuestion.value = { title: '', question: '', agent_id: null };
};
const editQuickQuestion = (qq: QuickQuestion) => {
isAddingQuestion.value = true;
editingQuestionId.value = qq.id;
newQuestion.value = {
title: qq.title,
question: qq.question,
agent_id: qq.agent_id
};
};
const cancelAddQuestion = () => {
isAddingQuestion.value = false;
editingQuestionId.value = null;
newQuestion.value = { title: '', question: '', agent_id: null };
};
const saveQuickQuestion = async () => {
if (!newQuestion.value.title || !newQuestion.value.question || !newQuestion.value.agent_id) {
msg.warning(t('workspace.quickQuestions.msg.fillAll'));
return;
}
const url = editingQuestionId.value
? `/api/user/quick-questions/${editingQuestionId.value}`
: '/api/user/quick-questions';
const method = editingQuestionId.value ? 'PUT' : 'POST';
const res = await fetch(url, {
method: method,
headers: { 'Content-Type': 'application/json', ...getAuthHeaders() },
body: JSON.stringify(newQuestion.value),
});
if (res.ok) {
await fetchHome();
isAddingQuestion.value = false;
editingQuestionId.value = null;
} else {
msg.error(t('workspace.quickQuestions.msg.saveFailed'));
}
};
const removeQuickQuestion = async (id: number) => {
// 删除动作分两步:先记录待删除 id 并打开公共弹框,真正删除在 confirm 回调中执行。
pendingDeleteQuickQuestionId.value = id;
showDeleteQuickQuestionDialog.value = true;
};
const confirmRemoveQuickQuestion = async () => {
if (pendingDeleteQuickQuestionId.value === null) return;
await fetch(`/api/user/quick-questions/${pendingDeleteQuickQuestionId.value}`, { method: 'DELETE', headers: getAuthHeaders() });
await fetchHome();
pendingDeleteQuickQuestionId.value = null;
showDeleteQuickQuestionDialog.value = false;
};
const cancelRemoveQuickQuestion = () => {
pendingDeleteQuickQuestionId.value = null;
showDeleteQuickQuestionDialog.value = false;
};
// Drag & Drop
const toggleSectionCollapse = async (section: LayoutSection) => {
section.collapsed = !section.collapsed;
// Save layout state
await fetch('/api/user/homepage-layout', {
method: 'PUT',
headers: { 'Content-Type': 'application/json', ...getAuthHeaders() },
body: JSON.stringify({ layout: { sections: layoutSections.value } })
});
};
const onDragStart = (index: number) => {
draggedSectionIndex.value = index;
};
const onDragOver = (event: DragEvent) => {
event.preventDefault();
};
const onDrop = async (index: number) => {
if (draggedSectionIndex.value === null) return;
const draggedItem = layoutSections.value[draggedSectionIndex.value];
if (!draggedItem) return;
layoutSections.value.splice(draggedSectionIndex.value, 1);
layoutSections.value.splice(index, 0, draggedItem);
draggedSectionIndex.value = null;
// Save layout
await fetch('/api/user/homepage-layout', {
method: 'PUT',
headers: { 'Content-Type': 'application/json', ...getAuthHeaders() },
body: JSON.stringify({ layout: { sections: layoutSections.value } })
});
};
const openAnnouncement = (ann: Announcement) => {
selectedAnnouncement.value = ann;
showAnnouncementModal.value = true;
};
onMounted(async () => {
window.addEventListener('hxops:logout', onAuthLogout);
loadLanguagePreference();
fetchAnnouncements();
const handledCasdoor = await tryCasdoorCallbackLogin();
if (handledCasdoor && currentUser.value && currentUser.value.role !== 'guest') {
return;
}
const handledWecom = await tryWecomCallbackLogin();
if (handledWecom && currentUser.value && currentUser.value.role !== 'guest') {
return;
}
loadAuthUser();
if (currentUser.value && currentUser.value.role !== 'guest') {
await fetchHome();
await handleWecomDeeplinkContext();
const viewParam = route.query.view as string;
const validViews: string[] = ['profile', 'applications', 'feedback', 'updates', 'knowledge_base', 'schedule_runs', 'history'];
if (viewParam && validViews.includes(viewParam)) {
activeSidebarItem.value = viewParam as typeof activeSidebarItem.value;
if (viewParam === 'profile' && !profileUser.value.id) {
await fetchProfile();
}
if (viewParam === 'history') {
await loadChatHistories();
}
}
} else {
await fetchPublicAgents();
isLoading.value = false;
}
});
onBeforeUnmount(() => {
window.removeEventListener('hxops:logout', onAuthLogout);
});
</script>
<template>
<div class="min-h-screen bg-gray-50 dark:bg-slate-950 font-sans text-slate-800 dark:text-slate-200">
<!-- 右上角全局控件:仅未登录页固定显示,避免与已登录头部区域重叠 -->
<div v-if="!isLoggedIn" class="fixed top-4 right-4 z-50 flex items-center gap-2">
<ThemeToggleButton />
<select v-model="locale" class="bg-white/80 dark:bg-slate-900/80 backdrop-blur-md shadow-sm border border-slate-200 dark:border-slate-700 text-xs font-medium text-slate-600 dark:text-slate-300 hover:text-slate-800 dark:hover:text-slate-100 cursor-pointer outline-none rounded-full px-3 py-1.5 transition-all hover:shadow-md">
<option value="en">English</option>
<option value="zh-CN">{{ $t('workspace.lang.zhCN') }}</option>
<option value="zh-TW">{{ $t('workspace.lang.zhTW') }}</option>
<option value="th">ไทย</option>
</select>
</div>
<main
class="mx-auto"
:class="isLoggedIn ? 'max-w-none min-h-screen px-0 py-0' : 'max-w-7xl page-shell-mobile pb-12'"
>
<div v-if="isLoading" class="animate-pulse space-y-8">
<div class="h-48 bg-gray-200 rounded-2xl"></div>
<div class="grid grid-cols-1 md:grid-cols-3 gap-6">
<div class="h-40 bg-gray-200 rounded-2xl"></div>
<div class="h-40 bg-gray-200 rounded-2xl"></div>
<div class="h-40 bg-gray-200 rounded-2xl"></div>
</div>
</div>
<!-- Not Logged In (Login Screen) -->
<div
v-else-if="!isLoggedIn"
class="relative min-h-[calc(100vh-4rem)] overflow-hidden rounded-[2rem] flex items-center justify-center"
:style="loginBackgroundStyle"
>
<div class="absolute inset-0 bg-white/55 backdrop-blur-[1px] dark:bg-slate-950/55"></div>
<div class="relative z-10 w-full max-w-6xl grid grid-cols-1 lg:grid-cols-2 gap-12 items-center p-4">
<!-- Hero Section -->
<div class="hidden lg:block space-y-8 animate-slide-up">
<!--
<div class="inline-flex items-center gap-2 px-3 py-1 rounded-full bg-brand-50 text-brand-600 text-sm font-medium border border-brand-100">
<span class="relative flex h-2 w-2">
<span class="animate-ping absolute inline-flex h-full w-full rounded-full bg-brand-400 opacity-75"></span>
<span class="relative inline-flex rounded-full h-2 w-2 bg-brand-500"></span>
</span>
{{ $t('title') }}
</div>
-->
<h1 class="text-5xl font-bold text-black leading-tight drop-shadow-sm">
{{ $t('landing.hero.prefix') }} <br/>
<span class="text-transparent bg-clip-text bg-gradient-to-r from-[#005a9c] to-[#7a1fd0] drop-shadow-sm">{{ $t('landing.hero.highlight') }}</span>
</h1>
<p class="text-lg text-slate-800 max-w-md leading-relaxed font-semibold drop-shadow-sm">
{{ $t('landing.hero.subtitle') }}
</p>
<!-- Announcements List -->
<div v-if="announcements.length > 0" class="bg-white/70 dark:bg-slate-900/70 backdrop-blur-sm rounded-2xl border border-slate-200 dark:border-slate-700 p-6 shadow-sm">
<h3 class="text-sm font-bold text-slate-950 mb-4 flex items-center gap-2">
<Megaphone class="w-4 h-4 text-brand-600" />
{{ $t('login.announcements') }}
</h3>
<div class="space-y-3">
<div v-for="ann in announcements.slice(0, 3)" :key="ann.id"
class="group cursor-pointer hover:bg-white/50 dark:hover:bg-slate-800/70 p-2 rounded-lg transition-colors"
@click="openAnnouncement(ann)">
<div class="flex justify-between items-start gap-2">
<h4 class="text-sm font-semibold text-slate-900 group-hover:text-brand-800 line-clamp-1">{{ ann.title }}</h4>
<span class="text-[10px] text-slate-500 whitespace-nowrap">{{ new Date(ann.created_at).toLocaleDateString() }}</span>
</div>
<p class="text-xs text-slate-700 line-clamp-2 mt-1">{{ ann.content }}</p>
</div>
</div>
</div>
<div v-if="isLoggedIn" class="grid grid-cols-2 gap-4">
<div v-for="agent in publicAgents.slice(0, 4)" :key="agent.id"
class="bg-white dark:bg-slate-900 p-4 rounded-xl border border-slate-100 dark:border-slate-700 shadow-sm flex items-center gap-3">
<div class="w-10 h-10 bg-brand-50 rounded-lg flex items-center justify-center text-brand-600 shrink-0">
<Bot class="w-5 h-5" />
</div>
<div class="truncate">
<div class="font-semibold text-slate-900 text-sm truncate">{{ agent.name }}</div>
<div class="text-xs text-slate-500 truncate">{{ $t('landing.agent.role') }}</div>
</div>
</div>
</div>
</div>
<!-- Login Card -->
<div class="w-full max-w-md mx-auto">
<div class="bg-white/90 dark:bg-slate-900/90 backdrop-blur-xl rounded-3xl border border-white/20 dark:border-slate-700 shadow-2xl shadow-brand-900/10 p-8 md:p-10 animate-fade-in relative overflow-hidden">
<div class="absolute top-0 left-0 w-full h-1.5 bg-gradient-to-r from-brand-500 to-purple-600"></div>
<div class="text-center mb-8">
<div class="w-12 h-12 bg-brand-600 rounded-xl mx-auto flex items-center justify-center text-white shadow-lg shadow-brand-600/30 mb-4 lg:hidden">
<Bot class="w-7 h-7" />
</div>
<h2 class="text-2xl font-bold text-slate-900 dark:text-slate-100">{{ $t('login.submit') }}</h2>
<p class="text-slate-600 dark:text-slate-400 text-sm mt-2">{{ $t('login.subtitle') }}</p>
</div>
<div class="space-y-5">
<div class="space-y-1.5">
<label class="text-xs font-semibold text-slate-800 uppercase ml-1">{{ $t('login.username') }}</label>
<input v-model="loginUsername" type="text" class="input-field" :placeholder="$t('login.placeholder.username')" @keyup.enter="handleLogin" />
</div>
<div class="space-y-1.5">
<label class="text-xs font-semibold text-slate-800 uppercase ml-1">{{ $t('login.password') }}</label>
<input v-model="loginPassword" type="password" class="input-field" :placeholder="$t('login.placeholder.password')" @keyup.enter="handleLogin" />
</div>
<div class="flex items-center gap-2 mt-2">
<input type="checkbox" id="rememberMe" v-model="rememberMe" class="rounded border-slate-300 text-brand-600 focus:ring-brand-500 w-4 h-4" />
<label for="rememberMe" class="text-sm text-slate-700 cursor-pointer select-none">{{ $t('login.rememberMe') }}</label>
</div>
<button type="button" @click="handleLogin" class="btn-primary w-full py-3 text-base shadow-brand-500/40 hover:shadow-brand-500/50 transform hover:-translate-y-0.5 transition-all mt-4">
{{ $t('login.submit') }}
</button>
<button
type="button"
v-if="config.auth?.wecom?.enabled && (!config.auth?.wecom?.loginViaCasdoor || config.auth?.casdoor?.enabled)"
@click="handleWecomLogin"
:disabled="isWecomLoggingIn"
class="btn-secondary w-full py-3 text-base mt-3 disabled:opacity-60 disabled:cursor-not-allowed"
>
{{ isWecomLoggingIn ? $t('login.wecomConnecting') : $t('login.wecomLogin') }}
</button>
<div class="flex justify-between items-center pt-4 mt-2 border-t border-slate-100/50">
<button type="button" @click="showForgotPasswordModal = true" class="text-sm text-slate-600 hover:text-brand-700 transition-colors">
{{ $t('login.forgotPassword') }}
</button>
<!-- 点击注册 -->
<!-- <button @click="showRegisterModal = true" class="text-sm font-semibold text-brand-600 hover:text-brand-700 hover:underline transition-colors">
{{ $t('login.registerLink') }}
</button> -->
</div>
</div>
<!-- Public Agents Showcase Mobile -->
<div v-if="isLoggedIn && publicAgents.length > 0" class="mt-8 pt-6 border-t border-slate-100 lg:hidden">
<div class="grid grid-cols-4 gap-3">
<div v-for="agent in publicAgents.slice(0, 4)" :key="agent.id"
class="flex flex-col items-center">
<div class="w-8 h-8 bg-slate-50 rounded-lg flex items-center justify-center text-slate-400">
<Bot class="w-4 h-4" />
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<!-- Logged In Layout -->
<div v-else class="min-h-screen animate-fade-in">
<header v-if="isMobile" class="sticky top-0 z-30 flex items-center justify-between border-b border-slate-200 bg-white px-4 py-2.5 dark:border-slate-800 dark:bg-slate-950">
<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>
<span class="text-sm font-semibold text-slate-800 dark:text-slate-100">{{ mobileTabTitle }}</span>
</div>
</header>
<div class="grid min-h-screen gap-0 lg:grid-cols-[232px_minmax(0,1fr)]">
<aside v-if="!isMobile" class="lg:sticky lg:top-0 lg:h-screen">
<div class="flex h-full flex-col border-r border-slate-200 bg-white px-5 py-6 shadow-sm dark:border-slate-800 dark:bg-slate-900">
<div class="border-b border-slate-100 pb-6 dark:border-slate-800">
<div class="flex items-center gap-3">
<div class="flex h-12 w-12 items-center justify-center rounded-2xl bg-gradient-to-br from-brand-500 via-brand-600 to-purple-600 text-white shadow-lg shadow-brand-500/25">
<Bot class="h-6 w-6" />
</div>
<div class="min-w-0">
<div class="text-2xl font-extrabold tracking-tight text-[#14213d] dark:text-slate-100">{{ $t('workspace.brandTitle') }}</div>
<div class="truncate text-xs font-medium text-slate-400 dark:text-slate-500">
{{ currentUser?.username }} / {{ currentUser?.role }}
</div>
</div>
</div>
</div>
<div class="flex-1 py-6">
<div class="space-y-2">
<button
@click="navigateToProfile"
class="flex w-full items-center gap-3 rounded-2xl px-4 py-3 text-left text-[15px] font-medium transition-all"
:class="activeSidebarItem === 'profile' ? workspaceSidebarNavActive : workspaceSidebarNavInactive"
>
<User class="h-4 w-4" />
<span>{{ $t('workspace.nav.profile') }}</span>
</button>
<button
v-if="currentUser?.role === 'admin'"
@click="openAdminPanel"
class="flex w-full items-center gap-3 rounded-2xl px-4 py-3 text-left text-[15px] font-medium transition-all"
:class="workspaceSidebarNavInactive"
>
<Settings class="h-4 w-4" />
<span>{{ $t('workspace.nav.admin') }}</span>
</button>
<button
@click="navigateToApplications"
class="flex w-full items-center gap-3 rounded-2xl px-4 py-3 text-left text-[15px] font-medium transition-all"
:class="activeSidebarItem === 'applications' ? workspaceSidebarNavActive : workspaceSidebarNavInactive"
>
<LayoutGrid class="h-4 w-4" />
<span>{{ $t('workspace.nav.applications') }}</span>
</button>
<button
@click="navigateToKnowledgeBase"
class="flex w-full items-center gap-3 rounded-2xl px-4 py-3 text-left text-[15px] font-medium transition-all"
:class="activeSidebarItem === 'knowledge_base' ? workspaceSidebarNavActive : workspaceSidebarNavInactive"
>
<FileText class="h-4 w-4" />
<span>{{ $t('workspace.nav.knowledgeBase') }}</span>
</button>
<button
@click="navigateToScheduleRuns"
class="flex w-full items-center gap-3 rounded-2xl px-4 py-3 text-left text-[15px] font-medium transition-all"
:class="activeSidebarItem === 'schedule_runs' ? workspaceSidebarNavActive : workspaceSidebarNavInactive"
>
<Clock class="h-4 w-4" />
<span>{{ $t('workspace.nav.scheduleRuns') }}</span>
</button>
<button
@click="openGeneralFeedback"
class="flex w-full items-center gap-3 rounded-2xl px-4 py-3 text-left text-[15px] font-medium transition-all"
:class="activeSidebarItem === 'feedback' ? workspaceSidebarNavActive : workspaceSidebarNavInactive"
>
<Edit class="h-4 w-4" />
<span>{{ $t('workspace.nav.feedback') }}</span>
</button>
<button
@click="navigateToUpdates"
class="flex w-full items-center gap-3 rounded-2xl px-4 py-3 text-left text-[15px] font-medium transition-all"
:class="activeSidebarItem === 'updates' ? workspaceSidebarNavActive : workspaceSidebarNavInactive"
>
<Megaphone class="h-4 w-4" />
<span>{{ $t('workspace.nav.updates') }}</span>
</button>
</div>
</div>
<div class="border-t border-slate-100 pt-6 dark:border-slate-800">
<div class="space-y-2">
<button
@click="navigateToGeneralChat"
class="flex w-full items-center gap-3 rounded-2xl px-4 py-3 text-left text-[15px] font-medium transition-all"
:class="workspaceSidebarNavInactive"
>
<Bot class="h-4 w-4" />
<span>{{ $t('workspace.nav.backToChat') }}</span>
</button>
<button
@click="handleLogout"
class="flex w-full items-center gap-3 rounded-2xl px-4 py-3 text-left text-[15px] font-medium text-red-500 transition-all hover:bg-red-50 hover:text-red-600 dark:text-red-400 dark:hover:bg-red-950/40 dark:hover:text-red-300"
>
<LogOut class="h-4 w-4" />
<span>{{ $t('workspace.nav.logout') }}</span>
</button>
</div>
</div>
</div>
</aside>
<section class="min-w-0 space-y-6 bg-gray-50 px-4 py-6 dark:bg-slate-950 md:px-6 md:py-8 lg:px-8" :class="isMobile ? 'pb-20' : ''">
<template v-if="activeSidebarItem === 'history'">
<div class="space-y-3">
<div v-if="isLoadingHistories" class="flex justify-center py-20">
<div class="animate-spin rounded-full h-8 w-8 border-b-2 border-brand-600"></div>
</div>
<div v-else-if="chatHistories.length === 0" class="flex flex-col items-center justify-center py-20 text-slate-400">
<Bot class="h-10 w-10 mb-2" />
<p class="text-sm">{{ $t('workspace.history.empty') }}</p>
</div>
<div v-else>
<button
v-for="item in chatHistories"
:key="item.id"
@click="router.push(`/chat/${item.agent_id || 16}?conversation_id=${item.conversation_id}`)"
class="w-full rounded-2xl border border-slate-200 bg-white p-3 text-left transition-colors hover:border-brand-300 hover:bg-brand-50/50 dark:border-slate-700 dark:bg-slate-800 dark:hover:border-brand-600 mb-2"
:class="isMobile ? 'p-2.5 rounded-xl' : ''"
>
<div class="flex items-start gap-3">
<div class="flex h-8 w-8 shrink-0 items-center justify-center rounded-lg bg-brand-50 text-xs font-bold text-brand-600 dark:bg-brand-900/30" :class="isMobile ? 'h-7 w-7 text-[10px]' : ''">
{{ (item.agent_name || 'AI').charAt(0) }}
</div>
<div class="min-w-0 flex-1">
<div class="flex items-center gap-2">
<span class="truncate text-sm font-medium text-slate-800 dark:text-slate-100">{{ item.title || $t('workspace.history.untitled') }}</span>
</div>
<div class="mt-0.5 flex items-center gap-2 text-xs text-slate-400">
<span>{{ item.agent_name || '' }}</span>
<span>{{ new Date(item.created_at).toLocaleDateString() }}</span>
</div>
</div>
</div>
</button>
</div>
</div>
</template>
<template v-else-if="activeSidebarItem === 'profile'">
<div v-if="isProfileLoading" class="flex justify-center py-20">
<div class="animate-spin rounded-full h-8 w-8 border-b-2 border-brand-600"></div>
</div>
<div v-else class="space-y-6">
<div class="rounded-3xl border border-slate-200 bg-white px-6 py-6 shadow-sm md:px-8">
<div class="flex flex-col gap-6 lg:flex-row lg:items-start lg:justify-between">
<div class="flex flex-1 flex-col gap-6 sm:flex-row sm:items-center sm:justify-start">
<div class="flex h-24 w-24 shrink-0 items-center justify-center rounded-full bg-brand-100 text-4xl font-bold text-brand-600" :class="isMobile ? 'h-14 w-14 text-2xl' : ''">
{{ (profileUser.real_name || profileUser.username || 'U').charAt(0).toUpperCase() }}
</div>
<div class="grid flex-1 text-left" :class="isMobile ? 'grid-cols-2 gap-x-4 gap-y-1' : 'grid-cols-1 gap-x-12 gap-y-3 sm:grid-cols-2'">
<div :class="isMobile ? '' : ''">
<div :class="isMobile ? 'text-xs text-slate-400' : 'text-lg font-semibold text-slate-900'">{{ isMobile ? $t('profile.realName') : (profileUser.username || '-') }}</div>
<div v-if="isMobile" class="text-sm font-medium text-slate-900 truncate">{{ profileUser.real_name || profileUser.username || '-' }}</div>
</div>
<div>
<div :class="isMobile ? 'text-xs text-slate-400' : 'text-lg font-semibold text-slate-900'">{{ isMobile ? $t('profile.employeeId') : (profileUser.employee_id || '-') }}</div>
<div v-if="isMobile" class="text-sm font-medium text-slate-900 truncate">{{ profileUser.employee_id || '-' }}</div>
</div>
<div>
<div :class="isMobile ? 'text-xs text-slate-400' : 'text-lg font-semibold text-slate-900'">{{ isMobile ? $t('profile.department') : (profileUser.department || '-') }}</div>
<div v-if="isMobile" class="text-sm font-medium text-slate-900 truncate">{{ profileUser.department || '-' }}</div>
</div>
<div>
<div :class="isMobile ? 'text-xs text-slate-400' : 'text-lg font-semibold text-slate-900'">{{ isMobile ? $t('profile.role') : (profileUser.role === 'admin' ? ($t('profile.roleAdmin') || 'Administrator') : ($t('profile.roleUser') || 'User')) }}</div>
<div v-if="isMobile" class="text-sm font-medium text-slate-900 truncate">{{ profileUser.role === 'admin' ? ($t('profile.roleAdmin') || 'Administrator') : ($t('profile.roleUser') || 'User') }}</div>
</div>
<div :class="isMobile ? 'col-span-2' : 'sm:col-span-2'">
<div :class="isMobile ? 'text-xs text-slate-400' : 'break-all text-lg font-semibold text-slate-900'">{{ isMobile ? $t('profile.email') : (profileUser.email || '-') }}</div>
<div v-if="isMobile" class="text-sm font-medium text-slate-900 truncate">{{ profileUser.email || '-' }}</div>
</div>
</div>
</div>
<div v-if="!isMobile" class="flex shrink-0 items-center gap-2 self-start lg:ml-6">
<button @click="showPasswordModal = true" class="btn-primary px-6 py-3 text-base">
{{ $t('profile.changePassword') }}
</button>
</div>
</div>
<div v-if="isMobile" class="mt-4 flex items-center justify-center gap-4">
<button @click="showPasswordModal = true" class="btn-primary flex-1 py-2.5 text-sm text-center">
{{ $t('profile.changePassword') }}
</button>
<button @click="handleLogout" class="btn-secondary flex-1 py-2.5 text-sm text-center text-red-600 hover:bg-red-50 dark:text-red-400 dark:hover:bg-red-950">
{{ $t('workspace.nav.logout') }}
</button>
</div>
</div>
<div class="space-y-6">
<div class="rounded-3xl border border-slate-200 bg-white p-8 shadow-sm" :class="isMobile ? 'p-4' : ''">
<div class="mb-8 flex flex-col gap-4 sm:flex-row sm:items-center sm:justify-between" :class="isMobile ? 'mb-4 gap-2' : ''">
<div class="flex items-center" :class="isMobile ? 'w-full justify-center gap-2' : ''">
<h3 class="flex items-center gap-3 text-3xl font-bold text-slate-900" :class="isMobile ? 'text-lg gap-2' : ''">
<User class="h-6 w-6 text-brand-500" :class="isMobile ? 'h-4 w-4' : ''" />
{{ $t('profile.basicInfo') }}
</h3>
<button v-if="isMobile && !isProfileEditing" @click="startProfileEditing" class="btn-secondary px-3 py-1 text-xs">
{{ $t('profile.edit') }}
</button>
</div>
<p v-if="!isMobile" class="mt-2 text-sm text-slate-500">
{{ isProfileEditing ? $t('profile.directEditHint') : $t('profile.switchEditHint') }}
</p>
<div v-if="!isMobile" class="flex items-center gap-2">
<button v-if="!isProfileEditing" @click="startProfileEditing" class="btn-secondary px-5 py-2.5 text-sm">
{{ $t('profile.edit') }}
</button>
<template v-else>
<button @click="cancelProfileEditing" class="btn-secondary px-5 py-2.5 text-sm">
{{ $t('profile.cancel') || 'Cancel' }}
</button>
<button
@click="saveProfile"
:disabled="isProfileSaving || !hasProfileUnsavedChanges"
class="btn-primary px-5 py-2.5 text-sm disabled:opacity-50 disabled:cursor-not-allowed"
>
<Save class="w-4 h-4" />
<span>{{ isProfileSaving ? $t('profile.saving') : $t('workspace.save') }}</span>
</button>
</template>
</div>
</div>
<div class="grid grid-cols-1 gap-5 md:grid-cols-2" :class="isMobile ? 'gap-3' : ''">
<div>
<label class="mb-2 flex items-center gap-2 text-sm font-medium text-slate-500" :class="isMobile ? 'text-xs mb-1' : ''">
<User class="h-4 w-4" /> {{ $t('profile.username') }}
</label>
<div class="rounded-2xl border border-slate-200 bg-slate-50 px-4 py-4 text-lg font-medium text-slate-700" :class="isMobile ? 'px-3 py-2 text-sm rounded-xl' : ''">
{{ profileUser.username || '-' }}
</div>
</div>
<div>
<label class="mb-2 flex items-center gap-2 text-sm font-medium text-slate-500" :class="isMobile ? 'text-xs mb-1' : ''">
<CreditCard class="h-4 w-4" /> {{ $t('profile.employeeId') }}
</label>
<input v-if="isProfileEditing" v-model="profileUser.employee_id" type="text" class="input-field" :class="isMobile ? 'h-10 text-sm' : 'h-[58px]'" />
<div v-else class="rounded-2xl border border-slate-200 bg-slate-50 px-4 py-4 text-lg font-medium text-slate-700" :class="isMobile ? 'px-3 py-2 text-sm rounded-xl' : ''">
{{ profileUser.employee_id || '-' }}
</div>
</div>
<div>
<label class="mb-2 flex items-center gap-2 text-sm font-medium text-slate-500" :class="isMobile ? 'text-xs mb-1' : ''">
<User class="h-4 w-4" /> {{ $t('profile.realName') }}
</label>
<input v-if="isProfileEditing" v-model="profileUser.real_name" type="text" class="input-field" :class="isMobile ? 'h-10 text-sm' : 'h-[58px]'" />
<div v-else class="rounded-2xl border border-slate-200 bg-slate-50 px-4 py-4 text-lg font-medium text-slate-700" :class="isMobile ? 'px-3 py-2 text-sm rounded-xl' : ''">
{{ profileUser.real_name || '-' }}
</div>
</div>
<div>
<label class="mb-2 flex items-center gap-2 text-sm font-medium text-slate-500" :class="isMobile ? 'text-xs mb-1' : ''">
<Building class="h-4 w-4" /> {{ $t('profile.department') }}
</label>
<input v-if="isProfileEditing" v-model="profileUser.department" type="text" class="input-field" :class="isMobile ? 'h-10 text-sm' : 'h-[58px]'" />
<div v-else class="rounded-2xl border border-slate-200 bg-slate-50 px-4 py-4 text-lg font-medium text-slate-700" :class="isMobile ? 'px-3 py-2 text-sm rounded-xl' : ''">
{{ profileUser.department || '-' }}
</div>
</div>
<div>
<label class="mb-2 flex items-center gap-2 text-sm font-medium text-slate-500" :class="isMobile ? 'text-xs mb-1' : ''">
<Mail class="h-4 w-4" /> {{ $t('profile.email') }}
</label>
<input v-if="isProfileEditing" v-model="profileUser.email" type="email" class="input-field" :class="isMobile ? 'h-10 text-sm' : 'h-[58px]'" />
<div v-else class="rounded-2xl border border-slate-200 bg-slate-50 px-4 py-4 text-lg font-medium text-slate-700" :class="isMobile ? 'px-3 py-2 text-sm rounded-xl' : ''">
{{ profileUser.email || '-' }}
</div>
</div>
<div>
<label class="mb-2 flex items-center gap-2 text-sm font-medium text-slate-500" :class="isMobile ? 'text-xs mb-1' : ''">
<Globe class="h-4 w-4" /> {{ $t('profile.phoneNumber') }}
</label>
<input v-if="isProfileEditing" v-model="profileUser.phone_number" type="text" class="input-field" :class="isMobile ? 'h-10 text-sm' : 'h-[58px]'" />
<div v-else class="rounded-2xl border border-slate-200 bg-slate-50 px-4 py-4 text-lg font-medium text-slate-700" :class="isMobile ? 'px-3 py-2 text-sm rounded-xl' : ''">
{{ profileUser.phone_number || '-' }}
</div>
</div>
</div>
</div>
<div class="rounded-3xl border border-slate-200 bg-white p-8 shadow-sm">
<h3 class="mb-6 flex items-center gap-3 text-2xl font-bold text-slate-900">
<Palette class="h-5 w-5 text-brand-500" />
{{ $t('profile.preferences') }}
</h3>
<div class="grid grid-cols-1 gap-6 md:grid-cols-2">
<div>
<label class="mb-2 block text-sm font-medium text-slate-500">{{ $t('workspace.languageLabel') }}</label>
<select v-model="profileUser.language" :disabled="!isProfileEditing" class="input-field h-[58px]">
<option value="en">English</option>
<option value="zh-CN">{{ $t('workspace.lang.zhCN') }}</option>
<option value="zh-TW">{{ $t('workspace.lang.zhTW') }}</option>
<option value="th">ไทย</option>
</select>
</div>
<div>
<label class="mb-2 block text-sm font-medium text-slate-500">{{ $t('profile.theme') }}</label>
<div class="grid grid-cols-3 gap-2">
<button
v-for="item in themeOptions"
:key="item.value"
type="button"
:disabled="!isProfileEditing"
@click="profileUser.theme_preference = item.value"
class="rounded-xl border px-3 py-3 text-sm font-medium transition-colors"
:class="profileUser.theme_preference === item.value
? 'border-brand-500 bg-brand-50 text-brand-700'
: 'border-slate-200 bg-white text-slate-600'"
>
{{ item.label() }}
</button>
</div>
</div>
</div>
</div>
</div>
</div>
</template>
<template v-else-if="activeSidebarItem === 'knowledge_base'">
<KbWorkspaceView :embedded="true" />
</template>
<template v-else-if="activeSidebarItem === 'schedule_runs'">
<div class="space-y-5 animate-fade-in-up">
<div class="flex items-center justify-between">
<h2 class="text-2xl font-bold text-slate-900 dark:text-slate-100">{{ $t('workspace.schedule.title') }}</h2>
<button
@click="loadWorkspaceScheduleRuns"
class="inline-flex items-center gap-1.5 rounded-xl border border-slate-200 px-3 py-1.5 text-sm font-medium text-slate-600 transition-colors hover:bg-slate-50 dark:border-slate-600 dark:text-slate-300 dark:hover:bg-slate-800"
>
<RefreshCw class="h-3.5 w-3.5" />
{{ $t('workspace.schedule.refresh') }}
</button>
</div>
<div class="flex flex-wrap items-end gap-3 rounded-2xl border border-slate-200/80 bg-white/70 px-4 py-3 shadow-sm dark:border-slate-800 dark:bg-slate-900/20 dark:shadow-none">
<div>
<label class="mb-1 block text-xs font-medium text-slate-500 dark:text-slate-400">{{ $t('workspace.schedule.filters.name') }}</label>
<input type="text" v-model="wsScheduleNameFilter" :placeholder="$t('workspace.schedule.filters.namePlaceholder')" :class="['!w-[150px]', wsScheduleFilterInputClass]" />
</div>
<div>
<label class="mb-1 block text-xs font-medium text-slate-500 dark:text-slate-400">{{ $t('workspace.schedule.filters.start') }}</label>
<input type="datetime-local" step="1" v-model="wsScheduleStartedAfter" :class="['!w-[170px]', wsScheduleFilterInputClass]" />
</div>
<div>
<label class="mb-1 block text-xs font-medium text-slate-500 dark:text-slate-400">{{ $t('workspace.schedule.filters.end') }}</label>
<input type="datetime-local" step="1" v-model="wsScheduleStartedBefore" :class="['!w-[170px]', wsScheduleFilterInputClass]" />
</div>
<div>
<label class="mb-1 block text-xs font-medium text-slate-500 dark:text-slate-400">{{ $t('workspace.schedule.filters.status') }}</label>
<select v-model="wsScheduleStatusFilter" :class="['!w-[120px]', wsScheduleFilterInputClass]">
<option v-for="o in wsScheduleStatusOptions" :key="o.value" :value="o.value">{{ o.label }}</option>
</select>
</div>
<button
@click="loadWorkspaceScheduleRuns"
class="inline-flex items-center gap-1 rounded-xl bg-brand-600 px-3 py-1.5 text-sm font-medium text-white transition-colors hover:bg-brand-700 dark:hover:bg-brand-500"
>
<Search class="h-3.5 w-3.5" />
{{ $t('workspace.schedule.search') }}
</button>
<button
@click="resetWsScheduleFilters"
class="rounded-xl border border-slate-200 px-3 py-1.5 text-sm font-medium text-slate-600 transition-colors hover:bg-slate-50 dark:border-slate-700 dark:bg-transparent dark:text-slate-300 dark:hover:bg-slate-800/60"
>
{{ $t('workspace.schedule.reset') }}
</button>
</div>
<div v-if="workspaceScheduleLoading" class="rounded-2xl border border-dashed border-slate-200 py-10 text-center text-sm text-slate-400 dark:border-slate-800 dark:text-slate-500">{{ $t('workspace.schedule.loading') }}</div>
<div v-else-if="workspaceScheduleRuns.length === 0" class="rounded-2xl border border-dashed border-slate-200 py-10 text-center text-sm text-slate-400 dark:border-slate-800 dark:text-slate-500">{{ $t('workspace.schedule.empty') }}</div>
<div v-else class="overflow-hidden rounded-2xl border border-slate-200 bg-white dark:border-slate-700 dark:bg-slate-800">
<div class="max-h-[calc(100vh-17rem)] overflow-auto scrollbar-thin">
<table class="w-full min-w-[1080px] text-sm">
<thead class="sticky top-0 z-10">
<tr class="border-b border-slate-100 bg-slate-50 dark:border-slate-700 dark:bg-slate-900">
<th class="min-w-[120px] whitespace-nowrap bg-slate-50 px-4 py-3 text-left font-semibold text-slate-600 dark:bg-slate-900 dark:text-slate-400">{{ $t('workspace.schedule.columns.name') }}</th>
<th class="min-w-[168px] whitespace-nowrap bg-slate-50 px-4 py-3 text-left font-semibold text-slate-600 dark:bg-slate-900 dark:text-slate-400">{{ $t('workspace.schedule.columns.runNo') }}</th>
<th class="min-w-[72px] whitespace-nowrap bg-slate-50 px-4 py-3 text-left font-semibold text-slate-600 dark:bg-slate-900 dark:text-slate-400">{{ $t('workspace.schedule.columns.triggerType') }}</th>
<th class="min-w-[152px] whitespace-nowrap bg-slate-50 px-4 py-3 text-left font-semibold text-slate-600 dark:bg-slate-900 dark:text-slate-400">{{ $t('workspace.schedule.columns.start') }}</th>
<th class="min-w-[152px] whitespace-nowrap bg-slate-50 px-4 py-3 text-left font-semibold text-slate-600 dark:bg-slate-900 dark:text-slate-400">{{ $t('workspace.schedule.columns.end') }}</th>
<th class="min-w-[64px] whitespace-nowrap bg-slate-50 px-4 py-3 text-left font-semibold text-slate-600 dark:bg-slate-900 dark:text-slate-400">{{ $t('workspace.schedule.columns.duration') }}</th>
<th class="min-w-[88px] whitespace-nowrap bg-slate-50 px-4 py-3 text-left font-semibold text-slate-600 dark:bg-slate-900 dark:text-slate-400">{{ $t('workspace.schedule.columns.status') }}</th>
<th class="min-w-[72px] whitespace-nowrap bg-slate-50 px-4 py-3 text-left font-semibold text-slate-600 dark:bg-slate-900 dark:text-slate-400">{{ $t('workspace.schedule.columns.total') }}</th>
<th class="min-w-[72px] whitespace-nowrap bg-slate-50 px-4 py-3 text-left font-semibold text-slate-600 dark:bg-slate-900 dark:text-slate-400">{{ $t('workspace.schedule.columns.success') }}</th>
<th class="min-w-[72px] whitespace-nowrap bg-slate-50 px-4 py-3 text-left font-semibold text-slate-600 dark:bg-slate-900 dark:text-slate-400">{{ $t('workspace.schedule.columns.failed') }}</th>
<th class="min-w-[72px] whitespace-nowrap bg-slate-50 px-4 py-3 text-left font-semibold text-slate-600 dark:bg-slate-900 dark:text-slate-400">{{ $t('workspace.schedule.columns.detail') }}</th>
</tr>
</thead>
<tbody>
<tr v-for="r in workspaceScheduleRuns" :key="r.id" class="border-b border-slate-50 transition-colors hover:bg-slate-50/50 dark:border-slate-700/80 dark:hover:bg-slate-700/40">
<td class="whitespace-nowrap px-4 py-3 font-medium text-slate-900 dark:text-slate-100">{{ r.schedule_name || '-' }}</td>
<td class="whitespace-nowrap px-4 py-3 font-mono text-xs text-slate-500 dark:text-slate-400">{{ r.run_no }}</td>
<td class="whitespace-nowrap px-4 py-3 text-slate-500 dark:text-slate-400">{{ r.trigger_type === 'manual' ? $t('workspace.schedule.trigger.manual') : r.trigger_type === 'test' ? $t('workspace.schedule.trigger.test') : $t('workspace.schedule.trigger.timed') }}</td>
<td class="whitespace-nowrap px-4 py-3 text-slate-500 dark:text-slate-400">{{ formatDateTime(r.started_at) }}</td>
<td class="whitespace-nowrap px-4 py-3 text-slate-500 dark:text-slate-400">{{ formatDateTime(r.finished_at) }}</td>
<td class="whitespace-nowrap px-4 py-3 text-slate-500 dark:text-slate-400">{{ r.duration_ms != null ? (r.duration_ms >= 1000 ? (r.duration_ms / 1000).toFixed(1) + 's' : r.duration_ms + 'ms') : '-' }}</td>
<td class="whitespace-nowrap px-4 py-3">
<span class="inline-flex shrink-0 items-center whitespace-nowrap rounded-full px-2.5 py-1 text-xs font-semibold" :class="getWsScheduleStatusBadge(r.status).cls">
{{ getWsScheduleStatusBadge(r.status).label }}
</span>
<span v-if="r.error_message && r.error_message !== '无待处理数据'" class="ml-1 text-xs text-slate-400 dark:text-slate-500" :title="r.error_message">...</span>
<span v-else-if="r.error_message === '无待处理数据'" class="ml-1 text-xs text-slate-400 dark:text-slate-500">({{ $t('workspace.schedule.noPendingData') }})</span>
</td>
<td class="whitespace-nowrap px-4 py-3 text-slate-500 dark:text-slate-400">{{ r.total_count || 0 }}</td>
<td class="whitespace-nowrap px-4 py-3 font-medium text-emerald-600 dark:text-emerald-400">{{ r.success_count ?? 0 }}</td>
<td class="whitespace-nowrap px-4 py-3 font-medium text-rose-600 dark:text-rose-400">{{ r.failed_count ?? 0 }}</td>
<td class="whitespace-nowrap px-4 py-3">
<a
v-if="r.total_count > 0 && r.excel_file_name"
href="#"
@click.prevent="downloadWsScheduleExcel(r.id)"
class="inline-flex items-center gap-1 rounded-lg border border-slate-200 px-2 py-1 text-xs font-medium text-slate-600 transition-colors hover:bg-slate-50 dark:border-slate-600 dark:text-slate-300 dark:hover:border-slate-500 dark:hover:bg-slate-700/80"
>
<Download class="h-3 w-3" />
{{ $t('workspace.schedule.download') }}
</a>
<span v-else class="text-xs text-slate-300 dark:text-slate-600">-</span>
</td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
</template>
<template v-else>
<div v-if="wecomEntryHint" class="rounded-2xl border border-blue-200 bg-blue-50 px-4 py-3 text-sm text-blue-700">
{{ wecomEntryHint }}
</div>
<div
v-for="(section, index) in layoutSections"
:id="`workspace-section-${section.id}`"
:key="section.id"
class="bg-transparent md:bg-white dark:md:bg-slate-900 md:rounded-3xl md:border md:border-slate-100 dark:md:border-slate-700 md:p-8 md:shadow-soft relative group transition-all scroll-mt-6"
:class="{ 'opacity-50 border-brand-300 border-dashed': draggedSectionIndex === index }"
draggable="true"
@dragstart="onDragStart(index)"
@dragover="onDragOver"
@drop="onDrop(index)"
>
<div class="absolute left-2 top-8 cursor-move opacity-0 group-hover:opacity-100 p-2 text-slate-300 hover:text-slate-500 transition-opacity hidden md:block">
<GripVertical class="w-5 h-5" />
</div>
<div class="md:pl-6">
<div class="flex justify-between items-center mb-6">
<h2 class="text-lg md:text-xl font-semibold text-[#1b2b49] dark:text-slate-100 flex items-center gap-2.5 cursor-pointer select-none" @click="toggleSectionCollapse(section)">
<div class="p-2 rounded-lg" :class="{
'bg-emerald-50 text-emerald-600 dark:bg-emerald-500/15 dark:text-emerald-400': section.id === 'announcements',
'bg-yellow-50 text-yellow-600 dark:bg-yellow-500/15 dark:text-yellow-400': section.id === 'favorites',
'bg-brand-50 text-brand-600 dark:bg-brand-500/15 dark:text-brand-300': section.id === 'quick_questions',
'bg-purple-50 text-purple-600 dark:bg-purple-500/15 dark:text-purple-400': section.id === 'embedded',
'bg-slate-100 text-slate-600 dark:bg-slate-700/80 dark:text-slate-300': section.id === 'all_agents'
}">
<component :is="section.id === 'announcements' ? Megaphone : (section.id === 'favorites' ? Star : (section.id === 'embedded' ? Bot : LayoutGrid))" class="w-5 h-5" />
</div>
{{ $t(getSectionTitleKey(section.id)) }}
<component :is="section.collapsed ? ChevronDown : ChevronUp" class="w-4 h-4 text-slate-400" />
</h2>
<button v-if="section.id === 'quick_questions' && !isAddingQuestion && !section.collapsed" @click="openAddQuestionForm" class="btn-ghost text-sm text-brand-600 hover:text-brand-700 hover:bg-brand-50 dark:text-brand-300 dark:hover:bg-brand-500/15">
<Plus class="w-4 h-4" /> {{ $t('workspace.quickQuestions.add') }}
</button>
</div>
<div v-show="!section.collapsed" class="animate-fade-in">
<!-- Content: Announcements -->
<div v-if="section.id === 'announcements'">
<div v-if="announcements.length === 0" class="text-slate-400 text-sm italic py-8 text-center bg-slate-50 rounded-xl border border-dashed border-slate-200">{{ $t('workspace.announcements.noData') }}</div>
<div v-else class="grid grid-cols-1 md:grid-cols-2 xl:grid-cols-3 gap-4">
<div
v-for="ann in announcements"
:key="ann.id"
class="group border border-slate-200 dark:border-slate-700 rounded-2xl bg-white dark:bg-slate-900 p-5 hover:border-emerald-300 hover:shadow-md transition-all cursor-pointer"
@click="openAnnouncement(ann)"
>
<div class="flex items-start justify-between gap-3 mb-2">
<h4 class="font-bold text-slate-900 dark:text-slate-100 line-clamp-2 group-hover:text-emerald-700 dark:group-hover:text-emerald-400 transition-colors">{{ ann.title }}</h4>
<span class="text-[10px] font-semibold text-emerald-700 bg-emerald-50 dark:text-emerald-300 dark:bg-emerald-500/15 px-2 py-0.5 rounded-full whitespace-nowrap">{{ new Date(ann.created_at).toLocaleDateString() }}</span>
</div>
<p class="text-sm text-slate-600 dark:text-slate-400 line-clamp-3">{{ ann.content }}</p>
</div>
</div>
</div>
<!-- Content: Favorites -->
<div v-if="section.id === 'favorites'">
<div v-if="favoriteAgents.length === 0" class="text-slate-400 text-sm italic py-4 bg-slate-50 rounded-xl text-center border border-dashed border-slate-200 dark:bg-slate-800/50 dark:border-slate-700">{{ $t('workspace.noFavorites') }}</div>
<div class="grid grid-cols-2 md:grid-cols-3 lg:grid-cols-4 gap-3 sm:gap-6">
<div v-for="agent in favoriteAgents" :key="agent.id" @click="navigateToChat(agent.id)"
class="card p-4 sm:p-5 cursor-pointer relative group/card hover:-translate-y-1 hover:shadow-lg hover:border-brand-200 dark:hover:border-brand-600 bg-gradient-to-br from-white to-slate-50/50 dark:from-slate-800 dark:to-slate-800/90">
<div class="w-8 h-8 sm:w-12 sm:h-12 bg-brand-100 dark:bg-brand-500/15 rounded-xl flex items-center justify-center text-brand-600 dark:text-brand-300 mb-3 sm:mb-4 shadow-sm dark:shadow-none group-hover/card:scale-110 transition-transform duration-300">
<img v-if="agent.icon_url" :src="agent.icon_url" class="w-5 h-5 sm:w-7 sm:h-7" />
<Bot v-else class="w-5 h-5 sm:w-7 sm:h-7" />
</div>
<div class="text-[15px] sm:text-base font-semibold text-[#1b2b49] dark:text-slate-100 mb-1 group-hover/card:text-brand-700 dark:group-hover/card:text-brand-300 transition-colors truncate">{{ agent.name }}</div>
<div class="text-[13px] sm:text-xs text-[#8fa1b8] dark:text-slate-300 truncate">{{ agent.description }}</div>
<button @click.stop="toggleFavorite(agent.id)" class="absolute top-3 right-3 text-yellow-400 hover:text-yellow-500 hover:scale-110 transition-all opacity-0 group-hover/card:opacity-100">
<Star class="w-5 h-5 fill-current" />
</button>
</div>
</div>
</div>
<!-- Content: Quick Questions -->
<div v-if="section.id === 'quick_questions'">
<!-- Add Question Form -->
<div v-if="isAddingQuestion" class="mb-6 p-6 bg-slate-50 border border-slate-200 rounded-2xl space-y-4 animate-fade-in">
<h3 class="font-bold text-slate-800">{{ editingQuestionId ? $t('workspace.quickQuestions.edit') : $t('workspace.quickQuestions.addNew') }}</h3>
<div class="grid grid-cols-1 md:grid-cols-2 gap-5">
<div class="space-y-1.5">
<label class="text-xs font-semibold text-slate-500 uppercase">{{ $t('workspace.quickQuestions.fields.title') }}</label>
<input v-model="newQuestion.title" class="input-field" :placeholder="$t('workspace.quickQuestions.fields.titlePlaceholder')" />
</div>
<div class="space-y-1.5">
<label class="text-xs font-semibold text-slate-500 uppercase">{{ $t('workspace.quickQuestions.fields.targetAgent') }}</label>
<select v-model="newQuestion.agent_id" class="input-field" :disabled="agents.length === 0">
<option :value="null" disabled>{{ agents.length === 0 ? $t('workspace.noAgents') : $t('workspace.quickQuestions.fields.selectAgent') }}</option>
<option v-for="agent in agents" :key="agent.id" :value="agent.id">{{ agent.name }}</option>
</select>
</div>
<div class="col-span-1 md:col-span-2 space-y-1.5">
<label class="text-xs font-semibold text-slate-500 uppercase">{{ $t('workspace.quickQuestions.fields.content') }}</label>
<textarea v-model="newQuestion.question" rows="3" class="input-field" :placeholder="$t('workspace.quickQuestions.fields.contentPlaceholder')"></textarea>
</div>
</div>
<div class="flex justify-end gap-3 pt-2">
<button @click="cancelAddQuestion" class="btn-secondary">{{ $t('workspace.cancel') }}</button>
<button @click="saveQuickQuestion" class="btn-primary">{{ $t('workspace.save') }}</button>
</div>
</div>
<div v-if="filteredQuickQuestions.length === 0 && !isAddingQuestion" class="text-slate-400 text-sm italic py-8 text-center bg-slate-50 rounded-xl border border-dashed border-slate-200">{{ $t('workspace.quickQuestions.noDefined') }}</div>
<div class="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-4">
<div v-for="qq in filteredQuickQuestions" :key="qq.id"
@click="navigateWithQuickQuestion(qq.agent_id, qq.question)"
class="group/item p-4 bg-white dark:bg-slate-900 border border-slate-200 dark:border-slate-700 rounded-xl hover:border-brand-500 hover:shadow-md transition-all cursor-pointer flex flex-col gap-3 relative h-full">
<div class="flex justify-between items-start">
<h4 class="font-bold text-slate-900 group-hover/item:text-brand-600 transition-colors">{{ qq.title }}</h4>
<span class="text-[10px] font-bold px-2 py-0.5 bg-slate-100 text-slate-600 rounded-full uppercase tracking-wide">
{{ getAgentName(qq.agent_id) }}
</span>
</div>
<p class="text-sm text-slate-600 line-clamp-2 leading-relaxed">{{ qq.question }}</p>
<div class="absolute top-2 right-2 flex gap-1 opacity-0 group-hover/item:opacity-100 transition-opacity bg-white/90 dark:bg-slate-900/90 backdrop-blur-sm p-1 rounded-lg">
<button @click.stop="editQuickQuestion(qq)" class="p-1.5 rounded-lg text-slate-400 hover:text-brand-600 hover:bg-brand-50 transition-colors">
<Edit class="w-4 h-4" />
</button>
<button @click.stop="removeQuickQuestion(qq.id)" class="p-1.5 rounded-lg text-slate-400 hover:text-red-600 hover:bg-red-50 transition-colors">
<Trash2 class="w-4 h-4" />
</button>
</div>
</div>
</div>
</div>
<!-- Content: Embedded Agents -->
<div v-if="section.id === 'embedded'">
<div v-if="embeddedAgents.length === 0" class="text-slate-400 text-sm italic py-4 bg-slate-50 rounded-xl text-center border border-dashed border-slate-200">{{ $t('workspace.embedded.noData') }}</div>
<div class="grid grid-cols-1 lg:grid-cols-2 gap-6">
<div v-for="agent in embeddedAgents" :key="agent.id" class="border border-slate-200 dark:border-slate-700 rounded-2xl overflow-hidden bg-white dark:bg-slate-900 shadow-sm hover:shadow-md transition-shadow h-[500px] flex flex-col">
<div class="bg-slate-50 dark:bg-slate-800 px-4 py-3 text-sm font-bold text-slate-700 dark:text-slate-200 flex justify-between items-center border-b border-slate-100 dark:border-slate-700">
<span>{{ agent.name }}</span>
<a :href="`/chat/${agent.id}`" target="_blank" class="text-brand-600 hover:text-brand-700 hover:bg-brand-50 dark:text-brand-300 dark:hover:bg-brand-500/15 p-1.5 rounded-lg transition-colors"><ExternalLink class="w-4 h-4"/></a>
</div>
<iframe v-if="agent.iframe_url" :src="agent.iframe_url" class="w-full flex-1 border-none bg-white dark:bg-slate-900"></iframe>
<div v-else class="flex items-center justify-center flex-1 text-slate-400 bg-slate-50/50">{{ $t('workspace.embedded.noUrl') }}</div>
</div>
</div>
</div>
<!-- Content: All Agents -->
<div v-if="section.id === 'all_agents'">
<div class="mb-6">
<input v-model="searchQuery" type="text" :placeholder="$t('workspace.search')" class="input-field max-w-md shadow-sm" />
</div>
<div class="grid grid-cols-2 md:grid-cols-3 lg:grid-cols-4 gap-3 sm:gap-6">
<div v-for="agent in otherAgents" :key="agent.id"
@click="navigateToChat(agent.id)"
class="card card-mobile-compact cursor-pointer relative group/card hover:-translate-y-1 hover:border-brand-200 dark:hover:border-brand-600">
<div class="flex items-start justify-between mb-2 sm:mb-4">
<div class="w-8 h-8 sm:w-10 sm:h-10 bg-slate-50 dark:bg-slate-700/80 rounded-xl flex items-center justify-center text-slate-500 dark:text-slate-300 group-hover/card:bg-brand-50 group-hover/card:text-brand-600 dark:group-hover/card:bg-brand-500/15 dark:group-hover/card:text-brand-300 transition-colors">
<img v-if="agent.icon_url" :src="agent.icon_url" class="w-4 h-4 sm:w-6 sm:h-6" />
<Bot v-else class="w-4 h-4 sm:w-6 sm:h-6" />
</div>
<button @click.stop="toggleFavorite(agent.id)" class="text-slate-200 hover:text-yellow-400 transition-colors">
<Star class="w-5 h-5" :class="{ 'fill-yellow-400 text-yellow-400': favoriteAgentIds.includes(agent.id) }" />
</button>
</div>
<h3 class="text-[15px] sm:text-base font-semibold text-[#1b2b49] dark:text-slate-100 mb-1 group-hover/card:text-brand-700 dark:group-hover/card:text-brand-300 transition-colors line-clamp-1 sm:line-clamp-2 leading-tight">{{ agent.name }}</h3>
<p class="text-[13px] sm:text-xs text-[#8fa1b8] dark:text-slate-300 line-clamp-1 sm:line-clamp-2 h-4 sm:h-8 leading-relaxed">{{ agent.description }}</p>
</div>
</div>
</div>
</div>
</div>
</div>
</template>
</section>
</div>
<nav v-if="isMobile" class="fixed bottom-0 left-0 right-0 z-40 border-t border-slate-200 bg-white dark:border-slate-800 dark:bg-slate-950 safe-bottom">
<div class="flex h-14 items-center justify-around">
<button
v-for="tab in ([
{ key: 'applications', icon: LayoutGrid, label: $t('workspace.mobileTabs.applications') },
{ key: 'history', icon: Bot, label: $t('workspace.mobileTabs.history') },
{ key: 'profile', icon: User, label: $t('workspace.mobileTabs.me') },
] as const)"
:key="tab.key"
@click="mobileTabActive = tab.key"
class="flex flex-1 flex-col items-center justify-center gap-0.5 py-1 transition-colors"
:class="mobileTabActive === tab.key ? 'text-brand-600 dark:text-brand-400' : 'text-slate-400 dark:text-slate-500'"
>
<component :is="tab.icon" class="h-5 w-5" />
<span class="text-[10px] font-medium">{{ tab.label }}</span>
</button>
</div>
</nav>
</div>
<!-- Forgot Password Modal -->
<div v-if="showForgotPasswordModal" class="fixed inset-0 bg-slate-900/40 dark:bg-slate-950/70 backdrop-blur-sm flex items-center justify-center z-50 p-4 animate-fade-in">
<div class="bg-white dark:bg-slate-900 rounded-3xl shadow-2xl w-full max-w-md p-8 animate-slide-up relative border border-slate-200 dark:border-slate-700">
<button @click="showForgotPasswordModal = false" class="absolute top-4 right-4 text-slate-400 hover:text-slate-600">
<X class="w-5 h-5" />
</button>
<div class="text-center mb-6">
<div class="w-12 h-12 bg-brand-100 rounded-xl mx-auto flex items-center justify-center text-brand-600 mb-4">
<Lock class="w-6 h-6" />
</div>
<h3 class="text-xl font-bold text-slate-900 dark:text-slate-100">{{ $t('login.forgotPassword') }}</h3>
<p class="text-slate-500 dark:text-slate-400 text-sm mt-2">{{ $t('login.forgotPasswordDesc') }}</p>
</div>
<div class="space-y-4">
<label class="text-xs font-semibold text-slate-700 uppercase ml-1">{{ $t('register.email') }}</label>
<input v-model="forgotPasswordForm.email" :placeholder="$t('register.email')" class="input-field" @keyup.enter="handleForgotPassword" />
</div>
<div class="flex justify-end gap-3 mt-8">
<button @click="showForgotPasswordModal = false" class="btn-secondary flex-1">{{ $t('register.cancel') }}</button>
<button @click="handleForgotPassword" class="btn-primary flex-1">{{ $t('login.findPassword') }}</button>
</div>
</div>
</div>
<!-- Announcement Modal -->
<div v-if="showAnnouncementModal && selectedAnnouncement" class="fixed inset-0 bg-slate-900/40 dark:bg-slate-950/70 backdrop-blur-sm flex items-center justify-center z-50 p-4 animate-fade-in">
<div class="bg-white dark:bg-slate-900 rounded-3xl shadow-2xl w-full max-w-2xl p-8 animate-slide-up relative max-h-[80vh] overflow-y-auto border border-slate-200 dark:border-slate-700">
<button @click="showAnnouncementModal = false" class="absolute top-4 right-4 text-slate-400 hover:text-slate-600">
<X class="w-5 h-5" />
</button>
<div class="mb-6">
<span class="text-xs font-bold text-brand-600 bg-brand-50 px-2 py-1 rounded-full">{{ new Date(selectedAnnouncement.created_at).toLocaleDateString() }}</span>
<h3 class="text-2xl font-bold text-slate-900 dark:text-slate-100 mt-2">{{ selectedAnnouncement.title }}</h3>
</div>
<div class="prose prose-slate max-w-none">
<p class="whitespace-pre-wrap text-slate-600 leading-relaxed">{{ selectedAnnouncement.content }}</p>
</div>
<div class="mt-8 pt-6 border-t border-slate-100 dark:border-slate-700 flex justify-end">
<button @click="showAnnouncementModal = false" class="btn-primary">
{{ $t('admin.close') }}
</button>
</div>
</div>
</div>
</main>
<div v-if="wecomLoginDialog" class="fixed inset-0 bg-slate-900/40 dark:bg-slate-950/70 backdrop-blur-sm flex items-center justify-center z-50 p-4 animate-fade-in">
<div class="bg-white dark:bg-slate-900 rounded-3xl shadow-2xl w-full max-w-lg p-8 animate-slide-up relative border border-slate-200 dark:border-slate-700">
<button @click="wecomLoginDialog = null" class="absolute top-4 right-4 text-slate-400 hover:text-slate-600">
<X class="w-5 h-5" />
</button>
<div class="mb-5">
<div class="w-12 h-12 bg-amber-100 text-amber-700 rounded-xl flex items-center justify-center mb-4">
<Lock class="w-6 h-6" />
</div>
<h3 class="text-xl font-bold text-slate-900 dark:text-slate-100">{{ wecomLoginDialog.title }}</h3>
<p class="text-sm text-slate-600 dark:text-slate-300 mt-3 leading-6">{{ wecomLoginDialog.summary }}</p>
</div>
<div v-if="wecomLoginDialog.details.length" class="rounded-2xl bg-slate-50 dark:bg-slate-800/80 border border-slate-200 dark:border-slate-700 px-4 py-4 space-y-3">
<p v-for="(detail, index) in wecomLoginDialog.details" :key="`${detail}-${index}`" class="text-sm text-slate-600 dark:text-slate-300 leading-6">
{{ detail }}
</p>
</div>
<p v-if="wecomLoginDialog.technical" class="mt-4 text-xs text-slate-400 break-all">
{{ $t('login.wecomTechnicalInfo', { detail: wecomLoginDialog.technical }) }}
</p>
<div class="flex justify-end gap-3 mt-8">
<button @click="wecomLoginDialog = null" class="btn-secondary">{{ $t('admin.close') }}</button>
<button @click="wecomLoginDialog = null; handleWecomLogin()" class="btn-primary" :disabled="isWecomLoggingIn">
{{ $t('login.wecomRetry') }}
</button>
</div>
</div>
</div>
<div v-if="wecomBindPrompt" class="fixed inset-0 bg-slate-900/40 dark:bg-slate-950/70 backdrop-blur-sm flex items-center justify-center z-50 p-4 animate-fade-in">
<div class="bg-white dark:bg-slate-900 rounded-3xl shadow-2xl w-full max-w-lg p-8 animate-slide-up relative border border-slate-200 dark:border-slate-700">
<button @click="wecomBindPrompt = null" class="absolute top-4 right-4 text-slate-400 hover:text-slate-600">
<X class="w-5 h-5" />
</button>
<div class="mb-6">
<div class="w-12 h-12 bg-blue-100 text-blue-700 rounded-xl flex items-center justify-center mb-4">
<User class="w-6 h-6" />
</div>
<h3 class="text-xl font-bold text-slate-900 dark:text-slate-100">{{ $t('login.wecomBindPromptTitle') }}</h3>
<p class="text-sm text-slate-600 dark:text-slate-300 mt-3 leading-6">
{{ $t('login.wecomBindPromptDesc', { name: wecomBindPrompt.wecom_name || '-' }) }}
</p>
</div>
<div class="space-y-4">
<div>
<label class="mb-1.5 block text-xs font-semibold text-slate-600 uppercase">{{ $t('login.wecomBindField') }}</label>
<select v-model="wecomBindPrompt.field" class="input-field">
<option v-for="field in wecomBindPrompt.allowed_fields" :key="field" :value="field">
{{ formatWecomFieldLabel(field, t) }}
</option>
</select>
</div>
<div>
<label class="mb-1.5 block text-xs font-semibold text-slate-600 uppercase">{{ $t('login.wecomBindValue') }}</label>
<input
v-model="wecomBindPrompt.value"
class="input-field"
:placeholder="$t('login.wecomBindValuePlaceholder', { field: formatWecomFieldLabel(wecomBindPrompt.field, t) })"
@keyup.enter="submitWecomCompleteBind"
/>
</div>
<p class="text-xs text-slate-500 leading-5">{{ $t('login.wecomBindPromptHint') }}</p>
<p v-if="wecomBindPrompt.error" class="text-sm text-red-600 leading-6">{{ wecomBindPrompt.error }}</p>
</div>
<div class="flex justify-end gap-3 mt-8">
<button @click="wecomBindPrompt = null" class="btn-secondary">{{ $t('admin.close') }}</button>
<button @click="submitWecomCompleteBind" class="btn-primary" :disabled="wecomBindPrompt.submitting">
{{ wecomBindPrompt.submitting ? $t('login.wecomConnecting') : $t('login.wecomBindSubmit') }}
</button>
</div>
</div>
</div>
<div v-if="showPasswordModal" class="fixed inset-0 z-50 flex items-center justify-center bg-black/50 backdrop-blur-sm p-4">
<div class="w-full max-w-md rounded-3xl border border-slate-200 bg-white p-6 shadow-2xl">
<div class="mb-6 flex items-center justify-between">
<h3 class="text-lg font-bold text-slate-900">{{ $t('profile.changePassword') || 'Change Password' }}</h3>
<button @click="showPasswordModal = false" class="rounded-full p-1 text-slate-500 transition-colors hover:bg-slate-100">
<X class="w-5 h-5" />
</button>
</div>
<form @submit.prevent="handleChangePassword" class="space-y-4">
<div>
<label class="text-xs font-medium text-slate-500 uppercase">{{ $t('profile.currentPassword') || 'Current Password' }}</label>
<input v-model="passwordForm.current" type="password" class="input-field mt-1" required />
</div>
<div>
<label class="text-xs font-medium text-slate-500 uppercase">{{ $t('profile.newPassword') || 'New Password' }}</label>
<input v-model="passwordForm.new" type="password" class="input-field mt-1" required />
</div>
<div>
<label class="text-xs font-medium text-slate-500 uppercase">{{ $t('profile.confirmPassword') || 'Confirm Password' }}</label>
<input v-model="passwordForm.confirm" type="password" class="input-field mt-1" required />
</div>
<div class="flex gap-3 pt-2">
<button type="button" @click="showPasswordModal = false" class="btn-secondary flex-1 py-2">
{{ $t('profile.cancel') || 'Cancel' }}
</button>
<button type="submit" class="btn-primary flex-1 py-2">
{{ $t('profile.changePassword') || 'Update' }}
</button>
</div>
</form>
</div>
</div>
<!-- Register Modal -->
<div v-if="showRegisterModal" class="fixed inset-0 bg-slate-900/40 dark:bg-slate-950/70 backdrop-blur-sm flex items-center justify-center z-50 p-4 animate-fade-in">
<div class="bg-white dark:bg-slate-900 rounded-3xl shadow-2xl w-full max-w-md p-8 animate-slide-up relative border border-slate-200 dark:border-slate-700">
<button @click="showRegisterModal = false" class="absolute top-4 right-4 text-slate-400 hover:text-slate-600">
<X class="w-5 h-5" />
</button>
<h3 class="text-xl font-bold text-slate-900 dark:text-slate-100 mb-6 text-center">{{ $t('register.title') }}</h3>
<div class="space-y-4">
<input v-model="registerForm.real_name" :placeholder="$t('register.fields.realName')" class="input-field" />
<input v-model="registerForm.employee_id" :placeholder="$t('register.fields.employeeId')" class="input-field" />
<input v-model="registerForm.phone_number" :placeholder="$t('register.fields.phone')" class="input-field" />
<input v-model="registerForm.username" :placeholder="$t('register.username')" class="input-field" />
<input v-model="registerForm.email" :placeholder="$t('register.email')" class="input-field" />
<input v-model="registerForm.password" type="password" :placeholder="$t('register.password')" class="input-field" />
</div>
<div class="flex justify-end gap-3 mt-8">
<button @click="showRegisterModal = false" class="btn-secondary">{{ $t('register.cancel') }}</button>
<button @click="handleRegister" class="btn-primary">{{ $t('register.submit') }}</button>
</div>
</div>
</div>
<DeleteConfirmDialog
v-model="showDeleteQuickQuestionDialog"
:title="$t('workspace.quickQuestions.deleteDialog.title')"
:message="$t('workspace.quickQuestions.deleteDialog.message')"
@confirm="confirmRemoveQuickQuestion"
@cancel="cancelRemoveQuickQuestion"
/>
<GeneralFeedbackDialog
v-model="showGeneralFeedbackDialog"
:auth-headers="getAuthHeaders()"
source-page="workspace"
@submitted="msg.success('\u53cd\u9988\u63d0\u4ea4\u6210\u529f')"
/>
</div>
</template>
<style scoped>
/* Scoped styles removed in favor of global utilities in style.css */
</style>