print_index.js 265 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394
  1. var env = (function (defaultEnv) {
  2. var isProduction = ~location.href.indexOf('schcur.com')
  3. var isLocal =
  4. ~location.href.indexOf('localhost') || ~location.href.indexOf('192.168') || ~location.href.indexOf('xg.xueping.com')
  5. if (isLocal) return defaultEnv
  6. if (isProduction) return 'online'
  7. return 'testing'
  8. })('localxx');
  9. //环境配置
  10. var envConfig = envConfigs[env]
  11. //登陆态'/username/pc002/time/1567499908/sig/7d9ca3d40b7422b759ce9a7e08b2de20/sessionid/session_93482f6cf1c865b7a2e2793c66f2c595'
  12. var loginStatus = envConfig.loginStatus
  13. //当前环境域名 'http://192.168.1.51/index.php'
  14. var domain = envConfig.domain
  15. //当前环境转pdf所需css 相对路径
  16. var printCssPath = envConfig.printCssPath
  17. //当前环境转pdf所要请求的域
  18. var printPdfIp = envConfig.printPdfIp
  19. //试题编辑区域高度
  20. var oldModH =0
  21. var ueEditor = null
  22. var topicEl = null
  23. var Print = {
  24. apis: {
  25. //获取答题卡信息
  26. getTopicsDetailAPi:
  27. domain + '/print/getPaperWithTopicsDetails' + loginStatus,
  28. //保存答题卡信息
  29. saveTopicsDetailsApi: domain+'/print/saveCardOnline' + loginStatus,
  30. //保存为pdf
  31. htmlToPdfApi: domain + '/print/htmlToPdf' + loginStatus,
  32. //上传图片===富文本编辑试题的时候需要
  33. uploadFileApi: domain + '/online/uploadFile' + loginStatus,
  34. //考试学生重置接口
  35. /**
  36. schoolId
  37. examGroupId
  38. 两个参数
  39. */
  40. resetExamStudentApi:
  41. domain + '/rest/answer_card_online/resetStudentStatus' + loginStatus,
  42. //下载pdf
  43. downPdfApi: domain + '/print/downOnlinePdf' + loginStatus,
  44. downOnlinePdfApi: domain + '/third/download' + loginStatus,
  45. getPdfApi: '//' + printPdfIp + '/getPdf',
  46. getOnlinePdfApi: domain + '/third/getOnlinePdf' + loginStatus,
  47. delPdfApi: '//' + printPdfIp + '/delPdf',
  48. batchGeneratePdfApi: '//' + printPdfIp + '/batchGeneratePdf',
  49. //latex 转 公式图片
  50. getMathtexApi: domain + '/print/ajaxGetMathtex' + loginStatus,
  51. // php生成pdf
  52. generatePhpPdf:domain +'/print/sendCreateOnlineAllStudents'+ loginStatus
  53. },
  54. init: function (config) {
  55. this.modal = hgc_modal
  56. //需要同时保存用来记忆布局的有:纸张规格,纸张方向,是否有装订线,考号配置(填涂考号or条形码,是否使用二维码)
  57. this.paper = 'A3'
  58. this.direction = 'horizontal'
  59. //装订线
  60. this.hasBindingLine = false
  61. //信息栏
  62. this.hasPaperMsg = true
  63. //考号配置
  64. this.examInfoConfig = {
  65. //时间
  66. wpTimes: true,
  67. //满分
  68. fullScore: true,
  69. //命卷人
  70. wpAuthor: true,
  71. //审核人
  72. wpReviewer: true
  73. }
  74. this.examInfoConfigText = {
  75. //时间
  76. wpTimes: '',
  77. //满分
  78. fullScore: '',
  79. //命卷人
  80. wpAuthor: '',
  81. //审核人
  82. wpReviewer: ''
  83. }
  84. //考号配置
  85. this.examNumberConfig = {
  86. //条形码
  87. barCode: true,
  88. //准考证号
  89. ticketNumber: true
  90. }
  91. //是否使用二维码
  92. this.useQrCode = false
  93. // 是否是学校答题卡 0 系统 1学校
  94. this.cardStatus = 0
  95. this.config = simpleCopy(config[this.paper])
  96. this.configOrigin = simpleCopy(this.config)
  97. //分栏
  98. this.columns = 2
  99. //页面页码计算
  100. //当前分页
  101. this.currentPage = 1
  102. //总分页
  103. this.totalPage = 1
  104. //当前纸张-包括正反两面 ceil(totalPage/(column*2))
  105. this.currentPaper = 0
  106. //当前纸张正面1正面2 反面1 反面2
  107. this.currentPaperPage = 0
  108. //初始化页面数据
  109. /**
  110. * 核心功能模块盒模型设计
  111. */
  112. //解答区域--最小高度
  113. this.moduleMinHeight = 10
  114. //解答区域--默认高度
  115. this.moduleDefaultHeihgt = 54
  116. //解答区域--左右内边距之和
  117. this.modulePaddingSide = 20
  118. //解答区域--上内边距
  119. this.modulePaddingTop = 42
  120. //解答区域--下内边距
  121. this.modulePaddingBottom = 12
  122. this.modulePadding = this.modulePaddingTop + this.modulePaddingBottom
  123. //每个分页答题区域的--上下内边距
  124. this.pagePadding = 50
  125. //这个答题区域布局外边距
  126. this.layoutPadding = 20
  127. //每页的左右间距
  128. this.pagePaddingSide = 30
  129. //用于页面 mm 和 px 之间单位转换
  130. //96dpi 打印出来300dpi纸张上面的的比例
  131. this.dpiRadio = 1
  132. this.unitConversion = new UnitConversion()
  133. this.pageHeight = this.unitConversion.mmConversionPx(this.config.height)
  134. this.pageWidth = this.unitConversion.mmConversionPx(this.config.width)
  135. //富文本编辑 ==>> 全局富文本编辑构造函数
  136. this.EDITOR = window.wangEditor
  137. //富文本菜单配置文件
  138. this.EDITOR_CONFIG = [
  139. 'underline', // 下划线
  140. 'justify', // 对齐方式
  141. 'image', // 插入图片
  142. 'table', // 表格
  143. 'undo', // 撤销
  144. 'redo', // 重复
  145. 'lineheight',
  146. 'formula'
  147. ]
  148. this.UEditorConfig = {
  149. toolbars: [[
  150. 'formatmatch','undo', 'redo','fontsize', 'bold','italic', 'underline','subscript','superscript',
  151. 'removeformat', 'lineheight', 'justifyleft','justifycenter', 'justifyright', 'justifyjustify',
  152. 'insertimage','imagenone', 'imageleft', 'imageright', 'horizontal', 'spechars',
  153. 'inserttable', 'deletetable', 'insertparagraphbeforetable', 'insertrow', 'deleterow',
  154. 'insertcol', 'deletecol', 'mergecells','kityformula','chineselattice','horizontalline'
  155. ]],
  156. enableAutoSave:false,
  157. imagePopup:false,
  158. focus:true,
  159. allHtmlEnabled:true,
  160. initialFrameHeight: 140,
  161. UEDITOR_HOME_URL: '/js/ueditor/',
  162. }
  163. //题型配置
  164. this.questionTypeMapForPhp = {
  165. //0单选
  166. singleSelect: 0,
  167. //8多选
  168. moreSelect: 8,
  169. //填空
  170. fillInBlank: 3,
  171. //解答
  172. answer: 1,
  173. //选做
  174. chooseAnswer: 2,
  175. //必做题
  176. mustAnswer: 27
  177. }
  178. //类型 1 单选 2 多选 5 填空 7 解答 17 选做
  179. this.questionTypeMapForC = {
  180. 1: 'singleSelect',
  181. 2: 'moreSelect',
  182. 5: 'fillInBlank',
  183. 7: 'shortAnswer',
  184. 27: 'mustAnswer',
  185. 17: 'chooseAnswer'
  186. }
  187. //题型名称映射
  188. this.questionNameMap = {
  189. singleSelect: '单选题',
  190. moreSelect: '多选题',
  191. fillInBlank: '填空题',
  192. shortAnswer: '解答题',
  193. chooseAnswer: '选做题',
  194. mustAnswer: '必做题'
  195. }
  196. //题型数据存储
  197. this.questionMap = []
  198. //全局groupId
  199. this.examGroupId = examGroupId
  200. this.examIds = examIds
  201. this.schoolId = schoolId
  202. //当前区域定位信息,用来简单判断两次保存是否有改动,来防止重复提交数据
  203. this.saveLocationPosition = {}
  204. //首次保存
  205. this.alreadySave = false
  206. //当前答题卡模块是否在编辑状态--是否可以 编辑当前答题卡模板
  207. /**
  208. * 刚进页面
  209. * 1如果是之前没有保存,就属于编辑状态
  210. * 2如果之前有保存过,就属于保存在状态(页面所有操作按钮不可操作,需要点击编辑才可操作)
  211. * 页面中
  212. * 1如果点击了保存,就是保存状态
  213. */
  214. this.isCanEditCard = true
  215. //是否已经有打印的班级
  216. this.printClassStatus = false
  217. //题卡合一 的type值
  218. this.subjectCardToOneType = 1
  219. //是否题卡合一
  220. this.isSubjectInfoToCard = false
  221. //替换富文本没用内容
  222. this.replaceEditorRegexp = /(<p><br><\/p>)|(<div><br><\/div>)/g
  223. //所有打分框的分值上线标准
  224. this.answerScoreLimitKeyArr = [15, 16, 29, 49]
  225. //下载PDFUrl
  226. this.downPdfUrl = ''
  227. this.examQuestions = []
  228. this.initDom()
  229. //初始化打印面积
  230. this.initPageStyle()
  231. //初始化页面渲染
  232. this.initPage()
  233. //解答题图片移动
  234. this.shortAnswerImgPositionChange()
  235. //显示编辑器
  236. this.showUeditor()
  237. },
  238. tpls: PRINT_TPL,
  239. initPageStyle: function () {
  240. var self = this
  241. var $headEL = $('head')
  242. var $styleTag = $('#pageSizeStyle')
  243. self.pageHeight = self.unitConversion.mmConversionPx(self.config.height)
  244. self.pageWidth = self.unitConversion.mmConversionPx(self.config.width)
  245. if ($styleTag.length) $styleTag.remove()
  246. var initPrintPageStyle = self.tpls.printPageStyle.substitute({
  247. pageWidth: self.pageWidth / self.columns,
  248. pageHeight: self.pageHeight
  249. })
  250. $headEL.append(initPrintPageStyle)
  251. },
  252. // 初始化打印区域宽高 mm 转 px
  253. //纸张方向,纸张大小,纸张分栏
  254. initPrintContentArea: function () {
  255. var self = this
  256. self.initPageStyle()
  257. //列举属于小版面的配置,统一使用小版面的布局
  258. var isHorizontal = self.direction === 'horizontal'
  259. var isLayoutWhite = ~[
  260. 'A3-3',
  261. 'A4-2',
  262. 'A4-3',
  263. '8Ks-3',
  264. '8Kb-3',
  265. '16K-2',
  266. '16K-3'
  267. ].indexOf(self.paper + '-' + self.columns)
  268. var isSmallLayout = isHorizontal && isLayoutWhite
  269. self.$firstPageContent[isSmallLayout ? 'addClass' : 'removeClass'](
  270. 'smallLayout'
  271. )
  272. //判断第一页有没有题型模块,如果第一页没有题型模块,则直接跳到第二页做题型重排处理
  273. var hasSurplus = false
  274. var $secondPage = self.$firstPageContent.find('.examNumberLayout').next()
  275. var $secondPageFirstModule = $secondPage.find('.module').eq(0)
  276. var secondPageFirstModuleType = $secondPage
  277. .find('.answerModule')
  278. .eq(0)
  279. .attr('data-type')
  280. if (
  281. !$secondPage.length ||
  282. !$secondPageFirstModule.length ||
  283. !secondPageFirstModuleType
  284. ) {
  285. hasSurplus = true
  286. } else {
  287. var curpageSurplusHeight = self.getCurPageSurplusHeight(
  288. self.$firstPageContent
  289. )
  290. var nextPageFirstModuleHeight = self.getNextPageFirstModuleHeight(
  291. $secondPageFirstModule,
  292. secondPageFirstModuleType
  293. )
  294. hasSurplus = curpageSurplusHeight > nextPageFirstModuleHeight
  295. }
  296. self.changePrintArea(
  297. hasSurplus ? self.$firstPageContent : self.$firstPageContent.next()
  298. )
  299. self.editNoScoringWidth()
  300. },
  301. //render page
  302. initPage: function () {
  303. var self = this
  304. $('#hgc_print').height($(window).height())
  305. self.getTopicDetails()
  306. },
  307. getTopicDetails: function () {
  308. var self = this
  309. //如果之前保存过,则需要记忆之前的答题卡排版
  310. $.post(
  311. self.apis.getTopicsDetailAPi,
  312. { examGroupId: self.examGroupId },
  313. function (res) {
  314. res = JSON.parse(res)
  315. if (res.success) {
  316. self.downPdfUrl = res.online_card_pdf
  317. self.examQuestions = res.object.questions
  318. //判断是否已经保存过,如果已经保存过,需要记忆布局
  319. self.alreadySave = res.position ? true : false
  320. //判断是否题卡合一
  321. self.isSubjectInfoToCard =
  322. res.paperTplType == self.subjectCardToOneType
  323. if (self.alreadySave) {
  324. var memoryPosition = JSON.parse(res.position)
  325. //之前题文信息存放直接单独存放stemInfo字段,现在直接放在position里面,做一个容错处理的判断
  326. if(res.stem_info){
  327. memoryPosition.stemInfo = res.stem_info
  328. }
  329. self.saveLocationPosition = res.position
  330. self.memoryColumns = memoryPosition.columns
  331. //保存过的答题卡进来默认都是不可编辑的
  332. self.isCanEditCard = false
  333. //是否已经有打印班级
  334. self.printClassStatus = res.printClassStatus
  335. self.initPrintContentArea()
  336. self.renderPage(res, memoryPosition)
  337. self.memoryLayout(memoryPosition)
  338. self.changeCardEditStatus()
  339. } else {
  340. self.isCanEditCard = true
  341. self.renderPage(res)
  342. self.changeCardEditStatus()
  343. }
  344. let arr = $('#printcontent').find('img');
  345. let imgLoadNumber = 0;
  346. if(self.isCanEditCard){
  347. for (let i=0;i<arr.length;i++){
  348. arr.eq(i).load(function (){
  349. let dom = $(this).parents('.pageContent')
  350. self.changePrintArea(dom)
  351. $('#printcontent').find('img').load(function (event){
  352. imgLoadNumber = imgLoadNumber++;
  353. if(imgLoadNumber>9){
  354. return false
  355. }
  356. let dom = $(this).parents('.pageContent')
  357. $(this).parents('.editorContent').height('auto');
  358. self.changePrintArea(dom)
  359. })
  360. })
  361. }
  362. }
  363. self.cardStatus = res.card_status;
  364. self.editNoticeDetail(self.useQrCode,res.card_status)
  365. } else {
  366. hgc_layer.msg('获取试卷题目信息失败')
  367. }
  368. }
  369. )
  370. },
  371. editNoticeDetail: function (qrStatus,cardStatus) {
  372. let noticeDetailMsgBoxXT =
  373. '<p>1、考生务必正确书写班级、姓名,请填涂系统准考证号。</p>' +
  374. '<p>2、考生务必用2B铅笔填涂。</p>' +
  375. '<p>3、考生务必在答题卡指定位置作答,并保持卷面整洁。</p>' +
  376. '<p>4、如需要条形码,则考生务必要在指定位置正确贴好条形码。</p>' +
  377. '<p>5、教师务必使用红笔阅卷。</p>';
  378. let noticeDetailMsgBoxXX =
  379. '<p>1、考生务必正确书写班级、姓名,请填涂学校准考证号。</p>' +
  380. '<p>2、考生务必用2B铅笔填涂。</p>' +
  381. '<p>3、考生务必在答题卡指定位置作答,并保持卷面整洁。</p>' +
  382. '<p>4、如需要条形码,则考生务必要在指定位置正确贴好条形码。</p>' +
  383. '<p>5、教师务必使用红笔阅卷。</p>';
  384. let noticeDetailMsgBoxQR =
  385. '<p>1、考生务必用2B铅笔填涂。</p>' +
  386. '<p>2、考生务必在答题卡指定位置作答,并保持卷面整洁。</p>' +
  387. '<p>3、如需要条形码,则考生务必要在指定位置正确贴好条形码。</p>' +
  388. '<p>4、教师务必使用红笔阅卷。</p>';
  389. if(qrStatus){
  390. $('#noticeDetailMsgBox').html(noticeDetailMsgBoxQR)
  391. } else {
  392. $('#noticeDetailMsgBox').html(cardStatus==0 ? noticeDetailMsgBoxXT : noticeDetailMsgBoxXX)
  393. }
  394. },
  395. /*
  396. --------------------------------------------------------------------------------------------------------------------
  397. 初始页面布局功能开始
  398. ---------------------------------------------------------------------------------------------------------------------
  399. */
  400. renderPage: function (renderJSON, memoryPosition) {
  401. var self = this
  402. memoryPosition = memoryPosition || null
  403. self.renderExamBaseInfo(renderJSON.object)
  404. self.renderSubjectInfo(renderJSON.object.questions, memoryPosition)
  405. if (!self.alreadySave) {
  406. //重新定义超出部分布局
  407. self.changePrintArea(self.$firstPageContent)
  408. }
  409. self.bindEvent()
  410. self.initEvent()
  411. },
  412. //渲染答题卡基本信息 准考证号、名称、考试时间等
  413. renderExamBaseInfo: function (examInfo) {
  414. var self = this
  415. //答题卡题目类型
  416. self.$dtkName.val(examInfo.paperName)
  417. // var examInfoHtml = self.tpls.examInfoTpl.substitute(examInfo)
  418. // $('#examInfo').html(examInfoHtml)
  419. self.examInfoConfigText.wpTimes = examInfo.wpTimes
  420. self.examInfoConfigText.fullScore = examInfo.fullScore
  421. self.examInfoConfigText.wpAuthor = examInfo.wpAuthor
  422. self.examInfoConfigText.wpReviewer = examInfo.wpReviewer
  423. self.showExamInfoHtml()
  424. //准考证号信息
  425. self.renderExamNumberInfo(examInfo)
  426. },
  427. //准考证号信息
  428. renderExamNumberInfo: function (examInfo) {
  429. var self = this
  430. //准考证号类型 1学校准考证 0系统准考证
  431. self.school_card_status = examInfo.school_card_status
  432. //准考证号长度
  433. var school_card_length = examInfo.school_card_length
  434. var examNumberHtml = ''
  435. var examNumberForOnlyCodeHtml = ''
  436. for (var colIndex = 0; colIndex < school_card_length; colIndex++) {
  437. examNumberHtml += self.tpls.examNumberItemTpl
  438. examNumberForOnlyCodeHtml += '<span></span>'
  439. }
  440. $('#hgc_examNumber .ticketNumber').html(examNumberHtml)
  441. $('#hgc_examNumberForOnlyBarcode .ticketNumber p').html(
  442. examNumberForOnlyCodeHtml
  443. )
  444. },
  445. renderSubjectDataFormat: function (questions) {
  446. var self = this
  447. //题型
  448. /**
  449. *
  450. "questionTypeId": 1,
  451. "fullScore": 5,
  452. "optionCount": 4,
  453. "questionNum": "1",
  454. "answer": "D"
  455. */
  456. var questionClassify = (self.questionMap = questions.reduce(
  457. function (questionMap, item) {
  458. var questionMapKey = self.questionTypeMapForC[item.questionTypeId]
  459. var questionMapItem = questionMap[questionMapKey]
  460. if (questionMapItem) {
  461. questionMapItem.push(item)
  462. } else {
  463. questionMap[questionMapKey] = [item]
  464. }
  465. return questionMap
  466. },
  467. {
  468. singleSelect: [],
  469. moreSelect: [],
  470. fillInBlank: [],
  471. shortAnswer: [],
  472. chooseAnswer: [],
  473. mustAnswer: []
  474. }
  475. ))
  476. var titleTPls = {
  477. singleSelect:
  478. '、选择题<span>(本大题共{subjectCount}小题,{subjectPointText}共{totalPoint}分。在每小题给出的四个选项中,只有一项是符合题目要求的。把答案填涂在答题卡上。)</span>',
  479. moreSelect:
  480. '、多选题<span>(本大题共{subjectCount}小题,{subjectPointText}共{totalPoint}分。在每小题给出的四个选项中,有两项及以上是符合题目要求的。把答案填涂在答题卡上。)</span>',
  481. fillInBlank:
  482. '、填空题<span>(本大题共{subjectCount}小题,{subjectPointText}共{totalPoint}分。把答案填写在答题卡相应的题号后的横线上。)</span>',
  483. shortAnswer:
  484. '、解答题<span>(本大题共{subjectCount}小题,{subjectPointText}共{totalPoint}分。解答写出相应的文字说明、证明过程或演算步骤。)</span>',
  485. chooseAnswer:
  486. '、选做题<span>(本题包括{chooseOption}{chooseOptionLength}小题,请选定其中{chooseCount}小题,并在相应的答题区域内作答,请用2B铅笔涂黑(示例:■)。若多做,则按作答的前一小题评分。解答应写出文字说明、证明过程或演算步骤。)</span>',
  487. mustAnswer:
  488. '、必做题<span>(本大题共{subjectCount}小题,{subjectPointText}共{totalPoint}分。解答写出相应的文字说明、证明过程或演算步骤。)</span>'
  489. }
  490. var objectiveTitleTpl = {
  491. singleSelect: '、选择题题文',
  492. moreSelect: '、多选题题文',
  493. fillInBlank: '、填空题题文'
  494. }
  495. //填空题,选择题超出控制数据
  496. var numberIndex = 0
  497. for (var type in questionClassify) {
  498. //当前分类
  499. var questionClassifyItem = questionClassify[type]
  500. if (!questionClassifyItem.length) continue
  501. numberIndex++
  502. var titleFormatData = {}
  503. var isChooseAnswer = type === 'chooseAnswer'
  504. var isMoreSelect = type === 'moreSelect'
  505. //选做题题干信息
  506. var chooseSubjectContent = ''
  507. //选做题标题特殊对待
  508. if (isChooseAnswer) {
  509. var chooseOptionLength = SectionToChinese(questionClassifyItem.length)
  510. var chooseOption = questionClassifyItem
  511. .map(function (questionItem, index) {
  512. let isP = questionItem.queBody.search('<p');
  513. let queBody = ''
  514. if(isP>1 || isP==-1){
  515. queBody = '<p>' + questionItem.queBody +'</p>'
  516. } else {
  517. queBody = questionItem.queBody
  518. }
  519. chooseSubjectContent +=
  520. '<div class="questionItemBody clearfix"><b>' +
  521. questionItem.questionNum +
  522. '、</b>' +
  523. queBody +
  524. '</div>'
  525. return String.fromCharCode(65 + index)
  526. }, [])
  527. .join(',')
  528. var chooseCount = SectionToChinese(questionClassifyItem[0].required)
  529. titleFormatData = {
  530. chooseOption: chooseOption,
  531. chooseCount: chooseCount === '二' ? '两' : chooseCount,
  532. chooseOptionLength:
  533. chooseOptionLength === '二' ? '两' : chooseOptionLength
  534. }
  535. } else {
  536. var subjectCount = questionClassifyItem.length
  537. var subjectPoint = questionClassifyItem[0].fullScore
  538. var totalPoint = 0
  539. var isSameScore = questionClassifyItem.every(function (item) {
  540. return item.fullScore === subjectPoint
  541. })
  542. var subjectPointText = ''
  543. if (isSameScore) {
  544. subjectPointText = '每小题{subjectPoint}分,'.substitute({
  545. subjectPoint: subjectPoint
  546. })
  547. totalPoint = subjectPoint * subjectCount
  548. } else {
  549. subjectPointText = questionClassifyItem.reduce((total, cur) => {
  550. total += '第{questionNum}题{fullScore}分,'.substitute(cur)
  551. totalPoint += cur.fullScore
  552. return total
  553. }, '')
  554. }
  555. titleFormatData = {
  556. subjectCount: subjectCount,
  557. subjectPoint: subjectPoint,
  558. totalPoint: totalPoint,
  559. subjectPointText: subjectPointText
  560. }
  561. }
  562. //如果需要题卡合一的话
  563. if (self.isSubjectInfoToCard && isChooseAnswer) {
  564. self.chooseAnswerObjective =
  565. '<div class="originSubjectInfo">' + chooseSubjectContent + '</div>'
  566. }
  567. //试卷大题默认title
  568. self[type + '-title'] =
  569. SectionToChinese(numberIndex) +
  570. titleTPls[type].substitute(titleFormatData)
  571. //题干信息title---只针对客观题
  572. if (objectiveTitleTpl[type]) {
  573. self[type + 'ObjectiveTitle'] =
  574. '<h3>' +
  575. SectionToChinese(numberIndex) +
  576. objectiveTitleTpl[type] +
  577. '</h3>'
  578. }
  579. self[type] = self[type] || {
  580. page2: [],
  581. page1: simpleCopy(questionClassifyItem)
  582. }
  583. }
  584. return questionClassify
  585. },
  586. titleHtml: function (title) {
  587. var self = this
  588. return title ? self.tpls.moduleTitleTpl.substitute({ title: title }) : ''
  589. },
  590. //渲染答题卡题目题型信息
  591. renderSubjectInfo: function (questions, memoryPosition) {
  592. var self = this
  593. //格式化题型题号信息
  594. var questionClassify = self.renderSubjectDataFormat(questions)
  595. //渲染右侧操作栏 题目列表信息
  596. self.renderSubjectListInfo(questionClassify)
  597. //保存题目定位点的时候 获取 题目数量 分数 等信息
  598. self.getSaveSubjectInfo(questionClassify)
  599. //批量渲染所有题干信息模块
  600. var dtkContentEl = $('.dtk-content')
  601. for (var subjectType in questionClassify) {
  602. if (subjectType === 'shortAnswer') {
  603. //或者一开始进来就是题卡合一
  604. if (!self.alreadySave && self.isSubjectInfoToCard) {
  605. self.renderObjective()
  606. //有记忆的时候先渲染题卡合一,主要是缓存原题干信息内容
  607. } else if (
  608. memoryPosition &&
  609. memoryPosition.stemInfo &&
  610. memoryPosition.stemInfo.length
  611. ) {
  612. self.renderObjective()
  613. }
  614. }
  615. if (!questionClassify[subjectType].length) continue
  616. self[subjectType + 'Render'](questionClassify[subjectType], dtkContentEl)
  617. }
  618. },
  619. //右侧题目列表模块-布局
  620. renderSubjectListInfo: function (questionClassify) {
  621. var self = this
  622. var nameMap = {
  623. singleSelect: '单选题',
  624. moreSelect: '多选题',
  625. fillInBlank: '填空题',
  626. shortAnswer: '解答题',
  627. chooseAnswer: '选做题',
  628. mustAnswer: '必做题'
  629. }
  630. var listItemTpl =
  631. '<div class="paper selOptions"><span class="name">{name}</span><div class="content">{quantityStart}~{quantityEnd}</div></div>'
  632. var listHtml = ''
  633. for (var name in questionClassify) {
  634. if (!questionClassify[name][0]) continue
  635. var quantityStart = +questionClassify[name][0].questionNum
  636. var quantityEnd = quantityStart + questionClassify[name].length - 1
  637. listHtml += listItemTpl.substitute({
  638. name: nameMap[name],
  639. quantityStart: quantityStart,
  640. quantityEnd: quantityEnd
  641. })
  642. }
  643. $('#subjectList').html(listHtml)
  644. },
  645. /**
  646. —————————————————————————————————————————————————————————————————————————————————————————————————————————————————————
  647. 客观题题干内容渲染 开始 —————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————
  648. */
  649. renderObjective: function (cb) {
  650. var self = this
  651. questionClassify = self.questionMap
  652. self.originStemInfos = []
  653. //,'shortAnswer','chooseAnswer','mustAnswer'
  654. var quesTypeOrder = ['fillInBlank', 'moreSelect', 'singleSelect']
  655. //判断第一次出现的分页
  656. var lastPageIndex
  657. var lastPageType
  658. quesTypeOrder.forEach(function (type) {
  659. if (lastPageType) return
  660. if (self[type]) {
  661. var pageIndex = Object.keys(self[type]).length
  662. function getLastPageIndex() {
  663. var pageData = self[type]['page' + pageIndex]
  664. if (pageData && pageData.length) {
  665. lastPageIndex = pageIndex
  666. lastPageType = type
  667. } else {
  668. pageIndex--
  669. getLastPageIndex()
  670. }
  671. }
  672. getLastPageIndex()
  673. }
  674. })
  675. //找到最后一个分页处理
  676. var $afterPage = $('.pageContent').eq(lastPageIndex - 1)
  677. var $afterContent = $afterPage.children('.dtk-content')
  678. var $afterModule
  679. //根据type 来判断题干信息该放在哪个元素后面
  680. if (lastPageType === 'fillInBlank') {
  681. $afterModule = $afterContent.children('.completion-topic')
  682. } else if (lastPageType === 'moreSelect') {
  683. $afterModule = $afterContent.children('.moreSelect')
  684. } else if (lastPageType === 'singleSelect') {
  685. $afterModule = $afterContent.children('.single-select:last()')
  686. }
  687. quesTypeOrder.forEach(function (quesType) {
  688. var quesTypeData = questionClassify[quesType]
  689. if (quesTypeData && quesTypeData.length) {
  690. self[quesType + 'StemRender'](quesTypeData, $afterModule)
  691. }
  692. })
  693. //图片加载时间
  694. self.judegeImgsLoaded('.objectiveItem')
  695. cb && cb($afterPage)
  696. },
  697. //公式自带的行内样式转换mm
  698. //type origin 原始高度 没有auto
  699. changeUnitForFormulaPic: function (parent, type) {
  700. var self = this
  701. parent = parent || $('.answerModule')
  702. parent.find('img').each(function () {
  703. var oh = $(this).attr('height')
  704. var ow = $(this).attr('width')
  705. if (!/^\d+$/.test(oh) || !/^\d+$/.test(ow)) return
  706. var widthMatch = $(this)[0].outerHTML.match(/width="(\d{1,3})"/) || [0, 0]
  707. var heightMatch = $(this)[0].outerHTML.match(/height="(\d{1,3})"/) || [
  708. 0,
  709. 0
  710. ]
  711. var pxWidth = +widthMatch[1]
  712. var pxHeight = +heightMatch[1]
  713. if (!pxWidth && !pxHeight) return
  714. //给你图片最大宽度的阀值
  715. var isMaxWidth = pxWidth > 430
  716. /**
  717. $(this).attr('style',originStyle+';width:'+mmWidth+';height:'+(isMaxWidth?'auto':mmHeight+'mm')+';vertical-align:middle;'+(isMaxWidth?'max-width:100%;':''))
  718. */
  719. var mmWidth = self.unitConversion.pxConversionMm(pxWidth) + 'mm'
  720. var mmHeight =
  721. type === 'origin' || !isMaxWidth
  722. ? self.unitConversion.pxConversionMm(pxHeight) + 'mm'
  723. : 'auto'
  724. var originStyle = $(this).attr('style') || ''
  725. $(this).attr(
  726. 'style',
  727. originStyle +
  728. ';width:' +
  729. mmWidth +
  730. ';height:' +
  731. mmHeight +
  732. ';max-width:100%;'
  733. )
  734. })
  735. },
  736. queBodyRegExp: /^<p([^<]*)>/,
  737. singleSelectStemRender: function (data, $afterModule) {
  738. var self = this
  739. var htmls = self.singleSelectObjectiveTitle
  740. var stemInfos = []
  741. data.forEach(function (item) {
  742. //一排排列几个
  743. //0一排一个 1一排4个 2一排两个',
  744. var columnNumber =
  745. typeof item.listType === 'number'
  746. ? !item.listType
  747. ? 1
  748. : item.listType === 1
  749. ? 4
  750. : 2
  751. : ''
  752. var columnClass = columnNumber ? 'column-' + columnNumber : ''
  753. var content = item.queBody.replace(
  754. self.queBodyRegExp,
  755. '<p' + RegExp.$1 + '><span>' + item.questionNum + '、</span>'
  756. )
  757. var optionsHtml =
  758. '<div class="optionObjectiveWrap clearfix ' + columnClass + '">'
  759. item.queOptions.forEach(function (option, index) {
  760. optionsHtml +=
  761. '<div class="optionItemObjective fl"><p>' +
  762. String.fromCharCode(65 + index) +
  763. '.</p>' +
  764. option.content +
  765. '</div>'
  766. })
  767. optionsHtml += '</div>'
  768. var stemItemHtml = self.tpls.objectiveItemTpl.substitute({
  769. content: content,
  770. options: optionsHtml
  771. })
  772. //如果是题卡合一并且是保存状态的时候 才会保存原题信息
  773. if (self.isSubjectInfoToCard) {
  774. stemInfos.push(encodeURIComponent(stemItemHtml))
  775. }
  776. htmls += stemItemHtml
  777. })
  778. self.originStemInfos = stemInfos.concat(self.originStemInfos)
  779. htmls = self.tpls.objectiveWrapTpl.substitute({
  780. editModule: htmls
  781. })
  782. $afterModule.after(htmls)
  783. },
  784. moreSelectStemRender: function (data, $afterModule) {
  785. var self = this
  786. var htmls = self.moreSelectObjectiveTitle
  787. var stemInfos = []
  788. data.forEach(function (item) {
  789. var columnNumber =
  790. typeof item.listType === 'number'
  791. ? !item.listType
  792. ? 1
  793. : item.listType === 1
  794. ? 4
  795. : 2
  796. : ''
  797. var columnClass = columnNumber ? 'column-' + columnNumber : ''
  798. var content = item.queBody.replace(
  799. self.queBodyRegExp,
  800. '<p' + RegExp.$1 + '><span>' + item.questionNum + '、</span>'
  801. )
  802. var optionsHtml =
  803. '<div class="optionObjectiveWrap clearfix ' + columnClass + '">'
  804. item.queOptions.forEach(function (option, index) {
  805. optionsHtml +=
  806. '<div class="optionItemObjective fl"><p>' +
  807. String.fromCharCode(65 + index) +
  808. '.</p>' +
  809. option.content +
  810. '</div>'
  811. })
  812. optionsHtml += '</div>'
  813. var stemItemHtml = self.tpls.objectiveItemTpl.substitute({
  814. content: content,
  815. options: optionsHtml
  816. })
  817. //如果是题卡合一并且是保存状态的时候 才会保存原题信息
  818. if (self.isSubjectInfoToCard) {
  819. stemInfos.push(encodeURIComponent(stemItemHtml))
  820. }
  821. htmls += stemItemHtml
  822. })
  823. self.originStemInfos = stemInfos.concat(self.originStemInfos)
  824. htmls = self.tpls.objectiveWrapTpl.substitute({
  825. editModule: htmls
  826. })
  827. $afterModule.after(htmls)
  828. },
  829. fillInBlankStemRender: function (data, $afterModule) {
  830. var self = this
  831. var htmls = self.fillInBlankObjectiveTitle
  832. var stemInfos = []
  833. data.forEach(function (item) {
  834. var content = item.queBody.replace(
  835. self.queBodyRegExp,
  836. '<p' + RegExp.$1 + '><span>' + item.questionNum + '、</span>'
  837. )
  838. var stemItemHtml = self.tpls.objectiveItemTpl.substitute({
  839. content: content
  840. })
  841. //如果是题卡合一并且是保存状态的时候 才会保存原题信息
  842. if (self.isSubjectInfoToCard) {
  843. stemInfos.push(encodeURIComponent(stemItemHtml))
  844. }
  845. htmls += stemItemHtml
  846. })
  847. htmls = self.tpls.objectiveWrapTpl.substitute({
  848. editModule: htmls
  849. })
  850. self.originStemInfos = stemInfos.concat(self.originStemInfos)
  851. $afterModule.after(htmls)
  852. },
  853. /**
  854. * —————————————————————————————————————————————————————————————————————————————————————————————————————————————————————
  855. 客观题题干内容渲染 结束 —————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————
  856. */
  857. getSingleSelectHtml: function (datas, type) {
  858. var self = this
  859. //判断是否多选
  860. var isMoreSelect = type === 'more'
  861. var moreSelectClass = isMoreSelect ? 'more-option' : ''
  862. var singleSelectHtml = ''
  863. var singleColHtml = ''
  864. datas.forEach(function (singleItem, index) {
  865. var singleContent = ''
  866. for (var i = 0; i < singleItem.optionCount; i++) {
  867. var option = String.fromCharCode(65 + i)
  868. singleContent += '<span data-option="{option}">[<i>{option}</i>]</span>'.substitute(
  869. { option: option }
  870. )
  871. }
  872. singleColHtml += self.tpls.singleSelectOptionTpl.substitute({
  873. _index: ++index,
  874. singleContent: singleContent,
  875. questionNum: singleItem.questionNum,
  876. answer: singleItem.answer
  877. })
  878. if (!(index % 5)) {
  879. singleSelectHtml +=
  880. '<ul class="single-option ' +
  881. moreSelectClass +
  882. ' clearfix">' +
  883. singleColHtml +
  884. '</ul>'
  885. singleColHtml = ''
  886. }
  887. })
  888. singleSelectHtml +=
  889. !datas.length % 5
  890. ? ''
  891. : '<ul class="single-option ' +
  892. moreSelectClass +
  893. ' clearfix">' +
  894. singleColHtml +
  895. '</ul>'
  896. return singleSelectHtml
  897. },
  898. /**
  899. * @param {多选 or 单选} title
  900. * @param {选择题布局方向} direction
  901. * @param {选择题内容} selectContent
  902. */
  903. getSelectRenderContent: function (data) {
  904. //selectContent, title, direction,hasTitle
  905. var self = this
  906. var titleMap = {
  907. //type
  908. singleSelect: self['singleSelect-title'],
  909. moreSelect: self['moreSelect-title']
  910. }
  911. data.settingBtn =
  912. typeof data.settingBtn === 'boolean' ? data.settingBtn : true
  913. /**
  914. * vertical 竖向布局
  915. * horizontal 横向布局
  916. */
  917. var direction = data.direction || 'vertical'
  918. var hasTitle = typeof data.hasTitle === 'undefined' ? true : data.hasTitle
  919. var SingleSelectModuleHtml = self.tpls.selectTpl.substitute({
  920. title: hasTitle ? self.titleHtml(titleMap[data.title]) : '',
  921. moduleType: data.title,
  922. selectContent: data.selectContent,
  923. direction: direction,
  924. settingBtn: data.settingBtn
  925. ? '<div class="settingBtn" data-type="{moduleType}"></div>'.substitute({
  926. moduleType: data.title
  927. })
  928. : ''
  929. })
  930. return SingleSelectModuleHtml
  931. },
  932. //单选题--布局
  933. singleSelectRender: function (datas, appendEl) {
  934. var self = this
  935. var singleSelectHtml = self.getSingleSelectHtml(datas, 'single')
  936. //selectContent, title, direction,hasTitle
  937. var SingleSelectModuleHtml = self.getSelectRenderContent({
  938. selectContent: singleSelectHtml,
  939. title: 'singleSelect'
  940. })
  941. appendEl.append(SingleSelectModuleHtml)
  942. },
  943. //多选题--布局
  944. moreSelectRender: function (datas, appendEl) {
  945. var self = this
  946. //获取选项html
  947. var singleSelectHtml = self.getSingleSelectHtml(datas, 'more')
  948. //获取整个选择题区域模块html
  949. //selectContent, title, direction,hasTitle
  950. var SingleSelectModuleHtml = self.getSelectRenderContent({
  951. selectContent: singleSelectHtml,
  952. title: 'moreSelect'
  953. })
  954. appendEl.append(SingleSelectModuleHtml)
  955. },
  956. getFillInBlankHtml: function (datas) {
  957. var self = this
  958. var fillInBlankHtml = ''
  959. var getScoreHtml = function (scoreStyle) {
  960. if (!scoreStyle) return '<i></i>'
  961. return scoreStyle.split('/').reduce(function (total, score) {
  962. total += '<i>' + score + '</i>'
  963. return total
  964. }, '')
  965. }
  966. datas.forEach(function (fillInBlankItem) {
  967. fillInBlankItem.scoreStyle = fillInBlankItem.scoreStyle || ''
  968. fillInBlankItem.scoreHtml = getScoreHtml(fillInBlankItem.scoreStyle)
  969. fillInBlankHtml += self.tpls.fillInBlankItemTpl.substitute(
  970. fillInBlankItem
  971. )
  972. })
  973. return fillInBlankHtml
  974. },
  975. getFillInBlankRenderContent: function (fillInBlankHtml, title, scoreStyle) {
  976. var self = this
  977. title = title || ''
  978. var fillInBlankModuleHtml = self.tpls.fillInBlankTpl.substitute({
  979. fillInBlankContent: fillInBlankHtml,
  980. scoreStyle: scoreStyle,
  981. title: title
  982. })
  983. return fillInBlankModuleHtml
  984. },
  985. //填空题--布局
  986. fillInBlankRender: function (datas, appendEl) {
  987. var self = this
  988. self.fillInBlankDatas = datas
  989. var fillInBlankHtml = self.getFillInBlankHtml(datas)
  990. var scoreStyle = datas[0].scoreStyle || ''
  991. var fillInBlankModuleHtml = self.getFillInBlankRenderContent(
  992. fillInBlankHtml,
  993. self.titleHtml(self['fillInBlank-title']),
  994. scoreStyle
  995. )
  996. appendEl.append(fillInBlankModuleHtml)
  997. },
  998. //重新渲染填空题
  999. reRenderFillInBlank: function () {
  1000. var self = this
  1001. var pageIndex = 1
  1002. while (self.fillInBlank['page' + pageIndex]) {
  1003. var pageFillInBlank = self.fillInBlank['page' + pageIndex]
  1004. if (!pageFillInBlank.length) {
  1005. pageIndex++
  1006. continue
  1007. }
  1008. var $curPage = $('#printcontent .pageContent').eq(pageIndex - 1)
  1009. var $pageFillInBlank = $curPage.find('.completion-topic .subjectCol')
  1010. var scoreStyle = pageFillInBlank[0].scoreStyle || ''
  1011. $pageFillInBlank
  1012. .attr('data-scorestyle', scoreStyle)
  1013. .html(self.getFillInBlankHtml(pageFillInBlank))
  1014. pageIndex++
  1015. }
  1016. },
  1017. //解答题获取最小可选分值
  1018. getAnswerMinScoreLimit: function (limit) {
  1019. var self = this
  1020. var minLimit = 16
  1021. for (var i = 0, item; (item = self.answerScoreLimitKeyArr[i++]); ) {
  1022. if (item >= limit) {
  1023. minLimit = item
  1024. break
  1025. }
  1026. }
  1027. return minLimit
  1028. },
  1029. //解答题--布局
  1030. shortAnswerRender: function (datas, appendEl) {
  1031. var self = this
  1032. var shortAnswerTpl = self.tpls.shortAnswerItemTpl
  1033. var shortAnswerHtml = ''
  1034. datas.forEach(function (shortAnswerItem) {
  1035. shortAnswerItem.editorContentHeight = shortAnswerItem.editorContentHeight
  1036. ? shortAnswerItem.editorContentHeight
  1037. : self.moduleDefaultHeihgt
  1038. //scorelimitkey 15 16 29 49 isHalf 是否有半分的概念
  1039. var minLimit = self.getAnswerMinScoreLimit(shortAnswerItem.fullScore)
  1040. shortAnswerItem.scoreColumnHtml = self.generateScoreBox(minLimit, false ,shortAnswerItem.fullScore)
  1041. shortAnswerItem.scoreLimit = minLimit
  1042. shortAnswerHtml += shortAnswerTpl.substitute(shortAnswerItem)
  1043. //保存原题信息
  1044. self.editorAreaOriginContent[shortAnswerItem.questionNum] =
  1045. shortAnswerItem.queBody
  1046. })
  1047. var shortAnswerModuleHtml = self.tpls.shortAnswerTpl.substitute({
  1048. shortAnswerContent: shortAnswerHtml,
  1049. title: self['shortAnswer-title']
  1050. })
  1051. appendEl.append(shortAnswerModuleHtml)
  1052. //初始化解答题富文本插件
  1053. datas.forEach(function (item) {
  1054. var questionNum = item.questionNum
  1055. var answerContent = ''
  1056. //题卡合一渲染原题信息,并且是题卡合一
  1057. if (!self.alreadySave && self.isSubjectInfoToCard) {
  1058. let topicObj = self.editorAreaOriginContent[questionNum]
  1059. let questionNumHtml = '<div class="editorQuestionNum">'+item.questionNum +'、</div>'
  1060. answerContent = questionNumHtml+topicObj
  1061. // answerContent = '<div class="w-e-text">'+ answerContent + self.editorAreaOriginContent[questionNum] +'</div>'
  1062. } else {
  1063. answerContent = item.questionNum +'、'
  1064. // $(self.editorAreaOriginContent[questionNum]).find('img').each(function () {
  1065. // if(!$(this).hasClass('gsImgLatex') && $(this).attr('data-type')===undefined){
  1066. // answerContent = answerContent + $(this).context.outerHTML;
  1067. // }
  1068. // })
  1069. if(item.matchPicture !==null){
  1070. answerContent = answerContent +"<br />"+ item.matchPicture;
  1071. }
  1072. }
  1073. answerContent = '<div class="w-e-text">'+answerContent+'</div>';
  1074. self.createShortAnswer(questionNum, answerContent)
  1075. })
  1076. },
  1077. //选做题--布局
  1078. chooseAnswerRender: function (datas, appendEl) {
  1079. var self = this
  1080. var chooseAnswerTpl = self.tpls.chooseAnswerItemTpl
  1081. var editorCreateIds = []
  1082. //m 选 n 的n
  1083. var requiredCount = datas[0].required
  1084. var chooseAnswerHtml = ''
  1085. //外显题号
  1086. var questionNumShow = 0
  1087. for (var i = 0; i < requiredCount; i++) {
  1088. var selOptionHtml = ''
  1089. var startChooseNumber = 0
  1090. var titleNumber = ''
  1091. var fullScore = 16
  1092. datas.forEach(function (item, index) {
  1093. if (index === i) {
  1094. if (!questionNumShow)
  1095. questionNumShow =
  1096. item.questionNum + '~' + (+item.questionNum + datas.length - 1)
  1097. startChooseNumber = item.questionNum
  1098. editorCreateIds.push(item.questionNum)
  1099. self.editorAreaOriginContent[item.questionNum] = item.queBody
  1100. fullScore = item.fullScore
  1101. }
  1102. titleNumber += item.questionNum + ','
  1103. selOptionHtml += '<span data-titleNumber="{titleNumber}" data-option="[{char}]">[{char}]</span>'.substitute(
  1104. {
  1105. char: String.fromCharCode(65 + index),
  1106. titleNumber: item.questionNum
  1107. }
  1108. )
  1109. })
  1110. var minLimit = self.getAnswerMinScoreLimit(fullScore)
  1111. var scoreColumnHtml = self.generateScoreBox(minLimit, false,fullScore)
  1112. chooseAnswerHtml += chooseAnswerTpl.substitute({
  1113. questionNum: startChooseNumber,
  1114. questionNumShow: questionNumShow,
  1115. //4,5,6,
  1116. titleNumber: titleNumber.substring(0, titleNumber.length - 1),
  1117. selOptionHtml: selOptionHtml,
  1118. scoreColumnHtml: scoreColumnHtml,
  1119. editorContentHeight: self.moduleDefaultHeihgt,
  1120. scoreLimit: minLimit,
  1121. fullScore:fullScore
  1122. })
  1123. }
  1124. //先渲染多选题
  1125. //选做题题干信息单独处理
  1126. var chooseAddTitle = ''
  1127. var hasObjective = self.chooseAnswerObjective && !self.alreadySave
  1128. if (hasObjective) {
  1129. chooseAddTitle = self.chooseAnswerObjective
  1130. }
  1131. var chooseAnswerModuleHtml = self.tpls.chooseAnswerTpl.substitute({
  1132. chooseAnswerContent: chooseAnswerHtml,
  1133. title: self['chooseAnswer-title'] + chooseAddTitle
  1134. })
  1135. appendEl.append(chooseAnswerModuleHtml)
  1136. //如果有题干信息
  1137. if (hasObjective) {
  1138. self.judegeImgsLoaded(
  1139. '.answerModule[data-type="chooseAnswer"] .originSubjectInfo'
  1140. )
  1141. }
  1142. let chooseContent = questionNumShow+ '、'
  1143. // self.questionMap[chooseAnswer].map(function (questionItem, index) {
  1144. // if (questionItem.matchPicture !== null) {
  1145. // chooseContent +=
  1146. // '<p>' +
  1147. // questionItem.questionNum +
  1148. // '、' +
  1149. // questionItem.matchPicture +
  1150. // '</p>'
  1151. // }
  1152. // }, [])
  1153. editorCreateIds.forEach(function (editorId) {
  1154. self.createShortAnswer(editorId,chooseContent)
  1155. })
  1156. },
  1157. //必做题--布局
  1158. mustAnswerRender: function (datas, appendEl) {
  1159. var self = this
  1160. var shortAnswerTpl = self.tpls.shortAnswerItemTpl
  1161. var shortAnswerHtml = ''
  1162. datas.forEach(function (shortAnswerItem) {
  1163. shortAnswerItem.editorContentHeight = shortAnswerItem.editorContentHeight
  1164. ? shortAnswerItem.editorContentHeight
  1165. : self.moduleDefaultHeihgt
  1166. var minLimit = self.getAnswerMinScoreLimit(shortAnswerItem.fullScore)
  1167. shortAnswerItem.scoreColumnHtml = self.generateScoreBox(minLimit, false)
  1168. shortAnswerItem.scoreLimit = minLimit
  1169. shortAnswerHtml += shortAnswerTpl.substitute(shortAnswerItem)
  1170. //保存原题信息
  1171. self.editorAreaOriginContent[shortAnswerItem.questionNum] =
  1172. shortAnswerItem.queBody
  1173. })
  1174. var shortAnswerModuleHtml = self.tpls.shortAnswerTpl.substitute({
  1175. shortAnswerContent: shortAnswerHtml,
  1176. title: self['mustAnswer-title']
  1177. })
  1178. appendEl.append(shortAnswerModuleHtml)
  1179. //初始化解答题富文本插件
  1180. datas.forEach(function (item) {
  1181. var questionNum = item.questionNum
  1182. var answerContent = ''
  1183. if (!self.alreadySave && self.isSubjectInfoToCard) {
  1184. answerContent = self.editorAreaOriginContent[questionNum]
  1185. }else {
  1186. // $(self.editorAreaOriginContent[questionNum]).find('img').each(function () {
  1187. // if(!$(this).hasClass('gsImgLatex') && $(this).attr('data-type')===undefined){
  1188. // answerContent = answerContent + $(this).context.outerHTML;
  1189. // }
  1190. // })
  1191. if(item.matchPicture !==null){
  1192. answerContent = answerContent +"<br />"+ item.matchPicture;
  1193. }
  1194. }
  1195. self.createShortAnswer(questionNum, answerContent)
  1196. })
  1197. },
  1198. /*--------------------------------------------------------------------------------------------------------------------
  1199. 初始页面布局功能结束
  1200. -----------------------------------------------------------------------------------------------------------------------*/
  1201. /*--------------------------------------------------------------------------------------------------------------------------------
  1202. 记忆布局功能开始
  1203. ------------------------------------------------------------------------------------------------------------------------------------*/
  1204. memoryLayout: function (res) {
  1205. var self = this
  1206. var formatData = self.memoryDataFormat(res)
  1207. var singleSelectData = formatData.singleSelectData
  1208. var moreSelectData = formatData.moreSelectData
  1209. var fillInBlankData = formatData.fillInBlankData
  1210. var shortAnswerData = formatData.shortAnswerData
  1211. // 先控制是否有装订线,纸张大小,方向,分栏,装订线考号
  1212. //{paper,direction,hasBindingLine,examNumberConfig:{barCode,ticketNumber},useQrCode}
  1213. self.memoryHasBindLine(res.hasBindingLine)
  1214. self.memoryPaperDirectColumn(res.paper, res.direction, res.columns)
  1215. //记忆布局--考号配置
  1216. self.memoryExamNumberConfig(res.examNumberConfig, res.useQrCode)
  1217. // 信息栏
  1218. self.memoryHasPaperMsgConfig(res)
  1219. //记忆布局--选择题选项排列方向设置
  1220. if (singleSelectData.length) {
  1221. self.memorySelectData(singleSelectData[0].direction, 'singleSelect')
  1222. }
  1223. if (moreSelectData.length) {
  1224. self.memorySelectData(moreSelectData[0].direction, 'moreSelect')
  1225. }
  1226. if (fillInBlankData.length) {
  1227. //然后再布局
  1228. self.memoryFillInBlank(fillInBlankData)
  1229. }
  1230. if (res.stemInfo && res.stemInfo.length) {
  1231. self.memoryObjective(res.stemInfo, res.chooseAnswerStemInfo)
  1232. }
  1233. if (shortAnswerData.length) {
  1234. self.memoryShortAnswer(shortAnswerData)
  1235. }
  1236. },
  1237. //把每一题的数据整合到一起
  1238. memoryDataFormat: function (res) {
  1239. var self = this
  1240. //选择题可以设置选项排列方向
  1241. var singleSelectData = []
  1242. var moreSelectData = []
  1243. //填空题可以设置每行列数、分值格式等
  1244. var fillInBlankData = []
  1245. var shortAnswerData = []
  1246. var linkQuestionData = {}
  1247. res.pages.forEach(function (pageData, index) {
  1248. for (var i = 0, questionItem; i < pageData.questions.length; i++) {
  1249. questionItem = pageData.questions[i]
  1250. var questionType = questionItem.type
  1251. switch (questionType) {
  1252. //选择题
  1253. case self.questionTypeMapForPhp.singleSelect:
  1254. singleSelectData.push(questionItem)
  1255. break
  1256. case self.questionTypeMapForPhp.moreSelect:
  1257. moreSelectData.push(questionItem)
  1258. break
  1259. //填空题
  1260. case self.questionTypeMapForPhp.fillInBlank:
  1261. fillInBlankData.push(questionItem)
  1262. break
  1263. //解答题 or 选做题
  1264. case self.questionTypeMapForPhp.answer:
  1265. case self.questionTypeMapForPhp.chooseAnswer:
  1266. //非多选题
  1267. var isShortAnswer = questionType === 1
  1268. var linkParm = isShortAnswer
  1269. ? questionItem.cut.linkparm
  1270. : questionItem.selectqts[0].cut.linkparm
  1271. //linkParm > 0 补充模块 如果存在补充模块 , 则先合并
  1272. if (linkParm) {
  1273. //第一个补充模块
  1274. if (linkParm === 1) {
  1275. if (JSON.stringify(linkQuestionData) !== '{}') {
  1276. shortAnswerData.push(linkQuestionData)
  1277. linkQuestionData = {}
  1278. }
  1279. linkQuestionData = questionItem
  1280. } else {
  1281. //后面几个补充模块
  1282. if (isShortAnswer) {
  1283. linkQuestionData.cut.height += questionItem.cut.height
  1284. } else {
  1285. linkQuestionData.selectqts[0].cut.height +=
  1286. questionItem.selectqts[0].cut.height
  1287. }
  1288. linkQuestionData.contents += questionItem.contents
  1289. }
  1290. if (
  1291. ((res.pages[index + 1] &&
  1292. !res.pages[index + 1].questions.length) ||
  1293. index + 1 === res.pages.length) &&
  1294. !pageData.questions[i + 1]
  1295. ) {
  1296. shortAnswerData.push(linkQuestionData)
  1297. }
  1298. } else {
  1299. if (JSON.stringify(linkQuestionData) !== '{}') {
  1300. shortAnswerData.push(linkQuestionData)
  1301. linkQuestionData = {}
  1302. }
  1303. shortAnswerData.push(questionItem)
  1304. }
  1305. break
  1306. }
  1307. }
  1308. })
  1309. return {
  1310. shortAnswerData: shortAnswerData,
  1311. fillInBlankData: fillInBlankData,
  1312. singleSelectData: singleSelectData,
  1313. moreSelectData: moreSelectData
  1314. }
  1315. },
  1316. memoryHasBindLine: function (hasBindingLine) {
  1317. if (hasBindingLine) {
  1318. $('#hasBindingLine .h_radioItem').eq(0).trigger('click')
  1319. }
  1320. },
  1321. //基本布局 纸张规格方向分栏
  1322. memoryPaperDirectColumn: function (paper, direction, column) {
  1323. var self = this
  1324. $('#paperOptions .h_radioItem').each(function () {
  1325. if ($(this).attr('data-paper') === paper) {
  1326. $(this).trigger('click')
  1327. }
  1328. })
  1329. $('#paperDirection .h_radioItem').each(function () {
  1330. if ($(this).attr('data-direction') === direction) {
  1331. $(this).trigger('click')
  1332. }
  1333. })
  1334. $('.layoutList .layoutItem').each(function () {
  1335. //column type:number
  1336. if ($(this).attr('data-column') == column) {
  1337. $(this).trigger('click')
  1338. }
  1339. })
  1340. },
  1341. //记忆布局--考号配置
  1342. memoryExamNumberConfig: function (examNumberConfig, useQrCode) {
  1343. var self = this
  1344. $('#examNumberConfig .h_checkItem').each(function () {
  1345. var configName = $(this).attr('data-value')
  1346. var isChecked = $(this).hasClass('checked')
  1347. if (examNumberConfig[configName]) {
  1348. if (!isChecked) $(this).trigger('click')
  1349. } else {
  1350. if (isChecked) $(this).trigger('click')
  1351. }
  1352. })
  1353. //是否使用二维码
  1354. var useQrCodeStatus = $('#useQrCode').hasClass('open')
  1355. if (useQrCode) {
  1356. if (!useQrCodeStatus) {
  1357. $('#useQrCode').trigger('click')
  1358. }
  1359. } else {
  1360. if (useQrCodeStatus) {
  1361. $('#useQrCode').trigger('click')
  1362. }
  1363. }
  1364. },
  1365. //记忆布局--信息栏
  1366. memoryHasPaperMsgConfig: function (hasPaperMsgConfig) {
  1367. var self = this
  1368. if(hasPaperMsgConfig.hasPaperMsg==undefined) return
  1369. self.examInfoConfigText=hasPaperMsgConfig.examInfoConfigText;
  1370. self.examInfoConfig=hasPaperMsgConfig.examInfoConfig;
  1371. self.hasPaperMsg=hasPaperMsgConfig.hasPaperMsg;
  1372. $('#examInfoConfig').find('.h_checkItem').each(function () {
  1373. let type = $(this).attr('data-value');
  1374. if(hasPaperMsgConfig.examInfoConfig[type]==true){
  1375. if(!$(this).hasClass('checked')){
  1376. $(this).addClass('checked')
  1377. }
  1378. } else {
  1379. if($(this).hasClass('checked')){
  1380. $(this).removeClass('checked')
  1381. }
  1382. }
  1383. })
  1384. self.isShowPaperMsg();
  1385. },
  1386. memorySelectData: function (direction, type) {
  1387. var self = this
  1388. var $this = $('.' + type)
  1389. .eq(0)
  1390. .find('.settingBtn')
  1391. self.selectStyleChange($this, type, direction)
  1392. },
  1393. memoryFillInBlank: function (fillInBlankData) {
  1394. var self = this
  1395. var questionItem = fillInBlankData[0]
  1396. //当前答题卡只有一大填空题大题的情况下
  1397. var $this = $('.completion-topic').eq(0).find('.settingBtn')
  1398. var column = questionItem.column || 1
  1399. var rowLinHeight = questionItem.rowLinHeight || 40
  1400. var scoreStyle = questionItem.scoreStyle || ''
  1401. self.fillInBlankStyleChange($this, column, rowLinHeight, scoreStyle)
  1402. },
  1403. /**
  1404. *
  1405. * 异步图片加载完成
  1406. * srcList
  1407. * _img = new Image()
  1408. * _img.src = srcList[i]
  1409. */
  1410. judegeImgsLoaded: function (imgBoxSelector, cb) {
  1411. var imgList = []
  1412. var $imgBox = $(imgBoxSelector)
  1413. $imgBox.find('img').each(function () {
  1414. var imge = $(this)
  1415. var styles = imge.attr('style')
  1416. if (styles) {
  1417. styles = styles.replace(/height:auto;/g, '')
  1418. imge.attr('style', styles)
  1419. }
  1420. imgList.push($(this).attr('src'))
  1421. })
  1422. if (!imgList.length) return
  1423. var self = this
  1424. var i = 0
  1425. var imgLen = imgList.length
  1426. function imgLoad() {
  1427. var _img = new Image()
  1428. _img.src = imgList[i]
  1429. _img.onload = function () {
  1430. i++
  1431. if (i >= imgLen) {
  1432. self.changeUnitForFormulaPic($(imgBoxSelector))
  1433. cb && cb()
  1434. } else {
  1435. imgLoad()
  1436. }
  1437. }
  1438. _img.onerror = function () {
  1439. i++
  1440. if (i >= imgLen) {
  1441. self.changeUnitForFormulaPic($(imgBoxSelector))
  1442. cb && cb()
  1443. } else {
  1444. imgLoad()
  1445. }
  1446. }
  1447. }
  1448. imgLoad()
  1449. },
  1450. memoryObjective: function (stemInfo, chooseAnswerStemInfo) {
  1451. var self = this
  1452. stemInfo = typeof stemInfo === 'object' ? stemInfo : stemInfo.split('|end|')
  1453. var isBase64Save = isBase64(stemInfo[0])
  1454. var imgList = []
  1455. $('.objectiveItem').each(function (index) {
  1456. //$(this)[0].outerHTML = decodeUtf8(stemInfo[index].split(',').map(function(v){return +v}))
  1457. var replaceStr = ''
  1458. if(isBase64Save){
  1459. replaceStr = decode(stemInfo[index]);
  1460. }else{
  1461. replaceStr = decodeURIComponent(stemInfo[index]);
  1462. }
  1463. $(this)[0].outerHTML = replaceStr
  1464. })
  1465. //选做题单独处理
  1466. if (chooseAnswerStemInfo) {
  1467. var $chooseAnswer = $('.answerModule[data-type="chooseAnswer"]')
  1468. var $chooseAnswerObjective = $chooseAnswer.find('.originSubjectInfo')
  1469. var memoryObjectiveHtml = decodeURIComponent(chooseAnswerStemInfo)
  1470. var delHMemory = memoryObjectiveHtml.replace(/height:auto;/g, '')
  1471. if ($chooseAnswerObjective.length) {
  1472. $chooseAnswerObjective[0].outerHTML = delHMemory
  1473. } else {
  1474. $chooseAnswer.eq(0).children('h3').append(delHMemory)
  1475. }
  1476. //重置图片高度
  1477. self.judegeImgsLoaded(
  1478. '.answerModule[data-type="chooseAnswer"] .originSubjectInfo'
  1479. )
  1480. }
  1481. },
  1482. memoryShortAnswer: function (shortAnswerData) {
  1483. // $('.module').find('.editorContent').html('');
  1484. var self = this
  1485. //2 解答题区域高度修改
  1486. //shortAnswerData 所有解答题的区域信息 通过两点确定唯一对应点关系
  1487. var checkQuestionData = {}
  1488. var checkmoduleEl = {}
  1489. var modules
  1490. for (var i = 0, questionItem; i < shortAnswerData.length; i++) {
  1491. var questionItem = shortAnswerData[i]
  1492. var moduleHeight = questionItem.cut
  1493. ? questionItem.cut.height
  1494. : questionItem.selectqts[0].cut.height
  1495. var scoreLimitKey = questionItem.scoreLimit
  1496. // var isAddHalf = questionItem.isAddHalf
  1497. var isAddHalf = questionItem.scorebox.point==1?true:false
  1498. var questionItemId = questionItem.id.replace(/、/g,',');
  1499. //console.log(moduleHeight)
  1500. $('#printcontent .pageContent .short-answer .module').each(function (
  1501. pageIndex,
  1502. moduleItem
  1503. ) {
  1504. var $pageItem = $(moduleItem).closest('.pageContent')
  1505. var $moduleItem = $(moduleItem)
  1506. var isOverPage = false
  1507. var titleNumber = $moduleItem.attr('title-number')
  1508. titleNumber = titleNumber.replace(/、/g,',');
  1509. var dataEditorIndex = $moduleItem.attr('data-editorindex')
  1510. if (self.isSurplusModule($moduleItem)) return
  1511. //该题已经布局就无需重复布局--针对选择题
  1512. //多选题的 titleNumber 都相同
  1513. //确定唯一模块,模块id来确定
  1514. if (
  1515. titleNumber === questionItemId &&
  1516. !checkQuestionData[questionItem.editorId] &&
  1517. !checkQuestionData[dataEditorIndex]
  1518. ) {
  1519. checkQuestionData[questionItem.editorId] = true
  1520. checkQuestionData[dataEditorIndex] = true
  1521. //同步之前设置的内容
  1522. if (questionItem.contents) {
  1523. var editorId = questionItem.editorId
  1524. // self.editorArea['editor' + editorId].txt.html(
  1525. // decodeURIComponent(questionItem.contents)
  1526. // )
  1527. let topicHtml = decodeURIComponent(questionItem.contents)
  1528. // let topicHtml = '<div class="w-e-text">'+decodeURIComponent(questionItem.contents)+'</div>'
  1529. $('#editorContent'+editorId).html('');
  1530. let isW = topicHtml.search(".w-e-text")
  1531. $('#printcontent .pageContent .short-answer .module').each(function (
  1532. pageIndexs,
  1533. moduleItems
  1534. ) {
  1535. if($(moduleItems).attr('title-number') == editorId ){
  1536. $(moduleItems).find('.editorContent').html('<div class="w-e-text"></div>');
  1537. }
  1538. })
  1539. if(isW>-1){
  1540. $('#editorContent'+editorId).html(decodeURIComponent(questionItem.contents));
  1541. }else {
  1542. $('#editorContent'+editorId).html('<div class="w-e-text">'+decodeURIComponent(questionItem.contents)+'</div>');
  1543. }
  1544. }
  1545. var $this = $moduleItem.children('.settingBtn')
  1546. self.shortAnswerStyleChange($this, scoreLimitKey, isAddHalf,questionItem.scorebox.limit)
  1547. //设置大题区域高度
  1548. $moduleItem
  1549. .children('.editorContent')
  1550. .height(moduleHeight - self.modulePadding)
  1551. curPageEl = $pageItem
  1552. //如果当前有page分栏页有超出 则直接调到下一个分页
  1553. isOverPage = self.getOverModule(curPageEl)
  1554. self.changePrintArea(curPageEl)
  1555. }
  1556. if (isOverPage) return false
  1557. })
  1558. }
  1559. },
  1560. /*--------------------------------------------------------------------------------------------------------------------------------
  1561. 记忆布局功能结束
  1562. ------------------------------------------------------------------------------------------------------------------------------------*/
  1563. /**
  1564. * --------------------------------------------------------------------------------------------------------------------------------
  1565. 还原原题题干信息开始
  1566. --------------------------------------------------------------------------------------------------------------------------------
  1567. */
  1568. restoreObjectiveInfo: function (data) {
  1569. var self = this
  1570. var clearStatus = data.clearStatus
  1571. if (clearStatus) {
  1572. var $pageContent
  1573. $('.answerModule').each(function () {
  1574. if ($(this).attr('data-type') === 'objective') {
  1575. if (!$pageContent) {
  1576. $pageContent = $(this).closest('.pageContent')
  1577. }
  1578. $(this).remove()
  1579. }
  1580. })
  1581. self.changePrintArea($pageContent)
  1582. return
  1583. }
  1584. $('.objectiveItem').each(function (index) {
  1585. $(this)[0].outerHTML = decodeURIComponent(self.originStemInfos[index])
  1586. })
  1587. //图片加载时间
  1588. self.judegeImgsLoaded('.objectiveItem')
  1589. },
  1590. restoreAnswerInfo: function (data) {
  1591. var self = this
  1592. var clearStatus = data.clearStatus
  1593. /**
  1594. * 清空之前所有的内容
  1595. * 包括清空统一题的本体模块和补充模块
  1596. * 然后用新内容放在本体模块里面
  1597. */
  1598. var overPageEl = []
  1599. //第一次出现
  1600. var firstChooseAnswer = true
  1601. $('.short-answer').each(function () {
  1602. var $shortAnswer = $(this)
  1603. var $modules = $(this).find('.module')
  1604. if ($shortAnswer.attr('data-type') === 'chooseAnswer') {
  1605. if (!firstChooseAnswer) {
  1606. $shortAnswer.find('h3').remove()
  1607. return
  1608. }
  1609. firstChooseAnswer = false
  1610. var chooseObjectiveEl = $shortAnswer.find('.originSubjectInfo')
  1611. if (chooseObjectiveEl.length) {
  1612. if (clearStatus) {
  1613. chooseObjectiveEl.remove()
  1614. } else {
  1615. chooseObjectiveEl[0].outerHTML = self.chooseAnswerObjective
  1616. }
  1617. } else {
  1618. $shortAnswer.find('h3').append(self.chooseAnswerObjective)
  1619. }
  1620. if (clearStatus) {
  1621. $shortAnswer.find('.module').each(function (){
  1622. let number = $(this).attr('title-number');
  1623. let numberArr = number.split(",");
  1624. let numberHtml = numberArr[0]+'~'+numberArr[numberArr.length-1]+'、';
  1625. $(this).find('.w-e-text').html(numberHtml)
  1626. })
  1627. }
  1628. var overHeight = self.getOverHeight($shortAnswer)
  1629. if (overHeight > 0) {
  1630. overPageEl.push($shortAnswer.closest('.pageContent'))
  1631. }
  1632. return
  1633. }
  1634. $modules.each(function () {
  1635. var $module = $(this)
  1636. var questionNum = $(this).attr('title-number')
  1637. var editorIndex = $(this).attr('data-editorIndex')
  1638. var $moduleEditorContent = $(this).find('.w-e-text')
  1639. var $moduleContentWrap = $(this).find('.w-e-text-container')
  1640. if($moduleEditorContent.length===0){
  1641. $(this).find('.editorContent').html('<div class="w-e-text"></div>');
  1642. $moduleEditorContent = $(this).find('.w-e-text')
  1643. }
  1644. //如果是补充模块直接清空内容
  1645. if (self.isSurplusModule($(this))) {
  1646. // let pageEl = $(this).parents('.pageContent')
  1647. $moduleEditorContent.html('')
  1648. // let modL = $(this).parents('.answerModule').find('.module');
  1649. // if(modL.length==1){
  1650. // let divL = $(this).parents('.dtk-content').children('div');
  1651. // if(divL.length==1){
  1652. // $(this).parents('.pageContent').remove();
  1653. // self.totalPage--
  1654. // self.refrushPageLabel()
  1655. // }else {
  1656. // $(this).parents('.answerModule').remove();
  1657. // }
  1658. //
  1659. // // self.changePrintArea(pageEl)
  1660. // } else {
  1661. // $(this).remove()
  1662. // }
  1663. // self.changePrintArea(pageEl)
  1664. } else {
  1665. var flexibleIconHtml =
  1666. '<div class="flexible_icon"><i class="resize_nwse"></i></div>'
  1667. var questionNumHtml =
  1668. '<div class="editorQuestionNum">' + questionNum + '、</div>'
  1669. // var baseContent = questionNumHtml + flexibleIconHtml
  1670. var baseContent = questionNumHtml
  1671. let topicImgHtml = ''
  1672. // $(self.editorAreaOriginContent[questionNum]).find('img').each(function () {
  1673. // if(!$(this).hasClass('gsImgLatex') && $(this).attr('data-type')===undefined){
  1674. // topicImgHtml = topicImgHtml + $(this).context.outerHTML;
  1675. // }
  1676. // })
  1677. if(clearStatus){
  1678. self.examQuestions.forEach(item => {
  1679. if(item.questionNum == questionNum){
  1680. if(item.matchPicture !==null){
  1681. topicImgHtml = topicImgHtml +"<br />"+ item.matchPicture;
  1682. }
  1683. }
  1684. })
  1685. }
  1686. $moduleEditorContent.html(
  1687. baseContent +
  1688. (clearStatus ? topicImgHtml : self.editorAreaOriginContent[questionNum])
  1689. )
  1690. $moduleEditorContent.find('img').load(function (e) {
  1691. var minHeight = self.calcEditorContentHeight($moduleEditorContent)
  1692. // if ($moduleContentWrap.height() < minHeight) {
  1693. // $moduleContentWrap.height(minHeight)
  1694. // }
  1695. if ($module.height() < minHeight) {
  1696. $module.find('.editorContent').height(minHeight)
  1697. let curPageEl = $module.parents('.pageContent')
  1698. self.changePrintArea(curPageEl)
  1699. }
  1700. })
  1701. var minHeight = self.calcEditorContentHeight($moduleEditorContent)
  1702. // if ($moduleContentWrap.height() < minHeight) {
  1703. // $moduleContentWrap.height(minHeight)
  1704. // }
  1705. if ($module.height() < minHeight) {
  1706. $module.find('.editorContent').height(minHeight)
  1707. }
  1708. var overHeight = self.getOverHeight($module)
  1709. if (overHeight > 0) {
  1710. overPageEl.push($module.closest('.pageContent'))
  1711. }
  1712. }
  1713. })
  1714. })
  1715. //图片加载时间
  1716. self.judegeImgsLoaded('.short-answer')
  1717. if (overPageEl.length) {
  1718. overPageEl.forEach(function (pageEl) {
  1719. self.changePrintArea($(pageEl))
  1720. })
  1721. }
  1722. },
  1723. /**
  1724. * --------------------------------------------------------------------------------------------------------------------------------
  1725. 还原原题题干信息结束
  1726. --------------------------------------------------------------------------------------------------------------------------------
  1727. */
  1728. initDom: function () {
  1729. var self = this
  1730. self.$layoutItem = $('#hgc_print .layoutItem')
  1731. self.$checkBindLineItem = $('.selOptions input[name="hasBinding"]')
  1732. //第一个page分页的元素,永远不会变
  1733. self.$firstPageContent = $('#printcontent .pageContent').eq(0)
  1734. //答题卡名称
  1735. self.$dtkName = $('#dtkName textarea')
  1736. },
  1737. initEvent: function () {
  1738. var self = this
  1739. //当前默认是 A3 两栏 有装订线 有条形码 有准考证号
  1740. self.linkageForPaper(self.paper)
  1741. },
  1742. /**
  1743. *
  1744. * @param {$element} $editorContentWrapEl 富文本包装内容的div
  1745. */
  1746. calcEditorContentHeight: function ($editorContentWrapEl) {
  1747. var self = this
  1748. var minScaleHeight = 0
  1749. $editorContentWrapEl.children().each(function () {
  1750. var boxWrap = $(this).hasClass('composition-column') ? 10 : 0
  1751. if($(this).hasClass('en')){
  1752. boxWrap = 33
  1753. }
  1754. minScaleHeight += $(this)[0].getBoundingClientRect().height + boxWrap
  1755. // minScaleHeight += $(this)[0].getBoundingClientRect().height
  1756. })
  1757. return minScaleHeight
  1758. },
  1759. bindEvent: function () {
  1760. var self = this
  1761. var base64_img = jrQrcode.getQrBase64(self.examGroupId)
  1762. $('#dtkEwm').attr('src', base64_img)
  1763. //编辑标题
  1764. $('#printcontent').on('blur', 'h3', function () {
  1765. var curPageEl = $(this).closest('.pageContent')
  1766. self.changePrintArea(curPageEl)
  1767. })
  1768. $('#printcontent').on('blur', '.objectiveItem', function () {
  1769. var curPageEl = $(this).closest('.pageContent')
  1770. self.changePrintArea(curPageEl)
  1771. })
  1772. //图片可扩展
  1773. //控制答题卡区域缩放事件
  1774. $('#printcontent').on('mousedown', '.short-answer .dragBtn', function (e) {
  1775. if (!self.isCanEditCard) return
  1776. e.preventDefault()
  1777. var inscreaseTop = $('#contentWrap').scrollTop()
  1778. //当前操作的分页
  1779. var curPageEl = $(this).closest('.pageContent')
  1780. var curPageOffsetTop = curPageEl.offset().top + inscreaseTop
  1781. //当前缩放分页下面的按钮
  1782. var curDtkModelEl = $(this).closest('.module')
  1783. var curDtkModelOffsetTop = curDtkModelEl.offset().top + inscreaseTop
  1784. //只要改变高度的模块
  1785. var changeEl = $(this).siblings('.editorContent')
  1786. //改变之前的初始高度
  1787. var startHeight = changeEl.height()
  1788. var startPageY = e.pageY
  1789. var distance = 0
  1790. //计算可以缩放的最小高度
  1791. // var scaleMinHeight = self.calcEditorContentHeight(
  1792. // changeEl.children('.w-e-text')
  1793. // )
  1794. var scaleMinHeight = changeEl.children('.w-e-text').height();
  1795. if(changeEl.children('.w-e-text').length<1){
  1796. scaleMinHeight = self.calcEditorContentHeight(
  1797. changeEl.children()
  1798. )
  1799. }
  1800. // 如果题卡合一的话,最小高度就是里面内容的高度
  1801. // 否则最小高度就是默认的高度
  1802. // if(this.isSubjectInfoToCard){
  1803. // }
  1804. /**
  1805. * 超过当前纸张的情况下 当鼠标松开的时候
  1806. * 1先把当前纸张放满
  1807. * 2剩余高度重新新到下个版本新建一个富文本高度一样没有内容
  1808. * 3单词拖动鼠标控制解答题区域缩放只能拖动到当前页面最底部
  1809. */
  1810. document.onmousemove = function (e) {
  1811. distance = e.pageY - startPageY
  1812. var newHeight = startHeight + distance
  1813. if (newHeight <= scaleMinHeight) return
  1814. changeEl.height(startHeight + distance)
  1815. }
  1816. //判断是否超过了一页
  1817. /**
  1818. * 1当前模块已经缩放超过了当前页
  1819. * a>该区域后面的内容板块自动清空
  1820. * b>该区域不可再移动,自动新建一页,然后在下一页新建一个富文本默认是上一页超出的区域
  1821. * 2后面的模块超过了当前缩放页面
  1822. * a>直接把后面的题放到新排版页面
  1823. */
  1824. document.onmouseup = function () {
  1825. self.changePrintArea(curPageEl)
  1826. document.onmouseup = null
  1827. document.onmousemove = null
  1828. }
  1829. })
  1830. //删除一个分页超出的部分
  1831. $('#printcontent').on('click', '.delBtn', function (e) {
  1832. if (!self.isCanEditCard) return
  1833. var $this = $(this)
  1834. // if($this.siblings('.editorContent').find('.w-e-text').html() == ''){
  1835. // $this.closest('.module').remove();
  1836. // return
  1837. // }
  1838. self.delPageOverPart($this, 'surplus', true)
  1839. })
  1840. //预览
  1841. $('#previewBtn').click(function () {
  1842. self.previewPrintDiv('printcontent')
  1843. })
  1844. //保存
  1845. $('#saveBtn').click(function () {
  1846. if (!self.isCanEditCard) {
  1847. if (self.isSubjectInfoToCard) {
  1848. self.modal.init({
  1849. content: '当前考试为“题卡合一”模式,是否需要重新替换成原题干内容?',
  1850. sureCb: function () {
  1851. //题问分离的,原题信息都在改问题的后面,试卷固定顺序 选择--填空--解答--必答
  1852. //渲染客观题题目信息
  1853. //如果第一次题卡分离
  1854. if (!$('.objectiveItem').length) {
  1855. self.renderObjective(function (pageEl) {
  1856. self.changePrintArea(pageEl)
  1857. })
  1858. } else {
  1859. self.restoreObjectiveInfo({ clearStatus: false })
  1860. }
  1861. self.restoreAnswerInfo({ clearStatus: false })
  1862. }
  1863. })
  1864. self.isCanEditCard = true
  1865. self.changeCardEditStatus()
  1866. } else {
  1867. hgc_layer.msg('考试已被设置为【题卡分离】,请注意答题卡已被重置!')
  1868. if ($('.objectiveItem').length) {
  1869. self.restoreObjectiveInfo({ clearStatus: true })
  1870. }
  1871. self.restoreAnswerInfo({ clearStatus: true })
  1872. self.isCanEditCard = true
  1873. self.changeCardEditStatus()
  1874. }
  1875. return
  1876. }
  1877. if (self.totalPage > self.columns * 2) {
  1878. hgc_layer.msg('答题卡最多支持' + self.columns * 2 + '页')
  1879. return
  1880. }
  1881. self.judgeHasPrintClass(function () {
  1882. self.savePrintPosition('printcontent')
  1883. })
  1884. })
  1885. //下载pdf
  1886. $('#downLoadBtn').click(function () {
  1887. if (self.isCanEditCard) return
  1888. var $this = $(this)
  1889. if (self.totalPage > self.columns * 2) {
  1890. hgc_layer.msg('答题卡最多支持' + self.columns * 2 + '页')
  1891. return
  1892. }
  1893. //保存状态不用重新执行保存逻辑直接下载或者批量生成
  1894. if (!self.isCanEditCard) {
  1895. if (self.useQrCode) {
  1896. self.judgeHasPrintClass(function () {
  1897. setTimeout(function () {
  1898. self.modal.init({
  1899. title: '批量生成',
  1900. content: '该操作会把该场考试下面的所有班级学生考试模板进行批量生成<p style="color:red;">请勿重复生成</p>',
  1901. ensureText: '确定',
  1902. cancelText: '取消',
  1903. sureCb: function () {
  1904. self.batchGeneratePdf()
  1905. }
  1906. })
  1907. }, 0)
  1908. })
  1909. } else {
  1910. self.downLoadPdf()
  1911. }
  1912. return
  1913. }
  1914. //如果使用了二维码后台批量生成,不影响当前页面
  1915. var nowPosition = JSON.stringify(self.getPositions())
  1916. if (self.useQrCode) {
  1917. if (nowPosition !== self.saveLocationPosition) {
  1918. self.judgeHasPrintClass(function () {
  1919. self.savePrintPosition('printcontent', function () {
  1920. self.modal.init({
  1921. title: '批量生成',
  1922. content:
  1923. '该操作会把该场考试下面的所有班级学生考试模板进行批量生成',
  1924. sureCb: function () {
  1925. self.batchGeneratePdf()
  1926. // self.resetExamStudentStatus(function(){
  1927. // })
  1928. }
  1929. })
  1930. })
  1931. })
  1932. } else {
  1933. self.judgeHasPrintClass(function () {
  1934. setTimeout(function () {
  1935. self.modal.init({
  1936. title: '批量生成',
  1937. content:
  1938. '该操作会把该场考试下面的所有班级学生考试模板进行批量生成',
  1939. sureCb: function () {
  1940. // self.resetExamStudentStatus(function(){
  1941. // })
  1942. self.batchGeneratePdf()
  1943. }
  1944. })
  1945. }, 0)
  1946. })
  1947. }
  1948. } else {
  1949. //保存状态不用重新执行保存逻辑直接下载或者批量生成
  1950. if (!self.isCanEditCard) {
  1951. self.downLoadPdf()
  1952. return
  1953. }
  1954. if (nowPosition !== self.saveLocationPosition) {
  1955. self.judgeHasPrintClass(function () {
  1956. self.savePrintPosition('printcontent', function () {
  1957. self.downLoadPdf()
  1958. })
  1959. })
  1960. } else {
  1961. self.downLoadPdf()
  1962. }
  1963. }
  1964. })
  1965. //答题卡布局
  1966. //选择纸张
  1967. new RadioBoxItem($('#paperOptions'), function ($radioItem, status) {
  1968. if(ueEditor!=null &&ueEditor.key!=undefined){
  1969. self.saveUeditor(ueEditor,topicEl)
  1970. }
  1971. var paper = $radioItem.attr('data-paper')
  1972. self.paper = paper
  1973. self.linkageForPaper(paper)
  1974. })
  1975. //选择排版方向
  1976. new RadioBoxItem($('#paperDirection'), function ($radioItem, status) {
  1977. var direction = $radioItem.attr('data-direction')
  1978. self.direction = direction
  1979. self.setPageWidthHeightForDirection(direction)
  1980. self.linkageForDirection(self.config.direction[direction])
  1981. })
  1982. //选择分栏
  1983. self.$layoutItem.click(function () {
  1984. var column = +$(this).attr('data-column')
  1985. //|| $(this).hasClass('current')
  1986. if ($(this).hasClass('disabled')) return
  1987. $(this).addClass('current').siblings().removeClass('current')
  1988. self.columns = column
  1989. self.initPrintContentArea()
  1990. })
  1991. //选择是否有装订线
  1992. new RadioBoxItem($('#hasBindingLine'), function ($radioItem, status) {
  1993. var bindingLineStatus = $radioItem.attr('data-value') === 'yes'
  1994. self.hasBindingLine = bindingLineStatus
  1995. self.ifBindingLine()
  1996. })
  1997. //选择是否显示信息栏
  1998. new RadioBoxItem($('#hasPaperMsg'), function ($radioItem, status) {
  1999. var bindingPaperMsgStatus = $radioItem.attr('data-value') === 'yes'
  2000. self.hasPaperMsg = bindingPaperMsgStatus
  2001. self.isShowPaperMsg()
  2002. })
  2003. //信息栏弹窗配置
  2004. new CheckBoxItem(
  2005. $('#examInfoConfig'),
  2006. function () { },
  2007. self.selExamInfoStyle.bind(self)
  2008. )
  2009. //信息栏设置
  2010. $('#printcontent').on('click', '.btn-examInfo', function () {
  2011. if (!self.isCanEditCard) return
  2012. $('#examInfoEditDialog').show()
  2013. })
  2014. $('#examInfoEditDialog').on('click', '.btn-hide-dialog', function () {
  2015. $('#examInfoEditDialog').hide()
  2016. })
  2017. $('#examInfoEditDialog').on('click', '.btn-save-examInfo', function () {
  2018. $('#examInfoEditDialog').hide()
  2019. self.showExamInfoHtml();
  2020. self.getSaveSubjectInfo(self.questionMap)
  2021. })
  2022. $('.opratorArea').on('mouseover', '.hgc_notice', function (e) {
  2023. let el = e.target
  2024. let noticeEl = $(this).parent('.notice-item').find('.noticeContent');
  2025. let triangleEl = $(this).parent('.notice-item').find('.noticeContent').find('b');
  2026. $(noticeEl).show();
  2027. let noticeH = $(noticeEl).get(0).offsetHeight
  2028. let noticeW = $(noticeEl).get(0).offsetWidth
  2029. let { top, left } = el.getBoundingClientRect();
  2030. $(noticeEl).css('top', top - noticeH - 10 + 'px')
  2031. $(noticeEl).css('left', left - noticeW / 2 + 'px');
  2032. $(triangleEl).css('top', top - 10 + 'px');
  2033. $(triangleEl).css('left', left + 'px');
  2034. })
  2035. $('.opratorArea').on('mouseout', '.hgc_notice', function (e) {
  2036. let noticeEl = $(this).parent('.notice-item').find('.noticeContent');
  2037. $(noticeEl).hide();
  2038. })
  2039. //考号配置
  2040. new CheckBoxItem(
  2041. $('#examNumberConfig'),
  2042. function () {},
  2043. self.selExamNumberStyle.bind(self)
  2044. )
  2045. //是否使用二维码
  2046. new Switch($('#useQrCode'), function (status) {
  2047. var $examNumberConfigOptions = $('#examNumberConfig .h_checkItem')
  2048. var $examNumberLayout = $('.examNumberLayout')
  2049. var $downLoadBtn = $('#downLoadBtn')
  2050. var $ewmTips = $('#ewmTips')
  2051. self.useQrCode = status
  2052. $downLoadBtn.html(status ? '生成' : '下载')
  2053. $examNumberConfigOptions.each(function () {
  2054. $(this)[status ? 'addClass' : 'removeClass']('disabled')
  2055. })
  2056. $('.className').html(status ? self.tpls.systemClassNoticeInfoTpl : '')
  2057. $('.examineeName').html(status ? self.tpls.systemNameNoticeInfoTpl : '')
  2058. $('.bindLineClassName').html(
  2059. status ? self.tpls.systemClassNoticeInfoForLineTpl : ''
  2060. )
  2061. $('.bindLineExamineeName').html(
  2062. status ? self.tpls.systemNameNoticeInfoForLineTpl : ''
  2063. )
  2064. self.editNoticeDetail(status,self.cardStatus)
  2065. $examNumberLayout[status ? 'addClass' : 'removeClass']('useqrcode')
  2066. $ewmTips.css('display', status ? 'flex' : 'none')
  2067. self.changePrintArea(self.$firstPageContent)
  2068. })
  2069. //单模块设置
  2070. $('#printcontent').on('click', '.settingBtn', function () {
  2071. if (!self.isCanEditCard) return
  2072. var $this = $(this)
  2073. var type = $this.attr('data-type')
  2074. //填空
  2075. if (type === 'fillInBlank') {
  2076. self.fillInBlankSet($this)
  2077. //选择 单选-多选
  2078. } else if (~type.indexOf('Select')) {
  2079. self.selectSetLayout($this, type)
  2080. } else {
  2081. self.shortAnswerSet($this)
  2082. }
  2083. })
  2084. // 给模块标题设置高度
  2085. $('#printcontent').on('click', '.answerModule h3', function () {
  2086. $(this).css('height','auto')
  2087. })
  2088. // 学校栏编辑状态
  2089. $('#printcontent').on('click', '.input-examInfo', function () {
  2090. if (!self.isCanEditCard){
  2091. $('.input-examInfo').attr("readonly","readonly");
  2092. } else {
  2093. $('.input-examInfo').removeAttr("readonly");
  2094. $('.input-examInfo.fraction').attr("readonly","readonly");
  2095. }
  2096. })
  2097. // 图片拖拽
  2098. // $('#printcontent').on('click', 'img', function () {
  2099. // if (!self.isCanEditCard) return
  2100. //
  2101. // })
  2102. //
  2103. // $('div').mousedown(function(e) {
  2104. // // e.pageX
  2105. // var positionDiv = $(this).offset();
  2106. // var distenceX = e.pageX - positionDiv.left;
  2107. // var distenceY = e.pageY - positionDiv.top;
  2108. // //alert(distenceX)
  2109. // // alert(positionDiv.left);
  2110. //
  2111. // $(document).mousemove(function(e) {
  2112. // var x = e.pageX - distenceX;
  2113. // var y = e.pageY - distenceY;
  2114. //
  2115. // if (x < 0) {
  2116. // x = 0;
  2117. // } else if (x > $(document).width() - $('div').outerWidth(true)) {
  2118. // x = $(document).width() - $('div').outerWidth(true);
  2119. // }
  2120. //
  2121. // if (y < 0) {
  2122. // y = 0;
  2123. // } else if (y > $(document).height() - $('div').outerHeight(true)) {
  2124. // y = $(document).height() - $('div').outerHeight(true);
  2125. // }
  2126. //
  2127. // $('div').css({
  2128. // 'left': x + 'px',
  2129. // 'top': y + 'px'
  2130. // });
  2131. // });
  2132. //
  2133. // $(document).mouseup(function() {
  2134. // $(document).off('mousemove');
  2135. // });
  2136. // });
  2137. function isPx(str) {
  2138. return /^\d+$/.test(str)
  2139. }
  2140. document.addEventListener(
  2141. 'error',
  2142. function (e) {
  2143. var elem = e.target
  2144. if (elem.tagName.toLowerCase() === 'img') {
  2145. var oh = $(elem).attr('height')
  2146. var ow = $(elem).attr('width')
  2147. if (!isPx(oh) || !isPx(ow)) return
  2148. var h = parseInt($(elem).attr('height'))
  2149. var w = parseInt($(elem).attr('width'))
  2150. var hmm = self.unitConversion.pxConversionMm(h)
  2151. var wmm = self.unitConversion.pxConversionMm(w)
  2152. $(elem).attr(
  2153. 'style',
  2154. $(elem).attr('style') +
  2155. ';height:' +
  2156. hmm +
  2157. 'mm !important;width:' +
  2158. wmm +
  2159. 'mm !important;'
  2160. )
  2161. }
  2162. },
  2163. true
  2164. )
  2165. document.addEventListener(
  2166. 'load',
  2167. function (e) {
  2168. var elem = e.target
  2169. if (
  2170. elem.tagName.toLowerCase() === 'img' &&
  2171. typeof $(elem).attr('word_img') === 'string'
  2172. ) {
  2173. var h = parseInt($(elem).attr('height'))
  2174. var w = parseInt($(elem).attr('width'))
  2175. var hmm = self.unitConversion.pxConversionMm(h)
  2176. var wmm = self.unitConversion.pxConversionMm(w)
  2177. $(elem).attr(
  2178. 'style',
  2179. $(elem).attr('style') +
  2180. ';height:' +
  2181. hmm +
  2182. 'mm !important;width:' +
  2183. wmm +
  2184. 'mm !important;'
  2185. )
  2186. }
  2187. },
  2188. true
  2189. )
  2190. self.eventForFormula()
  2191. },
  2192. //公式编辑器相关事件
  2193. eventForFormula: function () {
  2194. var self = this
  2195. var curEditorFormula = null
  2196. $('body').on('click', '.kfformula,.gsImgLatex', function () {
  2197. if (!self.isCanEditCard) return
  2198. self.formulaing = true
  2199. $('#formulaBox').show()
  2200. curEditorFormula = $(this)
  2201. var imgLatex =
  2202. $(this).attr('data-latex') || $(this).attr('src').split('?')[1]
  2203. var latexUse = unescape(imgLatex) //'\left\{ {\left( {x\;,\;y} \right)\left| {y = 2x - 1} \right.} \right\}'//
  2204. if (window.kfe) {
  2205. window.kfe.execCommand('render', latexUse || '\\placeholder')
  2206. } else {
  2207. window.factory = window.kf.EditorFactory.create(
  2208. $('#kfEditorContainer')[0],
  2209. {
  2210. render: {
  2211. fontsize: 24
  2212. },
  2213. resource: {
  2214. path: './js/kityformula/resource/'
  2215. }
  2216. }
  2217. )
  2218. window.factory.ready(function (KFEditor) {
  2219. KFEditor.execCommand('render', latexUse || '\\placeholder')
  2220. KFEditor.execCommand('focus')
  2221. window.kfe = KFEditor
  2222. })
  2223. $('#kf-formula-ensure')[0].onclick = function () {
  2224. window.kfe.execCommand('get.image.data', function (data) {
  2225. var latex = encodeURIComponent(window.kfe.execCommand('get.source'))
  2226. $.post(
  2227. self.apis.getMathtexApi,
  2228. { mathtex: window.kfe.execCommand('get.source') },
  2229. function (res) {
  2230. var newh = self.unitConversion.pxConversionMm(res.height)
  2231. var neww = self.unitConversion.pxConversionMm(res.width)
  2232. var newLatexImg =
  2233. '<img src="{url}" class="gsImgLatex mathType" style="vertical-align: middle;height:{newh}mm;width:{neww}mm;" data-latex="{latex}">'
  2234. curEditorFormula[0].outerHTML = newLatexImg.substitute({
  2235. url: res.url,
  2236. latex: latex,
  2237. newh: newh,
  2238. neww: neww
  2239. })
  2240. }
  2241. )
  2242. return true
  2243. })
  2244. $('#formulaBox').hide()
  2245. self.formulaing = false
  2246. return false
  2247. }
  2248. $('#kf-formula-cancel')
  2249. .off('click')
  2250. .click(function () {
  2251. $('#formulaBox').hide()
  2252. self.formulaing = false
  2253. })
  2254. }
  2255. })
  2256. },
  2257. changeCardEditStatus: function () {
  2258. var self = this
  2259. $('#dtkName textarea').prop('disabled', !self.isCanEditCard)
  2260. $('#saveBtn').html(self.isCanEditCard ? '保存' : '编辑')
  2261. $('#downLoadBtn')[self.isCanEditCard ? 'addClass' : 'removeClass'](
  2262. 'disabled'
  2263. )
  2264. //右侧操作栏目
  2265. $('#disabledCover')[self.isCanEditCard ? 'hide' : 'show']()
  2266. //题干信息
  2267. $('.objectiveItem').each(function () {
  2268. $(this).prop('contenteditable', self.isCanEditCard)
  2269. })
  2270. //编辑器
  2271. for (var editorId in self.editorArea) {
  2272. self.editorArea[editorId].$textElem.attr(
  2273. 'contenteditable',
  2274. self.isCanEditCard
  2275. )
  2276. }
  2277. //标题
  2278. $('.answerModule h3').each(function () {
  2279. $(this).prop('contenteditable', self.isCanEditCard)
  2280. })
  2281. },
  2282. //检测是否有已经生成的答题卡
  2283. judgeHasPrintClass: function (cb) {
  2284. var self = this
  2285. if (self.printClassStatus) {
  2286. self.modal.init({
  2287. title: '批量生成',
  2288. content:
  2289. '保存后,会重置原答题卡数据,将恢复班级/学生的打印状态,且可能会导致已打印出的答题卡扫描无效,请谨慎操作!',
  2290. sureCb: function () {
  2291. cb && cb()
  2292. }
  2293. })
  2294. } else {
  2295. cb && cb()
  2296. }
  2297. },
  2298. //根据选择排版方向设置答题卡的视觉排版宽高
  2299. setPageWidthHeightForDirection: function (direction) {
  2300. var self = this
  2301. var isVertical = direction === 'vertical'
  2302. //设置横竖版面
  2303. self.config[isVertical ? 'width' : 'height'] = self.configOrigin.width
  2304. self.config[isVertical ? 'height' : 'width'] = self.configOrigin.height
  2305. },
  2306. //点击选择纸张联动,纸张方向和纸张分栏选择
  2307. linkageForPaper: function (paper) {
  2308. var self = this
  2309. // '8K': {
  2310. // width: 267,
  2311. // height: 390,
  2312. // direction: {
  2313. // horizontal: [2, 3]
  2314. // }
  2315. // },
  2316. //layoutList
  2317. self.config = simpleCopy(sizeConfig[paper])
  2318. self.configOrigin = simpleCopy(sizeConfig[paper])
  2319. var directions = self.config.direction
  2320. var isPaperDirectionStop = false
  2321. $('#paperDirection .h_radioItem').each(function () {
  2322. var direction = $(this).attr('data-direction')
  2323. if (direction in directions) {
  2324. $(this).removeClass('disabled')
  2325. if (!isPaperDirectionStop) {
  2326. isPaperDirectionStop = true
  2327. $(this).trigger('click')
  2328. }
  2329. } else {
  2330. $(this).addClass('disabled')
  2331. }
  2332. })
  2333. },
  2334. //点击选择纸张方向联动 分栏选择
  2335. linkageForDirection: function (columns) {
  2336. var self = this
  2337. var isLayoutItemStop = false
  2338. self.$layoutItem.each(function () {
  2339. var $this = $(this)
  2340. var dataColumn = +$this.attr('data-column')
  2341. if (~columns.indexOf(dataColumn)) {
  2342. $this.removeClass('disabled')
  2343. if (!isLayoutItemStop) {
  2344. isLayoutItemStop = true
  2345. $this.trigger('click')
  2346. }
  2347. } else {
  2348. $this.addClass('disabled')
  2349. }
  2350. })
  2351. },
  2352. //选择题
  2353. selectSetLayout: function ($this, type) {
  2354. var self = this
  2355. var memoryDirection = $this.closest('.answerModule').attr('data-direction')
  2356. var directionCheckMap = {
  2357. vertical: 'verticalChecked',
  2358. horizontal: 'horizontalChecked'
  2359. }
  2360. var substituteData = {}
  2361. substituteData[directionCheckMap[memoryDirection]] = 'checked'
  2362. var tempDirection = ''
  2363. self.modal.init({
  2364. title: '选择题设置',
  2365. content: self.tpls.selectSetTpl.substitute(substituteData),
  2366. afterCb: function () {
  2367. new RadioBoxItem($('#selectDirection'), function ($radioItem, status) {
  2368. var direction = $radioItem.attr('data-value')
  2369. tempDirection = direction
  2370. })
  2371. },
  2372. sureCb: function () {
  2373. self.selectStyleChange($this, type, tempDirection)
  2374. }
  2375. })
  2376. },
  2377. selectStyleChange: function ($this, type, direction) {
  2378. var self = this
  2379. var curPageIndex = $this.closest('.pageContent').index() + 1
  2380. var $selectModule = $this.closest('.single-select')
  2381. var $curPage = $this.closest('.pageContent')
  2382. self[type].direction = direction
  2383. function setDirection($selectModule) {
  2384. if (!$selectModule.hasClass(direction)) {
  2385. var isHorizontal = direction === 'horizontal'
  2386. $selectModule
  2387. .removeClass(isHorizontal ? 'vertical' : 'horizontal')
  2388. .addClass(isHorizontal ? 'horizontal' : 'vertical')
  2389. .attr('data-direction', direction)
  2390. }
  2391. curPageIndex++
  2392. if (self[type]['page' + curPageIndex]) {
  2393. var $nextPage = $('.pageContent').eq(curPageIndex - 1)
  2394. var $nextPageFirstSelect = $nextPage.find('.single-select').eq(0)
  2395. setDirection($nextPageFirstSelect)
  2396. }
  2397. }
  2398. setDirection($selectModule)
  2399. self.changePrintArea($curPage)
  2400. },
  2401. //填空题设置
  2402. fillInBlankSet: function ($this) {
  2403. var self = this
  2404. var $subjectCol = $this.siblings('.subjectCol')
  2405. var columnSelectedMap = {
  2406. 1: 'columnOneSelected',
  2407. 2: 'columnTwoSelected',
  2408. 3: 'columnThreeSelected'
  2409. }
  2410. var rowLineHeightSelectedMap = {
  2411. 25: 'rowLineOneSelected',
  2412. 30: 'rowLineTwoSelected',
  2413. 35: 'rowLineThreeSelected',
  2414. 40: 'rowLineFourSelected',
  2415. 45: 'rowLineFiveSelected',
  2416. 50: 'rowLineSixSelected'
  2417. }
  2418. var scoreSelectedMap = {
  2419. '2/3/5': 'scoreOneSelected',
  2420. '2/3/4/6': 'scoreTwoSelected',
  2421. '2/4': 'scoreThreeSelected'
  2422. }
  2423. var memoryColumn = $subjectCol.attr('data-column') || 1
  2424. var memoryColumnRowLineHeight = $subjectCol.attr('data-rowLineHeight') || 40
  2425. var memoryScoreStyle = $subjectCol.attr('data-scoreStyle') || ''
  2426. var maxScoreArr = $subjectCol
  2427. .find('.subjectItem')
  2428. // .attr('data-fullScore')
  2429. // var maxScore = $subjectCol
  2430. // .children('.subjectItem')
  2431. // .eq(0)
  2432. // .attr('data-fullScore')
  2433. var substituteData = {}
  2434. substituteData[columnSelectedMap[memoryColumn]] = 'selected'
  2435. substituteData[rowLineHeightSelectedMap[memoryColumnRowLineHeight]] =
  2436. 'selected'
  2437. substituteData[scoreSelectedMap[memoryScoreStyle]] = 'selected'
  2438. for (var scoreFormat in scoreSelectedMap) {
  2439. let isDisabled = false
  2440. for( let i=0; i<maxScoreArr.length;i++){
  2441. let maxScore = $(maxScoreArr[i]).attr('data-fullScore')
  2442. if (!~scoreFormat.split('/').indexOf(maxScore)) {
  2443. isDisabled = true
  2444. // substituteData[scoreSelectedMap[scoreFormat]] = 'disabled'
  2445. }
  2446. }
  2447. if(isDisabled){
  2448. substituteData[scoreSelectedMap[scoreFormat]] = 'disabled'
  2449. }
  2450. }
  2451. self.modal.init({
  2452. title: '填空题设置',
  2453. content: self.tpls.fillInBlankSetTpl.substitute(substituteData),
  2454. sureCb: function () {
  2455. //每行列数
  2456. var column = $('#fillInBlankColumn').val()
  2457. //行间距
  2458. var rowLinHeight = $('#fillInBlankLineHeight').val()
  2459. //手写打分
  2460. var scoreStyle = $('#scoringBox').val()
  2461. //修改填空题样式
  2462. self.fillInBlankStyleChange($this, column, rowLinHeight, scoreStyle)
  2463. }
  2464. })
  2465. },
  2466. fillInBlankStyleChange: function ($this, column, rowLinHeight, scoreStyle) {
  2467. var self = this
  2468. var curPageEl = $this.closest('.pageContent')
  2469. var $fillInBlankCol = $('.pageContent').find('.subjectCol')
  2470. scoreStyle = scoreStyle || ''
  2471. //重新计算fillInBlank 查看是否需要修改手动打分样式
  2472. self.fillInBlank = self.calcFillInBlankData(
  2473. self.fillInBlank,
  2474. scoreStyle,
  2475. column
  2476. )
  2477. self.reRenderFillInBlank()
  2478. $fillInBlankCol.attr({
  2479. 'data-column': column,
  2480. 'data-rowLineHeight': rowLinHeight,
  2481. 'data-scoreStyle': scoreStyle,
  2482. class:
  2483. 'subjectCol clearfix col-' + column + ' rowLineHeight-' + rowLinHeight
  2484. })
  2485. //如果填空题由原来的一行变成多行,就有可能影响所有的布局样式,重新布局整个答题卡
  2486. self.changePrintArea(curPageEl)
  2487. },
  2488. //解答题设置
  2489. shortAnswerSet: function ($this) {
  2490. var self = this
  2491. var $module = $this.closest('.module')
  2492. var memoryScoreLimitKey = $module.attr('scoreLimit')
  2493. var fullScore = +$module.attr('data-fullScore')
  2494. var memoryIsAddHalf = $module.attr('isAddHalf') === 'true'
  2495. var disabledScoreKey
  2496. var limitSelectedMap = {
  2497. 15: 'limit15selected',
  2498. 16: 'limit16selected',
  2499. 29: 'limit29selected',
  2500. 49: 'limit49selected'
  2501. }
  2502. //禁用标识
  2503. var disabledSelectMap = {
  2504. 15: 'disabled15',
  2505. 16: 'disabled16',
  2506. 29: 'disabled29',
  2507. 49: 'disabled49'
  2508. }
  2509. var formatParam = {}
  2510. formatParam[limitSelectedMap[memoryScoreLimitKey]] = 'selected'
  2511. formatParam.isAddHalfChecked = memoryIsAddHalf ? 'checked' : ''
  2512. for (
  2513. var j = 0, scoreLimit;
  2514. (scoreLimit = self.answerScoreLimitKeyArr[j++]);
  2515. ) {
  2516. if (scoreLimit < fullScore) {
  2517. formatParam[disabledSelectMap[scoreLimit]] = 'disabled'
  2518. }
  2519. }
  2520. self.modal.init({
  2521. title: '解答题设置',
  2522. content: self.tpls.shortAnswerOptionTpl.substitute(formatParam),
  2523. sureCb: function () {
  2524. var scoreLimitKey = $('#scoreLimit').val()
  2525. var isAddHalf = $('#isAddHalf').prop('checked')
  2526. self.shortAnswerStyleChange($this, scoreLimitKey, isAddHalf ,fullScore)
  2527. }
  2528. })
  2529. },
  2530. /**
  2531. * @param {当前要修改的解答题区域内的标示符} $this
  2532. * @param {分值上限} scoreLimitKey
  2533. */
  2534. shortAnswerStyleChange: function ($this, scoreLimitKey, isAddHalf, topicScore) {
  2535. var self = this
  2536. var scorePartEl = $this.siblings('.scortColumn')
  2537. var colClass = 'col-' + scoreLimitKey
  2538. var scoreModuleHtml = self.generateScoreBox(scoreLimitKey, isAddHalf,topicScore)
  2539. //解答题分值上限配置
  2540. scorePartEl
  2541. .html(scoreModuleHtml)
  2542. .attr('class', 'scortColumn clearfix ' + colClass)
  2543. .parent('.module')
  2544. .attr('scoreLimit', scoreLimitKey)
  2545. .attr('isAddHalf', isAddHalf)
  2546. },
  2547. generateScoreBox: function (scoreLimitKey, isAddHalf,topicScore) {
  2548. var self = this
  2549. function rendScore(score) {
  2550. return '<span>' + score + '</span>'
  2551. }
  2552. var bit = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
  2553. //各个分值对应的分值 布局格式
  2554. var scoreLimitMap = {
  2555. '16': [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16],
  2556. '15': [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15],
  2557. '29': {
  2558. tenPlace: [1, 2],
  2559. bit: bit
  2560. },
  2561. '49': {
  2562. tenPlace: [1, 2, 3, 4],
  2563. bit: bit
  2564. }
  2565. }
  2566. var scoreLimit = scoreLimitMap[scoreLimitKey]
  2567. var scoreModuleHtml = ''
  2568. var scoreLimitArr = []
  2569. var noScoringW = 42
  2570. let pw = $('#printcontent').width();
  2571. noScoringW = pw/17
  2572. if (~'16|15'.indexOf(scoreLimitKey)) {
  2573. if (Number(topicScore) < Number(scoreLimitKey)) {
  2574. for (let index = 0; index < topicScore; index++) {
  2575. scoreLimitArr.push(index + 1)
  2576. }
  2577. } else {
  2578. scoreLimitArr = scoreLimit
  2579. }
  2580. } else {
  2581. scoreLimitArr.push('十位')
  2582. scoreLimitArr = scoreLimitArr.concat(scoreLimit.tenPlace)
  2583. scoreLimitArr.push('个位')
  2584. scoreLimitArr = scoreLimitArr.concat(scoreLimit.bit)
  2585. }
  2586. //是否增加0.5分机制
  2587. isAddHalf && scoreLimitArr.push('0.5')
  2588. scoreLimitArr.forEach(function (score, index) {
  2589. scoreModuleHtml += rendScore(score)
  2590. })
  2591. if (Number(topicScore) < Number(scoreLimitKey) && Number(scoreLimitKey) < 17) {
  2592. let width = (15 - topicScore) * noScoringW;
  2593. if (width < 48) {
  2594. width = 48
  2595. }
  2596. scoreModuleHtml += "<span class='no-scoring' style='flex: initial; width:" + width + "px; color: #dddddd;'>禁打分区</span>"
  2597. }
  2598. return scoreModuleHtml
  2599. },
  2600. editNoScoringWidth: function () {
  2601. let pw = $('#printcontent').width();
  2602. $('.scortColumn').each(function(i,k){
  2603. let kL = $(k).find('span').length;
  2604. let kw = pw/17*(16-kL);
  2605. if(kw<48){
  2606. kw = 48
  2607. }
  2608. $(k).find('.no-scoring').width(kw);
  2609. })
  2610. },
  2611. //是否有装订线
  2612. ifBindingLine: function () {
  2613. var self = this
  2614. var curPageEl = self.$firstPageContent
  2615. var isUseClass = self.hasBindingLine ? 'addClass' : 'removeClass'
  2616. var isHideBinding = self.hasBindingLine ? 'show' : 'hide'
  2617. var isHideExamineeInfo = !self.hasBindingLine ? 'show' : 'hide'
  2618. $('#printcontent')
  2619. [isUseClass]('hasBindingLine')
  2620. .find('.bindingLine')
  2621. [isHideBinding]()
  2622. $('#examineeInfoForLayout')[isHideExamineeInfo]()
  2623. //隐藏考生的姓名 班级信息也会影响布局
  2624. self.changePrintArea(curPageEl)
  2625. },
  2626. //是否显示信息栏
  2627. isShowPaperMsg: function () {
  2628. var self = this
  2629. if (self.hasPaperMsg) {
  2630. // let examInfo ={}
  2631. // var examInfoHtml = self.tpls.examInfoTpl.substitute(examInfo)
  2632. // $('#examInfo').html(examInfoHtml)
  2633. self.showExamInfoHtml();
  2634. self.getSaveSubjectInfo(self.questionMap)
  2635. $('#examInfo').css('display', 'flex');
  2636. $('#hasPaperMsg').find('.h_radioItem').eq(0).addClass('checked')
  2637. $('#hasPaperMsg').find('.h_radioItem').eq(1).removeClass('checked')
  2638. } else {
  2639. $('#hasPaperMsg').find('.h_radioItem').eq(0).removeClass('checked')
  2640. $('#hasPaperMsg').find('.h_radioItem').eq(1).addClass('checked')
  2641. $('#printcontent').find('#examInfo').html('');
  2642. $('#examInfo').css('display', 'none');
  2643. }
  2644. },
  2645. showExamInfoHtml: function () {
  2646. var self = this
  2647. if(!self.hasPaperMsg){
  2648. return false
  2649. }
  2650. let examInfoHtml = '';
  2651. if (self.examInfoConfig.wpTimes) {
  2652. if(self.examInfoConfigText.wpTimes == undefined) {
  2653. self.examInfoConfigText.wpTimes = ''
  2654. }
  2655. examInfoHtml += '<span>时间:<input class="input-examInfo time" name="wpTimes" maxlength="3" value="' + self.examInfoConfigText.wpTimes + '"></input>分钟</span>'
  2656. }
  2657. if (self.examInfoConfig.fullScore) {
  2658. if(self.examInfoConfigText.fullScore == undefined) {
  2659. self.examInfoConfigText.fullScore = ''
  2660. }
  2661. examInfoHtml += '<span>满分:<input readonly="readonly" class="input-examInfo fraction" name="fullScore" maxlength="3" value="' + self.examInfoConfigText.fullScore + '"></input>分</span>'
  2662. }
  2663. if (self.examInfoConfig.wpAuthor) {
  2664. if(self.examInfoConfigText.wpAuthor == undefined) {
  2665. self.examInfoConfigText.wpAuthor = ''
  2666. }
  2667. examInfoHtml += '<span>命卷人:<input class="input-examInfo" name="wpAuthor" maxlength="9" value="' + self.examInfoConfigText.wpAuthor + '"></input></span>'
  2668. }
  2669. if (self.examInfoConfig.wpReviewer) {
  2670. if(self.examInfoConfigText.wpReviewer == undefined) {
  2671. self.examInfoConfigText.wpReviewer = ''
  2672. }
  2673. examInfoHtml += '<span>审核人:<input class="input-examInfo" name="wpReviewer" maxlength="9" value="' + self.examInfoConfigText.wpReviewer + '"></input></span>'
  2674. }
  2675. examInfoHtml += '<div class="btn-examInfo"></div>'
  2676. $('#examInfo').html(examInfoHtml);
  2677. if (examInfoHtml.length < 33) {
  2678. $('#hasPaperMsg').find('.h_radioItem').removeClass('checked')
  2679. $('#hasPaperMsg').find('.h_radioItem').eq(1).addClass('checked')
  2680. $('#examInfo').css('display', 'none')
  2681. } else {
  2682. $('#hasPaperMsg').find('.h_radioItem').removeClass('checked')
  2683. $('#hasPaperMsg').find('.h_radioItem').eq(0).addClass('checked')
  2684. $('#examInfo').css('display', 'flex')
  2685. }
  2686. },
  2687. //是否只使用条形码
  2688. isOnlyBarCode: function () {
  2689. var self = this
  2690. return self.examNumberConfig.barCode && !self.examNumberConfig.ticketNumber
  2691. },
  2692. //判断当前选中个数
  2693. getExamConfigSeledCount: function () {
  2694. var self = this
  2695. var seledCount = 0
  2696. //条形码 和 考号 至少选择一个
  2697. for (var examKey in self.examNumberConfig) {
  2698. if (self.examNumberConfig[examKey]) {
  2699. seledCount += 1
  2700. }
  2701. }
  2702. return seledCount
  2703. },
  2704. //选择考号版式
  2705. selExamNumberStyle: function ($this, singleStatus) {
  2706. var self = this
  2707. var value = $this.attr('data-value')
  2708. //当前选考号配置的数量
  2709. var curExamConfigCount = self.getExamConfigSeledCount()
  2710. if (!singleStatus && curExamConfigCount === 1) {
  2711. hgc_layer.msg('不使用二维码的情况下,填涂考号和条形码至少选择一个')
  2712. $this.trigger('click')
  2713. return
  2714. }
  2715. self.examNumberConfig[value] = singleStatus
  2716. $('#hgc_examNumber .' + value)[singleStatus ? 'show' : 'hide']()
  2717. //只使用条形码
  2718. var isOnlyBarCode = self.isOnlyBarCode()
  2719. $('#hgc_examNumber').css('display', isOnlyBarCode ? 'none' : 'flex')
  2720. $('#hgc_examNumberForOnlyBarcode').css(
  2721. 'display',
  2722. isOnlyBarCode ? 'flex' : 'none'
  2723. )
  2724. self.changePrintArea(self.$firstPageContent)
  2725. },
  2726. //选择信息栏显示模块
  2727. selExamInfoStyle: function ($this, singleStatus) {
  2728. var self = this
  2729. let value = $this.attr('data-value');
  2730. self.examInfoConfig[value] = singleStatus;
  2731. },
  2732. //更新label显示文本
  2733. refrushPageLabel: function () {
  2734. var self = this
  2735. $('.pageLabel').each(function (index, $label) {
  2736. var curTotalPage = index + 1
  2737. var currentPaper = Math.ceil((index + 1) / (self.columns * 2))
  2738. //第一张纸 正面1 正面2 第一张至反面1 反面2
  2739. var paperDirection =
  2740. (curTotalPage % (self.columns * 2)
  2741. ? curTotalPage % (self.columns * 2)
  2742. : self.columns * 2) <= self.columns
  2743. ? '正面'
  2744. : '反面'
  2745. var pageForPaperDirection =
  2746. curTotalPage % self.columns ? curTotalPage % self.columns : self.columns
  2747. var currentPaperPage = paperDirection + pageForPaperDirection
  2748. var labelHtml = self.tpls.pageLabelTpl.substitute({
  2749. currentPage: curTotalPage,
  2750. totalPage: self.totalPage,
  2751. currentPaper: currentPaper,
  2752. currentPaperPage: currentPaperPage
  2753. })
  2754. $(this).html(labelHtml)
  2755. })
  2756. },
  2757. //重新计算同一题相同模块的
  2758. //存储当前超出缺没有被执行超出事件的模块
  2759. forgetOverPage: null,
  2760. saveForgetPage: function (forgetPage) {
  2761. var self = this
  2762. //之前当前被遗忘的分页在前面,就可以直接替换
  2763. if (self.forgetOverPage) {
  2764. if (forgetPage.index() < self.forgetOverPage.index()) {
  2765. self.forgetOverPage = forgetPage
  2766. }
  2767. } else {
  2768. self.forgetOverPage = forgetPage
  2769. }
  2770. },
  2771. resetPrevEditorContent: function ($surplusModule, $prevModule,type) {
  2772. var self = this
  2773. // var surplusModuleContentHeight = self.calcEditorContentHeight(
  2774. // $surplusModule.find('.editorContent')
  2775. // )
  2776. var surplusModuleContentHeight = $surplusModule.find('.editorContent').height();
  2777. var prevPage = $prevModule.closest('.pageContent')
  2778. var prevPageContentHeight = prevPage.height() - self.pagePadding * 2
  2779. //内容区域
  2780. // var $prevContentArea = $prevModule.find('.w-e-text-container')
  2781. var $prevContentArea = $($prevModule).children('.editorContent').children()
  2782. if($prevContentArea==undefined || $prevContentArea.length==0){
  2783. $prevContentArea = $prevModule.find('.editorContent')
  2784. }
  2785. // var $prevContentArea = $prevModule.find('.editorContent')
  2786. // var prevEditorIndex = $prevModule.attr('data-editorIndex')
  2787. // var surplusEditorIndex = $surplusModule.attr('data-editorIndex')
  2788. // var surplusEditorContent = self.editorArea[
  2789. // 'editor' + surplusEditorIndex
  2790. // ].txt
  2791. // .html()
  2792. // .clearFixible()
  2793. // var prevEditorContent = self.editorArea['editor' + prevEditorIndex].txt
  2794. // .html()
  2795. // .clearFixible()
  2796. // var prevCalcHeight = $prevContentArea.height() + surplusModuleContentHeight
  2797. // self.editorArea['editor' + prevEditorIndex].txt.html(
  2798. // (
  2799. // prevEditorContent +
  2800. // surplusEditorContent +
  2801. // self.tpls.flexibleIconTpl
  2802. // ).replace(self.replaceEditorRegexp, '')
  2803. // )
  2804. var surplusEditorContent = $surplusModule.find('.w-e-text').html();
  2805. if(surplusEditorContent==undefined){
  2806. surplusEditorContent = $surplusModule.find('.editorContent').html();
  2807. }
  2808. var prevEditorContent = $prevContentArea.html();
  2809. // if(surplusEditorContent==undefined){
  2810. // prevEditorContent = $prevModule.find('.editorContent').html();
  2811. // }
  2812. let prevModuleH = $prevContentArea.height();
  2813. if($prevModule.find('.editorContent').height()>prevModuleH){
  2814. prevModuleH = $prevModule.find('.editorContent').height()
  2815. }
  2816. var prevCalcHeight = prevModuleH + surplusModuleContentHeight;
  2817. if(type === 'surplus'){
  2818. prevCalcHeight = prevModuleH
  2819. }
  2820. let topicHtml = prevEditorContent +surplusEditorContent
  2821. // let isW = $(topicHtml).find('.w-e-text')
  2822. let isW = topicHtml.search(".w-e-text")
  2823. if(isW>-1){
  2824. if(prevEditorContent==''){
  2825. topicHtml = surplusEditorContent
  2826. } else {
  2827. let isSurplusW = surplusEditorContent.search(".w-e-text")
  2828. if(isSurplusW>-1){
  2829. surplusEditorContent = surplusEditorContent.replace(/.w-e-text/g,'');
  2830. } else {
  2831. prevEditorContent = prevEditorContent.replace(/.w-e-text/g,'');
  2832. }
  2833. // topicHtml = $(prevEditorContent).prepend(surplusEditorContent)
  2834. // topicHtml = prevEditorContent+ surplusEditorContent
  2835. topicHtml = '<div class="w-e-text">'+prevEditorContent +surplusEditorContent+'<div>'
  2836. }
  2837. } else {
  2838. topicHtml = '<div class="w-e-text">'+prevEditorContent +surplusEditorContent+'<div>'
  2839. }
  2840. $prevModule.find('.editorContent').html(topicHtml)
  2841. let wH = $prevModule.find('.editorContent').children().height()
  2842. if(wH>prevCalcHeight){
  2843. prevCalcHeight = wH
  2844. }
  2845. $($prevModule).children('.editorContent').height(prevCalcHeight)
  2846. if (self.getOverHeight($prevModule) > 0) {
  2847. //之前当前被遗忘的分页在前面,就可以直接替换
  2848. self.saveForgetPage(prevPage)
  2849. }
  2850. },
  2851. /**
  2852. * 删除一个分页超出的部分
  2853. * @param {*} $delBtn 删除按钮
  2854. * @param {el} type 下面两种类型的值 over surplus
  2855. * @param {boolean} isUserTrigger 是否用户主动手动触发---触发
  2856. * 1 上一页有超出模块,下一页的补充模块需要删除的情况
  2857. * 2 上一页有剩余空间,下一页的补充模块一样需要删除的情况
  2858. * 两种情况计算当前需要删除的补充模块的上一个模块的方式有所不同
  2859. */
  2860. //判断是不是补充模块
  2861. isSurplusModule: function (module) {
  2862. return typeof module.attr('isSurplus') === 'string'
  2863. },
  2864. //需要把内容部分全部移到上面的部分,然后上面的高度要重置一下
  2865. delPageOverPart: function ($delBtn, type, isUserTrigger) {
  2866. var self = this
  2867. var answerModel = $delBtn.closest('.short-answer')
  2868. var delModel = $delBtn.closest('.module')
  2869. var delPage = delModel.closest('.pageContent')
  2870. var prevPage = delPage.prev()
  2871. //默认上一页有超出模块的时候计算方式
  2872. var memoryPrevModule = delModel
  2873. .closest('.answerModule')
  2874. .prev('.answerModule')
  2875. .children('.module:last()')
  2876. var prevPageLastEditor = memoryPrevModule.children('.editorContent')
  2877. //如果是上一页有剩余空间才来的话
  2878. if (type === 'surplus') {
  2879. var loopPrevPage = delPage.prev()
  2880. while (!memoryPrevModule.length) {
  2881. memoryPrevModule = loopPrevPage.find('.module:last()')
  2882. loopPrevPage = loopPrevPage.prev()
  2883. }
  2884. }
  2885. self.resetPrevEditorContent(delModel, memoryPrevModule,type)
  2886. //点击删除重置上一页最后一个模块的高度
  2887. prevPageLastEditor.height(
  2888. prevPageLastEditor.height() - self.modulePaddingBottom
  2889. )
  2890. delModel.remove()
  2891. self.updatePageElement(delPage, answerModel)
  2892. //判断上一个模块是否是第一个链接模块
  2893. // if (prevPageLastModule.attr('data-linkparm') === '1') {
  2894. // prevPageLastModule.removeAttr('data-linkparm')
  2895. // }
  2896. if (!answerModel.children('.module').length) answerModel.remove()
  2897. if (isUserTrigger) {
  2898. self.changePrintArea(delPage)
  2899. }
  2900. },
  2901. /**
  2902. * 获取超出当前page的模块 作答大题区域模块 作答小题区域模块
  2903. * @return {answerModule,subjectModule}
  2904. */
  2905. getOverModule: function (curPageEl) {
  2906. var self = this
  2907. var overPart = false
  2908. //当前第几页,用做后面计算的高度距离的倍数
  2909. var times = curPageEl.index() + 1
  2910. //判断超出当前页面的条件
  2911. var overHeight =
  2912. self.pageHeight * times + self.layoutPadding - self.pagePadding
  2913. //判断当前区域是否超出
  2914. function isOver(el) {
  2915. var moduleTop =
  2916. $(el).outerHeight() + $(el).offset().top + $('#contentWrap').scrollTop()
  2917. return moduleTop >= overHeight
  2918. }
  2919. /**
  2920. * 1 判断当前页面里面的答题区域内容是否超过了当前页面所能承受的内容的高度
  2921. * a 如果超出了,从当前移动的那个模块开始向后判断,取出所有超出的模块
  2922. * I 在下一页的排版中,如果下一页存在直接插入最前面,如果不存在,直接新建一页==>>然后循环【1】操作
  2923. * b 如果没有超出直接退出
  2924. */
  2925. //需要判断当前page里面所有模块是否有超出
  2926. //当前答题卡区域
  2927. var curDtkPartEl = curPageEl.children('.dtk-content')
  2928. if (curDtkPartEl[0].clientHeight + self.pagePadding * 2 >= self.pageHeight) {
  2929. //区分原题题干和答题区域
  2930. var shortAnswerEl = [].splice.call(
  2931. curDtkPartEl.children('.answerModule'),
  2932. 0
  2933. )
  2934. //var shortAnswerEl = objectiveModule.concat(shortANswerModule)
  2935. for (var i = 0, ilen = shortAnswerEl.length; i < ilen; i++) {
  2936. var shortAnswerItem = $(shortAnswerEl[i])
  2937. //找到第一个超过当前页面的元素,把这个以及以后的模块提取出来在下一个版面进行重新排版
  2938. //得到第一个大题的index 第一个大题下面小题的index
  2939. if (isOver(shortAnswerItem)) {
  2940. var answerType = shortAnswerItem.attr('data-type')
  2941. var isChooseAnswer = answerType === 'chooseAnswer'
  2942. var hasObjective = shortAnswerItem.find('.originSubjectInfo').length
  2943. var isObjective = answerType === 'objective'
  2944. var childrenSelector =
  2945. isChooseAnswer && hasObjective
  2946. ? ''
  2947. : isObjective
  2948. ? '.objectiveItem'
  2949. : '.module'
  2950. var moduleEl = $(shortAnswerItem).children(childrenSelector)
  2951. for (var m = 0, mlen = moduleEl.length; m < mlen; m++) {
  2952. var moduleItem = moduleEl.eq(m)
  2953. if (isOver(moduleItem)) {
  2954. var subjectModule = null
  2955. //选做题如果题干信息超出的话,也特殊模块超出,因为选做题模块可能很长
  2956. var objectiveModule = null
  2957. if (isChooseAnswer) {
  2958. if (moduleItem[0].tagName === 'H3') {
  2959. objectiveModule = moduleItem
  2960. if (moduleItem.next().length) {
  2961. subjectModule = moduleItem.next()
  2962. }
  2963. } else {
  2964. subjectModule = moduleItem
  2965. }
  2966. } else {
  2967. subjectModule = moduleItem
  2968. }
  2969. overPart = {
  2970. curPage: curPageEl,
  2971. //当前超出的answerModule
  2972. answerModule: shortAnswerItem,
  2973. //当前超出的module
  2974. subjectModule: subjectModule,
  2975. //当前超出的选做题题干信息
  2976. objectiveModule: objectiveModule
  2977. }
  2978. return overPart
  2979. }
  2980. }
  2981. }
  2982. }
  2983. }
  2984. return overPart
  2985. },
  2986. //获取超出模块高度
  2987. getOverHeight: function (el) {
  2988. var self = this
  2989. var curPageEl = $(el).closest('.pageContent')
  2990. //当前第几页,用做后面计算的高度距离的倍数
  2991. var times = curPageEl.index() + 1
  2992. var overHeight =
  2993. self.pageHeight * times + self.layoutPadding - self.pagePadding
  2994. var moduleTop =
  2995. $(el).outerHeight() + $(el).offset().top + $('#contentWrap').scrollTop()
  2996. return moduleTop - overHeight - 4
  2997. },
  2998. //根据缩放的要求拓宽需要打印的区域
  2999. /*
  3000. * 1拓宽打印区域
  3001. * 2减小打印区域
  3002. */
  3003. changePrintArea: function (curPageEl) {
  3004. var self = this
  3005. if (self.forgetOverPage && self.forgetOverPage[0] === curPageEl[0]) {
  3006. self.forgetOverPage = null
  3007. }
  3008. //找出超出的区域
  3009. var overPart = self.getOverModule(curPageEl)
  3010. if (overPart) {
  3011. //填空题选择题特殊对待
  3012. var moduleType = overPart.answerModule.attr('data-type')
  3013. if (moduleType === 'fillInBlank') {
  3014. self.addPrintForFillInBlank(curPageEl, overPart)
  3015. } else if (~moduleType.indexOf('Select')) {
  3016. self.addPrintForSelect(curPageEl, overPart, moduleType)
  3017. } else if (moduleType === 'objective') {
  3018. self.addPrintForObjective(curPageEl, overPart)
  3019. self.judegeImgsLoaded('.objectiveItem')
  3020. } else {
  3021. self.addPrintForAnswer(curPageEl, overPart)
  3022. }
  3023. } else {
  3024. self.reducePrintArea(curPageEl)
  3025. }
  3026. },
  3027. //重新计算填空题渲染数据,改变填空题手动打分分值样式
  3028. calcFillInBlankData: function (fillInBlankData, scoreStyle, column) {
  3029. //如果前一页不是column 的倍数 直接补充成column的倍数
  3030. var pageIndex = 1
  3031. while (fillInBlankData['page' + pageIndex]) {
  3032. var pageKey = 'page' + pageIndex
  3033. var curPageKeyIndex = pageIndex
  3034. var pageLength = fillInBlankData[pageKey].length
  3035. var pageNextData = fillInBlankData['page' + (curPageKeyIndex + 1)]
  3036. //这里的规则是:
  3037. //当前模块所有的填空题全部拿到第一次当前填空题模块出现的分页
  3038. //然后根据心规则重新渲染
  3039. //所以需要把第一次出现的填空题模块保留,其他的删除
  3040. var prevFillInBlankData = fillInBlankData['page' + (pageIndex - 1)]
  3041. if (pageLength) {
  3042. //如果下一页有数据
  3043. if (pageNextData && pageNextData.length) {
  3044. if (pageLength % column) {
  3045. var restLength = column - (pageLength % column)
  3046. fillInBlankData[pageKey] = fillInBlankData[pageKey].concat(
  3047. pageNextData.splice(0, restLength)
  3048. )
  3049. if (!pageNextData.length) {
  3050. var nextFillEl = $('#printcontent .pageContent')
  3051. .eq(pageIndex)
  3052. .find('.completion-topic')
  3053. if (nextFillEl.length) {
  3054. nextFillEl.remove()
  3055. }
  3056. }
  3057. }
  3058. }
  3059. fillInBlankData[pageKey] = fillInBlankData[pageKey].map(function (
  3060. item
  3061. ) {
  3062. item.scoreStyle = scoreStyle
  3063. return item
  3064. })
  3065. }
  3066. pageIndex++
  3067. }
  3068. return fillInBlankData
  3069. },
  3070. //题干区域超出
  3071. addPrintForObjective: function (curPageEl, overPart) {
  3072. var self = this
  3073. var curPageIndex = curPageEl.index()
  3074. var times = curPageIndex + 1
  3075. var part = overPart.subjectModule
  3076. //判断超出简答题区域
  3077. var overAnswerModule = overPart.answerModule
  3078. //超出区域模块的题型
  3079. var overAnswerModuleType = overAnswerModule.attr('data-type') || 'objective'
  3080. var resetEditorIds = []
  3081. //简答小题
  3082. var subjectHtml = ''
  3083. //合并的简答题区域
  3084. var overAnswerHtml = ''
  3085. //通过缩放确定每个页面需要移除的元素
  3086. var removeElements = []
  3087. var nextPageEl = curPageEl.next()
  3088. //首先判断是要删除下一个分页的补充模块如果下一个分页存在的话
  3089. var nextPageFirstModule = null
  3090. if (nextPageEl.length) {
  3091. nextPageFirstModule = nextPageEl.find('.module').eq(0)
  3092. nextPageFirstAnswerModule = nextPageEl.find('.answerModule').eq(0)
  3093. }
  3094. while (part.length) {
  3095. subjectHtml += self.addNewModuleForObjective(
  3096. part,
  3097. overAnswerModuleType,
  3098. removeElements
  3099. )
  3100. part = part.next()
  3101. }
  3102. //根据module 的data-type来确定使用的module 模板
  3103. var tplForTypeMap = {
  3104. singleSelect: 'selectTpl',
  3105. moreSelect: 'selectTpl',
  3106. fillInBlank: 'answerModulForFillInBlankTpl',
  3107. answer: 'answerModuleTpl',
  3108. chooseAnswer: 'answerModuleTpl',
  3109. mustAnswer: 'answerModuleTpl',
  3110. objective: 'objectiveWrapTpl'
  3111. }
  3112. //超出模块
  3113. while (overAnswerModule.length) {
  3114. var editModuleHtml = ''
  3115. var moduleTitle = ''
  3116. overAnswerModuleType = overAnswerModule.attr('data-type')
  3117. var isObjective = overAnswerModuleType === 'objective'
  3118. var direction = overAnswerModule.attr('data-direction')
  3119. var isSelect = ~overAnswerModuleType.indexOf('Select')
  3120. //如果是当前超出模块,则直接用上面的多余的moduleHtml来填充
  3121. //否则,直接用answerModule的内容来填充
  3122. if (overAnswerModule[0] === overPart.answerModule[0]) {
  3123. editModuleHtml = subjectHtml
  3124. } else {
  3125. //如果下一个大模块是选做题,并且只有选做题提文字信息
  3126. if (
  3127. overAnswerModuleType === 'chooseAnswer' &&
  3128. !overAnswerModule.find('.module').length &&
  3129. overAnswerModule.children().length &&
  3130. overAnswerModule.find('.originSubjectInfo').length
  3131. ) {
  3132. var objectiveReg = /<div class="originSubjectInfo">(.*)<\/div>/
  3133. var objectiveRegG = /<div class="originSubjectInfo">(.*)<\/div>/g
  3134. //超出的选做题标题元素
  3135. var overAnswerModuleH3Html = overAnswerModule.find('h3')[0].outerHTML
  3136. //超出选做题标题的题干内容
  3137. var overAnswerModuleH3ObjectiveHtml = overAnswerModuleH3Html.match(
  3138. objectiveReg
  3139. )[1]
  3140. var nextPageFirstH3 = nextPageFirstAnswerModule.children('h3')
  3141. if (nextPageFirstH3.length) {
  3142. var nextPageFIrstH3ObjectiveHtml = nextPageFirstH3
  3143. .children('.originSubjectInfo')
  3144. .html()
  3145. //如果下一页存在选做题h3 则 需要拿当前的h3 做替换
  3146. nextPageFirstH3[0].outerHTML = overAnswerModuleH3Html.replace(
  3147. objectiveRegG,
  3148. '<div class="originSubjectInfo">' +
  3149. overAnswerModuleH3ObjectiveHtml +
  3150. nextPageFIrstH3ObjectiveHtml +
  3151. '</div>'
  3152. )
  3153. } else {
  3154. //如果下一页没有标题,直接插入到下一个模块的
  3155. // subjectHtml = nextPageFirstH3.children('.originSubjectInfo').prepend(overAnswerModule[0].outerHTML.replace(objectiveRegG,'<div class="originSubjectInfo">'+curPageH3ObjectiveHtml+'<\/div>'))
  3156. subjectHtml = overAnswerModule.children('h3')[0].outerHTML
  3157. nextPageFirstAnswerModule.prepend(subjectHtml)
  3158. }
  3159. overAnswerModule.remove()
  3160. break
  3161. }
  3162. //如果是选做题特殊处理
  3163. var isChooseAnswer = overAnswerModuleType === 'chooseAnswer'
  3164. var isSelect = ~overAnswerModuleType.indexOf('Select')
  3165. var isFillInBlank = overAnswerModuleType === 'fillInBlank'
  3166. self.resetPageDataForSubject(
  3167. overAnswerModule,
  3168. times,
  3169. resetEditorIds,
  3170. nextPageEl
  3171. )
  3172. if (isSelect || isFillInBlank) {
  3173. moduleTitle = self.titleHtml(self[overAnswerModuleType + '-title'])
  3174. if (isSelect) {
  3175. editModuleHtml =
  3176. '<div class="single-option more-option clearfix">' +
  3177. overAnswerModule.find('.single-option').html() +
  3178. '</div>'
  3179. }
  3180. }
  3181. if (!isSelect) editModuleHtml = overAnswerModule.html()
  3182. removeElements.push(overAnswerModule)
  3183. }
  3184. overAnswerHtml += self.tpls[
  3185. tplForTypeMap[overAnswerModuleType]
  3186. ].substitute({
  3187. editModule: editModuleHtml,
  3188. moduleType: overAnswerModuleType,
  3189. selectType: overAnswerModuleType,
  3190. selectContent: editModuleHtml,
  3191. direction: direction,
  3192. title: moduleTitle
  3193. })
  3194. overAnswerModule = overAnswerModule.next()
  3195. }
  3196. /**
  3197. * 【优化】
  3198. * 模块删除关系需要优化
  3199. */
  3200. removeElements.forEach(function (element) {
  3201. $(element).remove()
  3202. })
  3203. if (!overPart.answerModule.children('.objectiveItem').length)
  3204. overPart.answerModule.remove()
  3205. //是否存在下一个分页
  3206. if (nextPageEl.length) {
  3207. nextPageEl.children('.dtk-content').prepend(overAnswerHtml)
  3208. if (self.isSurplusModule(nextPageFirstModule)) {
  3209. self.delPageOverPart(nextPageFirstModule.children('.delBtn'), 'over')
  3210. }
  3211. } else {
  3212. self.addPage(overAnswerHtml)
  3213. nextPageEl = $('#printcontent').children('.pageContent:last()')
  3214. }
  3215. //重置富文本
  3216. resetEditorIds.length && self.resetAddNewModuleEditor(resetEditorIds)
  3217. //递归轮询判断
  3218. self.changePrintArea(nextPageEl)
  3219. },
  3220. /**
  3221. * 超出情况
  3222. * ** 如果下一页的模块有补充模块,最终都需要删除,增加新的补充模块
  3223. * 1 如果剩余解答区域小于默认解答区域高度--则直接全部拿到下一页,高度和下一个区域的补充模块高度累加,下一页的补充模块自动移除
  3224. * 2 如果剩余解答区域大于默认解答区域高度--则超出部分高度和之前下一区域的补充模块高度累加,下一页补充模块高度自动移除
  3225. * 缺失情况
  3226. * 1 如果剩余空间大于下一个模块
  3227. * -如果是补充模块,直接拿上来,高度累加该补充模块的高度
  3228. * -如果不是补充模块,直接拿上来,然后递归下一页的下一个模块,直到该页面没有剩余空间
  3229. * 2 如果剩余空间小于下一个模块
  3230. * a如果有标题
  3231. * - 如果小于标题加题号的空间,则不动,递归下一页的缺失情况
  3232. * - 如果大于标题加题号的空间,则直接拿上去,下一页保留多余高度的作答区域 (可以高度缩小直接拿上去,然后再补一个剩余高度的拓展模块)
  3233. * b如果没有标题(小题或者补充模块)
  3234. * - 如果下一页的第一个模块是补充模块,直接缩小对应的高度,上一个页面增加对应的高度
  3235. * - 如果下一个面是小题模块,则直接拿上去,下一页保留多余高度的作答区域 (可以高度缩小直接拿上去,然后再补一个剩余高度的拓展模块)
  3236. */
  3237. addPrintForAnswer: function (curPageEl, overPart) {
  3238. var self = this
  3239. var curPageIndex = curPageEl.index()
  3240. var times = curPageIndex + 1
  3241. //如果part不存在只有一种可能就是选做题只有题干信息超出
  3242. var part = overPart.subjectModule
  3243. //判断超出简答题区域
  3244. var overAnswerModule = overPart.answerModule
  3245. //超出区域模块的题型
  3246. var overAnswerModuleType = overAnswerModule.attr('data-type')
  3247. //简答小题
  3248. var subjectHtml = ''
  3249. //合并的简答题区域
  3250. var overAnswerHtml = ''
  3251. //判断是否是当前鼠标操作答题区域的坐标
  3252. //var curOperation = part[0] === self.curDtkModelEl[0]
  3253. //通过缩放确定每个页面需要移除的元素
  3254. var removeElements = []
  3255. //需要重置富文本编辑功能区域的id
  3256. var resetEditorIds = []
  3257. //判断是否有需要新增的富文本
  3258. var hasNewRichText = false
  3259. //超出的富文本的内容部分
  3260. var editorOverContent = ''
  3261. var nextPageEl = curPageEl.next()
  3262. //首先判断是要删除下一个分页的补充模块如果下一个分页存在的话
  3263. var nextPageFirstModule = null
  3264. var nextPageFirstAnswerModule = null
  3265. if (nextPageEl.length) {
  3266. nextPageFirstModule = nextPageEl.find('.module').eq(0)
  3267. nextPageFirstAnswerModule = nextPageEl.find('.answerModule').eq(0)
  3268. }
  3269. let titleNumber = 0
  3270. while (part && part.length) {
  3271. /**
  3272. * 如果是当前缩放的模块超出,直接在下一模块新建当前模块的子模块
  3273. * 如果不是,则直接拷贝超出模块所有内容到下一页
  3274. */
  3275. //当前缩放的模块没有超出规定区域 则超出的所有模块全局复制
  3276. if (part !== overPart.subjectModule) {
  3277. //1 新增新模块resetEditorIds removeElements
  3278. subjectHtml += self.addNewModule(
  3279. part,
  3280. overAnswerModuleType,
  3281. resetEditorIds,
  3282. removeElements
  3283. )
  3284. } else {
  3285. //如果剩余模块的高度小于 最小高度,直接放到下一页
  3286. //如果是多选题题目信息
  3287. var surplusHeight = self.getOverHeight(part)
  3288. if (part.outerHeight() - surplusHeight <= 100) {
  3289. //判断超出简答题区域
  3290. var overAnswerModule = part.closest('.answerModule')
  3291. //超出区域模块的题型
  3292. var overAnswerModuleType = overAnswerModule.attr('data-type')
  3293. //1 新增新模块resetEditorIds removeElements
  3294. subjectHtml += self.addNewModule(
  3295. part,
  3296. overAnswerModuleType,
  3297. resetEditorIds,
  3298. removeElements
  3299. )
  3300. } else {
  3301. //1 拓展新模块
  3302. hasNewRichText = true
  3303. //当前超出的模块height
  3304. //计算超出文本内容区域,同时原来的富文本区域对应超出的内容
  3305. var overContentObj = self.getOverContent(
  3306. part,
  3307. surplusHeight,
  3308. removeElements
  3309. )
  3310. let isW = overContentObj.overContent.search('.w-e-text');
  3311. if(isW>-1){
  3312. editorOverContent = overContentObj.overContent
  3313. } else {
  3314. editorOverContent = '<div class="w-e-text">'+overContentObj.overContent+'</div>'
  3315. }
  3316. var editorOverHeight = overContentObj.overHeight
  3317. titleNumber = part.attr('title-number');
  3318. subjectHtml += self.expandModule(part,editorOverContent, editorOverHeight)
  3319. }
  3320. }
  3321. part = part.next()
  3322. }
  3323. //当前超出小模块只是选做题题干信息
  3324. if (!subjectHtml) {
  3325. var removeTemps = []
  3326. var $itemBodys = overPart.objectiveModule.find('.questionItemBody')
  3327. for (var i = 0; i < $itemBodys.length; i++) {
  3328. var $itemBody = $itemBodys.eq(i)
  3329. if (self.getOverHeight($itemBody) > 0) {
  3330. subjectHtml += $itemBody[0].outerHTML
  3331. removeTemps.push($itemBody)
  3332. }
  3333. }
  3334. var objectiveReg = /<div class="originSubjectInfo">(.*)<\/div>/
  3335. var objectiveRegG = /<div class="originSubjectInfo">(.*)<\/div>/g
  3336. var curPageH3ObjectiveHtml = overPart.objectiveModule[0].outerHTML.match(
  3337. objectiveReg
  3338. )[1]
  3339. if (removeTemps.length >= $itemBodys.length) {
  3340. //如果下一页存在标题
  3341. var nextPageFirstH3 = nextPageFirstAnswerModule.children('h3')
  3342. if (nextPageFirstH3.length) {
  3343. var nextPageFirstH3Html = nextPageFirstH3
  3344. .children('.originSubjectInfo')
  3345. .html()
  3346. subjectHtml = overPart.objectiveModule[0].outerHTML.replace(
  3347. objectiveRegG,
  3348. '<div class="originSubjectInfo">' +
  3349. curPageH3ObjectiveHtml +
  3350. nextPageFirstH3Html +
  3351. '</div>'
  3352. )
  3353. nextPageFirstH3[0].outerHTML = subjectHtml
  3354. } else {
  3355. subjectHtml = overPart.objectiveModule[0].outerHTML.replace(
  3356. objectiveRegG,
  3357. '<div class="originSubjectInfo">' +
  3358. curPageH3ObjectiveHtml +
  3359. '</div>'
  3360. )
  3361. nextPageFirstAnswerModule.prepend(subjectHtml)
  3362. }
  3363. overPart.objectiveModule.closest('.answerModule').remove()
  3364. } else {
  3365. //如果下一页存在标题
  3366. var nextPageFirstH3 = nextPageFirstAnswerModule.children('h3')
  3367. if (nextPageFirstH3.length) {
  3368. nextPageFirstH3.children('.originSubjectInfo').prepend(subjectHtml)
  3369. } else {
  3370. //overPart.objectiveModule[0].outerHTML.replace(objectiveRegG,'');
  3371. nextPageFirstAnswerModule.prepend(
  3372. '<h3><div class="originSubjectInfo">' + subjectHtml + '</div></h3>'
  3373. )
  3374. }
  3375. removeTemps.forEach(function (el) {
  3376. $(el).remove()
  3377. })
  3378. }
  3379. self.changePrintArea(nextPageEl)
  3380. return
  3381. }
  3382. //超出模块
  3383. while (overAnswerModule.length) {
  3384. var editModuleHtml = ''
  3385. overAnswerModuleType = overAnswerModule.attr('data-type')
  3386. //如果是当前超出模块,则直接用上面的多余的moduleHtml来填充
  3387. //否则,直接用answerModule的内容来填充
  3388. if (overAnswerModule[0] === overPart.answerModule[0]) {
  3389. editModuleHtml = subjectHtml
  3390. } else {
  3391. //如果下一个大模块是选做题,并且只有选做题提文字信息
  3392. if (
  3393. overAnswerModuleType === 'chooseAnswer' &&
  3394. !overAnswerModule.find('.module').length &&
  3395. overAnswerModule.children().length &&
  3396. overAnswerModule.find('.originSubjectInfo').length
  3397. ) {
  3398. var objectiveReg = /<div class="originSubjectInfo">(.*)<\/div>/
  3399. var objectiveRegG = /<div class="originSubjectInfo">(.*)<\/div>/g
  3400. //超出的选做题标题元素
  3401. var overAnswerModuleH3Html = overAnswerModule.find('h3')[0].outerHTML
  3402. //超出选做题标题的题干内容
  3403. var overAnswerModuleH3ObjectiveHtml = overAnswerModuleH3Html.match(
  3404. objectiveReg
  3405. )[1]
  3406. var nextPageFirstH3 = nextPageFirstAnswerModule.children('h3')
  3407. if (nextPageFirstH3.length) {
  3408. var nextPageFIrstH3ObjectiveHtml = nextPageFirstH3
  3409. .children('.originSubjectInfo')
  3410. .html()
  3411. //如果下一页存在选做题h3 则 需要拿当前的h3 做替换
  3412. nextPageFirstH3[0].outerHTML = overAnswerModuleH3Html.replace(
  3413. objectiveRegG,
  3414. '<div class="originSubjectInfo">' +
  3415. overAnswerModuleH3ObjectiveHtml +
  3416. nextPageFIrstH3ObjectiveHtml +
  3417. '</div>'
  3418. )
  3419. } else {
  3420. //如果下一页没有标题,直接插入到下一个模块的
  3421. // subjectHtml = nextPageFirstH3.children('.originSubjectInfo').prepend(overAnswerModule[0].outerHTML.replace(objectiveRegG,'<div class="originSubjectInfo">'+curPageH3ObjectiveHtml+'<\/div>'))
  3422. subjectHtml = overAnswerModule.children('h3')[0].outerHTML
  3423. nextPageFirstAnswerModule.prepend(subjectHtml)
  3424. }
  3425. overAnswerModule.remove()
  3426. break
  3427. }
  3428. editModuleHtml = overAnswerModule.html()
  3429. //2 判断是否有需要重置的富文本
  3430. var editorEls = overAnswerModule.find('.editorContent')
  3431. editorEls.length &&
  3432. editorEls.each(function () {
  3433. resetEditorIds.push({
  3434. editorId: $(this).attr('id'),
  3435. toolbarId: $(this).prev().attr('id')
  3436. })
  3437. })
  3438. removeElements.push(overAnswerModule)
  3439. }
  3440. var formatStrData = {
  3441. editModule: editModuleHtml,
  3442. moduleType: overAnswerModule.attr('data-type')
  3443. }
  3444. overAnswerHtml += self.tpls.answerModuleTpl.substitute(formatStrData)
  3445. overAnswerModule = overAnswerModule.next()
  3446. }
  3447. /**
  3448. * 是否需要重置上一个页面的高度
  3449. * 当前缩放的模块超出,直接当前模块在当前分页高度设置到限制内最大
  3450. */
  3451. //重置上一页第一个超出模块的高度 = pageHeight - subject.offset().top - subjectModullePadding的模块高度
  3452. //上一个页面其他剩余模块的所占的高度
  3453. var preOtherModuleHeight =
  3454. overPart.subjectModule.offset().top +
  3455. $('#contentWrap').scrollTop() +
  3456. self.pagePadding +
  3457. self.modulePadding +10
  3458. //上一个页面第一个超出模块所能占用的高度
  3459. var preFirstOverModuleHeight =
  3460. self.pageHeight * times - preOtherModuleHeight
  3461. let isEn = overPart.subjectModule.children('.editorContent').find('.w-e-text').find('en')
  3462. if(isEn.length>0){
  3463. preFirstOverModuleHeight = preFirstOverModuleHeight - 20
  3464. }
  3465. // let wH = overPart.subjectModule.children('.editorContent').find('.w-e-text').height();
  3466. //
  3467. // if(wH>preFirstOverModuleHeight){
  3468. // preFirstOverModuleHeight = wH
  3469. // }
  3470. overPart.subjectModule
  3471. .children('.editorContent')
  3472. .height(preFirstOverModuleHeight)
  3473. /**
  3474. * 【优化】
  3475. * 模块删除关系需要优化
  3476. */
  3477. removeElements.forEach(function (element) {
  3478. $(element).remove()
  3479. })
  3480. if (
  3481. !overPart.answerModule.children('.module').length &&
  3482. !overPart.answerModule.find('h3').length
  3483. )
  3484. overPart.answerModule.remove()
  3485. //是否存在下一个分页
  3486. if (nextPageEl.length) {
  3487. nextPageEl.children('.dtk-content').prepend(overAnswerHtml)
  3488. } else {
  3489. self.addPage(overAnswerHtml)
  3490. nextPageEl = $('#printcontent').children('.pageContent:last()')
  3491. }
  3492. //curOperation
  3493. // hasNewRichText &&
  3494. // self.createShortAnswer(self.editorIndex, editorOverContent)
  3495. hasNewRichText &&
  3496. self.createShortAnswer(titleNumber+'-'+self.editorIndex, editorOverContent)
  3497. //下一页存在上一页最后一个模块的拓展模块,也必须等上一页的新拓展(超出模块)放到下一页之后再执行老拓展模块的删除
  3498. //因为删除功能会进行下一页是否有内容模块,对下一页整个页面进行选择性的删除,如果删除了下一页,超出的内容就不知道放到哪里了
  3499. if (nextPageFirstModule && self.isSurplusModule(nextPageFirstModule)) {
  3500. self.delPageOverPart(nextPageFirstModule.children('.delBtn'), 'over')
  3501. }
  3502. //重置富文本
  3503. self.resetAddNewModuleEditor(resetEditorIds)
  3504. //递归轮询判断
  3505. self.changePrintArea(nextPageEl)
  3506. },
  3507. //填空题超出
  3508. addPrintForFillInBlank: function (curPageEl, overPart) {
  3509. var self = this
  3510. var part = overPart.subjectModule
  3511. var curPageIndex = curPageEl.index() + 1
  3512. //合并的简答题区域
  3513. var overAnswerHtml = ''
  3514. //通过缩放确定每个页面需要移除的元素
  3515. var removeElements = []
  3516. //需要重置富文本编辑功能区域的id
  3517. var resetEditorIds = []
  3518. var nextPageEl = curPageEl.next()
  3519. //首先判断是要删除下一个分页的补充模块如果下一个分页存在的话
  3520. var nextPageFirstModule = null
  3521. if (nextPageEl.length) {
  3522. nextPageFirstModule = nextPageEl.find('.module').eq(0)
  3523. nextPageEl.find('.completion-topic').remove()
  3524. }
  3525. //当前超出的模块height
  3526. var overHeight = self.getOverHeight(part)
  3527. //一行几栏
  3528. var $firstColForInfoEl = part.children('.subjectCol')
  3529. var dataColumns = $firstColForInfoEl.attr('data-column')
  3530. var scoreStyle = $firstColForInfoEl.attr('data-scoreStyle')
  3531. var columns = dataColumns ? +dataColumns : 1
  3532. var rowLineHeight = $firstColForInfoEl.attr('data-rowlineheight')
  3533. //计算每个填空题item的高度 默认40 padding 10 border 1
  3534. var fillInBlankItemHeight = (+rowLineHeight || 40) + 11
  3535. //当前模块有几个填空题
  3536. var fillInBlankCount = part.find('.subjectItem').length
  3537. //最后一排几个
  3538. var lastRowCount =
  3539. fillInBlankCount % columns ? fillInBlankCount % columns : columns
  3540. //需要复制几个填空题
  3541. //超出的行数量
  3542. var overRows = Math.ceil(overHeight / fillInBlankItemHeight)
  3543. //如果最后一行计算最后一行有几个
  3544. var copyFillInBlankLength = lastRowCount + (overRows - 1) * columns
  3545. var curModuleDataIndex = 'page' + curPageIndex
  3546. var nextExpendDataIndex = 'page' + (curPageIndex + 1)
  3547. var nextExpendDataLength = self.fillInBlank[curModuleDataIndex].length
  3548. copyFillInBlankLength =
  3549. copyFillInBlankLength > nextExpendDataLength
  3550. ? nextExpendDataLength
  3551. : copyFillInBlankLength
  3552. //原页面保留的题目
  3553. self.fillInBlank[nextExpendDataIndex] =
  3554. self.fillInBlank[nextExpendDataIndex] || []
  3555. self.fillInBlank[nextExpendDataIndex] = self.fillInBlank[curModuleDataIndex]
  3556. .splice(nextExpendDataLength - copyFillInBlankLength)
  3557. .concat(self.fillInBlank[nextExpendDataIndex])
  3558. var originPageRetainHtml = self.getFillInBlankHtml(
  3559. self.fillInBlank[curModuleDataIndex]
  3560. )
  3561. var overFillInBlankItemsHtml = self.getFillInBlankHtml(
  3562. self.fillInBlank[nextExpendDataIndex]
  3563. )
  3564. if (!originPageRetainHtml) {
  3565. removeElements.push(part.closest('.completion-topic'))
  3566. } else {
  3567. part.find('.subjectCol').html(originPageRetainHtml)
  3568. }
  3569. //超出的放在新页面上 如果原页面没有保留模块则需要加上title 并且需要setting按钮
  3570. overFillInBlankItemsHtml =
  3571. self.titleHtml(!originPageRetainHtml ? self['fillInBlank-title'] : '') +
  3572. self.tpls.fillInBlankContentTpl.substitute({
  3573. addFillInBlankHtml: overFillInBlankItemsHtml,
  3574. columns: columns,
  3575. scoreStyle: scoreStyle,
  3576. rowLineHeight: rowLineHeight,
  3577. settingBtn: !originPageRetainHtml
  3578. ? self.tpls.fillInBlankSettingBtnTpl
  3579. : ''
  3580. })
  3581. //超出模块
  3582. //判断超出简答题区域
  3583. var overAnswerModule = overPart.answerModule
  3584. var overModuleHasObjective = false
  3585. while (overAnswerModule.length) {
  3586. var editModuleHtml = ''
  3587. var isCurOverAnswer = overAnswerModule === overPart.answerModule
  3588. //如果有题干信息
  3589. var isObjective = overAnswerModule.attr('data-type') === 'objective'
  3590. //如果是当前超出模块,则直接用上面的多余的moduleHtml来填充
  3591. //否则,直接用answerModule的内容来填充
  3592. if (isCurOverAnswer) {
  3593. editModuleHtml = overFillInBlankItemsHtml
  3594. } else {
  3595. editModuleHtml = overAnswerModule.html()
  3596. //2 判断是否有需要重置的富文本
  3597. var editorEls = overAnswerModule.find('.editorContent')
  3598. editorEls.length &&
  3599. editorEls.each(function () {
  3600. resetEditorIds.push({
  3601. editorId: $(this).attr('id'),
  3602. toolbarId: $(this).prev().attr('id')
  3603. })
  3604. })
  3605. removeElements.push(overAnswerModule)
  3606. }
  3607. overAnswerHtml += self.tpls[
  3608. isCurOverAnswer ? 'answerModulForFillInBlankTpl' : 'answerModuleTpl'
  3609. ].substitute({
  3610. editModule: editModuleHtml,
  3611. moduleType: overAnswerModule.attr('data-type')
  3612. })
  3613. if (isObjective) {
  3614. overModuleHasObjective = true
  3615. }
  3616. overAnswerModule = overAnswerModule.next()
  3617. }
  3618. /**
  3619. * 【优化】
  3620. * 模块删除关系需要优化
  3621. */
  3622. removeElements.forEach(function (element) {
  3623. $(element).remove()
  3624. })
  3625. //是否存在下一个分页
  3626. if (nextPageEl.length) {
  3627. nextPageEl.children('.dtk-content').prepend(overAnswerHtml)
  3628. if (self.isSurplusModule(nextPageFirstModule)) {
  3629. self.delPageOverPart(nextPageFirstModule.children('.delBtn'), 'over')
  3630. }
  3631. } else {
  3632. self.addPage(overAnswerHtml)
  3633. nextPageEl = $('#printcontent').children('.pageContent:last()')
  3634. }
  3635. if (overModuleHasObjective) {
  3636. self.judegeImgsLoaded('.objectiveItem')
  3637. }
  3638. //重置富文本
  3639. self.resetAddNewModuleEditor(resetEditorIds)
  3640. //递归轮询判断
  3641. self.changePrintArea(nextPageEl)
  3642. },
  3643. //选择题超出
  3644. /**
  3645. * @param {*} curPageEl
  3646. * @param {*} overPart
  3647. */
  3648. addPrintForSelect: function (curPageEl, overPart, type) {
  3649. var self = this
  3650. //超出选择题的题目
  3651. var curPageIndex = curPageEl.index() + 1
  3652. //合并的简答题区域
  3653. var overAnswerHtml = ''
  3654. //通过缩放确定每个页面需要移除的元素
  3655. var removeElements = []
  3656. //需要重置富文本编辑功能区域的id
  3657. var resetEditorIds = []
  3658. //当前超出的模块height
  3659. var part = overPart.subjectModule
  3660. var overHeight = self.getOverHeight(part)
  3661. //page data index
  3662. var curModuleDataIndex = 'page' + curPageIndex
  3663. var nextExpendDataIndex = 'page' + (curPageIndex + 1)
  3664. //每小题的高度
  3665. var selectItemHeight = $('.single-option').eq(0).outerHeight()
  3666. //针对选择题竖版一行排几个
  3667. var curConfigForLine =
  3668. self.config[self.direction][self.hasBindingLine ? 'yesLine' : 'noLine']
  3669. var rowLength = curConfigForLine[self.columns]
  3670. //一共多少个选择ul module
  3671. var optionsModuleLength = part.children('.single-option').length
  3672. //当前布局下面有几排
  3673. var optionsRowLength = Math.floor(part.outerHeight() / selectItemHeight)
  3674. //一排几个options 模块
  3675. var optionsModule = rowLength / 5
  3676. //最后一个排放几个选项
  3677. var lastRowOptionLength =
  3678. optionsModuleLength - (optionsRowLength - 1) * optionsModule
  3679. var lastRowOptionLength =
  3680. self[type][curModuleDataIndex].length -
  3681. (optionsRowLength - 1) * optionsModule * 5
  3682. //如果当前页面超过一排的情况下,则超出的数量需要计算到最后一排没有排满的情况
  3683. /**
  3684. * 超出的计算单位以 一整排为单位
  3685. * 每一排的一列以5题为单位 计算
  3686. *
  3687. */
  3688. //计算超出多少小题
  3689. var overSelectItemsLength
  3690. var overRowLength = Math.ceil(overHeight / selectItemHeight)
  3691. if (overRowLength <= 1) {
  3692. overSelectItemsLength = lastRowOptionLength
  3693. } else {
  3694. overSelectItemsLength =
  3695. (overRowLength - 1) * rowLength + lastRowOptionLength
  3696. }
  3697. var nextExpendDataLength = self[type]['page' + curPageIndex].length
  3698. //超出的放在新页面上,顺表保存一份用来给下一次使用
  3699. self[type][nextExpendDataIndex] = self[type][nextExpendDataIndex] || []
  3700. self[type][nextExpendDataIndex] = self[type][curModuleDataIndex]
  3701. .splice(nextExpendDataLength - overSelectItemsLength)
  3702. .concat(self[type][nextExpendDataIndex])
  3703. //是否存在下一页
  3704. var nextPageEl = curPageEl.next()
  3705. //首先判断是要删除下一个分页的补充模块如果下一个分页存在的话
  3706. var nextPageFirstModule = null
  3707. var nextPageFirstAnswerModule = null
  3708. if (nextPageEl.length) {
  3709. nextPageFirstAnswerModule = nextPageEl.find('.answerModule').eq(0)
  3710. nextPageFirstModule = nextPageEl.find('.module').eq(0)
  3711. }
  3712. //计算留在当前页面的和下一个页面的数据
  3713. var originPageRetainHtml = self.getSingleSelectHtml(
  3714. self[type][curModuleDataIndex]
  3715. )
  3716. var overSelectItemsHtml = self.getSingleSelectHtml(
  3717. self[type][nextExpendDataIndex]
  3718. )
  3719. if (!originPageRetainHtml) {
  3720. removeElements.push(part.closest('.single-select'))
  3721. overSelectItemsHtml =
  3722. self.tpls.settingBtnTpl.substitute({ moduleType: type }) +
  3723. overSelectItemsHtml
  3724. } else {
  3725. //原来模块必须保留设置按钮
  3726. originPageRetainHtml =
  3727. self.tpls.settingBtnTpl.substitute({ moduleType: type }) +
  3728. originPageRetainHtml
  3729. part.html(originPageRetainHtml)
  3730. }
  3731. //根据module 的data-type来确定使用的module 模板
  3732. var tplForTypeMap = {
  3733. singleSelect: 'selectTpl',
  3734. moreSelect: 'selectTpl',
  3735. fillInBlank: 'answerModulForFillInBlankTpl',
  3736. answer: 'answerModuleTpl',
  3737. chooseAnswer: 'answerModuleTpl',
  3738. mustAnswer: 'answerModuleTpl',
  3739. objective: 'objectiveWrapTpl'
  3740. }
  3741. //判断超出简答题区域
  3742. var overAnswerModule = overPart.answerModule
  3743. var overModuleHasObjective = false
  3744. while (overAnswerModule.length) {
  3745. var editModuleHtml = ''
  3746. var overModuleType = overAnswerModule.attr('data-type')
  3747. var direction = overAnswerModule.attr('data-direction')
  3748. var moduleTitle = ''
  3749. //如果是当前超出模块,则直接用上面的多余的moduleHtml来填充
  3750. //否则,直接用answerModule的内容来填充
  3751. var isCurOverAnswer = overAnswerModule === overPart.answerModule
  3752. var isObjective = overModuleType === 'objective'
  3753. if (isCurOverAnswer) {
  3754. editModuleHtml = overSelectItemsHtml
  3755. if (!originPageRetainHtml) {
  3756. moduleTitle = self.titleHtml(self[type + '-title'])
  3757. }
  3758. if (
  3759. nextPageFirstAnswerModule &&
  3760. overModuleType === nextPageFirstAnswerModule.attr('data-type')
  3761. ) {
  3762. removeElements.push(nextPageFirstAnswerModule)
  3763. }
  3764. } else {
  3765. var isSelect = ~overModuleType.indexOf('Select')
  3766. var isFillInBlank = overModuleType === 'fillInBlank'
  3767. self.resetPageDataForSubject(
  3768. overAnswerModule,
  3769. curPageIndex,
  3770. resetEditorIds,
  3771. nextPageEl
  3772. )
  3773. if (isSelect || isFillInBlank) {
  3774. moduleTitle = self.titleHtml(self[overModuleType + '-title'])
  3775. if (isSelect) {
  3776. overAnswerModule.find('.singleContent h3').remove()
  3777. editModuleHtml = overAnswerModule.find('.singleContent').html()
  3778. }
  3779. }
  3780. if (!isSelect) editModuleHtml = overAnswerModule.html()
  3781. removeElements.push(overAnswerModule)
  3782. }
  3783. overAnswerHtml += self.tpls[tplForTypeMap[overModuleType]].substitute({
  3784. editModule: editModuleHtml,
  3785. moduleType: overModuleType,
  3786. selectType: overModuleType,
  3787. selectContent: editModuleHtml,
  3788. direction: direction,
  3789. title: moduleTitle
  3790. })
  3791. if (isObjective) {
  3792. overModuleHasObjective = true
  3793. }
  3794. overAnswerModule = overAnswerModule.next()
  3795. }
  3796. /**
  3797. * 【优化】
  3798. * 模块删除关系需要优化
  3799. */
  3800. removeElements.forEach(function (element) {
  3801. $(element).remove()
  3802. })
  3803. //是否存在下一个分页
  3804. if (nextPageEl.length) {
  3805. nextPageEl.children('.dtk-content').prepend(overAnswerHtml)
  3806. if (self.isSurplusModule(nextPageFirstModule)) {
  3807. self.delPageOverPart(nextPageFirstModule.children('.delBtn'), 'over')
  3808. }
  3809. let nextPageFirstModuleType = $(nextPageFirstModule).parents('.answerModule').attr('data-type');
  3810. if(nextPageFirstModuleType == 'fillInBlank'&&$(nextPageFirstModule).parents('.dtk-content').find('.completion-topic').length>1){
  3811. let fillInBlankItemNo = $(nextPageFirstModule).find('.subjectItem').length;
  3812. if(fillInBlankItemNo>0){
  3813. $(nextPageFirstModule).parents('.dtk-content').find('.completion-topic').eq(0).find('.subjectCol').append($(nextPageFirstModule).find('.subjectCol').html())
  3814. }
  3815. $(nextPageFirstModule).parents('.answerModule').remove();
  3816. }
  3817. } else {
  3818. self.addPage(overAnswerHtml)
  3819. nextPageEl = $('#printcontent').children('.pageContent:last()')
  3820. }
  3821. if (overModuleHasObjective) {
  3822. self.judegeImgsLoaded('.objectiveItem')
  3823. }
  3824. //重置富文本
  3825. self.resetAddNewModuleEditor(resetEditorIds)
  3826. //递归轮询判断
  3827. self.changePrintArea(nextPageEl)
  3828. },
  3829. //重新计算当前超出模块之后的分页数据
  3830. resetPageDataForSubject: function (
  3831. overAnswerModule,
  3832. curPageIndex,
  3833. resetEditorIds,
  3834. nextPageEl
  3835. ) {
  3836. var self = this
  3837. //page data index
  3838. var curModuleDataIndex = 'page' + curPageIndex
  3839. var nextExpendDataIndex = 'page' + (curPageIndex + 1)
  3840. var overModuleType = overAnswerModule.attr('data-type')
  3841. //如果下一个页面的第一个模块是选择题或者填空题的补充模块,则特殊处理
  3842. var isSelect = ~overModuleType.indexOf('Select')
  3843. var isFillInBlank = overModuleType === 'fillInBlank'
  3844. if (isSelect || isFillInBlank) {
  3845. var nextHasData = false
  3846. self[overModuleType][nextExpendDataIndex] =
  3847. self[overModuleType][nextExpendDataIndex] || []
  3848. var nextExpendData = self[overModuleType][nextExpendDataIndex]
  3849. var curModuleData = self[overModuleType][curModuleDataIndex]
  3850. if (nextExpendData.length) {
  3851. nextHasData = true
  3852. self[overModuleType][nextExpendDataIndex] = curModuleData.concat(
  3853. nextExpendData
  3854. )
  3855. } else {
  3856. self[overModuleType][nextExpendDataIndex] = [].concat(curModuleData)
  3857. }
  3858. self[overModuleType][curModuleDataIndex].length = 0
  3859. if (isSelect) {
  3860. //如果下一个模块存在数据,直接合并到上一页在整体下移到下一页
  3861. if (nextHasData) {
  3862. var $expendModule = overAnswerModule.find('.singleContent')
  3863. var $nextRemoveModule = nextPageEl.find('.single-select').eq(0)
  3864. var $expendHtml =
  3865. self.tpls.settingBtnTpl.substitute({ moduleType: overModuleType }) +
  3866. self.getSingleSelectHtml(self[overModuleType][nextExpendDataIndex])
  3867. $expendModule.html($expendHtml)
  3868. $nextRemoveModule.remove()
  3869. }
  3870. } else if (overModuleType === 'fillInBlank') {
  3871. if (nextHasData) {
  3872. var $expendModule = overAnswerModule.find('.subjectCol')
  3873. var $nextRemoveModule = nextPageEl.find('.completion-topic').eq(0)
  3874. var $expendHtml = self.getFillInBlankHtml(
  3875. self[overModuleType][nextExpendDataIndex]
  3876. )
  3877. $expendModule.html($expendHtml)
  3878. $nextRemoveModule.remove()
  3879. }
  3880. }
  3881. } else {
  3882. //解答题重置富文本
  3883. //2 判断是否有需要重置的富文本
  3884. var editorEls = overAnswerModule.find('.editorContent')
  3885. editorEls.length &&
  3886. editorEls.each(function () {
  3887. resetEditorIds.push({
  3888. editorId: $(this).attr('id'),
  3889. toolbarId: $(this).prev().attr('id')
  3890. })
  3891. })
  3892. }
  3893. },
  3894. //新建分栏
  3895. /**
  3896. * @param {上一栏超出的模块html} overAnswerHtml
  3897. */
  3898. addPage: function (overAnswerHtml) {
  3899. var self = this
  3900. //新建的分页
  3901. self.totalPage++
  3902. self.currentPage++
  3903. self.currentPaper = Math.ceil(self.totalPage / (self.columns * 2))
  3904. //第一张纸 正面1 正面2 第一张至反面1 反面2
  3905. var paperDirection =
  3906. (self.totalPage % (self.columns * 2)
  3907. ? self.totalPage % (self.columns * 2)
  3908. : self.columns * 2) <= self.columns
  3909. ? '正面'
  3910. : '反面'
  3911. var pageForPaperDirection =
  3912. self.totalPage % self.columns ? self.totalPage % self.columns : 2
  3913. var currentPaperPage = paperDirection + pageForPaperDirection
  3914. //新建page
  3915. var newPage = self.tpls.pageModuleTpl.substitute({
  3916. subjectModule: overAnswerHtml,
  3917. currentPage: self.currentPage,
  3918. totalPage: self.totalPage,
  3919. currentPaper: self.currentPaper,
  3920. currentPaperPage: currentPaperPage
  3921. })
  3922. $('#printcontent').append(newPage)
  3923. self.refrushPageLabel()
  3924. },
  3925. //重新初始化移动的富文本题目编辑区域
  3926. resetAddNewModuleEditor: function (resetEditorIds) {
  3927. var self = this
  3928. /**
  3929. * editorId
  3930. * toolbarId
  3931. */
  3932. resetEditorIds.forEach(function (resetEditorId) {
  3933. // if (!$('#' + resetEditorId.toolbarId).length) return
  3934. // var editorIndex = resetEditorId.editorId.match(/\d+/g)[0]
  3935. // $('#' + resetEditorId.toolbarId).html('')
  3936. // var editor = new self.EDITOR(
  3937. // '#' + resetEditorId.toolbarId,
  3938. // '#' + resetEditorId.editorId
  3939. // )
  3940. // editor.customConfig.menus = self.EDITOR_CONFIG
  3941. // editor.customConfig.onfocus = function () {
  3942. // if (!self.isCanEditCard) return
  3943. // $('#' + resetEditorId.editorId)
  3944. // .siblings('.toolbar')
  3945. // .addClass('seled')
  3946. // }
  3947. // editor.customConfig.onblur = function () {
  3948. // //如果当前答题卡模板不在编辑状态,或者 正在使用公式编辑器,都不用启动这个事件
  3949. // if (!self.isCanEditCard || self.formulaing) return
  3950. // $('#' + resetEditorId.editorId)
  3951. // .siblings('.toolbar')
  3952. // .removeClass('seled')
  3953. // //过滤所有的空标签 换行产生的标签
  3954. // var newEditorHtml = editor.txt
  3955. // .html()
  3956. // .replace(self.replaceEditorRegexp, '')
  3957. // editor.txt.html(newEditorHtml)
  3958. // }
  3959. // editor.customConfig.linkImgCallback = function (url) {
  3960. // editor.$textElem.find('img').forEach(function (el) {
  3961. // var src = $(el).attr('src')
  3962. // if (src === url) {
  3963. // $(el).addClass('customImg')
  3964. // }
  3965. // return false
  3966. // })
  3967. // }
  3968. //
  3969. // // 关闭粘贴样式的过滤
  3970. // editor.customConfig.pasteFilterStyle = true
  3971. // editor.customConfig.customUploadImg = function (files, insert) {
  3972. // self.addImgToEditor(files, editor)
  3973. // }
  3974. // //#747474
  3975. // editor.create()
  3976. //
  3977. // //记录模块信息
  3978. // var editorText = self.editorArea['editor' + editorIndex].txt
  3979. // .html()
  3980. // .clearFixible()
  3981. // if (!~editorText.indexOf('flexible_icon')) {
  3982. // //设置图片伸缩使用icon
  3983. // editorText += self.tpls.flexibleIconTpl
  3984. // }
  3985. //
  3986. // editor.txt.html(editorText)
  3987. // self.editorArea['editor' + editorIndex] = editor
  3988. })
  3989. },
  3990. //可编辑区域
  3991. editorArea: {},
  3992. editorIndex: 0,
  3993. editorAreaOriginContent: {},
  3994. //解答题区域添加图片
  3995. addImgToEditor: function (files, editor) {
  3996. var self = this
  3997. var uploadForm = new FormData()
  3998. uploadForm.append('editor_file', files[0])
  3999. $.ajax({
  4000. url: self.apis.uploadFileApi,
  4001. method: 'POST',
  4002. processData: false,
  4003. contentType: false,
  4004. dataType: 'json',
  4005. data: uploadForm,
  4006. success: function (result) {
  4007. var imgTpl =
  4008. '<img style="max-height:calc(100% - {maxHeight}px);" src="{imgUrl}" class="customImg">'
  4009. var editorContetEl = editor.$textContainerElem.children('.w-e-text')
  4010. var contentHeihgt = self.calcEditorContentHeight($(editorContetEl))
  4011. var maxHeight = contentHeihgt + 64
  4012. editor.txt.html(
  4013. editor.txt.html() +
  4014. imgTpl.substitute({ maxHeight: maxHeight, imgUrl: result.data })
  4015. )
  4016. }
  4017. })
  4018. },
  4019. //创建作答区域模块
  4020. createShortAnswer: function (editorIndex, originContent) {
  4021. var self = this
  4022. originContent = originContent || ''
  4023. //this.createShortAnswer("#toolbar2", "#editorContent2", 2);
  4024. if (!$('#toolbar' + editorIndex).length) return
  4025. $('#editorContent' + editorIndex).html(originContent);
  4026. $('#editorContent' + editorIndex).find('img').load(function (e) {
  4027. let curPageEl = $('#editorContent' + editorIndex).parents('.pageContent')
  4028. self.changePrintArea(curPageEl)
  4029. })
  4030. // $('#editorContent' + editorIndex).html(originContent);
  4031. // var editor = new self.EDITOR(
  4032. // '#toolbar' + editorIndex,
  4033. // '#editorContent' + editorIndex
  4034. // )
  4035. // var ueEditor = window.UE.getEditor('toolbar' + editorIndex,);
  4036. // 自定义菜单配置
  4037. // editor.customConfig.menus = self.EDITOR_CONFIG
  4038. // editor.customConfig.onfocus = function () {
  4039. // if (!self.isCanEditCard) return
  4040. // $('#editorContent' + editorIndex)
  4041. // .siblings('.toolbar')
  4042. // .addClass('seled')
  4043. // }
  4044. // editor.customConfig.onblur = function () {
  4045. // if (!self.isCanEditCard || self.formulaing) return
  4046. // $('#editorContent' + editorIndex)
  4047. // .siblings('.toolbar')
  4048. // .removeClass('seled')
  4049. // //过滤所有的空标签 换行产生的标签
  4050. // var newEditorHtml = editor.txt
  4051. // .html()
  4052. // .replace(self.replaceEditorRegexp, '')
  4053. // editor.txt.html(newEditorHtml)
  4054. // }
  4055. //网络图片自定义类名
  4056. // editor.customConfig.linkImgCallback = function (url) {
  4057. // editor.$textElem.find('img').forEach(function (el) {
  4058. // var src = $(el).attr('src')
  4059. // if (src === url) {
  4060. // $(el).addClass('customImg')
  4061. // }
  4062. // return false
  4063. // })
  4064. // }
  4065. // 关闭粘贴样式的过滤
  4066. // editor.customConfig.pasteFilterStyle = false
  4067. // editor.customConfig.customUploadImg = function (files, insert) {
  4068. // self.addImgToEditor(files, editor)
  4069. // }
  4070. // editor.create()
  4071. //记录模块信息
  4072. // var editorText = editor.txt.html().clearFixible()
  4073. // if (!~editorText.indexOf('flexible_icon')) {
  4074. // //设置图片伸缩使用icon
  4075. // editorText += self.tpls.flexibleIconTpl
  4076. // }
  4077. // editorText += originContent.clearFixible()
  4078. // editor.txt.html(editorText.replace(self.replaceEditorRegexp, ''))
  4079. // self.editorIndex = editorIndex
  4080. // self.editorArea['editor' + editorIndex] = editor
  4081. },
  4082. //答题区域文本图片位置更换
  4083. shortAnswerImgPositionChange: function () {
  4084. var self = this
  4085. var curOpratorImg = null
  4086. var fa = null
  4087. var imgSelector = '.editorContent .customImg'
  4088. $('#hgc_print').on('mousedown', imgSelector, function (e) {
  4089. e.preventDefault()
  4090. var moveImgEl = $(this)[0]
  4091. var boundaryEl = $(moveImgEl).closest('.module')[0]
  4092. var flexibleIcon = $(this).closest('.module').find('.flexible_icon')[0]
  4093. var moveElHeight = moveImgEl.offsetHeight
  4094. var moveElWidth = moveImgEl.offsetWidth
  4095. var oldX = e.clientX
  4096. var oldY = e.clientY
  4097. var startLeft = moveImgEl.offsetLeft
  4098. var startTop = moveImgEl.offsetTop
  4099. document.onmousemove = function (ev) {
  4100. var maxTop =
  4101. boundaryEl.offsetHeight - self.modulePaddingBottom - moveElHeight
  4102. var maxLeft =
  4103. boundaryEl.offsetWidth - self.modulePaddingSide - moveElWidth
  4104. var distanceX = ev.clientX - oldX
  4105. var distanceY = ev.clientY - oldY
  4106. var newLeft = startLeft + distanceX
  4107. var newTop = startTop + distanceY
  4108. if (newLeft <= self.modulePaddingSide / 2)
  4109. newLeft = self.modulePaddingSide / 2
  4110. if (newTop <= self.modulePaddingTop) newTop = self.modulePaddingTop
  4111. if (newTop >= maxTop) newTop = maxTop
  4112. if (newLeft >= maxLeft) newLeft = maxLeft
  4113. moveImgEl.style.left = newLeft + 'px'
  4114. moveImgEl.style.top = newTop + 'px'
  4115. flexibleIcon.style.left = newLeft + moveElWidth - 20 + 'px'
  4116. flexibleIcon.style.top = newTop + moveElHeight - 20 + 'px'
  4117. }
  4118. document.onmouseup = function () {
  4119. document.onmousemove = null
  4120. document.onmouseup = null
  4121. flexibleIcon.style.display = 'none'
  4122. }
  4123. })
  4124. function resetFlexibleIcon($flexibleIcon, $curImg) {
  4125. $flexibleIcon.css({
  4126. left: parseFloat($curImg.css('left')) + $curImg.width() - 20,
  4127. top: parseFloat($curImg.css('top')) + $curImg.height() - 20
  4128. })
  4129. }
  4130. //图片缩放
  4131. $('#hgc_print').on('mouseover', imgSelector, function (e) {
  4132. //缩放icon
  4133. var $curImg = $(this)
  4134. var $curModule = $curImg.closest('.module')
  4135. var $flexibleIcon = $curModule.find('.flexible_icon')
  4136. $flexibleIcon.show()
  4137. curOpratorImg = $curImg[0]
  4138. fa = $curModule[0]
  4139. $flexibleIcon.show()
  4140. resetFlexibleIcon($flexibleIcon, $curImg)
  4141. })
  4142. $('#hgc_print').on('mouseout', imgSelector, function (e) {
  4143. e.stopPropagation()
  4144. //缩放icon
  4145. var $curImg = $(this)
  4146. var $curModule = $curImg.closest('.module')
  4147. var $flexibleIcon = $curModule.find('.flexible_icon')
  4148. $flexibleIcon.hide()
  4149. })
  4150. $('#hgc_print').on('mouseover', '.editorContent .flexible_icon', function (
  4151. e
  4152. ) {
  4153. //缩放icon
  4154. var $curImg = $(this)
  4155. var $curModule = $curImg.closest('.module')
  4156. var $flexibleIcon = $curModule.find('.flexible_icon')
  4157. $flexibleIcon.show()
  4158. })
  4159. //图片缩放
  4160. $('#hgc_print').on('mousedown', '.editorContent .flexible_icon', function (
  4161. e
  4162. ) {
  4163. // 阻止冒泡,避免缩放时触发移动事件
  4164. e.stopPropagation()
  4165. e.preventDefault()
  4166. var $flexibleIcon = $(this)
  4167. var pos = {
  4168. w: curOpratorImg.offsetWidth,
  4169. h: curOpratorImg.offsetHeight,
  4170. x: e.clientX,
  4171. y: e.clientY
  4172. }
  4173. fa.onmousemove = function (ev) {
  4174. ev.preventDefault()
  4175. // 设置图片的最小缩放为30*30
  4176. var w = Math.max(30, ev.clientX - pos.x + pos.w)
  4177. var h = Math.max(30, ev.clientY - pos.y + pos.h)
  4178. // console.log(w,h)
  4179. // 设置图片的最大宽高
  4180. w =
  4181. w >= fa.offsetWidth - curOpratorImg.offsetLeft
  4182. ? fa.offsetWidth - curOpratorImg.offsetLeft
  4183. : w
  4184. h =
  4185. h >= fa.offsetHeight - curOpratorImg.offsetTop
  4186. ? fa.offsetHeight - curOpratorImg.offsetTop
  4187. : h
  4188. curOpratorImg.style.width = w + 'px'
  4189. curOpratorImg.style.height = h + 'px'
  4190. resetFlexibleIcon($flexibleIcon, $(curOpratorImg))
  4191. // console.log(box.offsetWidth,box.offsetHeight)
  4192. }
  4193. fa.onmouseup = function () {
  4194. fa.onmousemove = null
  4195. fa.onmouseup = null
  4196. }
  4197. })
  4198. },
  4199. //新模块 part
  4200. addNewModule: function (part, moduleType, resetEditorIds, removeElements) {
  4201. var self = this
  4202. var moduleTitle = ''
  4203. var modulePrev = part.prev()
  4204. var hasTitle = modulePrev.length && modulePrev[0].tagName === 'H3'
  4205. //判断超出当前页面的条件
  4206. //如果是选做题并且当前有题干信息,题干信息单独提取出来,当成模块超出
  4207. var isChooseAnswer = moduleType === 'chooseAnswer'
  4208. //1 新增新模块resetEditorIds removeElements
  4209. //2 判断是否有需要重置的富文本
  4210. var editorEl = part.children('.editorContent')
  4211. if (editorEl.length) {
  4212. resetEditorIds.push({
  4213. editorId: editorEl.attr('id'),
  4214. toolbarId: editorEl.prev().attr('id')
  4215. })
  4216. }
  4217. //3 移除老模块
  4218. removeElements.push(part)
  4219. if (hasTitle) {
  4220. var objectiveInfo = part.siblings('h3').children('.originSubjectInfo')
  4221. if (isChooseAnswer && objectiveInfo.length) {
  4222. var $itemBodys = objectiveInfo.children('.questionItemBody')
  4223. var overChooseObjectiveHtml = ''
  4224. var removeTemp = []
  4225. for (var i = 0; i < $itemBodys.length; i++) {
  4226. var $itemBody = $itemBodys.eq(i)
  4227. if (self.getOverHeight($itemBody) > 0) {
  4228. overChooseObjectiveHtml += $itemBody[0].outerHTML
  4229. removeTemp.push($itemBody)
  4230. }
  4231. }
  4232. if (removeTemp.length >= $itemBodys.length) {
  4233. moduleTitle = modulePrev[0].outerHTML
  4234. removeElements.push(modulePrev)
  4235. } else if (removeTemp.length) {
  4236. moduleTitle =
  4237. '<h3 contenteditable="true"><div class="originSubjectInfo">' +
  4238. overChooseObjectiveHtml +
  4239. '</div></h3>'
  4240. removeElements.push(...removeTemp)
  4241. }
  4242. } else {
  4243. moduleTitle = modulePrev[0].outerHTML
  4244. removeElements.push(modulePrev)
  4245. }
  4246. }
  4247. return moduleTitle + part[0].outerHTML
  4248. },
  4249. addNewModuleForObjective: function (part, moduleType, removeElements) {
  4250. var self = this
  4251. var moduleTitle = ''
  4252. var modulePrev = part.prev()
  4253. var hasTitle = modulePrev.length && modulePrev[0].tagName === 'H3'
  4254. //3 移除老模块
  4255. removeElements.push(part)
  4256. if (hasTitle) {
  4257. moduleTitle = modulePrev[0].outerHTML
  4258. removeElements.push(modulePrev)
  4259. }
  4260. return moduleTitle + part[0].outerHTML
  4261. },
  4262. //拿到富文本超出的内容 顺便计算一下下一个模块该有的最低高度
  4263. getOverContent: function (part, surplusHeight, removeElements) {
  4264. var self = this
  4265. // var editorContentEl = part.find('.w-e-text')
  4266. var editorContentEl = part.find('.editorContent')
  4267. let partHtml = part.html()
  4268. let WETextLength =partHtml.search(".w-e-text")
  4269. // let WETextLength = part.find('.w-e-text').length
  4270. if(WETextLength>-1){
  4271. editorContentEl = part.find('.w-e-text')
  4272. if(editorContentEl.length==0){
  4273. editorContentEl =$(part).children('.editorContent').children()
  4274. }
  4275. }
  4276. var overContent = []
  4277. var overHeight = 0
  4278. //富文本可视化高度
  4279. // var surplusEditorViewportHeight =
  4280. // editorContentEl.height() - surplusHeight - 20
  4281. var surplusEditorViewportHeight =
  4282. part.find('.editorContent').height() - surplusHeight - 20
  4283. //看看当前富文本内容的高度有没有被超出的高度区域截掉
  4284. // var editorContentHeight = self.calcEditorContentHeight(editorContentEl)
  4285. var editorContentHeight = editorContentEl.height();
  4286. //如果剩余高度还能装的下答题文本 直接返回空
  4287. if (surplusEditorViewportHeight > editorContentHeight) {
  4288. return {
  4289. overContent: overContent.reverse().join(''),
  4290. overHeight: overHeight
  4291. }
  4292. }
  4293. var paperHeight = $(part).parents('.pageContent').height()
  4294. //当前超出富文本内容元素集合,倒序递归删除放到下一页
  4295. var editorContentElements = '';
  4296. if(WETextLength>-1){
  4297. editorContentElements = [].slice
  4298. .call(editorContentEl.children(), 0)
  4299. .reverse()
  4300. } else {
  4301. editorContentElements = [].slice
  4302. .call(part.find('.editorContent').children(), 0)
  4303. .reverse()
  4304. }
  4305. for (var i = 0, elItem; (elItem = editorContentElements[i++]); ) {
  4306. if (editorContentHeight < surplusEditorViewportHeight) break
  4307. var elItemHeight = $(elItem).height()
  4308. if ($(elItem).hasClass("composition-column")){
  4309. elItemHeight = 10
  4310. }
  4311. if ($(elItem).hasClass("en")){
  4312. elItemHeight = 34
  4313. }
  4314. if(elItemHeight>(paperHeight-150)){
  4315. $(elItem).find('img').css('max-height',paperHeight-150)
  4316. elItemHeight = paperHeight-150
  4317. }
  4318. editorContentHeight -= elItemHeight
  4319. overHeight += elItemHeight
  4320. removeElements.push($(elItem))
  4321. overContent.push(elItem.outerHTML)
  4322. }
  4323. return {
  4324. overContent: overContent.reverse().join(''),
  4325. overHeight: overHeight
  4326. }
  4327. },
  4328. //上一个模块的拓展模块
  4329. expandModule: function (part,editorOverContent, nextContentMinHeight) {
  4330. var self = this
  4331. var titleNumber = part.attr('title-number')
  4332. //当前超出的模块height
  4333. var overHeight = self.getOverHeight(part)
  4334. var $nextPage = part.closest('.pageContent').next()
  4335. var $nextPageFirstModule = $nextPage.find('.module').eq(0)
  4336. var $nextPageModuleTitleNumber = $nextPageFirstModule.attr('title-number')
  4337. overHeight =
  4338. overHeight < self.moduleMinHeight ? self.moduleDefaultHeihgt : overHeight
  4339. //如果下一页已经存在当前模块的 高度累加
  4340. if ($nextPageModuleTitleNumber === titleNumber) {
  4341. overHeight += 0 //$nextPageFirstModule.height()
  4342. }
  4343. //如果该模块超出区域 这需要通过linkparam 去 排列超出的顺序
  4344. ++self.editorIndex
  4345. var linkparm = 1
  4346. var cutId = self.editorIndex
  4347. //如果该模块是首次超出 则直接从1开始计数,否则从当前位置开始计数
  4348. if (!part.attr('data-linkparm')) {
  4349. part.attr({
  4350. 'data-cutId': self.editorIndex,
  4351. 'data-linkparm': linkparm
  4352. })
  4353. linkparm++
  4354. } else {
  4355. linkparm = +part.attr('data-linkparm')
  4356. cutId = +part.attr('data-cutId')
  4357. linkparm++
  4358. }
  4359. return self.tpls.overModuleTpl.substitute({
  4360. overIndex: self.editorIndex,
  4361. cutId: cutId,
  4362. linkparm: linkparm,
  4363. titleNumber: titleNumber,
  4364. editorOverContent:editorOverContent,
  4365. editorContentHeight:
  4366. overHeight < nextContentMinHeight ? nextContentMinHeight : overHeight
  4367. })
  4368. },
  4369. reduceFillInBlank: function (part, surplusHeight, $dtKContent) {
  4370. var self = this
  4371. var curPageIndex = $dtKContent.closest('.pageContent').index() + 1
  4372. var fromPageIndex = part.closest('.pageContent').index() + 1
  4373. //一行几栏
  4374. var $firstColForInfoEl = part.children('.subjectCol')
  4375. var dataColumns = $firstColForInfoEl.attr('data-column')
  4376. var columns = dataColumns ? +dataColumns : 1
  4377. //计算每个填空题item的高度
  4378. var rowLinHeight = $firstColForInfoEl.attr('data-rowlineheight')
  4379. var fillInBlankItemHeight = (+rowLinHeight || 40) + 11
  4380. var scoreStyle = $firstColForInfoEl.attr('data-scoreStyle')
  4381. //需要复制几个填空题-如果有标题要减去比哀痛的高度
  4382. if (part.prev().length && part.prev()[0].tagName === 'H3') {
  4383. surplusHeight -= part.prev().height()
  4384. }
  4385. var copyFillInBlankLength =
  4386. Math.floor(surplusHeight / fillInBlankItemHeight) * columns
  4387. //原页面保留的题目
  4388. //超出的放在新页面上
  4389. var curModuleDataIndex = 'page' + curPageIndex
  4390. var nextExpendDataIndex = 'page' + fromPageIndex
  4391. self.fillInBlank[curModuleDataIndex] = self.fillInBlank[
  4392. curModuleDataIndex
  4393. ].concat(
  4394. self.fillInBlank[nextExpendDataIndex].splice(0, copyFillInBlankLength)
  4395. )
  4396. //原页面残留
  4397. var originPageRetainHtml = self.getFillInBlankHtml(
  4398. self.fillInBlank[curModuleDataIndex]
  4399. )
  4400. //新页面超出
  4401. var overFillInBlankItemsHtml = self.getFillInBlankHtml(
  4402. self.fillInBlank[nextExpendDataIndex]
  4403. )
  4404. var $overFillInBlank = part.closest('.completion-topic')
  4405. var $overDtkContent = $overFillInBlank.closest('.dtk-content')
  4406. $overFillInBlank.remove()
  4407. if (overFillInBlankItemsHtml) {
  4408. overFillInBlankItemsHtml =
  4409. self.titleHtml(originPageRetainHtml ? '' : self['fillInBlank-title']) +
  4410. self.tpls.fillInBlankContentTpl.substitute({
  4411. addFillInBlankHtml: overFillInBlankItemsHtml,
  4412. columns: columns,
  4413. scoreStyle: scoreStyle,
  4414. rowLinHeight: rowLinHeight,
  4415. settingBtn: originPageRetainHtml
  4416. ? ''
  4417. : self.tpls.fillInBlankSettingBtnTpl
  4418. })
  4419. overFillInBlankItemsHtml = self.tpls.answerModulForFillInBlankTpl.substitute(
  4420. {
  4421. editModule: overFillInBlankItemsHtml,
  4422. moduleType: 'fillInBlank'
  4423. }
  4424. )
  4425. $overDtkContent.prepend(overFillInBlankItemsHtml)
  4426. }
  4427. //老页面残留填空题模块
  4428. var $prevFillInBlank = $dtKContent.find('.completion-topic')
  4429. if (!$prevFillInBlank.length) {
  4430. originPageRetainHtml =
  4431. self.titleHtml(self['fillInBlank-title']) +
  4432. self.tpls.fillInBlankContentTpl.substitute({
  4433. addFillInBlankHtml: originPageRetainHtml,
  4434. columns: columns,
  4435. scoreStyle: scoreStyle,
  4436. rowLinHeight: rowLinHeight,
  4437. settingBtn: self.tpls.fillInBlankSettingBtnTpl
  4438. })
  4439. originPageRetainHtml = self.tpls.answerModulForFillInBlankTpl.substitute({
  4440. editModule: originPageRetainHtml,
  4441. moduleType: 'fillInBlank'
  4442. })
  4443. $dtKContent.append(originPageRetainHtml)
  4444. } else {
  4445. $prevFillInBlank.find('.subjectCol').html(originPageRetainHtml)
  4446. }
  4447. return !overFillInBlankItemsHtml
  4448. },
  4449. reduceSingleSelect: function (part, surplusHeight, $dtKContent) {
  4450. var self = this
  4451. var curPageIndex = $dtKContent.closest('.pageContent').index() + 1
  4452. var fromPageIndex = part.closest('.pageContent').index() + 1
  4453. var type = part.closest('.answerModule').attr('data-type')
  4454. var direction = part.closest('.answerModule').attr('data-direction')
  4455. var prevTag = part.prev()[0]
  4456. if (prevTag && prevTag.tagName === 'H3') {
  4457. surplusHeight -= part.prev().height()
  4458. }
  4459. //每小题的高度
  4460. var selectItemHeight = $(part).find('.single-option').eq(0).outerHeight()
  4461. //当前超出的模块height
  4462. if (Math.floor(surplusHeight / selectItemHeight) < 1) return
  4463. //针对选择题竖版一行排几个
  4464. /**
  4465. * 超出的计算单位以 一整排为单位
  4466. * 每一排的一列以5题为单位 计算
  4467. */
  4468. var rowSubjectNum =
  4469. self.config[self.direction][self.hasBindingLine ? 'yesLine' : 'noLine'][
  4470. self.columns
  4471. ]
  4472. //计算超出多少小题
  4473. var overSelectItemsLength =
  4474. Math.floor(surplusHeight / selectItemHeight) * rowSubjectNum
  4475. //超出的放在新页面上
  4476. var curModuleDataIndex = 'page' + curPageIndex
  4477. var nextExpendDataIndex = 'page' + fromPageIndex
  4478. self[type][curModuleDataIndex] = self[type][curModuleDataIndex].concat(
  4479. self[type][nextExpendDataIndex].splice(0, overSelectItemsLength)
  4480. )
  4481. //计算留在当前页面的和下一个页面的数据
  4482. var originPageRetainHtml = self.getSingleSelectHtml(
  4483. self[type][curModuleDataIndex]
  4484. )
  4485. var overSelectItemsHtml = self.getSingleSelectHtml(
  4486. self[type][nextExpendDataIndex]
  4487. )
  4488. //超出页面的数据处理
  4489. var $overAnswerModule = part.closest('.single-select')
  4490. var $overDtkContent = $overAnswerModule.closest('.dtk-content')
  4491. $overAnswerModule.remove()
  4492. if (overSelectItemsHtml) {
  4493. //获取超出选择题区域模块html
  4494. //selectContent, title, direction, hasTitle
  4495. overSelectItemsHtml = self.getSelectRenderContent({
  4496. selectContent: overSelectItemsHtml,
  4497. title: type,
  4498. direction: direction,
  4499. hasTitle: originPageRetainHtml ? false : true,
  4500. settingBtn: !originPageRetainHtml
  4501. })
  4502. $overDtkContent.prepend(overSelectItemsHtml)
  4503. }
  4504. //老页面残留填空题模块处理
  4505. var $originAnswerModule = $dtKContent.find(
  4506. type === 'singleSelect' ? '.single-select' : '.moreSelect'
  4507. )
  4508. if (!$originAnswerModule.length) {
  4509. //获取整个选择题区域模块html
  4510. originPageRetainHtml = self.getSelectRenderContent({
  4511. selectContent: originPageRetainHtml,
  4512. direction: direction,
  4513. title: type
  4514. })
  4515. $dtKContent.append(originPageRetainHtml)
  4516. } else {
  4517. $originAnswerModule.find('.singleContent').html(originPageRetainHtml)
  4518. }
  4519. return !overSelectItemsHtml
  4520. },
  4521. reducePrintArea: function (curPageEl) {
  4522. var self = this
  4523. var nextPage = curPageEl.next()
  4524. if (!nextPage.length) {
  4525. //在delPageOverModule 的方法中可能存在被遗忘的超出模块此时做重置
  4526. if (self.forgetOverPage) {
  4527. self.changePrintArea(self.forgetOverPage)
  4528. }
  4529. return
  4530. }
  4531. var curPageIndex = curPageEl.index()
  4532. //当前模块下面所有的模块都可以上移,只要当前剩余空间足够大
  4533. var canUpMovePage = $('#printcontent').children(
  4534. '.pageContent:gt(' + curPageIndex + ')'
  4535. )
  4536. /**
  4537. * 首先通过判断当前页面的剩余空间是否够下一个页面的第一个模块使用
  4538. * 1 如果下一页第一个是第一页的模块补充模块 直接合并
  4539. * 2 如果下一页第一个不是补充模块,如果上一页的空间大于当前这一页
  4540. * a. 直接把标题带着第一个模块一起拿上去
  4541. * b. 如果是一个小题 直接把当前小题拿上去,归并到上一个页面的大题下面
  4542. */
  4543. //获取顺序
  4544. var nextPageAllModule = [].splice.call(
  4545. canUpMovePage.find('.answerModule'),
  4546. 0
  4547. )
  4548. //var objectiveModule = [].splice.call(canUpMovePage.find('.objectiveModule'), 0)
  4549. //var nextPageAllModule = objectiveModule.concat(answerModule)
  4550. var isContiune = true
  4551. nextPageAllModule.forEach(function (answerEl, index) {
  4552. if (!isContiune) return false
  4553. var firstAnswer = $(answerEl)
  4554. var nextUpPage = firstAnswer.closest('.pageContent')
  4555. var answerModuleType = firstAnswer.attr('data-type')
  4556. //题干信息
  4557. var isObjective = answerModuleType === 'objective'
  4558. var isSelect = ~answerModuleType.indexOf('Select')
  4559. var isFillInBlank = answerModuleType === 'fillInBlank'
  4560. var isChooseAnswer = answerModuleType === 'chooseAnswer'
  4561. var firstModule = firstAnswer.children('.module').eq(0)
  4562. var curPageContent = curPageEl.children('.dtk-content')
  4563. //具体分页内容容器的宽度
  4564. var contentAndHeight = curPageContent.outerHeight()
  4565. //当前分页剩余空间
  4566. var surplusHeight = curPageEl.height() - contentAndHeight
  4567. if (surplusHeight <= 10) {
  4568. //如果当前分页超出直接重新计算排版方式
  4569. if (
  4570. surplusHeight < -10 &&
  4571. curPageEl.find('.answerModule:last()').children('.module').length
  4572. ) {
  4573. self.changePrintArea(curPageEl)
  4574. }
  4575. isContiune = false
  4576. return false
  4577. }
  4578. if (isFillInBlank) {
  4579. //下一页面第一个填空题的高度
  4580. var firstModuleHeight = self.getNextPageFirstModuleHeight(
  4581. firstModule,
  4582. 'fillInBlank'
  4583. )
  4584. if (surplusHeight >= firstModuleHeight) {
  4585. self.reduceFillInBlank(firstModule, surplusHeight, curPageContent)
  4586. self.updatePageElement(nextUpPage, firstAnswer)
  4587. } else {
  4588. isContiune = false
  4589. return false
  4590. }
  4591. } else if (isSelect) {
  4592. var firstModuleHeight = self.getNextPageFirstModuleHeight(
  4593. firstModule,
  4594. 'singleSelect'
  4595. )
  4596. if (surplusHeight >= firstModuleHeight) {
  4597. self.reduceSingleSelect(firstModule, surplusHeight, curPageContent)
  4598. self.updatePageElement(nextUpPage, firstAnswer)
  4599. } else {
  4600. isContiune = false
  4601. return false
  4602. }
  4603. } else if (isObjective) {
  4604. $(answerEl)
  4605. .children('.objectiveItem')
  4606. .each(function (idx, moduleEl) {
  4607. //解答题一个小题就是一个module
  4608. firstModule = $(moduleEl)
  4609. contentAndHeight = curPageContent.outerHeight()
  4610. surplusHeight = curPageEl.height() - contentAndHeight
  4611. //下一个页面第一个解答题模块
  4612. var firstModuleHeight = self.getNextPageFirstModuleHeight(
  4613. firstModule,
  4614. 'objective'
  4615. )
  4616. if (surplusHeight >= firstModuleHeight) {
  4617. self.copyModuleForObjective(firstModule, firstAnswer, curPageEl)
  4618. self.updatePageElement(nextUpPage, firstAnswer, 'objective')
  4619. } else {
  4620. isContiune = false
  4621. return false
  4622. }
  4623. })
  4624. } else {
  4625. //选做题特殊处理,题干信息一个一个往上拿
  4626. var $chooseAnswerObjectiveItems = $(answerEl).find('.questionItemBody')
  4627. //如果有单独的模块还是可以
  4628. // && !$(answerEl).children('.module').length
  4629. if (isChooseAnswer && $chooseAnswerObjectiveItems.length) {
  4630. contentAndHeight = curPageContent.outerHeight()
  4631. surplusHeight =
  4632. curPageEl.height() -
  4633. contentAndHeight -
  4634. $(answerEl).find('h3').children('span').height()
  4635. var removeItems = []
  4636. $chooseAnswerObjectiveItems.each(function () {
  4637. //如果上一页有选做题模块
  4638. var prePageLastAnswer = curPageEl.find('.answerModule:last')
  4639. var prevLastModuleIsChooseAnswer = prePageLastAnswer.length
  4640. ? prePageLastAnswer.attr('data-type') === 'chooseAnswer'
  4641. : false
  4642. var $item = $(this)
  4643. var itemHeight = $(this).height()
  4644. var itemHtml = $(this)[0].outerHTML
  4645. if (surplusHeight > itemHeight) {
  4646. if (prePageLastAnswer.length && prevLastModuleIsChooseAnswer) {
  4647. prePageLastAnswer
  4648. .children('h3')
  4649. .children('.originSubjectInfo')
  4650. .append(itemHtml)
  4651. surplusHeight -= itemHeight
  4652. removeItems.push($item)
  4653. } else {
  4654. //如果上一页没有多选题模块
  4655. //1 先拿到当前多选题的基础信息
  4656. var $h3 = $(answerEl).find('h3')
  4657. var baseInfo = $h3[0].outerHTML.replace(
  4658. /<div class="originSubjectInfo">(.*)<\/div>/g,
  4659. '<div class="originSubjectInfo">' + itemHtml + '</div>'
  4660. )
  4661. curPageContent.append(
  4662. '<div class="short-answer answerModule" data-type="chooseAnswer">' +
  4663. baseInfo +
  4664. '</div>'
  4665. )
  4666. surplusHeight -= itemHeight
  4667. removeItems.push($item)
  4668. }
  4669. } else {
  4670. isContiune = false
  4671. return false
  4672. }
  4673. })
  4674. if (removeItems.length >= $chooseAnswerObjectiveItems.length) {
  4675. $(answerEl).find('h3').remove()
  4676. } else {
  4677. if (removeItems.length) {
  4678. removeItems.forEach(function (el) {
  4679. $(el).remove()
  4680. })
  4681. $(answerEl)
  4682. .find('h3')
  4683. .html(
  4684. '<div class="originSubjectInfo">' +
  4685. $(answerEl)
  4686. .find('h3')
  4687. .children('.originSubjectInfo')
  4688. .html() +
  4689. '</div>'
  4690. )
  4691. }
  4692. }
  4693. self.updatePageElement(nextUpPage, firstAnswer, 'chooseAnswer')
  4694. //self.reducePrintArea(nextPage)
  4695. return
  4696. }
  4697. $(answerEl)
  4698. .children('.module')
  4699. .each(function (idx, moduleEl) {
  4700. var resetEditorIds = []
  4701. //解答题一个小题就是一个module
  4702. firstModule = $(moduleEl)
  4703. contentAndHeight = curPageContent.outerHeight()
  4704. surplusHeight = curPageEl.height() - contentAndHeight
  4705. //如果是补充模块--直接删除再计算其他高度
  4706. if (self.isSurplusModule(firstModule)) {
  4707. self.delPageOverPart(firstModule.find('.delBtn'), 'surplus')
  4708. return
  4709. }
  4710. //下一个页面第一个解答题模块
  4711. var firstModuleHeight = self.getNextPageFirstModuleHeight(
  4712. firstModule,
  4713. 'answer'
  4714. )
  4715. if (surplusHeight >= firstModuleHeight) {
  4716. self.copyModuleToSurplus(
  4717. firstModule,
  4718. firstAnswer,
  4719. curPageEl,
  4720. resetEditorIds
  4721. )
  4722. } else {
  4723. //判断是否是一个大题的开始
  4724. //如果是选做题题干信息
  4725. var modulePrev = firstModule.prev()
  4726. var hasTitle = modulePrev.length && modulePrev[0].tagName === 'H3'
  4727. var titleHeight = hasTitle ? modulePrev.height() : 0
  4728. if (surplusHeight <= titleHeight + 100) {
  4729. isContiune = false
  4730. return false
  4731. } else {
  4732. self.copyModuleToSurplus(
  4733. firstModule,
  4734. firstAnswer,
  4735. curPageEl,
  4736. resetEditorIds
  4737. )
  4738. if (self.getOverHeight(curPageEl.find('.module:last()'))) {
  4739. self.saveForgetPage(curPageEl)
  4740. }
  4741. }
  4742. }
  4743. self.updatePageElement(nextUpPage, firstAnswer)
  4744. //重置富文本
  4745. self.resetAddNewModuleEditor(resetEditorIds)
  4746. })
  4747. }
  4748. })
  4749. self.changePrintArea(nextPage)
  4750. },
  4751. //复制一个模块到上一个页面的剩余空间 type whole | few表示整体模块上移还是部分模块上去
  4752. copyModuleToSurplus: function (
  4753. firstModule,
  4754. firstAnswer,
  4755. curPageEl,
  4756. resetEditorIds
  4757. ) {
  4758. var self = this
  4759. //判断是否是一个大题的开始
  4760. var modulePrev = firstModule.prev()
  4761. var hasTitle = modulePrev.length && modulePrev[0].tagName === 'H3'
  4762. var moduleType = firstAnswer.attr('data-type')
  4763. var cloneHtml = ''
  4764. //准备重新初始化富文本所需要的 editorId
  4765. var editorEl = firstModule.children('.editorContent')
  4766. if (editorEl.length) {
  4767. resetEditorIds.push({
  4768. editorId: editorEl.attr('id'),
  4769. toolbarId: editorEl.prev().attr('id')
  4770. })
  4771. }
  4772. //如果没有标题 则认为是 上一页最后一大题的一个小题
  4773. var moduleHtml = firstModule[0].outerHTML
  4774. var $dtkContent = curPageEl.children('.dtk-content')
  4775. var $shortAnswerLast = curPageEl.find('.short-answer:last()')
  4776. if (hasTitle) {
  4777. var editModuleHtml = modulePrev[0].outerHTML + moduleHtml
  4778. cloneHtml = self.tpls.answerModuleTpl.substitute({
  4779. editModule: editModuleHtml,
  4780. moduleType: moduleType
  4781. })
  4782. $dtkContent.append(cloneHtml)
  4783. modulePrev.remove()
  4784. } else {
  4785. cloneHtml = moduleHtml
  4786. //可能中间出现真空区域
  4787. if (!$shortAnswerLast.length) {
  4788. cloneHtml = self.tpls.answerModuleTpl.substitute({
  4789. editModule: cloneHtml,
  4790. moduleType: moduleType
  4791. })
  4792. $dtkContent.append(cloneHtml)
  4793. } else {
  4794. $shortAnswerLast.append(cloneHtml)
  4795. }
  4796. }
  4797. //清理模块
  4798. firstModule.remove()
  4799. },
  4800. //题干信息copy
  4801. copyModuleForObjective: function (firstModule, firstAnswer, curPageEl) {
  4802. var self = this
  4803. //判断是否是一个大题的开始
  4804. var modulePrev = firstModule.prev()
  4805. var hasTitle = modulePrev.length && modulePrev[0].tagName === 'H3'
  4806. var cloneHtml = ''
  4807. //如果没有标题 则认为是 上一页最后一大题的一个小题
  4808. var moduleHtml = firstModule[0].outerHTML
  4809. // self.tpls.objectiveItemTpl.substitute({
  4810. // content: firstModule.html()
  4811. // })
  4812. var $dtkContent = curPageEl.children('.dtk-content')
  4813. if (hasTitle) {
  4814. var editModuleHtml = modulePrev[0].outerHTML + moduleHtml
  4815. cloneHtml = self.tpls.objectiveWrapTpl.substitute({
  4816. editModule: editModuleHtml
  4817. })
  4818. $dtkContent.append(cloneHtml)
  4819. modulePrev.remove()
  4820. } else {
  4821. var $shortAnswerLast = curPageEl.find('.objectiveModule:last()')
  4822. cloneHtml = moduleHtml
  4823. //可能中间出现真空区域
  4824. if (!$shortAnswerLast.length) {
  4825. cloneHtml = self.tpls.objectiveWrapTpl.substitute({
  4826. editModule: cloneHtml
  4827. })
  4828. $dtkContent.append(cloneHtml)
  4829. } else {
  4830. $shortAnswerLast.append(cloneHtml)
  4831. }
  4832. }
  4833. //清理模块
  4834. firstModule.remove()
  4835. },
  4836. //获取当前也页面的剩余空间
  4837. getCurPageSurplusHeight: function (curPageEl) {
  4838. var curPageContent = curPageEl.children('.dtk-content')
  4839. //具体分页内容容器的宽度
  4840. var contentAndHeight = curPageContent.outerHeight()
  4841. //当前分页剩余空间
  4842. return curPageEl.height() - contentAndHeight
  4843. },
  4844. //获取下一个页面第一个模块的高度,用来和上一个页面的剩余高度做对比
  4845. getNextPageFirstModuleHeight: function (firstModule, type) {
  4846. var self = this
  4847. //判断是否是一个大题的开始
  4848. var modulePrev = firstModule.prev()
  4849. var hasTitle = modulePrev.length && modulePrev[0].tagName === 'H3'
  4850. //如果包含title 必须满足上一页面剩余的高度大于 当前页面第一个模块的高度加上模块对应title的高度
  4851. //留点空间余地不能抵到最底下
  4852. var titleHeight = (hasTitle ? modulePrev.height() : 0) + 10
  4853. //type包含选择,填空,解答题
  4854. if (type === 'fillInBlank') {
  4855. var firstFillInBlank = firstModule.find('.subjectItem').eq(0)
  4856. return firstFillInBlank.outerHeight() + titleHeight
  4857. } else if (~type.indexOf('Select')) {
  4858. var firstSelect = firstModule.find('.single-option').eq(0)
  4859. return firstSelect.outerHeight() + titleHeight
  4860. } else {
  4861. return firstModule.outerHeight() + titleHeight
  4862. }
  4863. },
  4864. //页面之间模版串位之后更新每个页面的元素
  4865. updatePageElement: function (nextUpPage, firstAnswer, type) {
  4866. var self = this
  4867. //题干信息单独处理
  4868. var nextPage = nextUpPage
  4869. var isObjective = type === 'objective'
  4870. //选做题如果有题干信息
  4871. var isChooseAnswer =
  4872. type === 'chooseAnswer' && firstAnswer.find('.originSubjectInfo').length
  4873. if (firstAnswer) {
  4874. if (
  4875. !firstAnswer.children(isObjective ? '.objectiveItem' : '.module')
  4876. .length &&
  4877. !isChooseAnswer
  4878. ) {
  4879. firstAnswer.remove()
  4880. }
  4881. }
  4882. if (
  4883. !nextPage.find('.answerModule').length &&
  4884. !nextPage.find('.objectiveModule').length
  4885. ) {
  4886. // 判断当前页面是否最后一页----如果最后一页为空才直接删除该页面
  4887. // 选择题和填空题的数据是根据页面显示的,如果你删除了,选择题和填空题的数据就错位了
  4888. if ($('#printcontent .pageContent').length === nextPage.index() + 1) {
  4889. var prevPage = nextPage.prev()
  4890. nextPage.remove()
  4891. self.currentPage--
  4892. //新建的分页
  4893. self.totalPage--
  4894. self.refrushPageLabel()
  4895. if (prevPage.length) {
  4896. self.updatePageElement(prevPage)
  4897. }
  4898. }
  4899. }
  4900. },
  4901. //新页面预览
  4902. previewPrintDiv: function (printPart) {
  4903. var self = this
  4904. var priviewHtml = self.formatPrintHtml(printPart, 'preview')
  4905. var iframe = document.createElement('iframe')
  4906. iframe.setAttribute('id', 'preview-iframe')
  4907. document.body.appendChild(iframe)
  4908. var doc = iframe.contentWindow.document
  4909. doc.write(
  4910. '<link rel="stylesheet" type="text/css" href="' + printCssPath + '">'
  4911. )
  4912. doc.write(priviewHtml)
  4913. $('body').append('<div id="closeIframeBtn" class="h_btn">关闭</div>')
  4914. $('#closeIframeBtn').click(function () {
  4915. $('#preview-iframe').remove()
  4916. $(this).remove()
  4917. })
  4918. },
  4919. //保存题目坐标信息
  4920. //保存的时候传点坐标和原图
  4921. /**
  4922. *
  4923. timu:{"KeGuanTi":5,"TianKongTi":10,"ZhuGuanTi":1,"XuanZuoTi":0}
  4924. sheet_answer:{"1":"A","2":"A","3":"A","4":"A","5":"A"}
  4925. sheet_score:{"1":"2","2":"2","3":"2","4":"2","5":"2","6":"2","7":"3","8":"4","9":"5","10":"6","11":"6","12":"7","13":"8","14":"9","15":"10","16":"20"}
  4926. title:22
  4927. exam_id:17464269385543527633
  4928. position
  4929. imgFiles:[fileobj,fileobj]
  4930. */
  4931. //保存题目定位点的时候 获取 题目数量 分数 等信息
  4932. getSaveSubjectInfo: function (questionClassify) {
  4933. var self = this
  4934. var title = self.$dtkName.val()
  4935. //数量
  4936. var timu = {
  4937. KeGuanTi: questionClassify.singleSelect.length,
  4938. TianKongTi: questionClassify.fillInBlank.length,
  4939. ZhuGuanTi: questionClassify.shortAnswer.length,
  4940. XuanZuoTi: questionClassify.chooseAnswer.length
  4941. }
  4942. //选择题答案
  4943. var sheet_answer = {}
  4944. questionClassify.singleSelect.forEach(function (item) {
  4945. sheet_answer[item.questionNum] = item.answer
  4946. })
  4947. questionClassify.moreSelect.forEach(function (item) {
  4948. sheet_answer[item.questionNum] = item.answer
  4949. })
  4950. //每题对应分数
  4951. var sheet_score = {}
  4952. for (var subjectType in questionClassify) {
  4953. questionClassify[subjectType].forEach(function (subjectItem) {
  4954. sheet_score[subjectItem.questionNum] = '' + subjectItem.fullScore
  4955. })
  4956. }
  4957. self.savePrintInfo = {
  4958. title: title,
  4959. timu: timu,
  4960. sheet_answer: sheet_answer,
  4961. sheet_score: sheet_score
  4962. }
  4963. },
  4964. //printcontent --- printPart
  4965. savePrintPosition: function (printPart, cb) {
  4966. var self = this
  4967. // 给模块标题设置高度
  4968. $('.answerModule').find('h3').each(function (){
  4969. $(this).css('height',$(this).height())
  4970. })
  4971. var position = self.getPositions()
  4972. //校验答题卡试题量与试卷题量是否相等
  4973. var cardNos = ''
  4974. position.pages.forEach(paper=>{
  4975. paper.questions.forEach(topic=>{
  4976. cardNos = cardNos+topic.id+','
  4977. })
  4978. })
  4979. var cardNoArr = cardNos.split(',');
  4980. var isLeak = false;
  4981. self.examQuestions.forEach(paperTopic=>{
  4982. var isLeakTopic = true
  4983. cardNoArr.forEach(cardTopic=>{
  4984. if(paperTopic.questionNum == cardTopic){
  4985. isLeakTopic = false
  4986. }
  4987. })
  4988. if(isLeakTopic){
  4989. isLeak = true
  4990. }
  4991. })
  4992. if(isLeak){
  4993. self.modal.init({
  4994. title: '提示',
  4995. content: '答题卡题量与试卷不符,请重置',
  4996. ensureText: '重置',
  4997. cancelText: '取消',
  4998. sureCb: function () {
  4999. location.reload()
  5000. }
  5001. })
  5002. return false
  5003. }
  5004. //保存当前坐标点用于和下次一点击保存做对比,如果没有变化就可以防止重复提交
  5005. self.saveLocationPosition = JSON.stringify(position)
  5006. //console.log(JSON.stringify(position, null, 4))
  5007. var printHtml = self.formatPrintHtml(printPart)
  5008. var iframe = document.createElement('iframe')
  5009. iframe.setAttribute('id', 'print-iframe')
  5010. iframe.setAttribute('style', 'position:fixed;')
  5011. document.body.appendChild(iframe)
  5012. var doc = iframe.contentWindow.document
  5013. doc.write(
  5014. '<link rel="stylesheet" type="text/css" href="' + printCssPath + '">'
  5015. )
  5016. doc.write(printHtml)
  5017. doc.close()
  5018. iframe.contentWindow.focus()
  5019. iframe.contentWindow.onload = function () {
  5020. var pages = doc.getElementsByClassName('printIframeContent')
  5021. //生成的pdf所需要的html
  5022. var pdfHtml = (
  5023. self.tpls.htmlSkeleton +
  5024. printHtml +
  5025. '</body></html>'
  5026. ).replace(/\'/g, '"')
  5027. hgc_layer.msg('pdf生成中,请稍后...', { time: 0, shade: 0.4 })
  5028. $.post(
  5029. self.apis.getOnlinePdfApi,
  5030. {
  5031. width: self.config.width + 'mm',
  5032. height: self.config.height + 'mm',
  5033. name: 'pdf',
  5034. examGroupId: self.examGroupId,
  5035. direction: self.direction,
  5036. pdfHtml: pdfHtml
  5037. },
  5038. function (res) {
  5039. let resData = JSON.parse(res)
  5040. if(resData.status==0){
  5041. hgc_layer.msg('生成pdf失败,请稍后再试!')
  5042. return false
  5043. }
  5044. var pdfFileUrl = resData.data
  5045. self.downPdfUrl = resData.data
  5046. var html2canvasPromise = []
  5047. //html2canvas 返回的是一个promise
  5048. ;[].slice.call(pages).forEach(function (pageItem) {
  5049. html2canvasPromise.push(html2canvas(pageItem))
  5050. })
  5051. Promise.all(html2canvasPromise).then(function (res) {
  5052. var imgFiles = []
  5053. res.forEach(function (canvas, index) {
  5054. var img = Canvas2Image.convertToJPEG(canvas)
  5055. var dataUrl = img.src
  5056. imgFiles.push(dataURLtoFile(dataUrl, 'pic' + index + '.jpeg'))
  5057. })
  5058. //处理模版html
  5059. var pdfHtmlStream = new Blob([pdfHtml], {
  5060. type: 'text/plain;charset=utf-8'
  5061. })
  5062. self.savePrintInfo.pdfHtml = pdfHtml
  5063. self.savePrintInfo.position = position
  5064. self.savePrintInfo.examGroupId = self.examGroupId
  5065. self.savePrintInfo.useQrCode = self.useQrCode ? 1 : 0
  5066. self.savePrintInfo.columns = self.columns
  5067. //题干信息记忆布局
  5068. self.savePrintInfo.stemInfo = self.stemInfo
  5069. var formData = new FormData()
  5070. for (var field in self.savePrintInfo) {
  5071. if (typeof self.savePrintInfo[field] === 'object') {
  5072. formData.append(
  5073. field,
  5074. JSON.stringify(self.savePrintInfo[field])
  5075. )
  5076. } else {
  5077. formData.append(field, self.savePrintInfo[field])
  5078. }
  5079. }
  5080. formData.append('pdfTemplate', pdfHtmlStream, 'pdfTepmlate.txt')
  5081. //试卷原图
  5082. imgFiles.forEach(function (img, index) {
  5083. formData.append('imgFiles' + index, img)
  5084. })
  5085. //pdf链接
  5086. formData.append('pdf_url', pdfFileUrl)
  5087. $.ajax({
  5088. //'//192.168.1.51/index.php/print/saveCardOnline' + loginStatus,
  5089. url: self.apis.saveTopicsDetailsApi,
  5090. method: 'POST',
  5091. processData: false,
  5092. contentType: false,
  5093. dataType: 'json',
  5094. data: formData,
  5095. success: function (data) {
  5096. hgc_layer.closeAll()
  5097. if (data.success === 1) {
  5098. hgc_layer.msg('保存成功')
  5099. self.isCanEditCard = false
  5100. self.changeCardEditStatus()
  5101. self.alreadySave = true
  5102. //删除node端存储pdf文件
  5103. // $.post(self.apis.delPdfApi, {
  5104. // identifier: self.examGroupId
  5105. // })
  5106. //如果使用二维码
  5107. //考号 和 条形码 都没有了,导致试卷内所有定位点错误,需要重新保存定位点
  5108. cb && cb()
  5109. } else {
  5110. hgc_layer.msg('保存失败')
  5111. }
  5112. }
  5113. })
  5114. document.body.removeChild(iframe)
  5115. })
  5116. }
  5117. )
  5118. }
  5119. },
  5120. //重置学生状态
  5121. resetExamStudentStatus: function (cb) {
  5122. var self = this
  5123. $.post(
  5124. self.apis.resetExamStudentApi,
  5125. {
  5126. schoolId: this.schoolId,
  5127. examGroupId: this.examGroupId
  5128. },
  5129. function (res) {
  5130. //console.log(res)
  5131. cb && cb()
  5132. }
  5133. )
  5134. },
  5135. //后台批量生成examgroupid下面的所有考试
  5136. // batchGeneratePdf: function () {
  5137. // var self = this
  5138. // var printHtml = self.formatPrintHtml('printcontent')
  5139. // var pdfHtml = (
  5140. // self.tpls.htmlSkeleton +
  5141. // printHtml +
  5142. // '</body></html>'
  5143. // ).replace(/\'/g, '"')
  5144. // var batchParams = {
  5145. // width: self.config.width + 'mm',
  5146. // height: self.config.height + 'mm',
  5147. // examGroupId: self.examGroupId,
  5148. // examIds: self.examIds,
  5149. // schoolId: self.schoolId,
  5150. // direction: self.direction,
  5151. // pdfTpl: pdfHtml
  5152. // //savedInfoUrl: 'http://zxhx-test.cn-bj.ufileos.com/zsyas2%2Fcardonline%2F3865%2F2020%2F04%2F10%2F565798454967058432.zip?r=888'
  5153. // }
  5154. // // hgc_layer.msg('学生模板批量生成中,请稍后...', { time: 0, shade: 0.4 })
  5155. // $.ajax({
  5156. // url: self.apis.batchGeneratePdfApi,
  5157. // method: 'POST',
  5158. // data: batchParams,
  5159. // success: function (res) {
  5160. // hgc_layer.closeAll()
  5161. // hgc_layer.msg(res.msg)
  5162. // }
  5163. // })
  5164. // // batchInstance = $.post(self.apis.batchGeneratePdfApi, batchParams, function(res) {
  5165. // // })
  5166. // },
  5167. batchGeneratePdf: function () {
  5168. var self = this
  5169. var postData = {
  5170. exam_group_id: this.examGroupId
  5171. }
  5172. $.ajax({
  5173. url: self.apis.generatePhpPdf,
  5174. method: 'POST',
  5175. data: postData,
  5176. success: function (res) {
  5177. hgc_layer.closeAll()
  5178. var resData = JSON.parse(res);
  5179. if(resData.status==1){
  5180. hgc_layer.msg('发送成功!后台处理中。')
  5181. }else if(resData.status==0){
  5182. var layerMsg = resData.msg || '发送生成失败!'
  5183. hgc_layer.msg(layerMsg)
  5184. }
  5185. }
  5186. })
  5187. },
  5188. downLoadPdf: function () {
  5189. var self = this
  5190. if (!self.alreadySave || self.downPdfUrl=='') {
  5191. hgc_layer.msg('请先保存答题卡')
  5192. return
  5193. }
  5194. var downloadUrl =
  5195. // self.apis.downPdfApi + '?exam_group_id=' + self.examGroupId
  5196. self.apis.downOnlinePdfApi + '?url=' + self.downPdfUrl + '&title=pdf-'+self.examGroupId+'.pdf'
  5197. location.href = downloadUrl
  5198. },
  5199. /**
  5200. * 处理需要打印的html
  5201. * 返回处理之后直接可以打印的html
  5202. */
  5203. formatPrintHtml: function (elId, type) {
  5204. //format-需要打印的iframe里面的内容
  5205. //origin-原网页的内容
  5206. var self = this
  5207. $('#examInfo').find('.input-examInfo').each(function(i ,item){
  5208. $(this).attr('value',$(this).val())
  5209. })
  5210. //type 预览效果存储的html 和 用于转pdf 的不一样
  5211. var isPreview = type === 'preview'
  5212. var $formatContent = $('#formatContent').html($('#' + elId).html())
  5213. var $formatPageContent = $formatContent.children('.pageContent')
  5214. var $formatPageObjective = $formatPageContent.find('.objectiveItem')
  5215. var $formatDtkTitle = $formatPageContent.eq(0).find('.dtkName')
  5216. var $formatDtkNoticeDetail = $formatPageContent.eq(0).find('.noticeDetail')
  5217. var $formatShortAnswer = $formatContent.find('.short-answer')
  5218. // var $originShortAnswer = $('#' + elId + ' .short-answer')
  5219. var $originShortAnswer = $('#' + elId + ' .short-answer')
  5220. var $originDtkTitle = $('#' + elId + ' .pageContent')
  5221. .eq(0)
  5222. .find('.dtkName')
  5223. //设置每个分页的高度
  5224. $formatPageContent.height(self.config.height + 'mm')
  5225. $formatPageContent.find('.pageLabel .size').remove()
  5226. //设置答题卡title
  5227. $formatDtkTitle.html($originDtkTitle.children('textarea').val())
  5228. //设置注意事项-所有标题预览页面不可编辑
  5229. $formatDtkNoticeDetail.prop('contenteditable', false)
  5230. $formatPageContent.find('h3').prop('contenteditable', false)
  5231. $formatPageObjective.prop('contenteditable', false)
  5232. //模块格式化html
  5233. $originShortAnswer.each(function (index, el) {
  5234. $(el)
  5235. .children('.module')
  5236. .each(function (idx, elm) {
  5237. var $formatModuleItem = $formatShortAnswer
  5238. .eq(index)
  5239. .children('.module')
  5240. .eq(idx)
  5241. var $scortColumn = $(elm).children('.scortColumn')
  5242. var $chooseArea = $(elm).children('.selTopic')
  5243. var editorIndex = $(elm).attr('data-editorIndex')
  5244. if (!editorIndex) return
  5245. //富文本编辑内容
  5246. // var textareaContent = self.editorArea[
  5247. // 'editor' + editorIndex
  5248. // ].txt.html()
  5249. var textareaContent = $(elm).find('.editorContent').html();
  5250. //打分区域
  5251. var scortAreaContent = $scortColumn.length
  5252. ? $scortColumn[0].outerHTML
  5253. : ''
  5254. //多选区域
  5255. var chooseAreaHtml = ''
  5256. if ($chooseArea.length) {
  5257. chooseAreaHtml += $chooseArea[0].outerHTML
  5258. }
  5259. //height content
  5260. var modulePrintHeight = self.unitConversion.pxConversionMm(
  5261. $(elm).height()
  5262. )
  5263. $formatModuleItem
  5264. .height(modulePrintHeight + 'mm')
  5265. .html(
  5266. scortAreaContent +
  5267. chooseAreaHtml +
  5268. '<div class="modulePosition">' +
  5269. textareaContent +
  5270. '</div>'
  5271. )
  5272. })
  5273. })
  5274. //用几张纸
  5275. var paperLength = Math.ceil($formatPageContent.length / self.columns)
  5276. paperLength = paperLength < 2 ? paperLength + 1 : paperLength
  5277. var printHtmlForPaperHtml = ''
  5278. for (var j = 0; j < paperLength; j++) {
  5279. var printHtml = ''
  5280. //判断奇数页 还是 偶数页
  5281. var isEvenPaper = !((j + 1) % 2)
  5282. var isFirstPaper = !j
  5283. var scanDotPaperIndex = (j + 1) % 2 ? 1 : 2
  5284. for (var k = 0; k < self.columns; k++) {
  5285. var pageItem = $formatPageContent.eq(j * self.columns + k)
  5286. var pageClass = pageItem.attr('class') || 'pageContent'
  5287. var dtkContentHtml = pageItem.length
  5288. ? pageItem.html()
  5289. : self.tpls.forbiddenAreaTpl
  5290. var bindingLineHtml = ''
  5291. //奇数页面装订线在左边,偶数页面装订线在右边
  5292. //奇数页面的第一个分栏 和 偶数页面的最后一个分栏 加上装订线,除了第一个
  5293. if (self.hasBindingLine) {
  5294. if (isEvenPaper && k + 1 === self.columns) {
  5295. bindingLineHtml = self.tpls.bindLineTpl.substitute({ pos: 'right' })
  5296. } else if (!isEvenPaper && !k && !isFirstPaper) {
  5297. bindingLineHtml = self.tpls.bindLineTpl.substitute({ pos: 'left' })
  5298. }
  5299. }
  5300. printHtml +=
  5301. '<div class="' +
  5302. pageClass +
  5303. '" style="break-after: page;height:' +
  5304. self.config.height +
  5305. 'mm">' +
  5306. bindingLineHtml +
  5307. dtkContentHtml +
  5308. '</div>'
  5309. }
  5310. var scanDotHtml = self.tpls['scanDotPaper' + scanDotPaperIndex]
  5311. printHtmlForPaperHtml += self.tpls.printIframeContentTpl.substitute({
  5312. bindingLine: self.hasBindingLine ? 'hasBindingLine' : '',
  5313. previewClass: isPreview ? 'previewIframe' : '',
  5314. columns: self.columns,
  5315. widthMm: self.config.width,
  5316. printHtml: printHtml + scanDotHtml
  5317. })
  5318. }
  5319. //清空
  5320. $('#formatContent').html('')
  5321. return printHtmlForPaperHtml
  5322. },
  5323. //获取定位的基准点
  5324. getPositionOriginPoint: function () {
  5325. var self = this
  5326. //每个分页的定位基准点都是当前分页的左上角
  5327. self.printAreaLeft = $('#printcontent').offset().left
  5328. self.printAreaTop = $('#printcontent').offset().top
  5329. },
  5330. //获取扫描点信息
  5331. getScanPointInfo: function (currentPaper) {
  5332. var self = this
  5333. self.dotWidth = 40
  5334. self.dotHeight = 20
  5335. //大定位点上下间隙
  5336. self.dotTBGap = 20
  5337. //为了区分正反面,大定位点上面中间的那个点,需要正反面反向偏移一定距离
  5338. self.offsetDistance = self.pageWidth / 2 - 50
  5339. //获取页面的扫描点
  5340. /**
  5341. * 1.产品定义的区域
  5342. * 2.客观题区域
  5343. * 3.图片考号区域
  5344. * 4.选做题区域
  5345. */
  5346. var hasBinding = self.hasBindingLine
  5347. var pagePaddingSide = self.pagePaddingSide + (hasBinding ? 20 : 0)
  5348. var location = [
  5349. //上左
  5350. {
  5351. x: pagePaddingSide * self.dpiRadio,
  5352. y: self.dotTBGap * self.dpiRadio,
  5353. width: self.dotWidth * self.dpiRadio,
  5354. height: self.dotHeight * self.dpiRadio,
  5355. type: 1
  5356. },
  5357. //上右
  5358. {
  5359. x:
  5360. (self.pageWidth - self.pagePaddingSide - self.dotWidth) *
  5361. self.dpiRadio,
  5362. y: self.dotTBGap * self.dpiRadio,
  5363. width: self.dotWidth * self.dpiRadio,
  5364. height: self.dotHeight * self.dpiRadio,
  5365. type: 1
  5366. },
  5367. //下右
  5368. {
  5369. x:
  5370. (self.pageWidth - self.pagePaddingSide - self.dotWidth) *
  5371. self.dpiRadio,
  5372. y: (self.pageHeight - self.dotTBGap - self.dotHeight) * self.dpiRadio,
  5373. width: self.dotWidth * self.dpiRadio,
  5374. height: self.dotHeight * self.dpiRadio,
  5375. type: 1
  5376. },
  5377. //下左
  5378. {
  5379. x: pagePaddingSide * self.dpiRadio,
  5380. y: (self.pageHeight - self.dotTBGap - self.dotHeight) * self.dpiRadio,
  5381. width: self.dotWidth * self.dpiRadio,
  5382. height: self.dotHeight * self.dpiRadio,
  5383. type: 1
  5384. }
  5385. ]
  5386. if (currentPaper === 1) {
  5387. //上靠左边
  5388. location.splice(1, 0, {
  5389. x: self.offsetDistance * self.dpiRadio,
  5390. y: self.dotTBGap * self.dpiRadio,
  5391. width: self.dotWidth * self.dpiRadio,
  5392. height: self.dotHeight * self.dpiRadio,
  5393. type: 1
  5394. })
  5395. } else {
  5396. //上靠右边
  5397. location.splice(1, 0, {
  5398. x:
  5399. (self.pageWidth - self.offsetDistance - self.dotWidth) *
  5400. self.dpiRadio,
  5401. y: self.dotTBGap * self.dpiRadio,
  5402. width: self.dotWidth * self.dpiRadio,
  5403. height: self.dotHeight * self.dpiRadio,
  5404. type: 1
  5405. })
  5406. }
  5407. return location
  5408. },
  5409. getElementWidth: function (el, type) {
  5410. var self = this
  5411. var width = $(el).outerWidth()
  5412. return width * self.dpiRadio
  5413. },
  5414. getElementHeight: function (el, type) {
  5415. var self = this
  5416. var height = $(el).outerHeight()
  5417. return height * self.dpiRadio
  5418. },
  5419. getPositions: function () {
  5420. var self = this
  5421. /**
  5422. * {paper,direction,hasBindingLine,examNumberConfig:{barCode,ticketNumber},useQrCode}
  5423. */
  5424. //Math.ceil(self.totalPage / self.columns)
  5425. //每次获取每张纸的每一页定位信息,先确定 x轴,y轴的定位基准点
  5426. self.getPositionOriginPoint()
  5427. //是否合并题卡信息
  5428. var $chooseAnswerInfo = $('.answerModule[data-type="chooseAnswer"]')
  5429. var isConcat =
  5430. self.isSubjectInfoToCard &&
  5431. $('.objectiveItem').length &&
  5432. $chooseAnswerInfo.length &&
  5433. $chooseAnswerInfo.find('.originSubjectInfo').length
  5434. var chooseAnswerStemInfo = ''
  5435. if (isConcat) {
  5436. $('.originSubjectInfo').each(function () {
  5437. chooseAnswerStemInfo += $(this).html()
  5438. })
  5439. chooseAnswerStemInfo =
  5440. '<div class="originSubjectInfo">' + chooseAnswerStemInfo + '</div>'
  5441. }
  5442. var printPositionInfo = {
  5443. totalPage: 2,
  5444. stemInfo:self.getStemInfo(),
  5445. //准考证类型
  5446. school_card_status: self.school_card_status,
  5447. //需要记录本次的paperTplType 是否为题卡合一
  5448. isSubjectInfoToCard: self.isSubjectInfoToCard,
  5449. //选做题题干信息单独保存
  5450. chooseAnswerStemInfo: encodeURIComponent(chooseAnswerStemInfo),
  5451. //纸张大小、方向、分栏、装订线、考号配置等,需要记忆布局
  5452. columns: self.columns,
  5453. hasBindingLine: self.hasBindingLine,
  5454. paper: self.paper,
  5455. direction: self.direction,
  5456. examNumberConfig: self.examNumberConfig,
  5457. useQrCode: self.useQrCode,
  5458. width: self.config.width,
  5459. height: self.config.height,
  5460. examInfoConfigText:self.examInfoConfigText,
  5461. examInfoConfig:self.examInfoConfig,
  5462. hasPaperMsg:self.hasPaperMsg,
  5463. pages: []
  5464. }
  5465. //每张纸的一面
  5466. var examNumberAreaData = self.getExamNumberPosition()
  5467. var paperPosition = {
  5468. 1: {
  5469. pageNo: 1,
  5470. //四个定位点信息
  5471. location: self.getScanPointInfo(1),
  5472. //条形码
  5473. studentcode_bar: examNumberAreaData.studentcode_bar,
  5474. //准考证号码
  5475. studentcode_fill: examNumberAreaData.studentcode_fill,
  5476. //缺考标记定位信息
  5477. absent: self.getAbsentMarkPostion(),
  5478. //学生二维码信息
  5479. QrCode: self.getQrCodePosition(),
  5480. //打印区域宽高
  5481. imge: {
  5482. width: self.pageWidth * self.dpiRadio, //self.config.width,
  5483. height: self.pageHeight * self.dpiRadio //self.config.height
  5484. },
  5485. //题目坐标信息
  5486. questions: []
  5487. },
  5488. 2: {
  5489. pageNo: 2,
  5490. //四个定位点信息
  5491. location: self.getScanPointInfo(2),
  5492. //打印区域宽高
  5493. imge: {
  5494. width: self.pageWidth * self.dpiRadio, //self.config.width,
  5495. height: self.pageHeight * self.dpiRadio //self.config.height
  5496. },
  5497. //题目坐标信息
  5498. questions: []
  5499. }
  5500. }
  5501. //首先获取每个纸张一页的扫描点信息
  5502. $('#printcontent .pageContent').each(function (pageIndex, pageItem) {
  5503. var $pageItem = $(pageItem)
  5504. //判断纸张的第一面还是第二面 or 正面还是反面
  5505. var paperNo = Math.ceil((pageIndex + 1) / self.columns)
  5506. $pageItem.find('.answerModule').each(function (k, moduleItem) {
  5507. var type = $(moduleItem).attr('data-type')
  5508. var moduleInfo = { type: self.questionTypeMapForPhp[type] }
  5509. var positionInfos = []
  5510. switch (type) {
  5511. case 'singleSelect':
  5512. case 'moreSelect':
  5513. positionInfos = self.getSingleSelectPositions(
  5514. moduleItem,
  5515. moduleInfo
  5516. )
  5517. break
  5518. case 'answer':
  5519. case 'mustAnswer':
  5520. positionInfos = self.getAswerPositions(moduleItem, moduleInfo)
  5521. break
  5522. case 'chooseAnswer':
  5523. positionInfos = self.getChooseAswerPositions(moduleItem, moduleInfo)
  5524. break
  5525. case 'fillInBlank':
  5526. positionInfos = self.getFillInBlankPOsitions(moduleItem, moduleInfo)
  5527. break
  5528. }
  5529. paperPosition[paperNo].questions = paperPosition[
  5530. paperNo
  5531. ].questions.concat(positionInfos)
  5532. })
  5533. })
  5534. for (var paperKey in paperPosition) {
  5535. printPositionInfo.pages.push(paperPosition[paperKey])
  5536. }
  5537. //console.log(JSON.parse(JSON.stringify(printPositionInfo)))
  5538. return printPositionInfo
  5539. },
  5540. //获取填空题获取选择题的题干信息
  5541. getStemInfo: function () {
  5542. var self = this
  5543. var memoryObjectiveHtmls = ''
  5544. $('.objectiveItem').each(function () {
  5545. //memoryObjectiveHtmls += encodeUtf8($(this)[0].outerHTML).toString() + '|end|'
  5546. memoryObjectiveHtmls += encodeURIComponent($(this)[0].outerHTML) + '|end|'
  5547. })
  5548. return memoryObjectiveHtmls
  5549. },
  5550. //准考证和条形码区域
  5551. getExamNumberPosition: function () {
  5552. var self = this
  5553. //是否使用二维码
  5554. if (self.useQrCode) return {}
  5555. //是否只是使用条形码
  5556. var isOnlyBarCode = self.isOnlyBarCode()
  5557. //判断显示的是准考证号还是条形码
  5558. var isTicketNumber = self.examNumberConfig.ticketNumber
  5559. var isBarCode = self.examNumberConfig.barCode
  5560. var studentcodePosition = {
  5561. studentcode_bar: {},
  5562. studentcode_fill: {}
  5563. }
  5564. //准考证号
  5565. if (isTicketNumber) {
  5566. var numberWidth = false
  5567. var numberHeight = false
  5568. var $ticketNumberCol = $('#hgc_examNumber ul.ticketNumber').children(
  5569. '.numberCol'
  5570. )
  5571. studentcodePosition.studentcode_fill = {
  5572. object: []
  5573. }
  5574. $ticketNumberCol.each(function (k, numberColItem) {
  5575. var group = []
  5576. var $ticketNumberItem = $(numberColItem).find('i')
  5577. $ticketNumberItem.each(function (m, numberItem) {
  5578. var numberPosition = self.getItemPosition(numberItem, 'examNumber')
  5579. numberWidth = numberWidth || self.getElementWidth(numberItem)
  5580. numberHeight = numberHeight || self.getElementHeight(numberItem)
  5581. group.push({
  5582. x: numberPosition.x,
  5583. y: numberPosition.y,
  5584. width: numberWidth,
  5585. height: numberHeight,
  5586. optName: m
  5587. })
  5588. })
  5589. studentcodePosition.studentcode_fill.object.push({
  5590. group: group
  5591. })
  5592. })
  5593. }
  5594. //条形码
  5595. if (isBarCode) {
  5596. var examMarkEl = isOnlyBarCode
  5597. ? $('#hgc_examNumberForOnlyBarcode .barCode')
  5598. : $('#hgc_examNumber .barCode')
  5599. var barCodePosition = self.getItemPosition(examMarkEl, 'barCode')
  5600. studentcodePosition.studentcode_bar = {
  5601. object: {
  5602. x: barCodePosition.x,
  5603. y: barCodePosition.y,
  5604. width: self.getElementWidth(examMarkEl),
  5605. height: self.getElementHeight(examMarkEl)
  5606. }
  5607. }
  5608. }
  5609. return studentcodePosition
  5610. },
  5611. //缺考标记
  5612. getAbsentMarkPostion: function () {
  5613. var self = this
  5614. var $absentMark = $('.absentMark')
  5615. var absentMarkPosition = self.getItemPosition($absentMark)
  5616. var absentWidth = self.getElementWidth($absentMark)
  5617. var absentHeight = self.getElementHeight($absentMark)
  5618. return {
  5619. x: absentMarkPosition.x,
  5620. y: absentMarkPosition.y,
  5621. width: absentWidth,
  5622. height: absentHeight
  5623. }
  5624. },
  5625. //二维码定位信息
  5626. getQrCodePosition: function () {
  5627. var self = this
  5628. var $dtkEwm = $('#dtkEwm')
  5629. var dtkEwmPosition = self.getItemPosition($dtkEwm)
  5630. var dtkEwmWidth = self.getElementWidth($dtkEwm)
  5631. var dtkEwmHeight = self.getElementHeight($dtkEwm)
  5632. //if (!self.useQrCode) return {}
  5633. return {
  5634. x: dtkEwmPosition.x,
  5635. y: dtkEwmPosition.y,
  5636. width: dtkEwmWidth,
  5637. height: dtkEwmHeight
  5638. }
  5639. },
  5640. //单选题坐标获取
  5641. getSingleSelectPositions: function (moduleItem, moduleInfo) {
  5642. var self = this
  5643. var optionInfos = []
  5644. var direction = $(moduleItem).attr('data-direction')
  5645. $(moduleItem)
  5646. .find('li')
  5647. .each(function (i, optionItems) {
  5648. var optionInfo = {
  5649. type: moduleInfo.type,
  5650. answer: $(optionItems).attr('data-answer'),
  5651. score: {
  5652. full: 5
  5653. },
  5654. id: $(optionItems).attr('title-number'),
  5655. opt: [],
  5656. direction: direction
  5657. }
  5658. $(optionItems)
  5659. .children('span')
  5660. .each(function (k, option) {
  5661. var optionPosition = self.getItemPosition(option, 'select')
  5662. var width = self.getElementWidth(option)
  5663. var height = self.getElementHeight(option)
  5664. var optName = $(option).attr('data-option')
  5665. optionInfo.opt.push({
  5666. x: optionPosition.x,
  5667. y: optionPosition.y,
  5668. width: width,
  5669. height: height,
  5670. optName: optName
  5671. })
  5672. })
  5673. optionInfos.push(optionInfo)
  5674. })
  5675. return optionInfos
  5676. },
  5677. //填空题
  5678. getFillInBlankPOsitions: function (moduleItem, moduleInfo) {
  5679. var self = this
  5680. var optionInfos = []
  5681. $(moduleItem)
  5682. .find('.subjectItem')
  5683. .each(function (i, optionItems) {
  5684. var $subjectCol = $(optionItems).parent('.subjectCol')
  5685. var $score = $(optionItems).children('strong')
  5686. var column = $subjectCol.attr('data-column')
  5687. var scoreStyle = $subjectCol.attr('data-scoreStyle')
  5688. var rowLineHeight = $subjectCol.attr('data-rowLineHeight')
  5689. var optionPosition = self.getItemPosition(optionItems, 'fillInBlank')
  5690. var width = self.getElementWidth(optionItems, 'fillInBlank')
  5691. var height = self.getElementHeight(optionItems, 'fillInBlank')
  5692. var scorePosition = self.getItemPosition($score)
  5693. var scoreWidth = self.getElementWidth($score)
  5694. var scoreHeight = self.getElementHeight($score)
  5695. var optionInfo = {
  5696. type: moduleInfo.type,
  5697. scorebox: {
  5698. type: 3,
  5699. Score: scoreStyle.split('/'),
  5700. x: scorePosition.x,
  5701. y: scorePosition.y,
  5702. width: scoreWidth,
  5703. height: scoreHeight
  5704. },
  5705. score: {
  5706. full: 5
  5707. },
  5708. column: column || 1,
  5709. scoreStyle: scoreStyle || '',
  5710. rowLinHeight: rowLineHeight || '',
  5711. id: $(optionItems).attr('title-number'),
  5712. cut: {
  5713. x: optionPosition.x,
  5714. y: optionPosition.y,
  5715. width: width,
  5716. height: height
  5717. }
  5718. }
  5719. optionInfos.push(optionInfo)
  5720. })
  5721. return optionInfos
  5722. },
  5723. //解答题坐标获取
  5724. getAswerPositions: function (moduleItem, moduleInfo) {
  5725. var self = this
  5726. var answerInfos = []
  5727. $(moduleItem)
  5728. .find('.module')
  5729. .each(function (m, moduleEl) {
  5730. var modulePositon = self.getItemPosition(moduleEl, 'answer')
  5731. var width = self.getElementWidth(moduleEl, 'answer')
  5732. var height = self.getElementHeight(moduleEl, 'answer')
  5733. var titleNumber = $(moduleEl).attr('title-number')
  5734. var scoreLimit = $(moduleEl).attr('scorelimit') || '16'
  5735. var fullScore = $(moduleEl).attr('data-fullscore') || '16'
  5736. //分值格式
  5737. var $scoreColumn = $(moduleEl).children('.scortColumn')
  5738. var isAddHalf = $(moduleEl).attr('isAddHalf') === 'true'
  5739. var scorePosition = self.getItemPosition($scoreColumn)
  5740. var scoreWidth = self.getElementWidth($scoreColumn, 'answer')
  5741. var scoreHeight = self.getElementHeight($scoreColumn, 'answer')
  5742. let noScoringWidth = $($scoreColumn).find('.no-scoring').width();
  5743. if (noScoringWidth != null) {
  5744. scoreWidth = scoreWidth - noScoringWidth
  5745. }
  5746. /**
  5747. * "scorebox":{
  5748. "type":1,
  5749. "Score":[2, 3,5]
  5750. limit:16
  5751. "x":1517.4015748031497,
  5752. "y":20,
  5753. "width":40,
  5754. "height":20,
  5755. }
  5756. point:1 表示最后一个是0.5分 0表示没有0.5
  5757. type 1: 16 limit:12 OR 14 OR 16
  5758. type 2: 29/49 limit: 29 49
  5759. type 3:具体分值在score里面给出枚举: 2 3 5 , 2 3 4 6 limit 无效
  5760. */
  5761. //判断当前区域是否有超出的链接模块
  5762. var linkParm = +$(moduleEl).attr('data-linkparm') || 0
  5763. var cutId = $(moduleEl).attr('data-cutId')
  5764. var editorId = $(moduleEl).attr('data-editorindex')
  5765. let TopicHtml = $(moduleEl).find('.w-e-text').html()
  5766. if(TopicHtml==undefined){
  5767. TopicHtml = $(moduleEl).find('.editorContent').html()
  5768. }
  5769. var answerInfo = {
  5770. type: moduleInfo.type,
  5771. id: titleNumber,
  5772. scoreLimit: scoreLimit,
  5773. editorId: editorId,
  5774. contents: encodeURIComponent(TopicHtml),
  5775. cut: {
  5776. x: modulePositon.x,
  5777. y: modulePositon.y,
  5778. width: width,
  5779. height: height,
  5780. cutid: cutId,
  5781. linkparm: linkParm
  5782. },
  5783. scorebox: {
  5784. type: ~'16|15'.indexOf(scoreLimit) ? '1' : '2',
  5785. limit: fullScore,
  5786. point: isAddHalf ? 1 : 2,
  5787. x: scorePosition.x,
  5788. y: scorePosition.y,
  5789. width: scoreWidth,
  5790. height: scoreHeight
  5791. }
  5792. }
  5793. answerInfos.push(answerInfo)
  5794. })
  5795. return answerInfos
  5796. },
  5797. //选做题坐标获取
  5798. getChooseAswerPositions: function (moduleItem, moduleInfo) {
  5799. var self = this
  5800. var chooseAnswerInfos = []
  5801. $(moduleItem)
  5802. .find('.module')
  5803. .each(function (n, moduleEl) {
  5804. var modulePositon = self.getItemPosition(moduleEl, 'chooseAnswer')
  5805. var width = self.getElementWidth(moduleEl, 'answer')
  5806. var height = self.getElementHeight(moduleEl, 'answer')
  5807. var titleNumber = $(moduleEl).attr('title-number')
  5808. var scoreLimit = $(moduleEl).attr('scorelimit') || '16'
  5809. var fullScore = $(moduleEl).attr('data-fullscore') || '16'
  5810. //分值格式
  5811. var $scoreColumn = $(moduleEl).children('.scortColumn')
  5812. var isAddHalf = $(moduleEl).attr('isAddHalf') === 'true'
  5813. var scorePosition = self.getItemPosition($scoreColumn)
  5814. var scoreWidth = self.getElementWidth($scoreColumn, 'answer')
  5815. var scoreHeight = self.getElementHeight($scoreColumn, 'answer')
  5816. let noScoringWidth = $($scoreColumn).find('.no-scoring').width();
  5817. if (noScoringWidth != null) {
  5818. scoreWidth = scoreWidth - noScoringWidth
  5819. }
  5820. //是否是上一题的补充区域
  5821. //判断当前区域是否有超出的链接模块
  5822. var linkParm = +$(moduleEl).attr('data-linkparm') || 0
  5823. var cutId = $(moduleEl).attr('data-cutId')
  5824. var editorId = $(moduleEl).attr('data-editorindex')
  5825. //选择题目数量
  5826. var selCount = 1
  5827. let TopicHtml = $(moduleEl).find('.editorContent').html()
  5828. for (var choosePage in self.chooseAnswer) {
  5829. var pageChooseAnswer = self.chooseAnswer[choosePage]
  5830. if (pageChooseAnswer.length) {
  5831. selCount = pageChooseAnswer[0].required
  5832. break
  5833. }
  5834. }
  5835. var chooseAnswerInfo = {
  5836. type: moduleInfo.type,
  5837. id: titleNumber,
  5838. scoreLimit: scoreLimit,
  5839. editorId: editorId,
  5840. select: selCount,
  5841. contents: encodeURIComponent(TopicHtml),
  5842. total: titleNumber.split(',').length,
  5843. scorebox: {
  5844. type: ~'15|16'.indexOf(scoreLimit) ? '1' : '2',
  5845. limit: fullScore,
  5846. point: isAddHalf ? 1 : 2,
  5847. x: scorePosition.x,
  5848. y: scorePosition.y,
  5849. width: scoreWidth,
  5850. height: scoreHeight
  5851. },
  5852. selectqts: [
  5853. {
  5854. cut: {
  5855. x: modulePositon.x,
  5856. y: modulePositon.y,
  5857. width: width,
  5858. height: height,
  5859. cutid: cutId,
  5860. linkparm: linkParm
  5861. },
  5862. opt: []
  5863. }
  5864. ]
  5865. }
  5866. $(moduleEl)
  5867. .find('.selTopic span')
  5868. .each(function (l, selItem) {
  5869. var optName = $(selItem).attr('data-titleNumber')
  5870. var selItemPosition = self.getItemPosition(selItem, 'selTopic')
  5871. var width = self.getElementWidth(selItem)
  5872. var height = self.getElementHeight(selItem)
  5873. chooseAnswerInfo.selectqts[0].opt.push({
  5874. optName: optName,
  5875. width: width,
  5876. height: height,
  5877. x: selItemPosition.x,
  5878. y: selItemPosition.y
  5879. })
  5880. })
  5881. chooseAnswerInfos.push(chooseAnswerInfo)
  5882. })
  5883. return chooseAnswerInfos
  5884. },
  5885. /**
  5886. *
  5887. * @param {想要定位的元素} el
  5888. * @param {打印区域靠左距离} printAreaLeft
  5889. * @param {打印区域靠右距离} printAreaTop
  5890. * @param {是不是富文本解答题} isModule
  5891. * 如果是分栏 偶数页面的X轴定位点都要 加一个固定分页的宽
  5892. */
  5893. getItemPosition: function (el, moduleType) {
  5894. var self = this
  5895. if (!$(el).length) return {}
  5896. var curPage = $(el).closest('.pageContent')
  5897. var curPageIndex = curPage.index() + 1
  5898. var positionY = $(el).offset().top - self.printAreaTop
  5899. var positionX = $(el).offset().left - self.printAreaLeft
  5900. //定位坐标向右偏移位置
  5901. var columnLeft = 0
  5902. //是否第一面
  5903. var isFirstPaper = curPageIndex <= self.columns
  5904. //考虑分栏的定位点
  5905. //当前在第几栏
  5906. var curPageColumns =
  5907. curPageIndex % self.columns ? curPageIndex % self.columns : self.columns
  5908. //一栏宽度
  5909. var oneColumnsWidth = self.pageWidth / self.columns
  5910. columnLeft = oneColumnsWidth * (curPageColumns - 1)
  5911. //选择题和填空题特殊误差处理
  5912. // if (~'select|fillInBlank|examNumber'.indexOf(moduleType)) {
  5913. // positionY += 3
  5914. // }
  5915. //有装订线的情况需要第一页减去多余的
  5916. if (self.hasBindingLine) {
  5917. positionX -= 20
  5918. }
  5919. if (curPageIndex > 1) {
  5920. positionY -= (curPageIndex - 1) * self.pageHeight
  5921. }
  5922. return {
  5923. x: (positionX + columnLeft - self.pagePaddingSide) * self.dpiRadio,
  5924. y: (positionY - 20) * self.dpiRadio
  5925. }
  5926. },
  5927. showUeditor:function (){
  5928. let self = this
  5929. // var ueEditor = null
  5930. // var topicEl = null
  5931. $('.printcontent').on('click','.editorContent',function (event){
  5932. event.stopPropagation();
  5933. if (!self.isCanEditCard) return
  5934. let _this = this;
  5935. let ueHeidht = $(this).height();
  5936. self.UEditorConfig.initialFrameHeight = Number(ueHeidht);
  5937. // let ueId = $(this).parents('.module').attr('title-number');
  5938. // let dataEditorindex = $(this).parents('.module').attr('data-editorindex');
  5939. // if(dataEditorindex!=undefined){
  5940. // ueId = ueId+'-'+dataEditorindex
  5941. // }
  5942. let modId = $(this).attr('id');
  5943. let ueId = modId.replace(/editorContent/i,"toolbar");
  5944. let domHtml = $(this).find('.w-e-text').html();
  5945. if(domHtml===undefined){
  5946. domHtml = $(this).html();
  5947. }
  5948. // $(_this).find('.w-e-text').html('');
  5949. // $(_this).html('<div class="w-e-text"></div>')
  5950. $(_this).html('')
  5951. if(ueEditor!==null &&ueEditor.key!==undefined &&ueEditor.key!==ueId){
  5952. let ueShow = $('#'+ueEditor.key).find('.edui-editor').css('display');
  5953. if(ueShow!='none'){
  5954. self.saveUeditor(ueEditor,topicEl)
  5955. }
  5956. }
  5957. topicEl = this;
  5958. oldModH = ueHeidht;
  5959. let top = $('#contentWrap').scrollTop();
  5960. ueEditor = UE.getEditor(ueId,self.UEditorConfig);
  5961. $('.edui-for-chineselattice div').hide();
  5962. $('#contentWrap').scrollTop(top);
  5963. ueEditor.ready(function() {
  5964. let html = ueEditor.getContent();
  5965. if(html.length<1){
  5966. ueEditor.setContent(domHtml);
  5967. } else {
  5968. ueEditor.setShow();
  5969. let isShow = $('#'+ueId).children('.edui-editor').css('display');
  5970. if(isShow=='none'){
  5971. $('#'+ueId).children('.edui-editor').css('display','block');
  5972. }
  5973. if(domHtml.length>0){
  5974. ueEditor.setContent(domHtml);
  5975. }
  5976. ueEditor.setHeight(ueHeidht);
  5977. }
  5978. $(_this).find('.w-e-text').html('');
  5979. $(_this).height('auto');
  5980. ueEditor.body.addEventListener('click', function (event) {
  5981. let target = event.target || event.srcElement;
  5982. let k = target.getAttribute('data-latex');
  5983. if (target.className.indexOf('mathType') !== -1 ) {
  5984. let text = target.src.substring(target.src.indexOf("?")+1);
  5985. editKityFormula(ueEditor,'chineselattice',text)
  5986. }
  5987. if(k==null){
  5988. return false
  5989. }
  5990. if(k.length>0){
  5991. editKityFormula(ueEditor,'chineselattice',k);
  5992. }
  5993. })
  5994. });
  5995. });
  5996. $('body').on('click',function (event){
  5997. if(ueEditor==null) return
  5998. if(ueEditor.key==undefined) return
  5999. let ueDisplay = $(ueEditor.container).css('display');
  6000. if(ueDisplay=='none') return
  6001. let isUe = $(event.toElement).parents('.edui-default');
  6002. if(isUe.length>0){
  6003. event.stopPropagation();
  6004. event.preventDefault();
  6005. return false
  6006. }
  6007. self.saveUeditor(ueEditor,topicEl)
  6008. })
  6009. },
  6010. saveUeditor:function (ueEditor,dom){
  6011. let _this = this;
  6012. let html = ueEditor.getContent();
  6013. html = html.replace(/\u200B/g,'')
  6014. // html = html.replace(/&nbsp;/g,'&ensp;')
  6015. if($(dom).find('.w-e-text').length>0){
  6016. $(dom).find('.w-e-text').html(html);
  6017. } else {
  6018. let isW = html.search('.w-e-text');
  6019. if(isW>-1){
  6020. $(dom).html(html);
  6021. } else {
  6022. let domHtml = '<div class = "w-e-text">'+ html +'<div>'
  6023. $(dom).html(domHtml);
  6024. }
  6025. }
  6026. // $(dom).find('.w-e-text').html(html);
  6027. // if(oldModH>10){
  6028. // $(dom).find('.w-e-text').find('img').css('max-height',oldModH)
  6029. // } else {
  6030. // $(dom).find('.w-e-text').find('img').css('height',14)
  6031. // }
  6032. let imgBoxHeight = JSON.parse(JSON.stringify(oldModH));
  6033. $(dom).find('.w-e-text').find('img').load(function (e) {
  6034. // let paperHeight = $(dom).parents('.pageContent').height()
  6035. let elItemHeight = $(this).height();
  6036. if(imgBoxHeight>10){
  6037. if(elItemHeight>(imgBoxHeight-10)){
  6038. $(this).height(imgBoxHeight-10)
  6039. }
  6040. }else {
  6041. $(this).height(14)
  6042. }
  6043. // _this.changePrintArea(curPageEl)
  6044. })
  6045. $(dom).css('height','auto');
  6046. let newH = $(dom).height();
  6047. if(newH<oldModH){
  6048. $(dom).css('height',oldModH);
  6049. }
  6050. // ueEditor.setHide();
  6051. // UE.getEditor('editor').destroy();
  6052. let ueBoxId = ueEditor.key
  6053. ueEditor.destroy();
  6054. $('#'+ueBoxId).remove();
  6055. $(dom).before('<script id='+ueBoxId+' type="text/plain" style="width:100%"></script>')
  6056. // <script id="toolbar{questionNum}" type="text/plain" style="width:100%"></script>
  6057. // ('<script id='+ueBoxId+' type="text/plain" style="width:100%"></script>').replaceAll('#'+ueBoxId);
  6058. // $('#'+ueBoxId).css('height',0)
  6059. ueEditor = null;
  6060. let curPageEl = $(dom).parents('.pageContent')
  6061. if(newH>oldModH){
  6062. this.changePrintArea(curPageEl)
  6063. }
  6064. }
  6065. }
  6066. $(function () {
  6067. Print.init(sizeConfig)
  6068. })