260304调整
This commit is contained in:
1 parent
b48f1e592a
commit
a0c8721fbb
16 files changed
+1382
-291
No files matched your search
@@ -12,6 +12,7 @@
|
||||
import { ref, onMounted, watch, computed } from 'vue';
|
||||
import { useRouter } from 'vue-router';
|
||||
import { useI18n } from 'vue-i18n';
|
||||
import { config } from '../config';
|
||||
import {
|
||||
ArrowLeft,
|
||||
Save,
|
||||
@@ -36,16 +37,33 @@ import * as XLSX from 'xlsx';
|
||||
|
||||
const { t, locale } = useI18n();
|
||||
|
||||
const sidebarItems = computed(() => [
|
||||
{ id: 'dashboard', icon: LayoutDashboard, label: t('admin.nav.dashboard') },
|
||||
{ id: 'approvals', icon: UserPlus, label: t('admin.nav.approvals'), badge: pendingUsers.value.length },
|
||||
{ id: 'users', icon: UserCog, label: t('admin.nav.users') },
|
||||
{ id: 'departments', icon: Building, label: t('admin.nav.departments') },
|
||||
{ id: 'agents', icon: Bot, label: t('admin.nav.agents') },
|
||||
{ id: 'questions', icon: MessageCircleQuestion, label: t('admin.nav.questions') },
|
||||
{ id: 'permissions', icon: Users, label: t('admin.nav.permissions') },
|
||||
{ id: 'requests', icon: ShieldCheck, label: t('admin.nav.requests'), badge: permissionRequests.value.filter(r => r.status === 'pending').length },
|
||||
]);
|
||||
const sidebarItems = computed(() => {
|
||||
const items = [
|
||||
{ id: 'dashboard', icon: LayoutDashboard, label: t('admin.nav.dashboard') },
|
||||
{ id: 'approvals', icon: UserPlus, label: t('admin.nav.approvals'), badge: pendingUsers.value.length },
|
||||
{ id: 'users', icon: UserCog, label: t('admin.nav.users') },
|
||||
{ id: 'departments', icon: Building, label: t('admin.nav.departments') },
|
||||
{ id: 'agents', icon: Bot, label: t('admin.nav.agents') },
|
||||
{ id: 'questions', icon: MessageCircleQuestion, label: t('admin.nav.questions') },
|
||||
{ id: 'permissions', icon: Users, label: t('admin.nav.permissions') },
|
||||
{ id: 'requests', icon: ShieldCheck, label: t('admin.nav.requests'), badge: permissionRequests.value.filter(r => r.status === 'pending').length },
|
||||
{ id: 'reports', icon: BarChart2, label: t('admin.nav.reports') },
|
||||
];
|
||||
|
||||
return items.filter(item => {
|
||||
if (config.admin.modules[item.id as keyof typeof config.admin.modules] === false) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
});
|
||||
});
|
||||
|
||||
onMounted(() => {
|
||||
const allowed = sidebarItems.value.map(i => i.id);
|
||||
if (!allowed.includes(activeModule.value)) {
|
||||
activeModule.value = (allowed[0] ?? 'agents') as any;
|
||||
}
|
||||
});
|
||||
|
||||
// 获取路由实例,用于页面跳转
|
||||
interface AgentRow {
|
||||
@@ -229,14 +247,14 @@ const saveUser = async () => {
|
||||
});
|
||||
if (!res.ok) {
|
||||
const err = await res.json();
|
||||
throw new Error(err.error || 'Failed to create user');
|
||||
throw new Error(err.error || t('admin.msg.failed'));
|
||||
}
|
||||
}
|
||||
await loadUsers();
|
||||
showUserModal.value = false;
|
||||
} catch (e: any) {
|
||||
console.error(e);
|
||||
alert(e.message || '操作失败');
|
||||
alert(e.message || t('admin.msg.failed'));
|
||||
} finally {
|
||||
isSaving.value = false;
|
||||
}
|
||||
@@ -284,7 +302,7 @@ const loadDepartments = async () => {
|
||||
};
|
||||
|
||||
const saveDepartment = async () => {
|
||||
if (!editingDept.value.name) return alert('Name is required');
|
||||
if (!editingDept.value.name) return alert(t('admin.dept.msg.nameRequired'));
|
||||
try {
|
||||
if (editingDept.value.id) {
|
||||
const res = await fetch(`/api/admin/departments/${editingDept.value.id}`, {
|
||||
@@ -294,7 +312,7 @@ const saveDepartment = async () => {
|
||||
});
|
||||
if (!res.ok) {
|
||||
const err = await res.json();
|
||||
throw new Error(err.error || 'Failed');
|
||||
throw new Error(err.error || t('admin.msg.failed'));
|
||||
}
|
||||
} else {
|
||||
const res = await fetch('/api/admin/departments', {
|
||||
@@ -304,7 +322,7 @@ const saveDepartment = async () => {
|
||||
});
|
||||
if (!res.ok) {
|
||||
const err = await res.json();
|
||||
throw new Error(err.error || 'Failed');
|
||||
throw new Error(err.error || t('admin.msg.failed'));
|
||||
}
|
||||
}
|
||||
await loadDepartments();
|
||||
@@ -417,7 +435,7 @@ const cleanRejectedUsers = async () => {
|
||||
});
|
||||
const data = await res.json();
|
||||
if (res.ok) {
|
||||
alert(t('admin.user.msgs.batchDeleteSuccess', { count: data.deleted_count }));
|
||||
alert(t('admin.msg.batchDeleteResult', { count: data.deleted_count }));
|
||||
loadUsers();
|
||||
} else {
|
||||
alert(data.error);
|
||||
@@ -440,7 +458,7 @@ const batchDeleteUsers = async () => {
|
||||
});
|
||||
const data = await res.json();
|
||||
if (res.ok) {
|
||||
alert(`Deleted ${data.deleted_count} users.`);
|
||||
alert(t('admin.msg.batchDeleteResult', { count: data.deleted_count }));
|
||||
selectedUserIds.value = [];
|
||||
loadUsers();
|
||||
} else {
|
||||
@@ -448,7 +466,7 @@ const batchDeleteUsers = async () => {
|
||||
}
|
||||
} catch (e) {
|
||||
console.error(e);
|
||||
alert('Request failed');
|
||||
alert(t('admin.msg.requestFailed'));
|
||||
}
|
||||
};
|
||||
|
||||
@@ -490,7 +508,7 @@ const submitBatchEdit = async () => {
|
||||
if (batchEditForm.value.status) data.status = batchEditForm.value.status;
|
||||
|
||||
if (Object.keys(data).length === 0) {
|
||||
alert('Please enter at least one field to update');
|
||||
alert(t('admin.msg.enterOneField'));
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -503,7 +521,7 @@ const submitBatchEdit = async () => {
|
||||
})
|
||||
});
|
||||
|
||||
if (!res.ok) throw new Error('Batch update failed');
|
||||
if (!res.ok) throw new Error(t('admin.msg.batchUpdateFailed'));
|
||||
|
||||
await loadUsers();
|
||||
showBatchEditModal.value = false;
|
||||
@@ -534,24 +552,29 @@ const submitBatchPermission = async () => {
|
||||
})
|
||||
});
|
||||
|
||||
if (!res.ok) throw new Error('Batch permission update failed');
|
||||
if (!res.ok) throw new Error(t('admin.msg.batchPermissionUpdateFailed'));
|
||||
|
||||
await loadUsers();
|
||||
showBatchPermissionModal.value = false;
|
||||
selectedUserIds.value = [];
|
||||
} catch (e: any) {
|
||||
console.error(e);
|
||||
alert('Batch permission update failed');
|
||||
alert(t('admin.msg.batchPermissionUpdateFailed'));
|
||||
} finally {
|
||||
isSaving.value = false;
|
||||
}
|
||||
};
|
||||
|
||||
const getAuthHeaders = () => {
|
||||
let stored = localStorage.getItem('hxops_user');
|
||||
if (!stored) stored = sessionStorage.getItem('hxops_user');
|
||||
|
||||
if (!stored) return {};
|
||||
|
||||
try {
|
||||
const stored = localStorage.getItem('hxops_user');
|
||||
if (!stored) return {};
|
||||
const user = JSON.parse(stored) as { id?: number; username: string; role: string };
|
||||
const data = JSON.parse(stored);
|
||||
const user = data.user || data; // Handle both wrapped and unwrapped format
|
||||
|
||||
const headers: Record<string, string> = {
|
||||
'X-Username': user.username,
|
||||
'X-Role': user.role,
|
||||
@@ -561,7 +584,6 @@ const getAuthHeaders = () => {
|
||||
}
|
||||
return headers;
|
||||
} catch (e) {
|
||||
console.error('Error parsing user from localStorage:', e);
|
||||
return {};
|
||||
}
|
||||
};
|
||||
@@ -1221,7 +1243,7 @@ const handlePermissionImport = async (event: Event) => {
|
||||
</button>
|
||||
|
||||
<!-- Reports Submenu -->
|
||||
<div class="flex flex-col flex-shrink-0">
|
||||
<div v-if="config.admin.modules.reports !== false" class="flex flex-col flex-shrink-0">
|
||||
<button
|
||||
@click="expandedReports = !expandedReports"
|
||||
class="group px-4 py-3 text-left text-sm font-medium rounded-xl transition-all flex items-center justify-between gap-3 relative overflow-hidden whitespace-nowrap text-slate-600 hover:bg-slate-50 hover:text-slate-900"
|
||||
@@ -1358,7 +1380,7 @@ const handlePermissionImport = async (event: Event) => {
|
||||
<td class="px-8 py-5 text-sm text-slate-500">{{ user.phone_number || '-' }}</td>
|
||||
<td class="px-8 py-5">
|
||||
<span class="px-2.5 py-0.5 rounded-full text-xs font-medium bg-yellow-100 text-yellow-800 border border-yellow-200">
|
||||
{{ user.role }}
|
||||
{{ t('admin.role.' + user.role) }}
|
||||
</span>
|
||||
</td>
|
||||
<td class="px-8 py-5 text-right flex items-center justify-end gap-2">
|
||||
@@ -1497,7 +1519,7 @@ const handlePermissionImport = async (event: Event) => {
|
||||
<td class="px-6 py-4">
|
||||
<span class="px-2.5 py-0.5 rounded-full text-xs font-medium border"
|
||||
:class="user.role === 'admin' ? 'bg-purple-50 text-purple-700 border-purple-100' : 'bg-blue-50 text-blue-700 border-blue-100'">
|
||||
{{ user.role }}
|
||||
{{ t('admin.role.' + user.role) }}
|
||||
</span>
|
||||
</td>
|
||||
<td class="px-6 py-4 text-sm text-slate-500">
|
||||
@@ -1510,7 +1532,7 @@ const handlePermissionImport = async (event: Event) => {
|
||||
'bg-yellow-50 text-yellow-700 border-yellow-100': user.status === 'pending',
|
||||
'bg-red-50 text-red-700 border-red-100': user.status === 'disabled' || user.status === 'rejected'
|
||||
}">
|
||||
{{ user.status }}
|
||||
{{ t('admin.status.' + user.status) }}
|
||||
</span>
|
||||
</td>
|
||||
<td class="px-6 py-4 text-right">
|
||||
@@ -1636,8 +1658,8 @@ const handlePermissionImport = async (event: Event) => {
|
||||
<div class="space-y-2">
|
||||
<label class="text-xs font-bold text-gray-500 uppercase tracking-wider">{{ t('admin.agent.fields.type') }}</label>
|
||||
<select v-model="newAgent.type" class="w-full border-gray-200 rounded-xl px-4 py-3 text-base focus:ring-2 focus:ring-blue-500/20 focus:border-blue-500 outline-none transition-all shadow-sm bg-white">
|
||||
<option value="api">API Integration (Dify)</option>
|
||||
<option value="iframe">Iframe Embed</option>
|
||||
<option value="api">{{ t('admin.agent.fields.types.api') }}</option>
|
||||
<option value="iframe">{{ t('admin.agent.fields.types.iframe') }}</option>
|
||||
</select>
|
||||
</div>
|
||||
|
||||
@@ -1746,7 +1768,7 @@ const handlePermissionImport = async (event: Event) => {
|
||||
<td class="px-8 py-5">
|
||||
<span class="inline-flex items-center gap-1.5 px-3 py-1 rounded-full text-xs font-medium bg-green-50 text-green-700 border border-green-100">
|
||||
<span class="w-2 h-2 rounded-full bg-green-500"></span>
|
||||
Active
|
||||
{{ t('admin.status.active') }}
|
||||
</span>
|
||||
</td>
|
||||
<td class="px-8 py-5 text-right flex justify-end gap-2">
|
||||
@@ -1892,8 +1914,8 @@ const handlePermissionImport = async (event: Event) => {
|
||||
<input v-model="permissionFilters.department" :placeholder="t('admin.perm.filterDept')" class="px-3 py-2 border rounded-lg text-sm w-48 focus:ring-2 focus:ring-blue-500/20 focus:border-blue-500 outline-none" />
|
||||
<select v-model="permissionFilters.role" class="px-3 py-2 border rounded-lg text-sm w-32 focus:ring-2 focus:ring-blue-500/20 focus:border-blue-500 outline-none bg-white">
|
||||
<option value="">{{ t('admin.perm.allRoles') }}</option>
|
||||
<option value="user">User</option>
|
||||
<option value="admin">Admin</option>
|
||||
<option value="user">{{ t('admin.role.user') }}</option>
|
||||
<option value="admin">{{ t('admin.role.admin') }}</option>
|
||||
</select>
|
||||
</div>
|
||||
|
||||
@@ -1961,25 +1983,25 @@ const handlePermissionImport = async (event: Event) => {
|
||||
class="bg-white rounded-2xl border border-gray-100 shadow-sm overflow-hidden animate-fade-in-up"
|
||||
>
|
||||
<div class="px-8 py-6 border-b border-gray-100 bg-white">
|
||||
<h2 class="font-bold text-gray-900 text-lg">Permission Requests</h2>
|
||||
<p class="text-sm text-gray-500 mt-1">Review user requests for agent access</p>
|
||||
<h2 class="font-bold text-gray-900 text-lg">{{ t('admin.request.title') }}</h2>
|
||||
<p class="text-sm text-gray-500 mt-1">{{ t('admin.request.subtitle') }}</p>
|
||||
</div>
|
||||
|
||||
<div v-if="permissionRequests.length === 0" class="flex flex-col items-center justify-center py-16 text-gray-400">
|
||||
<div class="w-16 h-16 bg-gray-50 rounded-full flex items-center justify-center mb-4">
|
||||
<ShieldCheck class="w-8 h-8 text-gray-300" />
|
||||
</div>
|
||||
<p>No pending requests</p>
|
||||
<p>{{ t('admin.request.noPending') }}</p>
|
||||
</div>
|
||||
|
||||
<table v-else class="w-full text-left">
|
||||
<thead class="bg-gray-50/50 border-b border-gray-100">
|
||||
<tr>
|
||||
<th class="px-8 py-4 text-xs font-semibold text-gray-500 uppercase tracking-wider">User ID</th>
|
||||
<th class="px-8 py-4 text-xs font-semibold text-gray-500 uppercase tracking-wider">Target Agent</th>
|
||||
<th class="px-8 py-4 text-xs font-semibold text-gray-500 uppercase tracking-wider">Reason</th>
|
||||
<th class="px-8 py-4 text-xs font-semibold text-gray-500 uppercase tracking-wider">Status</th>
|
||||
<th class="px-8 py-4 text-xs font-semibold text-gray-500 uppercase tracking-wider text-right">Actions</th>
|
||||
<th class="px-8 py-4 text-xs font-semibold text-gray-500 uppercase tracking-wider">{{ t('admin.request.headers.userId') }}</th>
|
||||
<th class="px-8 py-4 text-xs font-semibold text-gray-500 uppercase tracking-wider">{{ t('admin.request.headers.targetAgent') }}</th>
|
||||
<th class="px-8 py-4 text-xs font-semibold text-gray-500 uppercase tracking-wider">{{ t('admin.request.headers.reason') }}</th>
|
||||
<th class="px-8 py-4 text-xs font-semibold text-gray-500 uppercase tracking-wider">{{ t('admin.request.headers.status') }}</th>
|
||||
<th class="px-8 py-4 text-xs font-semibold text-gray-500 uppercase tracking-wider text-right">{{ t('admin.request.headers.actions') }}</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody class="divide-y divide-gray-100">
|
||||
@@ -1989,7 +2011,7 @@ const handlePermissionImport = async (event: Event) => {
|
||||
<td class="px-8 py-4 text-sm text-gray-500 max-w-xs truncate" :title="req.reason">{{ req.reason || '-' }}</td>
|
||||
<td class="px-8 py-4">
|
||||
<span class="inline-flex items-center px-2.5 py-0.5 rounded-full text-xs font-medium bg-yellow-50 text-yellow-700 border border-yellow-100">
|
||||
{{ req.status }}
|
||||
{{ t('admin.status.' + req.status) }}
|
||||
</span>
|
||||
</td>
|
||||
<td class="px-8 py-4 text-right">
|
||||
@@ -1998,13 +2020,13 @@ const handlePermissionImport = async (event: Event) => {
|
||||
class="text-green-600 hover:text-green-800 text-sm font-medium hover:underline"
|
||||
@click="approvePermissionRequest(req.id)"
|
||||
>
|
||||
Approve
|
||||
{{ t('admin.request.approve') }}
|
||||
</button>
|
||||
<button
|
||||
class="text-red-500 hover:text-red-700 text-sm font-medium hover:underline"
|
||||
@click="rejectPermissionRequest(req.id)"
|
||||
>
|
||||
Reject
|
||||
{{ t('admin.request.reject') }}
|
||||
</button>
|
||||
</div>
|
||||
</td>
|
||||
@@ -2023,9 +2045,9 @@ const handlePermissionImport = async (event: Event) => {
|
||||
<div>
|
||||
<h2 class="font-bold text-gray-900 text-lg flex items-center gap-2">
|
||||
<BarChart2 class="w-5 h-5 text-blue-600" />
|
||||
Data Reports: {{ currentTable.replace(/_/g, ' ').replace(/\b\w/g, l => l.toUpperCase()) }}
|
||||
{{ t('admin.report.title', { table: currentTable.replace(/_/g, ' ').replace(/\b\w/g, l => l.toUpperCase()) }) }}
|
||||
</h2>
|
||||
<p class="text-sm text-gray-500 mt-1">Raw data view and statistics</p>
|
||||
<p class="text-sm text-gray-500 mt-1">{{ t('admin.report.subtitle') }}</p>
|
||||
</div>
|
||||
<div class="flex items-center gap-4">
|
||||
|
||||
@@ -2034,13 +2056,13 @@ const handlePermissionImport = async (event: Event) => {
|
||||
class="flex items-center gap-2 px-4 py-2 bg-green-600 text-white text-sm font-medium rounded-xl hover:bg-green-700 transition-all shadow-md shadow-green-200 active:scale-95"
|
||||
>
|
||||
<Download class="w-4 h-4" />
|
||||
Export Excel
|
||||
{{ t('admin.report.export') }}
|
||||
</button>
|
||||
|
||||
<button
|
||||
@click="isFullScreen = !isFullScreen"
|
||||
class="p-2 hover:bg-gray-100 rounded-xl transition-colors text-gray-500 hover:text-gray-900 border border-transparent hover:border-gray-200"
|
||||
:title="isFullScreen ? 'Exit Fullscreen' : 'Enter Fullscreen'"
|
||||
:title="isFullScreen ? t('admin.report.exitFullscreen') : t('admin.report.enterFullscreen')"
|
||||
>
|
||||
<svg v-if="!isFullScreen" xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M8 3H5a2 2 0 0 0-2 2v3"/><path d="M16 3h3a2 2 0 0 1 2 2v3"/><path d="M8 21H5a2 2 0 0 1-2-2v-3"/><path d="M16 21h3a2 2 0 0 1 2 2v-3"/></svg>
|
||||
<svg v-else xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M8 3v3a2 2 0 0 1-2 2H3"/><path d="M21 8h-3a2 2 0 0 1-2-2V3"/><path d="M3 16h3a2 2 0 0 1 2 2v3"/><path d="M16 21v-3a2 2 0 0 1 2-2h3"/></svg>
|
||||
@@ -2194,8 +2216,8 @@ const handlePermissionImport = async (event: Event) => {
|
||||
v-model="editingUser.role"
|
||||
class="w-full border-gray-200 rounded-xl px-4 py-3 text-sm focus:ring-2 focus:ring-blue-500/20 focus:border-blue-500 outline-none transition-all shadow-sm bg-gray-50 focus:bg-white"
|
||||
>
|
||||
<option value="user">User</option>
|
||||
<option value="admin">Admin</option>
|
||||
<option value="user">{{ t('admin.role.user') }}</option>
|
||||
<option value="admin">{{ t('admin.role.admin') }}</option>
|
||||
</select>
|
||||
</div>
|
||||
<div class="space-y-1.5">
|
||||
@@ -2232,8 +2254,8 @@ const handlePermissionImport = async (event: Event) => {
|
||||
<div class="bg-white rounded-2xl shadow-xl w-full max-w-2xl max-h-[90vh] flex flex-col animate-fade-in-up">
|
||||
<div class="px-8 py-6 border-b border-gray-100 flex justify-between items-center">
|
||||
<div>
|
||||
<h3 class="text-lg font-bold text-gray-900">Manage Access</h3>
|
||||
<p class="text-sm text-gray-500">Agent: <span class="font-medium text-blue-600">{{ selectedAgentForPermissions.name }}</span></p>
|
||||
<h3 class="text-lg font-bold text-gray-900">{{ t('admin.perm.agentModal.title') }}</h3>
|
||||
<p class="text-sm text-gray-500">{{ t('admin.perm.agentModal.agent') }} <span class="font-medium text-blue-600">{{ selectedAgentForPermissions.name }}</span></p>
|
||||
</div>
|
||||
<button @click="showAgentPermissionModal = false" class="p-2 hover:bg-gray-100 rounded-full text-gray-400 hover:text-gray-600 transition-colors">
|
||||
<svg xmlns="http://www.w3.org/2000/svg" class="h-6 w-6" fill="none" viewBox="0 0 24 24" stroke="currentColor">
|
||||
@@ -2272,7 +2294,7 @@ const handlePermissionImport = async (event: Event) => {
|
||||
@click="showAgentPermissionModal = false"
|
||||
class="px-5 py-2.5 text-gray-600 font-medium hover:bg-gray-200 rounded-xl transition-colors"
|
||||
>
|
||||
Cancel
|
||||
{{ t('admin.cancel') }}
|
||||
</button>
|
||||
<button
|
||||
@click="saveAgentPermissions"
|
||||
@@ -2280,7 +2302,7 @@ const handlePermissionImport = async (event: Event) => {
|
||||
class="px-6 py-2.5 bg-blue-600 text-white font-medium rounded-xl hover:bg-blue-700 transition-colors shadow-lg shadow-blue-200 disabled:opacity-50 disabled:cursor-not-allowed flex items-center gap-2"
|
||||
>
|
||||
<div v-if="isSaving" class="animate-spin rounded-full h-4 w-4 border-2 border-white border-t-transparent"></div>
|
||||
Save Changes
|
||||
{{ t('admin.perm.agentModal.save') }}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
@@ -2304,16 +2326,16 @@ const handlePermissionImport = async (event: Event) => {
|
||||
<label class="block text-xs font-semibold text-gray-500 uppercase tracking-wider">{{ t('admin.batchEdit.fields.role') }}</label>
|
||||
<select v-model="batchEditForm.role" class="w-full border-gray-200 rounded-xl px-4 py-3 text-sm focus:ring-2 focus:ring-blue-500/20 focus:border-blue-500 outline-none bg-gray-50 focus:bg-white">
|
||||
<option value="">{{ t('admin.batchEdit.fields.keepUnchanged') }}</option>
|
||||
<option value="user">User</option>
|
||||
<option value="admin">Admin</option>
|
||||
<option value="user">{{ t('admin.role.user') }}</option>
|
||||
<option value="admin">{{ t('admin.role.admin') }}</option>
|
||||
</select>
|
||||
</div>
|
||||
<div class="space-y-1.5">
|
||||
<label class="block text-xs font-semibold text-gray-500 uppercase tracking-wider">{{ t('admin.batchEdit.fields.status') }}</label>
|
||||
<select v-model="batchEditForm.status" class="w-full border-gray-200 rounded-xl px-4 py-3 text-sm focus:ring-2 focus:ring-blue-500/20 focus:border-blue-500 outline-none bg-gray-50 focus:bg-white">
|
||||
<option value="">{{ t('admin.batchEdit.fields.keepUnchanged') }}</option>
|
||||
<option value="active">Active</option>
|
||||
<option value="disabled">Disabled</option>
|
||||
<option value="active">{{ t('admin.status.active') }}</option>
|
||||
<option value="disabled">{{ t('admin.status.disabled') }}</option>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
@@ -2408,7 +2430,7 @@ const handlePermissionImport = async (event: Event) => {
|
||||
<button
|
||||
@click="deleteDepartment(d.id)"
|
||||
class="text-gray-400 hover:text-red-500 hover:bg-red-50 p-1.5 rounded-lg transition-colors opacity-0 group-hover:opacity-100"
|
||||
title="Delete"
|
||||
:title="t('admin.delete')"
|
||||
>
|
||||
<Trash2 class="w-4 h-4" />
|
||||
</button>
|
||||
|
||||
+143
-40
@@ -13,16 +13,28 @@
|
||||
import { ref, onMounted, computed } from 'vue';
|
||||
import { useI18n } from 'vue-i18n';
|
||||
import { useChat } from '../composables/useChat';
|
||||
import { Send, User, Bot, Loader2, ArrowLeft, Plus, Menu, Star } from 'lucide-vue-next';
|
||||
import { Send, User, Bot, Loader2, ArrowLeft, Plus, Menu, Star, Copy, Edit2, RotateCw, Check } from 'lucide-vue-next';
|
||||
import { marked } from 'marked';
|
||||
import { useRoute, useRouter } from 'vue-router';
|
||||
import { config } from '../config';
|
||||
|
||||
const { t, locale } = useI18n();
|
||||
|
||||
const renderMarkdown = (text: string) => {
|
||||
if (!text) return '';
|
||||
try {
|
||||
return marked.parse(text);
|
||||
} catch (e) {
|
||||
return text;
|
||||
}
|
||||
};
|
||||
const route = useRoute();
|
||||
const router = useRouter();
|
||||
const agentId = Number(route.params.agentId);
|
||||
|
||||
// Sidebar state for mobile
|
||||
const isSidebarOpen = ref(false);
|
||||
const copiedIndex = ref<number | null>(null);
|
||||
|
||||
// 从 useChat 中解构出消息列表、思考状态、会话 ID 与发送函数
|
||||
const { messages, isThinking, conversationId, sendMessage } = useChat();
|
||||
@@ -44,34 +56,41 @@ const presetQuestion = computed(() => {
|
||||
});
|
||||
|
||||
const getAuthHeaders = () => {
|
||||
const stored = localStorage.getItem('hxops_user');
|
||||
let stored = localStorage.getItem('hxops_user');
|
||||
if (!stored) stored = sessionStorage.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);
|
||||
|
||||
try {
|
||||
const data = JSON.parse(stored);
|
||||
const user = data.user || data;
|
||||
|
||||
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;
|
||||
} catch (e) {
|
||||
return {};
|
||||
}
|
||||
return headers;
|
||||
};
|
||||
|
||||
/**
|
||||
* handleSend
|
||||
* 用途:将输入框内容发送给当前 Agent
|
||||
* 核心逻辑:
|
||||
* 1. 校验输入非空且当前不在思考状态
|
||||
* 2. 调用 sendMessage
|
||||
* 3. 清空输入框
|
||||
*/
|
||||
|
||||
const handleSend = async () => {
|
||||
if (!input.value.trim() || isThinking.value) return;
|
||||
const userInput = input.value;
|
||||
input.value = '';
|
||||
const handleSend = async (textOrEvent?: string | Event) => {
|
||||
const content = (typeof textOrEvent === 'string' ? textOrEvent : null) || input.value;
|
||||
if (!content.trim() || isThinking.value) return;
|
||||
|
||||
await sendMessage(userInput, agentId);
|
||||
// Clear input if sending from input box (not resending/regenerating)
|
||||
if (typeof textOrEvent !== 'string') input.value = '';
|
||||
|
||||
await sendMessage(content, agentId);
|
||||
|
||||
// 发送完成后刷新历史记录,确保新会话出现
|
||||
if (!conversationId.value && history.value.length === 0) {
|
||||
@@ -83,10 +102,29 @@ const handleSend = async () => {
|
||||
}
|
||||
};
|
||||
|
||||
const copyToClipboard = async (text: string, index: number) => {
|
||||
try {
|
||||
await navigator.clipboard.writeText(text);
|
||||
copiedIndex.value = index;
|
||||
setTimeout(() => {
|
||||
copiedIndex.value = null;
|
||||
}, 2000);
|
||||
} catch (err) {
|
||||
console.error('Failed to copy:', err);
|
||||
}
|
||||
};
|
||||
|
||||
const regenerate = () => {
|
||||
const lastUserMsg = [...messages.value].reverse().find(m => m.role === 'user');
|
||||
if (lastUserMsg) {
|
||||
handleSend(lastUserMsg.content);
|
||||
}
|
||||
};
|
||||
|
||||
// 加载历史记录
|
||||
const loadHistory = async () => {
|
||||
try {
|
||||
const res = await fetch(`/api/chat/sessions`, { headers: getAuthHeaders() });
|
||||
const res = await fetch(`/api/chat/sessions?agent_id=${agentId}`, { headers: getAuthHeaders() });
|
||||
if (res.ok) {
|
||||
history.value = await res.json();
|
||||
}
|
||||
@@ -99,7 +137,7 @@ const loadConversation = async (id: string) => {
|
||||
if (conversationId.value === id) return;
|
||||
|
||||
try {
|
||||
const res = await fetch(`/api/chat/messages?conversation_id=${id}`, { headers: getAuthHeaders() });
|
||||
const res = await fetch(`/api/chat/messages?conversation_id=${id}&agent_id=${agentId}`, { headers: getAuthHeaders() });
|
||||
if (res.ok) {
|
||||
messages.value = await res.json();
|
||||
conversationId.value = id;
|
||||
@@ -122,17 +160,27 @@ const startNewChat = () => {
|
||||
feedbackSubmitted.value = false;
|
||||
};
|
||||
|
||||
// 组件挂载时,如果存在预设问题,则自动触发一次发送
|
||||
onMounted(async () => {
|
||||
// Fetch Agent Details
|
||||
const loadAgent = async () => {
|
||||
try {
|
||||
const agentRes = await fetch(`/api/user/agents/${agentId}`, { headers: getAuthHeaders() });
|
||||
if (agentRes.ok) {
|
||||
currentAgent.value = await agentRes.json();
|
||||
const res = await fetch(`/api/user/agents/${agentId}`, { headers: getAuthHeaders() });
|
||||
if (res.ok) {
|
||||
currentAgent.value = await res.json();
|
||||
} else {
|
||||
if (res.status === 403) {
|
||||
alert(t('workspace.permission.denied') || 'Access denied');
|
||||
router.push('/');
|
||||
return;
|
||||
}
|
||||
currentAgent.value = { name: t('workspace.unknownAgent') };
|
||||
}
|
||||
} catch (e) {
|
||||
console.error('Failed to load agent details', e);
|
||||
console.error('Failed to load agent', e);
|
||||
}
|
||||
};
|
||||
|
||||
// 组件挂载时,如果存在预设问题,则自动触发一次发送
|
||||
onMounted(async () => {
|
||||
await loadAgent();
|
||||
|
||||
await loadHistory();
|
||||
|
||||
@@ -140,11 +188,8 @@ onMounted(async () => {
|
||||
input.value = presetQuestion.value;
|
||||
handleSend();
|
||||
}
|
||||
const res = await fetch('/api/user/config', { headers: getAuthHeaders() });
|
||||
if (res.ok) {
|
||||
const data = await res.json();
|
||||
enableFeedback.value = !!data.feedback_enabled;
|
||||
}
|
||||
// Use config from config.ts instead of API
|
||||
enableFeedback.value = config.workspace.enableFeedback;
|
||||
});
|
||||
|
||||
/**
|
||||
@@ -264,7 +309,7 @@ const submitFeedback = async () => {
|
||||
<!-- Chat Content -->
|
||||
<div v-if="!currentAgent" class="flex-1 flex flex-col items-center justify-center space-y-4">
|
||||
<Loader2 class="w-10 h-10 animate-spin text-brand-500" />
|
||||
<p class="text-slate-400 text-sm animate-pulse">Loading agent...</p>
|
||||
<p class="text-slate-400 text-sm animate-pulse">{{ $t('chat.loadingAgent') }}</p>
|
||||
</div>
|
||||
|
||||
<div v-else-if="currentAgent.type === 'iframe'" class="flex-1 w-full h-full bg-white relative">
|
||||
@@ -285,7 +330,12 @@ const submitFeedback = async () => {
|
||||
<p class="text-slate-500 text-lg max-w-md text-center leading-relaxed">{{ $t('chat.welcome.subtitle') }}</p>
|
||||
|
||||
<div class="grid grid-cols-1 md:grid-cols-2 gap-4 mt-12 w-full max-w-2xl">
|
||||
<button v-for="suggestion in ['What can you do?', 'Help me write a report', 'Analyze this data', 'Creative writing']"
|
||||
<button v-for="suggestion in (currentAgent.suggested_questions && currentAgent.suggested_questions.length > 0 ? currentAgent.suggested_questions : [
|
||||
$t('chat.suggestions.whatCanYouDo'),
|
||||
$t('chat.suggestions.helpWriteReport'),
|
||||
$t('chat.suggestions.analyzeData'),
|
||||
$t('chat.suggestions.creativeWriting')
|
||||
])"
|
||||
:key="suggestion"
|
||||
@click="input = suggestion; handleSend()"
|
||||
class="p-4 bg-white border border-slate-200 rounded-xl hover:border-brand-400 hover:shadow-md hover:text-brand-700 text-slate-600 text-sm font-medium transition-all text-left">
|
||||
@@ -306,11 +356,64 @@ const submitFeedback = async () => {
|
||||
</div>
|
||||
|
||||
<!-- Message Bubble -->
|
||||
<div
|
||||
class="py-3.5 px-6 rounded-2xl shadow-sm max-w-[85%] md:max-w-[75%] leading-relaxed text-[15px]"
|
||||
:class="msg.role === 'user' ? 'bg-brand-600 text-white rounded-tr-sm shadow-brand-500/20' : 'bg-white border border-slate-100 text-slate-800 rounded-tl-sm shadow-slate-200/50'"
|
||||
>
|
||||
<div class="whitespace-pre-wrap prose prose-sm max-w-none" :class="msg.role === 'user' ? 'prose-invert' : 'prose-slate'">{{ msg.content }}</div>
|
||||
<div class="flex flex-col max-w-[85%] md:max-w-[75%]">
|
||||
<div
|
||||
class="py-3.5 px-6 rounded-2xl shadow-sm leading-relaxed text-[15px]"
|
||||
:class="msg.role === 'user' ? 'bg-brand-600 text-white rounded-tr-sm shadow-brand-500/20' : 'bg-white border border-slate-100 text-slate-800 rounded-tl-sm shadow-slate-200/50'"
|
||||
>
|
||||
<div
|
||||
v-if="msg.role === 'user'"
|
||||
class="whitespace-pre-wrap prose prose-sm max-w-none text-white prose-invert"
|
||||
>{{ msg.content }}</div>
|
||||
<div
|
||||
v-else
|
||||
class="prose prose-sm max-w-none text-slate-800 prose-headings:font-bold prose-a:text-brand-600 prose-code:bg-slate-100 prose-code:text-brand-600 prose-code:px-1 prose-code:rounded prose-pre:bg-slate-800 prose-pre:text-slate-100"
|
||||
v-html="renderMarkdown(msg.content)"
|
||||
></div>
|
||||
</div>
|
||||
|
||||
<!-- Message Actions -->
|
||||
<div
|
||||
class="flex items-center gap-1 mt-1 opacity-0 group-hover:opacity-100 transition-opacity"
|
||||
:class="msg.role === 'user' ? 'justify-end text-slate-400' : 'justify-start text-slate-400'"
|
||||
>
|
||||
<button
|
||||
@click="copyToClipboard(msg.content, index)"
|
||||
class="p-1 hover:bg-slate-100 rounded text-xs flex items-center gap-1 transition-colors"
|
||||
:title="$t('chat.actions.copy')"
|
||||
>
|
||||
<Check v-if="copiedIndex === index" class="w-3.5 h-3.5 text-green-500" />
|
||||
<Copy v-else class="w-3.5 h-3.5" />
|
||||
</button>
|
||||
|
||||
<template v-if="msg.role === 'user'">
|
||||
<button
|
||||
@click="input = msg.content"
|
||||
class="p-1 hover:bg-slate-100 rounded text-xs transition-colors"
|
||||
:title="$t('chat.actions.edit')"
|
||||
>
|
||||
<Edit2 class="w-3.5 h-3.5" />
|
||||
</button>
|
||||
<button
|
||||
@click="handleSend(msg.content)"
|
||||
class="p-1 hover:bg-slate-100 rounded text-xs transition-colors"
|
||||
:title="$t('chat.actions.resend')"
|
||||
>
|
||||
<RotateCw class="w-3.5 h-3.5" />
|
||||
</button>
|
||||
</template>
|
||||
|
||||
<template v-else>
|
||||
<button
|
||||
v-if="index === messages.length - 1 && !isThinking"
|
||||
@click="regenerate"
|
||||
class="p-1 hover:bg-slate-100 rounded text-xs transition-colors"
|
||||
:title="$t('chat.actions.regenerate')"
|
||||
>
|
||||
<RotateCw class="w-3.5 h-3.5" />
|
||||
</button>
|
||||
</template>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- User Avatar -->
|
||||
|
||||
@@ -0,0 +1,338 @@
|
||||
<script setup lang="ts">
|
||||
import { ref, onMounted } from 'vue';
|
||||
import { useI18n } from 'vue-i18n';
|
||||
import { useRouter } from 'vue-router';
|
||||
import {
|
||||
User,
|
||||
Mail,
|
||||
Building,
|
||||
CreditCard,
|
||||
Shield,
|
||||
Globe,
|
||||
LogOut,
|
||||
Save,
|
||||
ChevronLeft,
|
||||
X
|
||||
} from 'lucide-vue-next';
|
||||
|
||||
const { t, locale } = useI18n();
|
||||
const router = useRouter();
|
||||
|
||||
// State
|
||||
const isLoading = ref(true);
|
||||
const user = ref({
|
||||
id: 0,
|
||||
username: '',
|
||||
real_name: '',
|
||||
email: '',
|
||||
phone_number: '',
|
||||
department: '',
|
||||
role: '',
|
||||
employee_id: '',
|
||||
language: 'zh-CN'
|
||||
});
|
||||
|
||||
const isEditing = ref(false);
|
||||
const passwordForm = ref({
|
||||
current: '',
|
||||
new: '',
|
||||
confirm: ''
|
||||
});
|
||||
|
||||
// Methods
|
||||
const getAuthHeaders = (): Record<string, string> => {
|
||||
let stored = localStorage.getItem('hxops_user');
|
||||
if (!stored) stored = sessionStorage.getItem('hxops_user');
|
||||
|
||||
if (!stored) return {};
|
||||
|
||||
try {
|
||||
const data = JSON.parse(stored);
|
||||
const u = data.user || data;
|
||||
return {
|
||||
'X-Username': u.username,
|
||||
'X-Role': u.role,
|
||||
'X-User-Id': String(u.id)
|
||||
};
|
||||
} catch (e) {
|
||||
return {};
|
||||
}
|
||||
};
|
||||
|
||||
const fetchProfile = async () => {
|
||||
isLoading.value = true;
|
||||
try {
|
||||
const res = await fetch('/api/user/profile', { headers: getAuthHeaders() });
|
||||
if (res.ok) {
|
||||
const data = await res.json();
|
||||
user.value = { ...user.value, ...data };
|
||||
if (data.language) locale.value = data.language;
|
||||
} else {
|
||||
console.error('Failed to load profile');
|
||||
}
|
||||
} catch (e) {
|
||||
console.error(e);
|
||||
} finally {
|
||||
isLoading.value = false;
|
||||
}
|
||||
};
|
||||
|
||||
const showPasswordModal = ref(false);
|
||||
|
||||
const handleSaveProfile = async () => {
|
||||
try {
|
||||
const res = await fetch('/api/user/profile', {
|
||||
method: 'PUT',
|
||||
headers: { 'Content-Type': 'application/json', ...getAuthHeaders() },
|
||||
body: JSON.stringify({
|
||||
real_name: user.value.real_name,
|
||||
phone_number: user.value.phone_number,
|
||||
language: user.value.language,
|
||||
email: user.value.email,
|
||||
employee_id: user.value.employee_id,
|
||||
department: user.value.department
|
||||
})
|
||||
});
|
||||
|
||||
if (res.ok) {
|
||||
alert(t('profile.saveSuccess') || 'Profile saved successfully');
|
||||
isEditing.value = false;
|
||||
// Update locale immediately if changed
|
||||
locale.value = user.value.language;
|
||||
} else {
|
||||
const err = await res.json();
|
||||
alert(err.error || 'Failed to save profile');
|
||||
}
|
||||
} catch (e) {
|
||||
console.error(e);
|
||||
alert('Error saving profile');
|
||||
}
|
||||
};
|
||||
|
||||
const handleChangePassword = async () => {
|
||||
if (passwordForm.value.new !== passwordForm.value.confirm) {
|
||||
alert(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) {
|
||||
alert(t('profile.passwordChanged') || 'Password changed successfully');
|
||||
passwordForm.value = { current: '', new: '', confirm: '' };
|
||||
showPasswordModal.value = false;
|
||||
} else {
|
||||
alert(data.error || 'Failed to change password');
|
||||
}
|
||||
} catch (e) {
|
||||
console.error(e);
|
||||
alert('Error changing password');
|
||||
}
|
||||
};
|
||||
|
||||
const handleLogout = () => {
|
||||
localStorage.removeItem('hxops_user');
|
||||
router.push('/');
|
||||
};
|
||||
|
||||
onMounted(() => {
|
||||
fetchProfile();
|
||||
});
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="min-h-screen bg-slate-50 pb-20">
|
||||
<!-- Header -->
|
||||
<header class="bg-white border-b border-slate-200 sticky top-0 z-30">
|
||||
<div class="max-w-5xl mx-auto px-4 sm:px-6 lg:px-8 h-16 flex items-center justify-between">
|
||||
<div class="flex items-center gap-4">
|
||||
<button @click="router.push('/workspace')" class="p-2 hover:bg-slate-100 rounded-full text-slate-500 transition-colors">
|
||||
<ChevronLeft class="w-5 h-5" />
|
||||
</button>
|
||||
<h1 class="text-xl font-bold text-slate-900">{{ $t('profile.title') || 'My Profile' }}</h1>
|
||||
</div>
|
||||
<button @click="handleLogout" class="text-sm font-medium text-red-600 hover:text-red-700 flex items-center gap-2 px-3 py-1.5 hover:bg-red-50 rounded-lg transition-colors">
|
||||
<LogOut class="w-4 h-4" />
|
||||
<span class="hidden sm:inline">{{ $t('workspace.logout') }}</span>
|
||||
</button>
|
||||
</div>
|
||||
</header>
|
||||
|
||||
<main class="max-w-5xl mx-auto px-4 sm:px-6 lg:px-8 py-8">
|
||||
<div v-if="isLoading" 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="grid grid-cols-1 lg:grid-cols-3 gap-8">
|
||||
<!-- Left Column: User Card -->
|
||||
<div class="lg:col-span-1 space-y-6">
|
||||
<div class="bg-white rounded-2xl shadow-sm border border-slate-100 p-6 text-center">
|
||||
<div class="w-24 h-24 bg-brand-100 rounded-full mx-auto flex items-center justify-center text-brand-600 mb-4 text-3xl font-bold">
|
||||
{{ user.real_name ? user.real_name.charAt(0).toUpperCase() : user.username.charAt(0).toUpperCase() }}
|
||||
</div>
|
||||
<h2 class="text-xl font-bold text-slate-900">{{ user.real_name || user.username }}</h2>
|
||||
<p class="text-slate-500 text-sm mt-1">{{ user.email }}</p>
|
||||
<div class="mt-4 inline-flex items-center px-3 py-1 rounded-full bg-slate-100 text-slate-600 text-xs font-medium">
|
||||
{{ user.role === 'admin' ? 'Administrator' : 'User' }}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="bg-white rounded-2xl shadow-sm border border-slate-100 p-6">
|
||||
<h3 class="font-semibold text-slate-900 mb-4 flex items-center gap-2">
|
||||
<Shield class="w-4 h-4 text-brand-500" />
|
||||
{{ $t('profile.security') || 'Security' }}
|
||||
</h3>
|
||||
<button @click="showPasswordModal = true" class="btn-primary w-full py-2 text-sm flex items-center justify-center gap-2">
|
||||
<Shield class="w-4 h-4" />
|
||||
{{ $t('profile.changePassword') || 'Change Password' }}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Right Column: Details & Settings -->
|
||||
<div class="lg:col-span-2 space-y-6">
|
||||
<div class="bg-white rounded-2xl shadow-sm border border-slate-100 p-6 md:p-8">
|
||||
<div class="flex justify-between items-center mb-6">
|
||||
<h3 class="text-lg font-bold text-slate-900 flex items-center gap-2">
|
||||
<User class="w-5 h-5 text-brand-500" />
|
||||
{{ $t('profile.personalInfo') || 'Personal Information' }}
|
||||
</h3>
|
||||
<button @click="isEditing = !isEditing" class="text-sm font-medium text-brand-600 hover:text-brand-700">
|
||||
{{ isEditing ? ($t('profile.cancel') || 'Cancel') : ($t('profile.edit') || 'Edit') }}
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<div class="grid grid-cols-1 md:grid-cols-2 gap-6">
|
||||
<div>
|
||||
<label class="text-xs font-medium text-slate-500 uppercase flex items-center gap-1.5 mb-1.5">
|
||||
<User class="w-3.5 h-3.5" /> {{ $t('login.username') }}
|
||||
</label>
|
||||
<div class="p-2.5 bg-slate-50 rounded-lg text-slate-700 border border-slate-200 text-sm font-medium cursor-not-allowed">
|
||||
{{ user.username }}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<label class="text-xs font-medium text-slate-500 uppercase flex items-center gap-1.5 mb-1.5">
|
||||
<CreditCard class="w-3.5 h-3.5" /> {{ $t('register.fields.employeeId') || 'Employee ID' }}
|
||||
</label>
|
||||
<input v-if="isEditing" v-model="user.employee_id" type="text" class="input-field" />
|
||||
<div v-else class="p-2.5 bg-slate-50 rounded-lg text-slate-700 border border-slate-200 text-sm font-medium">
|
||||
{{ user.employee_id || '-' }}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<label class="text-xs font-medium text-slate-500 uppercase flex items-center gap-1.5 mb-1.5">
|
||||
<User class="w-3.5 h-3.5" /> {{ $t('register.fields.realName') || 'Real Name' }}
|
||||
</label>
|
||||
<input v-if="isEditing" v-model="user.real_name" type="text" class="input-field" />
|
||||
<div v-else class="p-2.5 bg-white rounded-lg text-slate-900 border border-transparent text-sm font-medium">
|
||||
{{ user.real_name || '-' }}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<label class="text-xs font-medium text-slate-500 uppercase flex items-center gap-1.5 mb-1.5">
|
||||
<Building class="w-3.5 h-3.5" /> {{ $t('admin.user.dept') || 'Department' }}
|
||||
</label>
|
||||
<input v-if="isEditing" v-model="user.department" type="text" class="input-field" />
|
||||
<div v-else class="p-2.5 bg-slate-50 rounded-lg text-slate-700 border border-slate-200 text-sm font-medium">
|
||||
{{ user.department || '-' }}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<label class="text-xs font-medium text-slate-500 uppercase flex items-center gap-1.5 mb-1.5">
|
||||
<Mail class="w-3.5 h-3.5" /> {{ $t('register.email') }}
|
||||
</label>
|
||||
<input v-if="isEditing" v-model="user.email" type="email" class="input-field" />
|
||||
<div v-else class="p-2.5 bg-slate-50 rounded-lg text-slate-700 border border-slate-200 text-sm font-medium">
|
||||
{{ user.email }}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<label class="text-xs font-medium text-slate-500 uppercase flex items-center gap-1.5 mb-1.5">
|
||||
<Globe class="w-3.5 h-3.5" /> {{ $t('register.fields.phone') || 'Phone' }}
|
||||
</label>
|
||||
<input v-if="isEditing" v-model="user.phone_number" type="text" class="input-field" />
|
||||
<div v-else class="p-2.5 bg-white rounded-lg text-slate-900 border border-transparent text-sm font-medium">
|
||||
{{ user.phone_number || '-' }}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div v-if="isEditing" class="mt-8 flex justify-end pt-6 border-t border-slate-100">
|
||||
<button @click="handleSaveProfile" class="btn-primary flex items-center gap-2">
|
||||
<Save class="w-4 h-4" />
|
||||
{{ $t('workspace.save') }}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="bg-white rounded-2xl shadow-sm border border-slate-100 p-6 md:p-8">
|
||||
<h3 class="text-lg font-bold text-slate-900 mb-6 flex items-center gap-2">
|
||||
<Globe class="w-5 h-5 text-brand-500" />
|
||||
{{ $t('profile.preferences') || 'Preferences' }}
|
||||
</h3>
|
||||
|
||||
<div class="grid grid-cols-1 md:grid-cols-2 gap-6">
|
||||
<div>
|
||||
<label class="text-xs font-medium text-slate-500 uppercase mb-1.5 block">Language</label>
|
||||
<select v-model="user.language" :disabled="!isEditing" class="input-field appearance-none bg-no-repeat bg-right pr-8" :class="{ 'bg-slate-50': !isEditing }">
|
||||
<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>
|
||||
</main>
|
||||
</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="bg-white rounded-2xl shadow-xl w-full max-w-md p-6 animate-fade-in-up">
|
||||
<div class="flex justify-between items-center mb-6">
|
||||
<h3 class="text-lg font-bold text-slate-900">{{ $t('profile.changePassword') || 'Change Password' }}</h3>
|
||||
<button @click="showPasswordModal = false" class="p-1 hover:bg-slate-100 rounded-full transition-colors">
|
||||
<X class="w-5 h-5 text-slate-500" />
|
||||
</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="flex-1 px-4 py-2 border border-slate-200 rounded-lg text-slate-600 hover:bg-slate-50 font-medium transition-colors">
|
||||
{{ $t('profile.cancel') || 'Cancel' }}
|
||||
</button>
|
||||
<button type="submit" class="flex-1 btn-primary py-2 text-sm">
|
||||
{{ $t('profile.changePassword') || 'Update' }}
|
||||
</button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
@@ -0,0 +1,106 @@
|
||||
<script setup lang="ts">
|
||||
import { ref } from 'vue';
|
||||
import { useRoute, useRouter } from 'vue-router';
|
||||
import { Lock, AlertCircle, CheckCircle } from 'lucide-vue-next';
|
||||
|
||||
const route = useRoute();
|
||||
const router = useRouter();
|
||||
|
||||
const token = ref(route.query.token as string || '');
|
||||
const password = ref('');
|
||||
const confirmPassword = ref('');
|
||||
const isLoading = ref(false);
|
||||
const status = ref<'idle' | 'success' | 'error'>('idle');
|
||||
const message = ref('');
|
||||
|
||||
const handleReset = async () => {
|
||||
if (!password.value || !confirmPassword.value) {
|
||||
message.value = 'Please fill in all fields';
|
||||
status.value = 'error';
|
||||
return;
|
||||
}
|
||||
|
||||
if (password.value !== confirmPassword.value) {
|
||||
message.value = 'Passwords do not match';
|
||||
status.value = 'error';
|
||||
return;
|
||||
}
|
||||
|
||||
isLoading.value = true;
|
||||
status.value = 'idle';
|
||||
message.value = '';
|
||||
|
||||
try {
|
||||
const res = await fetch('/api/user/reset-password-confirm', {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({
|
||||
token: token.value,
|
||||
new_password: password.value
|
||||
})
|
||||
});
|
||||
|
||||
const data = await res.json();
|
||||
if (res.ok) {
|
||||
status.value = 'success';
|
||||
message.value = 'Password reset successfully! Redirecting to login...';
|
||||
setTimeout(() => {
|
||||
router.push('/');
|
||||
}, 3000);
|
||||
} else {
|
||||
status.value = 'error';
|
||||
message.value = data.error || 'Failed to reset password';
|
||||
}
|
||||
} catch (e) {
|
||||
status.value = 'error';
|
||||
message.value = 'Network error occurred';
|
||||
} finally {
|
||||
isLoading.value = false;
|
||||
}
|
||||
};
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="min-h-screen bg-slate-50 flex items-center justify-center p-4">
|
||||
<div class="max-w-md w-full bg-white rounded-3xl shadow-xl p-8 md:p-10 border border-slate-100">
|
||||
<div class="text-center mb-8">
|
||||
<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>
|
||||
<h2 class="text-2xl font-bold text-slate-900">Reset Password</h2>
|
||||
<p class="text-slate-500 text-sm mt-2">Enter your new password below</p>
|
||||
</div>
|
||||
|
||||
<div v-if="status === 'success'" class="bg-green-50 text-green-700 p-4 rounded-xl flex items-start gap-3 mb-6">
|
||||
<CheckCircle class="w-5 h-5 shrink-0 mt-0.5" />
|
||||
<div>{{ message }}</div>
|
||||
</div>
|
||||
|
||||
<div v-if="status === 'error'" class="bg-red-50 text-red-700 p-4 rounded-xl flex items-start gap-3 mb-6">
|
||||
<AlertCircle class="w-5 h-5 shrink-0 mt-0.5" />
|
||||
<div>{{ message }}</div>
|
||||
</div>
|
||||
|
||||
<form v-if="status !== 'success'" @submit.prevent="handleReset" class="space-y-5">
|
||||
<div>
|
||||
<label class="text-xs font-semibold text-slate-700 uppercase ml-1">New Password</label>
|
||||
<input v-model="password" type="password" class="input-field" placeholder="Enter new password" required />
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<label class="text-xs font-semibold text-slate-700 uppercase ml-1">Confirm Password</label>
|
||||
<input v-model="confirmPassword" type="password" class="input-field" placeholder="Confirm new password" required />
|
||||
</div>
|
||||
|
||||
<button type="submit" :disabled="isLoading" class="btn-primary w-full py-3 flex justify-center items-center gap-2">
|
||||
<div v-if="isLoading" class="animate-spin rounded-full h-4 w-4 border-2 border-white/30 border-t-white"></div>
|
||||
<span>{{ isLoading ? 'Resetting...' : 'Reset Password' }}</span>
|
||||
</button>
|
||||
</form>
|
||||
|
||||
<div class="mt-6 text-center">
|
||||
<router-link to="/" class="text-sm font-medium text-slate-500 hover:text-slate-700">Back to Login</router-link>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
@@ -7,6 +7,7 @@
|
||||
import { ref, onMounted, computed } from 'vue';
|
||||
import { useRouter } from 'vue-router';
|
||||
import { useI18n } from 'vue-i18n';
|
||||
import { config } from '../config';
|
||||
import {
|
||||
Settings,
|
||||
LayoutGrid,
|
||||
@@ -16,7 +17,13 @@ import {
|
||||
Trash2,
|
||||
Edit,
|
||||
ExternalLink,
|
||||
Bot
|
||||
Bot,
|
||||
User,
|
||||
LogOut,
|
||||
Megaphone,
|
||||
X,
|
||||
ChevronDown,
|
||||
ChevronUp
|
||||
} from 'lucide-vue-next';
|
||||
|
||||
const { t, locale } = useI18n();
|
||||
@@ -46,30 +53,78 @@ interface EmbeddedAgent {
|
||||
interface LayoutSection {
|
||||
id: string;
|
||||
visible: boolean;
|
||||
collapsed?: boolean;
|
||||
title?: string;
|
||||
}
|
||||
|
||||
interface Announcement {
|
||||
id: number;
|
||||
title: string;
|
||||
content: string;
|
||||
created_at: 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 announcements = ref<Announcement[]>([]);
|
||||
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' },
|
||||
{ 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' },
|
||||
{ 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 handleForgotPassword = async () => {
|
||||
if (!forgotPasswordForm.value.email) {
|
||||
alert(t('register.email') + ' is required');
|
||||
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) {
|
||||
alert(t('login.passwordResetEmailSent') || 'If the account exists, a reset link has been sent to your email.');
|
||||
showForgotPasswordModal.value = false;
|
||||
forgotPasswordForm.value = { email: '' };
|
||||
} else {
|
||||
alert(data.error || 'Failed to request password reset');
|
||||
}
|
||||
} catch (e) {
|
||||
console.error('Password reset error', e);
|
||||
alert('An error occurred');
|
||||
}
|
||||
};
|
||||
|
||||
/*
|
||||
const showLoginTip = () => {
|
||||
alert(t('login.pleaseLoginFirst') || 'Please login to access this agent.');
|
||||
};
|
||||
*/
|
||||
const userReport = ref<any>(null);
|
||||
|
||||
// Quick Question Form State
|
||||
@@ -92,11 +147,6 @@ const favoriteAgents = computed(() => {
|
||||
});
|
||||
|
||||
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(
|
||||
@@ -114,17 +164,26 @@ const filteredQuickQuestions = computed(() => {
|
||||
|
||||
// Methods
|
||||
const getAuthHeaders = () => {
|
||||
const stored = localStorage.getItem('hxops_user');
|
||||
let stored = localStorage.getItem('hxops_user');
|
||||
if (!stored) stored = sessionStorage.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);
|
||||
|
||||
try {
|
||||
const data = JSON.parse(stored);
|
||||
const user = data.user || data; // Handle both wrapped and unwrapped format
|
||||
|
||||
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;
|
||||
} catch (e) {
|
||||
return {};
|
||||
}
|
||||
return headers;
|
||||
};
|
||||
|
||||
const fetchHome = async () => {
|
||||
@@ -146,9 +205,7 @@ const fetchHome = async () => {
|
||||
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 },
|
||||
@@ -157,24 +214,50 @@ const fetchHome = async () => {
|
||||
{ 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));
|
||||
const mapKey = (id: string) => (id === 'quick_questions' ? 'quickQuestions' : id === 'all_agents' ? 'allAgents' : id);
|
||||
|
||||
// Add backend sections
|
||||
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 });
|
||||
});
|
||||
|
||||
// Add missing sections
|
||||
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);
|
||||
}
|
||||
});
|
||||
|
||||
layoutSections.value = merged;
|
||||
// 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: 'favorites', visible: true, collapsed: false },
|
||||
{ id: 'quick_questions', visible: true, collapsed: false },
|
||||
{ id: 'embedded', visible: true, collapsed: false },
|
||||
{ id: 'all_agents', visible: true, collapsed: false },
|
||||
];
|
||||
|
||||
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);
|
||||
@@ -185,18 +268,54 @@ const fetchHome = async () => {
|
||||
|
||||
const fetchPublicAgents = async () => {
|
||||
try {
|
||||
const res = await fetch('/api/user/public-agents');
|
||||
publicAgents.value = await res.json();
|
||||
const res = await fetch('/api/agents/public');
|
||||
if (res.ok) {
|
||||
publicAgents.value = await res.json();
|
||||
} else {
|
||||
publicAgents.value = [];
|
||||
}
|
||||
} catch (e) {
|
||||
console.error('Failed to load public agents', 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 = () => {
|
||||
const stored = localStorage.getItem('hxops_user');
|
||||
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) return;
|
||||
|
||||
try {
|
||||
const user = JSON.parse(stored) as { id?: number; username: string; role: string };
|
||||
const data = JSON.parse(stored);
|
||||
const user = data.user || data; // Handle both wrapped and unwrapped format
|
||||
currentUser.value = {
|
||||
id: user.id || 0,
|
||||
username: user.username,
|
||||
@@ -204,6 +323,7 @@ const loadAuthUser = () => {
|
||||
};
|
||||
} catch (e) {
|
||||
localStorage.removeItem('hxops_user');
|
||||
sessionStorage.removeItem('hxops_user');
|
||||
}
|
||||
};
|
||||
|
||||
@@ -225,12 +345,29 @@ const handleLogin = async () => {
|
||||
|
||||
if (!res.ok) {
|
||||
const err = await res.json();
|
||||
alert(err.error || t('login.failed'));
|
||||
// Handle specific error messages if needed, or just alert
|
||||
let msg = err.error || t('login.failed');
|
||||
if (err.error === 'User not found') msg = t('login.userNotFound') || 'User not found';
|
||||
if (err.error === 'Incorrect password') msg = t('login.incorrectPassword') || 'Incorrect password';
|
||||
if (err.error === 'Account is disabled') msg = t('login.accountDisabled') || 'Account is disabled';
|
||||
if (err.error === 'Database connection failed') msg = t('login.dbConnectionFailed') || 'Database connection failed';
|
||||
if (err.error === 'Internal server error') msg = t('login.internalError') || 'Internal server error';
|
||||
|
||||
alert(msg);
|
||||
return;
|
||||
}
|
||||
|
||||
const user = await res.json();
|
||||
localStorage.setItem('hxops_user', JSON.stringify(user));
|
||||
|
||||
if (rememberMe.value) {
|
||||
// Store in localStorage with 30 days expiry
|
||||
const expiry = new Date().getTime() + 30 * 24 * 60 * 60 * 1000;
|
||||
localStorage.setItem('hxops_user', JSON.stringify({ user, expiry }));
|
||||
} else {
|
||||
// Store in sessionStorage (cleared when tab closed)
|
||||
sessionStorage.setItem('hxops_user', JSON.stringify({ user }));
|
||||
}
|
||||
|
||||
await fetchHome();
|
||||
|
||||
if (pendingAgentId.value) {
|
||||
@@ -244,7 +381,7 @@ const handleLogin = async () => {
|
||||
}
|
||||
} catch (e) {
|
||||
console.error(e);
|
||||
alert(t('login.requestFailed'));
|
||||
alert(t('login.requestFailed') || 'Login request failed. Please check your network or server status.');
|
||||
}
|
||||
};
|
||||
|
||||
@@ -275,6 +412,9 @@ const handleRegister = async () => {
|
||||
}
|
||||
};
|
||||
|
||||
// Header Dropdown State
|
||||
const showUserDropdown = ref(false);
|
||||
|
||||
const handleLogout = () => {
|
||||
localStorage.removeItem('hxops_user');
|
||||
currentUser.value = null;
|
||||
@@ -284,6 +424,11 @@ const handleLogout = () => {
|
||||
embeddedAgents.value = [];
|
||||
userReport.value = null;
|
||||
fetchPublicAgents();
|
||||
router.push('/');
|
||||
};
|
||||
|
||||
const navigateToProfile = () => {
|
||||
router.push('/profile');
|
||||
};
|
||||
|
||||
const navigateToChat = (id: number) => {
|
||||
@@ -384,6 +529,17 @@ const removeQuickQuestion = async (id: number) => {
|
||||
};
|
||||
|
||||
// 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;
|
||||
};
|
||||
@@ -408,8 +564,14 @@ const onDrop = async (index: number) => {
|
||||
});
|
||||
};
|
||||
|
||||
const openAnnouncement = (ann: Announcement) => {
|
||||
selectedAnnouncement.value = ann;
|
||||
showAnnouncementModal.value = true;
|
||||
};
|
||||
|
||||
onMounted(async () => {
|
||||
loadAuthUser();
|
||||
fetchAnnouncements();
|
||||
if (currentUser.value && currentUser.value.role !== 'guest') {
|
||||
await fetchHome();
|
||||
} else {
|
||||
@@ -421,6 +583,16 @@ onMounted(async () => {
|
||||
|
||||
<template>
|
||||
<div class="min-h-screen bg-gray-50 font-sans text-slate-800">
|
||||
<!-- Top Global Language Selector (Always visible) -->
|
||||
<div class="fixed top-4 right-4 z-50">
|
||||
<select v-model="locale" class="bg-white/80 backdrop-blur-md shadow-sm border border-slate-200 text-xs font-medium text-slate-600 hover:text-slate-800 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">简体中文</option>
|
||||
<option value="zh-TW">繁體中文</option>
|
||||
<option value="th">ไทย</option>
|
||||
</select>
|
||||
</div>
|
||||
|
||||
<!-- 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">
|
||||
@@ -436,18 +608,46 @@ onMounted(async () => {
|
||||
</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 class="flex items-center gap-4">
|
||||
<!-- User Profile Dropdown -->
|
||||
<div class="relative">
|
||||
<button @click="showUserDropdown = !showUserDropdown" class="flex items-center gap-3 pl-3 pr-2 py-1.5 rounded-full hover:bg-slate-50 transition-colors border border-transparent hover:border-slate-200">
|
||||
<div class="text-right hidden sm:block">
|
||||
<div class="text-sm font-bold text-slate-900 leading-tight">{{ currentUser?.username }}</div>
|
||||
<div class="text-[10px] font-medium text-slate-500 uppercase tracking-wide">{{ currentUser?.role === 'admin' ? 'Admin' : 'User' }}</div>
|
||||
</div>
|
||||
<div class="w-9 h-9 bg-brand-100 rounded-full flex items-center justify-center text-brand-600 font-bold border-2 border-white shadow-sm">
|
||||
{{ (currentUser?.username || 'U').charAt(0).toUpperCase() }}
|
||||
</div>
|
||||
</button>
|
||||
|
||||
<!-- Dropdown Menu -->
|
||||
<div v-if="showUserDropdown"
|
||||
class="absolute right-0 top-full mt-2 w-48 bg-white rounded-xl shadow-xl border border-slate-100 py-1 z-50 animate-fade-in"
|
||||
@click.away="showUserDropdown = false">
|
||||
<div class="px-4 py-3 border-b border-slate-50 md:hidden">
|
||||
<div class="text-sm font-bold text-slate-900">{{ currentUser?.username }}</div>
|
||||
<div class="text-xs text-slate-500">{{ currentUser?.role }}</div>
|
||||
</div>
|
||||
|
||||
<button @click="navigateToProfile" class="w-full text-left px-4 py-2 text-sm text-slate-700 hover:bg-slate-50 hover:text-brand-600 flex items-center gap-2">
|
||||
<User class="w-4 h-4" />
|
||||
{{ $t('profile.title') || 'My Profile' }}
|
||||
</button>
|
||||
|
||||
<button v-if="currentUser?.role === 'admin'" @click="router.push('/admin')" class="w-full text-left px-4 py-2 text-sm text-slate-700 hover:bg-slate-50 hover:text-brand-600 flex items-center gap-2">
|
||||
<Settings class="w-4 h-4" />
|
||||
{{ $t('admin.title') }}
|
||||
</button>
|
||||
|
||||
<div class="border-t border-slate-50 my-1"></div>
|
||||
|
||||
<button @click="handleLogout" class="w-full text-left px-4 py-2 text-sm text-red-600 hover:bg-red-50 flex items-center gap-2">
|
||||
<LogOut class="w-4 h-4" />
|
||||
{{ $t('workspace.logout') }}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</header>
|
||||
@@ -482,6 +682,25 @@ onMounted(async () => {
|
||||
Access a suite of powerful AI agents tailored for your enterprise needs. Secure, scalable, and intelligent.
|
||||
</p>
|
||||
|
||||
<!-- Announcements List -->
|
||||
<div v-if="announcements.length > 0" class="bg-white/60 backdrop-blur-sm rounded-2xl border border-slate-100 p-6 shadow-sm">
|
||||
<h3 class="text-sm font-bold text-slate-900 mb-4 flex items-center gap-2">
|
||||
<Megaphone class="w-4 h-4 text-brand-600" />
|
||||
{{ $t('login.announcements') || '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 p-2 rounded-lg transition-colors"
|
||||
@click="openAnnouncement(ann)">
|
||||
<div class="flex justify-between items-start gap-2">
|
||||
<h4 class="text-sm font-medium text-slate-800 group-hover:text-brand-700 line-clamp-1">{{ ann.title }}</h4>
|
||||
<span class="text-[10px] text-slate-400 whitespace-nowrap">{{ new Date(ann.created_at).toLocaleDateString() }}</span>
|
||||
</div>
|
||||
<p class="text-xs text-slate-500 line-clamp-2 mt-1">{{ ann.content }}</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<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">
|
||||
@@ -491,50 +710,64 @@ onMounted(async () => {
|
||||
<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>
|
||||
|
||||
</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="bg-white/90 backdrop-blur-xl rounded-3xl border border-white/20 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">{{ $t('login.submit') }}</h2>
|
||||
<p class="text-slate-500 text-sm mt-2">Welcome back! Please enter your details.</p>
|
||||
<p class="text-slate-500 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-700 uppercase ml-1">{{ $t('login.username') }}</label>
|
||||
<input v-model="loginUsername" type="text" class="input-field" placeholder="Enter your username" />
|
||||
<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-700 uppercase ml-1">{{ $t('login.password') }}</label>
|
||||
<input v-model="loginPassword" type="password" class="input-field" placeholder="••••••••" />
|
||||
<input v-model="loginPassword" type="password" class="input-field" :placeholder="$t('login.placeholder.password')" @keyup.enter="handleLogin" />
|
||||
</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">
|
||||
<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-600 cursor-pointer select-none">{{ $t('login.rememberMe') || 'Remember me for 30 days' }}</label>
|
||||
</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 mt-4">
|
||||
{{ $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 class="flex justify-between items-center pt-4 mt-2 border-t border-slate-100/50">
|
||||
<button @click="showForgotPasswordModal = true" class="text-sm text-slate-500 hover:text-brand-600 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>
|
||||
|
||||
<!-- 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>
|
||||
<!-- Public Agents Showcase Mobile -->
|
||||
<div v-if="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>
|
||||
@@ -563,7 +796,7 @@ onMounted(async () => {
|
||||
<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">
|
||||
<h2 class="text-xl font-bold text-slate-800 flex items-center gap-2.5 cursor-pointer select-none" @click="toggleSectionCollapse(section)">
|
||||
<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',
|
||||
@@ -573,13 +806,15 @@ onMounted(async () => {
|
||||
<component :is="section.id === 'favorites' ? Star : (section.id === 'embedded' ? Bot : LayoutGrid)" class="w-5 h-5" />
|
||||
</div>
|
||||
{{ $t(section.title || section.id) }}
|
||||
<component :is="section.collapsed ? ChevronDown : ChevronUp" class="w-4 h-4 text-slate-400" />
|
||||
</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">
|
||||
<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">
|
||||
<Plus class="w-4 h-4" /> {{ $t('workspace.quickQuestions.add') }}
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<div v-show="!section.collapsed" class="animate-fade-in">
|
||||
<!-- 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>
|
||||
@@ -695,7 +930,53 @@ onMounted(async () => {
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<!-- Forgot Password Modal -->
|
||||
<div v-if="showForgotPasswordModal" 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 relative">
|
||||
<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">{{ $t('login.forgotPassword') }}</h3>
|
||||
<p class="text-slate-500 text-sm mt-2">{{ $t('login.forgotPasswordDesc') || 'Enter your email to reset your password' }}</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') || 'Find Password' }}</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Announcement Modal -->
|
||||
<div v-if="showAnnouncementModal && selectedAnnouncement" 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-2xl p-8 animate-slide-up relative max-h-[80vh] overflow-y-auto">
|
||||
<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 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 flex justify-end">
|
||||
<button @click="showAnnouncementModal = false" class="btn-primary">
|
||||
{{ $t('admin.close') }}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@@ -703,7 +984,10 @@ onMounted(async () => {
|
||||
|
||||
<!-- 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">
|
||||
<div class="bg-white rounded-3xl shadow-2xl w-full max-w-md p-8 animate-slide-up relative">
|
||||
<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 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" />
|
||||
@@ -725,4 +1009,4 @@ onMounted(async () => {
|
||||
|
||||
<style scoped>
|
||||
/* Scoped styles removed in favor of global utilities in style.css */
|
||||
</style>
|
||||
</style>
|
||||
Reference in new issue
Block a user