var env = (function (defaultEnv) { var isProduction = ~location.href.indexOf('schcur.com') var isLocal = ~location.href.indexOf('localhost') || ~location.href.indexOf('192.168') || ~location.href.indexOf('xg.xueping.com') if (isLocal) return defaultEnv if (isProduction) return 'online' return 'testing' })('localxx'); //环境配置 var envConfig = envConfigs[env] //登陆态'/username/pc002/time/1567499908/sig/7d9ca3d40b7422b759ce9a7e08b2de20/sessionid/session_93482f6cf1c865b7a2e2793c66f2c595' var loginStatus = envConfig.loginStatus //当前环境域名 'http://192.168.1.51/index.php' var domain = envConfig.domain //当前环境转pdf所需css 相对路径 var printCssPath = envConfig.printCssPath //当前环境转pdf所要请求的域 var printPdfIp = envConfig.printPdfIp //试题编辑区域高度 var oldModH =0 var ueEditor = null var topicEl = null var Print = { apis: { //获取答题卡信息 getTopicsDetailAPi: domain + '/print/getPaperWithTopicsDetails' + loginStatus, //保存答题卡信息 saveTopicsDetailsApi: domain+'/print/saveCardOnline' + loginStatus, //保存为pdf htmlToPdfApi: domain + '/print/htmlToPdf' + loginStatus, //上传图片===富文本编辑试题的时候需要 uploadFileApi: domain + '/online/uploadFile' + loginStatus, //考试学生重置接口 /** schoolId examGroupId 两个参数 */ resetExamStudentApi: domain + '/rest/answer_card_online/resetStudentStatus' + loginStatus, //下载pdf downPdfApi: domain + '/print/downOnlinePdf' + loginStatus, downOnlinePdfApi: domain + '/third/download' + loginStatus, getPdfApi: '//' + printPdfIp + '/getPdf', getOnlinePdfApi: domain + '/third/getOnlinePdf' + loginStatus, delPdfApi: '//' + printPdfIp + '/delPdf', batchGeneratePdfApi: '//' + printPdfIp + '/batchGeneratePdf', //latex 转 公式图片 getMathtexApi: domain + '/print/ajaxGetMathtex' + loginStatus, // php生成pdf generatePhpPdf:domain +'/print/sendCreateOnlineAllStudents'+ loginStatus }, init: function (config) { this.modal = hgc_modal //需要同时保存用来记忆布局的有:纸张规格,纸张方向,是否有装订线,考号配置(填涂考号or条形码,是否使用二维码) this.paper = 'A3' this.direction = 'horizontal' //装订线 this.hasBindingLine = false //信息栏 this.hasPaperMsg = true //考号配置 this.examInfoConfig = { //时间 wpTimes: true, //满分 fullScore: true, //命卷人 wpAuthor: true, //审核人 wpReviewer: true } this.examInfoConfigText = { //时间 wpTimes: '', //满分 fullScore: '', //命卷人 wpAuthor: '', //审核人 wpReviewer: '' } //考号配置 this.examNumberConfig = { //条形码 barCode: true, //准考证号 ticketNumber: true } //是否使用二维码 this.useQrCode = false // 是否是学校答题卡 0 系统 1学校 this.cardStatus = 0 this.config = simpleCopy(config[this.paper]) this.configOrigin = simpleCopy(this.config) //分栏 this.columns = 2 //页面页码计算 //当前分页 this.currentPage = 1 //总分页 this.totalPage = 1 //当前纸张-包括正反两面 ceil(totalPage/(column*2)) this.currentPaper = 0 //当前纸张正面1正面2 反面1 反面2 this.currentPaperPage = 0 //初始化页面数据 /** * 核心功能模块盒模型设计 */ //解答区域--最小高度 this.moduleMinHeight = 10 //解答区域--默认高度 this.moduleDefaultHeihgt = 54 //解答区域--左右内边距之和 this.modulePaddingSide = 20 //解答区域--上内边距 this.modulePaddingTop = 42 //解答区域--下内边距 this.modulePaddingBottom = 12 this.modulePadding = this.modulePaddingTop + this.modulePaddingBottom //每个分页答题区域的--上下内边距 this.pagePadding = 50 //这个答题区域布局外边距 this.layoutPadding = 20 //每页的左右间距 this.pagePaddingSide = 30 //用于页面 mm 和 px 之间单位转换 //96dpi 打印出来300dpi纸张上面的的比例 this.dpiRadio = 1 this.unitConversion = new UnitConversion() this.pageHeight = this.unitConversion.mmConversionPx(this.config.height) this.pageWidth = this.unitConversion.mmConversionPx(this.config.width) //富文本编辑 ==>> 全局富文本编辑构造函数 this.EDITOR = window.wangEditor //富文本菜单配置文件 this.EDITOR_CONFIG = [ 'underline', // 下划线 'justify', // 对齐方式 'image', // 插入图片 'table', // 表格 'undo', // 撤销 'redo', // 重复 'lineheight', 'formula' ] this.UEditorConfig = { toolbars: [[ 'formatmatch','undo', 'redo','fontsize', 'bold','italic', 'underline','subscript','superscript', 'removeformat', 'lineheight', 'justifyleft','justifycenter', 'justifyright', 'justifyjustify', 'insertimage','imagenone', 'imageleft', 'imageright', 'horizontal', 'spechars', 'inserttable', 'deletetable', 'insertparagraphbeforetable', 'insertrow', 'deleterow', 'insertcol', 'deletecol', 'mergecells','kityformula','chineselattice','horizontalline' ]], enableAutoSave:false, imagePopup:false, focus:true, allHtmlEnabled:true, initialFrameHeight: 140, UEDITOR_HOME_URL: '/js/ueditor/', } //题型配置 this.questionTypeMapForPhp = { //0单选 singleSelect: 0, //8多选 moreSelect: 8, //填空 fillInBlank: 3, //解答 answer: 1, //选做 chooseAnswer: 2, //必做题 mustAnswer: 27 } //类型 1 单选 2 多选 5 填空 7 解答 17 选做 this.questionTypeMapForC = { 1: 'singleSelect', 2: 'moreSelect', 5: 'fillInBlank', 7: 'shortAnswer', 27: 'mustAnswer', 17: 'chooseAnswer' } //题型名称映射 this.questionNameMap = { singleSelect: '单选题', moreSelect: '多选题', fillInBlank: '填空题', shortAnswer: '解答题', chooseAnswer: '选做题', mustAnswer: '必做题' } //题型数据存储 this.questionMap = [] //全局groupId this.examGroupId = examGroupId this.examIds = examIds this.schoolId = schoolId //当前区域定位信息,用来简单判断两次保存是否有改动,来防止重复提交数据 this.saveLocationPosition = {} //首次保存 this.alreadySave = false //当前答题卡模块是否在编辑状态--是否可以 编辑当前答题卡模板 /** * 刚进页面 * 1如果是之前没有保存,就属于编辑状态 * 2如果之前有保存过,就属于保存在状态(页面所有操作按钮不可操作,需要点击编辑才可操作) * 页面中 * 1如果点击了保存,就是保存状态 */ this.isCanEditCard = true //是否已经有打印的班级 this.printClassStatus = false //题卡合一 的type值 this.subjectCardToOneType = 1 //是否题卡合一 this.isSubjectInfoToCard = false //替换富文本没用内容 this.replaceEditorRegexp = /(
<\/p>)|(
1、考生务必正确书写班级、姓名,请填涂系统准考证号。
' + '2、考生务必用2B铅笔填涂。
' + '3、考生务必在答题卡指定位置作答,并保持卷面整洁。
' + '4、如需要条形码,则考生务必要在指定位置正确贴好条形码。
' + '5、教师务必使用红笔阅卷。
'; let noticeDetailMsgBoxXX = '1、考生务必正确书写班级、姓名,请填涂学校准考证号。
' + '2、考生务必用2B铅笔填涂。
' + '3、考生务必在答题卡指定位置作答,并保持卷面整洁。
' + '4、如需要条形码,则考生务必要在指定位置正确贴好条形码。
' + '5、教师务必使用红笔阅卷。
'; let noticeDetailMsgBoxQR = '1、考生务必用2B铅笔填涂。
' + '2、考生务必在答题卡指定位置作答,并保持卷面整洁。
' + '3、如需要条形码,则考生务必要在指定位置正确贴好条形码。
' + '4、教师务必使用红笔阅卷。
'; if(qrStatus){ $('#noticeDetailMsgBox').html(noticeDetailMsgBoxQR) } else { $('#noticeDetailMsgBox').html(cardStatus==0 ? noticeDetailMsgBoxXT : noticeDetailMsgBoxXX) } }, /* -------------------------------------------------------------------------------------------------------------------- 初始页面布局功能开始 --------------------------------------------------------------------------------------------------------------------- */ renderPage: function (renderJSON, memoryPosition) { var self = this memoryPosition = memoryPosition || null self.renderExamBaseInfo(renderJSON.object) self.renderSubjectInfo(renderJSON.object.questions, memoryPosition) if (!self.alreadySave) { //重新定义超出部分布局 self.changePrintArea(self.$firstPageContent) } self.bindEvent() self.initEvent() }, //渲染答题卡基本信息 准考证号、名称、考试时间等 renderExamBaseInfo: function (examInfo) { var self = this //答题卡题目类型 self.$dtkName.val(examInfo.paperName) // var examInfoHtml = self.tpls.examInfoTpl.substitute(examInfo) // $('#examInfo').html(examInfoHtml) self.examInfoConfigText.wpTimes = examInfo.wpTimes self.examInfoConfigText.fullScore = examInfo.fullScore self.examInfoConfigText.wpAuthor = examInfo.wpAuthor self.examInfoConfigText.wpReviewer = examInfo.wpReviewer self.showExamInfoHtml() //准考证号信息 self.renderExamNumberInfo(examInfo) }, //准考证号信息 renderExamNumberInfo: function (examInfo) { var self = this //准考证号类型 1学校准考证 0系统准考证 self.school_card_status = examInfo.school_card_status //准考证号长度 var school_card_length = examInfo.school_card_length var examNumberHtml = '' var examNumberForOnlyCodeHtml = '' for (var colIndex = 0; colIndex < school_card_length; colIndex++) { examNumberHtml += self.tpls.examNumberItemTpl examNumberForOnlyCodeHtml += '' } $('#hgc_examNumber .ticketNumber').html(examNumberHtml) $('#hgc_examNumberForOnlyBarcode .ticketNumber p').html( examNumberForOnlyCodeHtml ) }, renderSubjectDataFormat: function (questions) { var self = this //题型 /** * "questionTypeId": 1, "fullScore": 5, "optionCount": 4, "questionNum": "1", "answer": "D" */ var questionClassify = (self.questionMap = questions.reduce( function (questionMap, item) { var questionMapKey = self.questionTypeMapForC[item.questionTypeId] var questionMapItem = questionMap[questionMapKey] if (questionMapItem) { questionMapItem.push(item) } else { questionMap[questionMapKey] = [item] } return questionMap }, { singleSelect: [], moreSelect: [], fillInBlank: [], shortAnswer: [], chooseAnswer: [], mustAnswer: [] } )) var titleTPls = { singleSelect: '、选择题(本大题共{subjectCount}小题,{subjectPointText}共{totalPoint}分。在每小题给出的四个选项中,只有一项是符合题目要求的。把答案填涂在答题卡上。)', moreSelect: '、多选题(本大题共{subjectCount}小题,{subjectPointText}共{totalPoint}分。在每小题给出的四个选项中,有两项及以上是符合题目要求的。把答案填涂在答题卡上。)', fillInBlank: '、填空题(本大题共{subjectCount}小题,{subjectPointText}共{totalPoint}分。把答案填写在答题卡相应的题号后的横线上。)', shortAnswer: '、解答题(本大题共{subjectCount}小题,{subjectPointText}共{totalPoint}分。解答写出相应的文字说明、证明过程或演算步骤。)', chooseAnswer: '、选做题(本题包括{chooseOption}{chooseOptionLength}小题,请选定其中{chooseCount}小题,并在相应的答题区域内作答,请用2B铅笔涂黑(示例:■)。若多做,则按作答的前一小题评分。解答应写出文字说明、证明过程或演算步骤。)', mustAnswer: '、必做题(本大题共{subjectCount}小题,{subjectPointText}共{totalPoint}分。解答写出相应的文字说明、证明过程或演算步骤。)' } var objectiveTitleTpl = { singleSelect: '、选择题题文', moreSelect: '、多选题题文', fillInBlank: '、填空题题文' } //填空题,选择题超出控制数据 var numberIndex = 0 for (var type in questionClassify) { //当前分类 var questionClassifyItem = questionClassify[type] if (!questionClassifyItem.length) continue numberIndex++ var titleFormatData = {} var isChooseAnswer = type === 'chooseAnswer' var isMoreSelect = type === 'moreSelect' //选做题题干信息 var chooseSubjectContent = '' //选做题标题特殊对待 if (isChooseAnswer) { var chooseOptionLength = SectionToChinese(questionClassifyItem.length) var chooseOption = questionClassifyItem .map(function (questionItem, index) { let isP = questionItem.queBody.search('1 || isP==-1){ queBody = '
' + questionItem.queBody +'
' } else { queBody = questionItem.queBody } chooseSubjectContent += '/, singleSelectStemRender: function (data, $afterModule) { var self = this var htmls = self.singleSelectObjectiveTitle var stemInfos = [] data.forEach(function (item) { //一排排列几个 //0一排一个 1一排4个 2一排两个', var columnNumber = typeof item.listType === 'number' ? !item.listType ? 1 : item.listType === 1 ? 4 : 2 : '' var columnClass = columnNumber ? 'column-' + columnNumber : '' var content = item.queBody.replace( self.queBodyRegExp, '
' + item.questionNum + '、' ) var optionsHtml = '
' + String.fromCharCode(65 + index) + '.
' + option.content + '' + item.questionNum + '、' ) var optionsHtml = '
' + String.fromCharCode(65 + index) + '.
' + option.content + '' + item.questionNum + '、' ) var stemItemHtml = self.tpls.objectiveItemTpl.substitute({ content: content }) //如果是题卡合一并且是保存状态的时候 才会保存原题信息 if (self.isSubjectInfoToCard) { stemInfos.push(encodeURIComponent(stemItemHtml)) } htmls += stemItemHtml }) htmls = self.tpls.objectiveWrapTpl.substitute({ editModule: htmls }) self.originStemInfos = stemInfos.concat(self.originStemInfos) $afterModule.after(htmls) }, /** * ————————————————————————————————————————————————————————————————————————————————————————————————————————————————————— 客观题题干内容渲染 结束 ————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————— */ getSingleSelectHtml: function (datas, type) { var self = this //判断是否多选 var isMoreSelect = type === 'more' var moreSelectClass = isMoreSelect ? 'more-option' : '' var singleSelectHtml = '' var singleColHtml = '' datas.forEach(function (singleItem, index) { var singleContent = '' for (var i = 0; i < singleItem.optionCount; i++) { var option = String.fromCharCode(65 + i) singleContent += '[{option}]'.substitute( { option: option } ) } singleColHtml += self.tpls.singleSelectOptionTpl.substitute({ _index: ++index, singleContent: singleContent, questionNum: singleItem.questionNum, answer: singleItem.answer }) if (!(index % 5)) { singleSelectHtml += '
' + // questionItem.questionNum + // '、' + // questionItem.matchPicture + // '
' // } // }, []) editorCreateIds.forEach(function (editorId) { self.createShortAnswer(editorId,chooseContent) }) }, //必做题--布局 mustAnswerRender: function (datas, appendEl) { var self = this var shortAnswerTpl = self.tpls.shortAnswerItemTpl var shortAnswerHtml = '' datas.forEach(function (shortAnswerItem) { shortAnswerItem.editorContentHeight = shortAnswerItem.editorContentHeight ? shortAnswerItem.editorContentHeight : self.moduleDefaultHeihgt var minLimit = self.getAnswerMinScoreLimit(shortAnswerItem.fullScore) shortAnswerItem.scoreColumnHtml = self.generateScoreBox(minLimit, false) shortAnswerItem.scoreLimit = minLimit shortAnswerHtml += shortAnswerTpl.substitute(shortAnswerItem) //保存原题信息 self.editorAreaOriginContent[shortAnswerItem.questionNum] = shortAnswerItem.queBody }) var shortAnswerModuleHtml = self.tpls.shortAnswerTpl.substitute({ shortAnswerContent: shortAnswerHtml, title: self['mustAnswer-title'] }) appendEl.append(shortAnswerModuleHtml) //初始化解答题富文本插件 datas.forEach(function (item) { var questionNum = item.questionNum var answerContent = '' if (!self.alreadySave && self.isSubjectInfoToCard) { answerContent = self.editorAreaOriginContent[questionNum] }else { // $(self.editorAreaOriginContent[questionNum]).find('img').each(function () { // if(!$(this).hasClass('gsImgLatex') && $(this).attr('data-type')===undefined){ // answerContent = answerContent + $(this).context.outerHTML; // } // }) if(item.matchPicture !==null){ answerContent = answerContent +"请勿重复生成
', ensureText: '确定', cancelText: '取消', sureCb: function () { self.batchGeneratePdf() } }) }, 0) }) } else { self.downLoadPdf() } return } //如果使用了二维码后台批量生成,不影响当前页面 var nowPosition = JSON.stringify(self.getPositions()) if (self.useQrCode) { if (nowPosition !== self.saveLocationPosition) { self.judgeHasPrintClass(function () { self.savePrintPosition('printcontent', function () { self.modal.init({ title: '批量生成', content: '该操作会把该场考试下面的所有班级学生考试模板进行批量生成', sureCb: function () { self.batchGeneratePdf() // self.resetExamStudentStatus(function(){ // }) } }) }) }) } else { self.judgeHasPrintClass(function () { setTimeout(function () { self.modal.init({ title: '批量生成', content: '该操作会把该场考试下面的所有班级学生考试模板进行批量生成', sureCb: function () { // self.resetExamStudentStatus(function(){ // }) self.batchGeneratePdf() } }) }, 0) }) } } else { //保存状态不用重新执行保存逻辑直接下载或者批量生成 if (!self.isCanEditCard) { self.downLoadPdf() return } if (nowPosition !== self.saveLocationPosition) { self.judgeHasPrintClass(function () { self.savePrintPosition('printcontent', function () { self.downLoadPdf() }) }) } else { self.downLoadPdf() } } }) //答题卡布局 //选择纸张 new RadioBoxItem($('#paperOptions'), function ($radioItem, status) { if(ueEditor!=null &&ueEditor.key!=undefined){ self.saveUeditor(ueEditor,topicEl) } var paper = $radioItem.attr('data-paper') self.paper = paper self.linkageForPaper(paper) }) //选择排版方向 new RadioBoxItem($('#paperDirection'), function ($radioItem, status) { var direction = $radioItem.attr('data-direction') self.direction = direction self.setPageWidthHeightForDirection(direction) self.linkageForDirection(self.config.direction[direction]) }) //选择分栏 self.$layoutItem.click(function () { var column = +$(this).attr('data-column') //|| $(this).hasClass('current') if ($(this).hasClass('disabled')) return $(this).addClass('current').siblings().removeClass('current') self.columns = column self.initPrintContentArea() }) //选择是否有装订线 new RadioBoxItem($('#hasBindingLine'), function ($radioItem, status) { var bindingLineStatus = $radioItem.attr('data-value') === 'yes' self.hasBindingLine = bindingLineStatus self.ifBindingLine() }) //选择是否显示信息栏 new RadioBoxItem($('#hasPaperMsg'), function ($radioItem, status) { var bindingPaperMsgStatus = $radioItem.attr('data-value') === 'yes' self.hasPaperMsg = bindingPaperMsgStatus self.isShowPaperMsg() }) //信息栏弹窗配置 new CheckBoxItem( $('#examInfoConfig'), function () { }, self.selExamInfoStyle.bind(self) ) //信息栏设置 $('#printcontent').on('click', '.btn-examInfo', function () { if (!self.isCanEditCard) return $('#examInfoEditDialog').show() }) $('#examInfoEditDialog').on('click', '.btn-hide-dialog', function () { $('#examInfoEditDialog').hide() }) $('#examInfoEditDialog').on('click', '.btn-save-examInfo', function () { $('#examInfoEditDialog').hide() self.showExamInfoHtml(); self.getSaveSubjectInfo(self.questionMap) }) $('.opratorArea').on('mouseover', '.hgc_notice', function (e) { let el = e.target let noticeEl = $(this).parent('.notice-item').find('.noticeContent'); let triangleEl = $(this).parent('.notice-item').find('.noticeContent').find('b'); $(noticeEl).show(); let noticeH = $(noticeEl).get(0).offsetHeight let noticeW = $(noticeEl).get(0).offsetWidth let { top, left } = el.getBoundingClientRect(); $(noticeEl).css('top', top - noticeH - 10 + 'px') $(noticeEl).css('left', left - noticeW / 2 + 'px'); $(triangleEl).css('top', top - 10 + 'px'); $(triangleEl).css('left', left + 'px'); }) $('.opratorArea').on('mouseout', '.hgc_notice', function (e) { let noticeEl = $(this).parent('.notice-item').find('.noticeContent'); $(noticeEl).hide(); }) //考号配置 new CheckBoxItem( $('#examNumberConfig'), function () {}, self.selExamNumberStyle.bind(self) ) //是否使用二维码 new Switch($('#useQrCode'), function (status) { var $examNumberConfigOptions = $('#examNumberConfig .h_checkItem') var $examNumberLayout = $('.examNumberLayout') var $downLoadBtn = $('#downLoadBtn') var $ewmTips = $('#ewmTips') self.useQrCode = status $downLoadBtn.html(status ? '生成' : '下载') $examNumberConfigOptions.each(function () { $(this)[status ? 'addClass' : 'removeClass']('disabled') }) $('.className').html(status ? self.tpls.systemClassNoticeInfoTpl : '') $('.examineeName').html(status ? self.tpls.systemNameNoticeInfoTpl : '') $('.bindLineClassName').html( status ? self.tpls.systemClassNoticeInfoForLineTpl : '' ) $('.bindLineExamineeName').html( status ? self.tpls.systemNameNoticeInfoForLineTpl : '' ) self.editNoticeDetail(status,self.cardStatus) $examNumberLayout[status ? 'addClass' : 'removeClass']('useqrcode') $ewmTips.css('display', status ? 'flex' : 'none') self.changePrintArea(self.$firstPageContent) }) //单模块设置 $('#printcontent').on('click', '.settingBtn', function () { if (!self.isCanEditCard) return var $this = $(this) var type = $this.attr('data-type') //填空 if (type === 'fillInBlank') { self.fillInBlankSet($this) //选择 单选-多选 } else if (~type.indexOf('Select')) { self.selectSetLayout($this, type) } else { self.shortAnswerSet($this) } }) // 给模块标题设置高度 $('#printcontent').on('click', '.answerModule h3', function () { $(this).css('height','auto') }) // 学校栏编辑状态 $('#printcontent').on('click', '.input-examInfo', function () { if (!self.isCanEditCard){ $('.input-examInfo').attr("readonly","readonly"); } else { $('.input-examInfo').removeAttr("readonly"); $('.input-examInfo.fraction').attr("readonly","readonly"); } }) // 图片拖拽 // $('#printcontent').on('click', 'img', function () { // if (!self.isCanEditCard) return // // }) // // $('div').mousedown(function(e) { // // e.pageX // var positionDiv = $(this).offset(); // var distenceX = e.pageX - positionDiv.left; // var distenceY = e.pageY - positionDiv.top; // //alert(distenceX) // // alert(positionDiv.left); // // $(document).mousemove(function(e) { // var x = e.pageX - distenceX; // var y = e.pageY - distenceY; // // if (x < 0) { // x = 0; // } else if (x > $(document).width() - $('div').outerWidth(true)) { // x = $(document).width() - $('div').outerWidth(true); // } // // if (y < 0) { // y = 0; // } else if (y > $(document).height() - $('div').outerHeight(true)) { // y = $(document).height() - $('div').outerHeight(true); // } // // $('div').css({ // 'left': x + 'px', // 'top': y + 'px' // }); // }); // // $(document).mouseup(function() { // $(document).off('mousemove'); // }); // }); function isPx(str) { return /^\d+$/.test(str) } document.addEventListener( 'error', function (e) { var elem = e.target if (elem.tagName.toLowerCase() === 'img') { var oh = $(elem).attr('height') var ow = $(elem).attr('width') if (!isPx(oh) || !isPx(ow)) return var h = parseInt($(elem).attr('height')) var w = parseInt($(elem).attr('width')) var hmm = self.unitConversion.pxConversionMm(h) var wmm = self.unitConversion.pxConversionMm(w) $(elem).attr( 'style', $(elem).attr('style') + ';height:' + hmm + 'mm !important;width:' + wmm + 'mm !important;' ) } }, true ) document.addEventListener( 'load', function (e) { var elem = e.target if ( elem.tagName.toLowerCase() === 'img' && typeof $(elem).attr('word_img') === 'string' ) { var h = parseInt($(elem).attr('height')) var w = parseInt($(elem).attr('width')) var hmm = self.unitConversion.pxConversionMm(h) var wmm = self.unitConversion.pxConversionMm(w) $(elem).attr( 'style', $(elem).attr('style') + ';height:' + hmm + 'mm !important;width:' + wmm + 'mm !important;' ) } }, true ) self.eventForFormula() }, //公式编辑器相关事件 eventForFormula: function () { var self = this var curEditorFormula = null $('body').on('click', '.kfformula,.gsImgLatex', function () { if (!self.isCanEditCard) return self.formulaing = true $('#formulaBox').show() curEditorFormula = $(this) var imgLatex = $(this).attr('data-latex') || $(this).attr('src').split('?')[1] var latexUse = unescape(imgLatex) //'\left\{ {\left( {x\;,\;y} \right)\left| {y = 2x - 1} \right.} \right\}'// if (window.kfe) { window.kfe.execCommand('render', latexUse || '\\placeholder') } else { window.factory = window.kf.EditorFactory.create( $('#kfEditorContainer')[0], { render: { fontsize: 24 }, resource: { path: './js/kityformula/resource/' } } ) window.factory.ready(function (KFEditor) { KFEditor.execCommand('render', latexUse || '\\placeholder') KFEditor.execCommand('focus') window.kfe = KFEditor }) $('#kf-formula-ensure')[0].onclick = function () { window.kfe.execCommand('get.image.data', function (data) { var latex = encodeURIComponent(window.kfe.execCommand('get.source')) $.post( self.apis.getMathtexApi, { mathtex: window.kfe.execCommand('get.source') }, function (res) { var newh = self.unitConversion.pxConversionMm(res.height) var neww = self.unitConversion.pxConversionMm(res.width) var newLatexImg = '' curEditorFormula[0].outerHTML = newLatexImg.substitute({ url: res.url, latex: latex, newh: newh, neww: neww }) } ) return true }) $('#formulaBox').hide() self.formulaing = false return false } $('#kf-formula-cancel') .off('click') .click(function () { $('#formulaBox').hide() self.formulaing = false }) } }) }, changeCardEditStatus: function () { var self = this $('#dtkName textarea').prop('disabled', !self.isCanEditCard) $('#saveBtn').html(self.isCanEditCard ? '保存' : '编辑') $('#downLoadBtn')[self.isCanEditCard ? 'addClass' : 'removeClass']( 'disabled' ) //右侧操作栏目 $('#disabledCover')[self.isCanEditCard ? 'hide' : 'show']() //题干信息 $('.objectiveItem').each(function () { $(this).prop('contenteditable', self.isCanEditCard) }) //编辑器 for (var editorId in self.editorArea) { self.editorArea[editorId].$textElem.attr( 'contenteditable', self.isCanEditCard ) } //标题 $('.answerModule h3').each(function () { $(this).prop('contenteditable', self.isCanEditCard) }) }, //检测是否有已经生成的答题卡 judgeHasPrintClass: function (cb) { var self = this if (self.printClassStatus) { self.modal.init({ title: '批量生成', content: '保存后,会重置原答题卡数据,将恢复班级/学生的打印状态,且可能会导致已打印出的答题卡扫描无效,请谨慎操作!', sureCb: function () { cb && cb() } }) } else { cb && cb() } }, //根据选择排版方向设置答题卡的视觉排版宽高 setPageWidthHeightForDirection: function (direction) { var self = this var isVertical = direction === 'vertical' //设置横竖版面 self.config[isVertical ? 'width' : 'height'] = self.configOrigin.width self.config[isVertical ? 'height' : 'width'] = self.configOrigin.height }, //点击选择纸张联动,纸张方向和纸张分栏选择 linkageForPaper: function (paper) { var self = this // '8K': { // width: 267, // height: 390, // direction: { // horizontal: [2, 3] // } // }, //layoutList self.config = simpleCopy(sizeConfig[paper]) self.configOrigin = simpleCopy(sizeConfig[paper]) var directions = self.config.direction var isPaperDirectionStop = false $('#paperDirection .h_radioItem').each(function () { var direction = $(this).attr('data-direction') if (direction in directions) { $(this).removeClass('disabled') if (!isPaperDirectionStop) { isPaperDirectionStop = true $(this).trigger('click') } } else { $(this).addClass('disabled') } }) }, //点击选择纸张方向联动 分栏选择 linkageForDirection: function (columns) { var self = this var isLayoutItemStop = false self.$layoutItem.each(function () { var $this = $(this) var dataColumn = +$this.attr('data-column') if (~columns.indexOf(dataColumn)) { $this.removeClass('disabled') if (!isLayoutItemStop) { isLayoutItemStop = true $this.trigger('click') } } else { $this.addClass('disabled') } }) }, //选择题 selectSetLayout: function ($this, type) { var self = this var memoryDirection = $this.closest('.answerModule').attr('data-direction') var directionCheckMap = { vertical: 'verticalChecked', horizontal: 'horizontalChecked' } var substituteData = {} substituteData[directionCheckMap[memoryDirection]] = 'checked' var tempDirection = '' self.modal.init({ title: '选择题设置', content: self.tpls.selectSetTpl.substitute(substituteData), afterCb: function () { new RadioBoxItem($('#selectDirection'), function ($radioItem, status) { var direction = $radioItem.attr('data-value') tempDirection = direction }) }, sureCb: function () { self.selectStyleChange($this, type, tempDirection) } }) }, selectStyleChange: function ($this, type, direction) { var self = this var curPageIndex = $this.closest('.pageContent').index() + 1 var $selectModule = $this.closest('.single-select') var $curPage = $this.closest('.pageContent') self[type].direction = direction function setDirection($selectModule) { if (!$selectModule.hasClass(direction)) { var isHorizontal = direction === 'horizontal' $selectModule .removeClass(isHorizontal ? 'vertical' : 'horizontal') .addClass(isHorizontal ? 'horizontal' : 'vertical') .attr('data-direction', direction) } curPageIndex++ if (self[type]['page' + curPageIndex]) { var $nextPage = $('.pageContent').eq(curPageIndex - 1) var $nextPageFirstSelect = $nextPage.find('.single-select').eq(0) setDirection($nextPageFirstSelect) } } setDirection($selectModule) self.changePrintArea($curPage) }, //填空题设置 fillInBlankSet: function ($this) { var self = this var $subjectCol = $this.siblings('.subjectCol') var columnSelectedMap = { 1: 'columnOneSelected', 2: 'columnTwoSelected', 3: 'columnThreeSelected' } var rowLineHeightSelectedMap = { 25: 'rowLineOneSelected', 30: 'rowLineTwoSelected', 35: 'rowLineThreeSelected', 40: 'rowLineFourSelected', 45: 'rowLineFiveSelected', 50: 'rowLineSixSelected' } var scoreSelectedMap = { '2/3/5': 'scoreOneSelected', '2/3/4/6': 'scoreTwoSelected', '2/4': 'scoreThreeSelected' } var memoryColumn = $subjectCol.attr('data-column') || 1 var memoryColumnRowLineHeight = $subjectCol.attr('data-rowLineHeight') || 40 var memoryScoreStyle = $subjectCol.attr('data-scoreStyle') || '' var maxScoreArr = $subjectCol .find('.subjectItem') // .attr('data-fullScore') // var maxScore = $subjectCol // .children('.subjectItem') // .eq(0) // .attr('data-fullScore') var substituteData = {} substituteData[columnSelectedMap[memoryColumn]] = 'selected' substituteData[rowLineHeightSelectedMap[memoryColumnRowLineHeight]] = 'selected' substituteData[scoreSelectedMap[memoryScoreStyle]] = 'selected' for (var scoreFormat in scoreSelectedMap) { let isDisabled = false for( let i=0; i