mirror of
https://github.com/margrop/wrong-notebook.git
synced 2026-12-05 08:00:20 +08:00
feat: 优化手机端弹窗高度与多选悬浮栏
- DialogContent 默认限制 90vh/90dvh 并滚动,避免手机端弹窗溢出视口 - 多选悬浮栏在 sm 以下收敛为单行图标操作,导出/移动/批量编辑收进「更多」 - 相似度对比弹窗新增 compact 图标触发按钮,补充 375×667 E2E 断言
This commit is contained in:
@@ -23,6 +23,52 @@ test.describe('手机端基础控件', () => {
|
||||
await expect(page.getByRole('tab', { name: '导入题库文件' })).toBeVisible();
|
||||
});
|
||||
|
||||
test('[E2E-M12] 手机端多选栏保持单行且弹窗不超出视口', async ({ page, scenario }) => {
|
||||
test.setTimeout(90000);
|
||||
const first = await scenario.item('A');
|
||||
const second = await scenario.item('B');
|
||||
await scenario.login(page);
|
||||
await page.goto(`/notebooks/${scenario.book.id}`);
|
||||
await expect(page.getByText(first.questionText!, { exact: false })).toBeVisible({ timeout: 15000 });
|
||||
|
||||
await page.getByRole('button', { name: '更多', exact: true }).first().click();
|
||||
await page.getByRole('menuitem', { name: '多选', exact: true }).click();
|
||||
for (const item of [first, second]) {
|
||||
await page.locator('a', { hasText: item.questionText! }).locator('..').getByRole('checkbox').click();
|
||||
}
|
||||
|
||||
const bar = page.getByTestId('error-list-selection-bar');
|
||||
await expect(bar.getByText('已选 2 项')).toBeVisible();
|
||||
const barBox = await bar.boundingBox();
|
||||
expect(barBox).not.toBeNull();
|
||||
// 375×667 下悬浮栏收敛为单行图标操作,不再折成三行遮住列表
|
||||
expect(barBox!.height).toBeLessThan(120);
|
||||
const visibleButtons = bar.getByRole('button');
|
||||
for (const button of await visibleButtons.all()) {
|
||||
const box = await button.boundingBox();
|
||||
if (!box) continue;
|
||||
expect(box.x).toBeGreaterThanOrEqual(0);
|
||||
expect(box.x + box.width).toBeLessThanOrEqual(375 + 1);
|
||||
}
|
||||
|
||||
// 次要操作收进「更多」,批量编辑弹窗可完整滚动且不越出视口
|
||||
await bar.getByRole('button', { name: '更多', exact: true }).click();
|
||||
await expect(page.getByRole('menuitem', { name: '导出 JSON' })).toBeVisible();
|
||||
await expect(page.getByRole('menuitem', { name: '移动到错题本' })).toBeVisible();
|
||||
await expect(page.getByRole('menuitem', { name: '批量编辑' })).toBeVisible();
|
||||
await page.getByRole('menuitem', { name: '批量编辑' }).click();
|
||||
|
||||
const dialog = page.getByRole('dialog').filter({ has: page.getByRole('heading', { name: '批量编辑 2 道错题' }) });
|
||||
await expect(dialog).toBeVisible();
|
||||
const dialogBox = await dialog.boundingBox();
|
||||
expect(dialogBox).not.toBeNull();
|
||||
expect(dialogBox!.y).toBeGreaterThanOrEqual(0);
|
||||
expect(dialogBox!.y + dialogBox!.height).toBeLessThanOrEqual(667 + 1);
|
||||
expect(dialogBox!.height).toBeLessThanOrEqual(667 * 0.9 + 1);
|
||||
await dialog.getByRole('button', { name: '保存修改', exact: true }).scrollIntoViewIfNeeded();
|
||||
await expect(dialog.getByRole('button', { name: '保存修改', exact: true })).toBeVisible();
|
||||
});
|
||||
|
||||
test('[E2E-M11] 子页面页头在手机端返回按钮与标题同行', async ({ page, scenario }) => {
|
||||
test.setTimeout(90000);
|
||||
await scenario.login(page);
|
||||
|
||||
@@ -141,6 +141,18 @@
|
||||
@apply bg-background text-foreground;
|
||||
-webkit-tap-highlight-color: transparent;
|
||||
}
|
||||
|
||||
/* 弹窗默认限制在可视高度内并可滚动;优先动态视口,旧内核回退静态视口 */
|
||||
.dialog-viewport-limit {
|
||||
max-height: 90vh;
|
||||
overflow-y: auto;
|
||||
}
|
||||
|
||||
@supports (height: 90dvh) {
|
||||
.dialog-viewport-limit {
|
||||
max-height: 90dvh;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* 移动端底部导航与系统安全区之间的留白 */
|
||||
|
||||
@@ -1,12 +1,13 @@
|
||||
"use client";
|
||||
|
||||
import { useState } from "react";
|
||||
import { ArrowRightLeft, FileJson, ListChecks, PencilLine, Trash2, X } from "lucide-react";
|
||||
import { ArrowRightLeft, FileJson, ListChecks, MoreHorizontal, PencilLine, Trash2, X } from "lucide-react";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { BatchEditDialog } from "@/components/error-list/batch-edit-dialog";
|
||||
import { BatchProgress } from "@/components/error-list/batch-progress";
|
||||
import { ExportQuestionsDialog } from "@/components/error-list/export-questions-dialog";
|
||||
import { MoveToNotebookDialog } from "@/components/error-list/move-to-notebook-dialog";
|
||||
import { DropdownMenu, DropdownMenuContent, DropdownMenuItem, DropdownMenuTrigger } from "@/components/ui/dropdown-menu";
|
||||
import { QuestionSimilarityDialog } from "@/components/question-similarity-dialog";
|
||||
import { useLanguage } from "@/contexts/LanguageContext";
|
||||
import type { BatchRunnerState } from "@/lib/hooks/use-batch-runner";
|
||||
@@ -46,13 +47,13 @@ export function ErrorListSelectionBar({
|
||||
const [editDialogOpen, setEditDialogOpen] = useState(false);
|
||||
|
||||
return (
|
||||
<div className="pb-safe fixed bottom-0 left-0 right-0 z-50 border-t bg-card/95 p-4 shadow-lg backdrop-blur">
|
||||
<div className="mx-auto flex max-w-6xl flex-col gap-3 sm:flex-row sm:items-center sm:justify-between">
|
||||
<div data-testid="error-list-selection-bar" className="pb-safe fixed bottom-0 left-0 right-0 z-50 border-t bg-card/95 p-3 shadow-lg backdrop-blur sm:p-4">
|
||||
<div className="mx-auto flex max-w-6xl flex-col gap-2 sm:flex-row sm:items-center sm:justify-between sm:gap-3">
|
||||
<div className="space-y-1 text-sm text-muted-foreground">
|
||||
<p>{t.notebook.selectedCount.replace("{count}", String(selectedIds.length))}</p>
|
||||
<p className="text-xs">{t.questionSimilarity.selectTwo}</p>
|
||||
<p className="hidden text-xs sm:block">{t.questionSimilarity.selectTwo}</p>
|
||||
</div>
|
||||
<div className="flex flex-wrap gap-2">
|
||||
<div className="hidden flex-wrap gap-2 sm:flex">
|
||||
<QuestionSimilarityDialog ids={selectedIds} />
|
||||
<Button
|
||||
variant="outline"
|
||||
@@ -91,9 +92,83 @@ export function ErrorListSelectionBar({
|
||||
<Trash2 className="mr-2 h-4 w-4" />{t.notebook.deleteSelected}
|
||||
</Button>
|
||||
</div>
|
||||
|
||||
{/* 手机端只保留高频图标操作,导出/移动/批量编辑收进「更多」,避免多行悬浮栏遮住列表 */}
|
||||
<div className="flex items-center gap-2 sm:hidden">
|
||||
<QuestionSimilarityDialog ids={selectedIds} compact />
|
||||
<Button
|
||||
variant="outline"
|
||||
size="sm"
|
||||
className="h-9 w-9 p-0"
|
||||
onClick={onSelectAll}
|
||||
disabled={deleting}
|
||||
aria-label={t.notebook.selectAll}
|
||||
title={t.notebook.selectAll}
|
||||
>
|
||||
<ListChecks className="h-4 w-4" />
|
||||
</Button>
|
||||
<DropdownMenu>
|
||||
<DropdownMenuTrigger asChild>
|
||||
<Button
|
||||
variant="outline"
|
||||
size="sm"
|
||||
className="h-9 w-9 p-0"
|
||||
aria-label={t.notebook.moreActions}
|
||||
title={t.notebook.moreActions}
|
||||
>
|
||||
<MoreHorizontal className="h-4 w-4" />
|
||||
</Button>
|
||||
</DropdownMenuTrigger>
|
||||
<DropdownMenuContent align="end" side="top" className="w-52">
|
||||
<DropdownMenuItem
|
||||
onClick={() => setExportDialogOpen(true)}
|
||||
disabled={selectedIds.length === 0 || deleting}
|
||||
>
|
||||
<FileJson className="mr-2 h-4 w-4" />
|
||||
{t.notebook.exportJson}
|
||||
</DropdownMenuItem>
|
||||
<DropdownMenuItem
|
||||
onClick={() => setMoveDialogOpen(true)}
|
||||
disabled={selectedIds.length === 0 || deleting}
|
||||
>
|
||||
<ArrowRightLeft className="mr-2 h-4 w-4" />
|
||||
{t.notebook.moveToNotebook}
|
||||
</DropdownMenuItem>
|
||||
<DropdownMenuItem
|
||||
onClick={() => setEditDialogOpen(true)}
|
||||
disabled={selectedIds.length === 0 || deleting}
|
||||
>
|
||||
<PencilLine className="mr-2 h-4 w-4" />
|
||||
{t.notebook.batchEdit}
|
||||
</DropdownMenuItem>
|
||||
</DropdownMenuContent>
|
||||
</DropdownMenu>
|
||||
<Button
|
||||
variant="outline"
|
||||
size="sm"
|
||||
className="ml-auto h-9 w-9 p-0"
|
||||
onClick={onCancel}
|
||||
disabled={deleting}
|
||||
aria-label={t.notebook.cancelSelect}
|
||||
title={t.notebook.cancelSelect}
|
||||
>
|
||||
<X className="h-4 w-4" />
|
||||
</Button>
|
||||
<Button
|
||||
variant="destructive"
|
||||
size="sm"
|
||||
className="h-9 w-9 p-0"
|
||||
onClick={onDelete}
|
||||
disabled={selectedIds.length === 0 || deleting}
|
||||
aria-label={t.notebook.deleteSelected}
|
||||
title={t.notebook.deleteSelected}
|
||||
>
|
||||
<Trash2 className="h-4 w-4" />
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="mx-auto mt-3 max-w-6xl">
|
||||
<div className="mx-auto mt-2 max-w-6xl sm:mt-3">
|
||||
<BatchProgress
|
||||
done={batchState.done}
|
||||
total={batchState.total}
|
||||
|
||||
@@ -14,10 +14,12 @@ import type { QuestionSimilarityResponse } from '@/types/api';
|
||||
|
||||
interface QuestionSimilarityDialogProps {
|
||||
ids: string[];
|
||||
/** 手机多选栏使用图标按钮,节省横向空间 */
|
||||
compact?: boolean;
|
||||
}
|
||||
|
||||
/** 对比结果与阈值调整放在同一处,保存后重新读取服务端判重结果。 */
|
||||
export function QuestionSimilarityDialog({ ids }: QuestionSimilarityDialogProps) {
|
||||
export function QuestionSimilarityDialog({ ids, compact = false }: QuestionSimilarityDialogProps) {
|
||||
const { t } = useLanguage();
|
||||
const [open, setOpen] = useState(false);
|
||||
const [data, setData] = useState<QuestionSimilarityResponse | null>(null);
|
||||
@@ -50,9 +52,16 @@ export function QuestionSimilarityDialog({ ids }: QuestionSimilarityDialogProps)
|
||||
return (
|
||||
<Dialog open={open} onOpenChange={(value) => { setOpen(value); if (value) refresh(); }}>
|
||||
<DialogTrigger asChild>
|
||||
<Button variant="outline" disabled={ids.length !== 2} title={t.questionSimilarity.selectTwo}>
|
||||
<GitCompareArrows className="mr-2 h-4 w-4" />
|
||||
{t.questionSimilarity.title}
|
||||
<Button
|
||||
variant="outline"
|
||||
size={compact ? "sm" : undefined}
|
||||
className={compact ? "h-9 w-9 p-0" : undefined}
|
||||
disabled={ids.length !== 2}
|
||||
title={compact ? t.questionSimilarity.title : t.questionSimilarity.selectTwo}
|
||||
aria-label={compact ? t.questionSimilarity.title : undefined}
|
||||
>
|
||||
<GitCompareArrows className={compact ? "h-4 w-4" : "mr-2 h-4 w-4"} />
|
||||
{!compact && t.questionSimilarity.title}
|
||||
</Button>
|
||||
</DialogTrigger>
|
||||
<DialogContent className="w-[calc(100vw-2rem)] sm:max-w-3xl max-h-[85vh] overflow-y-auto">
|
||||
|
||||
@@ -44,7 +44,7 @@ const DialogContent = React.forwardRef<
|
||||
// 用 inset-0 + m-auto 居中,不依赖 CSS translate 属性:旧版安卓系统 WebView(Chrome 104 以下)
|
||||
// 不支持 translate,按 left/top 50% 定位会让面板偏到屏幕右下方,按钮点不到
|
||||
className={cn(
|
||||
"fixed inset-0 m-auto h-fit z-50 grid w-[calc(100%-2rem)] max-w-lg gap-4 rounded-2xl border bg-card p-6 shadow-xl duration-200 data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95",
|
||||
"dialog-viewport-limit fixed inset-0 m-auto h-fit z-50 grid w-[calc(100%-2rem)] max-w-lg gap-4 rounded-2xl border bg-card p-6 shadow-xl duration-200 data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95",
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
@@ -79,7 +79,7 @@ const DialogFooter = ({
|
||||
}: React.HTMLAttributes<HTMLDivElement>) => (
|
||||
<div
|
||||
className={cn(
|
||||
"flex flex-col-reverse sm:flex-row sm:justify-end sm:space-x-2",
|
||||
"flex flex-col-reverse gap-2 sm:flex-row sm:justify-end sm:space-x-2",
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
|
||||
Reference in New Issue
Block a user