fix: report
This commit is contained in:
1 parent
07e83132c0
commit
4445ff68d4
46 files changed
+3904
-897
No files matched your search
@@ -8,10 +8,9 @@
|
||||
<script setup lang="ts">
|
||||
import { computed, ref, onMounted } from 'vue';
|
||||
import { useI18n } from 'vue-i18n';
|
||||
import { Bot, Plus, SquarePen, Trash2, Users } from 'lucide-vue-next';
|
||||
import { Bot, Plus, SquarePen, Trash2 } from 'lucide-vue-next';
|
||||
import DeleteConfirmDialog from '@/shared/components/DeleteConfirmDialog.vue';
|
||||
import AgentFormModal from './components/AgentFormModal.vue';
|
||||
import AgentPermissionModal from './components/AgentPermissionModal.vue';
|
||||
import AgentTestModal from './components/AgentTestModal.vue';
|
||||
import { useAgentsAdmin } from './composables/useAgentsAdmin';
|
||||
import { useAgentsTableColumnResize } from './composables/useAgentsTableColumnResize';
|
||||
@@ -29,7 +28,6 @@ const {
|
||||
contentProfileOptions,
|
||||
scheduleTasks,
|
||||
trainingExamPdfGuides,
|
||||
activeUsers,
|
||||
isLoading,
|
||||
isSaving,
|
||||
isImportingTrainingPdf,
|
||||
@@ -40,9 +38,6 @@ const {
|
||||
isTesting,
|
||||
testingAgent,
|
||||
testResult,
|
||||
showPermissionModal,
|
||||
permissionAgent,
|
||||
permissionUserIds,
|
||||
showDeleteConfirmDialog,
|
||||
deleteConfirmMessage,
|
||||
loadAll,
|
||||
@@ -59,9 +54,6 @@ const {
|
||||
deleteAgent,
|
||||
openTestModal,
|
||||
runAgentTest,
|
||||
openPermissionModal,
|
||||
togglePermissionUser,
|
||||
savePermissions,
|
||||
closeDeleteConfirm,
|
||||
confirmDelete,
|
||||
} = useAgentsAdmin();
|
||||
@@ -75,13 +67,11 @@ const {
|
||||
|
||||
const tableHeaderColumns = computed(() => [
|
||||
{ key: 'name', label: t('admin.agent.headers.name'), align: 'left' as const },
|
||||
{ key: 'type', label: t('admin.agent.headers.type'), align: 'left' as const },
|
||||
{ key: 'aggregation', label: t('admin.agent.headers.aggregation'), align: 'left' as const },
|
||||
{ key: 'config', label: t('admin.agent.headers.config'), align: 'left' as const },
|
||||
{ key: 'status', label: t('admin.agent.headers.status'), align: 'left' as const },
|
||||
{ key: 'actions', label: t('admin.agent.headers.actions'), align: 'right' as const },
|
||||
]);
|
||||
|
||||
/* 列表仅展示名称、状态和操作;类型/聚合/配置仍由编辑弹窗维护。 */
|
||||
const formatAgentCode = (agent: AgentRow) => agent.agent_code || 'generic';
|
||||
|
||||
const formatAgentAggregationPrimary = (agent: AgentRow) => (
|
||||
@@ -131,6 +121,8 @@ const formatRuntimeProviderLabel = (agent: AgentRow) => {
|
||||
const translated = t(key);
|
||||
return translated === key ? provider : translated;
|
||||
};
|
||||
void [formatAgentAggregationPrimary, formatAgentAggregationSecondary, formatAgentConfigPrimary,
|
||||
formatAgentConfigSecondary, formatAgentTypeLabel, formatRuntimeProviderLabel];
|
||||
|
||||
const showFormDialog = ref(false);
|
||||
|
||||
@@ -241,43 +233,6 @@ onMounted(() => {
|
||||
</p>
|
||||
</div>
|
||||
</td>
|
||||
<td class="px-4 py-4 align-middle">
|
||||
<div class="agent-list-cell">
|
||||
<p class="truncate text-sm text-primary" :title="formatAgentTypeLabel(agent)">
|
||||
{{ formatAgentTypeLabel(agent) }}
|
||||
</p>
|
||||
<p class="truncate text-xs text-muted" :title="formatRuntimeProviderLabel(agent)">
|
||||
{{ formatRuntimeProviderLabel(agent) }}
|
||||
</p>
|
||||
</div>
|
||||
</td>
|
||||
<td class="px-4 py-4 align-middle">
|
||||
<div class="agent-list-cell">
|
||||
<p
|
||||
class="truncate text-sm font-medium"
|
||||
:class="agent.is_aggregate ? 'text-brand-700' : 'text-secondary'"
|
||||
:title="formatAgentAggregationPrimary(agent)"
|
||||
>
|
||||
{{ formatAgentAggregationPrimary(agent) }}
|
||||
</p>
|
||||
<p class="truncate text-xs text-muted" :title="formatAgentAggregationSecondary(agent)">
|
||||
{{ formatAgentAggregationSecondary(agent) }}
|
||||
</p>
|
||||
</div>
|
||||
</td>
|
||||
<td class="px-4 py-4 align-middle">
|
||||
<div class="agent-list-cell">
|
||||
<p
|
||||
class="truncate font-mono text-sm text-primary"
|
||||
:title="formatAgentConfigPrimary(agent)"
|
||||
>
|
||||
{{ formatAgentConfigPrimary(agent) }}
|
||||
</p>
|
||||
<p class="truncate text-xs text-muted">
|
||||
{{ formatAgentConfigSecondary(agent) }}
|
||||
</p>
|
||||
</div>
|
||||
</td>
|
||||
<td class="px-4 py-4 align-middle">
|
||||
<div class="agent-list-cell">
|
||||
<span
|
||||
@@ -300,14 +255,6 @@ onMounted(() => {
|
||||
<SquarePen class="w-4 h-4 shrink-0" />
|
||||
{{ t('admin.edit') }}
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
class="inline-flex shrink-0 items-center justify-center p-2 text-blue-600 bg-blue-50 hover:bg-blue-100 rounded-lg transition-all"
|
||||
:title="t('admin.agent.manageAccess')"
|
||||
@click.stop="openPermissionModal(agent)"
|
||||
>
|
||||
<Users class="w-5 h-5 shrink-0" />
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
class="inline-flex shrink-0 items-center whitespace-nowrap p-2 text-emerald-600 bg-emerald-50 hover:bg-emerald-100 rounded-lg transition-all"
|
||||
@@ -367,17 +314,6 @@ onMounted(() => {
|
||||
@import-training-pdf="importTrainingQuestionBankFromPdf"
|
||||
/>
|
||||
|
||||
<AgentPermissionModal
|
||||
:visible="showPermissionModal"
|
||||
:agent="permissionAgent"
|
||||
:users="activeUsers()"
|
||||
:selected-user-ids="permissionUserIds"
|
||||
:is-saving="isSaving"
|
||||
@close="showPermissionModal = false"
|
||||
@save="savePermissions"
|
||||
@toggle-user="togglePermissionUser"
|
||||
/>
|
||||
|
||||
<DeleteConfirmDialog
|
||||
v-model="showDeleteConfirmDialog"
|
||||
:message="deleteConfirmMessage"
|
||||
|
||||
+5
-3
@@ -8,12 +8,14 @@
|
||||
|
||||
import { computed, onBeforeUnmount, ref } from 'vue';
|
||||
|
||||
const STORAGE_KEY = 'hxops.admin.agents.tableColumnWidths';
|
||||
// 列结构已移除权限操作,升级缓存键以废弃旧的拖拽宽度,避免旧值继续撑出横向滚动。
|
||||
const STORAGE_KEY = 'hxops.admin.agents.tableColumnWidths.v4';
|
||||
|
||||
/** 名称 / 类型 / 分类 / 配置 / 状态 / 操作 */
|
||||
const DEFAULT_WIDTHS = [220, 168, 128, 140, 96, 220] as const;
|
||||
// 列宽只根据字段和操作控件确定;描述始终在名称单元格内截断,不参与宽度计算。
|
||||
const DEFAULT_WIDTHS = [400, 140, 240] as const;
|
||||
|
||||
const MIN_WIDTHS = [140, 120, 100, 120, 80, 200] as const;
|
||||
const MIN_WIDTHS = [220, 110, 220] as const;
|
||||
|
||||
const COLUMN_COUNT = DEFAULT_WIDTHS.length;
|
||||
|
||||
|
||||
@@ -5,15 +5,22 @@
|
||||
* 逻辑:路由 /admin/departments;表头排序复用 shared SortableTableHeader + useTableSort。
|
||||
*/
|
||||
<script setup lang="ts">
|
||||
import { onMounted } from 'vue';
|
||||
import { onMounted, ref } from 'vue';
|
||||
import { useI18n } from 'vue-i18n';
|
||||
import { Edit, Plus, Search, Trash2 } from 'lucide-vue-next';
|
||||
import { Edit, Plus, Search, Trash2, Users } from 'lucide-vue-next';
|
||||
import DeleteConfirmDialog from '@/shared/components/DeleteConfirmDialog.vue';
|
||||
import SortableTableHeader from '@/shared/components/SortableTableHeader.vue';
|
||||
import DepartmentFormModal from './components/DepartmentFormModal.vue';
|
||||
import DepartmentMembersModal from './components/DepartmentMembersModal.vue';
|
||||
import { useDepartmentsAdmin } from './composables/useDepartmentsAdmin';
|
||||
import { listAdminDepartmentMembers } from '@/features/admin/api/admin.api';
|
||||
import type { AdminDepartmentMembersResponse } from '@/features/admin/types/admin.types';
|
||||
import { useMessage } from '@/shared/composables/useMessage';
|
||||
|
||||
const { t } = useI18n();
|
||||
const msg = useMessage();
|
||||
const showMembersModal = ref(false);
|
||||
const departmentMembers = ref<AdminDepartmentMembersResponse | null>(null);
|
||||
|
||||
const {
|
||||
filteredDepartments,
|
||||
@@ -40,6 +47,16 @@ const {
|
||||
onMounted(() => {
|
||||
void loadAll();
|
||||
});
|
||||
|
||||
/** 加载并展示指定部门的员工名单。 */
|
||||
const openDepartmentMembers = async (departmentId: number): Promise<void> => {
|
||||
try {
|
||||
departmentMembers.value = await listAdminDepartmentMembers(departmentId) as AdminDepartmentMembersResponse;
|
||||
showMembersModal.value = true;
|
||||
} catch (error) {
|
||||
msg.error((error as Error).message || t('admin.msg.requestFailed'));
|
||||
}
|
||||
};
|
||||
</script>
|
||||
|
||||
<template>
|
||||
@@ -77,13 +94,14 @@ onMounted(() => {
|
||||
</div>
|
||||
|
||||
<div class="admin-table-wrap">
|
||||
<!-- 列宽:名称 / 编码 / 公司 / 操作 -->
|
||||
<!-- 列宽:名称 / 编码 / 公司 / 员工 / 操作 -->
|
||||
<table class="admin-table table-fixed">
|
||||
<colgroup>
|
||||
<col class="w-[25%]" />
|
||||
<col class="w-[20%]" />
|
||||
<col class="w-[35%]" />
|
||||
<col class="w-[15%]" />
|
||||
<col class="w-[30%]" />
|
||||
<col class="w-[12%]" />
|
||||
<col class="w-[13%]" />
|
||||
</colgroup>
|
||||
<thead>
|
||||
<tr>
|
||||
@@ -114,12 +132,13 @@ onMounted(() => {
|
||||
@sort="toggleSort"
|
||||
/>
|
||||
</th>
|
||||
<th class="px-6 py-4 text-center text-xs">{{ t('admin.dept.headers.members') }}</th>
|
||||
<th class="px-6 py-4 text-right text-xs">{{ t('admin.dept.headers.actions') }}</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr v-if="filteredDepartments.length === 0">
|
||||
<td colspan="4" class="px-6 admin-table-empty">
|
||||
<td colspan="5" class="px-6 admin-table-empty">
|
||||
{{ searchQuery.trim() ? t('admin.dept.noSearchResults') : t('admin.dept.noDepts') }}
|
||||
</td>
|
||||
</tr>
|
||||
@@ -140,6 +159,14 @@ onMounted(() => {
|
||||
<td class="px-6 py-4 text-sm text-muted truncate" :title="d.company || '-'">
|
||||
{{ d.company || '-' }}
|
||||
</td>
|
||||
<td class="px-6 py-4 text-center">
|
||||
<button
|
||||
type="button"
|
||||
class="inline-flex items-center justify-center rounded-lg bg-blue-50 p-2 text-blue-600 hover:bg-blue-100"
|
||||
:title="t('admin.dept.actions.viewMembers')"
|
||||
@click="openDepartmentMembers(d.id)"
|
||||
><Users class="w-5 h-5" /><span class="ml-1 text-xs">{{ d.member_count || 0 }}</span></button>
|
||||
</td>
|
||||
<td class="px-6 py-4">
|
||||
<div class="flex justify-end gap-1">
|
||||
<button
|
||||
@@ -173,6 +200,11 @@ onMounted(() => {
|
||||
@close="closeFormModal"
|
||||
@save="saveDepartment"
|
||||
/>
|
||||
<DepartmentMembersModal
|
||||
:visible="showMembersModal"
|
||||
:data="departmentMembers"
|
||||
@close="showMembersModal = false"
|
||||
/>
|
||||
|
||||
<DeleteConfirmDialog
|
||||
v-model="showDeleteConfirmDialog"
|
||||
|
||||
@@ -0,0 +1,44 @@
|
||||
/**
|
||||
* features/admin/modules/departments/components/DepartmentMembersModal.vue
|
||||
* 用途:展示部门对应的员工数量和名单。
|
||||
* 依赖:部门成员只读 API 响应与 Vue 事件。
|
||||
* 逻辑:DepartmentsPage 点击员工图标后传入数据,本组件只负责呈现与关闭。
|
||||
*/
|
||||
<script setup lang="ts">
|
||||
import { useI18n } from 'vue-i18n';
|
||||
import { Users, X } from 'lucide-vue-next';
|
||||
import type { AdminDepartmentMembersResponse } from '@/features/admin/types/admin.types';
|
||||
|
||||
defineProps<{ visible: boolean; data: AdminDepartmentMembersResponse | null }>();
|
||||
const emit = defineEmits<{ close: [] }>();
|
||||
const { t } = useI18n();
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div v-if="visible && data" class="admin-modal-overlay items-center" @click.self="emit('close')">
|
||||
<section class="admin-modal-panel max-w-2xl max-h-[90vh] animate-fade-in-up">
|
||||
<header class="px-8 py-6 border-b border-subtle flex items-center justify-between">
|
||||
<div>
|
||||
<h3 class="text-lg font-bold text-primary">{{ t('admin.dept.members.title', { name: data.department.name }) }}</h3>
|
||||
<p class="text-sm text-muted mt-1">{{ t('admin.dept.members.count', { count: data.count }) }}</p>
|
||||
</div>
|
||||
<button type="button" class="btn-icon-ds rounded-full" :title="t('admin.close')" @click="emit('close')"><X class="w-5 h-5" /></button>
|
||||
</header>
|
||||
<div class="max-h-[60vh] overflow-y-auto p-6">
|
||||
<div v-if="data.members.length === 0" class="py-12 text-center text-muted">
|
||||
<Users class="w-9 h-9 mx-auto mb-3 opacity-60" />
|
||||
{{ t('admin.dept.members.empty') }}
|
||||
</div>
|
||||
<ul v-else class="divide-y divide-subtle">
|
||||
<li v-for="member in data.members" :key="member.id" class="py-3 flex items-center justify-between gap-4">
|
||||
<div class="min-w-0">
|
||||
<p class="font-medium text-primary">{{ member.real_name || member.username }}</p>
|
||||
<p class="text-xs text-muted truncate">{{ member.employee_id || member.username }} · {{ member.email || '-' }}</p>
|
||||
</div>
|
||||
<span class="text-xs text-muted whitespace-nowrap">{{ member.status }}</span>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
</section>
|
||||
</div>
|
||||
</template>
|
||||
@@ -5,17 +5,20 @@
|
||||
* 逻辑:路由 /admin/permissions;左侧用户相关列 sticky,右侧为各应用权限列。
|
||||
*/
|
||||
<script setup lang="ts">
|
||||
import { onMounted } from 'vue';
|
||||
import { computed, onMounted, ref, watch } from 'vue';
|
||||
import { useI18n } from 'vue-i18n';
|
||||
import { Download, FileText, Users } from 'lucide-vue-next';
|
||||
import BatchPermissionModal from '@/features/admin/modules/users/components/BatchPermissionModal.vue';
|
||||
import PaginationBar from '@/shared/components/PaginationBar.vue';
|
||||
import { getUserAvatarLabel } from '@/shared/utils/user-avatar';
|
||||
import { usePermissionsAdmin } from './composables/usePermissionsAdmin';
|
||||
|
||||
const { t } = useI18n();
|
||||
|
||||
const {
|
||||
agents,
|
||||
users,
|
||||
appRows,
|
||||
permissionFilters,
|
||||
selectedUserIds,
|
||||
paginatedUsers,
|
||||
@@ -40,6 +43,45 @@ const { t } = useI18n();
|
||||
importPermissions,
|
||||
} = usePermissionsAdmin();
|
||||
|
||||
const permissionView = ref<'apps' | 'members'>('apps');
|
||||
const selectedApp = ref<(typeof agents.value)[number] | null>(null);
|
||||
const appMemberSearch = ref('');
|
||||
const appMemberPage = ref(1);
|
||||
const appMemberPageSize = ref(10);
|
||||
const appMemberPageSizeOptions = [10, 20, 50, 100];
|
||||
|
||||
/** 应用成员弹窗:已授权人员优先展示,同时可搜索全部有效人员以便增删权限。 */
|
||||
const appMembers = computed(() => {
|
||||
const appId = selectedApp.value?.id;
|
||||
const keyword = appMemberSearch.value.trim().toLowerCase();
|
||||
if (!appId) return [];
|
||||
return users.value
|
||||
.filter((user) => user.status !== 'pending')
|
||||
.filter((user) => !keyword || [user.username, user.real_name, user.department, user.employee_id]
|
||||
.filter(Boolean)
|
||||
.some((value) => String(value).toLowerCase().includes(keyword)))
|
||||
.sort((a, b) => Number(b.agent_ids.includes(appId)) - Number(a.agent_ids.includes(appId)));
|
||||
});
|
||||
|
||||
const appMemberTotalPages = computed(() => Math.max(1, Math.ceil(appMembers.value.length / appMemberPageSize.value)));
|
||||
const paginatedAppMembers = computed(() => {
|
||||
const page = Math.min(Math.max(1, appMemberPage.value), appMemberTotalPages.value);
|
||||
const start = (page - 1) * appMemberPageSize.value;
|
||||
return appMembers.value.slice(start, start + appMemberPageSize.value);
|
||||
});
|
||||
watch(appMemberSearch, () => { appMemberPage.value = 1; });
|
||||
|
||||
const openAppMembers = (app: (typeof agents.value)[number]): void => {
|
||||
selectedApp.value = app;
|
||||
appMemberSearch.value = '';
|
||||
appMemberPage.value = 1;
|
||||
};
|
||||
|
||||
const closeAppMembers = (): void => {
|
||||
selectedApp.value = null;
|
||||
appMemberSearch.value = '';
|
||||
};
|
||||
|
||||
onMounted(() => {
|
||||
void loadAll();
|
||||
});
|
||||
@@ -85,7 +127,7 @@ onMounted(() => {
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="admin-table-filters--inline">
|
||||
<div v-if="permissionView === 'members'" class="admin-table-filters--inline">
|
||||
<input
|
||||
v-model="permissionFilters.username"
|
||||
:placeholder="t('admin.perm.filterName')"
|
||||
@@ -104,11 +146,37 @@ onMounted(() => {
|
||||
</select>
|
||||
</div>
|
||||
|
||||
<div class="admin-table-section admin-table-wrap">
|
||||
<table class="admin-table">
|
||||
<div class="flex gap-6 border-b border-default">
|
||||
<button type="button" class="border-b-2 px-1 py-3 text-sm font-medium transition-colors" :class="permissionView === 'apps' ? 'border-brand-600 text-brand-600' : 'border-transparent text-muted hover:text-primary'" @click="permissionView = 'apps'">
|
||||
{{ t('admin.perm.views.apps') }}
|
||||
</button>
|
||||
<button type="button" class="border-b-2 px-1 py-3 text-sm font-medium transition-colors" :class="permissionView === 'members' ? 'border-brand-600 text-brand-600' : 'border-transparent text-muted hover:text-primary'" @click="permissionView = 'members'">
|
||||
{{ t('admin.perm.views.members') }}
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<div v-if="permissionView === 'apps'" class="admin-table-section admin-table-wrap">
|
||||
<table class="admin-table min-w-[680px]">
|
||||
<thead><tr>
|
||||
<th class="px-6 py-4 text-left text-sm">{{ t('admin.perm.appHeaders.app') }}</th>
|
||||
<th class="px-4 py-4 text-center text-sm">{{ t('admin.perm.appHeaders.type') }}</th>
|
||||
<th class="px-4 py-4 text-center text-sm">{{ t('admin.perm.appHeaders.authorized') }}</th>
|
||||
<th class="px-6 py-4 text-right text-sm">{{ t('admin.perm.appHeaders.actions') }}</th>
|
||||
</tr></thead>
|
||||
<tbody><tr v-for="app in appRows" :key="app.id">
|
||||
<td class="px-6 py-4"><div class="font-medium text-primary">{{ app.name }}</div><div class="mt-1 text-xs text-muted">{{ t('admin.perm.appHeaders.accessHint') }}</div></td>
|
||||
<td class="px-4 py-4 text-center text-sm text-muted">{{ app.type || 'API' }}</td>
|
||||
<td class="px-4 py-4 text-center text-sm font-medium text-primary">{{ app.authorizedCount }}</td>
|
||||
<td class="px-6 py-4 text-right"><button type="button" class="text-sm font-medium text-brand-600 hover:text-brand-700" @click="openAppMembers(app)">{{ t('admin.perm.appHeaders.viewMembers') }}</button></td>
|
||||
</tr></tbody>
|
||||
</table>
|
||||
</div>
|
||||
|
||||
<div v-else class="admin-table-section admin-table-wrap">
|
||||
<table class="admin-table min-w-max">
|
||||
<thead>
|
||||
<tr>
|
||||
<th class="px-4 py-4 w-12 text-center sticky left-0 admin-table-sticky-head z-20">
|
||||
<th class="w-[3rem] px-2 py-4 text-center sticky left-0 admin-table-sticky-head z-20">
|
||||
<input
|
||||
type="checkbox"
|
||||
class="w-4 h-4 rounded text-brand-600 focus:ring-brand-500"
|
||||
@@ -117,27 +185,17 @@ onMounted(() => {
|
||||
/>
|
||||
</th>
|
||||
<th
|
||||
class="px-6 py-4 text-left text-sm sticky left-12 admin-table-sticky-head z-20 w-56"
|
||||
class="w-[18rem] min-w-[18rem] px-4 py-4 text-left text-sm sticky left-[3rem] admin-table-sticky-head z-20 border-r border-subtle shadow-[2px_0_5px_-2px_rgba(0,0,0,0.1)]"
|
||||
>
|
||||
{{ t('admin.perm.headers.user') }}
|
||||
</th>
|
||||
<th
|
||||
class="px-6 py-4 text-left text-sm sticky left-[17rem] admin-table-sticky-head z-20 w-36"
|
||||
>
|
||||
{{ t('admin.perm.headers.realName') }}
|
||||
</th>
|
||||
<th
|
||||
class="px-6 py-4 text-left text-sm sticky left-[26rem] admin-table-sticky-head z-20 w-40 border-r border-subtle shadow-[2px_0_5px_-2px_rgba(0,0,0,0.1)]"
|
||||
>
|
||||
{{ t('admin.perm.headers.dept') }}
|
||||
</th>
|
||||
<th
|
||||
v-for="agent in agents"
|
||||
:key="agent.id"
|
||||
class="px-4 py-4 text-center text-sm min-w-[100px]"
|
||||
class="w-[7.5rem] min-w-[7.5rem] px-3 py-4 text-center text-sm"
|
||||
>
|
||||
<div class="flex flex-col items-center gap-1">
|
||||
<span>{{ agent.name }}</span>
|
||||
<div class="flex min-h-14 flex-col items-center justify-center gap-1">
|
||||
<span class="line-clamp-2 max-w-[6.5rem] break-words leading-tight" :title="agent.name">{{ agent.name }}</span>
|
||||
<span class="text-[10px] text-muted font-normal border border-default px-1 rounded">
|
||||
{{ agent.type }}
|
||||
</span>
|
||||
@@ -147,7 +205,7 @@ onMounted(() => {
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr v-for="user in paginatedUsers" :key="user.id">
|
||||
<td class="px-4 py-4 text-center sticky left-0 admin-table-sticky-cell z-20">
|
||||
<td class="w-[3rem] px-2 py-4 text-center sticky left-0 admin-table-sticky-cell z-20">
|
||||
<input
|
||||
type="checkbox"
|
||||
class="w-4 h-4 rounded text-brand-600 focus:ring-brand-500"
|
||||
@@ -155,34 +213,29 @@ onMounted(() => {
|
||||
@change="toggleUserSelection(user.id)"
|
||||
/>
|
||||
</td>
|
||||
<td class="px-6 py-4 sticky left-12 admin-table-sticky-cell z-20">
|
||||
<td class="w-[18rem] min-w-[18rem] px-4 py-3 sticky left-[3rem] admin-table-sticky-cell z-20 border-r border-subtle shadow-[2px_0_5px_-2px_rgba(0,0,0,0.05)]">
|
||||
<div class="flex items-center gap-3">
|
||||
<div
|
||||
class="w-8 h-8 rounded-full bg-gradient-to-br from-brand-100 to-indigo-100 text-brand-600 flex items-center justify-center font-bold text-sm"
|
||||
>
|
||||
{{ user.username.charAt(0).toUpperCase() }}
|
||||
{{ getUserAvatarLabel(user) }}
|
||||
</div>
|
||||
<div class="font-medium text-primary text-sm truncate max-w-[120px]" :title="user.username">
|
||||
{{ user.username }}
|
||||
<div class="min-w-0">
|
||||
<div class="truncate text-sm font-medium text-primary" :title="user.real_name || user.username">
|
||||
{{ user.real_name || user.username }}
|
||||
</div>
|
||||
<div class="mt-1 flex min-w-0 items-center gap-2 text-xs text-muted">
|
||||
<span class="max-w-[7rem] truncate" :title="user.username">{{ user.username }}</span>
|
||||
<span class="h-3 w-px shrink-0 bg-border" />
|
||||
<span class="max-w-[8rem] truncate" :title="user.department || '-'">{{ user.department || '-' }}</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</td>
|
||||
<td class="px-6 py-4 sticky left-[17rem] admin-table-sticky-cell z-20">
|
||||
<div class="text-sm text-primary truncate" :title="user.real_name || '-'">
|
||||
{{ user.real_name || '-' }}
|
||||
</div>
|
||||
</td>
|
||||
<td
|
||||
class="px-6 py-4 sticky left-[26rem] admin-table-sticky-cell z-20 border-r border-subtle shadow-[2px_0_5px_-2px_rgba(0,0,0,0.05)]"
|
||||
>
|
||||
<div class="text-sm text-muted truncate" :title="user.department">
|
||||
{{ user.department || '-' }}
|
||||
</div>
|
||||
</td>
|
||||
<td
|
||||
v-for="agent in agents"
|
||||
:key="agent.id"
|
||||
class="px-4 py-4 text-center border-l border-dashed border-subtle"
|
||||
class="w-[7.5rem] min-w-[7.5rem] px-3 py-3 text-center border-l border-dashed border-subtle"
|
||||
>
|
||||
<input
|
||||
type="checkbox"
|
||||
@@ -215,5 +268,33 @@ onMounted(() => {
|
||||
@close="closeBatchPermissionModal"
|
||||
@save="submitBatchPermission"
|
||||
/>
|
||||
|
||||
<div v-if="selectedApp" class="fixed inset-0 z-50 flex items-center justify-center bg-slate-950/30 p-4" @click.self="closeAppMembers">
|
||||
<section class="flex max-h-[min(720px,calc(100vh-2rem))] w-full max-w-2xl flex-col overflow-hidden rounded-2xl border border-default bg-surface shadow-2xl">
|
||||
<header class="flex items-start justify-between border-b border-default px-6 py-5"><div><h3 class="text-lg font-semibold text-primary">{{ selectedApp.name }}</h3><p class="mt-1 text-sm text-muted">{{ t('admin.perm.appHeaders.memberHint') }}</p></div><button type="button" class="text-sm text-muted hover:text-primary" @click="closeAppMembers">{{ t('admin.close') }}</button></header>
|
||||
<div class="border-b border-subtle bg-surface-soft px-6 py-4"><input v-model="appMemberSearch" :placeholder="t('admin.perm.appHeaders.memberSearch')" class="admin-table-filter-input w-full" /></div>
|
||||
<div class="min-h-0 flex-1 overflow-y-auto">
|
||||
<div v-for="member in paginatedAppMembers" :key="member.id" class="flex items-center justify-between gap-4 border-b border-subtle px-6 py-3 last:border-b-0"><div class="flex min-w-0 items-center gap-3"><div class="flex h-9 w-9 shrink-0 items-center justify-center rounded-full bg-brand-100 text-sm font-bold text-brand-600">{{ getUserAvatarLabel(member) }}</div><div class="min-w-0"><div class="truncate text-sm font-medium text-primary">{{ member.real_name || member.username }}</div><div class="truncate text-xs text-muted">{{ member.username }} · {{ member.department || '-' }}</div></div></div><button type="button" class="shrink-0 rounded-lg px-3 py-1.5 text-sm font-medium transition-colors" :class="member.agent_ids.includes(selectedApp.id) ? 'text-red-600 hover:bg-red-50' : 'text-brand-600 hover:bg-brand-50'" @click="toggleUserAgentPermission(member, selectedApp.id)">{{ member.agent_ids.includes(selectedApp.id) ? t('admin.perm.appHeaders.removeMember') : t('admin.perm.appHeaders.addMember') }}</button></div>
|
||||
<p v-if="appMembers.length === 0" class="px-6 py-12 text-center text-sm text-muted">{{ t('admin.perm.appHeaders.noMembers') }}</p>
|
||||
</div>
|
||||
<PaginationBar v-if="appMembers.length > 0" v-model:page="appMemberPage" v-model:page-size="appMemberPageSize" :total="appMembers.length" :pages="appMemberTotalPages" :page-size-options="appMemberPageSizeOptions" class="app-member-pagination rounded-none border-x-0 border-b-0" />
|
||||
</section>
|
||||
</div>
|
||||
|
||||
</section>
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
/* 查看成员弹窗宽度固定,分页摘要与翻页操作保持在同一行。 */
|
||||
:deep(.app-member-pagination) {
|
||||
flex-wrap: nowrap;
|
||||
}
|
||||
|
||||
:deep(.app-member-pagination > div) {
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
:deep(.app-member-pagination > div:last-child) {
|
||||
flex-wrap: nowrap;
|
||||
}
|
||||
</style>
|
||||
@@ -39,6 +39,12 @@ export function usePermissionsAdmin() {
|
||||
|
||||
const activeUsers = computed(() => users.value.filter((u) => u.status !== 'pending'));
|
||||
|
||||
/** 按应用视图行:复用已加载用户权限,统计每个应用的有效授权人数。 */
|
||||
const appRows = computed(() => agents.value.map((agent) => ({
|
||||
...agent,
|
||||
authorizedCount: activeUsers.value.filter((user) => user.agent_ids.includes(agent.id)).length,
|
||||
})));
|
||||
|
||||
const filteredUsers = computed(() =>
|
||||
activeUsers.value.filter((u) => {
|
||||
const matchName =
|
||||
@@ -216,6 +222,7 @@ export function usePermissionsAdmin() {
|
||||
return {
|
||||
users,
|
||||
agents,
|
||||
appRows,
|
||||
permissionFilters,
|
||||
selectedUserIds,
|
||||
filteredUsers,
|
||||
|
||||
File diff suppressed because it is too large.
Load diff
@@ -1,9 +1,10 @@
|
||||
/**
|
||||
/**
|
||||
* features/admin/modules/reports/composables/useReportsAdmin.ts
|
||||
* 用途:管理后台报表(多表浏览、筛选、排序、chat_logs 批量删除、使用分析与应用运营看板)。
|
||||
* 依赖:admin.api、useReportLayoutStorage、useOffsetPagination、useMessage、dateTime、vue-router。
|
||||
* 逻辑:ReportsPage 调用本 composable;使用分析按用户服务端分页、按应用前端分页,均复用 PaginationBar;
|
||||
* 低使用应用优先消费后端 low_agents(含零使用启用应用),与应用运营口径对齐。
|
||||
* 低使用应用优先消费后端 low_agents(含零使用启用应用),与应用运营口径对齐;
|
||||
* 趋势 by_day 前端按日期升序兜底;问题分析优先问题表前端分页;非表页切换时清空通用表状态防幽灵分页。
|
||||
*/
|
||||
import { computed, ref, watch } from 'vue';
|
||||
import { useI18n } from 'vue-i18n';
|
||||
@@ -11,10 +12,16 @@ import { useRoute, useRouter } from 'vue-router';
|
||||
import * as XLSX from 'xlsx';
|
||||
import {
|
||||
batchDeleteAdminChatLogs,
|
||||
closeAdminGeneralFeedback,
|
||||
getAdminApplicationReport,
|
||||
getAdminChatLogTops,
|
||||
getAdminFeedbackSummary,
|
||||
getAdminIssueAnalysis,
|
||||
getAdminOpsOverview,
|
||||
getAdminReportTable,
|
||||
getAdminReportTableCount,
|
||||
getAdminUsageReport,
|
||||
listAdminAgents,
|
||||
} from '@/features/admin/api/admin.api';
|
||||
import { loadReportLayoutPref, saveReportLayoutPref } from '@/shared/composables/useReportLayoutStorage';
|
||||
import { buildOffsetPageButtons } from '@/shared/composables/useOffsetPagination';
|
||||
@@ -28,7 +35,9 @@ import type {
|
||||
ApplicationStatusFilter,
|
||||
ApplicationUsageFilter,
|
||||
ChatLogsLayoutPref,
|
||||
OpsOverviewReport,
|
||||
ReportColumnConfig,
|
||||
ReportFeedbackTab,
|
||||
SortRule,
|
||||
UsageRangeKey,
|
||||
UsageReport,
|
||||
@@ -41,6 +50,8 @@ const CHAT_LOGS_REPORT_KEYS = [
|
||||
'username',
|
||||
'real_name',
|
||||
'created_at',
|
||||
'risk_status',
|
||||
'risk_score',
|
||||
'query',
|
||||
'answer',
|
||||
'tokens_used',
|
||||
@@ -48,8 +59,12 @@ const CHAT_LOGS_REPORT_KEYS = [
|
||||
|
||||
const CHAT_LOGS_TABLE_KEYS = ['id', ...CHAT_LOGS_REPORT_KEYS] as const;
|
||||
|
||||
/** 聊天日志风险状态可选项(值 = 后端 risk_status 枚举) */
|
||||
const CHAT_LOG_RISK_STATUS_OPTIONS = ['attention', 'review', 'responded'] as const;
|
||||
|
||||
/**
|
||||
* 聊天日志列默认宽度:前三列与 Token 收窄,提问/回答留宽。
|
||||
* 报表列默认宽度:聊天日志前三列与 Token 收窄,提问/回答留宽,风险列居中紧凑;
|
||||
* 意见反馈操作列保留按钮所需空间,防止中文文案按单字断行拉高整行。
|
||||
* @param key - 列字段名
|
||||
* @returns 像素宽度
|
||||
*/
|
||||
@@ -67,9 +82,21 @@ const defaultChatLogsColumnWidth = (key: string): number => {
|
||||
return 156;
|
||||
case 'tokens_used':
|
||||
return 96;
|
||||
case 'risk_status':
|
||||
return 104;
|
||||
case 'risk_score':
|
||||
return 84;
|
||||
case 'latency':
|
||||
return 90;
|
||||
case 'is_empty_answer':
|
||||
return 96;
|
||||
case 'is_system_failure':
|
||||
return 108;
|
||||
case 'query':
|
||||
case 'answer':
|
||||
return 240;
|
||||
case 'actions':
|
||||
return 112;
|
||||
default:
|
||||
return 160;
|
||||
}
|
||||
@@ -85,9 +112,29 @@ export function useReportsAdmin() {
|
||||
const usageUserPage = ref(1);
|
||||
const usageUserPageSize = ref(10);
|
||||
const usageUserPageSizeOptions = [5, 10, 20, 50];
|
||||
/** 使用分析时间范围,默认近一月 */
|
||||
/** 使用分析时间范围,默认近 30 天 */
|
||||
const usageRange = ref<UsageRangeKey>('30d');
|
||||
const usageRangeOptions: UsageRangeKey[] = ['7d', '30d', '90d', '180d', '365d'];
|
||||
/** 统一时间范围筛选器:仅近 7 天 / 30 天 / 90 天 */
|
||||
const usageRangeOptions: UsageRangeKey[] = ['7d', '30d', '90d'];
|
||||
|
||||
/** 用户反馈与回答评价页内 Tab:general=意见反馈,rating=回答评价 */
|
||||
const feedbackTab = ref<ReportFeedbackTab>('general');
|
||||
/** 「意见反馈」Tab 角标:general_feedbacks 记录总数 */
|
||||
const generalFeedbackTotal = ref(0);
|
||||
/** 反馈概览卡片:待处理 / 本月已关闭 / 最多反馈应用 */
|
||||
const feedbackSummary = ref<{ pending_count: number; closed_this_month: number; top_app: { name: string; count: number } } | null>(null);
|
||||
/** 「意见反馈」内容列当前展开查看的行 id(null=全部收起) */
|
||||
const expandedFeedbackId = ref<number | null>(null);
|
||||
/** 反馈页枚举筛选选项:值取自后端枚举,展示时按当前语言翻译 */
|
||||
const feedbackTypeOptions = ['feature_suggestion', 'issue_feedback', 'experience_optimization'];
|
||||
const feedbackModuleOptions = ['knowledge_base', 'general', 'workflow', 'account_permission'];
|
||||
const feedbackSourceOptions = ['workspace', 'chat', 'unknown'];
|
||||
/** 运营总览报表(复用 chat_logs / feedbacks / general_feedbacks / agents / 应用授权数据) */
|
||||
const opsOverview = ref<OpsOverviewReport | null>(null);
|
||||
/** 问题分析:高频问题簇 KPI + 优先处理问题 */
|
||||
const issueAnalysis = ref<any | null>(null);
|
||||
/** 运营总览时间范围,默认近 30 天 */
|
||||
const opsOverviewRange = ref<UsageRangeKey>('30d');
|
||||
|
||||
/** 按应用统计:前端分页(后端已返回范围内全部应用) */
|
||||
const usageAgentPage = ref(1);
|
||||
@@ -123,6 +170,31 @@ export function useReportsAdmin() {
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* 加载运营总览报表。
|
||||
* 核心逻辑:调用 /reports/overview 拉取 KPI / 趋势环比 / Top 与低使用应用 / 低评分回答 / 未处理反馈。
|
||||
*/
|
||||
const loadOpsOverview = async (): Promise<void> => {
|
||||
try {
|
||||
opsOverview.value = await getAdminOpsOverview({ range: opsOverviewRange.value });
|
||||
} catch (e) {
|
||||
console.error('Error loading ops overview:', e);
|
||||
opsOverview.value = null;
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* 加载问题分析(高频问题簇 KPI + 优先处理问题)。
|
||||
* 核心逻辑:调用 /reports/issue-analysis,复用聊天日志风险规则。
|
||||
*/
|
||||
const loadIssueAnalysis = async (): Promise<void> => {
|
||||
try {
|
||||
issueAnalysis.value = await getAdminIssueAnalysis();
|
||||
} catch {
|
||||
issueAnalysis.value = null;
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* 加载应用运营报表。
|
||||
* 核心逻辑:调用 /reports/applications,按当前筛选与排序拉取分页数据。
|
||||
@@ -207,6 +279,200 @@ export function useReportsAdmin() {
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* 「用户反馈与回答评价」关联跳转:跳到对应聊天日志明细。
|
||||
* 核心逻辑:按 chat_log_id 精确过滤 /admin/reports/chat_logs,落点即该条对话。
|
||||
* @param chatLogId - 关联的聊天日志 ID(无关联 ID 时直接忽略)
|
||||
*/
|
||||
const openFeedbackChatLog = (chatLogId: number | string | null | undefined): void => {
|
||||
const id = Number(chatLogId);
|
||||
if (!Number.isFinite(id) || id <= 0) return;
|
||||
void router.push({
|
||||
name: 'AdminReports',
|
||||
params: { table: 'chat_logs' },
|
||||
query: { id: String(id) },
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* 计算反馈/评价「关联聊天」单元格的展示形态。
|
||||
* 规则:无关联 chat_log_id -> empty(显示“未关联”,不强行补齐);
|
||||
* 意见反馈仅当来源为“对话”时才是可点击链接,其余展示原始 ID;回答评价有 ID 即链接。
|
||||
* @param row - 反馈/评价行
|
||||
* @returns { type, value?, chatLogId? }
|
||||
*/
|
||||
const getFeedbackChatLogCell = (
|
||||
row: any,
|
||||
): { type: 'empty' | 'plain' | 'link'; value?: string; chatLogId?: number } => {
|
||||
const chatLogId = Number(row?.chat_log_id);
|
||||
const hasId = Number.isFinite(chatLogId) && chatLogId > 0;
|
||||
if (!hasId) return { type: 'empty' };
|
||||
if (feedbackTab.value === 'general') {
|
||||
const source = String(row?.source_page ?? '').trim().toLowerCase();
|
||||
const fromChat = source === 'chat' || source === '\u5bf9\u8bdd' || source === 'chat_page';
|
||||
if (!fromChat) return { type: 'plain', value: String(chatLogId) };
|
||||
}
|
||||
return { type: 'link', chatLogId };
|
||||
};
|
||||
|
||||
/**
|
||||
* 展开/收起「意见反馈」内容列。
|
||||
* @param row - 反馈行
|
||||
*/
|
||||
const toggleFeedbackContent = (row: any): void => {
|
||||
const id = Number(row?.id);
|
||||
expandedFeedbackId.value = id === expandedFeedbackId.value ? null : id;
|
||||
};
|
||||
|
||||
/** 当前反馈行内容是否已展开查看 */
|
||||
const isFeedbackContentExpanded = (row: any): boolean =>
|
||||
expandedFeedbackId.value === Number(row?.id);
|
||||
|
||||
/**
|
||||
* 打开反馈内容浮窗(悬停/聚焦时)。
|
||||
* @param row - 反馈行
|
||||
*/
|
||||
const openFeedbackContent = (row: any): void => {
|
||||
const id = Number(row?.id);
|
||||
expandedFeedbackId.value = Number.isFinite(id) ? id : null;
|
||||
};
|
||||
|
||||
/** 关闭反馈内容浮窗。 */
|
||||
const closeFeedbackContent = (): void => {
|
||||
expandedFeedbackId.value = null;
|
||||
};
|
||||
|
||||
/**
|
||||
* 打开聊天日志详情弹窗(用户提问/智能体回答/风险状态/风险分/判定原因/建议检查项)。
|
||||
* @param row - 聊天日志行
|
||||
*/
|
||||
const openChatLogDetail = (row: any): void => {
|
||||
chatLogDetailRow.value = row;
|
||||
chatLogDetailVisible.value = true;
|
||||
};
|
||||
|
||||
/** 关闭聊天日志详情弹窗 */
|
||||
const closeChatLogDetail = (): void => {
|
||||
chatLogDetailVisible.value = false;
|
||||
chatLogDetailRow.value = null;
|
||||
};
|
||||
|
||||
/** 风险状态 → 本地化标签 */
|
||||
const getChatLogRiskStatusLabel = (status: string): string => {
|
||||
const key = `admin.report.chatLog.risk.${status}`;
|
||||
const v = t(key);
|
||||
return v && v !== key ? v : status;
|
||||
};
|
||||
|
||||
/** 判定原因 code → 本地化标签 */
|
||||
const getChatLogRiskReasonLabel = (code: string): string => {
|
||||
const key = `admin.report.chatLog.reason.${code}`;
|
||||
const v = t(key);
|
||||
return v && v !== key ? v : code;
|
||||
};
|
||||
|
||||
/** 建议检查项 code → 本地化标签 */
|
||||
const getChatLogRiskCheckLabel = (code: string): string => {
|
||||
const key = `admin.report.chatLog.check.${code}`;
|
||||
const v = t(key);
|
||||
return v && v !== key ? v : code;
|
||||
};
|
||||
|
||||
/** 风险状态 → 徽标颜色 class(便于前端三色区分) */
|
||||
const getChatLogRiskStatusClass = (status: string): string => {
|
||||
switch (status) {
|
||||
case 'attention':
|
||||
return 'bg-rose-100 text-rose-700';
|
||||
case 'review':
|
||||
return 'bg-amber-100 text-amber-700';
|
||||
default:
|
||||
return 'bg-emerald-100 text-emerald-700';
|
||||
}
|
||||
};
|
||||
|
||||
/** 重置聊天日志风险/定位筛选并重新加载(清除关联跳转残留的 id/agent_id 等) */
|
||||
const resetChatLogFilters = (): void => {
|
||||
const keys = [
|
||||
'created_from', 'created_to', 'agent_name', 'agent_id', 'username', 'user_id',
|
||||
'is_empty_answer', 'is_system_failure', 'risk_status', 'risk_score',
|
||||
'min_score', 'max_score', 'feedback_score', 'id',
|
||||
];
|
||||
for (const k of keys) {
|
||||
columnFilters.value[k] = '';
|
||||
}
|
||||
handleFilterChange();
|
||||
};
|
||||
|
||||
/** 聊天日志 Top 提问/回答内容条形图数据(随当前识别条件刷新) */
|
||||
const loadChatLogTops = async (): Promise<void> => {
|
||||
if (!isChatLogsTable.value) return;
|
||||
try {
|
||||
const params = new URLSearchParams();
|
||||
for (const [key, value] of Object.entries(columnFilters.value)) {
|
||||
if (value) params.append(key, value);
|
||||
}
|
||||
const qs = params.toString();
|
||||
chatLogTops.value = await getAdminChatLogTops(qs ? `?${qs}` : '');
|
||||
} catch {
|
||||
chatLogTops.value = null;
|
||||
}
|
||||
};
|
||||
|
||||
/** Top 提问条形图宽度归一化基准 */
|
||||
const chatLogTopsQuestionsMax = computed(() =>
|
||||
Math.max(1, ...(chatLogTops.value?.questions || []).map((x) => x.count)),
|
||||
);
|
||||
/** Top 回答条形图宽度归一化基准 */
|
||||
const chatLogTopsAnswersMax = computed(() =>
|
||||
Math.max(1, ...(chatLogTops.value?.answers || []).map((x) => x.count)),
|
||||
);
|
||||
|
||||
/** 加载反馈概览卡片(待处理/本月已关闭/最多反馈应用) */
|
||||
const loadFeedbackSummary = async (): Promise<void> => {
|
||||
if (!isMergedFeedbackTable.value || feedbackTab.value !== 'general') return;
|
||||
try {
|
||||
const params = new URLSearchParams();
|
||||
for (const [key, value] of Object.entries(columnFilters.value)) {
|
||||
if (value) params.append(key, value);
|
||||
}
|
||||
const qs = params.toString();
|
||||
feedbackSummary.value = await getAdminFeedbackSummary(qs ? `?${qs}` : '');
|
||||
} catch {
|
||||
feedbackSummary.value = null;
|
||||
}
|
||||
};
|
||||
|
||||
/** 将一条意见反馈标记为已关闭,并刷新列表与概览 */
|
||||
const closeFeedback = async (row: any): Promise<void> => {
|
||||
const id = Number(row?.id);
|
||||
if (!Number.isFinite(id) || id <= 0) return;
|
||||
try {
|
||||
await closeAdminGeneralFeedback(id);
|
||||
msg.success(t('admin.report.feedback.closedOk'));
|
||||
await loadTableData();
|
||||
void loadFeedbackSummary();
|
||||
} catch (e) {
|
||||
msg.error((e as Error).message || t('admin.msg.failed'));
|
||||
}
|
||||
};
|
||||
|
||||
/** 拉取聊天日志「应用」筛选项(应用列表) */
|
||||
const loadChatLogAgents = async (): Promise<void> => {
|
||||
if (!isChatLogsTable.value) return;
|
||||
try {
|
||||
chatLogAgents.value = await listAdminAgents();
|
||||
} catch {
|
||||
chatLogAgents.value = [];
|
||||
}
|
||||
};
|
||||
|
||||
/** 进入聊天日志页时给统一时间范围一个默认值,保证筛选生效 */
|
||||
const ensureChatLogsRange = (): void => {
|
||||
if (isChatLogsTable.value && !columnFilters.value.range) {
|
||||
columnFilters.value.range = '30d';
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* 导出应用运营报表 Excel(仅运营字段)。
|
||||
*/
|
||||
@@ -240,6 +506,44 @@ export function useReportsAdmin() {
|
||||
const usageUserTopLimit = computed(() => usageReport.value?.user_top_limit ?? 50);
|
||||
const usageActiveAgentCount = computed(() => usageReport.value?.by_agent.length ?? 0);
|
||||
const usageTrendMax = computed(() => Math.max(1, ...(usageReport.value?.by_day || []).map((item) => item.count)));
|
||||
|
||||
/**
|
||||
* 将报表日维度日期解析为可比较时间戳;非法值回退 0。
|
||||
* @param date - 后端日期字符串(期望 yyyy-mm-dd,兼容未补零)
|
||||
*/
|
||||
const reportDayTimestamp = (date: string): number => {
|
||||
const raw = String(date || '').trim();
|
||||
if (!raw) return 0;
|
||||
const head = raw.split(/[ T]/)[0]?.replace(/\//g, '-') || '';
|
||||
const parts = head.split('-');
|
||||
if (parts.length >= 3) {
|
||||
const y = Number(parts[0]);
|
||||
const m = Number(parts[1]);
|
||||
const d = Number(String(parts[2]).slice(0, 2));
|
||||
if (Number.isFinite(y) && Number.isFinite(m) && Number.isFinite(d)) {
|
||||
return Date.UTC(y, m - 1, d);
|
||||
}
|
||||
}
|
||||
const parsed = Date.parse(raw);
|
||||
return Number.isFinite(parsed) ? parsed : 0;
|
||||
};
|
||||
|
||||
/**
|
||||
* 按自然日升序排序趋势点,避免未补零日期字符串把月初甩到横轴末尾。
|
||||
* @param days - by_day 原始列表
|
||||
*/
|
||||
const sortReportDaysAsc = <T extends { date: string }>(days: T[]): T[] =>
|
||||
[...days].sort((a, b) => {
|
||||
const diff = reportDayTimestamp(a.date) - reportDayTimestamp(b.date);
|
||||
if (diff !== 0) return diff;
|
||||
return String(a.date).localeCompare(String(b.date));
|
||||
});
|
||||
|
||||
/** 使用分析「近段趋势」按日期升序后的柱状数据 */
|
||||
const usageTrendByDay = computed(() => sortReportDaysAsc(usageReport.value?.by_day || []));
|
||||
|
||||
/** 运营总览「对话趋势」按日期升序后的柱状数据 */
|
||||
const opsTrendByDay = computed(() => sortReportDaysAsc(opsOverview.value?.trend.by_day || []));
|
||||
/** 低使用应用:范围内对话次数 ≤ 该阈值(兜底;优先用后端返回值) */
|
||||
const USAGE_LOW_AGENT_MAX_CHATS = 2;
|
||||
/** 低使用应用提醒最多展示条数(兜底;优先用后端返回值) */
|
||||
@@ -350,6 +654,10 @@ export function useReportsAdmin() {
|
||||
if (typeof table === 'string' && (ADMIN_REPORT_TABLES as readonly string[]).includes(table)) {
|
||||
return table as AdminReportTableId;
|
||||
}
|
||||
// 兼容旧链接:意见反馈曾是独立导航项,现并入「用户反馈与回答评价」页
|
||||
if (table === 'general_feedbacks') {
|
||||
return 'feedbacks';
|
||||
}
|
||||
return 'usage_analysis';
|
||||
};
|
||||
|
||||
@@ -377,6 +685,18 @@ const reportCurrentPage = ref(1);
|
||||
const reportPageSize = ref(20);
|
||||
const reportPageSizeOptions = [10, 20, 50, 100];
|
||||
|
||||
/** 聊天日志详情弹窗:当前查看行(null=关闭) */
|
||||
const chatLogDetailVisible = ref(false);
|
||||
const chatLogDetailRow = ref<any | null>(null);
|
||||
|
||||
/** 聊天日志 Top 提问/回答内容(直接按 ChatLog 明细统计) */
|
||||
const chatLogTops = ref<{ questions: Array<{ label: string; count: number }>; answers: Array<{ label: string; count: number }> } | null>(null);
|
||||
|
||||
/** 聊天日志统一时间范围(近 7/30/90 天) */
|
||||
const chatLogRangeOptions: UsageRangeKey[] = ['7d', '30d', '90d'];
|
||||
/** 聊天日志「应用」筛选项(应用运营跳转/按应用查看) */
|
||||
const chatLogAgents = ref<any[]>([]);
|
||||
|
||||
const chatLogsColumns = ref<ReportColumnConfig[]>([]);
|
||||
const chatLogsSortRules = ref<SortRule[]>([]);
|
||||
const reportHeaderSort = ref<SortRule | null>(null);
|
||||
@@ -385,10 +705,16 @@ const resizingColumnKey = ref<string | null>(null);
|
||||
let resizeStartX = 0;
|
||||
let resizeStartWidth = 0;
|
||||
|
||||
/** 使用分析 / 应用运营是菜单层虚拟页,明细表仍复用对应数据源。 */
|
||||
const dataSourceTable = computed<Exclude<AdminReportTableId, 'usage_analysis'>>(() => {
|
||||
/**
|
||||
* 数据源表解析:使用分析/应用运营是菜单层虚拟页,明细表仍复用对应数据源。
|
||||
* 「用户反馈与回答评价」页内按 Tab 切换数据源(general_feedbacks / feedbacks)。
|
||||
*/
|
||||
const dataSourceTable = computed<AdminReportTableId>(() => {
|
||||
if (currentTable.value === 'usage_analysis') return 'chat_logs';
|
||||
return currentTable.value as Exclude<AdminReportTableId, 'usage_analysis'>;
|
||||
if (currentTable.value === 'feedbacks') {
|
||||
return feedbackTab.value === 'general' ? 'general_feedbacks' : 'feedbacks';
|
||||
}
|
||||
return currentTable.value;
|
||||
});
|
||||
|
||||
/**
|
||||
@@ -405,6 +731,18 @@ const applyRouteQueryFilters = (): void => {
|
||||
};
|
||||
|
||||
const loadTableData = async () => {
|
||||
// 使用分析 / 运营总览 / 问题分析:非通用数据表(使用分析严格不展示聊天原文,直接清空)
|
||||
if (
|
||||
isUsageAnalysisTable.value
|
||||
|| isPlaceholderTable.value
|
||||
|| isOpsOverviewTable.value
|
||||
|| isIssueAnalysisTable.value
|
||||
) {
|
||||
tableData.value = [];
|
||||
selectedReportRowIds.value = [];
|
||||
chatLogsColumns.value = [];
|
||||
return;
|
||||
}
|
||||
// 应用运营页不走通用配置表
|
||||
if (currentTable.value === 'agents') {
|
||||
tableData.value = [];
|
||||
@@ -428,9 +766,11 @@ const loadTableData = async () => {
|
||||
tableData.value = await getAdminReportTable(url);
|
||||
if (tableData.value.length > 0) {
|
||||
const rowKeys = Object.keys(tableData.value[0] || {});
|
||||
// 反馈表隐藏内部字段(status/closed_at/id 等,避免出现在列设置)
|
||||
const internalRelKeys = new Set(['id', 'user_id', 'status', 'closed_at']);
|
||||
const columnKeys = dataSourceTable.value === 'chat_logs'
|
||||
? CHAT_LOGS_TABLE_KEYS.filter((k) => rowKeys.includes(k))
|
||||
: rowKeys;
|
||||
: rowKeys.filter((k) => !internalRelKeys.has(k));
|
||||
initChatLogsColumns(columnKeys);
|
||||
}
|
||||
if (dataSourceTable.value === 'chat_logs') {
|
||||
@@ -447,6 +787,15 @@ const loadTableData = async () => {
|
||||
tableData.value = [];
|
||||
selectedReportRowIds.value = [];
|
||||
}
|
||||
// 聊天日志:刷新 Top 提问/回答内容(复用当前识别条件)
|
||||
if (isChatLogsTable.value) {
|
||||
void loadChatLogTops();
|
||||
void loadChatLogAgents();
|
||||
}
|
||||
// 用户反馈:刷新概览卡片(仅意见反馈 Tab)
|
||||
if (isMergedFeedbackTable.value && feedbackTab.value === 'general') {
|
||||
void loadFeedbackSummary();
|
||||
}
|
||||
};
|
||||
|
||||
const saveChatLogsColumns = () => {
|
||||
@@ -573,19 +922,41 @@ const startResizeColumn = (key: string, e: MouseEvent) => {
|
||||
document.addEventListener('mouseup', onResizeMouseUp);
|
||||
};
|
||||
|
||||
/** 构造带当前列筛选的 count URL,使「总数」随筛选变化(与「显示」一致)。 */
|
||||
const buildCountUrl = (table: string): string => {
|
||||
const countUrl = table === 'general_feedbacks'
|
||||
? '/api/admin/reports/general-feedbacks/count'
|
||||
: `/api/admin/database/${table}/count`;
|
||||
const params = new URLSearchParams();
|
||||
for (const [key, value] of Object.entries(columnFilters.value)) {
|
||||
if (value) params.append(key, value);
|
||||
}
|
||||
const qs = params.toString();
|
||||
return qs ? `${countUrl}?${qs}` : countUrl;
|
||||
};
|
||||
|
||||
const loadTableCount = async (table: string) => {
|
||||
try {
|
||||
const countUrl = table === 'general_feedbacks'
|
||||
? '/api/admin/reports/general-feedbacks/count'
|
||||
: `/api/admin/database/${table}/count`;
|
||||
|
||||
const data = await getAdminReportTableCount(countUrl);
|
||||
const data = await getAdminReportTableCount(buildCountUrl(table));
|
||||
return Number(data.total || 0);
|
||||
} catch {
|
||||
return 0;
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* 加载「意见反馈」Tab 角标计数(general_feedbacks 记录总数)。
|
||||
* 核心逻辑:进入用户反馈与回答评价页时刷新,供 Tab 角标展示,非核心数据失败时静默降级为 0。
|
||||
*/
|
||||
const loadGeneralFeedbackTotal = async (): Promise<void> => {
|
||||
if (!isMergedFeedbackTable.value) return;
|
||||
try {
|
||||
generalFeedbackTotal.value = await loadTableCount('general_feedbacks');
|
||||
} catch {
|
||||
generalFeedbackTotal.value = 0;
|
||||
}
|
||||
};
|
||||
|
||||
const exportToExcel = () => {
|
||||
if (currentTable.value === 'agents') {
|
||||
exportApplicationReport();
|
||||
@@ -593,17 +964,33 @@ const exportToExcel = () => {
|
||||
}
|
||||
if (tableData.value.length === 0) return;
|
||||
const keys = visibleReportKeys.value;
|
||||
const rows = tableData.value.map((row) => {
|
||||
// 「用户反馈与回答评价」导出当前 Tab + 当前筛选结果(时间范围已由服务端过滤进 tableData)
|
||||
const sourceRows = isMergedFeedbackTable.value ? sortedTableData.value : tableData.value;
|
||||
const rows = sourceRows.map((row) => {
|
||||
const out: Record<string, unknown> = {};
|
||||
for (const key of keys) {
|
||||
out[getReportColumnLabel(key)] = getReportCellValue(row, key);
|
||||
}
|
||||
return out;
|
||||
});
|
||||
const ws = XLSX.utils.json_to_sheet(rows.length > 0 ? rows : tableData.value);
|
||||
const ws = XLSX.utils.json_to_sheet(rows.length > 0 ? rows : sourceRows);
|
||||
const wb = XLSX.utils.book_new();
|
||||
XLSX.utils.book_append_sheet(wb, ws, currentTable.value);
|
||||
XLSX.writeFile(wb, `${currentTable.value}_report_${new Date().toISOString().split('T')[0]}.xlsx`);
|
||||
// 反馈页文件名包含模块(Tab)与时间范围,避免误解为总体结论
|
||||
let sheetName: string = currentTable.value;
|
||||
let fileName: string = `${currentTable.value}_report_${new Date().toISOString().split('T')[0]}`;
|
||||
if (isMergedFeedbackTable.value) {
|
||||
const tabLabel = feedbackTab.value === 'rating'
|
||||
? t('admin.report.feedback.tabs.rating')
|
||||
: t('admin.report.feedback.tabs.general');
|
||||
const moduleLabel = getReportTableLabel(currentTable.value);
|
||||
const fromDate = columnFilters.value.created_from || '';
|
||||
const toDate = columnFilters.value.created_to || '';
|
||||
const rangeLabel = fromDate && toDate ? `${fromDate}_${toDate}` : 'all';
|
||||
fileName = `${moduleLabel}_${tabLabel}_${rangeLabel}`;
|
||||
sheetName = feedbackTab.value === 'rating' ? 'answer_rating' : 'general_feedback';
|
||||
}
|
||||
XLSX.utils.book_append_sheet(wb, ws, sheetName);
|
||||
XLSX.writeFile(wb, `${fileName}.xlsx`);
|
||||
};
|
||||
|
||||
// Debounce filter input
|
||||
@@ -618,10 +1005,20 @@ const handleFilterChange = () => {
|
||||
const isUsageAnalysisTable = computed(() => currentTable.value === 'usage_analysis');
|
||||
const isApplicationOpsTable = computed(() => currentTable.value === 'agents');
|
||||
const isChatLogsTable = computed(() => dataSourceTable.value === 'chat_logs');
|
||||
/** 列已初始化后(含筛选无结果)仍展示表头与筛选框;应用运营页用专用看板,不展示通用表 */
|
||||
const isMergedFeedbackTable = computed(() => currentTable.value === 'feedbacks');
|
||||
const isOpsOverviewTable = computed(() => currentTable.value === 'ops_overview');
|
||||
const isIssueAnalysisTable = computed(() => currentTable.value === 'issue_analysis');
|
||||
/** 已无占位页(问题分析已实现) */
|
||||
const isPlaceholderTable = computed(() => false);
|
||||
/** 使用分析 / 运营总览 / 问题分析:非通用数据表页,隐藏列设置/导出等表格工具栏 */
|
||||
const isNonTablePage = computed(
|
||||
() => isUsageAnalysisTable.value || isOpsOverviewTable.value || isIssueAnalysisTable.value,
|
||||
);
|
||||
/** 列已初始化后(含筛选无结果)仍展示表头与筛选框;应用运营/非表看板不展示通用表 */
|
||||
const showReportTable = computed(
|
||||
() =>
|
||||
!isApplicationOpsTable.value
|
||||
&& !isNonTablePage.value
|
||||
&& (tableData.value.length > 0 || chatLogsColumns.value.length > 0),
|
||||
);
|
||||
const visibleReportKeys = computed(() => {
|
||||
@@ -632,7 +1029,14 @@ const visibleReportKeys = computed(() => {
|
||||
keys = chatLogsColumns.value.filter((c) => c.visible).map((c) => c.key);
|
||||
}
|
||||
|
||||
if (currentTable.value === 'general_feedbacks') {
|
||||
if (dataSourceTable.value === 'feedbacks') {
|
||||
// 回答评价:字段更易读的顺序(关联聊天/评价时间/评分/评价内容/内部 ID)
|
||||
const ratingFixedOrder = ['chat_log_id', 'created_at', 'score', 'comment', 'id'];
|
||||
const available = new Set(keys);
|
||||
return ratingFixedOrder.filter((k) => available.has(k));
|
||||
}
|
||||
|
||||
if (dataSourceTable.value === 'general_feedbacks') {
|
||||
const feedbackFixedOrder = [
|
||||
'created_at',
|
||||
'source_page',
|
||||
@@ -643,9 +1047,11 @@ const visibleReportKeys = computed(() => {
|
||||
'real_name',
|
||||
'department',
|
||||
'chat_log_id',
|
||||
'actions',
|
||||
];
|
||||
const available = new Set(keys);
|
||||
return feedbackFixedOrder.filter((k) => available.has(k));
|
||||
// actions 为虚拟操作列,始终展示;其余按可用列过滤
|
||||
return feedbackFixedOrder.filter((k) => k === 'actions' || available.has(k));
|
||||
}
|
||||
|
||||
if (dataSourceTable.value === 'chat_logs') {
|
||||
@@ -664,12 +1070,26 @@ const resolveReportLang = () => {
|
||||
return 'en';
|
||||
};
|
||||
|
||||
const feedbackReportI18nMap: Record<string, {
|
||||
/** 反馈报表 i18n 语言包:列/类型/模块/页面/按 Tab 收敛的列名 */
|
||||
interface FeedbackReportI18nPack {
|
||||
columns: Record<string, string>;
|
||||
types: Record<string, string>;
|
||||
modules: Record<string, string>;
|
||||
pages: Record<string, string>;
|
||||
}> = {
|
||||
generalColumns: Record<string, string>;
|
||||
ratingColumns: Record<string, string>;
|
||||
}
|
||||
/** 兜底空语言包,避免 enPack 回退时缺失字段导致类型报错 */
|
||||
const EMPTY_FEEDBACK_PACK: FeedbackReportI18nPack = {
|
||||
columns: {},
|
||||
types: {},
|
||||
modules: {},
|
||||
pages: {},
|
||||
generalColumns: {},
|
||||
ratingColumns: {},
|
||||
};
|
||||
|
||||
const feedbackReportI18nMap: Record<string, FeedbackReportI18nPack> = {
|
||||
en: {
|
||||
columns: {
|
||||
feedback_module: 'Feedback Module',
|
||||
@@ -694,6 +1114,18 @@ const feedbackReportI18nMap: Record<string, {
|
||||
chat: 'Chat',
|
||||
unknown: 'Unknown',
|
||||
},
|
||||
/** 意见反馈 Tab 专用列名(覆盖通用列名,主要在关联跳转列) */
|
||||
generalColumns: {
|
||||
chat_log_id: 'Linked Chat',
|
||||
},
|
||||
/** 回答评价 Tab 列名:更易读、贴合评价语境 */
|
||||
ratingColumns: {
|
||||
chat_log_id: 'Linked Chat',
|
||||
created_at: 'Rated At',
|
||||
score: 'Score',
|
||||
comment: 'Comment',
|
||||
id: 'Internal ID',
|
||||
},
|
||||
},
|
||||
'zh-CN': {
|
||||
columns: {
|
||||
@@ -719,6 +1151,16 @@ const feedbackReportI18nMap: Record<string, {
|
||||
chat: '\u5bf9\u8bdd',
|
||||
unknown: '\u672a\u77e5',
|
||||
},
|
||||
generalColumns: {
|
||||
chat_log_id: '\u5173\u8054\u804a\u5929',
|
||||
},
|
||||
ratingColumns: {
|
||||
chat_log_id: '\u5173\u8054\u804a\u5929',
|
||||
created_at: '\u8bc4\u4ef7\u65f6\u95f4',
|
||||
score: '\u8bc4\u5206',
|
||||
comment: '\u8bc4\u4ef7\u5185\u5bb9',
|
||||
id: '\u5185\u90e8 ID',
|
||||
},
|
||||
},
|
||||
'zh-TW': {
|
||||
columns: {
|
||||
@@ -744,6 +1186,16 @@ const feedbackReportI18nMap: Record<string, {
|
||||
chat: '\u5c0d\u8a71',
|
||||
unknown: '\u672a\u77e5',
|
||||
},
|
||||
generalColumns: {
|
||||
chat_log_id: '\u95dc\u806f\u804a\u5929',
|
||||
},
|
||||
ratingColumns: {
|
||||
chat_log_id: '\u95dc\u806f\u804a\u5929',
|
||||
created_at: '\u8a55\u50f9\u6642\u9593',
|
||||
score: '\u8a55\u5206',
|
||||
comment: '\u8a55\u50f9\u5167\u5bb9',
|
||||
id: '\u5167\u90e8 ID',
|
||||
},
|
||||
},
|
||||
th: {
|
||||
columns: {
|
||||
@@ -769,12 +1221,30 @@ const feedbackReportI18nMap: Record<string, {
|
||||
chat: '\u0e41\u0e0a\u0e17',
|
||||
unknown: '\u0e44\u0e21\u0e48\u0e17\u0e23\u0e32\u0e1a',
|
||||
},
|
||||
generalColumns: {
|
||||
chat_log_id: '\u0e41\u0e0a\u0e17\u0e17\u0e35\u0e48\u0e40\u0e0a\u0e37\u0e48\u0e2d\u0e21\u0e42\u0e22\u0e07',
|
||||
},
|
||||
ratingColumns: {
|
||||
chat_log_id: '\u0e41\u0e0a\u0e17\u0e17\u0e35\u0e48\u0e40\u0e0a\u0e37\u0e48\u0e2d\u0e21\u0e42\u0e22\u0e07',
|
||||
created_at: '\u0e40\u0e27\u0e25\u0e32\u0e17\u0e35\u0e48\u0e43\u0e2b\u0e49\u0e04\u0e30\u0e41\u0e19\u0e19',
|
||||
score: '\u0e04\u0e30\u0e41\u0e19\u0e19',
|
||||
comment: '\u0e40\u0e19\u0e37\u0e49\u0e2d\u0e2b\u0e32\u0e04\u0e27\u0e32\u0e21\u0e04\u0e34\u0e14\u0e40\u0e2b\u0e47\u0e19',
|
||||
id: 'ID \u0e20\u0e32\u0e22\u0e43\u0e19',
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
const getReportColumnLabel = (key: string) => {
|
||||
const getReportColumnLabel = (key: string): string => {
|
||||
const lang = resolveReportLang();
|
||||
const enPack = feedbackReportI18nMap['en'] || { columns: {}, types: {}, modules: {}, pages: {} };
|
||||
const enPack = feedbackReportI18nMap['en'] || EMPTY_FEEDBACK_PACK;
|
||||
// 「用户反馈与回答评价」页按 Tab 收敛更易读的列名(关联聊天/评价时间/评分/评价内容等)
|
||||
if (isMergedFeedbackTable.value) {
|
||||
const tabPack = feedbackTab.value === 'rating'
|
||||
? (feedbackReportI18nMap[lang]?.ratingColumns || enPack.ratingColumns)
|
||||
: (feedbackReportI18nMap[lang]?.generalColumns || enPack.generalColumns);
|
||||
const tabDirect = tabPack[key];
|
||||
if (tabDirect) return tabDirect;
|
||||
}
|
||||
const direct = feedbackReportI18nMap[lang]?.columns?.[key] || enPack.columns[key];
|
||||
if (direct) return direct;
|
||||
const i18nKey = `admin.report.columns.${key}`;
|
||||
@@ -834,9 +1304,9 @@ const getTranslatedFeedbackValue = (group: 'types' | 'modules' | 'pages', value:
|
||||
const normalized = normalizeFeedbackKey(value);
|
||||
if (!normalized) return value;
|
||||
const lang = resolveReportLang();
|
||||
const enPack = feedbackReportI18nMap['en'] || { columns: {}, types: {}, modules: {}, pages: {} };
|
||||
const enPack = feedbackReportI18nMap['en'] || EMPTY_FEEDBACK_PACK;
|
||||
const dict = feedbackReportI18nMap[lang]?.[group] || enPack[group];
|
||||
return dict?.[normalized] || value;
|
||||
return dict[normalized] || value;
|
||||
};
|
||||
|
||||
const formatReportDateTime = (value: any) => {
|
||||
@@ -919,7 +1389,20 @@ const sortedTableData = computed(() => {
|
||||
const list = [...tableData.value];
|
||||
const advanced = chatLogsSortRules.value.length > 0 ? chatLogsSortRules.value : [];
|
||||
const rules = advanced.length > 0 ? advanced : (reportHeaderSort.value ? [reportHeaderSort.value] : []);
|
||||
if (rules.length === 0) return list;
|
||||
if (rules.length === 0) {
|
||||
// 「用户反馈与回答评价」默认按创建时间倒序(回答评价无服务端排序,前端兜底)
|
||||
if (isMergedFeedbackTable.value && dataSourceTable.value === 'feedbacks') {
|
||||
return list.sort((a, b) => {
|
||||
const av = Date.parse(String(a?.created_at ?? ''));
|
||||
const bv = Date.parse(String(b?.created_at ?? ''));
|
||||
if (Number.isNaN(av) && Number.isNaN(bv)) return 0;
|
||||
if (Number.isNaN(av)) return 1;
|
||||
if (Number.isNaN(bv)) return -1;
|
||||
return bv - av;
|
||||
});
|
||||
}
|
||||
return list;
|
||||
}
|
||||
return list.sort((a, b) => {
|
||||
for (const r of rules) {
|
||||
const c = compareByRule(a, b, r);
|
||||
@@ -963,6 +1446,31 @@ const reportPageButtons = computed(() => {
|
||||
return buildOffsetPageButtons(current, total);
|
||||
});
|
||||
|
||||
/** 问题分析:优先处理问题总数(前端分页) */
|
||||
const issueQuestionTotal = computed(() => issueAnalysis.value?.questions?.length ?? 0);
|
||||
const issueQuestionTotalPages = computed(() => {
|
||||
const size = Math.max(1, Number(reportPageSize.value) || 20);
|
||||
return Math.max(1, Math.ceil(issueQuestionTotal.value / size));
|
||||
});
|
||||
/**
|
||||
* 问题分析当前页问题列表。
|
||||
* 核心逻辑:复用 reportCurrentPage / reportPageSize,对 questions 做偏移切片。
|
||||
*/
|
||||
const paginatedIssueQuestions = computed(() => {
|
||||
const list = issueAnalysis.value?.questions ?? [];
|
||||
const size = Math.max(1, Number(reportPageSize.value) || 20);
|
||||
const safePage = Math.min(Math.max(1, reportCurrentPage.value), issueQuestionTotalPages.value);
|
||||
const start = (safePage - 1) * size;
|
||||
return list.slice(start, start + size);
|
||||
});
|
||||
/**
|
||||
* 跳转问题分析分页;页码超出时钳制到有效范围。
|
||||
* @param page - 目标页(1-based)
|
||||
*/
|
||||
const goToIssueAnalysisPage = (page: number): void => {
|
||||
reportCurrentPage.value = Math.min(Math.max(1, page), issueQuestionTotalPages.value);
|
||||
};
|
||||
|
||||
const onReportHeaderClick = (key: string) => {
|
||||
// Column-header sorting is the quick mode; clear advanced rules to avoid precedence conflict.
|
||||
if (chatLogsSortRules.value.length > 0) {
|
||||
@@ -1062,18 +1570,61 @@ const batchDeleteChatLogs = async () => {
|
||||
|
||||
watch(currentTable, async () => {
|
||||
applyRouteQueryFilters();
|
||||
ensureChatLogsRange();
|
||||
chatLogsColumns.value = [];
|
||||
selectedReportRowIds.value = [];
|
||||
showChatLogsColumnPanel.value = false;
|
||||
showChatLogsSelection.value = false;
|
||||
reportCurrentPage.value = 1;
|
||||
await loadTableData();
|
||||
reportHeaderSort.value = null;
|
||||
if (dataSourceTable.value === 'chat_logs' && !isApplicationOpsTable.value) {
|
||||
expandedFeedbackId.value = null;
|
||||
if (isOpsOverviewTable.value) {
|
||||
tableData.value = [];
|
||||
await loadOpsOverview();
|
||||
return;
|
||||
}
|
||||
if (isIssueAnalysisTable.value) {
|
||||
tableData.value = [];
|
||||
await loadIssueAnalysis();
|
||||
return;
|
||||
}
|
||||
if (isUsageAnalysisTable.value) {
|
||||
tableData.value = [];
|
||||
await loadUsageReport();
|
||||
return;
|
||||
}
|
||||
await loadTableData();
|
||||
if (dataSourceTable.value === 'chat_logs' && !isApplicationOpsTable.value && !isUsageAnalysisTable.value) {
|
||||
chatLogsTotal.value = await loadTableCount('chat_logs');
|
||||
}
|
||||
if (isMergedFeedbackTable.value) {
|
||||
await loadGeneralFeedbackTotal();
|
||||
}
|
||||
});
|
||||
|
||||
/**
|
||||
* 「用户反馈与回答评价」页内切换 Tab 时,重建列配置并按新数据源重新加载。
|
||||
*/
|
||||
watch(feedbackTab, async () => {
|
||||
if (!isMergedFeedbackTable.value) return;
|
||||
chatLogsColumns.value = [];
|
||||
selectedReportRowIds.value = [];
|
||||
showChatLogsColumnPanel.value = false;
|
||||
showChatLogsSelection.value = false;
|
||||
reportCurrentPage.value = 1;
|
||||
reportHeaderSort.value = null;
|
||||
expandedFeedbackId.value = null;
|
||||
await loadTableData();
|
||||
});
|
||||
|
||||
/**
|
||||
* 切换「用户反馈与回答评价」页内 Tab。
|
||||
* @param tab - general=意见反馈,rating=回答评价
|
||||
*/
|
||||
const switchFeedbackTab = (tab: ReportFeedbackTab): void => {
|
||||
feedbackTab.value = tab;
|
||||
};
|
||||
|
||||
watch(chatLogsColumns, () => {
|
||||
saveChatLogsColumns();
|
||||
}, { deep: true });
|
||||
@@ -1108,6 +1659,12 @@ watch(usageRange, () => {
|
||||
void loadUsageReport();
|
||||
});
|
||||
|
||||
watch(opsOverviewRange, () => {
|
||||
if (isOpsOverviewTable.value) {
|
||||
void loadOpsOverview();
|
||||
}
|
||||
});
|
||||
|
||||
watch(usageAgentPageSize, () => {
|
||||
usageAgentPage.value = 1;
|
||||
});
|
||||
@@ -1134,21 +1691,62 @@ watch([reportPageSize, sortedTableData], () => {
|
||||
}
|
||||
});
|
||||
|
||||
watch([reportPageSize, issueQuestionTotal], () => {
|
||||
if (!isIssueAnalysisTable.value) return;
|
||||
if (reportCurrentPage.value > issueQuestionTotalPages.value) {
|
||||
reportCurrentPage.value = issueQuestionTotalPages.value;
|
||||
}
|
||||
if (reportCurrentPage.value < 1) {
|
||||
reportCurrentPage.value = 1;
|
||||
}
|
||||
});
|
||||
|
||||
const loadAll = async (): Promise<void> => {
|
||||
isLoading.value = true;
|
||||
// 运营总览:走独立 /reports/overview 接口
|
||||
if (isOpsOverviewTable.value) {
|
||||
tableData.value = [];
|
||||
chatLogsColumns.value = [];
|
||||
selectedReportRowIds.value = [];
|
||||
showChatLogsColumnPanel.value = false;
|
||||
showChatLogsSelection.value = false;
|
||||
reportCurrentPage.value = 1;
|
||||
reportHeaderSort.value = null;
|
||||
await loadOpsOverview();
|
||||
isLoading.value = false;
|
||||
return;
|
||||
}
|
||||
// 问题分析:高频问题簇 KPI + 优先处理问题(复用聊天日志风险规则)
|
||||
if (isIssueAnalysisTable.value) {
|
||||
tableData.value = [];
|
||||
chatLogsColumns.value = [];
|
||||
selectedReportRowIds.value = [];
|
||||
showChatLogsColumnPanel.value = false;
|
||||
showChatLogsSelection.value = false;
|
||||
reportCurrentPage.value = 1;
|
||||
reportHeaderSort.value = null;
|
||||
await loadIssueAnalysis();
|
||||
isLoading.value = false;
|
||||
return;
|
||||
}
|
||||
await loadReports();
|
||||
applyRouteQueryFilters();
|
||||
ensureChatLogsRange();
|
||||
selectedReportRowIds.value = [];
|
||||
showChatLogsColumnPanel.value = false;
|
||||
showChatLogsSelection.value = false;
|
||||
reportCurrentPage.value = 1;
|
||||
reportHeaderSort.value = null;
|
||||
expandedFeedbackId.value = null;
|
||||
await loadTableData();
|
||||
if (dataSourceTable.value === 'chat_logs' && !isApplicationOpsTable.value) {
|
||||
if (dataSourceTable.value === 'chat_logs' && !isApplicationOpsTable.value && !isUsageAnalysisTable.value) {
|
||||
chatLogsTotal.value = await loadTableCount('chat_logs');
|
||||
} else {
|
||||
showChatLogsSelection.value = false;
|
||||
}
|
||||
if (isMergedFeedbackTable.value) {
|
||||
await loadGeneralFeedbackTotal();
|
||||
}
|
||||
isLoading.value = false;
|
||||
};
|
||||
|
||||
@@ -1164,6 +1762,8 @@ watch([reportPageSize, sortedTableData], () => {
|
||||
usageUserTopLimit,
|
||||
usageActiveAgentCount,
|
||||
usageTrendMax,
|
||||
usageTrendByDay,
|
||||
opsTrendByDay,
|
||||
usageLowAgentMaxChats,
|
||||
usageLowAgentListLimit,
|
||||
usageSpikeDayMinChats: USAGE_SPIKE_DAY_MIN_CHATS,
|
||||
@@ -1183,6 +1783,9 @@ watch([reportPageSize, sortedTableData], () => {
|
||||
goToUsageUserPage,
|
||||
prevUsageUserPage,
|
||||
nextUsageUserPage,
|
||||
opsOverview,
|
||||
opsOverviewRange,
|
||||
issueAnalysis,
|
||||
applicationReport,
|
||||
applicationRange,
|
||||
applicationStatus,
|
||||
@@ -1227,11 +1830,51 @@ watch([reportPageSize, sortedTableData], () => {
|
||||
isUsageAnalysisTable,
|
||||
isApplicationOpsTable,
|
||||
isChatLogsTable,
|
||||
isMergedFeedbackTable,
|
||||
isOpsOverviewTable,
|
||||
isIssueAnalysisTable,
|
||||
isPlaceholderTable,
|
||||
isNonTablePage,
|
||||
feedbackTab,
|
||||
switchFeedbackTab,
|
||||
generalFeedbackTotal,
|
||||
feedbackSummary,
|
||||
expandedFeedbackId,
|
||||
closeFeedback,
|
||||
feedbackTypeOptions,
|
||||
feedbackModuleOptions,
|
||||
feedbackSourceOptions,
|
||||
getTranslatedFeedbackValue,
|
||||
openFeedbackChatLog,
|
||||
getFeedbackChatLogCell,
|
||||
toggleFeedbackContent,
|
||||
isFeedbackContentExpanded,
|
||||
openFeedbackContent,
|
||||
closeFeedbackContent,
|
||||
chatLogDetailVisible,
|
||||
chatLogDetailRow,
|
||||
openChatLogDetail,
|
||||
closeChatLogDetail,
|
||||
chatLogTops,
|
||||
chatLogTopsQuestionsMax,
|
||||
chatLogTopsAnswersMax,
|
||||
chatLogRangeOptions,
|
||||
chatLogAgents,
|
||||
getChatLogRiskStatusLabel,
|
||||
getChatLogRiskReasonLabel,
|
||||
getChatLogRiskCheckLabel,
|
||||
getChatLogRiskStatusClass,
|
||||
resetChatLogFilters,
|
||||
chatLogRiskStatusOptions: CHAT_LOG_RISK_STATUS_OPTIONS,
|
||||
showReportTable,
|
||||
visibleReportKeys,
|
||||
allReportRowsSelected,
|
||||
sortedTableData,
|
||||
paginatedSortedTableData,
|
||||
issueQuestionTotal,
|
||||
issueQuestionTotalPages,
|
||||
paginatedIssueQuestions,
|
||||
goToIssueAnalysisPage,
|
||||
reportTotalRows,
|
||||
reportTotalPages,
|
||||
reportRangeStart,
|
||||
|
||||
@@ -1,100 +0,0 @@
|
||||
/**
|
||||
* features/admin/modules/requests/RequestsPage.vue
|
||||
* 权限申请管理独立页面。路由:/admin/requests
|
||||
*/
|
||||
<script setup lang="ts">
|
||||
import { onMounted } from 'vue';
|
||||
import { useI18n } from 'vue-i18n';
|
||||
import { ShieldCheck } from 'lucide-vue-next';
|
||||
import { useRequestsAdmin } from './composables/useRequestsAdmin';
|
||||
|
||||
const { t } = useI18n();
|
||||
|
||||
const {
|
||||
requests,
|
||||
isLoading,
|
||||
loadAll,
|
||||
approveRequest,
|
||||
rejectRequest,
|
||||
} = useRequestsAdmin();
|
||||
|
||||
onMounted(() => {
|
||||
void loadAll();
|
||||
});
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<section class="admin-table-section">
|
||||
<div v-if="isLoading" class="flex items-center justify-center py-20">
|
||||
<div class="animate-spin rounded-full h-10 w-10 border-b-2 border-brand-600" />
|
||||
</div>
|
||||
|
||||
<template v-else>
|
||||
<div class="admin-table-header">
|
||||
<div>
|
||||
<h2 class="section-title">{{ t('admin.request.title') }}</h2>
|
||||
<p class="section-desc mt-1">{{ t('admin.request.subtitle') }}</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div
|
||||
v-if="requests.length === 0"
|
||||
class="flex flex-col items-center justify-center py-16 text-muted"
|
||||
>
|
||||
<div class="w-16 h-16 bg-surface-soft rounded-full flex items-center justify-center mb-4">
|
||||
<ShieldCheck class="w-8 h-8 text-muted" />
|
||||
</div>
|
||||
<p>{{ t('admin.request.noPending') }}</p>
|
||||
</div>
|
||||
|
||||
<table v-else class="admin-table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th class="px-8 py-4 text-xs">{{ t('admin.request.headers.userId') }}</th>
|
||||
<th class="px-8 py-4 text-xs">{{ t('admin.request.headers.targetAgent') }}</th>
|
||||
<th class="px-8 py-4 text-xs">{{ t('admin.request.headers.reason') }}</th>
|
||||
<th class="px-8 py-4 text-xs">{{ t('admin.request.headers.status') }}</th>
|
||||
<th class="px-8 py-4 text-xs text-right">{{ t('admin.request.headers.actions') }}</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr v-for="req in requests" :key="req.id">
|
||||
<td class="px-8 py-4 text-sm font-medium text-primary">{{ req.user_id }}</td>
|
||||
<td class="px-8 py-4 text-sm text-secondary">{{ req.agent_id }}</td>
|
||||
<td
|
||||
class="px-8 py-4 text-sm text-muted 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"
|
||||
>
|
||||
{{ t('admin.status.' + req.status) }}
|
||||
</span>
|
||||
</td>
|
||||
<td class="px-8 py-4 text-right">
|
||||
<div class="flex justify-end gap-3">
|
||||
<button
|
||||
type="button"
|
||||
class="text-green-600 hover:text-green-800 text-sm font-medium hover:underline"
|
||||
@click="approveRequest(req.id)"
|
||||
>
|
||||
{{ t('admin.request.approve') }}
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
class="text-red-500 hover:text-red-700 text-sm font-medium hover:underline"
|
||||
@click="rejectRequest(req.id)"
|
||||
>
|
||||
{{ t('admin.request.reject') }}
|
||||
</button>
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</template>
|
||||
</section>
|
||||
</template>
|
||||
@@ -1,68 +0,0 @@
|
||||
/**
|
||||
* features/admin/modules/requests/composables/useRequestsAdmin.ts
|
||||
* 权限申请管理:列表、通过、拒绝。
|
||||
*/
|
||||
import { ref } from 'vue';
|
||||
import { useI18n } from 'vue-i18n';
|
||||
import {
|
||||
approveAdminPermissionRequest,
|
||||
listAdminPermissionRequests,
|
||||
rejectAdminPermissionRequest,
|
||||
} from '@/features/admin/api/admin.api';
|
||||
import { useMessage } from '@/shared/composables/useMessage';
|
||||
import { useAdminNavBadges } from '@/features/admin/composables/useAdminNavBadges';
|
||||
import type { AdminPermissionRequestRow } from '@/features/admin/types/request.types';
|
||||
|
||||
export function useRequestsAdmin() {
|
||||
const { t } = useI18n();
|
||||
const msg = useMessage();
|
||||
const { refreshBadges } = useAdminNavBadges();
|
||||
|
||||
const requests = ref<AdminPermissionRequestRow[]>([]);
|
||||
const isLoading = ref(true);
|
||||
|
||||
const loadRequests = async (): Promise<void> => {
|
||||
try {
|
||||
requests.value = await listAdminPermissionRequests();
|
||||
} catch (e) {
|
||||
console.error('Error loading permission requests:', e);
|
||||
requests.value = [];
|
||||
}
|
||||
};
|
||||
|
||||
const loadAll = async (): Promise<void> => {
|
||||
isLoading.value = true;
|
||||
await loadRequests();
|
||||
isLoading.value = false;
|
||||
};
|
||||
|
||||
const approveRequest = async (id: number): Promise<void> => {
|
||||
try {
|
||||
await approveAdminPermissionRequest(id);
|
||||
await loadRequests();
|
||||
await refreshBadges();
|
||||
} catch (e) {
|
||||
console.error(e);
|
||||
msg.error((e as Error).message || t('admin.msg.failed'));
|
||||
}
|
||||
};
|
||||
|
||||
const rejectRequest = async (id: number): Promise<void> => {
|
||||
try {
|
||||
await rejectAdminPermissionRequest(id);
|
||||
await loadRequests();
|
||||
await refreshBadges();
|
||||
} catch (e) {
|
||||
console.error(e);
|
||||
msg.error((e as Error).message || t('admin.msg.failed'));
|
||||
}
|
||||
};
|
||||
|
||||
return {
|
||||
requests,
|
||||
isLoading,
|
||||
loadAll,
|
||||
approveRequest,
|
||||
rejectRequest,
|
||||
};
|
||||
}
|
||||
@@ -11,6 +11,7 @@ import { Edit, Plus, Trash2, Users } from 'lucide-vue-next';
|
||||
import DeleteConfirmDialog from '@/shared/components/DeleteConfirmDialog.vue';
|
||||
import PaginationBar from '@/shared/components/PaginationBar.vue';
|
||||
import SortableTableHeader from '@/shared/components/SortableTableHeader.vue';
|
||||
import { getUserAvatarLabel } from '@/shared/utils/user-avatar';
|
||||
import BatchEditUserModal from './components/BatchEditUserModal.vue';
|
||||
import BatchPermissionModal from './components/BatchPermissionModal.vue';
|
||||
import UserFormModal from './components/UserFormModal.vue';
|
||||
@@ -199,7 +200,7 @@ onMounted(() => {
|
||||
<td class="px-6 py-4">
|
||||
<div class="flex items-center">
|
||||
<div class="h-9 w-9 rounded-full bg-gradient-to-br from-brand-500 to-indigo-600 text-white flex items-center justify-center text-xs font-bold shadow-sm">
|
||||
{{ user.username.charAt(0).toUpperCase() }}
|
||||
{{ getUserAvatarLabel(user) }}
|
||||
</div>
|
||||
<div class="ml-3 text-sm font-medium text-primary">{{ user.username }}</div>
|
||||
</div>
|
||||
|
||||
Reference in new issue
Block a user