aiPptContent.ts 2.1 KB

123456789101112131415161718192021222324252627
  1. import type { AiCoursewarePage } from "@/api/aiCourseware"
  2. // 资源身份、静态谱图与装饰配图分别判断,不能用封面图冒充曲谱。
  3. export const usableResourceUrl = (value?: string) => /^(https?:\/\/|data:(image|audio|video)\/)/i.test(value || "")
  4. export const scoreBinding = (page: AiCoursewarePage) => (page.resourceBindings || [])
  5. .find(item => item.verified === true && item.resourceType === "MUSIC" && Boolean(item.resourceId))
  6. export const audioBindings = (page: AiCoursewarePage) => (page.resourceBindings || [])
  7. .filter(item => item.verified === true && item.resourceType === "SONG" && usableResourceUrl(item.contentUrl))
  8. export const isScorePage = (page: AiCoursewarePage) => /melody|score/.test(page.type || "") || Boolean(scoreBinding(page))
  9. export const needsAudio = (page: AiCoursewarePage) => /listen|phrase_sing|expressive_sing/.test(page.type || "") ||
  10. (page.resourceBindings || []).some(item => item.required && item.resourceType === "SONG")
  11. // 只识别明确的教案表述,保留“观察图片”“跟老师唱”等有效学生指令。
  12. export const isTeacherFacingText = (text?: string) => /(?:教师|老师)(?:讲述|提问|引导|指导|组织|巡视|示范)|(?:引导|指导|组织)学生|(?:激发|产生|建立)(?:学生)?(?:兴趣|期待|好奇)|学习表现[::]|复述课后任务要求|回顾并口头总结本课所学/.test(text || "")
  13. export function teacherFacingTexts(page: AiCoursewarePage): string[] {
  14. return [page.studentContent?.headline, page.classroomAction?.studentTask, page.subtitle,
  15. ...(page.studentContent?.points || []), ...(page.bullets || [])]
  16. .filter((text): text is string => Boolean(text) && isTeacherFacingText(text))
  17. }
  18. export function studentTexts(page: AiCoursewarePage): string[] {
  19. return [page.title, page.studentContent?.headline, page.classroomAction?.studentTask,
  20. ...(page.studentContent?.points?.length ? page.studentContent.points : page.bullets || []),
  21. page.interaction?.question, ...(page.interaction?.options || [])]
  22. .map(text => String(text || "").trim()).filter(text => Boolean(text) && !isTeacherFacingText(text))
  23. }