列表正文改为按需读取;保留完整导出、版本隔离和有效标签筛选。 验证:前端全量、Go全量及隔离PG全mirror竞态通过;覆盖首批回调、续载失败与筛选分页。
This commit is contained in:
+70
-11
@@ -9,6 +9,8 @@ import { QARegionalStatistics } from './QADepartmentStatistics'
|
||||
import { QADashboard } from './QADashboard'
|
||||
import { QAWeekly } from './QAWeekly'
|
||||
import { QAInlineFields } from './QAInlineFields'
|
||||
import { QAFieldFilters } from './QAFieldFilters'
|
||||
import { buildQAWeeklyCSV, downloadQAWeekly } from './qaWeekly'
|
||||
import { qaFieldColors, qaTagColumns } from './qaFieldColors'
|
||||
import { qualityLabels } from './qaQuality'
|
||||
import { QAWeekPicker } from './QAWeekPicker'
|
||||
@@ -169,10 +171,10 @@ export function QAOperationsView(props: ViewProps) {
|
||||
<section className="qa-ops-results" aria-label="问答记录">
|
||||
<div className="qa-ops-result-bar">
|
||||
<span>
|
||||
{props.loading
|
||||
? `正在读取全部问答…${props.progress ? `(${props.progress.loaded} / ${props.progress.total})` : ''}`
|
||||
: page
|
||||
? `共 ${page.total} 条 · 已载入 ${page.items.length} 条`
|
||||
{page
|
||||
? `共 ${page.total} 条 · 已载入 ${page.items.length} 条${props.loading ? ' · 后台加载中' : props.error || page.has_more ? ' · 未完整读取' : ''}`
|
||||
: props.loading
|
||||
? '正在读取首批问答…'
|
||||
: '尚未读取问答'}
|
||||
</span>
|
||||
<small className="qa-ops-muted">双击行查看详情</small>
|
||||
@@ -360,6 +362,10 @@ export function QAOperations() {
|
||||
const auth = useOptionalAuth()
|
||||
const canRead = auth?.identity?.role === 'admin'
|
||||
const [draft, setDraft] = useState(initialDraft)
|
||||
const [filters, setFilters] = useState<NonNullable<QAQuery['filters']>>({})
|
||||
const [exporting, setExporting] = useState(false),
|
||||
[exportError, setExportError] = useState('')
|
||||
const exportRequest = useRef<AbortController | null>(null)
|
||||
const [query, setQuery] = useState<QAQuery | null>(null)
|
||||
const [page, setPage] = useState<QARecordPage | null>(null)
|
||||
const [status, setStatus] = useState<QAStatus | null>(null)
|
||||
@@ -415,9 +421,18 @@ export function QAOperations() {
|
||||
.catch(() => {
|
||||
if (!controller.signal.aborted) setStatus(null)
|
||||
})
|
||||
void fetchAllQARecords({ ...query, dataset: 'master' }, controller.signal, (loaded, total) => {
|
||||
if (!controller.signal.aborted) setProgress({ loaded, total })
|
||||
})
|
||||
const publish = (result: QARecordPage) => {
|
||||
if (!controller.signal.aborted)
|
||||
setPage({ ...result, items: result.items.map((item) => freshAI.current.get(item.id) ?? item) })
|
||||
}
|
||||
void fetchAllQARecords(
|
||||
{ ...query, dataset: 'master', projection: 'summary' },
|
||||
controller.signal,
|
||||
(loaded, total) => {
|
||||
if (!controller.signal.aborted) setProgress({ loaded, total })
|
||||
},
|
||||
publish
|
||||
)
|
||||
.then((result) => {
|
||||
if (!controller.signal.aborted)
|
||||
setPage({ ...result, items: result.items.map((item) => freshAI.current.get(item.id) ?? item) })
|
||||
@@ -428,8 +443,33 @@ export function QAOperations() {
|
||||
.finally(() => {
|
||||
if (!controller.signal.aborted) setLoading(false)
|
||||
})
|
||||
return () => controller.abort()
|
||||
return () => {
|
||||
controller.abort()
|
||||
generation.current += 1
|
||||
}
|
||||
}, [query, canRead, revision, view])
|
||||
useEffect(() => {
|
||||
exportRequest.current?.abort()
|
||||
setExporting(false)
|
||||
setExportError('')
|
||||
return () => exportRequest.current?.abort()
|
||||
}, [query, view])
|
||||
const exportCSV = async () => {
|
||||
if (!query || exporting) return
|
||||
const abort = new AbortController()
|
||||
exportRequest.current = abort
|
||||
setExporting(true)
|
||||
setExportError('')
|
||||
try {
|
||||
const result = await fetchAllQARecords({ ...query, dataset: 'master', projection: 'full' }, abort.signal)
|
||||
if (!abort.signal.aborted)
|
||||
downloadQAWeekly(buildQAWeeklyCSV(result), 'DobotAI-Questions.csv', 'text/csv;charset=utf-8')
|
||||
} catch (e) {
|
||||
if (!abort.signal.aborted) setExportError(e instanceof Error ? e.message : '完整明细导出失败')
|
||||
} finally {
|
||||
if (!abort.signal.aborted) setExporting(false)
|
||||
}
|
||||
}
|
||||
|
||||
useEffect(
|
||||
() => () => {
|
||||
@@ -445,7 +485,7 @@ export function QAOperations() {
|
||||
end = qaDateTimeToISO(draft.end)
|
||||
if (!(Date.parse(start) < Date.parse(end))) throw new Error('开始时间必须早于结束时间')
|
||||
if (Date.parse(start) >= Date.now()) throw new Error('所选周或时间尚未开始,请选择已开始的时间范围')
|
||||
setQuery({ start, end, keyword: draft.keyword, cursor: '' })
|
||||
setQuery({ start, end, keyword: draft.keyword, cursor: '', filters: { ...filters } })
|
||||
} catch (reason) {
|
||||
setError(reason instanceof Error ? reason.message : '时间格式无效')
|
||||
}
|
||||
@@ -531,6 +571,7 @@ export function QAOperations() {
|
||||
end: qaDateTimeToISO(current.end),
|
||||
keyword: draft.keyword,
|
||||
cursor: '',
|
||||
filters: { ...filters },
|
||||
})
|
||||
}}
|
||||
onChange={(year, week) =>
|
||||
@@ -567,9 +608,10 @@ export function QAOperations() {
|
||||
onChange={(e) => setDraft({ ...draft, keyword: e.target.value })}
|
||||
/>
|
||||
</label>
|
||||
<button className="qa-query-action" type="submit" disabled={loading}>
|
||||
<button className="qa-query-action" type="submit">
|
||||
查询
|
||||
</button>
|
||||
<QAFieldFilters value={filters} onChange={setFilters} />
|
||||
<QAMirrorSync
|
||||
onChanged={() => {
|
||||
if (detail || detailLoading) {
|
||||
@@ -583,7 +625,23 @@ export function QAOperations() {
|
||||
/>
|
||||
</form>
|
||||
<div hidden={view !== 'records'}>
|
||||
<QAAIWorkbench query={query} onStatus={setAIStatus} onRecordChanged={refreshAIRecord} />
|
||||
<QAAIWorkbench
|
||||
query={query}
|
||||
filteredIDs={
|
||||
query?.filters && Object.keys(query.filters).length && page && !loading && !error && !page.has_more
|
||||
? page.items.map((item) => item.id)
|
||||
: undefined
|
||||
}
|
||||
filterRevision={page?.local_revision}
|
||||
onStatus={setAIStatus}
|
||||
onRecordChanged={refreshAIRecord}
|
||||
/>
|
||||
<div className="qa-ledger-export">
|
||||
<button type="button" disabled={!query || exporting} onClick={() => void exportCSV()}>
|
||||
{exporting ? '正在导出完整明细…' : '导出全部明细'}
|
||||
</button>
|
||||
{exportError ? <span role="alert">{exportError}</span> : null}
|
||||
</div>
|
||||
</div>
|
||||
</>
|
||||
) : null}
|
||||
@@ -621,6 +679,7 @@ export function QAOperations() {
|
||||
}}
|
||||
onQualitySaved={(fresh) => {
|
||||
if (fresh.id !== detail?.id) return
|
||||
freshAI.current.set(fresh.id, fresh)
|
||||
setDetail(fresh)
|
||||
setPage((old) =>
|
||||
old ? { ...old, items: old.items.map((item) => (item.id === fresh.id ? fresh : item)) } : old
|
||||
|
||||
Reference in New Issue
Block a user