newfront/dist/js/954.b76f59ca.js
2025-12-19 17:06:08 +08:00

2 lines
24 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

"use strict";(self["webpackChunknewfront"]=self["webpackChunknewfront"]||[]).push([[954],{4853:function(e,t,o){o.d(t,{A:function(){return h}});var s=o(6768),r=o(4232);const a={key:0,class:"loading-container"},i={class:"loading-content"},n={class:"loading-text"};function l(e,t,o,l,c,d){return o.visible?((0,s.uX)(),(0,s.CE)("div",a,[t[1]||(t[1]=(0,s.Lk)("div",{class:"loading-overlay"},null,-1)),(0,s.Lk)("div",i,[t[0]||(t[0]=(0,s.Lk)("div",{class:"loading-spinner"},[(0,s.Lk)("div",{class:"spinner"})],-1)),(0,s.Lk)("div",n,(0,r.v_)(o.text),1)])])):(0,s.Q3)("",!0)}var c={name:"Loading",props:{visible:{type:Boolean,default:!1},text:{type:String,default:"加载中..."}}},d=o(1241);const u=(0,d.A)(c,[["render",l],["__scopeId","data-v-032dd7a4"]]);var h=u},4954:function(e,t,o){o.r(t),o.d(t,{default:function(){return ie}});var s=o(6768),r=o(5130),a=o(4232);const i={class:"submit-page"},n={key:0,class:"course-selector-modal"},l={class:"modal-container"},c={class:"modal-header"},d={class:"modal-body"},u={class:"search-bar"},h={class:"course-results"},p={key:0,class:"course-loading"},m={key:1,class:"search-error"},f={key:2,class:"no-results"},g={key:3,class:"course-table"},k=["onClick"],v=["checked","onClick"],L={class:"rating"},b={class:"rating-count"},w={key:4,class:"pagination"},y=["disabled"],C={class:"page-info"},A=["disabled"],E={class:"modal-footer"},x=["disabled"],P={class:"container"},S={class:"page-header"},z={class:"sub-title"},M={key:0,class:"sub-title"},j={class:"submission-form"},D={class:"form-section"},_={class:"form-group"},T={for:"title"},F={class:"form-group"},U={class:"form-group"},$={class:"form-section"},I={class:"upload-area"},X={class:"file-input-container"},O={key:0,class:"file-list"},q={class:"file-name"},B={class:"file-size"},N={class:"total-size"},R={class:"form-section"},W={class:"section-desc",style:{color:"purple"}},J={xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",fill:"none",stroke:"black","stroke-linecap":"round","stroke-linejoin":"round",width:"20",height:"24","stroke-width":"1.1",style:{"vertical-align":"middle",display:"inline-block","margin-bottom":"2px"}},V={key:0,class:"section-desc",style:{color:"red"}},Q={class:"editor-container"},G={class:"draft-actions"},K={class:"form-actions"};function H(e,t,o,H,Y,Z){const ee=(0,s.g2)("Navbar"),te=(0,s.g2)("Loading"),oe=(0,s.g2)("MdEditor");return(0,s.uX)(),(0,s.CE)("div",i,[(0,s.bF)(ee),(0,s.bF)(te,{visible:Y.isLoading,text:Y.loadingText},null,8,["visible","text"]),Y.showCourseSelector?((0,s.uX)(),(0,s.CE)("div",n,[(0,s.Lk)("div",{class:"modal-overlay",onClick:t[0]||(t[0]=(...e)=>Z.closeCourseSelector&&Z.closeCourseSelector(...e))}),(0,s.Lk)("div",l,[(0,s.Lk)("div",c,[t[19]||(t[19]=(0,s.Lk)("h3",null,"选择课程",-1)),(0,s.Lk)("button",{class:"close-btn",onClick:t[1]||(t[1]=(...e)=>Z.closeCourseSelector&&Z.closeCourseSelector(...e))},"×")]),(0,s.Lk)("div",d,[(0,s.Lk)("div",u,[(0,s.bo)((0,s.Lk)("input",{type:"text","onUpdate:modelValue":t[2]||(t[2]=e=>Y.courseSearch=e),placeholder:"请输入课程名称",class:"search-input",onKeyup:t[3]||(t[3]=(0,r.jR)(((...e)=>Z.searchCourses&&Z.searchCourses(...e)),["enter"]))},null,544),[[r.Jo,Y.courseSearch]]),(0,s.Lk)("button",{class:"search-btn",onClick:t[4]||(t[4]=(...e)=>Z.searchCourses&&Z.searchCourses(...e))},"搜索")]),(0,s.Lk)("div",h,[Y.searchLoading?((0,s.uX)(),(0,s.CE)("div",p,t[20]||(t[20]=[(0,s.Lk)("div",{class:"spinner"},null,-1),(0,s.Lk)("span",null,"搜索中...",-1)]))):Y.searchError?((0,s.uX)(),(0,s.CE)("div",m,(0,a.v_)(Y.searchError),1)):0===Y.courseResults.length?((0,s.uX)(),(0,s.CE)("div",f," 未找到相关课程 ")):((0,s.uX)(),(0,s.CE)("table",g,[t[21]||(t[21]=(0,s.Lk)("thead",null,[(0,s.Lk)("tr",null,[(0,s.Lk)("th",null,"选择"),(0,s.Lk)("th",null,"课程名称"),(0,s.Lk)("th",null,"课程类别"),(0,s.Lk)("th",null,"授课教师"),(0,s.Lk)("th",null,"评分")])],-1)),(0,s.Lk)("tbody",null,[((0,s.uX)(!0),(0,s.CE)(s.FK,null,(0,s.pI)(Y.courseResults,(e=>((0,s.uX)(),(0,s.CE)("tr",{key:e.course_id,onClick:t=>Z.selectCourse(e),class:(0,a.C4)({selected:Y.selectedCourse&&Y.selectedCourse.course_id===e.course_id})},[(0,s.Lk)("td",null,[(0,s.Lk)("input",{type:"radio",checked:Y.selectedCourse&&Y.selectedCourse.course_id===e.course_id,onClick:(0,r.D$)((t=>Z.selectCourse(e)),["stop"])},null,8,v)]),(0,s.Lk)("td",null,(0,a.v_)(e.course_name),1),(0,s.Lk)("td",null,(0,a.v_)(Z.getCategoryName(e.category_id)),1),(0,s.Lk)("td",null,(0,a.v_)(e.teachers),1),(0,s.Lk)("td",null,[(0,s.Lk)("span",L,(0,a.v_)(e.rating),1),(0,s.Lk)("span",b,"("+(0,a.v_)(e.rating_count)+"人评)",1)])],10,k)))),128))])])),Y.totalPages>1?((0,s.uX)(),(0,s.CE)("div",w,[(0,s.Lk)("button",{class:"page-btn",disabled:1===Y.currentPage,onClick:t[5]||(t[5]=e=>Z.changePage(Y.currentPage-1))}," 上一页 ",8,y),(0,s.Lk)("span",C,"第 "+(0,a.v_)(Y.currentPage)+" / "+(0,a.v_)(Y.totalPages)+" 页",1),(0,s.Lk)("button",{class:"page-btn",disabled:Y.currentPage===Y.totalPages,onClick:t[6]||(t[6]=e=>Z.changePage(Y.currentPage+1))}," 下一页 ",8,A)])):(0,s.Q3)("",!0)])]),(0,s.Lk)("div",E,[(0,s.Lk)("button",{class:"btn btn-secondary",onClick:t[7]||(t[7]=(...e)=>Z.closeCourseSelector&&Z.closeCourseSelector(...e))}," 取消 "),(0,s.Lk)("button",{class:"btn btn-primary",onClick:t[8]||(t[8]=(...e)=>Z.confirmCourseSelection&&Z.confirmCourseSelection(...e)),disabled:!Y.selectedCourse}," 确定 ",8,x)])])])):(0,s.Q3)("",!0),(0,s.Lk)("div",P,[(0,s.Lk)("div",S,[(0,s.Lk)("h1",null,(0,a.v_)(Y.isEditMode?"编辑投稿内容":"内容投稿"),1),(0,s.Lk)("p",z,(0,a.v_)(Y.isEditMode?"编辑您的投稿内容":"感谢您分享您的学习资源或独到见解!"),1),Y.isEditMode?(0,s.Q3)("",!0):((0,s.uX)(),(0,s.CE)("p",M,"请在投稿之前先检索本站是否已有相同内容,避免重复投稿,谢谢合作!"))]),(0,s.Lk)("div",j,[(0,s.Lk)("div",D,[(0,s.Lk)("div",_,[(0,s.Lk)("label",T,"标题 "+(0,a.v_)(Y.isEditMode?"(如需更改标题请不要更改【edit】前缀)":""),1),(0,s.bo)((0,s.Lk)("input",{type:"text",id:"title","onUpdate:modelValue":t[9]||(t[9]=e=>Y.formData.title=e),class:"form-control",placeholder:"请输入投稿标题",maxlength:"50"},null,512),[[r.Jo,Y.formData.title]])]),(0,s.Lk)("div",F,[t[23]||(t[23]=(0,s.Lk)("label",{for:"section"},"板块",-1)),(0,s.bo)((0,s.Lk)("select",{id:"section","onUpdate:modelValue":t[10]||(t[10]=e=>Y.formData.section=e),class:"form-control"},t[22]||(t[22]=[(0,s.Lk)("option",{value:"",disabled:""},"请选择板块",-1),(0,s.Lk)("option",{value:"攻略指南"},"攻略指南",-1),(0,s.Lk)("option",{value:"资源共享"},"资源共享",-1)]),512),[[r.u1,Y.formData.section]])]),(0,s.Lk)("div",U,[t[24]||(t[24]=(0,s.Lk)("label",{for:"note"},"备注信息 (选填)",-1)),(0,s.bo)((0,s.Lk)("input",{type:"text",id:"note","onUpdate:modelValue":t[11]||(t[11]=e=>Y.formData.note=e),class:"form-control",placeholder:"可添加备注信息"},null,512),[[r.Jo,Y.formData.note]])])]),(0,s.Lk)("div",$,[t[27]||(t[27]=(0,s.Lk)("h3",null,"附件上传",-1)),t[28]||(t[28]=(0,s.Lk)("p",{class:"section-desc"},"您可以上传最多10个文件总大小不超过500MB。",-1)),(0,s.Lk)("div",I,[(0,s.Lk)("div",X,[t[25]||(t[25]=(0,s.Lk)("label",{for:"filePicker",class:"upload-label"},[(0,s.Lk)("span",{class:"upload-icon"},"📎"),(0,s.Lk)("span",null,"选择文件")],-1)),(0,s.Lk)("input",{type:"file",id:"filePicker",ref:"filePicker",onChange:t[12]||(t[12]=(...e)=>Z.validateFiles&&Z.validateFiles(...e)),multiple:"",class:"file-input"},null,544)]),Y.selectedFiles.length>0?((0,s.uX)(),(0,s.CE)("div",O,[t[26]||(t[26]=(0,s.Lk)("h4",null,"已选择的文件:",-1)),(0,s.Lk)("ul",null,[((0,s.uX)(!0),(0,s.CE)(s.FK,null,(0,s.pI)(Y.selectedFiles,((e,t)=>((0,s.uX)(),(0,s.CE)("li",{key:t},[(0,s.Lk)("span",q,(0,a.v_)(e.name),1),(0,s.Lk)("span",B,"("+(0,a.v_)(Z.formatFileSize(e.size))+")",1)])))),128))]),(0,s.Lk)("p",N,"总大小: "+(0,a.v_)(Z.formatFileSize(Y.totalFileSize)),1)])):(0,s.Q3)("",!0)])]),(0,s.Lk)("div",R,[t[35]||(t[35]=(0,s.Lk)("h3",null,"内容编辑",-1)),t[36]||(t[36]=(0,s.Lk)("p",{class:"section-desc"},'此部分主要用于"攻略指南"板块,"资源共享"板块可以留空。',-1)),t[37]||(t[37]=(0,s.Lk)("p",{class:"section-desc"},"使用Markdown语法编辑您的投稿内容。插入图片后如需修改图片大小请在编辑器中找到插入的图片标签修改其width属性。",-1)),t[38]||(t[38]=(0,s.Lk)("p",{class:"section-desc"},[(0,s.eW)("如上传了附件且需在文中指定位置展示,"),(0,s.Lk)("strong",null,"可以用[附件名]来表示附件位置"),(0,s.eW)("。如不指定,则审核人员将按照文章内容在适当位置展示。")],-1)),t[39]||(t[39]=(0,s.Lk)("p",{class:"section-desc"},[(0,s.Lk)("strong",null,'"保存草稿"功能和"在文章页中预览"功能只针对此部分内容,上传的附件等将不会保存草稿并不支持"在文章页中预览"功能。')],-1)),(0,s.Lk)("p",W,[t[30]||(t[30]=(0,s.eW)("您可以轻松地插入课程卡片(点击")),((0,s.uX)(),(0,s.CE)("svg",J,t[29]||(t[29]=[(0,s.Lk)("path",{d:"M22 9l-10 -4l-10 4l10 4l10 -4v6"},null,-1),(0,s.Lk)("path",{d:"M6 10.6v5.4a6 3 0 0 0 12 0v-5.4"},null,-1)]))),t[31]||(t[31]=(0,s.eW)("按钮),引用课程评分系统中的课程数据。")),t[32]||(t[32]=(0,s.Lk)("strong",null,"注意:由于网站的安全设置,课程卡片前必须有其他内容,请勿在内容第一行插入课程卡片,否则将无法正常显示!",-1))]),Y.isEditMode?((0,s.uX)(),(0,s.CE)("p",V,t[33]||(t[33]=[(0,s.Lk)("strong",null,"检测到您当前正在编辑已有的投稿内容,请注意您之前如有其他投稿的草稿内容,这些内容在此页面保存草稿或提交编辑后将不会保留。",-1)]))):(0,s.Q3)("",!0),(0,s.Lk)("div",Q,[(0,s.bF)(oe,{modelValue:Y.formData.content,"onUpdate:modelValue":t[14]||(t[14]=e=>Y.formData.content=e),ref:"markdownEditor",theme:Y.editorTheme,toolbars:Y.editorToolbars,language:"zh-CN","preview-theme":"github",placeholder:Y.editorPlaceholder,onOnUploadImg:Z.handleImageUpload,onOnSave:Z.saveDraftWithConfirm},{defToolbars:(0,s.k6)((()=>[(0,s.Lk)("span",{class:"md-editor-toolbar-item",title:"添加课程卡片",onClick:t[13]||(t[13]=(...e)=>Z.chooseCourse&&Z.chooseCourse(...e))},t[34]||(t[34]=[(0,s.Lk)("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-linecap":"round","stroke-linejoin":"round",width:"20",height:"24","stroke-width":"1.1"},[(0,s.Lk)("path",{d:"M22 9l-10 -4l-10 4l10 4l10 -4v6"}),(0,s.Lk)("path",{d:"M6 10.6v5.4a6 3 0 0 0 12 0v-5.4"})],-1)]))])),_:1},8,["modelValue","theme","toolbars","placeholder","onOnUploadImg","onOnSave"])]),(0,s.Lk)("div",G,[(0,s.Lk)("button",{type:"button",class:"btn btn-secondary",onClick:t[15]||(t[15]=(...e)=>Z.loadDraft&&Z.loadDraft(...e))}," 加载草稿 "),(0,s.Lk)("button",{type:"button",class:"btn btn-secondary",onClick:t[16]||(t[16]=(...e)=>Z.saveDraftWithConfirm&&Z.saveDraftWithConfirm(...e))}," 保存草稿 "),(0,s.Lk)("button",{type:"button",class:"btn btn-secondary preview-btn",onClick:t[17]||(t[17]=(...e)=>Z.previewDraft&&Z.previewDraft(...e))}," 在文章页中预览 ")])]),(0,s.Lk)("div",K,[(0,s.Lk)("button",{type:"button",class:"btn btn-primary",onClick:t[18]||(t[18]=(...e)=>Z.submitForm&&Z.submitForm(...e))},(0,a.v_)(Y.isEditMode?"提交编辑":"提交投稿"),1)])])])])}o(4114),o(8111),o(1701);var Y=o(1697),Z=o(3577),ee=o(8704),te=o(4993),oe=o(4853),se={name:"SubmitPage",components:{Navbar:Y.A,MdEditor:Z.A,Loading:oe.A},data(){return{formData:{title:"",section:"",note:"",content:""},selectedFiles:[],totalFileSize:0,imageUrl:"",imageTag:"",editorTheme:"light",editorPlaceholder:"在此输入您的内容,支持直接把图片粘贴到编辑器中",editorToolbars:["bold","italic","underline","sub","sup","-","title","unorderedList","orderedList","-","quote","link","image","table","codeRow","code","mermaid",0,"=","save","revoke","next","-","preview","pageFullscreen","fullscreen"],isEditMode:!1,editArticleId:null,isLoading:!1,loadingText:"获取投稿内容中...",showCourseSelector:!1,courseSearch:"",searchLoading:!1,searchError:null,courseResults:[],selectedCourse:null,currentPage:1,totalPages:1,categoryMap:{1:"通识选修类",2:"人文选修类",3:"专业方向类",4:"体育类",5:"学科基础类",6:"暑期国际课",7:"数学与自然科学类",8:"重修专栏",9:"数学与自然科学类(必修)",10:"人文社会科学类(必修)",11:"学科基础类(必修)",12:"专业方向类(必修)",13:"实践类(必修)"}}},created(){document.title="内容投稿 - NEU小站",this.checkLoginStatus().then((()=>{this.checkEditMode()}))},methods:{async checkLoginStatus(){const e=ee.A.get("token");if(!e)return this.$router.push("/login"),Promise.reject(new Error("未登录"));try{const t=await fetch("https://newfront.xn--xhq44jb2fzpc.com/user/islogin",{method:"GET",headers:{Authorization:e}});if(!t.ok)throw new Error("验证失败");const o=await t.json();return o.isLoggedIn?Promise.resolve():(ee.A.remove("token"),this.$router.push("/login"),Promise.reject(new Error("登录已过期")))}catch(t){return console.error("登录验证失败:",t),ee.A.remove("token"),this.$router.push("/login"),Promise.reject(t)}},async checkEditMode(){const e=new URLSearchParams(window.location.search),t=e.get("article");if(t)try{this.isEditMode=!0,this.editArticleId=t,this.isLoading=!0;const e=ee.A.get("token"),o=await fetch(`https://newfront.xn--xhq44jb2fzpc.com/article?id=${t}&edit=true`,{method:"GET",headers:{Authorization:e}});if(!o.ok)throw new Error("获取文章失败");const s=await o.json();this.formData.title=`【edit${t}${s.title}`,this.formData.section=s.section,this.formData.content=s.content,document.title="编辑投稿内容 - NEU小站"}catch(o){console.error("获取文章信息失败:",o),this.isEditMode=!1,this.editArticleId=null}finally{this.isLoading=!1}},async handleImageUpload(e,t){const o=ee.A.get("token");if(o)try{const s=e.map((async e=>{if(e.size>2097152)throw new Error(`图片 ${e.name} 大小不能超过2MB`);const t=e.name.split(".").pop().toLowerCase(),s=e.type,r=await fetch("https://userlogin.xn--xhq44jb2fzpc.com/submission/prepare-image-upload",{method:"POST",headers:{Authorization:o,"Content-Type":"application/json"},body:JSON.stringify({postfix:t,type:s})});if(!r.ok)throw new Error("准备上传失败");const{uploadUrl:a,path:i}=await r.json(),n=await fetch(a,{method:"PUT",body:e,headers:{"Content-Type":s,Authorization:o}});if(!n.ok)throw new Error(`文件 ${e.name} 上传失败`);const l=`https://download.xn--xhq44jb2fzpc.com/${i}`;return l})),r=await Promise.all(s);t(r),r.length>0&&setTimeout((()=>{te.A.alert("您已成功上传图片。如需修改图片大小请在编辑器中找到刚插入的图片标签修改其width属性。","图片大小调整提示")}),800)}catch(s){console.error("图片上传失败:",s),te.A.alert("图片上传失败:"+s.message,"错误")}else te.A.alert("请先登录!","提示")},validateFiles(e){const t=10,o=524288e3,s=e.target.files;if(s.length>t)return te.A.alert(`您只能选择最多 ${t} 个文件。`,"提示"),e.target.value="",this.selectedFiles=[],void(this.totalFileSize=0);let r=0;const a=[];for(let i=0;i<s.length;i++){const t=s[i],n=t.size;if(r+=n,r>o)return te.A.alert("所有文件的总大小不能超过 500MB。","提示"),e.target.value="",this.selectedFiles=[],void(this.totalFileSize=0);a.push(t)}this.selectedFiles=a,this.totalFileSize=r},formatFileSize(e){if(0===e)return"0 Bytes";const t=1024,o=["Bytes","KB","MB","GB"],s=Math.floor(Math.log(e)/Math.log(t));return parseFloat((e/Math.pow(t,s)).toFixed(2))+" "+o[s]},async uploadImage(e){const t=e.target.files[0];if(t){if(t.size>2097152)return te.A.alert("图片文件大小不能超过2MB","提示"),void(e.target.value="");if(!t.type.startsWith("image/"))return te.A.alert("请选择图片文件!","提示"),void(e.target.value="");try{const e=ee.A.get("token");if(!e)return void te.A.alert("请先登录!","提示");const o=t.name.split(".").pop().toLowerCase(),s=t.type,r=await fetch("https://userlogin.xn--xhq44jb2fzpc.com/submission/prepare-image-upload",{method:"POST",headers:{Authorization:e,"Content-Type":"application/json"},body:JSON.stringify({postfix:o,type:s})});if(!r.ok)throw new Error("准备上传失败");const{uploadUrl:a,path:i}=await r.json(),n=await fetch(a,{method:"PUT",body:t,headers:{"Content-Type":s,Authorization:e}});if(!n.ok){const e=await n.text();if(e.includes("<?xml")){const t=new DOMParser,o=t.parseFromString(e,"text/xml"),s=o.getElementsByTagName("RequestId")[0]?.textContent;throw new Error(`文件上传失败 (RequestId: ${s||"未知"})`)}throw new Error("文件上传失败")}const l=`https://download.xn--xhq44jb2fzpc.com/${i}`,c=`<img src="${l}" alt="自定义图片文字" width="150">`;this.imageUrl=l,this.imageTag=c}catch(o){console.error("上传失败:",o),te.A.alert("图片上传失败:"+o.message,"错误"),e.target.value=""}}else te.A.alert("请先选择图片文件!","提示")},copyImageUrl(){const e=document.createElement("textarea");e.value=this.imageTag,document.body.appendChild(e),e.select();try{const e=document.execCommand("copy"),t=e?"标签已复制到剪贴板!请直接粘贴到编辑区中,并根据预览效果调整大小。":"复制失败!";te.A.alert(t,"提示")}catch(t){te.A.alert(`复制失败!${t}`,"错误")}document.body.removeChild(e)},async previewDraft(){const{content:e}=this.formData;if(e.trim())try{const e=await te.A.confirm("此操作会自动保存草稿。确认继续吗?如您之前有草稿记录,此操作会覆盖之前的草稿内容。","确认");if(!e)return;this.saveDraft(!0).then((()=>{window.open("/preview","_blank")})).catch((e=>{console.error("无法预览草稿:",e)}))}catch(t){console.error("预览草稿操作被取消:",t)}else te.A.alert("内容不能为空!","提示")},async saveDraftWithConfirm(){const{content:e}=this.formData;if(e.trim())try{const e=await te.A.confirm("确认保存草稿内容吗?如您之前有草稿记录,此操作会覆盖之前的草稿内容。","确认");e&&this.saveDraft(!0)}catch(t){console.error("保存草稿操作被取消:",t)}else te.A.alert("内容不能为空!","提示")},async saveDraft(e=!1){const t=ee.A.get("token");if(!t)return te.A.alert("非法操作!请先登录。","警告"),Promise.reject(new Error("未登录"));const o=this.formData.content;if(o.trim())try{let s=!0;if(e||(s=await te.A.confirm("确认保存草稿内容吗?如您之前有草稿记录,此操作会覆盖之前的草稿内容。","确认")),!s)return;const r=await fetch("https://userlogin.xn--xhq44jb2fzpc.com/submission/save-draft",{method:"POST",headers:{Authorization:t,"Content-Type":"application/json"},body:JSON.stringify({content:o})});if(!r.ok){const e=await r.json();throw new Error(e.message||"保存草稿失败")}return e||te.A.alert("草稿已保存!","成功"),Promise.resolve()}catch(s){return console.error("保存草稿时出错:",s),e||te.A.alert("保存草稿失败,请稍后再试。","错误"),Promise.reject(s)}else te.A.alert("内容不能为空!","提示")},async loadDraft(){const e=ee.A.get("token");if(e)try{const o=await fetch("https://userlogin.xn--xhq44jb2fzpc.com/submission/load-draft",{method:"GET",headers:{Authorization:e}});if(!o.ok){if(404!==o.status){const e=await o.json();throw new Error(e.message||"无法加载草稿内容")}return void te.A.alert("没有草稿记录!","提示")}const s=await o.json();try{const e=await te.A.confirm("此操作会覆盖您当前的输入内容,确认加载草稿吗?","确认");if(!e)return;this.formData.content=s.content,te.A.alert("草稿已加载!","成功")}catch(t){console.log("用户取消了加载草稿操作")}}catch(t){console.error("加载草稿时出错:",t),te.A.alert("加载草稿失败,请稍后再试。","错误")}else te.A.alert("非法操作!请先登录。","警告")},async submitForm(){const{title:e,section:t,note:o,content:s}=this.formData,r=ee.A.get("token"),a=this.selectedFiles;if(e&&t)try{let l="确认提交投稿内容吗?";this.isEditMode&&(l="确认提交修改?修改后的内容将重新进入审核流程。");const c=await te.A.confirm(l,"提交确认");if(!c)return;const d=[];for(let e=0;e<a.length;e++){const t=a[e],o=t.name.split(".").pop().toLowerCase();d.push({filename:t.name,postfix:o,type:t.type||"application/octet-stream",size:(t.size/1048576).toFixed(2)})}let u="https://userlogin.xn--xhq44jb2fzpc.com/submission/submit";const h={title:e,section:t,detail:s||null,submission_note:o||null,has_file:a.length>0?1:0,files:d};this.isEditMode&&this.editArticleId&&(h.article_id=this.editArticleId);const p=await fetch(u,{method:"POST",headers:{Authorization:r,"Content-Type":"application/json"},body:JSON.stringify(h)});if(!p.ok){const e=await p.json();throw new Error(e.message||"投稿失败,请重试!")}const m=await p.json(),f=m.submissionId;if(m.fileUploadData&&m.fileUploadData.length>0){this.loadingText="文件正在上传中,请耐心等待...",this.isLoading=!0;try{for(let e=0;e<a.length;e++){const t=a[e],o=m.fileUploadData[e],s=await fetch(o.uploadUrl,{method:"PUT",body:t,headers:{"Content-Type":t.type||"application/octet-stream",Authorization:r}});if(!s.ok)throw new Error(`文件 ${t.name} 上传失败`)}this.isLoading=!1}catch(i){throw i}}try{this.loadingText="确认状态中...",this.isLoading=!0;const e=await fetch("https://userlogin.xn--xhq44jb2fzpc.com/submission/confirm-submit",{method:"POST",headers:{Authorization:r,"Content-Type":"application/json"},body:JSON.stringify({submission_id:f})});if(!e.ok){const t=await e.json();console.error("确认投稿失败:",t.message||"未知错误"),te.A.alert("投稿失败,请重试。如多次尝试仍失败,请联系管理员。","警告")}}catch(n){console.error("确认状态时出错:",n),te.A.alert("确认状态时出错,请稍后重试或联系管理员。","错误")}finally{this.isLoading=!1}let g="投稿成功!您将会在审核状态变化后收到邮件通知,敬请留意~";this.isEditMode&&(g="修改提交成功!您将会在审核状态变化后收到邮件通知,敬请留意~"),await te.A.alert(g,"成功"),this.$router.push("/user-center")}catch(l){if(this.isLoading=!1,console.error("投稿失败:",l),l&&"cancel"===l.action)return;te.A.alert(`投稿失败:${l.message||"未知错误"}`,"错误")}else te.A.alert("请填写内容的标题和板块。","提示")},chooseCourse(){this.showCourseSelector=!0,this.courseSearch="",this.courseResults=[],this.selectedCourse=null,this.currentPage=1,this.totalPages=1,this.searchError=null},closeCourseSelector(){this.showCourseSelector=!1},async searchCourses(e=1){if(e&&"object"===typeof e&&e.type&&(e=1),this.courseSearch.trim()){this.searchLoading=!0,this.searchError=null,this.selectedCourse=null,this.currentPage=e;try{const t=encodeURIComponent(this.courseSearch.trim()),o=`https://coursesystem.xn--xhq44jb2fzpc.com/list/courses?search=${t}&page=${e}`,s=await fetch(o);if(!s.ok)throw new Error("搜索课程失败");const r=await s.json();this.courseResults=r.courses||[],this.currentPage=r.currentPage||1,this.totalPages=r.totalPages||1}catch(t){console.error("课程搜索出错:",t),this.searchError="搜索课程时发生错误,请稍后重试"}finally{this.searchLoading=!1}}else te.A.alert("请输入课程名称","提示")},getCategoryName(e){return this.categoryMap[e]||"未知类别"},selectCourse(e){this.selectedCourse=e},changePage(e){e<1||e>this.totalPages||this.searchCourses(e)},confirmCourseSelection(){if(!this.selectedCourse)return void te.A.alert("请先选择一个课程","提示");const e=this.$refs.markdownEditor,t=`<CourseCard id="${this.selectedCourse.course_id}" />\n`;e.insert((e=>({targetValue:t,select:!1,deviationStart:0,deviationEnd:0}))),this.closeCourseSelector()}},computed:{displayedPages(){const e=5,t=Math.floor(e/2);let o=Math.max(1,this.currentPage-t),s=Math.min(this.totalPages,o+e-1);s-o+1<e&&(o=Math.max(1,s-e+1));const r=[];for(let a=o;a<=s;a++)r.push(a);return r}}},re=o(1241);const ae=(0,re.A)(se,[["render",H],["__scopeId","data-v-15731f90"]]);var ie=ae}}]);
//# sourceMappingURL=954.b76f59ca.js.map