mirror of
https://github.com/margrop/wrong-notebook.git
synced 2026-12-02 10:20:25 +08:00
feat: 账户设置支持选择具体年级学期
- 学段选择后联动显示年级下拉,选完年级出现学期下拉 - 保存时自动组装 fixedGradeSemester 提交到 API - API 对 educationStage 加枚举校验,空字符串安全跳过 - 新增 grade-options 工具函数(gradesForStage、parseGradeSemester) - 中英文翻译同步补充
This commit is contained in:
43
prisma/migrations/20261031200339_add_tag_set/migration.sql
Normal file
43
prisma/migrations/20261031200339_add_tag_set/migration.sql
Normal file
@@ -0,0 +1,43 @@
|
||||
-- RedefineTables
|
||||
PRAGMA defer_foreign_keys=ON;
|
||||
PRAGMA foreign_keys=OFF;
|
||||
CREATE TABLE "new_KnowledgeTag" (
|
||||
"id" TEXT NOT NULL PRIMARY KEY,
|
||||
"name" TEXT NOT NULL,
|
||||
"subject" TEXT NOT NULL,
|
||||
"parentId" TEXT,
|
||||
"order" INTEGER NOT NULL DEFAULT 0,
|
||||
"code" TEXT,
|
||||
"isSystem" BOOLEAN NOT NULL DEFAULT false,
|
||||
"userId" TEXT,
|
||||
"tagSet" TEXT NOT NULL DEFAULT 'default',
|
||||
"createdAt" DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
"updatedAt" DATETIME NOT NULL,
|
||||
CONSTRAINT "KnowledgeTag_parentId_fkey" FOREIGN KEY ("parentId") REFERENCES "KnowledgeTag" ("id") ON DELETE SET NULL ON UPDATE CASCADE,
|
||||
CONSTRAINT "KnowledgeTag_userId_fkey" FOREIGN KEY ("userId") REFERENCES "User" ("id") ON DELETE CASCADE ON UPDATE CASCADE
|
||||
);
|
||||
INSERT INTO "new_KnowledgeTag" ("code", "createdAt", "id", "isSystem", "name", "order", "parentId", "subject", "updatedAt", "userId") SELECT "code", "createdAt", "id", "isSystem", "name", "order", "parentId", "subject", "updatedAt", "userId" FROM "KnowledgeTag";
|
||||
DROP TABLE "KnowledgeTag";
|
||||
ALTER TABLE "new_KnowledgeTag" RENAME TO "KnowledgeTag";
|
||||
CREATE INDEX "KnowledgeTag_parentId_idx" ON "KnowledgeTag"("parentId");
|
||||
CREATE INDEX "KnowledgeTag_subject_idx" ON "KnowledgeTag"("subject");
|
||||
CREATE INDEX "KnowledgeTag_tagSet_idx" ON "KnowledgeTag"("tagSet");
|
||||
CREATE UNIQUE INDEX "KnowledgeTag_subject_name_userId_parentId_tagSet_key" ON "KnowledgeTag"("subject", "name", "userId", "parentId", "tagSet");
|
||||
CREATE TABLE "new_Subject" (
|
||||
"id" TEXT NOT NULL PRIMARY KEY,
|
||||
"name" TEXT NOT NULL,
|
||||
"stage" TEXT NOT NULL DEFAULT 'primary',
|
||||
"subjectKey" TEXT,
|
||||
"tagSet" TEXT NOT NULL DEFAULT 'default',
|
||||
"userId" TEXT NOT NULL,
|
||||
"createdAt" DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
"updatedAt" DATETIME NOT NULL,
|
||||
CONSTRAINT "Subject_userId_fkey" FOREIGN KEY ("userId") REFERENCES "User" ("id") ON DELETE CASCADE ON UPDATE CASCADE
|
||||
);
|
||||
INSERT INTO "new_Subject" ("createdAt", "id", "name", "stage", "subjectKey", "updatedAt", "userId") SELECT "createdAt", "id", "name", "stage", "subjectKey", "updatedAt", "userId" FROM "Subject";
|
||||
DROP TABLE "Subject";
|
||||
ALTER TABLE "new_Subject" RENAME TO "Subject";
|
||||
CREATE INDEX "Subject_userId_idx" ON "Subject"("userId");
|
||||
CREATE UNIQUE INDEX "Subject_name_userId_key" ON "Subject"("name", "userId");
|
||||
PRAGMA foreign_keys=ON;
|
||||
PRAGMA defer_foreign_keys=OFF;
|
||||
@@ -62,17 +62,21 @@ model KnowledgeTag {
|
||||
userId String? // 如果是用户自定义标签,绑定 userId
|
||||
user User? @relation(fields: [userId], references: [id], onDelete: Cascade)
|
||||
|
||||
// 标签体系:标识标签所属的数据源/体系,不同体系可并存于同一学科
|
||||
tagSet String @default("default")
|
||||
|
||||
// 与错题的多对多关系
|
||||
errorItems ErrorItem[]
|
||||
|
||||
createdAt DateTime @default(now())
|
||||
updatedAt DateTime @updatedAt
|
||||
|
||||
// 联合索引:确保同一用户(或系统)下同一父节点下的标签名不重复
|
||||
@@unique([subject, name, userId, parentId])
|
||||
// 联合索引:确保同一用户(或系统)下同一父节点、同一体系下的标签名不重复
|
||||
@@unique([subject, name, userId, parentId, tagSet])
|
||||
// 索引:加速父子查询
|
||||
@@index([parentId])
|
||||
@@index([subject])
|
||||
@@index([tagSet])
|
||||
}
|
||||
|
||||
model Subject {
|
||||
@@ -80,6 +84,7 @@ model Subject {
|
||||
name String
|
||||
stage String @default("primary") // 学段:primary / junior_high / senior_high,仅创建时设置
|
||||
subjectKey String? // 学科:math / english / physics 等,仅创建时设置;为空时按名称推断
|
||||
tagSet String @default("default") // 标签体系:default=内置体系,其他值为导入的备选体系
|
||||
userId String
|
||||
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
|
||||
|
||||
|
||||
@@ -40,5 +40,10 @@ afterEach(() => {
|
||||
vi.restoreAllMocks();
|
||||
});
|
||||
|
||||
// jsdom 未实现 scrollIntoView,Radix Select 打开下拉时调用
|
||||
if (typeof Element !== 'undefined' && !Element.prototype.scrollIntoView) {
|
||||
Element.prototype.scrollIntoView = () => {};
|
||||
}
|
||||
|
||||
// Export for use in individual tests
|
||||
export { localStorageMock };
|
||||
|
||||
107
src/__tests__/unit/account-settings.test.tsx
Normal file
107
src/__tests__/unit/account-settings.test.tsx
Normal file
@@ -0,0 +1,107 @@
|
||||
import { act } from 'react';
|
||||
import { createRoot } from 'react-dom/client';
|
||||
import type { Root } from 'react-dom/client';
|
||||
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
|
||||
import { AccountSettings } from '@/components/settings/account-settings';
|
||||
import { LanguageProvider } from '@/contexts/LanguageContext';
|
||||
import { apiClient } from '@/lib/api-client';
|
||||
|
||||
vi.mock('@/lib/api-client', () => ({ apiClient: { get: vi.fn(), patch: vi.fn() } }));
|
||||
vi.mock('@/lib/frontend-logger', () => ({ frontendLogger: { error: vi.fn() } }));
|
||||
vi.mock('@/lib/feedback', () => ({ toast: { success: vi.fn(), error: vi.fn() } }));
|
||||
|
||||
let container: HTMLDivElement;
|
||||
let root: Root;
|
||||
|
||||
beforeEach(() => {
|
||||
vi.stubGlobal('IS_REACT_ACT_ENVIRONMENT', true);
|
||||
container = document.createElement('div');
|
||||
document.body.appendChild(container);
|
||||
root = createRoot(container);
|
||||
});
|
||||
|
||||
afterEach(async () => {
|
||||
await act(async () => root.unmount());
|
||||
container.remove();
|
||||
vi.unstubAllGlobals();
|
||||
});
|
||||
|
||||
async function render() {
|
||||
await act(async () => root.render(<LanguageProvider><AccountSettings /></LanguageProvider>));
|
||||
}
|
||||
|
||||
/** 在 Select 组件上模拟选择:找到 trigger button,点击打开,再点击对应项 */
|
||||
async function selectOption(triggerIndex: number, optionText: string) {
|
||||
// Radix Select trigger 是 button
|
||||
const triggers = container.querySelectorAll<HTMLButtonElement>('[role="combobox"]');
|
||||
const trigger = triggers[triggerIndex];
|
||||
if (!trigger) throw new Error(`Select trigger ${triggerIndex} not found`);
|
||||
await act(async () => trigger.click());
|
||||
// 找到下拉面板中匹配的选项
|
||||
const options = document.querySelectorAll('[role="option"]');
|
||||
const target = [...options].find((el) => el.textContent === optionText);
|
||||
if (!target) throw new Error(`Option "${optionText}" not found`);
|
||||
await act(async () => (target as HTMLElement).click());
|
||||
}
|
||||
|
||||
describe('账户设置的当前年级学期联动', () => {
|
||||
it('未选学段时不显示年级学期选择', async () => {
|
||||
vi.mocked(apiClient.get).mockResolvedValue({ name: '', email: '', educationStage: '', enrollmentYear: '', fixedGradeSemester: null });
|
||||
await render();
|
||||
expect(container.textContent).not.toContain('当前年级学期');
|
||||
});
|
||||
|
||||
it('选择学段后显示年级选择,选完年级出现学期选择', async () => {
|
||||
vi.mocked(apiClient.get).mockResolvedValue({ name: '', email: '', educationStage: '', enrollmentYear: '', fixedGradeSemester: null });
|
||||
await render();
|
||||
// 第一个 select 是学段
|
||||
await selectOption(0, '小学');
|
||||
expect(container.textContent).toContain('当前年级学期');
|
||||
// 选年级(第二个 select)
|
||||
await selectOption(1, '三年级');
|
||||
expect(container.textContent).toContain('选择学期');
|
||||
});
|
||||
|
||||
it('从 fixedGradeSemester 回填年级和学期', async () => {
|
||||
vi.mocked(apiClient.get).mockResolvedValue({ name: '', email: '', educationStage: 'junior_high', enrollmentYear: 2025, fixedGradeSemester: '初二下' });
|
||||
await render();
|
||||
expect(container.textContent).toContain('当前年级学期');
|
||||
// 年级应该是初二
|
||||
const triggers = container.querySelectorAll<HTMLButtonElement>('[role="combobox"]');
|
||||
expect(triggers[1]?.textContent).toContain('初二');
|
||||
// 学期应该是下学期
|
||||
expect(triggers[2]?.textContent).toContain('下学期');
|
||||
});
|
||||
|
||||
it('保存时提交组装好的 fixedGradeSemester', async () => {
|
||||
vi.mocked(apiClient.get).mockResolvedValue({ name: '', email: '', educationStage: 'primary', enrollmentYear: '', fixedGradeSemester: null });
|
||||
vi.mocked(apiClient.patch).mockResolvedValue({});
|
||||
await render();
|
||||
await selectOption(1, '五年级');
|
||||
await selectOption(2, '上学期');
|
||||
await act(async () => {
|
||||
const saveBtn = [...container.querySelectorAll('button')].find((b) => b.textContent?.includes('更新个人信息'))!;
|
||||
saveBtn.click();
|
||||
});
|
||||
expect(apiClient.patch).toHaveBeenCalledWith('/api/user', expect.objectContaining({
|
||||
educationStage: 'primary',
|
||||
fixedGradeSemester: '五年级上',
|
||||
}));
|
||||
});
|
||||
|
||||
it('清除年级后提交 fixedGradeSemester 为 null', async () => {
|
||||
vi.mocked(apiClient.get).mockResolvedValue({ name: '', email: '', educationStage: 'junior_high', enrollmentYear: 2025, fixedGradeSemester: '初三上' });
|
||||
vi.mocked(apiClient.patch).mockResolvedValue({});
|
||||
await render();
|
||||
// 年级回填为初三,清除:选择空选项(Radix Select 的 placeholder 项)
|
||||
// 通过重新选学段触发重置来模拟清除
|
||||
await selectOption(0, '高中');
|
||||
await act(async () => {
|
||||
const saveBtn = [...container.querySelectorAll('button')].find((b) => b.textContent?.includes('更新个人信息'))!;
|
||||
saveBtn.click();
|
||||
});
|
||||
expect(apiClient.patch).toHaveBeenCalledWith('/api/user', expect.objectContaining({
|
||||
fixedGradeSemester: null,
|
||||
}));
|
||||
});
|
||||
});
|
||||
74
src/__tests__/unit/grade-options.test.ts
Normal file
74
src/__tests__/unit/grade-options.test.ts
Normal file
@@ -0,0 +1,74 @@
|
||||
/**
|
||||
* grade-options 单元测试
|
||||
* 测试学段年级映射与年级学期解析函数
|
||||
*/
|
||||
import { describe, it, expect } from 'vitest';
|
||||
import { GRADE_NAMES, GRADE_SEMESTERS, STAGE_GRADE_RANGES, gradesForStage, parseGradeSemester } from '@/lib/grade-options';
|
||||
|
||||
describe('gradesForStage', () => {
|
||||
it('返回各学段的完整年级列表', () => {
|
||||
expect(gradesForStage('primary')).toEqual(['一年级', '二年级', '三年级', '四年级', '五年级', '六年级']);
|
||||
expect(gradesForStage('junior_high')).toEqual(['初一', '初二', '初三']);
|
||||
expect(gradesForStage('senior_high')).toEqual(['高一', '高二', '高三']);
|
||||
expect(gradesForStage('university')).toEqual(['大一', '大二', '大三', '大四']);
|
||||
});
|
||||
|
||||
it('未知学段返回空数组', () => {
|
||||
expect(gradesForStage('unknown')).toEqual([]);
|
||||
expect(gradesForStage('')).toEqual([]);
|
||||
});
|
||||
|
||||
it('所有学段年级合在一起等于完整 GRADE_NAMES', () => {
|
||||
const all = [
|
||||
...gradesForStage('primary'),
|
||||
...gradesForStage('junior_high'),
|
||||
...gradesForStage('senior_high'),
|
||||
...gradesForStage('university'),
|
||||
];
|
||||
expect(all).toEqual([...GRADE_NAMES]);
|
||||
});
|
||||
});
|
||||
|
||||
describe('parseGradeSemester', () => {
|
||||
it('解析「上」结尾的年级学期', () => {
|
||||
expect(parseGradeSemester('四年级上')).toEqual({ grade: '四年级', semester: '上' });
|
||||
expect(parseGradeSemester('初一上')).toEqual({ grade: '初一', semester: '上' });
|
||||
});
|
||||
|
||||
it('解析「下」结尾的年级学期', () => {
|
||||
expect(parseGradeSemester('高二下')).toEqual({ grade: '高二', semester: '下' });
|
||||
});
|
||||
|
||||
it('不带学期后缀返回 null', () => {
|
||||
expect(parseGradeSemester('四年级')).toBeNull();
|
||||
});
|
||||
|
||||
it('空字符串返回 null', () => {
|
||||
expect(parseGradeSemester('')).toBeNull();
|
||||
});
|
||||
|
||||
it('解析结果可通过 GRADE_SEMESTERS 校验', () => {
|
||||
for (const gs of ['四年级上', '初一下', '高三上', '大二下']) {
|
||||
const parsed = parseGradeSemester(gs);
|
||||
expect(parsed).not.toBeNull();
|
||||
expect(GRADE_SEMESTERS).toContain(gs);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
describe('STAGE_GRADE_RANGES', () => {
|
||||
it('覆盖所有四个学段', () => {
|
||||
expect(Object.keys(STAGE_GRADE_RANGES)).toEqual(['primary', 'junior_high', 'senior_high', 'university']);
|
||||
});
|
||||
|
||||
it('各学段范围互不重叠且连续', () => {
|
||||
const ranges = Object.values(STAGE_GRADE_RANGES);
|
||||
let prevEnd = 0;
|
||||
for (const { start, end } of ranges) {
|
||||
expect(start).toBe(prevEnd);
|
||||
expect(end).toBeGreaterThan(start);
|
||||
prevEnd = end;
|
||||
}
|
||||
expect(prevEnd).toBe(GRADE_NAMES.length);
|
||||
});
|
||||
});
|
||||
@@ -20,7 +20,7 @@ const userUpdateSchema = z.object({
|
||||
name: z.string().optional(),
|
||||
email: z.string().optional(),
|
||||
password: z.string().optional(),
|
||||
educationStage: z.string().optional(),
|
||||
educationStage: z.preprocess((val) => (val === '' ? undefined : val), z.enum(["primary", "junior_high", "senior_high", "university"]).optional()),
|
||||
enrollmentYear: z.number().optional().nullable(),
|
||||
gradeRecognitionMode: z.enum(GRADE_RECOGNITION_MODES).optional(),
|
||||
fixedGradeSemester: z.enum(GRADE_SEMESTERS).nullable().optional(),
|
||||
|
||||
@@ -12,6 +12,7 @@ import { apiClient } from "@/lib/api-client";
|
||||
import { getApiErrorMessage, getErrorMessage } from "@/lib/error-message";
|
||||
import { toast } from "@/lib/feedback";
|
||||
import { frontendLogger } from "@/lib/frontend-logger";
|
||||
import { gradesForStage, parseGradeSemester } from "@/lib/grade-options";
|
||||
import type { UpdateUserProfileRequest, UserProfile } from "@/types/api";
|
||||
|
||||
interface ProfileFormState {
|
||||
@@ -19,12 +20,16 @@ interface ProfileFormState {
|
||||
email: string;
|
||||
educationStage: string;
|
||||
enrollmentYear: string | number;
|
||||
/** 从 fixedGradeSemester 解析出的当前年级,空字符串表示未设置 */
|
||||
currentGrade: string;
|
||||
/** 从 fixedGradeSemester 解析出的当前学期:上 / 下 */
|
||||
currentSemester: string;
|
||||
password: string;
|
||||
}
|
||||
|
||||
const EMPTY_PROFILE: ProfileFormState = { name: "", email: "", educationStage: "", enrollmentYear: "", password: "" };
|
||||
const EMPTY_PROFILE: ProfileFormState = { name: "", email: "", educationStage: "", enrollmentYear: "", currentGrade: "", currentSemester: "", password: "" };
|
||||
|
||||
/** 账户设置:姓名、邮箱、学段、入学年份和修改密码 */
|
||||
/** 账户设置:姓名、邮箱、学段、当前年级学期、入学年份和修改密码 */
|
||||
export function AccountSettings() {
|
||||
const { t } = useLanguage();
|
||||
const [profile, setProfile] = useState<ProfileFormState>(EMPTY_PROFILE);
|
||||
@@ -35,11 +40,14 @@ export function AccountSettings() {
|
||||
const fetchProfile = useCallback(async () => {
|
||||
try {
|
||||
const data = await apiClient.get<UserProfile>("/api/user");
|
||||
const parsed = data.fixedGradeSemester ? parseGradeSemester(data.fixedGradeSemester) : null;
|
||||
setProfile({
|
||||
name: data.name || "",
|
||||
email: data.email || "",
|
||||
educationStage: data.educationStage || "",
|
||||
enrollmentYear: data.enrollmentYear || "",
|
||||
currentGrade: parsed?.grade || "",
|
||||
currentSemester: parsed?.semester || "",
|
||||
password: ""
|
||||
});
|
||||
} catch (error) {
|
||||
@@ -74,6 +82,12 @@ export function AccountSettings() {
|
||||
if (profile.password) {
|
||||
payload.password = profile.password;
|
||||
}
|
||||
// 组装 fixedGradeSemester:有年级有学期才提交;清空年级时也提交 null
|
||||
if (profile.currentGrade && profile.currentSemester) {
|
||||
payload.fixedGradeSemester = `${profile.currentGrade}${profile.currentSemester}`;
|
||||
} else if (!profile.currentGrade) {
|
||||
payload.fixedGradeSemester = null;
|
||||
}
|
||||
|
||||
await apiClient.patch("/api/user", payload);
|
||||
|
||||
@@ -122,7 +136,13 @@ export function AccountSettings() {
|
||||
<Label>{t.auth?.educationStage || "Education Stage"}</Label>
|
||||
<Select
|
||||
value={profile.educationStage || ""}
|
||||
onValueChange={(val) => setProfile({ ...profile, educationStage: val })}
|
||||
onValueChange={(val) => setProfile({
|
||||
...profile,
|
||||
educationStage: val,
|
||||
// 切换学段时重置年级学期,避免跨学段残留
|
||||
currentGrade: gradesForStage(val).includes(profile.currentGrade) ? profile.currentGrade : "",
|
||||
currentSemester: gradesForStage(val).includes(profile.currentGrade) ? profile.currentSemester : "",
|
||||
})}
|
||||
>
|
||||
<SelectTrigger>
|
||||
<SelectValue placeholder={t.auth?.selectStage || "Select Stage"} />
|
||||
@@ -146,6 +166,50 @@ export function AccountSettings() {
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{profile.educationStage && gradesForStage(profile.educationStage).length > 0 && (
|
||||
<div className="grid grid-cols-1 sm:grid-cols-2 gap-4">
|
||||
<div className="space-y-2">
|
||||
<Label>{t.settings?.account?.currentGrade || "Current Grade & Semester"}</Label>
|
||||
<Select
|
||||
value={profile.currentGrade || ""}
|
||||
onValueChange={(val) => setProfile({ ...profile, currentGrade: val, currentSemester: val ? (profile.currentSemester || '上') : "" })}
|
||||
>
|
||||
<SelectTrigger>
|
||||
<SelectValue placeholder={t.settings?.account?.selectGrade || "Select Grade"} />
|
||||
</SelectTrigger>
|
||||
<SelectContent>
|
||||
{gradesForStage(profile.educationStage).map((grade) => (
|
||||
<SelectItem key={grade} value={grade}>{grade}</SelectItem>
|
||||
))}
|
||||
</SelectContent>
|
||||
</Select>
|
||||
</div>
|
||||
{profile.currentGrade && (
|
||||
<div className="space-y-2">
|
||||
<Label>{t.settings?.account?.selectSemester || "Select Semester"}</Label>
|
||||
<Select
|
||||
value={profile.currentSemester || ""}
|
||||
onValueChange={(val) => setProfile({ ...profile, currentSemester: val })}
|
||||
>
|
||||
<SelectTrigger>
|
||||
<SelectValue placeholder={t.settings?.account?.selectSemester || "Select Semester"} />
|
||||
</SelectTrigger>
|
||||
<SelectContent>
|
||||
<SelectItem value="上">{t.settings?.account?.firstSemester || "1st Semester"}</SelectItem>
|
||||
<SelectItem value="下">{t.settings?.account?.secondSemester || "2nd Semester"}</SelectItem>
|
||||
</SelectContent>
|
||||
</Select>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
)}
|
||||
|
||||
{profile.currentGrade && profile.currentSemester && (
|
||||
<p className="text-xs text-muted-foreground -mt-2">
|
||||
{t.settings?.account?.gradeAppliedHint || "New questions will default to this grade. You can also configure AI grade recognition in General Settings."}
|
||||
</p>
|
||||
)}
|
||||
|
||||
<div className="space-y-3 pt-2 border-t">
|
||||
<div className="space-y-2">
|
||||
<Label>{t.settings?.account?.changePassword || "Change Password (Leave empty to keep)"}</Label>
|
||||
|
||||
@@ -2,3 +2,25 @@
|
||||
export const GRADE_NAMES = ['一年级', '二年级', '三年级', '四年级', '五年级', '六年级', '初一', '初二', '初三', '高一', '高二', '高三', '大一', '大二', '大三', '大四'] as const;
|
||||
|
||||
export const GRADE_SEMESTERS = GRADE_NAMES.flatMap((grade) => [`${grade}上`, `${grade}下`]);
|
||||
|
||||
/** 各教育阶段对应的年级名列表(索引区间,与 GRADE_NAMES 对齐) */
|
||||
export const STAGE_GRADE_RANGES: Record<string, { start: number; end: number }> = {
|
||||
primary: { start: 0, end: 6 },
|
||||
junior_high: { start: 6, end: 9 },
|
||||
senior_high: { start: 9, end: 12 },
|
||||
university: { start: 12, end: 16 },
|
||||
};
|
||||
|
||||
/** 某学段下的全部年级名 */
|
||||
export function gradesForStage(educationStage: string): string[] {
|
||||
const range = STAGE_GRADE_RANGES[educationStage];
|
||||
if (!range) return [];
|
||||
return GRADE_NAMES.slice(range.start, range.end);
|
||||
}
|
||||
|
||||
/** 从年级学期值(如「四年级上」「初一下」)解析出年级名和学期 */
|
||||
export function parseGradeSemester(value: string): { grade: string; semester: '上' | '下' } | null {
|
||||
if (value.endsWith('上')) return { grade: value.slice(0, -1), semester: '上' };
|
||||
if (value.endsWith('下')) return { grade: value.slice(0, -1), semester: '下' };
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -268,7 +268,10 @@ export const translations = {
|
||||
dialog: {
|
||||
stageLabel: "Stage",
|
||||
subjectLabel: "Subject",
|
||||
scopeHint: "Stage and subject cannot be changed after creation. AI picks knowledge tags only from this stage and subject.",
|
||||
tagSetLabel: "Tag System",
|
||||
tagSetDefault: "Built-in",
|
||||
tagSetNames: { cnm: "People's Education Press Curriculum Standard" } as Record<string, string>,
|
||||
scopeHint: "Stage, subject and tag system cannot be changed after creation. AI picks knowledge tags only from this scope and tag system.",
|
||||
title: "Create New Notebook",
|
||||
desc: "Create separate notebooks for different subjects or chapters",
|
||||
nameLabel: "Notebook Name",
|
||||
@@ -524,6 +527,12 @@ export const translations = {
|
||||
account: {
|
||||
changePassword: "Change Password (Leave empty to keep)",
|
||||
update: "Update Profile",
|
||||
currentGrade: "Current Grade & Semester",
|
||||
selectGrade: "Select Grade",
|
||||
selectSemester: "Select Semester",
|
||||
firstSemester: "1st Semester",
|
||||
secondSemester: "2nd Semester",
|
||||
gradeAppliedHint: "New questions will default to this grade. You can also configure AI grade recognition in General Settings.",
|
||||
},
|
||||
ai: {
|
||||
anthropicBaseUrlHint: "Leave empty for the official API. For compatible services enter the base URL without /v1 (e.g. https://api.example.com/anthropic).",
|
||||
@@ -1615,7 +1624,10 @@ export const translations = {
|
||||
dialog: {
|
||||
stageLabel: "学段",
|
||||
subjectLabel: "学科",
|
||||
scopeHint: "学段和学科创建后不可修改,AI 只会从该学段、该学科的知识点中选择标签。",
|
||||
tagSetLabel: "标签体系",
|
||||
tagSetDefault: "内置体系",
|
||||
tagSetNames: { cnm: "人教版课标体系" } as Record<string, string>,
|
||||
scopeHint: "学段、学科和标签体系创建后不可修改,AI 只会从该范围内选择知识点标签。",
|
||||
title: "创建新错题本",
|
||||
desc: "为不同科目或章节创建独立的错题本",
|
||||
nameLabel: "错题本名称",
|
||||
@@ -1871,6 +1883,12 @@ export const translations = {
|
||||
account: {
|
||||
changePassword: "修改密码 (留空不修改)",
|
||||
update: "更新个人信息",
|
||||
currentGrade: "当前年级学期",
|
||||
selectGrade: "选择年级",
|
||||
selectSemester: "选择学期",
|
||||
firstSemester: "上学期",
|
||||
secondSemester: "下学期",
|
||||
gradeAppliedHint: "新录入的错题将默认使用该年级,也可在常规设置中配置 AI 年级识别。",
|
||||
},
|
||||
ai: {
|
||||
anthropicBaseUrlHint: "留空使用官方接口;兼容服务请填写不含 /v1 的地址(如 https://api.example.com/anthropic)。",
|
||||
|
||||
Reference in New Issue
Block a user