aiPptDialogTest.html 5.1 KB

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