style: 日期查询展示时间范围
This commit is contained in:
1 parent
4445ff68d4
commit
cc41f8fe25
9 files changed
+215
-116
No files matched your search
@@ -33,8 +33,8 @@ function formatUsageUserLabel(user: { username: string; real_name?: string }): s
|
||||
|
||||
const {
|
||||
usageReport,
|
||||
usageRange,
|
||||
usageRangeOptions,
|
||||
usageStartDate,
|
||||
usageEndDate,
|
||||
usageUserTotal,
|
||||
usageUserTopLimit,
|
||||
usageActiveAgentCount,
|
||||
@@ -61,7 +61,8 @@ const {
|
||||
usageSpikeDayMinChats,
|
||||
usageSpikeDayAvgMultiplier,
|
||||
usageSpikeDayListLimit,
|
||||
applicationRange,
|
||||
applicationStartDate,
|
||||
applicationEndDate,
|
||||
applicationStatus,
|
||||
applicationUsage,
|
||||
applicationQuery,
|
||||
@@ -102,7 +103,8 @@ const {
|
||||
isIssueAnalysisTable,
|
||||
isNonTablePage,
|
||||
opsOverview,
|
||||
opsOverviewRange,
|
||||
opsOverviewStartDate,
|
||||
opsOverviewEndDate,
|
||||
issueAnalysis,
|
||||
feedbackTab,
|
||||
switchFeedbackTab,
|
||||
@@ -132,7 +134,6 @@ const {
|
||||
chatLogTops,
|
||||
chatLogTopsQuestionsMax,
|
||||
chatLogTopsAnswersMax,
|
||||
chatLogRangeOptions,
|
||||
chatLogAgents,
|
||||
showReportTable,
|
||||
visibleReportKeys,
|
||||
@@ -460,14 +461,16 @@ onBeforeUnmount(() => {
|
||||
<h3 class="section-title text-lg">{{ t('admin.report.usage') }}</h3>
|
||||
<p class="mt-1 text-sm text-secondary">{{ t('admin.report.usageIntro') }}</p>
|
||||
</div>
|
||||
<label class="flex items-center gap-2 text-sm text-secondary">
|
||||
<span class="whitespace-nowrap">{{ t('admin.report.usageRangeLabel') }}</span>
|
||||
<select v-model="usageRange" class="admin-table-filter-input min-w-[8rem]">
|
||||
<option v-for="key in usageRangeOptions" :key="key" :value="key">
|
||||
{{ t(`admin.report.usageRanges.${key}`) }}
|
||||
</option>
|
||||
</select>
|
||||
</label>
|
||||
<div class="flex items-end gap-2">
|
||||
<label class="flex flex-col gap-1 text-sm text-secondary">
|
||||
<span class="whitespace-nowrap">{{ t('admin.report.dateFrom') }}</span>
|
||||
<input v-model="usageStartDate" type="date" class="admin-table-filter-input" />
|
||||
</label>
|
||||
<label class="flex flex-col gap-1 text-sm text-secondary">
|
||||
<span class="whitespace-nowrap">{{ t('admin.report.dateTo') }}</span>
|
||||
<input v-model="usageEndDate" type="date" class="admin-table-filter-input" />
|
||||
</label>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="grid grid-cols-1 gap-3 md:grid-cols-3">
|
||||
@@ -709,14 +712,14 @@ onBeforeUnmount(() => {
|
||||
<h3 class="section-title text-lg">{{ t('admin.report.appOps.title') }}</h3>
|
||||
<p class="mt-1 text-sm text-secondary">{{ t('admin.report.appOps.intro') }}</p>
|
||||
</div>
|
||||
<div class="flex flex-wrap items-center gap-2">
|
||||
<label class="flex items-center gap-2 text-sm text-secondary">
|
||||
<span class="whitespace-nowrap">{{ t('admin.report.usageRangeLabel') }}</span>
|
||||
<select v-model="applicationRange" class="admin-table-filter-input min-w-[8rem]">
|
||||
<option v-for="key in usageRangeOptions" :key="`app-range-${key}`" :value="key">
|
||||
{{ t(`admin.report.usageRanges.${key}`) }}
|
||||
</option>
|
||||
</select>
|
||||
<div class="flex flex-wrap items-end gap-2">
|
||||
<label class="flex flex-col gap-1 text-sm text-secondary">
|
||||
<span class="whitespace-nowrap">{{ t('admin.report.dateFrom') }}</span>
|
||||
<input v-model="applicationStartDate" type="date" class="admin-table-filter-input" />
|
||||
</label>
|
||||
<label class="flex flex-col gap-1 text-sm text-secondary">
|
||||
<span class="whitespace-nowrap">{{ t('admin.report.dateTo') }}</span>
|
||||
<input v-model="applicationEndDate" type="date" class="admin-table-filter-input" />
|
||||
</label>
|
||||
<label class="flex items-center gap-2 text-sm text-secondary">
|
||||
<span class="whitespace-nowrap">{{ t('admin.report.appOps.statusLabel') }}</span>
|
||||
@@ -1014,14 +1017,16 @@ onBeforeUnmount(() => {
|
||||
<h3 class="section-title text-lg">{{ t('admin.report.opsOverview.title') }}</h3>
|
||||
<p class="mt-1 text-sm text-secondary">{{ t('admin.report.opsOverview.intro') }}</p>
|
||||
</div>
|
||||
<label class="flex items-center gap-2 text-sm text-secondary">
|
||||
<span class="whitespace-nowrap">{{ t('admin.report.usageRangeLabel') }}</span>
|
||||
<select v-model="opsOverviewRange" class="admin-table-filter-input min-w-[8rem]">
|
||||
<option v-for="key in usageRangeOptions" :key="`ov-range-${key}`" :value="key">
|
||||
{{ t(`admin.report.usageRanges.${key}`) }}
|
||||
</option>
|
||||
</select>
|
||||
</label>
|
||||
<div class="flex items-end gap-2">
|
||||
<label class="flex flex-col gap-1 text-sm text-secondary">
|
||||
<span class="whitespace-nowrap">{{ t('admin.report.dateFrom') }}</span>
|
||||
<input v-model="opsOverviewStartDate" type="date" class="admin-table-filter-input" />
|
||||
</label>
|
||||
<label class="flex flex-col gap-1 text-sm text-secondary">
|
||||
<span class="whitespace-nowrap">{{ t('admin.report.dateTo') }}</span>
|
||||
<input v-model="opsOverviewEndDate" type="date" class="admin-table-filter-input" />
|
||||
</label>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div v-if="opsOverview" class="space-y-5">
|
||||
@@ -1215,12 +1220,16 @@ onBeforeUnmount(() => {
|
||||
</div>
|
||||
|
||||
<div v-else-if="!isNonTablePage && !isApplicationOpsTable" class="space-y-4">
|
||||
<!-- 聊天日志:统一统计范围(近 7/30/90 天) -->
|
||||
<div v-if="isChatLogsTable" class="flex items-center gap-2 text-sm text-secondary">
|
||||
<span class="whitespace-nowrap">{{ t('admin.report.usageRangeLabel') }}</span>
|
||||
<select v-model="columnFilters.range" class="admin-table-filter-input min-w-[8rem] py-1" @change="handleFilterChange">
|
||||
<option v-for="key in chatLogRangeOptions" :key="key" :value="key">{{ t(`admin.report.usageRanges.${key}`) }}</option>
|
||||
</select>
|
||||
<!-- 聊天日志:统计范围(开始/结束日期,与后端 created_from/created_to 对应) -->
|
||||
<div v-if="isChatLogsTable" class="flex items-end gap-2 text-sm text-secondary">
|
||||
<label class="flex flex-col gap-1">
|
||||
<span class="whitespace-nowrap">{{ t('admin.report.dateFrom') }}</span>
|
||||
<input v-model="columnFilters.created_from" type="date" class="admin-table-filter-input" @change="handleFilterChange" />
|
||||
</label>
|
||||
<label class="flex flex-col gap-1">
|
||||
<span class="whitespace-nowrap">{{ t('admin.report.dateTo') }}</span>
|
||||
<input v-model="columnFilters.created_to" type="date" class="admin-table-filter-input" @change="handleFilterChange" />
|
||||
</label>
|
||||
</div>
|
||||
|
||||
<!-- 聊天日志:Top 提问内容 / Top 回答内容(直接按明细统计,条柱展示) -->
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
* 依赖:admin.api、useReportLayoutStorage、useOffsetPagination、useMessage、dateTime、vue-router。
|
||||
* 逻辑:ReportsPage 调用本 composable;使用分析按用户服务端分页、按应用前端分页,均复用 PaginationBar;
|
||||
* 低使用应用优先消费后端 low_agents(含零使用启用应用),与应用运营口径对齐;
|
||||
* 统计范围统一为开始/结束日期(默认近 30 天),经 start_date/end_date 传给后端,聊天日志走 created_from/created_to;
|
||||
* 趋势 by_day 前端按日期升序兜底;问题分析优先问题表前端分页;非表页切换时清空通用表状态防幽灵分页。
|
||||
*/
|
||||
import { computed, ref, watch } from 'vue';
|
||||
@@ -39,7 +40,6 @@ import type {
|
||||
ReportColumnConfig,
|
||||
ReportFeedbackTab,
|
||||
SortRule,
|
||||
UsageRangeKey,
|
||||
UsageReport,
|
||||
} from '@/features/admin/types/report.types';
|
||||
import type { AdminReportTableId } from '@/features/admin/types/admin.types';
|
||||
@@ -102,6 +102,22 @@ const defaultChatLogsColumnWidth = (key: string): number => {
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* 格式化为日期选择器(type=date)所需的本地 yyyy-mm-dd 值。
|
||||
* @param date - 本地日期对象
|
||||
* @returns yyyy-mm-dd 字符串
|
||||
*/
|
||||
const formatDateInputValue = (date: Date): string => {
|
||||
const y = date.getFullYear();
|
||||
const m = `${date.getMonth() + 1}`.padStart(2, '0');
|
||||
const d = `${date.getDate()}`.padStart(2, '0');
|
||||
return `${y}-${m}-${d}`;
|
||||
};
|
||||
|
||||
/** 报表统计范围默认值:近 30 天(今天往前 29 天 ~ 今天),与原「近 30 天」下拉口径一致 */
|
||||
const getDefaultReportStartDate = (): string => formatDateInputValue(new Date(Date.now() - 29 * 24 * 60 * 60 * 1000));
|
||||
const getDefaultReportEndDate = (): string => formatDateInputValue(new Date());
|
||||
|
||||
export function useReportsAdmin() {
|
||||
const { t, locale } = useI18n();
|
||||
const msg = useMessage();
|
||||
@@ -112,10 +128,9 @@ export function useReportsAdmin() {
|
||||
const usageUserPage = ref(1);
|
||||
const usageUserPageSize = ref(10);
|
||||
const usageUserPageSizeOptions = [5, 10, 20, 50];
|
||||
/** 使用分析时间范围,默认近 30 天 */
|
||||
const usageRange = ref<UsageRangeKey>('30d');
|
||||
/** 统一时间范围筛选器:仅近 7 天 / 30 天 / 90 天 */
|
||||
const usageRangeOptions: UsageRangeKey[] = ['7d', '30d', '90d'];
|
||||
/** 使用分析统计范围:开始/结束日期(默认近 30 天) */
|
||||
const usageStartDate = ref(getDefaultReportStartDate());
|
||||
const usageEndDate = ref(getDefaultReportEndDate());
|
||||
|
||||
/** 用户反馈与回答评价页内 Tab:general=意见反馈,rating=回答评价 */
|
||||
const feedbackTab = ref<ReportFeedbackTab>('general');
|
||||
@@ -133,8 +148,9 @@ export function useReportsAdmin() {
|
||||
const opsOverview = ref<OpsOverviewReport | null>(null);
|
||||
/** 问题分析:高频问题簇 KPI + 优先处理问题 */
|
||||
const issueAnalysis = ref<any | null>(null);
|
||||
/** 运营总览时间范围,默认近 30 天 */
|
||||
const opsOverviewRange = ref<UsageRangeKey>('30d');
|
||||
/** 运营总览统计范围:开始/结束日期(默认近 30 天) */
|
||||
const opsOverviewStartDate = ref(getDefaultReportStartDate());
|
||||
const opsOverviewEndDate = ref(getDefaultReportEndDate());
|
||||
|
||||
/** 按应用统计:前端分页(后端已返回范围内全部应用) */
|
||||
const usageAgentPage = ref(1);
|
||||
@@ -143,7 +159,9 @@ export function useReportsAdmin() {
|
||||
|
||||
/** 应用运营看板状态(替换原 agents 配置表浏览) */
|
||||
const applicationReport = ref<ApplicationReport | null>(null);
|
||||
const applicationRange = ref<UsageRangeKey>('30d');
|
||||
/** 应用运营统计范围:开始/结束日期(默认近 30 天) */
|
||||
const applicationStartDate = ref(getDefaultReportStartDate());
|
||||
const applicationEndDate = ref(getDefaultReportEndDate());
|
||||
const applicationStatus = ref<ApplicationStatusFilter>('all');
|
||||
const applicationUsage = ref<ApplicationUsageFilter>('all');
|
||||
const applicationQuery = ref('');
|
||||
@@ -159,7 +177,8 @@ export function useReportsAdmin() {
|
||||
usageReport.value = await getAdminUsageReport({
|
||||
user_page: usageUserPage.value,
|
||||
user_page_size: usageUserPageSize.value,
|
||||
range: usageRange.value,
|
||||
start_date: usageStartDate.value,
|
||||
end_date: usageEndDate.value,
|
||||
});
|
||||
const pages = usageReport.value?.user_pages ?? 1;
|
||||
if (usageUserPage.value > pages) {
|
||||
@@ -176,7 +195,10 @@ export function useReportsAdmin() {
|
||||
*/
|
||||
const loadOpsOverview = async (): Promise<void> => {
|
||||
try {
|
||||
opsOverview.value = await getAdminOpsOverview({ range: opsOverviewRange.value });
|
||||
opsOverview.value = await getAdminOpsOverview({
|
||||
start_date: opsOverviewStartDate.value,
|
||||
end_date: opsOverviewEndDate.value,
|
||||
});
|
||||
} catch (e) {
|
||||
console.error('Error loading ops overview:', e);
|
||||
opsOverview.value = null;
|
||||
@@ -202,7 +224,8 @@ export function useReportsAdmin() {
|
||||
const loadApplicationReport = async (): Promise<void> => {
|
||||
try {
|
||||
applicationReport.value = await getAdminApplicationReport({
|
||||
range: applicationRange.value,
|
||||
start_date: applicationStartDate.value,
|
||||
end_date: applicationEndDate.value,
|
||||
status: applicationStatus.value,
|
||||
usage: applicationUsage.value,
|
||||
q: applicationQuery.value,
|
||||
@@ -390,16 +413,18 @@ export function useReportsAdmin() {
|
||||
}
|
||||
};
|
||||
|
||||
/** 重置聊天日志风险/定位筛选并重新加载(清除关联跳转残留的 id/agent_id 等) */
|
||||
/** 重置聊天日志风险/定位筛选并重新加载(清除关联跳转残留的 id/agent_id 等);统计范围恢复默认近 30 天 */
|
||||
const resetChatLogFilters = (): void => {
|
||||
const keys = [
|
||||
'created_from', 'created_to', 'agent_name', 'agent_id', 'username', 'user_id',
|
||||
'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] = '';
|
||||
}
|
||||
columnFilters.value.created_from = getDefaultReportStartDate();
|
||||
columnFilters.value.created_to = getDefaultReportEndDate();
|
||||
handleFilterChange();
|
||||
};
|
||||
|
||||
@@ -466,10 +491,15 @@ export function useReportsAdmin() {
|
||||
}
|
||||
};
|
||||
|
||||
/** 进入聊天日志页时给统一时间范围一个默认值,保证筛选生效 */
|
||||
/** 进入聊天日志页时给统计范围一个默认区间(近 30 天),保证筛选生效 */
|
||||
const ensureChatLogsRange = (): void => {
|
||||
if (isChatLogsTable.value && !columnFilters.value.range) {
|
||||
columnFilters.value.range = '30d';
|
||||
if (isChatLogsTable.value) {
|
||||
if (!columnFilters.value.created_from) {
|
||||
columnFilters.value.created_from = getDefaultReportStartDate();
|
||||
}
|
||||
if (!columnFilters.value.created_to) {
|
||||
columnFilters.value.created_to = getDefaultReportEndDate();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
@@ -692,8 +722,6 @@ 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[]>([]);
|
||||
|
||||
@@ -1653,13 +1681,16 @@ watch(usageUserPageSize, () => {
|
||||
void loadUsageReport();
|
||||
});
|
||||
|
||||
watch(usageRange, () => {
|
||||
watch([usageStartDate, usageEndDate], ([start, end]) => {
|
||||
// 开始日期晚于结束日期时为非法区间,等待用户修正后再刷新
|
||||
if (start && end && start > end) return;
|
||||
usageUserPage.value = 1;
|
||||
usageAgentPage.value = 1;
|
||||
void loadUsageReport();
|
||||
});
|
||||
|
||||
watch(opsOverviewRange, () => {
|
||||
watch([opsOverviewStartDate, opsOverviewEndDate], ([start, end]) => {
|
||||
if (start && end && start > end) return;
|
||||
if (isOpsOverviewTable.value) {
|
||||
void loadOpsOverview();
|
||||
}
|
||||
@@ -1675,7 +1706,8 @@ watch(usageAgentTotalPages, (pages) => {
|
||||
}
|
||||
});
|
||||
|
||||
watch([applicationRange, applicationStatus, applicationUsage, applicationPageSize], () => {
|
||||
watch([applicationStartDate, applicationEndDate, applicationStatus, applicationUsage, applicationPageSize], ([start, end]) => {
|
||||
if (start && end && start > end) return;
|
||||
applicationPage.value = 1;
|
||||
if (isApplicationOpsTable.value) {
|
||||
void loadApplicationReport();
|
||||
@@ -1752,8 +1784,8 @@ watch([reportPageSize, issueQuestionTotal], () => {
|
||||
|
||||
return {
|
||||
usageReport,
|
||||
usageRange,
|
||||
usageRangeOptions,
|
||||
usageStartDate,
|
||||
usageEndDate,
|
||||
usageUserPage,
|
||||
usageUserPageSize,
|
||||
usageUserPageSizeOptions,
|
||||
@@ -1784,10 +1816,12 @@ watch([reportPageSize, issueQuestionTotal], () => {
|
||||
prevUsageUserPage,
|
||||
nextUsageUserPage,
|
||||
opsOverview,
|
||||
opsOverviewRange,
|
||||
opsOverviewStartDate,
|
||||
opsOverviewEndDate,
|
||||
issueAnalysis,
|
||||
applicationReport,
|
||||
applicationRange,
|
||||
applicationStartDate,
|
||||
applicationEndDate,
|
||||
applicationStatus,
|
||||
applicationUsage,
|
||||
applicationQuery,
|
||||
@@ -1858,7 +1892,6 @@ watch([reportPageSize, issueQuestionTotal], () => {
|
||||
chatLogTops,
|
||||
chatLogTopsQuestionsMax,
|
||||
chatLogTopsAnswersMax,
|
||||
chatLogRangeOptions,
|
||||
chatLogAgents,
|
||||
getChatLogRiskStatusLabel,
|
||||
getChatLogRiskReasonLabel,
|
||||
|
||||
Reference in new issue
Block a user