import{_ as N}from"./ExamConfigEditor-wzeRd6Hm.js";import{d as C}from"./dataProvider-DCfw-Z8G.js";import{_ as I,j as f,o as m,w as i,d as s,l as v,q as k,t as l,v as d,S as T,z as w,B as p,i as g,C as x,y as u,a6 as R,A as S,F as z,G as L,a7 as B,aE as A,aF as F,L as O,H as V,N as K,M as _,x as D,k as U}from"./index-UWNvEtdO.js";import{V as j,a as M}from"./VRow-DW6VnVhF.js";import{V as b}from"./VAlert-CihErmIR.js";import{V as E}from"./VChip-D39RDiPW.js";import{V as q}from"./VSkeletonLoader--4kBD8B1.js";import{V as G}from"./VTextField-DrEjs8Br.js";import{V as H}from"./VContainer-CX4odj8f.js";import"./VTooltip-Bbw60eT3.js";import"./VTextarea-DTZJ2fR2.js";import"./VMenu-Bugsew5u.js";import"./VDatePicker-Ch4pILAI.js";import"./axios-Co85_kZk.js";const P={name:"ExamScheduleManager",components:{ExamConfigEditor:N},data(){return{configs:[],loading:!1,error:"",success:"",renameDialog:!1,editDialog:!1,configToRename:null,editingConfig:null,newConfigName:"",renaming:!1,saving:!1}},async mounted(){await this.loadConfigs()},methods:{async initializeExampleData(){const n=[{id:"exam_example_001",examName:"期末考试安排",message:"请按时参加考试,携带学生证和身份证",examInfos:[{name:"数学",start:"2025/01/15 09:00",end:"2025/01/15 11:00"},{name:"英语",start:"2025/01/16 14:00",end:"2025/01/16 16:00"}]},{id:"exam_example_002",examName:"期中考试安排",message:"考试期间请保持安静",examInfos:[{name:"物理",start:"2025/01/20 10:00",end:"2025/01/20 12:00"},{name:"化学",start:"2025/01/21 14:00",end:"2025/01/21 16:00"}]},{id:"exam_example_003",examName:"模拟考试安排",message:"模拟考试,请认真对待",examInfos:[{name:"语文",start:"2025/01/25 09:00",end:"2025/01/25 11:30"}]}],e=n.map(r=>({id:r.id}));await C.saveData("es_list",e);for(let r of n){const c={...r};delete c.id,await C.saveData(`es_${r.id}`,c)}return n},async loadConfigs(){this.loading=!0,this.error="";try{const n=await C.loadData("es_list");if(n&&n&&n.length>0){this.configs=[];for(let e of n)try{const r=await C.loadData(`es_${e.id}`);r&&this.configs.push({id:e.id,...r})}catch(r){console.warn(`加载配置 es_${e.id} 失败:`,r)}}else this.configs=await this.initializeExampleData()}catch(n){this.error="加载配置列表失败: "+n.message,this.configs=[]}finally{this.loading=!1}},async createNewConfig(){var r,c;const n=Date.now().toString(),e={examName:"新考试配置",message:"请编辑此配置",room:U("server.classNumber")||"待定",examInfos:[{name:"科目1",start:"2025/08/29 16:27",end:"2025/08/29 17:27"}]};try{const t=await C.saveData(`es_${n}`,e);if(!t)throw new Error(((r=t.error)==null?void 0:r.message)||"保存失败");this.configs.push({id:n,...e});const a=this.configs.map(y=>({id:y.id})),h=await C.saveData("es_list",a);if(!h)throw new Error(((c=h.error)==null?void 0:c.message)||"更新列表失败");this.success="新配置创建成功";const o=this.configs.find(y=>y.id===n);o&&(this.editingConfig=o,this.editDialog=!0)}catch(t){this.error="创建配置失败: "+t.message}},showRenameDialog(n){this.configToRename=n,this.newConfigName=n.examName||`配置 ${n.id}`,this.renameDialog=!0},async renameConfig(){var n;if(!(!this.configToRename||!this.newConfigName)){this.renaming=!0;try{const e={examName:this.newConfigName,message:this.configToRename.message,examInfos:this.configToRename.examInfos},r=await C.saveData(`es_${this.configToRename.id}`,e);if(!r)throw new Error(((n=r.error)==null?void 0:n.message)||"保存失败");const c=this.configs.findIndex(t=>t.id===this.configToRename.id);c!==-1&&(this.configs[c].examName=this.newConfigName),this.success="配置重命名成功",this.renameDialog=!1,this.configToRename=null,this.newConfigName=""}catch(e){this.error="重命名配置失败: "+e.message}finally{this.renaming=!1}}},showEditDialog(n){this.editingConfig=n,this.editDialog=!0},closeEditDialog(){this.editDialog=!1,this.editingConfig=null,this.saving=!1},async saveConfigInDialog(){if(this.$refs.configEditor){this.saving=!0;try{await this.$refs.configEditor.saveConfig()}catch(n){console.error("保存配置失败:",n)}finally{this.saving=!1}}},onConfigSaved(){this.success="配置保存成功!",this.loadConfigs(),setTimeout(()=>{this.success=""},3e3)},onConfigError(n){this.error=n||"保存配置时发生错误",setTimeout(()=>{this.error=""},5e3)},onConfigOpened(){this.success="配置已在新窗口中打开",setTimeout(()=>{this.success=""},3e3)},onConfigDeleted(n){n.success?(this.success=n.message||"配置删除成功",this.editDialog=!1,this.loadConfigs()):this.error=n.message||"删除失败"}}},J={class:"d-flex align-center"},Q={class:"d-flex align-center"},W={class:"d-flex justify-space-between align-center mb-4"},X={class:"d-flex align-center"},Y={class:"d-flex align-center"},Z={class:"d-flex align-center mt-1"},$={class:"d-flex align-center"};function ee(n,e,r,c,t,a){const h=N;return m(),f(H,{class:"fill-height"},{default:i(()=>[s(j,null,{default:i(()=>[s(M,{cols:"12"},{default:i(()=>[s(v,{class:"elevation-12",border:""},{default:i(()=>[s(k,{class:"d-flex align-center primary lighten-1 white--text py-3 px-4"},{default:i(()=>[s(d,{color:"white",class:"mr-2"},{default:i(()=>[...e[6]||(e[6]=[l("mdi-calendar-check",-1)])]),_:1}),e[7]||(e[7]=l(" 考试看板 ",-1))]),_:1}),s(T,null,{default:i(()=>[...e[8]||(e[8]=[l(" 不只是考试看板。 ",-1)])]),_:1}),s(w,null,{default:i(()=>[t.error?(m(),f(b,{key:0,type:"error",class:"mb-4 mt-3 mx-2",variant:"tonal",border:"start",closable:"","onClick:close":e[0]||(e[0]=o=>t.error="")},{default:i(()=>[g("div",J,[s(d,{class:"mr-2"},{default:i(()=>[...e[9]||(e[9]=[l("mdi-alert-circle",-1)])]),_:1}),l(" "+x(t.error),1)])]),_:1})):p("",!0),t.success?(m(),f(b,{key:1,type:"success",class:"mb-4 mt-3 mx-2",variant:"tonal",border:"start",closable:"","onClick:close":e[1]||(e[1]=o=>t.success="")},{default:i(()=>[g("div",Q,[s(d,{class:"mr-2"},{default:i(()=>[...e[10]||(e[10]=[l("mdi-check-circle",-1)])]),_:1}),l(" "+x(t.success),1)])]),_:1})):p("",!0),g("div",W,[g("div",X,[s(u,{color:"primary","prepend-icon":"mdi-plus",class:"mr-2",onClick:a.createNewConfig},{default:i(()=>[...e[11]||(e[11]=[l(" 新建配置 ",-1)])]),_:1},8,["onClick"]),s(u,{color:"info","prepend-icon":"mdi-refresh",loading:t.loading,onClick:a.loadConfigs,variant:"outlined"},{default:i(()=>[...e[12]||(e[12]=[l(" 刷新 ",-1)])]),_:1},8,["loading","onClick"])]),t.configs.length>0?(m(),f(E,{key:0,color:"primary","prepend-icon":"mdi-format-list-numbered"},{default:i(()=>[l(x(t.configs.length)+" 个配置 ",1)]),_:1})):p("",!0)]),t.loading?(m(),f(v,{key:2,class:"my-4",outlined:""},{default:i(()=>[s(w,null,{default:i(()=>[s(q,{type:"list-item-avatar-two-line@3",class:"mx-auto"})]),_:1})]),_:1})):p("",!0),!t.loading&&t.configs.length>0?(m(),f(v,{key:3,class:"my-4",elevation:"1"},{default:i(()=>[s(k,{class:"d-flex align-center pa-4 bg-primary-lighten-5"},{default:i(()=>[s(d,{class:"mr-2"},{default:i(()=>[...e[13]||(e[13]=[l("mdi-format-list-bulleted",-1)])]),_:1}),e[14]||(e[14]=g("span",{class:"font-weight-bold"},"配置列表",-1))]),_:1}),s(R,null,{default:i(()=>[(m(!0),S(z,null,L(t.configs,o=>(m(),f(B,{key:o.id,class:"border-b",style:{cursor:"pointer"},onClick:y=>a.showEditDialog(o)},{prepend:i(()=>[s(O,{color:"primary",class:"mr-2"},{default:i(()=>[s(d,{color:"white"},{default:i(()=>[...e[15]||(e[15]=[l("mdi-calendar-text",-1)])]),_:1})]),_:1})]),append:i(()=>[g("div",$,[s(u,{icon:"mdi-pencil",size:"small",color:"primary",variant:"text",class:"mr-1",onClick:y=>a.showEditDialog(o)},{default:i(()=>[s(d,null,{default:i(()=>[...e[18]||(e[18]=[l("mdi-pencil",-1)])]),_:1})]),_:1},8,["onClick"]),s(u,{icon:"mdi-eye",size:"small",color:"info",variant:"text",class:"mr-1",onClick:y=>a.showEditDialog(o)},{default:i(()=>[s(d,null,{default:i(()=>[...e[19]||(e[19]=[l("mdi-eye",-1)])]),_:1})]),_:1},8,["onClick"])])]),default:i(()=>[s(A,{class:"font-weight-medium"},{default:i(()=>[l(x(o.examName||`配置 ${o.id}`),1)]),_:2},1024),s(F,{class:"text-caption mt-1"},{default:i(()=>[g("div",Y,[s(d,{size:"small",class:"mr-1"},{default:i(()=>[...e[16]||(e[16]=[l("mdi-information-outline",-1)])]),_:1}),l(" "+x(o.message||"无描述"),1)]),g("div",Z,[s(d,{size:"small",class:"mr-1"},{default:i(()=>[...e[17]||(e[17]=[l("mdi-book-multiple",-1)])]),_:1}),l(" "+x(o.examInfos?o.examInfos.length:0)+" 堂考试 ",1)])]),_:2},1024)]),_:2},1032,["onClick"]))),128))]),_:1})]),_:1})):p("",!0),!t.loading&&t.configs.length===0?(m(),f(v,{key:4,class:"my-4",elevation:"1"},{default:i(()=>[s(w,{class:"text-center py-8"},{default:i(()=>[s(d,{size:"64",color:"grey-lighten-1",class:"mb-4"},{default:i(()=>[...e[20]||(e[20]=[l(" mdi-calendar-blank ",-1)])]),_:1}),e[22]||(e[22]=g("h3",{class:"text-h6 mb-2 text-grey-darken-1"},"暂无配置",-1)),e[23]||(e[23]=g("p",{class:"text-body-2 text-grey-darken-1 mb-4"},' 点击"新建配置"按钮创建您的第一个考试配置 ',-1)),s(u,{color:"primary","prepend-icon":"mdi-plus",onClick:a.createNewConfig},{default:i(()=>[...e[21]||(e[21]=[l(" 新建配置 ",-1)])]),_:1},8,["onClick"])]),_:1})]),_:1})):p("",!0)]),_:1})]),_:1})]),_:1})]),_:1}),s(V,{modelValue:t.renameDialog,"onUpdate:modelValue":e[4]||(e[4]=o=>t.renameDialog=o),"max-width":"500"},{default:i(()=>[s(v,null,{default:i(()=>[s(k,{class:"d-flex align-center"},{default:i(()=>[s(d,{color:"primary",class:"mr-2"},{default:i(()=>[...e[24]||(e[24]=[l("mdi-rename-box",-1)])]),_:1}),e[25]||(e[25]=l(" 重命名配置 ",-1))]),_:1}),s(w,null,{default:i(()=>[s(G,{modelValue:t.newConfigName,"onUpdate:modelValue":e[2]||(e[2]=o=>t.newConfigName=o),label:"配置名称","prepend-inner-icon":"mdi-calendar-text",variant:"outlined",rules:[o=>!!o||"配置名称不能为空"],onKeyup:K(a.renameConfig,["enter"])},null,8,["modelValue","rules","onKeyup"])]),_:1}),s(_,null,{default:i(()=>[s(D),s(u,{color:"grey",variant:"text",onClick:e[3]||(e[3]=o=>t.renameDialog=!1)},{default:i(()=>[...e[26]||(e[26]=[l(" 取消 ",-1)])]),_:1}),s(u,{color:"primary",variant:"outlined",loading:t.renaming,onClick:a.renameConfig,disabled:!t.newConfigName},{default:i(()=>[...e[27]||(e[27]=[l(" 确认 ",-1)])]),_:1},8,["loading","onClick","disabled"])]),_:1})]),_:1})]),_:1},8,["modelValue"]),s(V,{modelValue:t.editDialog,"onUpdate:modelValue":e[5]||(e[5]=o=>t.editDialog=o),"max-width":"1200",persistent:""},{default:i(()=>[s(v,null,{default:i(()=>[s(k,{class:"d-flex align-center primary lighten-1 white--text py-3 px-4"},{default:i(()=>[s(d,{color:"white",class:"mr-2"},{default:i(()=>[...e[28]||(e[28]=[l("mdi-pencil",-1)])]),_:1}),e[30]||(e[30]=l(" 编辑考试配置 ",-1)),s(D),t.editingConfig?(m(),f(E,{key:0,color:"white","text-color":"primary",size:"small",class:"mr-2"},{default:i(()=>[l(" ID: "+x(t.editingConfig.id),1)]),_:1})):p("",!0),s(u,{icon:"mdi-close",color:"white",variant:"text",onClick:a.closeEditDialog},{default:i(()=>[s(d,null,{default:i(()=>[...e[29]||(e[29]=[l("mdi-close",-1)])]),_:1})]),_:1},8,["onClick"])]),_:1}),s(w,{class:"pa-4",style:{"max-height":"70vh","overflow-y":"auto"}},{default:i(()=>[t.editingConfig?(m(),f(h,{key:0,"config-id":t.editingConfig.id,ref:"configEditor","dialog-mode":!0,onSaved:a.onConfigSaved,onError:a.onConfigError,onOpened:a.onConfigOpened,onDeleted:a.onConfigDeleted},null,8,["config-id","onSaved","onError","onOpened","onDeleted"])):p("",!0)]),_:1}),s(_,{class:"pa-4"},{default:i(()=>[s(u,{color:"grey",variant:"outlined","prepend-icon":"mdi-close",onClick:a.closeEditDialog},{default:i(()=>[...e[31]||(e[31]=[l(" 关闭 ",-1)])]),_:1},8,["onClick"]),s(D),s(u,{color:"success",variant:"outlined","prepend-icon":"mdi-content-save",loading:t.saving,onClick:a.saveConfigInDialog},{default:i(()=>[...e[32]||(e[32]=[l(" 保存配置 ",-1)])]),_:1},8,["loading","onClick"])]),_:1})]),_:1})]),_:1},8,["modelValue"])]),_:1})}const pe=I(P,[["render",ee],["__scopeId","data-v-ddf88918"]]);export{pe as default};