260304调整

This commit is contained in:
super committed 2026-03-04 22:48:05 +08:00
1 parent b48f1e592a
commit a0c8721fbb
16 files changed
+1382 -291

No files matched your search

+83 -61
View File
@@ -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>