优化快捷回复联想与个人调用统计,数据统计支持自定义日期
/ 按输入码与个人频次建议(最多10条,唯一自动填入),正文关键字联想;统计页可日历选区间并统一中文日历。
This commit is contained in:
+51
-11
@@ -212,6 +212,26 @@ export interface StatisticsKpis {
|
||||
total_messages: number
|
||||
}
|
||||
|
||||
export type StatsQuery = {
|
||||
/** today | week | month */
|
||||
period?: string
|
||||
/** YYYY-MM-DD,与 to 同时传则优先自定义区间 */
|
||||
from?: string
|
||||
to?: string
|
||||
}
|
||||
|
||||
function statsQueryString(params?: StatsQuery) {
|
||||
const search = new URLSearchParams()
|
||||
if (params?.from && params?.to) {
|
||||
search.set('from', params.from)
|
||||
search.set('to', params.to)
|
||||
} else if (params?.period) {
|
||||
search.set('period', params.period)
|
||||
}
|
||||
const qs = search.toString()
|
||||
return qs ? `?${qs}` : ''
|
||||
}
|
||||
|
||||
// Auth
|
||||
export const login = (params: LoginParams) => post<LoginResult>('/login', params)
|
||||
|
||||
@@ -359,8 +379,8 @@ export const exportSessionsCSV = (params?: {
|
||||
return downloadFile(`/sessions/export${qs ? `?${qs}` : ''}`, `sessions_${Date.now()}.csv`)
|
||||
}
|
||||
|
||||
export const exportStatisticsCSV = () =>
|
||||
downloadFile('/statistics/export', `statistics_${Date.now()}.csv`)
|
||||
export const exportStatisticsCSV = (params?: StatsQuery) =>
|
||||
downloadFile(`/statistics/export${statsQueryString(params)}`, `statistics_${Date.now()}.csv`)
|
||||
|
||||
export const getCustomer = (id: number) =>
|
||||
get<{ customer: Customer; sessions: Session[]; contacts?: CustomerContact[] }>(`/customers/${id}`)
|
||||
@@ -465,6 +485,8 @@ export interface QuickReply {
|
||||
status: 'draft' | 'published' | string
|
||||
sort_order: number
|
||||
usage_count: number
|
||||
/** 当前坐席个人调用次数(建议排序用) */
|
||||
my_usage_count?: number
|
||||
created_at: string
|
||||
updated_at: string
|
||||
}
|
||||
@@ -486,11 +508,17 @@ export const getQuickReplies = (params?: {
|
||||
return getList<QuickReply>(`/quick-replies${qs ? `?${qs}` : ''}`)
|
||||
}
|
||||
|
||||
export const suggestQuickReplies = (prefix = '') => {
|
||||
/** slash=输入码前缀;keyword=标题/内容关键字。均按个人调用频次排序,最多 10 条 */
|
||||
export const suggestQuickReplies = (opts?: {
|
||||
mode?: 'slash' | 'keyword'
|
||||
prefix?: string
|
||||
q?: string
|
||||
}) => {
|
||||
const search = new URLSearchParams()
|
||||
if (prefix) search.set('prefix', prefix)
|
||||
const qs = search.toString()
|
||||
return get<QuickReply[]>(`/quick-replies/suggest${qs ? `?${qs}` : ''}`)
|
||||
search.set('mode', opts?.mode || 'slash')
|
||||
if (opts?.prefix) search.set('prefix', opts.prefix)
|
||||
if (opts?.q) search.set('q', opts.q)
|
||||
return get<QuickReply[]>(`/quick-replies/suggest?${search.toString()}`)
|
||||
}
|
||||
|
||||
export const createQuickReply = (data: {
|
||||
@@ -597,11 +625,23 @@ export const updateTenantSettings = (
|
||||
) => put<TenantSettings>('/settings', data)
|
||||
|
||||
// Statistics
|
||||
export const getKPIs = () => get<StatisticsKpis>('/statistics/kpi')
|
||||
export const getSessionTrend = (period: 'today' | 'day' | 'month' = 'day') => get<{ date: string; count: number }[]>(`/statistics/trend?period=${period}`)
|
||||
export const getResponseDistribution = () => get<{ range: string; count: number }[]>('/statistics/response-distribution')
|
||||
export const getChannelDistribution = () => get<{ type: string; value: number }[]>('/statistics/channels')
|
||||
export const getAgentPerformance = () => get<{ name: string; conversations: number; avg_response: number; satisfaction: number }[]>('/statistics/performance')
|
||||
export const getKPIs = (params?: StatsQuery) =>
|
||||
get<StatisticsKpis>(`/statistics/kpi${statsQueryString(params)}`)
|
||||
export const getSessionTrend = (params?: StatsQuery | 'today' | 'day' | 'month') => {
|
||||
// 兼容旧调用 getSessionTrend('day')
|
||||
if (typeof params === 'string') {
|
||||
return get<{ date: string; count: number }[]>(`/statistics/trend?period=${params}`)
|
||||
}
|
||||
return get<{ date: string; count: number }[]>(`/statistics/trend${statsQueryString(params)}`)
|
||||
}
|
||||
export const getResponseDistribution = (params?: StatsQuery) =>
|
||||
get<{ range: string; count: number }[]>(`/statistics/response-distribution${statsQueryString(params)}`)
|
||||
export const getChannelDistribution = (params?: StatsQuery) =>
|
||||
get<{ type: string; value: number }[]>(`/statistics/channels${statsQueryString(params)}`)
|
||||
export const getAgentPerformance = (params?: StatsQuery) =>
|
||||
get<{ name: string; conversations: number; avg_response: number; satisfaction: number }[]>(
|
||||
`/statistics/performance${statsQueryString(params)}`,
|
||||
)
|
||||
|
||||
// Admin
|
||||
export const getTenants = (params?: { search?: string; status?: string; page?: number; pageSize?: number }) => {
|
||||
|
||||
Reference in New Issue
Block a user