diff --git a/web/src/QADashboard.test.tsx b/web/src/QADashboard.test.tsx
new file mode 100644
index 0000000..c7d5634
--- /dev/null
+++ b/web/src/QADashboard.test.tsx
@@ -0,0 +1,42 @@
+import { renderToStaticMarkup } from 'react-dom/server'
+import { describe, it, expect, vi } from 'vitest'
+import { qaDailySeries, qaCategorySeries } from './qaDashboard'
+import { QADashboardView } from './QADashboard'
+import type { QARecord, QAQuery } from './qaOps'
+const query: QAQuery = { start: '2026-10-11T16:00:00Z', end: '2026-10-13T16:00:00Z', keyword: '', cursor: '' }
+const records = [
+ { id: 'a', asked_at: '2026-10-11T16:30:00Z', product_category: '

', problem_type: '通信' },
+ { id: 'b', asked_at: '2026-10-12T16:01:00Z' },
+] as QARecord[]
+describe('question dashboard projections', () => {
+ it('groups by Beijing day and keeps zero days instead of using the browser timezone', () => {
+ expect(qaDailySeries(records, query)).toEqual([
+ { label: '2026-10-12', count: 1 },
+ { label: '2026-10-13', count: 1 },
+ ])
+ expect(qaDailySeries([], query).map((p) => p.count)).toEqual([0, 0])
+ })
+ it('keeps unclassified records distinct without inventing a category', () => {
+ expect(qaCategorySeries(records, 'problem_type')).toEqual([
+ { label: '通信', count: 1 },
+ { label: '未分类', count: 1 },
+ ])
+ })
+ it('renders the real dashboard panels and escaped category text', () => {
+ const html = renderToStaticMarkup(
+
+ )
+ for (const title of ['问题总量', '每日提问趋势', '质量分布', '区域分布', '产品分类', '问题类型'])
+ expect(html).toContain(title)
+ expect(html).not.toContain('
)
void
+}
+const percent = (r: QualityRate | undefined) => (r?.percent == null ? '—' : `${r.percent.toFixed(1)}%`)
+function Bars({ points }: { points: QACountPoint[] }) {
+ const max = Math.max(1, ...points.map((p) => p.count))
+ return points.length ? (
+
+ {points.map((p) => (
+
+
{p.label}
+
+
+
+
{p.count}
+
+ ))}
+
+ ) : (
+
暂无数据
+ )
+}
+export function QADashboardView(p: QADashboardProps) {
+ const page = p.loading ? null : p.page,
+ items = page?.items || [],
+ q = page && p.quality?.summary.total === page.total ? p.quality : null
+ const b = q?.summary.rates.breakdown
+ const daily = page && p.query ? qaDailySeries(items, p.query) : []
+ const max = Math.max(1, ...daily.map((d) => d.count))
+ const outcomes = b
+ ? [
+ ['已覆盖', b.covered],
+ ['未覆盖', b.uncovered],
+ ['部分覆盖', b.partial],
+ ['待确认', b.pending],
+ ['未评估', b.unassessed],
+ ['不计入', b.excluded],
+ ['待重新核对', b.stale],
+ ].map(([label, count]) => ({ label: String(label), count: Number(count) }))
+ : []
+ return (
+
+ {p.error ? (
+
+ {p.error}{' '}
+
+
+ ) : null}
+ {p.loading ? 正在读取完整统计范围…
: null}
+
+
+ 问题总量
+ {page?.total ?? '—'}
+ 条
+
+
+ 知识覆盖率
+ {percent(q?.summary.rates.coverage)}
+
+ {q ? `${q.summary.rates.coverage.numerator} / ${q.summary.rates.coverage.denominator}` : '分子 / 分母'}
+
+
+
+ 回答正确率
+ {percent(q?.summary.rates.correctness)}
+
+ {q
+ ? `${q.summary.rates.correctness.numerator} / ${q.summary.rates.correctness.denominator}`
+ : '分子 / 分母'}
+
+
+
+ 已人工复核
+ {q?.summary.reviewed ?? '—'}
+ {q ? `待复核 ${q.summary.unreviewed}` : '条'}
+
+
+
+
+ 每日提问趋势
+ {daily.length ? (
+
+ {daily.map((d) => (
+
+
{d.count}
+
+
+
+
{d.label.slice(5)}
+
+ ))}
+
+ ) : (
+ 暂无数据
+ )}
+
+
+
+ 区域分布
+ r.questions > 0)
+ .map((r) => ({ label: usageLabels[r.key] || r.key, count: r.questions })) || []
+ }
+ />
+ {p.usage ? (
+
+
+
+
+ | 区域 |
+ 提问量 |
+ 已关联使用人数 |
+
+
+
+ {p.usage.rows
+ .filter((r) => r.questions > 0 || r.roster_people !== null)
+ .map((r) => (
+
+ | {usageLabels[r.key] || r.key} |
+ {r.questions} |
+ {r.users ?? '—'} |
+
+ ))}
+
+
+
+ ) : null}
+
+
+
+
+
+ )
+}
+export function QADashboard({
+ page,
+ query,
+ loading,
+ error,
+ revision,
+ onRetry,
+}: {
+ page: QARecordPage | null
+ query: QAQuery | null
+ loading: boolean
+ error: string | null
+ revision: number
+ onRetry: () => void
+}) {
+ const [quality, setQuality] = useState
(null),
+ [usage, setUsage] = useState(null),
+ [failure, setFailure] = useState(''),
+ [monthly, setMonthly] = useState(false)
+ useEffect(() => {
+ setQuality(null)
+ setUsage(null)
+ setFailure('')
+ if (!query) return
+ const abort = new AbortController()
+ void fetchQADashboardQuality(query, abort.signal)
+ .then((v) => {
+ if (!abort.signal.aborted) setQuality(v)
+ })
+ .catch((e) => {
+ if (!abort.signal.aborted) setFailure(e instanceof Error ? e.message : '质量统计读取失败')
+ })
+ void fetchQAUsage(query, abort.signal)
+ .then((v) => {
+ if (!abort.signal.aborted) setUsage(v)
+ })
+ .catch((e) => {
+ if (!abort.signal.aborted) setFailure(e instanceof Error ? e.message : '区域统计读取失败')
+ })
+ return () => abort.abort()
+ }, [query, revision])
+ const mismatch = !!page && !!quality && page.total !== quality.summary.total
+ return (
+
+
+ setMonthly(e.currentTarget.open)}>
+ 个人月明细
+ {monthly ? : null}
+
+
+ )
+}
diff --git a/web/src/QAMirrorSync.test.tsx b/web/src/QAMirrorSync.test.tsx
index 5bf3cbd..bc7a23b 100644
--- a/web/src/QAMirrorSync.test.tsx
+++ b/web/src/QAMirrorSync.test.tsx
@@ -22,7 +22,7 @@ describe('local Q&A synchronization strip', () => {
expect(html).toContain('本地数据库')
expect(html).toContain('首次同步尚未完成')
expect(html).toContain('立即同步')
- expect(html).toContain('每 5 分钟')
+ expect(html).not.toContain('每 5 分钟后台同步 · 查询不请求远端')
})
it('keeps the last-good dataset visibly stale after a failed sync', () => {
const status = {
@@ -38,7 +38,7 @@ describe('local Q&A synchronization strip', () => {
const html = renderToStaticMarkup()
expect(html).toContain('639')
expect(html).toContain('保留上次成功数据')
- expect(html).toContain('最近成功同步')
+ expect(html).not.toContain('不承诺实时源快照')
})
it('distinguishes authorization blocking from an ordinary network failure', () => {
const html = renderToStaticMarkup(
diff --git a/web/src/QAMirrorSync.tsx b/web/src/QAMirrorSync.tsx
index 4bb8019..ddbc3d0 100644
--- a/web/src/QAMirrorSync.tsx
+++ b/web/src/QAMirrorSync.tsx
@@ -9,7 +9,6 @@ interface ViewProps {
submitting: boolean
onSync: () => void
}
-const stamp = (v: string) => new Date(v).toLocaleString('zh-CN', { hour12: false })
export function QAMirrorSyncView(p: ViewProps) {
const s = p.status
const active = mirrorSyncActive(s)
@@ -17,7 +16,7 @@ export function QAMirrorSyncView(p: ViewProps) {
本地数据库
- 每 5 分钟后台同步 · 查询不请求远端
+
{s?.ready ? 已同步 {s.records} 条 : null}
- {page?.organization ? (
-
- {page.organization.state === 'ready'
- ? `缺失组织信息按当前通讯录补全(${stamp(page.organization.synced_at!)}),不代表提问时归属。目录:${page.organization.directory_id};区域版本:${page.organization.revision_id || '未保存'}`
- : '尚无完整通讯录,仅展示源端已有组织快照,不根据姓名推断。'}
-
- ) : null}
+
{props.status?.warnings.map((warning) => (
{warningLabels[warning] ?? '数据源有待审核的安全告警'}
@@ -138,12 +147,7 @@ export function QAOperationsView(props: ViewProps) {
) : page && !props.loading && !props.error ? (
没有符合条件的问答,请调整时间范围或关键词。
) : null}
- {page ? (
-
- ) : null}
+
{showDrawer ? (
<>
('records')
- const [usageMode, setUsageMode] = useState<'regions' | 'monthly'>('regions')
+ const [view, setView] = useState('records')
const auth = useOptionalAuth()
const canRead = auth?.identity?.role === 'admin'
const [draft, setDraft] = useState(initialDraft)
@@ -331,7 +334,7 @@ export function QAOperations() {
useEffect(() => {
if (!query || !canRead) return
- if (view !== 'records') {
+ if (view !== 'records' && view !== 'dashboard') {
setLoading(false)
detailRequest.current?.abort()
setDetail(null)
@@ -414,13 +417,11 @@ export function QAOperations() {
setDetailLoading(false)
returnFocus.current?.focus()
}
+ const queryView = view === 'records' || view === 'dashboard'
return (
{!canRead ? (
@@ -428,78 +429,48 @@ export function QAOperations() {
) : (
<>
- {
- if (detail || detailLoading) {
- setMirrorChanged(true)
- return
- }
- setQuery((q) => (q ? { ...q } : q))
- setRevision((v) => v + 1)
- setQualityRevision((v) => v + 1)
- }}
- />
- {mirrorChanged ? (
- 本地副本已更新;当前详情和未保存复核不会被覆盖,关闭详情后刷新列表。
- ) : null}
-
- {view === 'usage' ? (
-
- ) : null}
- {view === 'usage' && usageMode === 'monthly' ? (
-
- ) : view === 'regions' ? (
-
- ) : (
+
+ {queryView ? (
<>
+ {
+ if (detail || detailLoading) {
+ setMirrorChanged(true)
+ return
+ }
+ setQuery((q) => (q ? { ...q } : q))
+ setRevision((v) => v + 1)
+ setQualityRevision((v) => v + 1)
+ }}
+ />
+ {mirrorChanged ? 数据已更新,关闭详情后刷新。
: null}
-
- 部门/区域保留源快照,缺失时按当前通讯录补全;使用统计不是绩效结论。外语翻译与AI评估仍暂缓,空值不默认填“否”。
-
- {view === 'records' ? : null}
- {view === 'usage' ? (
-
- ) : (
- {
- if (detail) void select(detail.id)
- }}
- onQualitySaved={(fresh) => {
- if (fresh.id !== detail?.id) return
- setDetail(fresh)
- setPage((old) => {
- if (!old) return old
- const all = new Set(old.columns)
- const f = fresh.quality?.effective
- if (f) {
- if (f.coverage) all.add('coverage')
- if (f.correctness) all.add('is_correct')
- for (const key of ['product_category', 'problem_type', 'root_cause'] as const)
- if (f[key]) all.add(key)
- }
- return {
- ...old,
- items: old.items.map((item) => (item.id === fresh.id ? fresh : item)),
- columns: qaColumns.filter((c) => all.has(c.key)).map((c) => c.key),
- }
- })
- setQualityRevision((v) => v + 1)
- }}
- onSelect={(id) => void select(id)}
- onCloseDetail={close}
- progress={progress}
- onRetry={() => setRevision((value) => value + 1)}
- />
- )}
>
+ ) : null}
+ {view === 'regions' ? (
+
+ ) : view === 'weekly' ? (
+
+ ) : view === 'dashboard' ? (
+ {
+ setRevision((v) => v + 1)
+ setQualityRevision((v) => v + 1)
+ }}
+ />
+ ) : (
+ {
+ if (detail) void select(detail.id)
+ }}
+ onQualitySaved={(fresh) => {
+ if (fresh.id !== detail?.id) return
+ setDetail(fresh)
+ setPage((old) =>
+ old ? { ...old, items: old.items.map((item) => (item.id === fresh.id ? fresh : item)) } : old
+ )
+ setQualityRevision((v) => v + 1)
+ }}
+ onSelect={(id) => void select(id)}
+ onCloseDetail={close}
+ progress={progress}
+ onRetry={() => setRevision((v) => v + 1)}
+ />
)}
>
)}
diff --git a/web/src/QARegions.test.tsx b/web/src/QARegions.test.tsx
index 2923234..2884f31 100644
--- a/web/src/QARegions.test.tsx
+++ b/web/src/QARegions.test.tsx
@@ -87,7 +87,7 @@ describe('region mapping workbench', () => {
const html = renderToStaticMarkup()
expect(html).toContain('历史快照')
expect(html).toContain('跨区域待核对:1')
- expect(html).toContain('配置区域归属不等于纳入绩效考核')
+ expect(html).not.toContain('配置区域归属不等于纳入绩效考核')
expect(html).not.toContain('')
expect(html).not.toContain('达标率')
expect(html).toMatch(/disabled=""[^>]*>保存归属/)
diff --git a/web/src/QARegions.tsx b/web/src/QARegions.tsx
index 07e94c3..1209d4f 100644
--- a/web/src/QARegions.tsx
+++ b/web/src/QARegions.tsx
@@ -85,9 +85,7 @@ export function RegionMappingView(p: Props) {
{p.state.revision_id || '尚未保存'}
) : null}
-
- 父部门包含子部门,子部门单独配置优先。配置区域归属不等于纳入绩效考核;跨区域多部门人员先待核对。
-
+
{p.error ? (
{p.error}
@@ -97,7 +95,7 @@ export function RegionMappingView(p: Props) {
{!p.state ? (
{p.busy ? '正在读取通讯录…' : '尚未读取通讯录'}
) : !available ? (
- 尚无完整通讯录快照。先接入已验证的全量同步结果,不能使用按需人员缓存或编造部门。
+ 暂无通讯录,请先同步。
) : (
<>
@@ -185,9 +183,6 @@ export function RegionMappingView(p: Props) {
{!departments.length ?
没有匹配的部门路径
: null}
-
- 此处仅预览通讯录归属人数;2.0 使用次数、考核名单与绩效统计尚未接入。不会将未知在职状态当作已确认在职人数。
-
>
)}
diff --git a/web/src/QAWeekPicker.test.tsx b/web/src/QAWeekPicker.test.tsx
index 9a99a17..6bcd202 100644
--- a/web/src/QAWeekPicker.test.tsx
+++ b/web/src/QAWeekPicker.test.tsx
@@ -15,8 +15,7 @@ describe('QA week picker', () => {
expect(html).toContain('value="40" selected=""')
expect(html).toContain('第40周(09-28 到 10-04)')
expect(html).toContain('第53周(2026-12-28 到 2027-01-03)')
- expect(html).toContain('北京时间')
- expect(html).toContain('周一至周日')
+ expect(html).not.toContain('北京时间 · 周一至周日 · 本周截至当前')
})
it('preserves custom range mode and does not offer invalid week 53', () => {
const html = renderToStaticMarkup()
diff --git a/web/src/QAWeekPicker.tsx b/web/src/QAWeekPicker.tsx
index 49d3579..f0f4b85 100644
--- a/web/src/QAWeekPicker.tsx
+++ b/web/src/QAWeekPicker.tsx
@@ -50,7 +50,6 @@ export function QAWeekPicker({ year, week, onChange, onCurrentWeek }: Props) {
本周
- 北京时间 · 周一至周日 · 本周截至当前
)
}
diff --git a/web/src/QAWeekly.tsx b/web/src/QAWeekly.tsx
new file mode 100644
index 0000000..770fa40
--- /dev/null
+++ b/web/src/QAWeekly.tsx
@@ -0,0 +1,97 @@
+import { useEffect, useRef, useState } from 'react'
+import type { QAQuery } from './qaOps'
+import { fetchAllQARecords } from './qaOps'
+import { fetchQADashboardQuality } from './qaDashboard'
+import { fetchQAMirrorStatus } from './qaMirror'
+import { buildQAWeeklyDraft, downloadQAWeekly } from './qaWeekly'
+import type { QAWeeklyDraft } from './qaWeekly'
+import { QAAnswerMarkdown } from './QAAnswerMarkdown'
+export function QAWeekly({ query }: { query: QAQuery | null }) {
+ const [draft, setDraft] = useState