feat: Initial commit with full deployment architecture and scripts
This commit is contained in:
commit
abb3efe114
96 files changed
+16789
No files matched your search
@@ -0,0 +1,728 @@
|
||||
<script setup lang="ts">
|
||||
/**
|
||||
* WorkspaceView.vue
|
||||
* 文件用途:用户工作台,支持自定义布局、收藏、嵌入 Agent
|
||||
* 引用文件:vue, vue-router, lucide-vue-next, 后端 /api/user 接口
|
||||
*/
|
||||
import { ref, onMounted, computed } from 'vue';
|
||||
import { useRouter } from 'vue-router';
|
||||
import { useI18n } from 'vue-i18n';
|
||||
import {
|
||||
Settings,
|
||||
LayoutGrid,
|
||||
Star,
|
||||
GripVertical,
|
||||
Plus,
|
||||
Trash2,
|
||||
Edit,
|
||||
ExternalLink,
|
||||
Bot
|
||||
} from 'lucide-vue-next';
|
||||
|
||||
const { t, locale } = useI18n();
|
||||
const router = useRouter();
|
||||
|
||||
// Interfaces
|
||||
interface Agent {
|
||||
id: number;
|
||||
name: string;
|
||||
description: string;
|
||||
icon_url?: string;
|
||||
}
|
||||
|
||||
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;
|
||||
title?: string;
|
||||
}
|
||||
|
||||
// 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 quickQuestions = ref<QuickQuestion[]>([]);
|
||||
const favoriteAgentIds = ref<number[]>([]);
|
||||
const embeddedAgents = ref<EmbeddedAgent[]>([]);
|
||||
const layoutSections = ref<LayoutSection[]>([
|
||||
{ id: 'favorites', visible: true, title: 'workspace.favorites' },
|
||||
{ id: 'quick_questions', visible: true, title: 'workspace.quickQuestions.title' },
|
||||
{ id: 'embedded', visible: true, title: 'workspace.embedded' },
|
||||
{ id: 'all_agents', visible: true, title: 'workspace.availableAgents' },
|
||||
]);
|
||||
|
||||
const searchQuery = ref('');
|
||||
const loginUsername = ref('');
|
||||
const loginPassword = ref('');
|
||||
const showRegisterModal = ref(false);
|
||||
const registerForm = ref({ username: '', password: '', email: '', real_name: '', employee_id: '', phone_number: '' });
|
||||
const pendingAgentId = ref<number | null>(null);
|
||||
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(() => {
|
||||
// If we want to show ALL agents in the bottom list, just return filtered agents.
|
||||
// Or if we want to exclude favorites, we can filter them out.
|
||||
// Usually "All Applications" includes favorites too, or separates them.
|
||||
// Let's keep all agents in the main list for completeness, or just non-favorites if preferred.
|
||||
// For now, let's show all matching search.
|
||||
if (!searchQuery.value.trim()) return agents.value;
|
||||
const q = searchQuery.value.toLowerCase();
|
||||
return agents.value.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)
|
||||
);
|
||||
});
|
||||
|
||||
// Methods
|
||||
const getAuthHeaders = () => {
|
||||
const stored = localStorage.getItem('hxops_user');
|
||||
if (!stored) return {};
|
||||
const user = JSON.parse(stored) as { id?: number; username: string; role: string };
|
||||
const headers: Record<string, string> = {
|
||||
'X-Username': user.username,
|
||||
'X-Role': user.role,
|
||||
};
|
||||
if (user.id) {
|
||||
headers['X-User-Id'] = String(user.id);
|
||||
}
|
||||
return headers;
|
||||
};
|
||||
|
||||
const fetchHome = async () => {
|
||||
try {
|
||||
const res = await fetch('/api/user/home', { headers: getAuthHeaders() });
|
||||
if (res.status === 401) {
|
||||
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 || [];
|
||||
|
||||
// Merge layout from backend if exists
|
||||
if (data.layout && data.layout.sections) {
|
||||
// Ensure all required sections exist even if backend layout is old
|
||||
const backendSections = data.layout.sections as LayoutSection[];
|
||||
const defaultSections = [
|
||||
{ id: 'favorites', visible: true },
|
||||
{ id: 'quick_questions', visible: true },
|
||||
{ id: 'embedded', visible: true },
|
||||
{ id: 'all_agents', visible: true },
|
||||
];
|
||||
|
||||
// Update local layout, preserving order from backend but ensuring all keys exist
|
||||
const merged: LayoutSection[] = [];
|
||||
const backendIds = new Set(backendSections.map(s => s.id));
|
||||
|
||||
// Add backend sections
|
||||
backendSections.forEach(s => {
|
||||
const def = defaultSections.find(d => d.id === s.id);
|
||||
merged.push({ ...def, ...s });
|
||||
});
|
||||
|
||||
// Add missing sections
|
||||
defaultSections.forEach(d => {
|
||||
if (!backendIds.has(d.id)) {
|
||||
merged.push(d);
|
||||
}
|
||||
});
|
||||
|
||||
layoutSections.value = merged;
|
||||
}
|
||||
} catch (e) {
|
||||
console.error('Failed to load user home', e);
|
||||
} finally {
|
||||
isLoading.value = false;
|
||||
}
|
||||
};
|
||||
|
||||
const fetchPublicAgents = async () => {
|
||||
try {
|
||||
const res = await fetch('/api/user/public-agents');
|
||||
publicAgents.value = await res.json();
|
||||
} catch (e) {
|
||||
console.error('Failed to load public agents', e);
|
||||
}
|
||||
};
|
||||
|
||||
const loadAuthUser = () => {
|
||||
const stored = localStorage.getItem('hxops_user');
|
||||
if (!stored) return;
|
||||
try {
|
||||
const user = JSON.parse(stored) as { id?: number; username: string; role: string };
|
||||
currentUser.value = {
|
||||
id: user.id || 0,
|
||||
username: user.username,
|
||||
role: user.role,
|
||||
};
|
||||
} catch (e) {
|
||||
localStorage.removeItem('hxops_user');
|
||||
}
|
||||
};
|
||||
|
||||
const handleLogin = async () => {
|
||||
if (!loginUsername.value.trim()) {
|
||||
alert(t('login.usernameRequired'));
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
const res = await fetch('/api/user/login', {
|
||||
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();
|
||||
alert(err.error || t('login.failed'));
|
||||
return;
|
||||
}
|
||||
|
||||
const user = await res.json();
|
||||
localStorage.setItem('hxops_user', JSON.stringify(user));
|
||||
await fetchHome();
|
||||
|
||||
if (pendingAgentId.value) {
|
||||
const targetId = pendingAgentId.value;
|
||||
pendingAgentId.value = null;
|
||||
if (agents.value.some(a => a.id === targetId)) {
|
||||
navigateToChat(targetId);
|
||||
} else {
|
||||
alert(t('workspace.permission.denied'));
|
||||
}
|
||||
}
|
||||
} catch (e) {
|
||||
console.error(e);
|
||||
alert(t('login.requestFailed'));
|
||||
}
|
||||
};
|
||||
|
||||
const handleRegister = async () => {
|
||||
if (!registerForm.value.username || !registerForm.value.password || !registerForm.value.real_name || !registerForm.value.employee_id || !registerForm.value.phone_number) {
|
||||
alert(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) {
|
||||
alert(t('register.success'));
|
||||
showRegisterModal.value = false;
|
||||
registerForm.value = { username: '', password: '', email: '', real_name: '', employee_id: '', phone_number: '' };
|
||||
} else {
|
||||
const err = await res.json();
|
||||
alert(err.error || t('register.failed'));
|
||||
}
|
||||
} catch (e) {
|
||||
console.error('Register error:', e);
|
||||
alert(t('register.requestFailed'));
|
||||
}
|
||||
};
|
||||
|
||||
const handleLogout = () => {
|
||||
localStorage.removeItem('hxops_user');
|
||||
currentUser.value = null;
|
||||
agents.value = [];
|
||||
quickQuestions.value = [];
|
||||
favoriteAgentIds.value = [];
|
||||
embeddedAgents.value = [];
|
||||
userReport.value = null;
|
||||
fetchPublicAgents();
|
||||
};
|
||||
|
||||
const navigateToChat = (id: number) => {
|
||||
if (!isLoggedIn.value) {
|
||||
pendingAgentId.value = id;
|
||||
alert(t('login.loginRequired'));
|
||||
return;
|
||||
}
|
||||
const url = router.resolve(`/chat/${id}`).href;
|
||||
window.open(url, '_blank');
|
||||
};
|
||||
|
||||
const navigateWithQuickQuestion = (agentId: number, question: string) => {
|
||||
if (!isLoggedIn.value) {
|
||||
pendingAgentId.value = agentId;
|
||||
alert(t('login.loginRequired'));
|
||||
return;
|
||||
}
|
||||
const url = router.resolve({
|
||||
path: `/chat/${agentId}`,
|
||||
query: { preset: question },
|
||||
}).href;
|
||||
window.open(url, '_blank');
|
||||
};
|
||||
|
||||
// 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', 'Unknown Agent');
|
||||
};
|
||||
|
||||
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) {
|
||||
alert(t('workspace.quickQuestions.addTitle') + ' (Please fill all fields)');
|
||||
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 {
|
||||
alert(t('workspace.quickQuestions.msg.saveFailed'));
|
||||
}
|
||||
};
|
||||
|
||||
const removeQuickQuestion = async (id: number) => {
|
||||
if (!window.confirm(t('workspace.quickQuestions.confirmDelete'))) return;
|
||||
await fetch(`/api/user/quick-questions/${id}`, { method: 'DELETE', headers: getAuthHeaders() });
|
||||
await fetchHome();
|
||||
};
|
||||
|
||||
// Drag & Drop
|
||||
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 } })
|
||||
});
|
||||
};
|
||||
|
||||
onMounted(async () => {
|
||||
loadAuthUser();
|
||||
if (currentUser.value && currentUser.value.role !== 'guest') {
|
||||
await fetchHome();
|
||||
} else {
|
||||
await fetchPublicAgents();
|
||||
isLoading.value = false;
|
||||
}
|
||||
});
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="min-h-screen bg-gray-50 font-sans text-slate-800">
|
||||
<!-- Header (Logged In) -->
|
||||
<header v-if="isLoggedIn" class="sticky top-0 z-30 bg-white/80 backdrop-blur-md border-b border-gray-100 px-4 md:px-8 py-4 mb-8 transition-all duration-300">
|
||||
<div class="max-w-7xl mx-auto flex flex-col md:flex-row justify-between items-center gap-4">
|
||||
<div class="flex items-center gap-3">
|
||||
<div class="w-10 h-10 bg-gradient-to-br from-brand-500 to-brand-700 rounded-xl flex items-center justify-center text-white shadow-lg shadow-brand-500/30">
|
||||
<Bot class="w-6 h-6" />
|
||||
</div>
|
||||
<div>
|
||||
<h1 class="text-xl font-bold text-slate-900 tracking-tight">
|
||||
{{ currentUser ? $t('workspace.userTitle', { username: currentUser.username }) : $t('workspace.title') }}
|
||||
</h1>
|
||||
<p class="text-slate-500 text-xs font-medium">{{ $t('workspace.subtitle') }}</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="flex items-center gap-3">
|
||||
<select v-model="locale" class="bg-white border border-slate-200 rounded-xl px-3 py-2 text-sm font-medium text-slate-600 outline-none focus:ring-2 focus:ring-brand-500/20 focus:border-brand-500 transition-all cursor-pointer hover:bg-slate-50">
|
||||
<option value="en">English</option>
|
||||
<option value="zh-CN">简体中文</option>
|
||||
<option value="zh-TW">繁體中文</option>
|
||||
<option value="th">ไทย</option>
|
||||
</select>
|
||||
|
||||
<button v-if="currentUser?.role === 'admin'" @click="router.push('/admin')" class="btn-secondary">
|
||||
<Settings class="w-4 h-4 mr-2" /> {{ $t('admin.title') }}
|
||||
</button>
|
||||
<button @click="handleLogout" class="btn-ghost hover:text-red-600 hover:bg-red-50">{{ $t('workspace.logout') }}</button>
|
||||
</div>
|
||||
</div>
|
||||
</header>
|
||||
|
||||
<main class="max-w-7xl mx-auto px-4 md:px-8 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="min-h-[calc(100vh-4rem)] flex items-center justify-center -mt-16 md:-mt-20">
|
||||
<div class="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>
|
||||
Enterprise AI Gateway
|
||||
</div>
|
||||
<h1 class="text-5xl font-bold text-slate-900 leading-tight">
|
||||
Unleash the Power of <br/>
|
||||
<span class="text-transparent bg-clip-text bg-gradient-to-r from-brand-600 to-purple-600">Generative AI</span>
|
||||
</h1>
|
||||
<p class="text-lg text-slate-600 max-w-md leading-relaxed">
|
||||
Access a suite of powerful AI agents tailored for your enterprise needs. Secure, scalable, and intelligent.
|
||||
</p>
|
||||
|
||||
<div class="grid grid-cols-2 gap-4">
|
||||
<div v-for="agent in publicAgents.slice(0, 4)" :key="agent.id"
|
||||
class="bg-white p-4 rounded-xl border border-slate-100 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">AI Assistant</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Login Card -->
|
||||
<div class="w-full max-w-md mx-auto">
|
||||
<div class="bg-white rounded-3xl border border-slate-100 shadow-xl shadow-brand-900/5 p-8 md:p-10 animate-fade-in">
|
||||
<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">{{ $t('login.submit') }}</h2>
|
||||
<p class="text-slate-500 text-sm mt-2">Welcome back! Please enter your details.</p>
|
||||
</div>
|
||||
|
||||
<div class="space-y-5">
|
||||
<div class="space-y-1.5">
|
||||
<label class="text-xs font-semibold text-slate-700 uppercase ml-1">{{ $t('login.username') }}</label>
|
||||
<input v-model="loginUsername" type="text" class="input-field" placeholder="Enter your username" />
|
||||
</div>
|
||||
<div class="space-y-1.5">
|
||||
<label class="text-xs font-semibold text-slate-700 uppercase ml-1">{{ $t('login.password') }}</label>
|
||||
<input v-model="loginPassword" type="password" class="input-field" placeholder="••••••••" />
|
||||
</div>
|
||||
|
||||
<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">
|
||||
{{ $t('login.submit') }}
|
||||
</button>
|
||||
|
||||
<div class="text-center pt-2">
|
||||
<span class="text-sm text-slate-500">Don't have an account? </span>
|
||||
<button @click="showRegisterModal = true" class="text-sm font-semibold text-brand-600 hover:text-brand-700 hover:underline transition-colors">{{ $t('login.register') }}</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Language Selector for Login -->
|
||||
<div class="mt-8 pt-6 border-t border-slate-100 flex justify-center">
|
||||
<select v-model="locale" class="bg-transparent text-xs font-medium text-slate-400 hover:text-slate-600 cursor-pointer outline-none text-center">
|
||||
<option value="en">English</option>
|
||||
<option value="zh-CN">简体中文</option>
|
||||
<option value="zh-TW">繁體中文</option>
|
||||
<option value="th">ไทย</option>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Logged In Layout -->
|
||||
<div v-else class="space-y-8 animate-fade-in">
|
||||
<!-- Draggable Sections -->
|
||||
<div
|
||||
v-for="(section, index) in layoutSections"
|
||||
:key="section.id"
|
||||
class="bg-transparent md:bg-white md:rounded-3xl md:border md:border-slate-100 md:p-8 md:shadow-soft relative group transition-all"
|
||||
:class="{ 'opacity-50 border-brand-300 border-dashed': draggedSectionIndex === index }"
|
||||
draggable="true"
|
||||
@dragstart="onDragStart(index)"
|
||||
@dragover="onDragOver"
|
||||
@drop="onDrop(index)"
|
||||
>
|
||||
<!-- Drag Handle -->
|
||||
<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>
|
||||
|
||||
<!-- Section Content -->
|
||||
<div class="md:pl-6">
|
||||
<!-- Header -->
|
||||
<div class="flex justify-between items-center mb-6">
|
||||
<h2 class="text-xl font-bold text-slate-800 flex items-center gap-2.5">
|
||||
<div class="p-2 rounded-lg" :class="{
|
||||
'bg-yellow-50 text-yellow-600': section.id === 'favorites',
|
||||
'bg-brand-50 text-brand-600': section.id === 'quick_questions',
|
||||
'bg-purple-50 text-purple-600': section.id === 'embedded',
|
||||
'bg-slate-100 text-slate-600': section.id === 'all_agents'
|
||||
}">
|
||||
<component :is="section.id === 'favorites' ? Star : (section.id === 'embedded' ? Bot : LayoutGrid)" class="w-5 h-5" />
|
||||
</div>
|
||||
{{ $t(section.title || section.id) }}
|
||||
</h2>
|
||||
<!-- Actions for Quick Questions -->
|
||||
<button v-if="section.id === 'quick_questions' && !isAddingQuestion" @click="openAddQuestionForm" class="btn-ghost text-sm text-brand-600 hover:text-brand-700 hover:bg-brand-50">
|
||||
<Plus class="w-4 h-4" /> {{ $t('workspace.quickQuestions.add') }}
|
||||
</button>
|
||||
</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">{{ $t('workspace.noFavorites') }}</div>
|
||||
<div class="grid grid-cols-1 md:grid-cols-3 lg:grid-cols-4 gap-6">
|
||||
<div v-for="agent in favoriteAgents" :key="agent.id" @click="navigateToChat(agent.id)"
|
||||
class="card p-5 cursor-pointer relative group/card hover:-translate-y-1 hover:shadow-lg hover:border-brand-200 bg-gradient-to-br from-white to-slate-50/50">
|
||||
<div class="w-12 h-12 bg-brand-100 rounded-xl flex items-center justify-center text-brand-600 mb-4 shadow-sm group-hover/card:scale-110 transition-transform duration-300">
|
||||
<img v-if="agent.icon_url" :src="agent.icon_url" class="w-7 h-7" />
|
||||
<Bot v-else class="w-7 h-7" />
|
||||
</div>
|
||||
<div class="font-bold text-slate-900 mb-1 group-hover/card:text-brand-700 transition-colors">{{ agent.name }}</div>
|
||||
<div class="text-xs text-slate-500 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 border border-slate-200 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 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 rounded-2xl overflow-hidden bg-white shadow-sm hover:shadow-md transition-shadow h-[500px] flex flex-col">
|
||||
<div class="bg-slate-50 px-4 py-3 text-sm font-bold text-slate-700 flex justify-between items-center border-b border-slate-100">
|
||||
<span>{{ agent.name }}</span>
|
||||
<a :href="`/chat/${agent.id}`" target="_blank" class="text-brand-600 hover:text-brand-700 hover:bg-brand-50 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"></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-1 md:grid-cols-3 lg:grid-cols-4 gap-6">
|
||||
<div v-for="agent in otherAgents" :key="agent.id"
|
||||
class="card p-5 cursor-pointer relative group/card hover:-translate-y-1 hover:border-brand-200">
|
||||
<div class="flex items-start justify-between mb-4">
|
||||
<div class="w-10 h-10 bg-slate-50 rounded-xl flex items-center justify-center text-slate-500 group-hover/card:bg-brand-50 group-hover/card:text-brand-600 transition-colors">
|
||||
<img v-if="agent.icon_url" :src="agent.icon_url" class="w-6 h-6" />
|
||||
<Bot v-else class="w-6 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="font-bold text-slate-900 mb-1 group-hover/card:text-brand-700 transition-colors">{{ agent.name }}</h3>
|
||||
<p class="text-xs text-slate-500 line-clamp-2 h-8 leading-relaxed">{{ agent.description }}</p>
|
||||
<button @click="navigateToChat(agent.id)" class="mt-5 w-full py-2 bg-slate-50 text-slate-600 text-xs font-bold rounded-xl hover:bg-brand-600 hover:text-white transition-all duration-300">
|
||||
{{ $t('workspace.startChatShort') }}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</main>
|
||||
|
||||
<!-- Register Modal -->
|
||||
<div v-if="showRegisterModal" class="fixed inset-0 bg-slate-900/40 backdrop-blur-sm flex items-center justify-center z-50 p-4 animate-fade-in">
|
||||
<div class="bg-white rounded-3xl shadow-2xl w-full max-w-md p-8 animate-slide-up">
|
||||
<h3 class="text-xl font-bold text-slate-900 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>
|
||||
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
/* Scoped styles removed in favor of global utilities in style.css */
|
||||
</style>
|
||||
Reference in new issue
Block a user