PageSourceSearch

https://hocthongminh.ai/assets/ExamShufflePage-BLfKzNBN.js

js hocthongminh.ai collected 2026-10-05 14:37:38 UTC 16,636 bytes, 9 lines download raw bytes

1import{z as ne,f as ie,u as oe,g as le,r as a,t as w,j as e}from"./index-OK2gbu1I.js";import{T as de}from"./index-TSPXMuz7.js";import{A as ce}from"./AssignExamModal-Bn9-xxxC.js";import{f as me}from"./masterExamCache-CN_2i3Rv.js";import{T as he}from"./TeacherPageHeader-CJ2vvyfp.js";import"./useUserStore-BSlQ88Ks.js";import"./react-DIZE1BA-.js";import"./LanguageSwitcher-BREZ6Md_.js";import"./useTranslation-D4COAfGu.js";import"./apiErrorMessage-C2ePQ9QN.js";const ue=3e3,A="ABCDEFGH";function xe(n){if(!(!n.options||n.options.length===0))return n.options.map((g,h)=>`${A[h]||h+1}. ${g.content||""}`)}function ge(n){const g=n.options||[],h=g.findIndex(y=>y.isCorrect);if(h>=0)return A[h]||String(h+1);const l=(n.correctAnswer||"").trim();if(!l)return;if(l.length===1&&A.includes(l.toUpperCase()))return l.toUpperCase();const d=g.findIndex(y=>(y.content||"").trim()===l);return d>=0?A[d]||String(d+1):l}function Ce(){var J;const{blueprintId:n}=ne(),[g]=ie(),h=oe(),{user:l}=le(),d=g.get("variantId"),[y,X]=a.useState(null),j=d&&Number(d)>0?d:y;a.useEffect(()=>{if(d&&Number(d)>0||!n)return;let t=!1;return me(n).then(r=>{t||X(r!=null&&r.variantId?String(r.variantId):null)}),()=>{t=!0}},[d,n]);const[q,U]=a.useState(4),[u,H]=a.useState([]),[k,O]=a.useState(null),[p,R]=a.useState(!1),Q=a.useRef(null),[pe,Y]=a.useState(null),[i,T]=a.useState(null),[I,L]=a.useState(!1),[z,b]=a.useState(null),[F,K]=a.useState(!1),[E,Z]=a.useState(!1),[ee,G]=a.useState(!1),[c,te]=a.useState(null),m=a.useRef();a.useEffect(()=>()=>{m.current&&clearInterval(m.current)},[]),a.useEffect(()=>{n&&w.get(`/v1/exam-blueprints/${n}`).then(t=>{t!=null&&t.data&&te(t.data)}).catch(()=>{})},[n]);const re=async()=>{var t;if(!j){b('Chưa xác định được đề gốc để trộn. Hãy quay lại trang "Xem lại đề gốc" và sinh đề gốc trước.');return}L(!0),b(null),H([]),T(null);try{const r=l!=null&&l.id?Number(l.id):0,s=await w.post(`/v1/exam-blueprints/${j}/shuffle?variantCount=${q}&generatedBy=${r}`);if((t=s==null?void 0:s.data)!=null&&t.jobId){const o=s.data.jobId;Y(o),T({jobId:o,status:"PENDING",progressPercent:0}),se(o)}}catch(r){b(r instanceof Error?r.message:"Không thể khởi tạo job trộn đề"),L(!1)}},se=a.useCallback(t=>{m.current&&clearInterval(m.current),m.current=setInterval(async()=>{var r;try{const s=await w.get(`/v1/exam-blueprints/shuffle-jobs/${t}`),o=s==null?void 0:s.data;if(!o)return;const x={jobId:t,status:o.status,progressPercent:o.progress,variants:o.variants?JSON.parse(o.variants):void 0,errorMessage:o.errorMessage};if(T(x),x.status==="COMPLETED"){if(clearInterval(m.current),m.current=void 0,L(!1),x.variants&&x.variants.length>0){const _=await Promise.all(x.variants.map(async P=>{const C=P.questionIds?JSON.parse(P.questionIds):[];let V=[];if(C.length>0)try{const S=await w.post("/questions/by-ids",{ids:C}),M=(S==null?void 0:S.data)||[],$=new Map(M.map(f=>[Number(f.id),f]));V=C.map((f,B)=>{const v=$.get(Number(f));return v?{originalIndex:B,id:String(v.id),content:v.content||`Câu hỏi ${B+1}`,options:xe(v),correctAnswer:ge(v),questionType:v.questionType||"mcq"}:{originalIndex:B,id:String(f),content:`[Không tải được câu hỏi #${f}]`,questionType:"mcq"}})}catch{b("Không tải được nội dung câu hỏi của các mã đề. Vui lòng thử lại."),V=C.map((M,$)=>({originalIndex:$,id:String(M),content:`[Không tải được câu hỏi #${M}]`,questionType:"mcq"}))}return{code:P.variantCode,questions:V}}));H(_),O(((r=_[0])==null?void 0:r.code)||null)}}else x.status==="FAILED"&&(clearInterval(m.current),m.current=void 0,L(!1),b(x.errorMessage||"Trộn đề thất bại"))}catch{}},ue)},[]),ae=async()=>{if(!(!(i!=null&&i.variants)||i.variants.length===0)){K(!0);try{for(const t of i.variants){const r=t.questionIds?JSON.parse(t.questionIds):[];if(r.length===0)continue;const s=r.map(o=>({questionId:o}));await w.post("/practice-sets",{title:`${(c==null?void 0:c.name)||"Đề thi"} — Mã ${t.variantCode}`,description:`Mã đề ${t.variantCode} (${t.questionCount} câu) — tạo từ trộn đề`,subjectId:c==null?void 0:c.subjectId,gradeId:c==null?void 0:c.gradeId,questionIds:s,exerciseCategory:"ASSESSMENT",type:"EXAM_SIMULATION",visibility:"PRIVATE"})}Z(!0)}catch(t){b(t instanceof Error?t.message:"Không thể lưu vào bài tập đánh giá")}finally{K(!1)}}},W=t=>{const r=document.createElement("style");r.id="print-style-override",r.textContent=`
2            @media print {
3                body * { visibility: hidden !important; }
4                .print-area, .print-area * { visibility: visible !important; }
5                .print-area { position: absolute; left: 0; top: 0; width: 100%; }
6                .no-print { display: none !important; }
7                @page { size: A4; margin: 15mm; }
8            }
9        `,document.head.appendChild(r);const s=document.getElementById(t?`variant-${t}`:"answer-key-print");s&&s.classList.add("print-area"),window.print(),s&&s.classList.remove("print-area"),r.remove()},N=u.find(t=>t.code===k),D=()=>
9{if(!i)return"Đang khởi tạo...";switch(i.status){case"PENDING":return"Đang chờ xử lý...";case"PROCESSING":return`Đang trộn đề... ${i.progressPercent}%`;default:return"Đang xử lý..."}};return e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{children:[e.jsxs("button",{onClick:()=>h(de.examReview(n||"")),className:"inline-flex items-center gap-1 text-sm text-gray-500 dark:text-gray-400 hover:text-teal-600 dark:hover:text-teal-400 mb-2",children:[e.jsx("svg",{className:"w-4 h-4",fill:"none",viewBox:"0 0 24 24",strokeWidth:2,stroke:"currentColor",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M15.75 19.5L8.25 12l7.5-7.5"})}),"Quay lại xem đề gốc"]}),e.jsx(he,{title:"Trộn Đề Thi",subtitle:"Hệ thống sẽ tự động trộn thứ tự câu hỏi trắc nghiệm và đáp án để sinh ra nhiều mã đề khác nhau. Phần tự luận giữ nguyên thứ tự, không trộn."})]}),e.jsxs("div",{className:"tdash-panel",children:[e.jsx("h3",{className:"font-semibold text-gray-900 dark:text-white mb-4",children:"Cấu hình trộn đề"}),e.jsxs("div",{className:"flex flex-wrap items-end gap-4",children:[e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium text-gray-700 dark:text-gray-300 mb-1",children:"Số lượng mã đề"}),e.jsx("input",{type:"number",min:2,max:20,value:q,onChange:t=>U(Math.max(2,Math.min(20,Number(t.target.value)))),disabled:I,className:"w-28 px-3 py-2 rounded-lg border border-gray-300 dark:border-gray-600 bg-white dark:bg-gray-700 text-gray-900 dark:text-white text-center font-semibold focus:ring-2 focus:ring-teal-500 focus:border-teal-500 outline-none disabled:opacity-50"})]}),e.jsx("button",{onClick:re,disabled:I||!j,title:j?void 0:'Chưa có đề gốc — hãy sinh đề gốc ở trang "Xem lại đề gốc" trước',className:"inline-flex items-center gap-2 px-6 py-2.5 bg-teal-600 hover:bg-teal-700 disabled:opacity-60 disabled:cursor-not-allowed text-white font-medium rounded-lg transition-colors shadow-sm",children:I?e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"w-5 h-5 border-2 border-white border-t-transparent rounded-full animate-spin"}),D()]}):e.jsxs(e.Fragment,{children:[e.jsx("svg",{className:"w-5 h-5",fill:"none",viewBox:"0 0 24 24",strokeWidth:2,stroke:"currentColor",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M7.5 21L3 16.5m0 0L7.5 12M3 16.5h13.5m0-13.5L21 7.5m0 0L16.5 12M21 7.5H7.5"})}),"Trộn Đề"]})})]}),I&&i&&e.jsxs("div",{className:"mt-4",children:[e.jsxs("div",{className:"flex items-center justify-between text-sm mb-1",children:[e.jsx("span",{className:"text-gray-600 dark:text-gray-400",children:D()}),e.jsxs("span",{className:"text-teal-600 dark:text-teal-400 font-medium",children:[i.progressPercent,"%"]})]}),e.jsx("div",{className:"w-full h-2 bg-gray-200 dark:bg-gray-700 rounded-full overflow-hidden",children:e.jsx("div",{className:"h-full bg-teal-500 rounded-full transition-all duration-500",style:{width:`${i.progressPercent}%`}})})]}),!j&&e.jsxs("div",{className:"mt-4 bg-amber-50 dark:bg-amber-900/20 border border-amber-200 dark:border-amber-700 rounded-lg p-3 text-sm text-amber-700 dark:text-amber-300",children:["Chưa xác định được đề gốc để trộn. Hãy quay lại trang ",e.jsx("strong",{children:"Xem lại đề gốc"}),', sinh đề gốc rồi bấm "Tiếp tục — Trộn đề".']}),z&&e.jsx("div",{className:"mt-4 bg-red-50 dark:bg-red-900/20 border border-red-200 dark:border-red-800 rounded-lg p-3 text-sm text-red-700 dark:text-red-400",children:z})]}),u.length>0&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"tdash-panel tdash-panel--flush",children:[e.jsxs("div",{className:"px-5 py-3 border-b border-gray-200 dark:border-gray-700 flex items-center justify-between flex-wrap gap-2",children:[e.jsxs("div",{className:"flex items-center gap-1 overflow-x-auto",children:[u.map(t=>e.jsxs("button",{onClick:()=>{O(t.code),R(!1)},className:`px-3 py-1.5 text-sm font-medium rounded-lg transition-colors whitespace-nowrap ${k===t.code&&!p?"bg-teal-600 text-white":"text-gray-600 dark:text-gray-400 hover:bg-gray-100 dark:hover:bg-gray-700"}`,children:["Mã ",t.code]},t.code)),e.jsx("button",{onClick:()=>R(!0),className:`px-3 py-1.5 text-sm font-medium rounded-lg transition-colors whitespace-nowrap ${p?"bg-vi
9olet-600 text-white":"text-violet-600 dark:text-violet-400 hover:bg-violet-50 dark:hover:bg-violet-900/20"}`,children:"Đáp Án"})]}),e.jsxs("div",{className:"flex gap-2 no-print",children:[!p&&k&&e.jsxs("button",{onClick:()=>W(k),className:"inline-flex items-center gap-1.5 px-3 py-1.5 text-sm font-medium text-teal-600 dark:text-teal-400 hover:bg-teal-50 dark:hover:bg-teal-900/20 border border-teal-200 dark:border-teal-800 rounded-lg transition-colors",children:[e.jsx("svg",{className:"w-4 h-4",fill:"none",viewBox:"0 0 24 24",strokeWidth:2,stroke:"currentColor",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M6.72 13.829c-.24.03-.48.062-.72.096m.72-.096a42.415 42.415 0 0110.56 0m-10.56 0L6.34 18m10.94-4.171c.24.03.48.062.72.096m-.72-.096L17.66 18m0 0l.229 2.523a1.125 1.125 0 01-1.12 1.227H7.231c-.662 0-1.18-.568-1.12-1.227L6.34 18m11.318 0h1.091A2.25 2.25 0 0021 15.75V9.456c0-1.081-.768-2.015-1.837-2.175a48.055 48.055 0 00-1.913-.247M6.34 18H5.25A2.25 2.25 0 013 15.75V9.456c0-1.081.768-2.015 1.837-2.175a48.041 48.041 0 011.913-.247m10.5 0a48.536 48.536 0 00-10.5 0m10.5 0V3.375c0-.621-.504-1.125-1.125-1.125h-8.25c-.621 0-1.125.504-1.125 1.125v3.659M18.75 12h.008v.008h-.008V12zm-2.25 0h.008v.008H16.5V12z"})}),"In mã đề ",k]}),p&&e.jsxs("button",{onClick:()=>W(),className:"inline-flex items-center gap-1.5 px-3 py-1.5 text-sm font-medium text-violet-600 dark:text-violet-400 hover:bg-violet-50 dark:hover:bg-violet-900/20 border border-violet-200 dark:border-violet-800 rounded-lg transition-colors",children:[e.jsx("svg",{className:"w-4 h-4",fill:"none",viewBox:"0 0 24 24",strokeWidth:2,stroke:"currentColor",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M6.72 13.829c-.24.03-.48.062-.72.096m.72-.096a42.415 42.415 0 0110.56 0m-10.56 0L6.34 18m10.94-4.171c.24.03.48.062.72.096m-.72-.096L17.66 18m0 0l.229 2.523a1.125 1.125 0 01-1.12 1.227H7.231c-.662 0-1.18-.568-1.12-1.227L6.34 18m11.318 0h1.091A2.25 2.25 0 0021 15.75V9.456c0-1.081-.768-2.015-1.837-2.175a48.055 48.055 0 00-1.913-.247M6.34 18H5.25A2.25 2.25 0 013 15.75V9.456c0-1.081.768-2.015 1.837-2.175a48.041 48.041 0 011.913-.247m10.5 0a48.536 48.536 0 00-10.5 0m10.5 0V3.375c0-.621-.504-1.125-1.125-1.125h-8.25c-.621 0-1.125.504-1.125 1.125v3.659M18.75 12h.008v.008h-.008V12zm-2.25 0h.008v.008H16.5V12z"})}),"In Bảng Đáp Án"]})]})]}),!p&&N&&e.jsxs("div",{id:`variant-${N.code}`,className:"p-5",ref:Q,children:[e.jsxs("div",{className:"hidden print:block mb-6 text-center",children:[e.jsxs("h2",{className:"text-lg font-bold",children:["ĐỀ KIỂM TRA - MÃ ĐỀ: ",N.code]}),e.jsxs("p",{className:"text-sm mt-1",children:["Thời gian: 45 phút — Tổng: ",N.questions.length," câu"]}),e.jsx("hr",{className:"mt-3 border-gray-400"})]}),e.jsx("div",{className:"space-y-3",children:N.questions.map((t,r)=>e.jsxs("div",{className:"p-3 rounded-lg border border-gray-100 dark:border-gray-700",children:[e.jsxs("p",{className:"text-sm text-gray-900 dark:text-gray-100 font-medium",children:[e.jsxs("span",{className:"text-teal-600 dark:text-teal-400 font-bold",children:["Câu ",r+1,"."]})," ",t.content]}),t.options&&e.jsx("div",{className:"mt-1.5 grid grid-cols-2 gap-x-4 gap-y-1",children:t.options.map((s,o)=>e.jsx("span",{className:"text-sm text-gray-700 dark:text-gray-300",children:s},o))})]},t.id+r))})]}),p&&e.jsxs("div",{id:"answer-key-print",className:"p-5",children:[e.jsxs("div",{className:"hidden print:block mb-6 text-center",children:[e.jsx("h2",{className:"text-lg font-bold",children:"BẢNG ĐÁP ÁN"}),e.jsx("hr",{className:"mt-3 border-gray-400"})]}),e.jsx("div",{className:"space-y-6",children:u.map(t=>e.jsxs("div",{children:[e.jsxs("h4",{className:"font-semibold text-gray-900 dark:text-white mb-2 flex items-center gap-2",children:[e.jsx("span",{className:"inline-flex items-center justify-center w-7 h-7 rounded-full bg-violet-100 dark:bg-violet-900/30 text-violet-700 dark:text-violet-400 text-xs font-bold",children:t.code}),"Mã đề ",t.code]}),e.jsx("div",{className:"overflow-x-auto",children:e.jsxs("table",{className:"w-full text-sm border border-gray-200 dark:border-gray-700 rounded-lg overflow-hidden",children:[e.jsx("thead",{children:e.jsx("tr",{className:"bg-gray-50 dark:bg-gray-800/50",children:t.questions.map((r,s)=>e.jsx("th",{className:"px-2 py-1.5 text-center text-gray-600 dark:text-gray-400 font-medium border-r border-gray-200 dark:border-gray-700 last:border-r-0",children:s+1},s))})}),e.jsx("tbody",{children:e.jsx("tr",{children:t.questions.map((r,s)=>e.jsx("td",{className:"px-2 py-1.5 text-center font-bold text-teal-600 dar
9k:text-teal-400 border-r border-gray-200 dark:border-gray-700 last:border-r-0",children:r.correctAnswer||"—"},s))})})]})})]},t.code))})]})]}),e.jsx("div",{className:"tdash-panel",children:e.jsxs("div",{className:"flex flex-col sm:flex-row sm:items-center sm:justify-between gap-3",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"font-semibold text-gray-900 dark:text-white",children:"Lưu vào Bài tập đánh giá"}),e.jsxs("p",{className:"text-sm text-gray-500 dark:text-gray-400 mt-0.5",children:["Lưu tất cả ",u.length," mã đề vào danh sách bài tập đánh giá để giao cho học sinh"]})]}),e.jsxs("button",{onClick:()=>G(!0),className:"inline-flex items-center gap-2 px-5 py-2.5 text-sm font-medium text-teal-700 dark:text-teal-300 hover:bg-teal-50 dark:hover:bg-teal-900/20 border border-teal-200 dark:border-teal-800 rounded-lg transition-colors",children:[e.jsx("svg",{className:"w-4 h-4",fill:"none",viewBox:"0 0 24 24",strokeWidth:2,stroke:"currentColor",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M6 12L3.269 3.126A59.768 59.768 0 0121.485 12 59.77 59.77 0 013.27 20.876L5.999 12zm0 0h7.5"})}),"Giao đề cho lớp"]}),e.jsx("button",{onClick:ae,disabled:F||E,className:`inline-flex items-center gap-2 px-5 py-2.5 text-sm font-medium rounded-lg transition-colors shadow-sm ${E?"bg-emerald-600 text-white":"bg-orange-600 hover:bg-orange-700 text-white"} disabled:opacity-60`,children:F?e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"w-4 h-4 border-2 border-white border-t-transparent rounded-full animate-spin"}),"Đang lưu..."]}):E?e.jsxs(e.Fragment,{children:[e.jsx("svg",{className:"w-4 h-4",fill:"none",viewBox:"0 0 24 24",strokeWidth:2,stroke:"currentColor",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M9 12.75L11.25 15 15 9.75M21 12a9 9 0 11-18 0 9 9 0 0118 0z"})}),"Đã lưu ",u.length," mã đề vào BTĐG"]}):e.jsxs(e.Fragment,{children:[e.jsx("svg",{className:"w-4 h-4",fill:"none",viewBox:"0 0 24 24",strokeWidth:2,stroke:"currentColor",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M12 10.5v6m3-3H9m4.06-7.19l-2.12-2.12a1.5 1.5 0 00-1.061-.44H4.5A2.25 2.25 0 002.25 6v12a2.25 2.25 0 002.25 2.25h15A2.25 2.25 0 0021.75 18V9a2.25 2.25 0 00-2.25-2.25h-5.379a1.5 1.5 0 01-1.06-.44z"})}),"Lưu tất cả vào Bài tập đánh giá"]})})]})})]}),e.jsx(ce,{open:ee,onClose:()=>G(!1),examTitle:`Đề thi trộn — ${u.length} mã đề`,blueprintId:Number(n),variantIds:(J=i==null?void 0:i.variants)==null?void 0:J.map(t=>t.variantId)})]})}export{Ce as default};

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.