详情使用共享主表字典,稀疏修改所选字段并保留原始问答及旧复核审计。 月周统计提供文本和下拉双入口;每租户每周一份持久草稿,按技能六节双语模板真实预填。 加入幂等自动保存、冲突保留、未知响应重试、切周及离开保护和schema58非破坏降级保护。 验证:完整make verify、隔离PostgreSQL全mirror竞态回归、真实恢复库浏览器验收通过。 浏览器实测字段精确读回、月周双输入、模板预填、MD/CSV、自动保存、冲突、失败重试与API重启恢复。 未连接或改写DobotAI生产源库,未运行付费模型;提交时尚未部署。
This commit is contained in:
@@ -0,0 +1,102 @@
|
||||
import { useEffect, useId, useMemo, useState } from 'react'
|
||||
import type { QAPeriodKind } from './qaPeriodInput'
|
||||
import { periodInputOptions, validPeriodInput } from './qaPeriodInput'
|
||||
import { qaWeek } from './qaWeeks'
|
||||
import './qaPeriodInput.css'
|
||||
export interface QAPeriodInputProps {
|
||||
kind: QAPeriodKind
|
||||
label: string
|
||||
ariaLabel: string
|
||||
value: string
|
||||
max: string
|
||||
onChange: (value: string) => void
|
||||
disabled?: boolean
|
||||
}
|
||||
export function QAPeriodInput(p: QAPeriodInputProps) {
|
||||
const id = useId(),
|
||||
[text, setText] = useState(p.value),
|
||||
[error, setError] = useState('')
|
||||
useEffect(() => {
|
||||
setText(p.value)
|
||||
setError('')
|
||||
}, [p.value, p.kind])
|
||||
const options = useMemo(() => {
|
||||
const values = periodInputOptions(p.kind, p.max)
|
||||
if (validPeriodInput(p.kind, p.value, p.max) && !values.includes(p.value)) values.push(p.value)
|
||||
return values
|
||||
}, [p.kind, p.max, p.value])
|
||||
const apply = () => {
|
||||
if (text === p.value) return
|
||||
if (!validPeriodInput(p.kind, text, p.max)) {
|
||||
setError(
|
||||
`请输入有效的${p.kind === 'month' ? 'YYYY-MM月份' : 'YYYY-Www自然周'},最早2000年、不晚于${p.max};仍显示${p.value}的结果`
|
||||
)
|
||||
return
|
||||
}
|
||||
setError('')
|
||||
p.onChange(text)
|
||||
}
|
||||
return (
|
||||
<div className="qa-period-input">
|
||||
<label htmlFor={id}>{p.label}</label>
|
||||
<div className="qa-period-combo">
|
||||
<input
|
||||
id={id}
|
||||
type="text"
|
||||
aria-label={p.ariaLabel}
|
||||
aria-describedby={`${id}-hint`}
|
||||
aria-invalid={!!error}
|
||||
autoComplete="off"
|
||||
spellCheck={false}
|
||||
value={text}
|
||||
disabled={p.disabled}
|
||||
placeholder={p.kind === 'month' ? 'YYYY-MM' : 'YYYY-Www'}
|
||||
onChange={(e) => {
|
||||
setText(e.target.value)
|
||||
setError('')
|
||||
}}
|
||||
onBlur={apply}
|
||||
onKeyDown={(e) => {
|
||||
if (e.key === 'Enter') {
|
||||
e.preventDefault()
|
||||
apply()
|
||||
}
|
||||
if (e.key === 'Escape') {
|
||||
setText(p.value)
|
||||
setError('')
|
||||
}
|
||||
}}
|
||||
/>
|
||||
<select
|
||||
aria-label={`${p.ariaLabel}下拉选择`}
|
||||
value=""
|
||||
disabled={p.disabled}
|
||||
onChange={(e) => {
|
||||
const value = e.target.value
|
||||
if (!value) return
|
||||
setText(value)
|
||||
setError('')
|
||||
p.onChange(value)
|
||||
}}
|
||||
>
|
||||
<option value="" disabled>
|
||||
选择
|
||||
</option>
|
||||
{options.map((v) => (
|
||||
<option key={v} value={v}>
|
||||
{p.kind === 'week' ? `${v} ${qaWeek(Number(v.slice(0, 4)), Number(v.slice(6))).label}` : v}
|
||||
</option>
|
||||
))}
|
||||
</select>
|
||||
</div>
|
||||
<small id={`${id}-hint`} role={error ? 'alert' : undefined}>
|
||||
{error ||
|
||||
(text !== p.value
|
||||
? '尚未应用,按回车或移开输入框确认'
|
||||
: p.kind === 'week'
|
||||
? qaWeek(Number(p.value.slice(0, 4)), Number(p.value.slice(6))).label
|
||||
: '可下拉选择,也可直接输入')}
|
||||
</small>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
Reference in New Issue
Block a user