aiPptDialogTest.html 5.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. <!doctype html>
  2. <html lang="zh-CN"><head><meta charset="UTF-8"><title>AI课件流程回归</title></head><body><div id="app"></div>
  3. <script type="module">
  4. import { createApp, h, ref, nextTick } from "vue"
  5. import { createRouter, createMemoryHistory } from "vue-router"
  6. import { store, useSlidesStore } from "/src/store/index.ts"
  7. import "/src/router/index.ts"
  8. import { httpAxios } from "/src/api/ApiInstance.ts"
  9. import { setToken } from "/src/libs/auth.ts"
  10. import AiDialog from "/src/views/Editor/EditorHeader/AiCoursewareDialog.vue"
  11. import { inspectAiPptResources } from "/src/utils/aiPptResources.ts"
  12. import { draftKey, loadAiDraft, saveAiDraft } from "/src/utils/aiCoursewareDraft.ts"
  13. import "/src/assets/styles/global.scss"
  14. import "/src/assets/styles/elementTheme.scss"
  15. import "/src/assets/styles/prosemirror.scss"
  16. // 所有业务接口使用本地夹具,不调用生成服务,不修改任何线上课件。
  17. const scenario = new URLSearchParams(location.search).get("scenario") || "normal"
  18. setToken(`local-ai-ppt-regression-${scenario}`)
  19. const generated = ref(0)
  20. const repairs = ref(0)
  21. const historicalPolls = ref(0)
  22. let repaired = false
  23. const resourceCheck = ref("检查中")
  24. const runtimeError = ref("")
  25. const types = ["cover", "scene_intro", "objectives", "music_knowledge", "rhythm_practice", "performance_activity", "practice_check", "creative_activity", "summary"]
  26. const layouts = ["cover_scene", "hero_focus", "objectives", "split_content", "diagram_focus", "activity", "text_focus", "activity", "summary"]
  27. const outline = {
  28. title: "声音强弱课堂测试", gradeName: "一年级", textbookName: "本地测试教材", chapterName: "声音的强弱", courseType: "music", templateId: "ethnic-flower",
  29. textbookResearch: { exactMatch: true, confidence: "HIGH", contentSummary: "仅用于软件回归的教学夹具", teachingObjectives: ["能用声音表现强弱"], sources: [{ title: "本地测试依据(非真实教材认证)", url: "https://example.com/test-only" }] },
  30. pages: types.map((type, index) => ({ pageNo:index+1, type, title: index === 0 ? "声音强弱课堂测试" : `任务${index}:表现声音强弱`,
  31. studentContent:{ points:["用声音表现强弱变化", "说出判断的理由"] }, durationMinutes:index===0?8:4, objectiveIds:["1"],
  32. teachingPurpose:"表现声音强弱", learningEvidence:"能表现强弱并说明理由", speakerNotes:"示范后请学生练习,根据表现及时反馈。",
  33. classroomAction:{studentTask:"完成声音强弱挑战", teacherInstruction:"示范强弱对比,邀请学生练习后互评"},
  34. interaction:type==="practice_check"?{question:"哪种方式声音更轻?",options:["轻声哼唱","大声呼喊"],answer:"轻声哼唱",explanation:"根据声音强弱判断"}:undefined,
  35. visualPlan:{layout:layouts[index]}, imageKeywords:[] }))
  36. }
  37. if (scenario === "failed-resume") {
  38. const key = await draftKey("local-ai-ppt-regression", "TEACHER")
  39. if (!await loadAiDraft(key)) await saveAiDraft({
  40. key, updatedAt: Date.now(), outline: structuredClone(outline), taskId: "historical-failed-task", extraPrompt: "",
  41. preferences: { minPages: 9, maxPages: 12, lessonMinutes: 40 }
  42. })
  43. }
  44. httpAxios.axioseRquest = async config => {
  45. let data
  46. if (config.url.endsWith("/outline")) data = structuredClone(outline)
  47. else if (config.url.endsWith("/generate")) {
  48. generated.value++
  49. if (config.data.repairOnly) { repairs.value++; repaired=true }
  50. data={taskId:"local-task",status:"PENDING",progress:0}
  51. }
  52. else if (config.url.endsWith("/result")) {
  53. data={outline:structuredClone(outline),context:{resources:[]}}
  54. if (scenario === "draft" && !repaired) {
  55. data.outline.pages.forEach(page => page.objectiveIds=[])
  56. data.reviewMessage="声音强弱的练习与评价尚未完整关联"
  57. }
  58. }
  59. else if (config.url.endsWith("/task/historical-failed-task")) {
  60. historicalPolls.value++
  61. data={taskId:"historical-failed-task",status:"FAILED",progress:50,message:"教学目标1缺少对应实践或评价任务"}
  62. }
  63. else if (config.url.includes("/task/")) data={taskId:"local-task",status:scenario === "draft" && !repaired ? "DRAFT" : "DONE",progress:100}
  64. else throw new Error("测试禁止未声明的业务请求")
  65. return {data:{code:200,data}}
  66. }
  67. const router=createRouter({history:createMemoryHistory(),routes:[{path:"/",component:{render:()=>null}}]})
  68. await router.push("/?id=local-ai-ppt-regression")
  69. await router.isReady()
  70. const app=createApp({setup(){
  71. const visible=ref(false)
  72. const slidesStore=useSlidesStore()
  73. nextTick(()=>{visible.value=true})
  74. return ()=>h("main",[
  75. runtimeError.value ? h("pre", runtimeError.value) : null,
  76. h("p",{id:"test-status"},`生成请求次数:${generated.value};完善请求:${repairs.value};历史失败任务查询:${historicalPolls.value};已应用页数:${slidesStore.slides.length};资源检查:${resourceCheck.value}`),
  77. h("button",{onClick:()=>{visible.value=true}},"打开AI课件"),
  78. h(AiDialog,{visible:visible.value,"onUpdate:visible":value=>{visible.value=value}})
  79. ])
  80. }})
  81. app.config.errorHandler = error => { runtimeError.value=String(error?.stack || error) }
  82. app.use(store).use(router).mount("#app")
  83. // 使用浏览器真实图片解码验证损坏资源阻断及谱图等比缩放。
  84. const svg='data:image/svg+xml;charset=utf-8,'+encodeURIComponent('<svg xmlns="http://www.w3.org/2000/svg" width="400" height="100"><rect width="400" height="100" fill="white"/></svg>')
  85. const score={id:"image",type:"image",src:svg,left:0,top:0,width:200,height:200}
  86. const slides=[{elements:[score,{id:"broken",type:"image",src:"data:image/png;base64,invalid",left:0,top:0,width:100,height:100}]}]
  87. const issues=await inspectAiPptResources({pages:[{resourceBindings:[{resourceType:"MUSIC",scoreImageUrl:svg}]}]},slides)
  88. resourceCheck.value=issues.length===1&&score.width===200&&score.height===50&&score.top===75?"通过(损坏图片阻断、谱图等比缩放)":"失败"
  89. </script></body></html>