style: 日期查询展示时间范围
This commit is contained in:
1 parent
4445ff68d4
commit
cc41f8fe25
9 files changed
+215
-116
No files matched your search
@@ -19,7 +19,7 @@ def _query_params() -> dict[str, str]:
|
||||
@admin_bp.route('/reports/usage', methods=['GET'])
|
||||
@require_admin
|
||||
def usage_report():
|
||||
"""聊天使用分析报表(支持时间范围 range=7d|30d|90d|180d|365d)。"""
|
||||
"""聊天使用分析报表(统计范围:start_date/end_date 自定义日期优先,否则 range=7d|30d|90d|180d|365d)。"""
|
||||
try:
|
||||
user_page = int(request.args.get('user_page', 1))
|
||||
except (TypeError, ValueError):
|
||||
@@ -34,6 +34,8 @@ def usage_report():
|
||||
user_page=user_page,
|
||||
user_page_size=user_page_size,
|
||||
range_key=range_key,
|
||||
start_date=request.args.get('start_date'),
|
||||
end_date=request.args.get('end_date'),
|
||||
)
|
||||
)
|
||||
|
||||
@@ -43,7 +45,7 @@ def usage_report():
|
||||
def applications_report():
|
||||
"""
|
||||
应用运营报表:按应用聚合使用 / 权限 / 评分。
|
||||
Query: range, status, usage, q, sort, order, page, page_size。
|
||||
Query: start_date, end_date(自定义日期优先), range, status, usage, q, sort, order, page, page_size。
|
||||
"""
|
||||
try:
|
||||
page = int(request.args.get('page', 1))
|
||||
@@ -56,6 +58,8 @@ def applications_report():
|
||||
return jsonify(
|
||||
report_service.build_application_report(
|
||||
range_key=request.args.get('range'),
|
||||
start_date=request.args.get('start_date'),
|
||||
end_date=request.args.get('end_date'),
|
||||
status=request.args.get('status'),
|
||||
usage=request.args.get('usage'),
|
||||
q=request.args.get('q'),
|
||||
@@ -71,11 +75,15 @@ def applications_report():
|
||||
@require_admin
|
||||
def ops_overview_report():
|
||||
"""
|
||||
运营总览报表:对话量 / 活跃用户 / 活跃应用 / 好评率 / 趋势环比 / Top 与低使用应用 / 低评分回答 / 未处理反馈。
|
||||
Query: range(7d/30d/90d/180d/365d)。
|
||||
运营总览报表:对话量 / 活跃用户 / 活跃应用 / 趋势环比 / Top 与低使用应用 / 未处理反馈。
|
||||
Query: start_date, end_date(自定义日期优先),否则 range(7d/30d/90d/180d/365d)。
|
||||
"""
|
||||
return jsonify(
|
||||
report_service.build_ops_overview_report(range_key=request.args.get('range'))
|
||||
report_service.build_ops_overview_report(
|
||||
range_key=request.args.get('range'),
|
||||
start_date=request.args.get('start_date'),
|
||||
end_date=request.args.get('end_date'),
|
||||
)
|
||||
)
|
||||
|
||||
|
||||
|
||||
@@ -98,6 +98,38 @@ def resolve_usage_range_start(range_key: str | None) -> tuple[str, datetime]:
|
||||
return key, since
|
||||
|
||||
|
||||
def resolve_usage_period(
|
||||
range_key: str | None,
|
||||
start_date: str | None = None,
|
||||
end_date: str | None = None,
|
||||
) -> tuple[str, datetime, datetime | None]:
|
||||
"""
|
||||
解析报表统计范围:优先使用自定义起止日期(start_date/end_date,YYYY-MM-DD),否则回退 range key。
|
||||
|
||||
用途:运营总览 / 使用分析 / 应用运营统一由「年月日选择」驱动统计范围。
|
||||
|
||||
Args:
|
||||
range_key: 预设范围 key(7d/30d/90d/...),仅当未提供自定义日期时生效。
|
||||
start_date: 开始日期 YYYY-MM-DD(当天 00:00 起)。
|
||||
end_date: 结束日期 YYYY-MM-DD(当天 23:59:59 止)。
|
||||
|
||||
Returns:
|
||||
(normalized_key, since, until);until 为 None 表示不设上界(自定义日期下始终有值)。
|
||||
"""
|
||||
start_dt = _parse_datetime((start_date or '').strip(), end_of_day=False)
|
||||
end_dt = _parse_datetime((end_date or '').strip(), end_of_day=True)
|
||||
if start_dt is None and end_dt is None:
|
||||
key, since = resolve_usage_range_start(range_key)
|
||||
return key, since, None
|
||||
if start_dt is None:
|
||||
# 只给了结束日期:默认向前回溯一月
|
||||
start_dt = end_dt - timedelta(days=30)
|
||||
if end_dt is None:
|
||||
# 只给了开始日期:默认统计至今
|
||||
end_dt = datetime.utcnow()
|
||||
return 'custom', start_dt, end_dt
|
||||
|
||||
|
||||
def normalize_report_day(day: Any) -> str:
|
||||
"""
|
||||
将报表按日聚合的日期统一为 yyyy-mm-dd,避免未补零或带时间后缀导致前端横轴乱序。
|
||||
@@ -130,7 +162,14 @@ def normalize_report_day(day: Any) -> str:
|
||||
|
||||
|
||||
|
||||
def build_usage_report(*, user_page: int, user_page_size: int, range_key: str | None = None) -> dict:
|
||||
def build_usage_report(
|
||||
*,
|
||||
user_page: int,
|
||||
user_page_size: int,
|
||||
range_key: str | None = None,
|
||||
start_date: str | None = None,
|
||||
end_date: str | None = None,
|
||||
) -> dict:
|
||||
"""
|
||||
聊天使用分析报表(按应用 / 按用户),限定时间范围内的 ChatLog。
|
||||
|
||||
@@ -140,13 +179,17 @@ def build_usage_report(*, user_page: int, user_page_size: int, range_key: str |
|
||||
Args:
|
||||
user_page: 按用户统计分页页码。
|
||||
user_page_size: 每页条数(上限 USAGE_BY_USER_TOP_LIMIT)。
|
||||
range_key: 时间范围 key,见 USAGE_RANGE_DAYS。
|
||||
range_key: 时间范围 key,见 USAGE_RANGE_DAYS(与 start_date/end_date 互斥,自定义日期优先)。
|
||||
start_date: 自定义开始日期 YYYY-MM-DD。
|
||||
end_date: 自定义结束日期 YYYY-MM-DD。
|
||||
|
||||
Returns:
|
||||
含 total / by_user / by_agent / by_day / low_agents 及用户分页字段的字典。
|
||||
"""
|
||||
normalized_range, since = resolve_usage_range_start(range_key)
|
||||
normalized_range, since, until = resolve_usage_period(range_key, start_date, end_date)
|
||||
base_filter = ChatLog.created_at >= since
|
||||
if until is not None:
|
||||
base_filter = base_filter & (ChatLog.created_at <= until)
|
||||
|
||||
total = db.session.query(ChatLog).filter(base_filter).count()
|
||||
by_agent = (
|
||||
@@ -271,6 +314,8 @@ def build_feedback_report() -> dict:
|
||||
def build_application_report(
|
||||
*,
|
||||
range_key: str | None = None,
|
||||
start_date: str | None = None,
|
||||
end_date: str | None = None,
|
||||
status: str | None = None,
|
||||
usage: str | None = None,
|
||||
q: str | None = None,
|
||||
@@ -286,7 +331,9 @@ def build_application_report(
|
||||
Feedback JOIN ChatLog 统计均分;不含 API Key 等配置敏感字段。
|
||||
|
||||
Args:
|
||||
range_key: 时间范围 key(7d/30d/90d/180d/365d),非法值回退近一月。
|
||||
range_key: 时间范围 key(7d/30d/90d/180d/365d),非法值回退近一月(自定义日期优先)。
|
||||
start_date: 自定义开始日期 YYYY-MM-DD。
|
||||
end_date: 自定义结束日期 YYYY-MM-DD。
|
||||
status: all | active | inactive,按 is_active 过滤。
|
||||
usage: all | used | unused,按时间范围内是否有对话过滤。
|
||||
q: 应用名称模糊搜索。
|
||||
@@ -298,7 +345,10 @@ def build_application_report(
|
||||
Returns:
|
||||
含 summary / items / 分页字段的字典。
|
||||
"""
|
||||
normalized_range, since = resolve_usage_range_start(range_key)
|
||||
normalized_range, since, until = resolve_usage_period(range_key, start_date, end_date)
|
||||
period_filter = ChatLog.created_at >= since
|
||||
if until is not None:
|
||||
period_filter = period_filter & (ChatLog.created_at <= until)
|
||||
status_key = (status or 'all').strip().lower()
|
||||
if status_key not in {'all', 'active', 'inactive'}:
|
||||
status_key = 'all'
|
||||
@@ -325,7 +375,7 @@ def build_application_report(
|
||||
func.coalesce(func.sum(ChatLog.tokens_used), 0).label('tokens_used'),
|
||||
func.avg(ChatLog.latency).label('avg_latency_ms'),
|
||||
)
|
||||
.filter(ChatLog.created_at >= since)
|
||||
.filter(period_filter)
|
||||
.group_by(ChatLog.agent_id)
|
||||
.subquery()
|
||||
)
|
||||
@@ -344,7 +394,7 @@ def build_application_report(
|
||||
func.count(Feedback.id).label('feedback_count'),
|
||||
)
|
||||
.join(Feedback, Feedback.chat_log_id == ChatLog.id)
|
||||
.filter(ChatLog.created_at >= since)
|
||||
.filter(period_filter)
|
||||
.group_by(ChatLog.agent_id)
|
||||
.subquery()
|
||||
)
|
||||
@@ -1216,7 +1266,11 @@ def build_issue_analysis_report(query_params: dict[str, str], top_n: int = 10) -
|
||||
}
|
||||
|
||||
|
||||
def build_ops_overview_report(range_key: str | None = None) -> dict:
|
||||
def build_ops_overview_report(
|
||||
range_key: str | None = None,
|
||||
start_date: str | None = None,
|
||||
end_date: str | None = None,
|
||||
) -> dict:
|
||||
"""
|
||||
运营总览报表:聚合对话量 / 活跃用户 / 活跃应用 / 好评率 / 趋势环比 / Top 与低使用应用 / 低评分回答 / 未处理反馈。
|
||||
|
||||
@@ -1230,14 +1284,19 @@ def build_ops_overview_report(range_key: str | None = None) -> dict:
|
||||
- 环比 = 当前范围对话量 vs 上等长周期对话量。
|
||||
|
||||
Args:
|
||||
range_key: 时间范围 key(7d/30d/90d/180d/365d),非法值回退近一月。
|
||||
range_key: 时间范围 key(7d/30d/90d/180d/365d),非法值回退近一月(自定义日期优先)。
|
||||
start_date: 自定义开始日期 YYYY-MM-DD。
|
||||
end_date: 自定义结束日期 YYYY-MM-DD。
|
||||
|
||||
Returns:
|
||||
含 kpi / trend / top_apps / low_use_apps 的字典。
|
||||
"""
|
||||
normalized_range, since = resolve_usage_range_start(range_key)
|
||||
days = max(1, (datetime.utcnow() - since).days)
|
||||
normalized_range, since, until = resolve_usage_period(range_key, start_date, end_date)
|
||||
base_filter = ChatLog.created_at >= since
|
||||
if until is not None:
|
||||
base_filter = base_filter & (ChatLog.created_at <= until)
|
||||
period_end = until or datetime.utcnow()
|
||||
days = max(1, (period_end - since).days + 1)
|
||||
prev_since = since - timedelta(days=days)
|
||||
|
||||
total_chats = db.session.query(ChatLog).filter(base_filter).count()
|
||||
|
||||
@@ -260,15 +260,21 @@ export const getAdminDashboardSummary = () =>
|
||||
export interface AdminUsageReportParams {
|
||||
user_page?: number;
|
||||
user_page_size?: number;
|
||||
/** 时间范围:7d | 30d | 90d | 180d | 365d */
|
||||
/** 时间范围:7d | 30d | 90d | 180d | 365d(与 start_date/end_date 互斥,自定义日期优先) */
|
||||
range?: UsageRangeKey;
|
||||
/** 自定义开始日期 YYYY-MM-DD */
|
||||
start_date?: string;
|
||||
/** 自定义结束日期 YYYY-MM-DD */
|
||||
end_date?: string;
|
||||
}
|
||||
|
||||
export const getAdminUsageReport = (params: AdminUsageReportParams = {}) => {
|
||||
const qs = new URLSearchParams();
|
||||
if (params.user_page != null) qs.set('user_page', String(params.user_page));
|
||||
if (params.user_page_size != null) qs.set('user_page_size', String(params.user_page_size));
|
||||
if (params.range) qs.set('range', params.range);
|
||||
if (params.start_date) qs.set('start_date', params.start_date);
|
||||
if (params.end_date) qs.set('end_date', params.end_date);
|
||||
if (!params.start_date && !params.end_date && params.range) qs.set('range', params.range);
|
||||
const query = qs.toString();
|
||||
return requestJson<UsageReport>(
|
||||
`/api/admin/reports/usage${query ? `?${query}` : ''}`,
|
||||
@@ -278,6 +284,10 @@ export const getAdminUsageReport = (params: AdminUsageReportParams = {}) => {
|
||||
|
||||
export interface AdminApplicationReportParams {
|
||||
range?: UsageRangeKey;
|
||||
/** 自定义开始日期 YYYY-MM-DD(优先于 range) */
|
||||
start_date?: string;
|
||||
/** 自定义结束日期 YYYY-MM-DD(优先于 range) */
|
||||
end_date?: string;
|
||||
status?: ApplicationStatusFilter;
|
||||
usage?: ApplicationUsageFilter;
|
||||
q?: string;
|
||||
@@ -293,7 +303,9 @@ export interface AdminApplicationReportParams {
|
||||
*/
|
||||
export const getAdminApplicationReport = (params: AdminApplicationReportParams = {}) => {
|
||||
const qs = new URLSearchParams();
|
||||
if (params.range) qs.set('range', params.range);
|
||||
if (params.start_date) qs.set('start_date', params.start_date);
|
||||
if (params.end_date) qs.set('end_date', params.end_date);
|
||||
if (!params.start_date && !params.end_date && params.range) qs.set('range', params.range);
|
||||
if (params.status && params.status !== 'all') qs.set('status', params.status);
|
||||
if (params.usage && params.usage !== 'all') qs.set('usage', params.usage);
|
||||
if (params.q?.trim()) qs.set('q', params.q.trim());
|
||||
@@ -311,12 +323,14 @@ export const getAdminApplicationReport = (params: AdminApplicationReportParams =
|
||||
export const getAdminFeedbackReport = () => requestJson<any>('/api/admin/reports/feedback', auth());
|
||||
|
||||
/**
|
||||
* 拉取运营总览报表:对话量 / 活跃用户 / 活跃应用 / 好评率 / 趋势环比 / Top 与低使用应用 / 低评分回答 / 未处理反馈。
|
||||
* @param params - 时间范围(近 7/30/90 天)
|
||||
* 拉取运营总览报表:对话量 / 活跃用户 / 活跃应用 / 趋势环比 / Top 与低使用应用 / 未处理反馈。
|
||||
* @param params - 统计范围:自定义起止日期(优先)或预设 range key
|
||||
*/
|
||||
export const getAdminOpsOverview = (params: { range?: UsageRangeKey } = {}) => {
|
||||
export const getAdminOpsOverview = (params: { range?: UsageRangeKey; start_date?: string; end_date?: string } = {}) => {
|
||||
const qs = new URLSearchParams();
|
||||
if (params.range) qs.set('range', params.range);
|
||||
if (params.start_date) qs.set('start_date', params.start_date);
|
||||
if (params.end_date) qs.set('end_date', params.end_date);
|
||||
if (!params.start_date && !params.end_date && params.range) qs.set('range', params.range);
|
||||
const query = qs.toString();
|
||||
return requestJson<OpsOverviewReport>(
|
||||
`/api/admin/reports/overview${query ? `?${query}` : ''}`,
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -892,14 +892,8 @@
|
||||
"noData": "No data available for {table}",
|
||||
"noFilterResults": "No matching rows. Adjust your filters.",
|
||||
"usage": "Usage Analytics",
|
||||
"usageRangeLabel": "Time range",
|
||||
"usageRanges": {
|
||||
"7d": "Last 7 days",
|
||||
"30d": "Last 30 days",
|
||||
"90d": "Last 90 days",
|
||||
"180d": "Last 6 months",
|
||||
"365d": "Last 12 months"
|
||||
},
|
||||
"dateFrom": "Start date",
|
||||
"dateTo": "End date",
|
||||
"byUser": "Requests by User",
|
||||
"byAgent": "Requests by Agent",
|
||||
"byDepartment": "Requests by Department",
|
||||
|
||||
@@ -894,14 +894,8 @@
|
||||
"noData": "ไม่มีข้อมูลสำหรับ {table}",
|
||||
"noFilterResults": "ไม่พบข้อมูลที่ตรงกับเงื่อนไข โปรดปรับตัวกรอง",
|
||||
"usage": "วิเคราะห์การใช้งาน",
|
||||
"usageRangeLabel": "ช่วงเวลา",
|
||||
"usageRanges": {
|
||||
"7d": "7 วันล่าสุด",
|
||||
"30d": "30 วันล่าสุด",
|
||||
"90d": "90 วันล่าสุด",
|
||||
"180d": "6 เดือนล่าสุด",
|
||||
"365d": "12 เดือนล่าสุด"
|
||||
},
|
||||
"dateFrom": "วันเริ่มต้น",
|
||||
"dateTo": "วันสิ้นสุด",
|
||||
"byUser": "ตามผู้ใช้",
|
||||
"byAgent": "ตามตัวแทน",
|
||||
"byDepartment": "ตามแผนก",
|
||||
|
||||
@@ -892,14 +892,8 @@
|
||||
"noData": "暂无数据: {table}",
|
||||
"noFilterResults": "没有匹配的数据,请调整筛选条件",
|
||||
"usage": "使用分析",
|
||||
"usageRangeLabel": "统计范围",
|
||||
"usageRanges": {
|
||||
"7d": "近 7 天",
|
||||
"30d": "近 30 天",
|
||||
"90d": "近 90 天",
|
||||
"180d": "近半年",
|
||||
"365d": "近一年"
|
||||
},
|
||||
"dateFrom": "开始日期",
|
||||
"dateTo": "结束日期",
|
||||
"byUser": "按用户统计",
|
||||
"byAgent": "按应用统计",
|
||||
"byDepartment": "按部门统计",
|
||||
|
||||
@@ -894,14 +894,8 @@
|
||||
"noData": "暫無數據: {table}",
|
||||
"noFilterResults": "沒有匹配的數據,請調整篩選條件",
|
||||
"usage": "使用分析",
|
||||
"usageRangeLabel": "統計範圍",
|
||||
"usageRanges": {
|
||||
"7d": "近 7 天",
|
||||
"30d": "近 30 天",
|
||||
"90d": "近 90 天",
|
||||
"180d": "近半年",
|
||||
"365d": "近一年"
|
||||
},
|
||||
"dateFrom": "開始日期",
|
||||
"dateTo": "結束日期",
|
||||
"byUser": "按用戶統計",
|
||||
"byAgent": "按應用統計",
|
||||
"byDepartment": "按部門統計",
|
||||
|
||||
Reference in new issue
Block a user