mirror of
https://github.com/margrop/wrong-notebook.git
synced 2026-12-05 08:19:51 +08:00
merge: 试卷作答拍照入口与框选热区、数字键盘
This commit is contained in:
@@ -77,6 +77,7 @@ test('错题列表跳页、位置恢复与常用筛选视图', async ({ page, sc
|
||||
await expect(page.getByText(`共 ${ITEM_COUNT} 道错题`).last()).toBeVisible({ timeout: 15000 });
|
||||
const mobileJump = page.locator('input[type="number"]').first();
|
||||
await expect(mobileJump).toBeVisible();
|
||||
expect(await mobileJump.getAttribute('inputMode')).toBe('numeric');
|
||||
await mobileJump.fill('2');
|
||||
await page.getByRole('button', { name: '跳转' }).click();
|
||||
await expect(page.getByText(`显示第 19-36 条,共 ${ITEM_COUNT} 条`)).toBeVisible();
|
||||
|
||||
@@ -49,7 +49,7 @@ test.describe('试卷作答照片上传与配准', () => {
|
||||
await expect(dialog).toBeVisible();
|
||||
|
||||
// 上传不含二维码的图片
|
||||
const fileInput = dialog.locator('input[type="file"]');
|
||||
const fileInput = dialog.locator('input[type="file"]:not([capture])');
|
||||
await fileInput.setInputFiles({
|
||||
name: 'plain-sheet.png',
|
||||
mimeType: 'image/png',
|
||||
@@ -153,7 +153,7 @@ test.describe('试卷作答照片上传与配准', () => {
|
||||
const dialog = page.getByRole('dialog');
|
||||
await expect(dialog).toBeVisible();
|
||||
|
||||
await dialog.locator('input[type="file"]').setInputFiles({
|
||||
await dialog.locator('input[type="file"]:not([capture])').setInputFiles({
|
||||
name: 'qr-answer-page-1.png',
|
||||
mimeType: 'image/png',
|
||||
buffer: Buffer.from(photoBase64, 'base64'),
|
||||
@@ -186,8 +186,17 @@ test.describe('试卷作答照片上传与配准', () => {
|
||||
const dialog = page.getByRole('dialog');
|
||||
await expect(dialog).toBeVisible();
|
||||
|
||||
// 拍照与相册/PDF 是两个独立入口:相机入口带 capture,相册入口可多选
|
||||
await expect(dialog.getByRole('button', { name: '拍照', exact: true })).toBeVisible();
|
||||
const cameraInput = dialog.locator('input[type="file"][capture="environment"]');
|
||||
await expect(cameraInput).toHaveCount(1);
|
||||
expect(await cameraInput.getAttribute('accept')).toBe('image/*');
|
||||
const albumInput = dialog.locator('input[type="file"]:not([capture])');
|
||||
await expect(albumInput).toHaveCount(1);
|
||||
expect(await albumInput.getAttribute('multiple')).not.toBeNull();
|
||||
|
||||
// 一次选择两张无二维码照片:页号应为 1、2,后页不覆盖前页
|
||||
await dialog.locator('input[type="file"]').setInputFiles([
|
||||
await albumInput.setInputFiles([
|
||||
{ name: 'plain-a.png', mimeType: 'image/png', buffer: plainPngBuffer() },
|
||||
{ name: 'plain-b.png', mimeType: 'image/png', buffer: plainPngBuffer() },
|
||||
]);
|
||||
@@ -212,6 +221,13 @@ test.describe('试卷作答照片上传与配准', () => {
|
||||
}
|
||||
await expect(dialog.getByRole('button', { name: '保存作答区域' })).toBeEnabled();
|
||||
|
||||
// 框选删除按钮触控热区不小于 36×36px
|
||||
const removeBox = dialog.getByRole('button', { name: '删除第 1 个框', exact: true });
|
||||
const removeBoxSize = await removeBox.boundingBox();
|
||||
expect(removeBoxSize).not.toBeNull();
|
||||
expect(removeBoxSize!.width).toBeGreaterThanOrEqual(36);
|
||||
expect(removeBoxSize!.height).toBeGreaterThanOrEqual(36);
|
||||
|
||||
await dialog.getByRole('button', { name: '2. 手动框选', exact: true }).click();
|
||||
await expect(dialog.getByRole('button', { name: '保存作答区域' })).toBeDisabled();
|
||||
});
|
||||
|
||||
@@ -115,7 +115,7 @@ async function click(element: HTMLElement) {
|
||||
}
|
||||
|
||||
async function uploadFiles(files: File[]) {
|
||||
const input = document.body.querySelector('input[type="file"]');
|
||||
const input = document.body.querySelector('input[type="file"]:not([capture])');
|
||||
if (!(input instanceof HTMLInputElement)) throw new Error('找不到文件输入框');
|
||||
Object.defineProperty(input, 'files', { value: files, configurable: true });
|
||||
const { promise, resolve } = Promise.withResolvers<void>();
|
||||
@@ -166,6 +166,18 @@ afterEach(async () => {
|
||||
});
|
||||
|
||||
describe('ExamAnswerUploadDialog', () => {
|
||||
it('拍照入口单独唤起后置摄像头,相册/PDF 入口保留多选', async () => {
|
||||
await renderDialog(makePaper());
|
||||
|
||||
const camera = document.body.querySelector('input[type="file"][capture="environment"]');
|
||||
expect(camera).toBeInstanceOf(HTMLInputElement);
|
||||
expect(camera!.getAttribute('accept')).toBe('image/*');
|
||||
const album = document.body.querySelector('input[type="file"]:not([capture])');
|
||||
expect(album).toBeInstanceOf(HTMLInputElement);
|
||||
expect(album!.hasAttribute('multiple')).toBe(true);
|
||||
expect(buttonWithText('拍照').disabled).toBe(false);
|
||||
});
|
||||
|
||||
it('题号按卷内 1-based 顺序显示,单页卡片使用本页切图计数', async () => {
|
||||
await renderDialog(makePaper([makeSheet(1)]));
|
||||
|
||||
|
||||
@@ -250,7 +250,7 @@ export default function RegisterPage() {
|
||||
<Input
|
||||
id="enrollmentYear"
|
||||
name="enrollmentYear"
|
||||
type="number"
|
||||
type="number" inputMode="numeric"
|
||||
value={enrollmentYear}
|
||||
onChange={(e) => setEnrollmentYear(e.target.value)}
|
||||
placeholder="YYYY"
|
||||
|
||||
@@ -122,7 +122,7 @@ export function FigureScaleEditor({
|
||||
<label htmlFor={inputId}>{t.figure.scale}</label>
|
||||
<Input
|
||||
id={inputId}
|
||||
type="number"
|
||||
type="number" inputMode="numeric"
|
||||
min={MIN_FIGURE_SCALE}
|
||||
max={MAX_FIGURE_SCALE}
|
||||
step={1}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
"use client";
|
||||
|
||||
import { useEffect, useRef, useState } from "react";
|
||||
import { ImagePlus, Loader2, Trash2 } from "lucide-react";
|
||||
import { Camera, ImagePlus, Loader2, Trash2 } from "lucide-react";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { Dialog, DialogContent, DialogHeader, DialogTitle } from "@/components/ui/dialog";
|
||||
import { ManualAnswerCrop } from "@/components/exam/answer-upload/manual-answer-crop";
|
||||
@@ -73,6 +73,7 @@ export function ExamAnswerUploadDialog({ paper, open, onClose, onChanged }: Exam
|
||||
const [manual, setManual] = useState<{ questionId: string; sheetId: string } | null>(null);
|
||||
const [manualSaving, setManualSaving] = useState(false);
|
||||
const inputRef = useRef<HTMLInputElement>(null);
|
||||
const cameraInputRef = useRef<HTMLInputElement>(null);
|
||||
|
||||
// 父级刷新试卷详情后同步照片页列表
|
||||
useEffect(() => {
|
||||
@@ -196,6 +197,15 @@ export function ExamAnswerUploadDialog({ paper, open, onClose, onChanged }: Exam
|
||||
</DialogHeader>
|
||||
<p className="text-sm text-muted-foreground">{messages.hint}</p>
|
||||
<div className="flex flex-wrap items-center gap-2">
|
||||
{/* 相机入口单独使用 capture=environment,手机可直接唤起后置摄像头 */}
|
||||
<input
|
||||
ref={cameraInputRef}
|
||||
type="file"
|
||||
accept="image/*"
|
||||
capture="environment"
|
||||
className="hidden"
|
||||
onChange={(event) => { void handleFiles(event.target.files); event.target.value = ""; }}
|
||||
/>
|
||||
<input
|
||||
ref={inputRef}
|
||||
type="file"
|
||||
@@ -204,6 +214,10 @@ export function ExamAnswerUploadDialog({ paper, open, onClose, onChanged }: Exam
|
||||
className="hidden"
|
||||
onChange={(event) => { void handleFiles(event.target.files); event.target.value = ""; }}
|
||||
/>
|
||||
<Button size="sm" disabled={busy} onClick={() => cameraInputRef.current?.click()}>
|
||||
<Camera className="mr-2 h-4 w-4" />
|
||||
{messages.takePhoto}
|
||||
</Button>
|
||||
<Button size="sm" disabled={busy} onClick={() => inputRef.current?.click()}>
|
||||
{busy ? <Loader2 className="mr-2 h-4 w-4 animate-spin" /> : <ImagePlus className="mr-2 h-4 w-4" />}
|
||||
{busy ? messages.processing.replace("{count}", String(pendingCount)) : messages.addPhotos}
|
||||
|
||||
@@ -134,7 +134,7 @@ function ExamAttemptEditDialog({ attempt, onClose, onUpdate }: ExamAttemptEditDi
|
||||
<label className="flex items-center gap-2 text-sm">
|
||||
{t.exam.attemptScore}
|
||||
<Input
|
||||
type="number"
|
||||
type="number" inputMode="decimal"
|
||||
min={0}
|
||||
max={1000}
|
||||
step={0.1}
|
||||
|
||||
@@ -285,7 +285,7 @@ export function ExamCreateForm({ onClose }: ExamCreateFormProps) {
|
||||
<Label htmlFor="exam-count">{t.exam.count}</Label>
|
||||
<Input
|
||||
id="exam-count"
|
||||
type="number"
|
||||
type="number" inputMode="numeric"
|
||||
min={1}
|
||||
max={EXAM_FORM_MAX_COUNT}
|
||||
value={count}
|
||||
|
||||
@@ -101,7 +101,7 @@ export function ExamFigureScaleBar({ scales, aligns, onPreviewChange, onSave }:
|
||||
<label htmlFor={inputId} className="font-medium">{t.exam.uniformFigureScale}</label>
|
||||
<Input
|
||||
id={inputId}
|
||||
type="number"
|
||||
type="number" inputMode="numeric"
|
||||
min={MIN_FIGURE_SCALE}
|
||||
max={MAX_FIGURE_SCALE}
|
||||
step={1}
|
||||
|
||||
@@ -53,7 +53,7 @@ export function ExamQuestionScoreInput({ questionId, score, disabled, onSave }:
|
||||
</label>
|
||||
<Input
|
||||
id={`exam-score-${questionId}`}
|
||||
type="number"
|
||||
type="number" inputMode="decimal"
|
||||
min={0.1}
|
||||
max={MAX_EXAM_SCORE}
|
||||
step={0.1}
|
||||
|
||||
@@ -54,7 +54,7 @@ export function ExamScoreBar({ scores, disabled, onSave }: ExamScoreBarProps) {
|
||||
<form onSubmit={save} className="flex flex-wrap items-center gap-2 rounded-md border bg-background p-3 text-sm">
|
||||
<span className="font-medium">{t.exam.uniformScore}</span>
|
||||
<Input
|
||||
type="number"
|
||||
type="number" inputMode="decimal"
|
||||
min={0.1}
|
||||
max={MAX_EXAM_SCORE}
|
||||
step={0.1}
|
||||
|
||||
@@ -89,12 +89,12 @@ export const RegionSelector = forwardRef<HTMLImageElement, RegionSelectorProps>(
|
||||
<span className="absolute left-0 top-0 bg-sky-500 px-1.5 text-xs font-bold text-white">{index + 1}</span>
|
||||
<button
|
||||
type="button"
|
||||
className="absolute -right-3 -top-3 flex h-6 w-6 items-center justify-center rounded-full bg-red-500 text-white shadow"
|
||||
className="absolute -right-2 -top-2 flex h-9 w-9 items-center justify-center rounded-full bg-red-500 text-white shadow"
|
||||
aria-label={t.batchImport.removeRegion.replace("{index}", String(index + 1))}
|
||||
onPointerDown={(event) => event.stopPropagation()}
|
||||
onClick={() => onChange(regions.filter((_, i) => i !== index))}
|
||||
>
|
||||
<X className="h-3 w-3" />
|
||||
<X className="h-4 w-4" />
|
||||
</button>
|
||||
</div>
|
||||
))}
|
||||
|
||||
@@ -164,7 +164,7 @@ export function AccountSettings() {
|
||||
<div className="space-y-2">
|
||||
<Label>{t.auth?.enrollmentYear || "Enrollment Year"}</Label>
|
||||
<Input
|
||||
type="number"
|
||||
type="number" inputMode="numeric"
|
||||
value={profile.enrollmentYear || ""}
|
||||
onChange={(e) => setProfile({ ...profile, enrollmentYear: e.target.value })}
|
||||
placeholder="YYYY"
|
||||
|
||||
@@ -69,7 +69,7 @@ export function DuplicateThresholdSetting({ onSaved }: DuplicateThresholdSetting
|
||||
<div className="space-y-2 border-t pt-4">
|
||||
<Label htmlFor="question-duplicate-threshold">{t.importFlow.thresholdLabel}</Label>
|
||||
<div className="flex flex-wrap items-center gap-2">
|
||||
<Input id="question-duplicate-threshold" type="number" min={1} max={100} step={0.01}
|
||||
<Input id="question-duplicate-threshold" type="number" inputMode="decimal" min={1} max={100} step={0.01}
|
||||
value={value} onChange={(event) => { setValue(event.target.value); setMessage(null); }}
|
||||
disabled={loading || saving || saved === null} className="w-28" aria-describedby="question-duplicate-threshold-hint" />
|
||||
<span aria-hidden="true">%</span>
|
||||
|
||||
@@ -79,7 +79,7 @@ export function GeneralSettings({ config, setConfig, isAdmin, disabled }: Genera
|
||||
<div className="space-y-2 pt-4 border-t">
|
||||
<Label>{t.settings?.general?.timeoutLabel || "AI Analysis Timeout (Seconds)"}</Label>
|
||||
<Input
|
||||
type="number"
|
||||
type="number" inputMode="numeric"
|
||||
value={config.timeouts?.analyze ? config.timeouts.analyze / 1000 : ''}
|
||||
onChange={(e) => {
|
||||
// 输入时不限制范围,失去焦点时再校正
|
||||
|
||||
@@ -63,7 +63,7 @@ export function MasteryThresholdSetting() {
|
||||
<div className="space-y-2 border-t pt-4">
|
||||
<Label htmlFor="mastery-threshold">{t.mastery.thresholdLabel}</Label>
|
||||
<div className="flex flex-wrap items-center gap-2">
|
||||
<Input id="mastery-threshold" type="number" min={MIN_MASTERY_THRESHOLD} max={MAX_MASTERY_THRESHOLD} step={1}
|
||||
<Input id="mastery-threshold" type="number" inputMode="numeric" min={MIN_MASTERY_THRESHOLD} max={MAX_MASTERY_THRESHOLD} step={1}
|
||||
value={value} onChange={(event) => { setValue(event.target.value); setMessage(null); }}
|
||||
disabled={loading || saving || saved === null} className="w-28" aria-describedby="mastery-threshold-hint" />
|
||||
<span aria-hidden="true">%</span>
|
||||
|
||||
@@ -53,7 +53,7 @@ export function TelemetryEndpointForm({ endpoint, retentionDays, disabled, onSav
|
||||
<Label htmlFor="telemetry-retention">{text.retentionDays}</Label>
|
||||
<Input
|
||||
id="telemetry-retention"
|
||||
type="number"
|
||||
type="number" inputMode="numeric"
|
||||
min={1}
|
||||
max={365}
|
||||
className="w-32"
|
||||
|
||||
@@ -162,7 +162,7 @@ export function SubQuestionResultEditor({
|
||||
</label>
|
||||
<Input
|
||||
id={`${idPrefix}-sub-score-${question.index}`}
|
||||
type="number"
|
||||
type="number" inputMode="decimal"
|
||||
min={0}
|
||||
max={MAX_SUB_RESULT_SCORE}
|
||||
step={0.1}
|
||||
|
||||
@@ -2248,6 +2248,7 @@ export const en = {
|
||||
title: "Photo grading: upload answer photos",
|
||||
hint: "Upload full-page photos or a scanned PDF; cut each question's answer area from the printed QR markers and save it for later AI grading. First open this exam's print preview with question QR markers enabled and print it.",
|
||||
addPhotos: "Add photos/PDF",
|
||||
takePhoto: "Take photo",
|
||||
processing: "Processing {count} page(s)…",
|
||||
pageLabel: "Page {page}",
|
||||
noMarker: "No QR marker found; you can select the answer area manually.",
|
||||
|
||||
@@ -2247,6 +2247,7 @@ export const zh = {
|
||||
title: "拍照批改:上传作答照片",
|
||||
hint: "上传整页照片或扫描版 PDF,按打印稿的定位二维码把每道题的作答区域切出并保存,供后续 AI 批改。请先用本卷打印预览开启「每题打印定位二维码」并打印。",
|
||||
addPhotos: "添加照片/PDF",
|
||||
takePhoto: "拍照",
|
||||
processing: "正在处理 {count} 页…",
|
||||
pageLabel: "第 {page} 页",
|
||||
noMarker: "未识别到定位二维码,可手动框选作答区域。",
|
||||
|
||||
Reference in New Issue
Block a user