feat(analytics): 前端板块骨架——echarts按需/useChart/路由/侧栏组/API模块
Co-Authored-By: Claude Code <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,68 @@
|
||||
// 数据分析板块 API(2026-09-04)。client.ts 的 http 已带 Bearer + baseURL=/api,
|
||||
// getJson/requestJson 负责解包与泛型。Page/Channel 沿用 types.ts 现成定义。
|
||||
import { getJson, requestJson } from './client'
|
||||
import type { Channel, Page } from './types'
|
||||
|
||||
export type { Channel }
|
||||
export type Scope = 'today' | 'week' | 'month'
|
||||
|
||||
export interface OverviewCards {
|
||||
msg_total: number
|
||||
active_customers: number
|
||||
active_staff: number
|
||||
unmapped_accounts: number
|
||||
call_cnt: number
|
||||
first_contact: number
|
||||
prev_msg_total?: number
|
||||
msg_total_delta?: number | null
|
||||
}
|
||||
export interface TrendPoint { day: number; msg: number; active_customers: number; call_cnt: number }
|
||||
export interface AnomalyStaff { user_id: string; yesterday: number; prev7_mean: number; new?: boolean }
|
||||
export interface Anomaly { total_delta_pct: number; yesterday_total: number; prev7_mean: number; staff: AnomalyStaff[] }
|
||||
export interface OverviewResp {
|
||||
scope: Scope
|
||||
channel: Channel
|
||||
days: number[]
|
||||
cards: OverviewCards
|
||||
trend: TrendPoint[]
|
||||
anomaly: Anomaly | null
|
||||
}
|
||||
export interface HealthResp { data_as_of: number | null; entities: { table: string; last_seen: string | null }[] }
|
||||
export interface ChurnRow {
|
||||
friend_id: string; channel: string; nickname: string; owner_account_id: string | null
|
||||
user_id: string | null; last_chat_time: number | null; hist_msgs: number; active_days: number
|
||||
}
|
||||
export interface UnrepliedRow {
|
||||
peer_id: string; channel: string; owner_account_id: string; last_ts: number
|
||||
wait_ms: number; preview: string; msg_id: string
|
||||
}
|
||||
export interface SensitiveWordRow {
|
||||
id: number; word: string; category: string | null; enabled: boolean
|
||||
min_len: number; exclude_words: string[]
|
||||
}
|
||||
export interface SensitiveHitRow {
|
||||
id: number; word_id: number; word: string; category: string | null; msg_id: string
|
||||
channel: string; owner_account_id: string | null; talker_id: string | null
|
||||
room_id: string | null; ts: number | null; snippet: string | null; disposition: string
|
||||
}
|
||||
|
||||
export const getOverview = (channel: Channel, scope: Scope) =>
|
||||
getJson<OverviewResp>('/analytics/overview', { channel, scope })
|
||||
export const getAnalyticsHealth = () => getJson<HealthResp>('/analytics/health')
|
||||
export const getChurn = (params: Record<string, unknown>) =>
|
||||
getJson<Page<ChurnRow>>('/analytics/churn', params)
|
||||
export const getUnreplied = (params: Record<string, unknown>) =>
|
||||
getJson<Page<UnrepliedRow>>('/analytics/unreplied', params)
|
||||
export const getWords = () => getJson<SensitiveWordRow[]>('/analytics/sensitive/words')
|
||||
export const previewWord = (data: { word: string; exclude_words?: string[] }) =>
|
||||
requestJson<{ count: number; warn: boolean }>('post', '/analytics/sensitive/words/preview', data)
|
||||
export const createWord = (data: { word: string; category?: string; exclude_words?: string[] }) =>
|
||||
requestJson<{ id: number; word: string; enabled: boolean }>('post', '/analytics/sensitive/words', data)
|
||||
export const patchWord = (id: number, data: Record<string, unknown>) =>
|
||||
requestJson<Record<string, unknown>>('patch', `/analytics/sensitive/words/${id}`, data)
|
||||
export const deleteWord = (id: number) =>
|
||||
requestJson<{ ok: boolean }>('delete', `/analytics/sensitive/words/${id}`)
|
||||
export const getHits = (params: Record<string, unknown>) =>
|
||||
getJson<Page<SensitiveHitRow>>('/analytics/sensitive/hits', params)
|
||||
export const disposeHits = (ids: number[], disposition: string) =>
|
||||
requestJson<{ updated: number }>('patch', '/analytics/sensitive/hits', { ids, disposition })
|
||||
Reference in New Issue
Block a user