12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040 |
- var env = (function (defaultEnv) {
- var isProduction = ~location.href.indexOf('zhixinhuixue')
- var isLocal = ~location.href.indexOf('localhost') || ~location.href.indexOf('192.168')
- if (isLocal) return defaultEnv
- if (isProduction) return 'online'
- return 'testing'
- })('localxx')
- //环境配置
- var envConfig = envConfigs[env]
- //登陆态'/username/pc002/time/1567499908/sig/7d9ca3d40b7422b759ce9a7e08b2de20/sessionid/session_93482f6cf1c865b7a2e2793c66f2c595'
- var loginStatus = envConfig.loginStatus
- //当前环境域名'http://192.168.1.51/index.php'
- var domain = envConfig.domain + "/index.php"
- //当前环境转pdf所需css 相对路径
- var printCssPath = envConfig.printCssPath
- //当前环境转pdf所要请求的域
- var printPdfIp = envConfig.printPdfIp
- var editorIndexLi = 1
- var editorIndexUp = ''
- var isShowPreview = -1
- var isShowEdit = -1
- Print = {
- apis: {
- //获取答题卡信息
- getTopicsDetailAPi: domain + '/print/getPaperWithTopicsDetails' + loginStatus,
- //保存答题卡信息
- saveTopicsDetailsApi: domain + '/print/saveCardOnline' + loginStatus,
- //保存为pdf
- htmlToPdfApi: domain + '/print/htmlToPdf' + loginStatus,
- //上传图片===富文本编辑试题的时候需要
- uploadFileApi: domain + '/online/uploadFile' + loginStatus,
- //考试学生重置接口
- /**
- schoolId
- examGroupId
- 两个参数
- */
- resetExamStudentApi: domain + '/rest/answer_card_online/resetStudentStatus' + loginStatus,
- //下载pdf
- downPdfApi: domain + '/print/downOnlinePdf' + loginStatus,
- downOnlinePdfApi: domain + '/third/download' + loginStatus,
- getPdfApi: '//' + printPdfIp + '/getPdf',
- // getOnlinePdf
- getOnlinePdfApi: domain + '/third/getOnlinePdf' + loginStatus,
- delPdfApi: '//' + printPdfIp + '/delPdf',
- //直接下载node服务器上的pdf 模版
- //192.168.1.84:8001/download/
- downloadPdfUrl: '//' + printPdfIp + '/download/',
- batchGeneratePdfApi: '//' + printPdfIp + '/batchGeneratePdf',
- //latex 转 公式图片
- getMathtexApi: domain + '/print/ajaxGetMathtex' + loginStatus,
- //保存全学科试卷信息
- saveAllSubjectInfoApi: domain + '/third/createThirdOnline' + loginStatus,
- //保存为我的模版信息
- saveTemplateByOnlineApi: domain + '/third/saveTemplateByOnline' + loginStatus,
- //获取模版
- getTplListApi: domain + '/third/tplList' + loginStatus,
- //第三方创建答题卡的时候获取准考证配置信息
- getExamNumberConfigApi: domain + '/third/getCardStatusByGrade' + loginStatus
- },
- init: function (config) {
- this.modal = hgc_modal
- //是否第一次进入页面
- this.firstEnterPage = true
- //需要同时保存用来记忆布局的有:纸张规格,纸张方向,是否有装订线,考号配置(填涂考号or条形码,是否使用二维码)
- this.paper = 'A3'
- this.direction = 'horizontal'
- //装订线
- this.hasBindingLine = false
- //信息栏
- this.hasPaperMsg = true
- //考号配置
- this.examNumberConfig = {
- //条形码
- barCode: true,
- //准考证号
- ticketNumber: true
- }
- this.cardStatus = 0,
- //考号配置
- this.examInfoConfig = {
- //时间
- wpTimes: true,
- //满分
- fullScore: true,
- //命卷人
- wpAuthor: true,
- //审核人
- wpReviewer: true
- }
- this.examInfoConfigText = {
- //时间
- wpTimes: '',
- //满分
- fullScore: '',
- //命卷人
- wpAuthor: '',
- //审核人
- wpReviewer: ''
- }
- //是否使用二维码
- this.useQrCode = false
- this.config = simpleCopy(config[this.paper])
- this.configOrigin = simpleCopy(this.config)
- //分栏
- this.columns = 2
- //页面页码计算
- //当前分页
- this.currentPage = 1
- //总分页
- this.totalPage = 1
- //当前纸张-包括正反两面 ceil(totalPage/(column*2))
- this.currentPaper = 0
- //当前纸张正面1正面2 反面1 反面2
- this.currentPaperPage = 0
- //初始化页面数据
- /**
- * 核心功能模块盒模型设计
- */
- //解答区域--最小高度
- this.moduleMinHeight = 10
- //解答区域--默认高度
- this.moduleDefaultHeihgt = 54
- //解答区域--左右内边距之和
- this.modulePaddingSide = 20
- //解答区域--上内边距
- this.modulePaddingTop = 42
- //解答区域--下内边距
- this.modulePaddingBottom = 12
- this.modulePadding = this.modulePaddingTop + this.modulePaddingBottom
- //每个分页答题区域的--上下内边距
- this.pagePadding = 50
- //这个答题区域布局外边距
- this.layoutPadding = 20
- //每页的左右间距
- this.pagePaddingSide = 30
- //用于页面 mm 和 px 之间单位转换
- //96dpi 打印出来300dpi纸张上面的的比例
- this.dpiRadio = 1
- this.unitConversion = new UnitConversion()
- this.pageHeight = this.unitConversion.mmConversionPx(this.config.height)
- this.pageWidth = this.unitConversion.mmConversionPx(this.config.width)
- //富文本编辑 ==>> 全局富文本编辑构造函数
- this.EDITOR = window.wangEditor
- //富文本菜单配置文件
- this.EDITOR_CONFIG = [
- 'underline', // 下划线
- 'justify', // 对齐方式
- 'image', // 插入图片
- 'table', // 表格
- 'undo', // 撤销
- 'redo', // 重复
- 'lineheight',
- 'Hline',
- 'formula'
- ]
- this.EDITOR_CONFIG_ZW = [
- 'underline', // 下划线
- 'justify', // 对齐方式
- 'image', // 插入图片
- 'table', // 表格
- 'undo', // 撤销
- 'redo', // 重复
- 'lineheight',
- 'composition',
- 'Hline',
- 'formula'
- ]
- //题型配置 不定向选择 判断 作文 定位点c++
- this.questionTypeMapForPhp = {
- //0单选
- singleSelect: 0,
- //8多选
- moreSelect: 8,
- //填空
- fillInBlank: 3,
- //解答
- answer: 1,
- //选做
- chooseAnswer: 2,
- //必做题
- mustAnswer: 27,
- //不定项
- uncertainOption: 5
- }
- //类型 1 单选 2 多选 5 填空 7 解答 17 选做 11不定项 php
- this.questionTypeMapForC = {
- 1: 'singleSelect',
- 2: 'moreSelect',
- 11: 'uncertainOption',
- 5: 'fillInBlank',
- 7: 'shortAnswer',
- 27: 'mustAnswer',
- 17: 'chooseAnswer',
- '7c': 'composition'
- }
- //题型名称映射
- this.questionNameMap = {
- singleSelect: '单选题',
- moreSelect: '多选题',
- fillInBlank: '填空题',
- shortAnswer: '解答题',
- chooseAnswer: '选做题',
- uncertainOption: '不定项',
- mustAnswer: '必做题',
- composition: '作文'
- }
- //题型数据存储
- this.questionMap = []
- if (isNewBuild) {
- this.subjectId = subjectId
- } else {
- //全局groupId
- this.examGroupId = examGroupId || 0
- this.examIds = examIds
- this.schoolId = schoolId
- }
- //如果是创建考试,则唯一标识符 自定义,用来创建考试页面下载答题卡
- this.identifier = isNewBuild ? _symbolId() : self.examGroupId
- //当前区域定位信息,用来简单判断两次保存是否有改动,来防止重复提交数据
- this.saveLocationPosition = {}
- //首次保存
- this.alreadySave = false
- //当前答题卡模块是否在编辑状态--是否可以 编辑当前答题卡模板
- /**
- * 刚进页面
- * 1如果是之前没有保存,就属于编辑状态
- * 2如果之前有保存过,就属于保存在状态(页面所有操作按钮不可操作,需要点击编辑才可操作)
- * 页面中
- * 1如果点击了保存,就是保存状态
- */
- this.isCanEditCard = true
- //是否已经有打印的班级
- this.printClassStatus = false
- //题卡合一 的type值
- this.subjectCardToOneType = 1
- //是否需要题卡合一
- this.isSubjectInfoToCard = false
- //替换富文本没用内容
- this.replaceEditorRegexp = /(<p><br><\/p>)|(<div><br><\/div>)/g
- //所有打分框的分值上线标准
- this.answerScoreLimitKeyArr = [15, 16, 29, 49, 69]
- this.initDom()
- //初始化打印面积
- this.initPageStyle()
- //初始化页面渲染
- this.initPage()
- //解答题图片移动
- this.shortAnswerImgPositionChange()
- },
- tpls: PRINT_TPL,
- initPageStyle: function () {
- var self = this
- var $headEL = $('head')
- var $styleTag = $('#pageSizeStyle')
- self.pageHeight = self.unitConversion.mmConversionPx(self.config.height)
- self.pageWidth = self.unitConversion.mmConversionPx(self.config.width)
- if ($styleTag.length) $styleTag.remove()
- var initPrintPageStyle = self.tpls.printPageStyle.substitute({
- pageWidth: self.pageWidth / self.columns,
- pageHeight: self.pageHeight
- })
- $headEL.append(initPrintPageStyle)
- },
- /**
- * 初始化打印区域宽高 mm 转 px
- * 纸张方向,纸张大小,纸张分栏
- * 默认A3 两栏
- */
- initPrintContentArea: function () {
- var self = this
- self.initPageStyle()
- //列举属于小版面的配置,统一使用小版面的布局
- var isHorizontal = self.direction === 'horizontal'
- var isLayoutWhite = ~[
- 'A3-3',
- 'A4-2',
- 'A4-3',
- '8Ks-3',
- '8Kb-3',
- '16K-2',
- '16K-3'
- ].indexOf(self.paper + '-' + self.columns)
- var isSmallLayout = isHorizontal && isLayoutWhite
- self.$firstPageContent[isSmallLayout ? 'addClass' : 'removeClass'](
- 'smallLayout'
- )
- //判断第一页有没有题型模块,如果第一页没有题型模块,则直接跳到第二页做题型重排处理
- var hasSurplus = false
- var $secondPage = self.$firstPageContent.find('.examNumberLayout').next()
- var $secondPageFirstModule = $secondPage.find('.module').eq(0)
- var secondPageFirstModuleType = $secondPage
- .find('.answerModule')
- .eq(0)
- .attr('data-type')
- if (
- !$secondPage.length ||
- !$secondPageFirstModule.length ||
- !secondPageFirstModuleType
- ) {
- hasSurplus = true
- } else {
- var curpageSurplusHeight = self.getCurPageSurplusHeight(
- self.$firstPageContent
- )
- var nextPageFirstModuleHeight = self.getNextPageFirstModuleHeight(
- $secondPageFirstModule,
- secondPageFirstModuleType
- )
- hasSurplus = curpageSurplusHeight > nextPageFirstModuleHeight
- }
- self.changePrintArea(
- hasSurplus ? self.$firstPageContent : self.$firstPageContent.next()
- )
- self.editNoScoringWidth()
- },
- //render page
- initPage: function () {
- var self = this
- isShowPreview = window.location.href.indexOf('isPreview')
- isShowEdit = window.location.href.indexOf('isEdit')
- $('#hgc_print').height($(window).height())
- if (isNewBuild) {
- $('.switch_ewm').hide()
- self.initPageForNewBuild()
- } else {
- self.getTopicDetails()
- }
- if (isShowPreview > -1) {
- setTimeout(function () {
- self.previewPrintDiv('printcontent')
- }, 200)
- }
- if (isShowEdit > -1) {
- setTimeout(function () {
- self.isCanEditCard = false
- self.changeCardEditStatus()
- }, 200)
- }
- if(localStorage.examStatus && isShowEdit > -1){
- let examStatus = JSON.parse(localStorage.getItem('examStatus'));
- if(examStatus==2){
- $('#saveBtn').unbind();
- $('#saveBtn').addClass('disabled')
- }
- }
- },
- //创建答题卡部分-----------------------------------
- //get buildQuestions
- getBuildQuestions: function () {
- var self = this
- // 当前的数据包
- // var originQuestions = localStorage.getItem('buildQuestions')
- var localSavePrintInfo = localStorage.getItem('savePrintInfo')
- var localBuildQuestions = localSavePrintInfo ? JSON.parse(localSavePrintInfo) : {}
- var buildQuestions = localBuildQuestions.position ? self.reTopicNum(localBuildQuestions.position.buildQuestions) : {}
- // var buildQuestions = originQuestions ? JSON.parse(originQuestions) : {}
- if (isShowPreview > -1) {
- buildQuestions = JSON.parse(localStorage.getItem('previewBuildQuestions'))
- }
- if(localBuildQuestions.position){
- self.rePagesId(localBuildQuestions.position.pages)
- self.reQuestionInfoNum(localBuildQuestions.question_info.content)
- }
- self.questionMap = buildQuestions
- self.setBuildQuestions()
- return buildQuestions
- },
- reTopicNum: function(data){
- jQuery.each(data, function (i, bigTopicData){
- jQuery.each(bigTopicData.questions, function (i, minTopicData){
- minTopicData.questionNum = minTopicData.alias
- })
- jQuery.each(bigTopicData.pages, function (i, pages){
- jQuery.each(pages, function (i, pages){
- pages.questionNum = pages.alias
- })
- })
- })
- return data
- },
- rePagesId: function(data){
- jQuery.each(data, function (i, page){
- jQuery.each(page.questions, function (i, minTopicData){
- minTopicData.id = minTopicData.name
- })
- })
- },
- reQuestionInfoNum: function(data){
- jQuery.each(data, function (i, minTopicData){
- minTopicData.questionNum = minTopicData.alias
- })
- },
- setBuildQuestions: function () {
- localStorage.setItem('buildQuestions', JSON.stringify(this.questionMap))
- },
- //获取记忆配置信息
- getMemoryPosition: function () {
- var self = this
- var originPosition = JSON.parse(localStorage.getItem('position'))
- var savePrintInfoData = JSON.parse(localStorage.getItem('savePrintInfo'))
- savePrintInfoData = savePrintInfoData ? savePrintInfoData : {}
- originPosition = originPosition ? originPosition : savePrintInfoData.position
- var position = originPosition ? originPosition : {}
- return position
- },
- initPageForNewBuild: function () {
- var self = this
- localStorage.removeItem('position');
- localStorage.removeItem('buildQuestions');
- $('#addQustionBtn').show()
- self.getExamNumConfig()
- // 当前的数据包
- var buildQuestions = self.getBuildQuestions()
- if ($.isEmptyObject(buildQuestions)) {
- $('.addTips').show();
- } else {
- $('.addTips').hide();
- }
- /**
- * //如果是创建考试,则唯一标识符 自定义,用来创建考试页面下载答题卡
- var identifier = isNewBuild?_symbolId():self.examGroupId;
- */
- //先进行配置话记忆 --- 正常流式布局 --- 然后记忆布局
- var res = self.getMemoryPosition()
- // if (Object.keys(buildQuestions).length) {
- // //初始化内容区域,所有的pages 归1
- // self.renderSubjectInfo(
- // self.renderSubjectDataFormatForNewCard(buildQuestions)
- // )
- // //重新定义超出部分布局
- // self.changePrintArea(self.$firstPageContent)
- // }
- self.bindEvent()
- self.initEvent()
- if (Object.keys(res).length) {
- self.memoryLayout(res)
- }
- if (Object.keys(buildQuestions).length) {
- //初始化内容区域,所有的pages 归1
- self.renderSubjectInfo(
- self.renderSubjectDataFormatForNewCard(buildQuestions)
- )
- //重新定义超出部分布局
- self.changePrintArea(self.$firstPageContent)
- }
- if (Object.keys(res).length) {
- self.memoryLayout(res)
- }
- },
- reInitPageForNewBuild: function () {
- var self = this
- // $('#addQustionBtn').show()
- // self.getExamNumConfig()
- // 当前的数据包
- var buildQuestions = self.questionMap
- /**
- * //如果是创建考试,则唯一标识符 自定义,用来创建考试页面下载答题卡
- var identifier = isNewBuild?_symbolId():self.examGroupId;
- */
- // printcontent
- $('#printcontent').find('.pageContent').each(function (index) {
- if (index === 0) {
- $(this).find('.dtk-content').find('.answerModule').remove();
- } else {
- $(this).remove();
- }
- })
- self.totalPage = 1
- $(".pageContent .totalPage").html(self.totalPage)
- // 试题删除后 隐藏右边操作栏试题显示
- if ($('.answerModule').length > 0) {
- $('#subjectList').html(listHtml)
- } else {
- $('#subjectList').html('')
- }
- //先进行配置话记忆 --- 正常流式布局 --- 然后记忆布局
- var res = self.getMemoryPosition()
- if (Object.keys(buildQuestions).length) {
- //初始化内容区域,所有的pages 归1
- self.renderSubjectInfo(
- self.renderSubjectDataFormatForNewCard(buildQuestions)
- )
- //重新定义超出部分布局
- self.changePrintArea(self.$firstPageContent)
- }
- // self.bindEvent()
- // self.initEvent()
- if (Object.keys(res).length) {
- self.memoryLayout(res)
- }
- },
- getExamNumConfig: function () {
- var self = this
- $.post(
- self.apis.getExamNumberConfigApi, {
- grade: localStorage.getItem('grade')
- },
- function (res) {
- var result = JSON.parse(res)
- if (result.success === 1) {
- //初始化默认title
- var savePrintInfoData = JSON.parse(localStorage.getItem('savePrintInfo'))
- var testFormData = JSON.parse(localStorage.getItem('testFormData'))
- var paperName = ''
- self.cardStatus = result.data.card_status
- if (savePrintInfoData != null) {
- paperName = savePrintInfoData.title
- if (paperName == undefined) {
- paperName = testFormData ? testFormData.examName : ''
- }
- } else {
- paperName = testFormData ? testFormData.examName : ''
- }
- self.renderExamBaseInfo({
- school_card_length: +result.data.card_length,
- school_card_status: 1,
- paperName: paperName,
- wpTimes: 90,
- fullScore: '',
- wpAuthor: '',
- wpReviewer: '',
- })
- self.editNoticeDetail(self.useQrCode,result.data.card_status)
- }
- }
- )
- },
- editNoticeDetail: function (qrStatus,cardStatus) {
- let noticeDetailMsgBoxXT =
- '<p>1、考生务必正确书写班级、姓名,请填涂系统准考证号。</p>' +
- '<p>2、考生务必用2B铅笔填涂。</p>' +
- '<p>3、考生务必在答题卡指定位置作答,并保持卷面整洁。</p>' +
- '<p>4、如需要条形码,则考生务必要在指定位置正确贴好条形码。</p>' +
- '<p>5、教师务必使用红笔阅卷。</p>';
- let noticeDetailMsgBoxXX =
- '<p>1、考生务必正确书写班级、姓名,请填涂学校准考证号。</p>' +
- '<p>2、考生务必用2B铅笔填涂。</p>' +
- '<p>3、考生务必在答题卡指定位置作答,并保持卷面整洁。</p>' +
- '<p>4、如需要条形码,则考生务必要在指定位置正确贴好条形码。</p>' +
- '<p>5、教师务必使用红笔阅卷。</p>';
- let noticeDetailMsgBoxQR =
- '<p>1、考生务必用2B铅笔填涂。</p>' +
- '<p>2、考生务必在答题卡指定位置作答,并保持卷面整洁。</p>' +
- '<p>3、如需要条形码,则考生务必要在指定位置正确贴好条形码。</p>' +
- '<p>4、教师务必使用红笔阅卷。</p>';
- if(qrStatus){
- $('#noticeDetailMsgBox').html(noticeDetailMsgBoxQR)
- } else {
- $('#noticeDetailMsgBox').html(cardStatus==0 ? noticeDetailMsgBoxXT : noticeDetailMsgBoxXX)
- }
- },
- //创建答题卡部分-----------------------------------
- getTopicDetails: function () {
- var self = this
- //如果之前保存过,则需要记忆之前的答题卡排版
- $.post(
- self.apis.getTopicsDetailAPi, {
- examGroupId: self.examGroupId
- },
- function (res) {
- res = JSON.parse(res)
- if (res.success) {
- //判断是否已经保存过,如果已经保存过,需要记忆布局
- self.alreadySave = res.position ? true : false
- //判断是否题卡合一
- self.isSubjectInfoToCard =
- res.paperTplType == self.subjectCardToOneType
- if (self.alreadySave) {
- var memoryPosition = JSON.parse(res.position)
- self.saveLocationPosition = res.position
- self.memoryColumns = memoryPosition.columns
- self.isCanEditCard = false
- //是否已经有打印班级
- self.printClassStatus = res.printClassStatus
- self.initPrintContentArea()
- self.renderPage(res, memoryPosition)
- self.memoryLayout(memoryPosition)
- self.changeCardEditStatus()
- } else {
- self.isCanEditCard = true
- self.renderPage(res)
- self.changeCardEditStatus()
- }
- } else {
- hgc_layer.msg('获取试卷题目信息失败')
- }
- }
- )
- },
- /*
- --------------------------------------------------------------------------------------------------------------------
- 初始页面布局功能开始
- ---------------------------------------------------------------------------------------------------------------------
- */
- renderPage: function (renderJSON, memoryPosition) {
- var self = this
- memoryPosition = memoryPosition || null
- self.renderExamBaseInfo(renderJSON.object)
- //格式化题型题号信息 -- 可重复执行
- self.renderSubjectInfo(
- self.renderSubjectDataFormat(renderJSON.object.questions),
- memoryPosition
- )
- if (!self.alreadySave) {
- //重新定义超出部分布局
- self.changePrintArea(self.$firstPageContent)
- }
- self.bindEvent()
- self.initEvent()
- },
- //渲染答题卡基本信息 准考证号、名称、考试时间等
- renderExamBaseInfo: function (examInfo) {
- var self = this
- //答题卡题目类型
- self.$dtkName.val(examInfo.paperName)
- // var examInfoHtml = self.tpls.examInfoTpl.substitute(examInfo)
- // $('#examInfo').html(examInfoHtml)
- // self.examInfoConfigText.wpTimes = examInfo.wpTimes
- // self.examInfoConfigText.fullScore = examInfo.fullScore
- // self.examInfoConfigText.wpAuthor = examInfo.wpAuthor
- // self.examInfoConfigText.wpReviewer = examInfo.wpReviewer
- let examInfoConfigText = {
- wpTimes: examInfo.wpTimes,
- fullScore: examInfo.fullScore,
- wpAuthor: examInfo.wpAuthor,
- wpReviewer: examInfo.wpReviewer
- }
- self.examInfoConfigText = examInfoConfigText
- self.showExamInfoHtml()
- //准考证号信息
- self.renderExamNumberInfo(examInfo)
- },
- //准考证号信息
- renderExamNumberInfo: function (examInfo) {
- var self = this
- //准考证号类型 1学校准考证 0系统准考证
- self.school_card_status = examInfo.school_card_status
- //准考证号长度
- var school_card_length = examInfo.school_card_length
- var examNumberHtml = ''
- var examNumberForOnlyCodeHtml = ''
- for (var colIndex = 0; colIndex < school_card_length; colIndex++) {
- examNumberHtml += self.tpls.examNumberItemTpl
- examNumberForOnlyCodeHtml += '<span></span>'
- }
- $('#hgc_examNumber .ticketNumber').html(examNumberHtml)
- $('#hgc_examNumberForOnlyBarcode .ticketNumber p').html(
- examNumberForOnlyCodeHtml
- )
- },
- renderSubjectDataFormat: function (questions) {
- var self = this
- //大题分类
- var curGuid = ''
- var questionClassify = {}
- self.questionMap = questionClassify
- questions.forEach(function (question, index) {
- var curType = self.questionTypeMapForC[question.questionTypeId]
- var prevIndex = index - 1
- var prevQuestionTypeId = questions[prevIndex] ?
- questions[prevIndex].questionTypeId :
- ''
- var prevType = prevQuestionTypeId ?
- self.questionTypeMapForC[prevQuestionTypeId] :
- ''
- //如果之前的题型type和现在的题型type不一样,新建一个key做大题类型
- if (prevType !== curType) {
- curGuid = guid()
- questionClassify[curGuid] = {
- questions: [question]
- }
- } else {
- questionClassify[curGuid].questions.push(question)
- }
- })
- var titleTPls = {
- singleSelect: '、选择题<span>(本大题共{subjectCount}小题,{subjectPointText}共{totalPoint}分。在每小题给出的四个选项中,只有一项是符合题目要求的。把答案填涂在答题卡上。)</span>',
- moreSelect: '、多选题<span>(本大题共{subjectCount}小题,{subjectPointText}共{totalPoint}分。在每小题给出的四个选项中,有两项及以上是符合题目要求的。把答案填涂在答题卡上。)</span>',
- fillInBlank: '、填空题<span>(本大题共{subjectCount}小题,{subjectPointText}共{totalPoint}分。把答案填写在答题卡相应的题号后的横线上。)</span>',
- shortAnswer: '、解答题<span>(本大题共{subjectCount}小题,{subjectPointText}共{totalPoint}分。解答写出相应的文字说明、证明过程或演算步骤。)</span>',
- chooseAnswer: '、选做题<span>(本题包括{chooseOption}{chooseOptionLength}小题,请选定其中{chooseCount}小题,并在相应的答题区域内作答,请用2B铅笔涂黑(示例:■)。若多做,则按作答的前一小题评分。解答应写出文字说明、证明过程或演算步骤。)</span><div class="originSubjectInfo">{chooseSubjectContent}</div>',
- mustAnswer: '、必做题<span>(本大题共{subjectCount}小题,{subjectPointText}共{totalPoint}分。解答写出相应的文字说明、证明过程或演算步骤。)</span>'
- //一、选做题( 本题包括A、B两小题,请选定其中一小题,并在相应的答题区域内作答,请用2B铅笔涂黑(示例:■)。若多做,则按作答的前一小题评分。解答应写出文字说明、证明过程或演算步骤。)
- }
- var objectiveTitleTpl = {
- singleSelect: '、选择题题文',
- moreSelect: '、多选题题文',
- fillInBlank: '、填空题题文'
- }
- //填空题,选择题超出控制数据
- var numberIndex = 0
- for (var uid in questionClassify) {
- var questionClassifyItem = questionClassify[uid]
- //题型单个大题下面所有小题
- var questionClassifyItemQuestions = questionClassifyItem.questions
- var typeId = questionClassifyItem.questions[0].questionTypeId
- var type = self.questionTypeMapForC[typeId]
- questionClassifyItem.questionType = typeId
- numberIndex++
- var titleFormatData = {}
- var isChooseAnswer = type === 'chooseAnswer'
- var isMoreSelect = type === 'moreSelect'
- //选做题题干信息
- var chooseSubjectContent = ''
- //选做题标题特殊对待
- if (isChooseAnswer) {
- var chooseOptionLength = SectionToChinese(
- questionClassifyItemQuestions.length
- )
- var chooseOption = questionClassifyItemQuestions
- .map(function (questionItem, index) {
- chooseSubjectContent +=
- '<div class="questionItemBody"><b>' +
- questionItem.questionNum +
- '、</b>' +
- questionItem.queBody +
- '</div>'
- return String.fromCharCode(65 + index)
- }, [])
- .join(',')
- var chooseCount = SectionToChinese(
- questionClassifyItemQuestions[0].required
- )
- titleFormatData = {
- chooseOption: chooseOption,
- chooseCount: chooseCount === '二' ? '两' : chooseCount,
- chooseOptionLength: chooseOptionLength === '二' ? '两' : chooseOptionLength
- }
- } else {
- var subjectCount = questionClassifyItemQuestions.length
- var subjectPoint = questionClassifyItemQuestions[0].fullScore
- var totalPoint = 0
- var isSameScore = questionClassifyItemQuestions.every(function (item) {
- return item.fullScore === subjectPoint
- })
- var subjectPointText = ''
- if (isSameScore) {
- subjectPointText = '每小题{subjectPoint}分,'.substitute({
- subjectPoint: subjectPoint
- })
- totalPoint = subjectPoint * subjectCount
- } else {
- subjectPointText = questionClassifyItemQuestions.reduce(
- (total, cur) => {
- total += '第{questionNum}题{fullScore}分,'.substitute(cur)
- totalPoint += cur.fullScore
- return total
- },
- ''
- )
- }
- titleFormatData = {
- subjectCount: subjectCount,
- subjectPoint: subjectPoint,
- totalPoint: totalPoint,
- subjectPointText: subjectPointText
- }
- }
- //如果需要题卡合一的话
- //选做题的题干信息不可编辑
- if (self.isSubjectInfoToCard && isChooseAnswer) {
- titleFormatData.chooseSubjectContent =
- '<div class="originSubjectInfo">' + chooseSubjectContent + '</div>'
- }
- //试卷大题默认title 如果是接口传入,则使用接口传入的字段
- questionClassifyItem.bigTitle =
- SectionToChinese(numberIndex) +
- titleTPls[type].substitute(titleFormatData)
- //题干信息title---只针对客观题
- if (objectiveTitleTpl[type]) {
- questionClassifyItem.objectiveTitle =
- '<h3>' +
- SectionToChinese(numberIndex) +
- objectiveTitleTpl[type] +
- '</h3>'
- }
- questionClassifyItem.pages = {
- page1: simpleCopy(questionClassifyItemQuestions),
- page2: []
- }
- }
- return questionClassify
- },
- //所有的pages 数据归1
- renderSubjectDataFormatForNewCard: function (buildQuestions) {
- var self = this
- for (var modelId in buildQuestions) {
- var buildQuestionsItem = buildQuestions[modelId]
- var allPageData = []
- for (var page in buildQuestionsItem.pages) {
- allPageData = allPageData.concat(buildQuestionsItem.pages[page])
- }
- buildQuestionsItem.pages = {
- page1: allPageData,
- page2: []
- }
- }
- return buildQuestions
- },
- titleHtml: function (title) {
- var self = this
- return title ? self.tpls.moduleTitleTpl.substitute({
- title: title
- }) : ''
- },
- //渲染答题卡题目题型信息
- renderSubjectInfo: function (questionClassify, memoryPosition) {
- var self = this
- //渲染右侧操作栏 题目列表信息 -- 可重复执行
- self.renderSubjectListInfo(questionClassify)
- //保存题目定位点的时候 获取 题目数量 分数 等信息 -- 可重复执行
- self.getSaveSubjectInfo(questionClassify)
- //批量渲染所有题型模块
- if (!self.firstEnterPage) return
- var dtkContentEl = $('.dtk-content')
- for (var uid in questionClassify) {
- var questionClassifyItem = questionClassify[uid]
- var questionType = questionClassifyItem.questionType
- var subjectType = self.questionTypeMapForC[questionType]
- questionClassifyItem.modelId = uid
- if (subjectType === 'shortAnswer' && !isNewBuild) {
- //或者一开始进来就是题卡合一
- if (!self.alreadySave && self.isSubjectInfoToCard) {
- self.renderObjective()
- //有记忆的时候先渲染题卡合一,主要是缓存原题干信息内容
- } else if (
- memoryPosition &&
- memoryPosition.stemInfo &&
- memoryPosition.stemInfo.length
- ) {
- self.renderObjective()
- }
- }
- self[subjectType + 'Render'](questionClassifyItem, dtkContentEl)
- }
- },
- //右侧题目列表模块-布局
- renderSubjectListInfo: function (questionClassify) {
- var self = this
- var listItemTpl =
- '<div class="paper selOptions"><span class="name ">{name}</span><div class="content_wrap">{quantityList}</div></div>'
- var listItemNoTpl =
- '<div class="content s_num">{quantityStart}~{quantityEnd}</div>'
- var listItemNoXzTpl =
- '<div class="content s_num">{quantityStart}</div>'
- var listHtml = ''
- for (var uid in questionClassify) {
- let questions = questionClassify[uid].questions
- let configData = questionClassify[uid].commonFields
- if (!questions[0]) continue
- let listItemNoHtml = ''
- jQuery.each(configData.questionTypeArr, function (i, configItem) {
- let Start = configItem.startNo
- let End = configItem.endNo
- if (configData.questionType == 17) {
- listItemNoHtml += listItemNoXzTpl.substitute({
- quantityStart: Start
- })
- } else {
- listItemNoHtml += listItemNoTpl.substitute({
- quantityStart: Start,
- quantityEnd: End
- })
- }
- });
- let questionType = questionClassify[uid].questionType
- if (questionType == 7) {
- questionType = questionClassify[uid].markQuestionType
- }
- listHtml += listItemTpl.substitute({
- name: self.questionNameMap[self.questionTypeMapForC[questionType]],
- quantityList: listItemNoHtml
- })
- }
- $('#subjectList').html(listHtml)
- },
- /**
- —————————————————————————————————————————————————————————————————————————————————————————————————————————————————————
- 客观题题干内容渲染 开始 —————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————
- */
- renderObjective: function (cb) {
- var self = this
- questionClassify = self.questionMap
- self.originStemInfos = []
- //,'shortAnswer','chooseAnswer','mustAnswer'
- var quesTypeOrder = ['fillInBlank', 'moreSelect', 'singleSelect']
- function getDataFromSubjectType(subjectType) {
- var subjectData
- for (var uid in questionClassify) {
- var questionType = questionClassify[uid].questionType
- if (self.questionTypeMapForC[questionType] === subjectType) {
- subjectData = questionClassify[uid].pages
- break
- }
- }
- return subjectData
- }
- //判断第一次出现的分页
- var lastPageIndex
- var lastPageType
- quesTypeOrder.forEach(function (type) {
- if (lastPageType) return
- var subjectData = getDataFromSubjectType(type)
- if (subjectData) {
- var pageIndex = Object.keys(subjectData).length
- function getLastPageIndex() {
- var pageData = subjectData['page' + pageIndex]
- if (pageData && pageData.length) {
- lastPageIndex = pageIndex
- lastPageType = type
- } else {
- pageIndex--
- getLastPageIndex()
- }
- }
- getLastPageIndex()
- }
- })
- //找到最后一个分页处理
- var $afterPage = $('.pageContent').eq(lastPageIndex - 1)
- var $afterContent = $afterPage.children('.dtk-content')
- var $afterModule
- //根据type 来判断题干信息该放在哪个元素后面
- if (lastPageType === 'fillInBlank') {
- $afterModule = $afterContent.children('.completion-topic')
- } else if (lastPageType === 'moreSelect') {
- $afterModule = $afterContent.children('.moreSelect')
- } else if (lastPageType === 'singleSelect') {
- $afterModule = $afterContent.children('.single-select:last()')
- }
- quesTypeOrder.forEach(function (quesType) {
- //找到对应的模块,所有的主观题的题干信息
- var quesTypeData
- for (var modelId in questionClassify) {
- var questionClassItem = questionClassify[modelId]
- var typeId = questionClassItem.questionType
- var type = self.questionTypeMapForC[typeId]
- if (type === quesType) {
- quesTypeData = questionClassItem
- break
- }
- }
- if (quesTypeData.questions && quesTypeData.questions.length) {
- self[quesType + 'StemRender'](quesTypeData, $afterModule)
- }
- })
- //图片加载时间
- self.judegeImgsLoaded('.objectiveItem')
- cb && cb($afterPage)
- },
- //公式自带的行内样式转换mm
- changeUnitForFormulaPic: function (parent, type) {
- var self = this
- parent = parent || $('.answerModule')
- parent.find('img').each(function () {
- var oh = $(this).attr('height')
- var ow = $(this).attr('width')
- if (!/^\d+$/.test(oh) || !/^\d+$/.test(ow)) return
- var widthMatch = $(this)[0].outerHTML.match(/width="(\d{1,3})"/) || [0, 0]
- var heightMatch = $(this)[0].outerHTML.match(/height="(\d{1,3})"/) || [
- 0,
- 0
- ]
- var pxWidth = +widthMatch[1]
- var pxHeight = +heightMatch[1]
- if (!pxWidth && !pxHeight) return
- //给你图片最大宽度的阀值
- var isMaxWidth = pxWidth > 430
- var mmWidth = self.unitConversion.pxConversionMm(pxWidth) + 'mm'
- var mmHeight =
- type === 'origin' || !isMaxWidth
- ? self.unitConversion.pxConversionMm(pxHeight) + 'mm'
- : 'auto'
- var originStyle = $(this).attr('style') || ''
- $(this).attr(
- 'style',
- originStyle +
- ';width:' +
- mmWidth +
- ';height:' +
- mmHeight +
- ';max-width:100%;'
- )
- })
- },
- queBodyRegExp: /^<p([^<]*)>/,
- singleSelectStemRender: function (questionClassItem, $afterModule) {
- var self = this
- var htmls = questionClassItem.objectiveTitle
- var data = questionClassItem.questions
- var stemInfos = []
- data.forEach(function (item) {
- //一排排列几个
- //0一排一个 1一排4个 2一排两个',
- var columnNumber =
- typeof item.listType === 'number'
- ? !item.listType
- ? 1
- : item.listType === 1
- ? 4
- : 2
- : ''
- var columnClass = columnNumber ? 'column-' + columnNumber : ''
- var content = item.queBody.replace(
- self.queBodyRegExp,
- '<p' + RegExp.$1 + '><span>' + item.questionNum + '、</span>'
- )
- var optionsHtml =
- '<div class="optionObjectiveWrap clearfix ' + columnClass + '">'
- item.queOptions.forEach(function (option, index) {
- optionsHtml +=
- '<div class="optionItemObjective fl"><p>' +
- String.fromCharCode(65 + index) +
- '.</p>' +
- option.content +
- '</div>'
- })
- optionsHtml += '</div>'
- var stemItemHtml = self.tpls.objectiveItemTpl.substitute({
- content: content,
- options: optionsHtml
- })
- //如果是题卡合一并且是保存状态的时候 才会保存原题信息
- if (self.isSubjectInfoToCard) {
- stemInfos.push(encodeURIComponent(stemItemHtml))
- }
- htmls += stemItemHtml
- })
- self.originStemInfos = stemInfos.concat(self.originStemInfos)
- htmls = self.tpls.objectiveWrapTpl.substitute({
- editModule: htmls
- })
- $afterModule.after(htmls)
- },
- moreSelectStemRender: function (questionClassItem, $afterModule) {
- var self = this
- var htmls = questionClassItem.objectiveTitle
- var data = questionClassItem.questions
- var stemInfos = []
- data.forEach(function (item) {
- var columnNumber =
- typeof item.listType === 'number'
- ? !item.listType
- ? 1
- : item.listType === 1
- ? 4
- : 2
- : ''
- var columnClass = columnNumber ? 'column-' + columnNumber : ''
- var content = item.queBody.replace(
- self.queBodyRegExp,
- '<p' + RegExp.$1 + '><span>' + item.questionNum + '、</span>'
- )
- var optionsHtml =
- '<div class="optionObjectiveWrap clearfix ' + columnClass + '">'
- item.queOptions.forEach(function (option, index) {
- optionsHtml +=
- '<div class="optionItemObjective fl"><p>' +
- String.fromCharCode(65 + index) +
- '.</p>' +
- option.content +
- '</div>'
- })
- optionsHtml += '</div>'
- var stemItemHtml = self.tpls.objectiveItemTpl.substitute({
- content: content,
- options: optionsHtml
- })
- //如果是题卡合一并且是保存状态的时候 才会保存原题信息
- if (self.isSubjectInfoToCard) {
- stemInfos.push(encodeURIComponent(stemItemHtml))
- }
- htmls += stemItemHtml
- })
- self.originStemInfos = stemInfos.concat(self.originStemInfos)
- htmls = self.tpls.objectiveWrapTpl.substitute({
- editModule: htmls
- })
- $afterModule.after(htmls)
- },
- fillInBlankStemRender: function (questionClassItem, $afterModule) {
- var self = this
- var htmls = questionClassItem.objectiveTitle
- var data = questionClassItem.questions
- var stemInfos = []
- data.forEach(function (item) {
- var content = item.queBody.replace(
- self.queBodyRegExp,
- '<p' + RegExp.$1 + '><span>' + item.questionNum + '、</span>'
- )
- var stemItemHtml = self.tpls.objectiveItemTpl.substitute({
- content: content
- })
- //如果是题卡合一并且是保存状态的时候 才会保存原题信息
- if (self.isSubjectInfoToCard) {
- stemInfos.push(encodeURIComponent(stemItemHtml))
- }
- htmls += stemItemHtml
- })
- htmls = self.tpls.objectiveWrapTpl.substitute({
- editModule: htmls
- })
- self.originStemInfos = stemInfos.concat(self.originStemInfos)
- $afterModule.after(htmls)
- },
- /**
- * —————————————————————————————————————————————————————————————————————————————————————————————————————————————————————
- 主观题题干内容渲染 结束 —————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————
- */
- getSingleSelectHtml: function (datas, type) {
- var self = this
- //判断是否多选
- var isMoreSelect = type === 'more'
- var moreSelectClass = isMoreSelect ? 'more-option' : ''
- var singleSelectHtml = ''
- var singleColHtml = ''
- datas.forEach(function (singleItem, index) {
- var singleContent = ''
- for (var i = 0; i < singleItem.optionCount; i++) {
- var option = String.fromCharCode(65 + i)
- singleContent += '<span data-option="{option}">[<i>{option}</i>]</span>'.substitute(
- { option: option }
- )
- }
- singleColHtml += self.tpls.singleSelectOptionTpl.substitute({
- _index: ++index,
- singleContent: singleContent,
- questionNum: singleItem.questionNum,
- answer: singleItem.answer,
- alias: singleItem.alias
- })
- if (!(index % 5)) {
- singleSelectHtml +=
- '<ul class="single-option ' +
- moreSelectClass +
- ' clearfix">' +
- singleColHtml +
- '</ul>'
- singleColHtml = ''
- }
- })
- singleSelectHtml +=
- !datas.length % 5
- ? ''
- : '<ul class="single-option ' +
- moreSelectClass +
- ' clearfix">' +
- singleColHtml +
- '</ul>'
- return singleSelectHtml
- },
- /**
- * @param {多选 or 单选} title
- * @param {选择题布局方向} direction
- * @param {选择题内容} selectContent
- */
- getSelectRenderContent: function (data) {
- //selectContent, title, direction,hasTitle
- var self = this
- data.settingBtn =
- typeof data.settingBtn === 'boolean' ? data.settingBtn : true
- /**
- * vertical 竖向布局
- * horizontal 横向布局
- */
- var direction = data.direction || 'vertical'
- var hasTitle = typeof data.hasTitle === 'undefined' ? true : data.hasTitle
- var SingleSelectModuleHtml = self.tpls.selectTpl.substitute({
- title: hasTitle ? self.titleHtml(data.bigTitle) : '',
- direction: direction,
- moduleType: data.moduleType,
- selectContent: data.selectContent,
- modelId: data.modelId,
- settingBtn: data.settingBtn
- ? '<div class="settingBtn" data-type="{moduleType}"></div>'.substitute({
- moduleType: data.title
- })
- : ''
- })
- return SingleSelectModuleHtml
- },
- //单选题--布局
- // {
- // bigTitle:'',
- // question:[]
- // }
- getDirection: function (direction) {
- if (typeof direction === 'number') {
- return direction ? 'vertical' : 'horizontal'
- } else {
- return direction ? direction : 'vertical'
- }
- },
- singleSelectRender: function (questionModelData, appendEl, replaceEl) {
- var self = this
- var datas = questionModelData.questions
- var modelId = questionModelData.modelId
- var direction = self.getDirection(questionModelData.direction)
- var singleSelectHtml = self.getSingleSelectHtml(datas, 'single')
- //selectContent, title, direction,hasTitle
- var SingleSelectModuleHtml = self.getSelectRenderContent({
- selectContent: singleSelectHtml,
- moduleType: 'singleSelect',
- bigTitle: questionModelData.bigTitle,
- modelId: modelId,
- direction: direction
- })
- if (replaceEl) {
- replaceEl[0].outerHTML = SingleSelectModuleHtml
- var $settingBtn = self.getSettingBtn(modelId)
- self.selectStyleChange($settingBtn, direction)
- } else {
- appendEl.append(SingleSelectModuleHtml)
- }
- },
- //多选题--布局
- moreSelectRender: function (questionModelData, appendEl, replaceEl) {
- var self = this
- var datas = questionModelData.questions
- var modelId = questionModelData.modelId
- var direction = self.getDirection(questionModelData.direction)
- //获取选项html
- var singleSelectHtml = self.getSingleSelectHtml(datas, 'more')
- //获取整个选择题区域模块html
- //selectContent, title, direction,hasTitle
- var SingleSelectModuleHtml = self.getSelectRenderContent({
- selectContent: singleSelectHtml,
- moduleType: 'moreSelect',
- bigTitle: questionModelData.bigTitle,
- modelId: modelId,
- direction: direction
- })
- if (replaceEl) {
- replaceEl[0].outerHTML = SingleSelectModuleHtml
- var $settingBtn = self.getSettingBtn(modelId)
- self.selectStyleChange($settingBtn, direction)
- } else {
- appendEl.append(SingleSelectModuleHtml)
- }
- },
- //不定项--布局
- uncertainOptionRender: function (questionModelData, appendEl, replaceEl) {
- var self = this
- var datas = questionModelData.questions
- var modelId = questionModelData.modelId
- var direction = self.getDirection(questionModelData.direction)
- //获取选项html
- var singleSelectHtml = self.getSingleSelectHtml(datas, 'more')
- //获取整个选择题区域模块html
- //selectContent, title, direction,hasTitle
- var SingleSelectModuleHtml = self.getSelectRenderContent({
- selectContent: singleSelectHtml,
- moduleType: 'uncertainOption',
- bigTitle: questionModelData.bigTitle,
- modelId: modelId,
- direction: direction
- })
- if (replaceEl) {
- replaceEl[0].outerHTML = SingleSelectModuleHtml
- var $settingBtn = self.getSettingBtn(modelId)
- self.selectStyleChange($settingBtn, direction)
- } else {
- appendEl.append(SingleSelectModuleHtml)
- }
- },
- getFillInBlankHtml: function (datas) {
- var self = this
- var fillInBlankHtml = ''
- var getScoreHtml = function (scoreStyle) {
- if (!scoreStyle) return '<i></i>'
- return scoreStyle.split('/').reduce(function (total, score) {
- total += '<i>' + score + '</i>'
- return total
- }, '')
- }
- datas.forEach(function (fillInBlankItem) {
- fillInBlankItem.scoreStyle = fillInBlankItem.scoreStyle || ''
- fillInBlankItem.scoreHtml = getScoreHtml(fillInBlankItem.scoreStyle)
- fillInBlankHtml += self.tpls.fillInBlankItemTpl.substitute(
- fillInBlankItem
- )
- })
- return fillInBlankHtml
- },
- getFillInBlankRenderContent: function (
- fillInBlankHtml,
- title,
- scoreStyle,
- modelId,
- rowLineHeight,
- columns
- ) {
- var self = this
- title = title || ''
- var fillInBlankModuleHtml = self.tpls.fillInBlankTpl.substitute({
- fillInBlankContent: fillInBlankHtml,
- scoreStyle: scoreStyle,
- title: title,
- modelId: modelId,
- rowLineHeight,
- columns
- })
- return fillInBlankModuleHtml
- },
- //填空题--布局
- formatRenderDataForFillInBlank: function (datas, scoreStyle) {
- var renderData = JSON.parse(JSON.stringify(datas))
- return renderData.map(function (item) {
- item.scoreStyle = scoreStyle
- return item
- })
- },
- fillInBlankRender: function (questionModelData, appendEl, replaceEl) {
- var self = this
- var datas = questionModelData.questions
- var bigTitle = questionModelData.bigTitle
- var modelId = questionModelData.modelId
- var column = questionModelData.columns || 1
- var rowLinHeight = questionModelData.rowLineHeight || 40
- var scoreStyle = questionModelData.scoreStyle || ''
- var renderData = self.formatRenderDataForFillInBlank(datas, scoreStyle)
- var fillInBlankHtml = self.getFillInBlankHtml(renderData)
- var fillInBlankModuleHtml = self.getFillInBlankRenderContent(
- fillInBlankHtml,
- self.titleHtml(bigTitle),
- scoreStyle,
- modelId,
- rowLinHeight,
- column
- )
- if (replaceEl) {
- replaceEl[0].outerHTML = fillInBlankModuleHtml
- var $settingBtn = self.getSettingBtn(modelId)
- self.fillInBlankStyleChange($settingBtn, column, rowLinHeight, scoreStyle)
- } else {
- appendEl.append(fillInBlankModuleHtml)
- }
- },
- //重新渲染填空题
- reRenderFillInBlank: function (modelId) {
- var self = this
- var pageIndex = 1
- while (self.questionMap[modelId]['page' + pageIndex]) {
- var pageFillInBlank = self.questionMap[modelId]['page' + pageIndex]
- var scoreStyle = self.questionMap[modelId].scoreStyle || ''
- if (!pageFillInBlank.length) {
- pageIndex++
- continue
- }
- var $curPage = $('#printcontent .pageContent').eq(pageIndex - 1)
- var $pageFillInBlank = null
- $curPage.find('.completion-topic').each(function () {
- var findModelId = $(this).attr('data-modelId')
- if (modelId === findModelId) {
- $pageFillInBlank = $(this).find('.subjectCol')
- }
- })
- $pageFillInBlank
- .attr('data-scorestyle', scoreStyle)
- .html(self.getFillInBlankHtml(pageFillInBlank))
- pageIndex++
- }
- },
- //解答题获取最小可选分值
- getAnswerMinScoreLimit: function (limit) {
- var self = this
- var minLimit = 16
- for (var i = 0, item; (item = self.answerScoreLimitKeyArr[i++]);) {
- if (item >= limit) {
- minLimit = item
- break
- }
- }
- return minLimit
- },
- //解答题--布局
- shortAnswerRender: function (questionModelData, appendEl, replaceEl) {
- var self = this
- var shortAnswerTpl = self.tpls.shortAnswerItemTpl
- var shortAnswerHtml = ''
- var datas = questionModelData.questions
- datas.forEach(function (shortAnswerItem) {
- shortAnswerItem.editorContentHeight = shortAnswerItem.editorContentHeight
- ? shortAnswerItem.editorContentHeight
- : self.moduleDefaultHeihgt
- //scorelimitkey 15 16 29 49 isHalf 是否有半分的概念
- var minLimit = self.getAnswerMinScoreLimit(shortAnswerItem.fullScore)
- if (Number(shortAnswerItem.fullScore) < questionModelData.dialogData.scoreLimit) {
- minLimit = questionModelData.dialogData.scoreLimit
- }
- shortAnswerItem.scoreColumnHtml = self.generateScoreBox(minLimit, questionModelData.isAddHalf, shortAnswerItem.fullScore)
- shortAnswerItem.scoreLimit = minLimit
- shortAnswerHtml += shortAnswerTpl.substitute(shortAnswerItem)
- //保存原题信息
- self.editorAreaOriginContent[shortAnswerItem.questionNum] =
- shortAnswerItem.queBody || ''
- })
- var shortAnswerModuleHtml = self.tpls.shortAnswerTpl.substitute({
- shortAnswerContent: shortAnswerHtml,
- title: questionModelData.bigTitle,
- modelId: questionModelData.modelId
- })
- if (replaceEl) {
- replaceEl[0].outerHTML = shortAnswerModuleHtml
- } else {
- appendEl.append(shortAnswerModuleHtml)
- }
- //初始化解答题富文本插件
- datas.forEach(function (item) {
- var questionNum = item.questionNum
- var answerContent = ''
- let topicType = item.questionTypeId
- if (topicType == 7) {
- topicType = item.markQuestionType
- }
- //题卡合一渲染原题信息
- if (!self.alreadySave && self.isSubjectInfoToCard) {
- answerContent = self.editorAreaOriginContent[questionNum]
- }
- // self.createShortAnswer(questionNum, answerContent)
- self.createShortAnswer(item.topicEditorIndex, answerContent, topicType)
- })
- },
- //选做题--布局
- chooseAnswerRender: function (questionModelData, appendEl, replaceEl) {
- var self = this
- var chooseAnswerTpl = self.tpls.chooseAnswerItemTpl
- var editorCreateIds = []
- var datas = questionModelData.questions
- var bigTigle = questionModelData.bigTitle
- var modelId = questionModelData.modelId
- //m 选 n 的n
- var requiredCount = datas[0].required || 1
- var chooseAnswerHtml = ''
- //外显题号
- var questionNumShow = 0
- for (var i = 0; i < requiredCount; i++) {
- var selOptionHtml = ''
- var startChooseNumber = 0
- var titleNumber = ''
- var fullScore = 16
- datas.forEach(function (item, index) {
- if (index === i) {
- if (!questionNumShow)
- questionNumShow = item.topicNo
- // item.questionNum + '~' + (+item.questionNum + datas.length - 1)
- startChooseNumber = item.questionNum
- editorCreateIds.push(item.questionNum)
- self.editorAreaOriginContent[item.questionNum] = item.queBody || ''
- fullScore = item.fullScore
- }
- // titleNumber += item.questionNum + ','
- titleNumber = item.topicNo
- selOptionHtml += '<span data-titleNumber="{titleNumber}" data-option="[{char}]">[{char}]</span>'.substitute(
- {
- char: String.fromCharCode(65 + index),
- titleNumber: item.questionNum
- }
- )
- })
- var minLimit = self.getAnswerMinScoreLimit(fullScore)
- if (Number(datas[0].fullScore) < questionModelData.dialogData.scoreLimit) {
- minLimit = questionModelData.dialogData.scoreLimit
- }
- var scoreColumnHtml = self.generateScoreBox(minLimit, questionModelData.isAddHalf, datas[0].fullScore)
- chooseAnswerHtml += chooseAnswerTpl.substitute({
- questionNum: startChooseNumber,
- questionNumShow: questionNumShow,
- //4,5,6,
- // titleNumber: titleNumber.substring(0, titleNumber.length - 1),
- titleNumber: titleNumber,
- selOptionHtml: selOptionHtml,
- scoreColumnHtml: scoreColumnHtml,
- editorContentHeight: self.moduleDefaultHeihgt,
- scoreLimit: minLimit,
- fullScore:datas[0].fullScore
- })
- }
- //先渲染多选题
- //选做题题干信息单独处理
- var chooseAddTitle = ''
- var hasObjective = self.chooseAnswerObjective && !self.alreadySave
- if (hasObjective) {
- chooseAddTitle = self.chooseAnswerObjective
- }
- var chooseAnswerModuleHtml = self.tpls.chooseAnswerTpl.substitute({
- chooseAnswerContent: chooseAnswerHtml,
- title: bigTigle,
- modelId: modelId
- })
- if (replaceEl) {
- replaceEl[0].outerHTML = chooseAnswerModuleHtml
- } else {
- appendEl.append(chooseAnswerModuleHtml)
- }
- //如果有题干信息
- if (hasObjective) {
- self.judegeImgsLoaded(
- '.answerModule[data-type="chooseAnswer"] .originSubjectInfo'
- )
- }
- editorCreateIds.forEach(function (editorId) {
- self.createShortAnswer(editorId)
- })
- },
- //必做题--布局
- mustAnswerRender: function (datas, appendEl, replaceEl) {
- var self = this
- var shortAnswerTpl = self.tpls.shortAnswerItemTpl
- var shortAnswerHtml = ''
- datas.forEach(function (shortAnswerItem) {
- shortAnswerItem.editorContentHeight = shortAnswerItem.editorContentHeight
- ? shortAnswerItem.editorContentHeight
- : self.moduleDefaultHeihgt
- var minLimit = self.getAnswerMinScoreLimit(shortAnswerItem.fullScore)
- shortAnswerItem.scoreColumnHtml = self.generateScoreBox(minLimit, false)
- shortAnswerItem.scoreLimit = minLimit
- shortAnswerHtml += shortAnswerTpl.substitute(shortAnswerItem)
- //保存原题信息
- self.editorAreaOriginContent[shortAnswerItem.questionNum] =
- shortAnswerItem.queBody || ''
- })
- var shortAnswerModuleHtml = self.tpls.shortAnswerTpl.substitute({
- shortAnswerContent: shortAnswerHtml,
- title: questionModelData.bigTigle,
- modelId: questionModelData.modelId
- })
- if (replaceEl) {
- replaceEl[0].outerHTML = shortAnswerModuleHtml
- } else {
- appendEl.append(shortAnswerModuleHtml)
- }
- //初始化解答题富文本插件
- datas.forEach(function (item) {
- var questionNum = item.questionNum
- var answerContent = ''
- if (!self.alreadySave && self.isSubjectInfoToCard) {
- answerContent = self.editorAreaOriginContent[questionNum]
- }
- self.createShortAnswer(questionNum, answerContent)
- })
- },
- /*--------------------------------------------------------------------------------------------------------------------
- 初始页面布局功能结束
- -----------------------------------------------------------------------------------------------------------------------*/
- /*--------------------------------------------------------------------------------------------------------------------------------
- 记忆布局功能开始
- ------------------------------------------------------------------------------------------------------------------------------------*/
- memoryLayout: function (res) {
- var self = this
- var formatData = self.memoryDataFormat(res)
- var shortAnswerData = formatData.shortAnswerData
- // 先控制是否有装订线,纸张大小,方向,分栏,装订线考号
- //{paper,direction,hasBindingLine,examNumberConfig:{barCode,ticketNumber},useQrCode}
- self.memoryHasBindLine(res.hasBindingLine)
- self.memoryPaperDirectColumn(res.paper, res.direction, res.columns)
- //记忆布局--考号配置
- self.memoryExamNumberConfig(res.examNumberConfig, res.useQrCode)
- // 信息栏
- self.memoryHasPaperMsgConfig(res)
- //如果不是创建答题卡
- if (!isNewBuild) {
- //记忆布局--选择题选项排列方向设置
- var singleSelectData = formatData.singleSelectData
- var moreSelectData = formatData.moreSelectData
- var fillInBlankData = formatData.fillInBlankData
- if (singleSelectData.length) {
- self.memorySelectData(singleSelectData[0].direction, 'singleSelect')
- }
- if (moreSelectData.length) {
- self.memorySelectData(moreSelectData[0].direction, 'moreSelect')
- }
- if (fillInBlankData.length) {
- self.memoryFillInBlank(fillInBlankData)
- }
- if (res.stemInfo && res.stemInfo.length) {
- self.memoryObjective(res.stemInfo, res.chooseAnswerStemInfo)
- }
- }
- //然后再布局
- self.memoryShortAnswer(shortAnswerData)
- },
- //把每一题的数据整合到一起
- memoryDataFormat: function (res) {
- var self = this
- //选择题可以设置选项排列方向
- var singleSelectData = []
- var moreSelectData = []
- //填空题可以设置每行列数、分值格式等
- var fillInBlankData = []
- var shortAnswerData = []
- var linkQuestionData = {}
- res.pages.forEach(function (pageData, index) {
- for (
- var i = 0, questionItem;
- (questionItem = pageData.questions[i++]);
- ) {
- var questionType = questionItem.type
- switch (questionType) {
- //选择题
- case self.questionTypeMapForPhp.singleSelect:
- singleSelectData.push(questionItem)
- break
- case self.questionTypeMapForPhp.moreSelect:
- moreSelectData.push(questionItem)
- break
- //填空题
- case self.questionTypeMapForPhp.fillInBlank:
- fillInBlankData.push(questionItem)
- break
- //解答题 or 选做题
- case self.questionTypeMapForPhp.answer:
- case self.questionTypeMapForPhp.chooseAnswer:
- case self.questionTypeMapForPhp.mustAnswer:
- //非多选题
- var isShortAnswer = questionType === 1
- var linkParm = isShortAnswer
- ? questionItem.cut.linkparm
- : questionItem.selectqts[0].cut.linkparm
- //linkParm > 0 补充模块 如果存在补充模块 , 则先合并
- if (linkParm) {
- //第一个补充模块
- if (linkParm === 1) {
- if (JSON.stringify(linkQuestionData) !== '{}') {
- shortAnswerData.push(linkQuestionData)
- linkQuestionData = {}
- }
- linkQuestionData = questionItem
- } else {
- //后面几个补充模块
- if (isShortAnswer) {
- linkQuestionData.cut.height += questionItem.cut.height
- } else {
- linkQuestionData.selectqts[0].cut.height +=
- questionItem.selectqts[0].cut.height
- }
- linkQuestionData.contents += questionItem.contents
- }
- if (
- ((res.pages[index + 1] &&
- !res.pages[index + 1].questions.length) ||
- index + 1 === res.pages.length) &&
- !pageData.questions[i + 1]
- ) {
- shortAnswerData.push(linkQuestionData)
- }
- } else {
- if (JSON.stringify(linkQuestionData) !== '{}') {
- shortAnswerData.push(linkQuestionData)
- linkQuestionData = {}
- }
- shortAnswerData.push(questionItem)
- }
- break
- }
- }
- })
- return {
- shortAnswerData: shortAnswerData,
- fillInBlankData: fillInBlankData,
- singleSelectData: singleSelectData,
- moreSelectData: moreSelectData
- }
- },
- memoryHasBindLine: function (hasBindingLine) {
- if (hasBindingLine) {
- $('#hasBindingLine .h_radioItem').eq(0).trigger('click')
- }
- },
- //基本布局 纸张规格方向分栏
- memoryPaperDirectColumn: function (paper, direction, column) {
- var self = this
- $('#paperOptions .h_radioItem').each(function () {
- if ($(this).attr('data-paper') === paper) {
- $(this).trigger('click')
- }
- })
- $('#paperDirection .h_radioItem').each(function () {
- if ($(this).attr('data-direction') === direction) {
- $(this).trigger('click')
- }
- })
- $('.layoutList .layoutItem').each(function () {
- //column type:number
- if ($(this).attr('data-column') == column) {
- $(this).trigger('click')
- }
- })
- },
- //记忆布局--考号配置
- memoryExamNumberConfig: function (examNumberConfig, useQrCode) {
- var self = this
- $('#examNumberConfig .h_checkItem').each(function () {
- var configName = $(this).attr('data-value')
- var isChecked = $(this).hasClass('checked')
- if (examNumberConfig[configName]) {
- if (!isChecked) $(this).trigger('click')
- } else {
- if (isChecked) $(this).trigger('click')
- }
- })
- //是否使用二维码
- var useQrCodeStatus = $('#useQrCode').hasClass('open')
- if (useQrCode) {
- if (!useQrCodeStatus) {
- $('#useQrCode').trigger('click')
- }
- } else {
- if (useQrCodeStatus) {
- $('#useQrCode').trigger('click')
- }
- }
- },
- //记忆布局--信息栏
- memoryHasPaperMsgConfig: function (hasPaperMsgConfig) {
- var self = this
- // $('#hasPaperMsg .h_checkItem').each(function () {
- // var configName = $(this).attr('data-value')
- // var isChecked = $(this).hasClass('checked')
- // if (hasPaperMsgConfig[hasPaperMsg]) {
- // if (!isChecked) $(this).trigger('click')
- // } else {
- // if (isChecked) $(this).trigger('click')
- // }
- // })
- self.examInfoConfigText=hasPaperMsgConfig.examInfoConfigText;
- self.examInfoConfig=hasPaperMsgConfig.examInfoConfig;
- self.hasPaperMsg=hasPaperMsgConfig.hasPaperMsg;
- self.isShowPaperMsg();
-
- },
- memorySelectData: function (direction, type) {
- var self = this
- var $this = $('.' + type)
- .eq(0)
- .find('.settingBtn')
- self.selectStyleChange($this, direction)
- },
- memoryFillInBlank: function (fillInBlankData) {
- var self = this
- var questionItem = fillInBlankData[0]
- var modelId = questionItem.modelId
- //当前答题卡只有一大填空题大题的情况下
- var $this = null
- var column = questionItem.column || 1
- var rowLinHeight = questionItem.rowLinHeight || 40
- var scoreStyle = questionItem.scoreStyle || ''
- $('.completion-topic').each(function () {
- if ($(this).attr('data-modelId') === modelId) {
- $this = $(this)
- return false
- }
- })
- self.fillInBlankStyleChange($this, column, rowLinHeight, scoreStyle)
- },
- /**
- *
- * ajax 异步图片加载完成
- * srcList
- * _img = new Image()
- * _img.src = srcList[i]
- */
- judegeImgsLoaded: function (imgBoxSelector, cb) {
- var imgList = []
- var $imgBox = $(imgBoxSelector)
- $imgBox.find('img').each(function () {
- var imge = $(this)
- var styles = imge.attr('style')
- if (styles) {
- styles = styles.replace(/height:auto;/g, '')
- imge.attr('style', styles)
- }
- imgList.push($(this).attr('src'))
- })
- if (!imgList.length) return
- var self = this
- var i = 0
- var imgLen = imgList.length
- function imgLoad() {
- var _img = new Image()
- _img.src = imgList[i]
- _img.onload = function () {
- i++
- if (i >= imgLen) {
- self.changeUnitForFormulaPic($(imgBoxSelector))
- cb && cb()
- } else {
- imgLoad()
- }
- }
- _img.onerror = function () {
- i++
- if (i >= imgLen) {
- self.changeUnitForFormulaPic($(imgBoxSelector))
- cb && cb()
- } else {
- imgLoad()
- }
- }
- }
- imgLoad()
- },
- memoryObjective: function (stemInfo, chooseAnswerStemInfo) {
- var self = this
- stemInfo = typeof stemInfo === 'object' ? stemInfo : stemInfo.split('|end|')
- var isBase64Save = isBase64(stemInfo[0])
- var imgList = []
- $('.objectiveItem').each(function (index) {
- var replaceStr = ''
- if (isBase64Save) {
- replaceStr = decode(stemInfo[index]);
- } else {
- replaceStr = decodeURIComponent(stemInfo[index]);
- }
- $(this)[0].outerHTML = replaceStr
- })
- //选做题单独处理
- if (chooseAnswerStemInfo) {
- var $chooseAnswer = $('.answerModule[data-type="chooseAnswer"]')
- var $chooseAnswerObjective = $chooseAnswer.find('.originSubjectInfo')
- var memoryObjectiveHtml = decodeURIComponent(chooseAnswerStemInfo)
- var delHMemory = memoryObjectiveHtml.replace(/height:auto;/g, '')
- if ($chooseAnswerObjective.length) {
- $chooseAnswerObjective[0].outerHTML = delHMemory
- } else {
- $chooseAnswer.eq(0).children('h3').append(delHMemory)
- }
- //重置图片高度
- self.judegeImgsLoaded(
- '.answerModule[data-type="chooseAnswer"] .originSubjectInfo'
- )
- }
- },
- memoryShortAnswer: function (shortAnswerData) {
- var self = this
- //2 解答题区域高度修改
- //shortAnswerData 所有解答题的区域信息
- //多选题特殊处理
- var checkQuestionData = {}
- var checkmoduleEl = {}
- for (var i = 0, questionItem; i < shortAnswerData.length; i++) {
- var questionItem = shortAnswerData[i]
- var moduleHeight = questionItem.cut
- ? questionItem.cut.height
- : questionItem.selectqts[0].cut.height
- var scoreLimitKey = questionItem.scoreLimit
- var isAddHalf = questionItem.isAddHalf
- $('#printcontent .pageContent .short-answer .module').each(function (
- pageIndex,
- moduleItem
- ) {
- var $pageItem = $(moduleItem).closest('.pageContent')
- var $moduleItem = $(moduleItem)
- var isOverPage = false
- var titleNumber = Number($moduleItem.attr('title-number'))
- var dataEditorIndex = $moduleItem.attr('data-editorindex')
- if (self.isSurplusModule($moduleItem)) return
- //该题已经布局就无需重复布局--针对选择题
- if (
- titleNumber === Number(questionItem.name) &&
- !checkQuestionData[questionItem.editorId] &&
- !checkQuestionData[dataEditorIndex]
- ) {
- checkQuestionData[questionItem.editorId] = true
- checkQuestionData[dataEditorIndex] = true
- //同步之前设置的内容
- if (questionItem.contents) {
- // var editorId = questionItem.id
- var editorId = dataEditorIndex
- self.editorArea['editor' + editorId].txt.html(
- decodeURIComponent(questionItem.contents)
- )
- }
- var $this = $moduleItem.children('.settingBtn')
- let isAddHalf = questionItem.scorebox.point==1 ? true: false;
- self.shortAnswerStyleChange($this, scoreLimitKey, isAddHalf, questionItem.scorebox.limit)
- //设置大题区域高度
- $moduleItem
- .children('.editorContent')
- .height(moduleHeight - self.modulePadding)
- // $moduleItem
- // .children('.editorContent')
- // .css('min-height',moduleHeight - self.modulePadding)
- curPageEl = $pageItem
- //如果当前有page分栏页有超出 则直接调到下一个分页
- isOverPage = self.getOverModule(curPageEl)
- self.changePrintArea(curPageEl)
- }
- if (isOverPage) return false
- // if (isOverPage) {
- // isOverPage = false
- // }
- })
- }
- },
- /*--------------------------------------------------------------------------------------------------------------------------------
- 记忆布局功能结束
- ------------------------------------------------------------------------------------------------------------------------------------*/
- /**
- * --------------------------------------------------------------------------------------------------------------------------------
- 还原原题题干信息开始
- --------------------------------------------------------------------------------------------------------------------------------
- */
- restoreObjectiveInfo: function (data) {
- var self = this
- var clearStatus = data.clearStatus
- if (clearStatus) {
- var $pageContent
- $('.answerModule').each(function () {
- if ($(this).attr('data-type') === 'objective') {
- if (!$pageContent) {
- $pageContent = $(this).closest('.pageContent')
- }
- $(this).remove()
- }
- })
- self.changePrintArea($pageContent)
- return
- }
- $('.objectiveItem').each(function (index) {
- $(this)[0].outerHTML = decodeURIComponent(self.originStemInfos[index])
- })
- //图片加载时间
- self.judegeImgsLoaded('.objectiveItem')
- },
- restoreAnswerInfo: function (data) {
- var self = this
- var clearStatus = data.clearStatus
- /**
- * 清空之前所有的内容
- * 包括清空统一题的本体模块和补充模块
- * 然后用新内容放在本体模块里面
- */
- var overPageEl = []
- //第一次出现
- var firstChooseAnswer = true
- $('.short-answer').each(function () {
- var $shortAnswer = $(this)
- var $modules = $(this).find('.module')
- if ($shortAnswer.attr('data-type') === 'chooseAnswer') {
- if (!firstChooseAnswer) {
- $shortAnswer.find('h3').remove()
- return
- }
- firstChooseAnswer = false
- var chooseObjectiveEl = $shortAnswer.find('.originSubjectInfo')
- if (chooseObjectiveEl.length) {
- if (clearStatus) {
- chooseObjectiveEl.remove()
- } else {
- chooseObjectiveEl[0].outerHTML = self.chooseAnswerObjective
- }
- } else {
- $shortAnswer.find('h3').append(self.chooseAnswerObjective)
- }
- var overHeight = self.getOverHeight($shortAnswer)
- if (overHeight > 0) {
- overPageEl.push($shortAnswer.closest('.pageContent'))
- }
- return
- }
- $modules.each(function () {
- var $module = $(this)
- var questionNum = $(this).attr('title-number')
- var editorIndex = $(this).attr('data-editorIndex')
- var $moduleEditorContent = $(this).find('.w-e-text')
- var $moduleContentWrap = $(this).find('.w-e-text-container')
- //如果是补充模块直接清空内容
- if (self.isSurplusModule($(this))) {
- $moduleEditorContent.html('')
- } else {
- var flexibleIconHtml =
- '<div class="flexible_icon"><i class="resize_nwse"></i></div>'
- var questionNumHtml =
- '<div class="editorQuestionNum">' + questionNum + '、</div>'
- var baseContent = questionNumHtml + flexibleIconHtml
- $moduleEditorContent.html(
- baseContent +
- (clearStatus ? '' : self.editorAreaOriginContent[questionNum])
- )
- var minHeight = self.calcEditorContentHeight($moduleEditorContent)
- if ($moduleContentWrap.height() < minHeight) {
- $moduleContentWrap.height(minHeight)
- }
- var overHeight = self.getOverHeight($module)
- if (overHeight > 0) {
- overPageEl.push($module.closest('.pageContent'))
- }
- }
- })
- })
- //图片加载时间
- self.judegeImgsLoaded('.short-answer')
- if (overPageEl.length) {
- overPageEl.forEach(function (pageEl) {
- self.changePrintArea($(pageEl))
- })
- }
- },
- /**
- * --------------------------------------------------------------------------------------------------------------------------------
- 还原原题题干信息结束
- --------------------------------------------------------------------------------------------------------------------------------
- */
- initDom: function () {
- var self = this
- self.$layoutItem = $('#hgc_print .layoutItem')
- self.$checkBindLineItem = $('.selOptions input[name="hasBinding"]')
- //第一个page分页的元素,永远不会变
- self.$firstPageContent = $('#printcontent .pageContent').eq(0)
- //答题卡名称
- self.$dtkName = $('#dtkName textarea')
- },
- initEvent: function () {
- var self = this
- //当前默认是 A3 两栏 有装订线 有条形码 有准考证号
- self.linkageForPaper(self.paper)
- },
- /**
- *
- * @param {$element} $editorContentWrapEl 富文本包装内容的div
- * 语文作文格子需要格外加高度10
- */
- calcEditorContentHeight: function ($editorContentWrapEl) {
- var self = this
- var minScaleHeight = 0
- $editorContentWrapEl.children().each(function () {
- var boxWrap = $(this).hasClass('composition-column') ? 10 : 0
-
- if($(this).hasClass('en')){
- boxWrap = 33
- }
- minScaleHeight += $(this)[0].getBoundingClientRect().height + boxWrap
- })
- return minScaleHeight
- },
- bindEvent: function () {
- var self = this
- var testFormData = JSON.parse(localStorage.getItem('testFormData'))
- let exam_group_id = ''
- if (testFormData) {
- exam_group_id = testFormData.examGroupId;
- self.examGroupId = testFormData.examGroupId;
- }
- var base64_img = jrQrcode.getQrBase64(exam_group_id)
- $('#dtkEwm').attr('src', base64_img)
- //编辑标题
- $('#printcontent').on('blur', 'h3', function () {
- var curPageEl = $(this).closest('.pageContent')
- self.changePrintArea(curPageEl)
- })
- $('#printcontent').on('blur', '.objectiveItem', function () {
- var curPageEl = $(this).closest('.pageContent')
- self.changePrintArea(curPageEl)
- })
- // 限制标题输入内容
- $('#printcontent').on('keypress', 'h3', function () {
- let lock = true;
- let fullContent = '';
- let modelId = $(this).parent().attr('data-modelid');
- $('h3').on('compositionstart', function () {
- lock = false;
- });
- $('h3').on('compositionend', function (event) {
- lock = true;
- addInput(event, $(this));
- });
- $('h3').on('keyup input propertychange', function (event) {
- addInput(event, $(this));
- });
- // 字数限制
- function addInput(event, that) {
- let _words = that.text();
- if (lock) {
- let num = _words.length;
- if (num >= 10) {
- event.target.innerText = fullContent;
- event.target.innerText = _words.substring(0, 12);
- fullContent = _words.substring(0, 12);
- set_focus(event);
- seBigTopicTitle(fullContent,modelId)
- } else {
- fullContent = ''
- seBigTopicTitle(_words,modelId)
- }
- } else if (fullContent) {
- event.target.innerText = fullContent;
- lock = true;
- set_focus(event);
- seBigTopicTitle(fullContent,modelId)
- }
- }
- // 超过字数光标定位到末端
- function set_focus(e) {
- let el = document.getElementById(e.target.id);
- el.focus();
- if ($.support.msie) {
- let range = document.selection.createRange();
- this.last = range;
- range.moveToElementText(el);
- range.select();
- document.selection.empty();
- } else {
- let range = document.createRange();
- range.selectNodeContents(el);
- range.collapse(false);
- let sel = window.getSelection();
- sel.removeAllRanges();
- sel.addRange(range);
- }
- }
- // 设置大题title
- function seBigTopicTitle(text,modId) {
- let reg2 = /([^、/]+)$/;
- questionTypeTitle = text.match(reg2)[1];
- self.questionMap[modId].bigTitle=text
- self.questionMap[modId].commonFields.questionTypeTitle = questionTypeTitle
- }
- })
- //图片可扩展
- //控制答题卡区域缩放事件
- $('#printcontent').on('mousedown', '.short-answer .dragBtn', function (e) {
- e.stopPropagation()
- if (!self.isCanEditCard) return
- e.preventDefault()
- var inscreaseTop = $('#contentWrap').scrollTop()
- //当前操作的分页
- var curPageEl = $(this).closest('.pageContent')
- var curPageOffsetTop = curPageEl.offset().top + inscreaseTop
- //当前缩放分页下面的按钮
- var curDtkModelEl = $(this).closest('.module')
- var curDtkModelOffsetTop = curDtkModelEl.offset().top + inscreaseTop
- //只要改变高度的模块
- var changeEl = $(this).siblings('.editorContent')
- //改变之前的初始高度
- var startHeight = changeEl.height()
- var startPageY = e.pageY
- var distance = 0
- //计算可以缩放的最小高度
- var scaleMinHeight = self.calcEditorContentHeight(
- changeEl.children('.w-e-text')
- )
- // console.log('scaleMinHeight', scaleMinHeight)
- // console.log('startHeight', startHeight)
- // 如果题卡合一的话,最小高度就是里面内容的高度
- // 否则最小高度就是默认的高度
- // if(this.isSubjectInfoToCard){
- // }
- /**
- * 超过当前纸张的情况下 当鼠标松开的时候
- * 1先把当前纸张放满
- * 2剩余高度重新新到下个版本新建一个富文本高度一样没有内容
- * 3单词拖动鼠标控制解答题区域缩放只能拖动到当前页面最底部
- */
- document.onmousemove = function (e) {
- distance = e.pageY - startPageY
- var newHeight = startHeight + distance
- if (newHeight < scaleMinHeight) {
- newHeight = scaleMinHeight
- changeEl.height(newHeight)
- document.onmouseup(e)
- return
- }
- changeEl.height(newHeight)
- }
- //判断是否超过了一页
- /**
- * 1当前模块已经缩放超过了当前页
- * a>该区域后面的内容板块自动清空
- * b>该区域不可再移动,自动新建一页,然后在下一页新建一个富文本默认是上一页超出的区域
- * 2后面的模块超过了当前缩放页面
- * a>直接把后面的题放到新排版页面
- */
- document.onmouseup = function (e) {
- e.stopPropagation()
- self.changePrintArea(curPageEl)
- document.onmouseup = null
- document.onmousemove = null
- self.initPageTopic();
- }
- })
- //删除一个分页超出的部分
- $('#printcontent').on('click', '.delBtn', function (e) {
- if (!self.isCanEditCard) return
- var $this = $(this)
- self.delPageOverPart($this, 'surplus', true)
- })
- //预览
- $('#previewBtn').click(function () {
- self.previewPrintDiv('printcontent')
- })
- //保存
- $('#saveBtn').click(function () {
- if (!self.isCanEditCard) {
- if (self.isSubjectInfoToCard) {
- self.modal.init({
- content: '当前考试为“题卡合一”模式,是否需要重新替换成原题干内容?',
- sureCb: function () {
- //针对数学非第三方试卷:题卡分离的,原题信息都在改问题的后面,试卷固定顺序 选择--填空--解答--必答
- //渲染客观题题目信息
- //如果第一次题卡分离
- if (!$('.objectiveItem').length) {
- self.renderObjective(function (pageEl) {
- self.changePrintArea(pageEl)
- })
- } else {
- self.restoreObjectiveInfo({ clearStatus: false })
- }
- self.restoreAnswerInfo({ clearStatus: false })
- }
- })
- self.isCanEditCard = true
- self.changeCardEditStatus()
- } else {
- // hgc_layer.msg('考试已被设置为【题卡分离】,请注意答题卡已被重置!')
- // if ($('.objectiveItem').length) {
- // self.restoreObjectiveInfo({ clearStatus: true })
- // }
- // self.restoreAnswerInfo({ clearStatus: true })
- self.isCanEditCard = true
- self.changeCardEditStatus()
- }
- return
- }
- self.totalPage = $('.pageContent').length
- if (self.totalPage > self.columns * 2) {
- hgc_layer.msg('答题卡最多支持' + self.columns * 2 + '页')
- return
- }
- // 如果是全学科答题卡,保存并且返回 需要先设置主观题答案
- if (isNewBuild) {
- if ($.isEmptyObject(self.questionMap)) {
- hgc_layer.msg('请添加试题')
- return false
- }
- var allSetAnswer = true
- var buildQuestions = self.questionMap
- for (var modelId in buildQuestions) {
- var modelItem = buildQuestions[modelId]
- if (~[1, 2, 11].indexOf(modelItem.questionType)) {
- allSetAnswer = modelItem.questions.every(function (question) {
- return question.answer
- })
- if (!allSetAnswer) break
- }
- }
- if (!allSetAnswer) {
- self.modal.init({
- title: '提示',
- content: '请先设置客观题答案',
- ensureText: '去设置',
- cancelText: '关闭',
- sureCb: function () {
- $('#setAnswerBtn').trigger('click')
- }
- })
- return
- }
- if (self.$dtkName.val() == '') {
- self.modal.init({
- title: '提示',
- content: '请先设置标题',
- cancelText: '关闭'
- })
- return
- }
- // self.$dtkName.val()
- self.savePrintPosition('printcontent')
- return
- }
- if (!self.isCanEditCard) {
- self.isCanEditCard = true
- self.changeCardEditStatus()
- return
- }
- self.judgeHasPrintClass(function () {
- self.savePrintPosition('printcontent')
- })
- })
- //下载pdf
- $('#downLoadBtn').click(function () {
- if (self.isCanEditCard && !isNewBuild) return
- var $this = $(this)
- if (self.totalPage > self.columns * 2) {
- hgc_layer.msg('答题卡最多支持' + self.columns * 2 + '页')
- return
- }
- /**
- * 1 可编辑状态 编辑-保存 --编辑状态不可直接生成或者下载,只有保存状态下,才能生成或者下载
- * 2 是否和接口返回的记忆布局数据一样 --如果一样,默认没有修改,可直接下载或者生成
- * 3 判断是否已经存在在打印的班级 --如果已经存在正在打印的班级学生,则提示是否覆盖,然后才能生成或者下载
- * 4 是否使用二维码 --如果使用二维码,则使用生成pdf的那套逻辑
- *
- * 如果是创建答题卡 直接下载
- */
- if (isNewBuild) {
- self.downLoadPdf()
- return
- }
- //保存状态不用重新执行保存逻辑直接下载或者批量生成
- if (!self.isCanEditCard) {
- if (self.useQrCode) {
- self.judgeHasPrintClass(function () {
- setTimeout(function () {
- self.modal.init({
- title: '批量生成',
- content: '该操作会把该场考试下面的所有班级学生考试模板进行批量生成',
- sureCb: function () {
- self.batchGeneratePdf()
- }
- })
- }, 0)
- })
- } else {
- self.downLoadPdf()
- }
- return
- }
- //如果使用了二维码后台批量生成,不影响当前页面
- var nowPosition = JSON.stringify(self.getPositions())
- if (self.useQrCode) {
- if (nowPosition !== self.saveLocationPosition) {
- self.judgeHasPrintClass(function () {
- self.savePrintPosition('printcontent', function () {
- self.modal.init({
- title: '批量生成',
- content: '该操作会把该场考试下面的所有班级学生考试模板进行批量生成',
- sureCb: function () {
- self.batchGeneratePdf()
- }
- })
- })
- })
- } else {
- self.judgeHasPrintClass(function () {
- setTimeout(function () {
- self.modal.init({
- title: '批量生成',
- content: '该操作会把该场考试下面的所有班级学生考试模板进行批量生成',
- sureCb: function () {
- self.batchGeneratePdf()
- }
- })
- }, 0)
- })
- }
- } else {
- //保存状态不用重新执行保存逻辑直接下载或者批量生成
- if (!self.isCanEditCard) {
- self.downLoadPdf()
- return
- }
- if (nowPosition !== self.saveLocationPosition) {
- self.judgeHasPrintClass(function () {
- self.savePrintPosition('printcontent', function () {
- self.downLoadPdf()
- })
- })
- } else {
- self.downLoadPdf()
- }
- }
- })
- //答题卡布局
- //选择纸张
- new RadioBoxItem($('#paperOptions'), function ($radioItem, status) {
- var paper = $radioItem.attr('data-paper')
- self.paper = paper
- self.linkageForPaper(paper)
- // self.reInitPageForNewBuild();
- })
- //选择排版方向
- new RadioBoxItem($('#paperDirection'), function ($radioItem, status) {
- var direction = $radioItem.attr('data-direction')
- self.direction = direction
- self.setPageWidthHeightForDirection(direction)
- self.linkageForDirection(self.config.direction[direction])
- })
- //选择分栏
- self.$layoutItem.click(function () {
- var column = +$(this).attr('data-column')
- //|| $(this).hasClass('current')
- if ($(this).hasClass('disabled')) return
- $(this).addClass('current').siblings().removeClass('current')
- self.columns = column
- self.initPrintContentArea()
- })
- //选择是否有装订线
- new RadioBoxItem($('#hasBindingLine'), function ($radioItem, status) {
- var bindingLineStatus = $radioItem.attr('data-value') === 'yes'
- self.hasBindingLine = bindingLineStatus
- self.ifBindingLine()
- })
- //选择是否显示信息栏
- new RadioBoxItem($('#hasPaperMsg'), function ($radioItem, status) {
- var bindingPaperMsgStatus = $radioItem.attr('data-value') === 'yes'
- self.hasPaperMsg = bindingPaperMsgStatus
- self.isShowPaperMsg()
- })
- //信息栏设置
- $('#printcontent').on('click', '.btn-examInfo', function () {
- if (!self.isCanEditCard) return
- $('#examInfoEditDialog').show()
- })
- $('#examInfoEditDialog').on('click', '.btn-hide-dialog', function () {
- $('#examInfoEditDialog').hide()
- })
- $('#examInfoEditDialog').on('click', '.btn-save-examInfo', function () {
- $('#examInfoEditDialog').hide()
- self.showExamInfoHtml();
- self.getSaveSubjectInfo(self.questionMap)
- })
- $('.opratorArea').on('mouseover', '.hgc_notice', function (e) {
- let el = e.target
- let noticeEl = $(this).parent('.notice-item').find('.noticeContent');
- let triangleEl = $(this).parent('.notice-item').find('.noticeContent').find('b');
- $(noticeEl).show();
- let noticeH = $(noticeEl).get(0).offsetHeight
- let noticeW = $(noticeEl).get(0).offsetWidth
- let { top, left } = el.getBoundingClientRect();
- $(noticeEl).css('top', top - noticeH - 10 + 'px')
- $(noticeEl).css('left', left - noticeW / 2 + 'px');
- $(triangleEl).css('top', top - 10 + 'px');
- $(triangleEl).css('left', left + 'px');
- })
- $('.opratorArea').on('mouseout', '.hgc_notice', function (e) {
- let el = e.target
- let noticeEl = $(this).parent('.notice-item').find('.noticeContent');
- $(noticeEl).hide();
- })
- //考号配置
- new CheckBoxItem(
- $('#examNumberConfig'),
- function () { },
- self.selExamNumberStyle.bind(self)
- )
- //信息栏弹窗配置
- new CheckBoxItem(
- $('#examInfoConfig'),
- function () { },
- self.selExamInfoStyle.bind(self)
- )
- //是否使用二维码
- new Switch($('#useQrCode'), function (status) {
- var $examNumberConfigOptions = $('#examNumberConfig .h_checkItem')
- var $examNumberLayout = $('.examNumberLayout')
- var $downLoadBtn = $('#downLoadBtn')
- var $ewmTips = $('#ewmTips')
- self.useQrCode = status
- $downLoadBtn.html(status ? '生成' : '下载')
- $examNumberConfigOptions.each(function () {
- $(this)[status ? 'addClass' : 'removeClass']('disabled')
- })
- $('.className').html(status ? self.tpls.systemClassNoticeInfoTpl : '')
- $('.examineeName').html(status ? self.tpls.systemNameNoticeInfoTpl : '')
- $('.bindLineClassName').html(
- status ? self.tpls.systemClassNoticeInfoForLineTpl : ''
- )
- $('.bindLineExamineeName').html(
- status ? self.tpls.systemNameNoticeInfoForLineTpl : ''
- )
- self.editNoticeDetail(status,self.cardStatus)
- $examNumberLayout[status ? 'addClass' : 'removeClass']('useqrcode')
- $ewmTips.css('display', status ? 'flex' : 'none')
- self.changePrintArea(self.$firstPageContent)
- })
- //单模块设置
- $('#printcontent').on('click', '.settingBtn', function () {
- if (!self.isCanEditCard) return
- var $this = $(this)
- var type = $this.attr('data-type')
- var modelId = $this.closest('.answerModule').attr('data-modelId')
- //如果是创建答题卡则跳转到编辑页面
- if (isNewBuild) {
- self.setBuildQuestions()
- window.QE.questionEditStatus = true
- window.QE.questionData = JSON.parse(
- JSON.stringify({
- ...self.questionMap[modelId],
- subjectId: subjectId,
- isAdd: false,
- SelectbigNoArr: getSelectbigNoArr(self.questionMap)
- })
- )
- $('#questionEdit').show()
- return
- }
- //填空
- if (type === 'fillInBlank') {
- self.fillInBlankSet($this)
- //选择 单选-多选
- } else if (~type.indexOf('Select')) {
- self.selectSetLayout($this, type)
- } else {
- self.shortAnswerSet($this)
- }
- })
- //单模块删除
- $('#printcontent').on('click', '.delTopicBtn', function () {
- if (!self.isCanEditCard) return
- var $this = $(this);
- var type = $this.attr('data-type');
- var modelId = $this.closest('.answerModule').attr('data-modelId');
- let $replaceEl = null
- self.modal.init({
- title: '提示',
- content: '确定要删除当前题目吗?',
- ensureText: '确定',
- cancelText: '取消',
- sureCb: function () {
- $('.answerModule').each(function () {
- if ($(this).attr('data-modelId') === modelId) {
- $replaceEl = $(this)
- }
- })
-
-
- if(type!=='shortAnswer'){
- $this.parents('.answerModule').remove();
- }
- //填空
- if (type === 'fillInBlank') {
- delete self.questionMap[modelId]
- //选择 单选-多选
- } else if (~type.indexOf('Select')) {
- delete self.questionMap[modelId]
- } else if (~type.indexOf('uncertain')) {
- delete self.questionMap[modelId]
- } else if (~type.indexOf('chooseAnswer')) {
- delete self.questionMap[modelId]
- $('.pageContent').find('.short-answer').each(function(){
- let modelid = $(this).attr('data-modelid');
- if(modelid = modelId){
- $(this).remove();
- }
- })
- } else if (~type.indexOf('shortAnswer')) {
- let titleNumber = $this.closest('.module').attr('title-number');
- let questionsAll = JSON.parse(JSON.stringify(self.questionMap[modelId].questions));
- questionsAll.forEach((topic, index) => {
- if (topic.questionNum == titleNumber) {
- if (self.questionMap[modelId].questions.length === 1) {
- delete self.questionMap[modelId]
- // $this.parents('.answerModule').remove();
- $('.pageContent').find('.short-answer').each(function(){
- let modelid = $(this).attr('data-modelid');
- if(modelid = modelId){
- $(this).remove();
- }
- })
- } else {
- // $this.parents('.module').remove();
- $('.pageContent').find('.short-answer .module').each(function(){
- let moduleTitleNumber = $(this).attr('title-number');
- if(moduleTitleNumber = titleNumber){
- $(this).remove();
- }
- })
- self.questionMap[modelId].questions.splice(index, 1);
- self.questionMap[modelId].originQuestions.splice(index, 1);
- self.questionMap[modelId].commonFields.questionTypeArr.forEach((n, ni) => {
- if (titleNumber == n.startNo || titleNumber == n.endNo) {
- if (n.startNo == n.endNo) {
- self.questionMap[modelId].commonFields.questionTypeArr.splice(ni, 1);
- } else {
- if (titleNumber == n.startNo) {
- n.startNo = Number(n.startNo) + 1
- } else {
- n.endNo = Number(n.endNo) - 1
- }
- }
- } else if (titleNumber > n.startNo && titleNumber < n.endNo) {
- let ndata = JSON.parse(JSON.stringify(n))
- let questionType = {
- startNo: '',
- endNo: n.endNo,
- score: ndata.score
- };
- n.endNo = Number(titleNumber) - 1;
- questionType.startNo = Number(titleNumber) + 1;
- self.questionMap[modelId].commonFields.questionTypeArr.splice(ni + 1, 0, questionType);
- }
- })
- }
- }
- })
- }
- //重新设置
- localStorage.setItem('buildQuestions', JSON.stringify(self.questionMap))
- var DelPosition = self.getPositions();
- localStorage.setItem('position', JSON.stringify(DelPosition))
- self.reInitPageForNewBuild();
- if ($.isEmptyObject(self.questionMap)) {
- $('.addTips').show();
- // 当答题卡没有题时设置总分为空
- $('.fraction').val('')
- }
- }
- })
- })
- // 给模块标题设置高度
- $('#printcontent').on('click', '.answerModule h3', function () {
- $(this).css('height','auto')
- })
- function isPx(str) {
- return /^\d+$/.test(str)
- }
- document.addEventListener(
- 'error',
- function (e) {
- var elem = e.target
- if (elem.tagName.toLowerCase() === 'img') {
- var oh = $(elem).attr('height')
- var ow = $(elem).attr('width')
- if (!isPx(oh) || !isPx(ow)) return
- var h = parseInt($(elem).attr('height'))
- var w = parseInt($(elem).attr('width'))
- var hmm = self.unitConversion.pxConversionMm(h)
- var wmm = self.unitConversion.pxConversionMm(w)
- $(elem).attr(
- 'style',
- $(elem).attr('style') +
- ';height:' +
- hmm +
- 'mm !important;width:' +
- wmm +
- 'mm !important;'
- )
- }
- },
- true
- )
- document.addEventListener(
- 'load',
- function (e) {
- var elem = e.target
- if (
- elem.tagName.toLowerCase() === 'img' &&
- typeof $(elem).attr('word_img') === 'string'
- ) {
- var h = parseInt($(elem).attr('height'))
- var w = parseInt($(elem).attr('width'))
- var hmm = self.unitConversion.pxConversionMm(h)
- var wmm = self.unitConversion.pxConversionMm(w)
- $(elem).attr(
- 'style',
- $(elem).attr('style') +
- ';height:' +
- hmm +
- 'mm !important;width:' +
- wmm +
- 'mm !important;'
- )
- }
- },
- true
- )
- function getSelectbigNoArr(data) {
- var SelectbigNoArr = [];
- for (var i in data) {
- // console.log(i,":",obj[i]);
- SelectbigNoArr.push(data[i].commonFields.bigNo)
- }
- // for(var i = 0; i < data.length; i++) { // 这里的i是代表数组的下标
- // let key = 'modelId' + i+1;
- // SelectbigNoArr.push(data[key].commonFields.bigNo)
- // }
- return SelectbigNoArr
- }
- //添加试题
- $('#addQustionBtn').click(function () {
- var modelId = guid()
- window.QE.questionEditStatus = true
- window.QE.questionData = JSON.parse(
- JSON.stringify({
- ...window.defaultQuestionData,
- modelId: modelId,
- isAdd: true,
- subjectId: subjectId,
- SelectbigNoArr: getSelectbigNoArr(self.questionMap)
- })
- )
- $('#questionEdit').show()
- })
- //设置答案
- //保存备选答案
- var tempQuestions = null
- $('#setAnswerBtn').click(function () {
- self.showSettingAnswerArea()
- tempQuestions = JSON.parse(JSON.stringify(self.questionMap))
- $('#setAnswer').show()
- })
- $('#returnAnswer').click(function () {
- tempQuestions = null
- $('#setAnswer').hide()
- })
- $('#saveAnswer').click(function () {
- self.questionMap = tempQuestions
- tempQuestions = null
- self.getSaveSubjectInfo(self.questionMap);
- $('#setAnswer').hide()
- })
- //设置备选答案
- $('.answerList').on('click', '.answesOption', function () {
- var modelId = $(this).attr('data-id')
- var _index = +$(this).attr('data-index')
- var answer = $(this).attr('data-answer')
- var modelQuestionType = tempQuestions[modelId].questionType
- if (modelQuestionType === 1) {
- if ($(this).hasClass('active')) return
- $(this).addClass('active').siblings('i').removeClass('active')
- tempQuestions[modelId].questions[_index].answer = answer
- } else {
- $(this).toggleClass('active');
- // $(this).addClass('active');
- var arrAnswer = ""
- $(this).parent().find('.active').each(function (index) {
- arrAnswer = arrAnswer + (arrAnswer.length > 0 ? ',' : '') + $(this).attr('data-answer')
- // arrAnswer = arrAnswer + $(this).attr('data-answer')
- })
- tempQuestions[modelId].questions[_index].answer = arrAnswer
- // console.log(tempQuestions,arrAnswer,22)
- }
- })
- //公式编辑器插件
- self.eventForFormula()
- },
- //公式编辑器相关事件
- eventForFormula: function () {
- var self = this
- var curEditorFormula = null
- $('body').on('click', '.kfformula,.gsImgLatex', function () {
- if (!self.isCanEditCard) return
- self.formulaing = true
- $('#formulaBox').show()
- curEditorFormula = $(this)
- var imgLatex =
- $(this).attr('data-latex') || $(this).attr('src').split('?')[1]
- var latexUse = decodeURIComponent(imgLatex)
- if (window.kfe) {
- window.kfe.execCommand('render', latexUse || '\\placeholder')
- } else {
- window.factory = window.kf.EditorFactory.create(
- $('#kfEditorContainer')[0],
- {
- render: {
- fontsize: 18
- },
- resource: {
- path: './kityformula/resource/'
- }
- }
- )
- window.factory.ready(function (KFEditor) {
- KFEditor.execCommand('render', latexUse || '\\placeholder')
- KFEditor.execCommand('focus')
- window.kfe = KFEditor
- })
- $('#kf-formula-ensure')[0].onclick = function () {
- window.kfe.execCommand('get.image.data', function (data) {
- var latex = window.kfe.execCommand('get.source')
- $.post(self.apis.getMathtexApi, { mathtex: latex }, function (res) {
- var newh = self.unitConversion.pxConversionMm(res.height)
- var neww = self.unitConversion.pxConversionMm(res.width)
- var newLatexImg =
- '<img src="{url}" class="gsImgLatex mathType" style="vertical-align: middle;height:{newh}mm;width:{neww}mm;" data-latex="{latex}">'
- curEditorFormula[0].outerHTML = newLatexImg.substitute({
- url: res.url,
- latex: latex,
- newh: newh,
- neww: neww
- })
- })
- return true
- })
- $('#formulaBox').hide()
- self.formulaing = false
- return false
- }
- $('#kf-formula-cancel')
- .off('click')
- .click(function () {
- $('#formulaBox').hide()
- self.formulaing = false
- })
- }
- })
- },
- showSettingAnswerArea: function () {
- var self = this
- var answerItemTpl =
- '<div class="answerItem">\
- <span>{questionNum}</span>\
- <span>{questionName}</span>\
- <p>{answers}</p>\
- </div>'
- //拿到主观题数据
- // 通过modelId 和 题目索引来定位一个题
- var questionClassify = self.questionMap
- var answerHtml = ''
- for (var modelId in questionClassify) {
- var modelData = questionClassify[modelId]
- var modelType = modelData.questionType
- if (!~[1, 2, 11].indexOf(modelType)) continue
- answerHtml += modelData.questions.reduce(function (
- answerItemHtml,
- cur,
- index
- ) {
- var selectHtml = ''
- for (var i = 0; i < cur.optionCount; i++) {
- var content = String.fromCharCode(65 + i)
- var activeClass = ''
- var isActiveOption = cur.answer.indexOf(content)
- if (isActiveOption > -1) activeClass = 'active'
- selectHtml += '<i class="answesOption {activeClass}" data-id="{modelId}" data-index="{index}" data-answer="{content}">{content}</i>'.substitute(
- {
- content: content,
- modelId: modelId,
- index: index,
- activeClass: activeClass
- }
- )
- }
- answerItemHtml += answerItemTpl.substitute({
- questionNum: cur.questionNum,
- questionName: self.questionNameMap[self.questionTypeMapForC[modelType]],
- answers: selectHtml
- })
- return answerItemHtml
- },
- '')
- }
- $('#answerList').html(answerHtml)
- },
- //修改答题卡编辑状态
- changeCardEditStatus: function () {
- var self = this
- $('#dtkName textarea').prop('disabled', !self.isCanEditCard)
- $('#examInfo input').prop('disabled', !self.isCanEditCard)
- $('#saveBtn').html(self.isCanEditCard ? '保存' : '编辑')
- $('#downLoadBtn')[self.isCanEditCard ? 'addClass' : 'removeClass'](
- 'disabled'
- )
- //右侧操作栏目
- $('#disabledCover')[self.isCanEditCard ? 'hide' : 'show']()
- //题干信息
- $('.objectiveItem').each(function () {
- $(this).prop('contenteditable', self.isCanEditCard)
- })
- //编辑器
- for (var editorId in self.editorArea) {
- self.editorArea[editorId].$textElem.attr(
- 'contenteditable',
- self.isCanEditCard
- )
- }
- //标题
- $('.answerModule h3').each(function () {
- $(this).prop('contenteditable', self.isCanEditCard)
- })
- },
- //检测是否有已经生成的答题卡
- judgeHasPrintClass: function (cb) {
- var self = this
- if (self.printClassStatus) {
- self.modal.init({
- title: '批量生成',
- content: '保存后,会重置原答题卡数据,将恢复班级/学生的打印状态,且可能会导致已打印出的答题卡扫描无效,请谨慎操作!',
- sureCb: function () {
- cb && cb()
- }
- })
- } else {
- cb && cb()
- }
- },
- //根据选择排版方向设置答题卡的视觉排版宽高
- setPageWidthHeightForDirection: function (direction) {
- var self = this
- var isVertical = direction === 'vertical'
- //设置横竖版面
- self.config[isVertical ? 'width' : 'height'] = self.configOrigin.width
- self.config[isVertical ? 'height' : 'width'] = self.configOrigin.height
- },
- //点击选择纸张联动,纸张方向和纸张分栏选择
- linkageForPaper: function (paper) {
- var self = this
- // '8K': {
- // width: 267,
- // height: 390,
- // direction: {
- // horizontal: [2, 3]
- // }
- // },
- //layoutList
- self.config = simpleCopy(sizeConfig[paper])
- self.configOrigin = simpleCopy(sizeConfig[paper])
- var directions = self.config.direction
- var isPaperDirectionStop = false
- $('#paperDirection .h_radioItem').each(function () {
- var direction = $(this).attr('data-direction')
- if (direction in directions) {
- $(this).removeClass('disabled')
- if (!isPaperDirectionStop) {
- isPaperDirectionStop = true
- $(this).trigger('click')
- }
- } else {
- $(this).addClass('disabled')
- }
- })
- },
- //点击选择纸张方向联动 分栏选择
- linkageForDirection: function (columns) {
- var self = this
- var isLayoutItemStop = false
- let isClick = 0
- self.$layoutItem.each(function () {
- var $this = $(this)
- var dataColumn = +$this.attr('data-column')
- if (~columns.indexOf(dataColumn)) {
-
- if(isClick==0){
- isClick = dataColumn
- } else {
- if(self.columns == dataColumn){
- isClick = dataColumn
- }
- }
-
- }
- })
- self.columns = isClick
- self.$layoutItem.each(function () {
- var $this = $(this)
- var dataColumn = +$this.attr('data-column')
- if (~columns.indexOf(dataColumn)) {
- $this.removeClass('disabled')
- if(self.columns){
- if(self.columns == dataColumn){
- isLayoutItemStop = true
- $this.trigger('click')
- }
-
- } else {
- if (!isLayoutItemStop) {
- isLayoutItemStop = true
- $this.trigger('click')
- }
- }
-
- } else {
- $this.addClass('disabled')
- }
- })
- },
- //获取settingBtn
- getSettingBtn: function (modelId) {
- var $settingBtn = null
- $('#printcontent .answerModule').each(function () {
- if ($(this).attr('data-modelId') === modelId && !$settingBtn) {
- $settingBtn = $(this).find('.settingBtn')
- }
- })
- return $settingBtn
- },
- //获取大题模块
- getAnswerModuleForModelId: function (modelId) {
- var $answerModule = null
- $('#printcontent .answerModule').each(function () {
- if ($(this).attr('data-modelId') === modelId && !$answerModule) {
- $answerModule = $(this)
- }
- })
- return $answerModule
- },
- //选择题
- selectSetLayout: function ($this, type) {
- var self = this
- var memoryDirection = $this.closest('.answerModule').attr('data-direction')
- var directionCheckMap = {
- vertical: 'verticalChecked',
- horizontal: 'horizontalChecked'
- }
- var substituteData = {}
- substituteData[directionCheckMap[memoryDirection]] = 'checked'
- var tempDirection = ''
- self.modal.init({
- title: '选择题设置',
- content: self.tpls.selectSetTpl.substitute(substituteData),
- afterCb: function () {
- new RadioBoxItem($('#selectDirection'), function ($radioItem, status) {
- var direction = $radioItem.attr('data-value')
- tempDirection = direction
- })
- },
- sureCb: function () {
- self.selectStyleChange($this, tempDirection)
- }
- })
- },
- selectStyleChange: function ($this, direction) {
- var self = this
- var curPageIndex = $this.closest('.pageContent').index() + 1
- var $selectModule = $this.closest('.single-select')
- var $curPage = $this.closest('.pageContent')
- var modelId = $selectModule.attr('data-modelId')
- var modelData = self.questionMap[modelId]
- var modelPagesData = modelData.pages
- //modelData.direction = direction
- function setDirection($selectModule) {
- if (!$selectModule.hasClass(direction)) {
- var isHorizontal = direction === 'horizontal'
- $selectModule
- .removeClass(isHorizontal ? 'vertical' : 'horizontal')
- .addClass(isHorizontal ? 'horizontal' : 'vertical')
- .attr('data-direction', direction)
- }
- curPageIndex++
- if (modelPagesData[curPageIndex]) {
- var $nextPage = $('.pageContent').eq(curPageIndex - 1)
- var $nextPageFirstSelect = $nextPage.find('.single-select').eq(0)
- if ($nextPageFirstSelect.attr('data-modelId') === modelId) {
- setDirection($nextPageFirstSelect)
- }
- }
- }
- setDirection($selectModule)
- self.changePrintArea($curPage)
- },
- //填空题设置
- fillInBlankSet: function ($this) {
- var self = this
- var $subjectCol = $this.siblings('.subjectCol')
- var columnSelectedMap = {
- 1: 'columnOneSelected',
- 2: 'columnTwoSelected',
- 3: 'columnThreeSelected'
- }
- var rowLineHeightSelectedMap = {
- 25: 'rowLineOneSelected',
- 30: 'rowLineTwoSelected',
- 35: 'rowLineThreeSelected',
- 40: 'rowLineFourSelected',
- 45: 'rowLineFiveSelected',
- 50: 'rowLineSixSelected'
- }
- var scoreSelectedMap = {
- '2/3/5': 'scoreOneSelected',
- '2/3/4/6': 'scoreTwoSelected',
- '2/4': 'scoreThreeSelected'
- }
- var memoryColumn = $subjectCol.attr('data-column') || 1
- var memoryColumnRowLineHeight = $subjectCol.attr('data-rowLineHeight') || 40
- var memoryScoreStyle = $subjectCol.attr('data-scoreStyle') || ''
- var maxScore = $subjectCol
- .children('.subjectItem')
- .eq(0)
- .attr('data-fullScore')
- var substituteData = {}
- substituteData[columnSelectedMap[memoryColumn]] = 'selected'
- substituteData[rowLineHeightSelectedMap[memoryColumnRowLineHeight]] =
- 'selected'
- substituteData[scoreSelectedMap[memoryScoreStyle]] = 'selected'
- for (var scoreFormat in scoreSelectedMap) {
- if (!~scoreFormat.split('/').indexOf(maxScore)) {
- substituteData[scoreSelectedMap[scoreFormat]] = 'disabled'
- }
- }
- self.modal.init({
- title: '填空题设置',
- content: self.tpls.fillInBlankSetTpl.substitute(substituteData),
- sureCb: function () {
- //每行列数
- var column = $('#fillInBlankColumn').val()
- //行间距
- var rowLinHeight = $('#fillInBlankLineHeight').val()
- //手写打分
- var scoreStyle = $('#scoringBox').val()
- //修改填空题样式
- self.fillInBlankStyleChange($this, column, rowLinHeight, scoreStyle)
- }
- })
- },
- fillInBlankStyleChange: function ($this, column, rowLinHeight, scoreStyle) {
- var self = this
- var curPageEl = $this.closest('.pageContent')
- var modelId = $this.closest('.answerModule').attr('data-modelId')
- var $fillInBlankCol = $('.pageContent').find('.subjectCol')
- scoreStyle = scoreStyle || ''
- //重新计算fillInBlank 查看是否需要修改手动打分样式
- self.calcFillInBlankData(modelId, scoreStyle)
- self.reRenderFillInBlank(modelId)
- $fillInBlankCol.attr({
- 'data-column': column,
- 'data-rowLineHeight': rowLinHeight,
- 'data-scoreStyle': scoreStyle,
- class: 'subjectCol clearfix col-' + column + ' rowLineHeight-' + rowLinHeight
- })
- //如果填空题由原来的一行变成多行,就有可能影响所有的布局样式,重新布局整个答题卡
- //fiexd:curPageEl 需要修改成该填空题答题最后数据所在的pageEl
- self.changePrintArea(curPageEl)
- },
- //解答题设置
- shortAnswerSet: function ($this) {
- var self = this
- var $module = $this.closest('.module')
- var memoryScoreLimitKey = $module.attr('scoreLimit')
- var fullScore = +$module.attr('data-fullScore')
- var memoryIsAddHalf = $module.attr('isAddHalf') === 'true'
- var disabledScoreKey
- var limitSelectedMap = {
- 15: 'limit15selected',
- 16: 'limit16selected',
- 29: 'limit29selected',
- 49: 'limit49selected'
- }
- //禁用标识
- var disabledSelectMap = {
- 15: 'disabled15',
- 16: 'disabled16',
- 29: 'disabled29',
- 49: 'disabled49'
- }
- var formatParam = {}
- formatParam[limitSelectedMap[memoryScoreLimitKey]] = 'selected'
- formatParam.isAddHalfChecked = memoryIsAddHalf ? 'checked' : ''
- for (var scoreLimit in self.answerScoreLimitKeyArr) {
- if (scoreLimit < fullScore) {
- formatParam[disabledSelectMap[scoreLimit]] = 'disabled'
- }
- }
- self.modal.init({
- title: '解答题设置',
- content: self.tpls.shortAnswerOptionTpl.substitute(formatParam),
- sureCb: function () {
- var scoreLimitKey = $('#scoreLimit').val()
- var isAddHalf = $('#isAddHalf').prop('checked')
- self.shortAnswerStyleChange($this, scoreLimitKey, isAddHalf)
- }
- })
- },
- /**
- * @param {当前要修改的解答题区域内的标示符} $this
- * @param {分值上限} scoreLimitKey
- */
- shortAnswerStyleChange: function ($this, scoreLimitKey, isAddHalf, topicScore) {
- var self = this
- var scorePartEl = $this.siblings('.scortColumn')
- var colClass = 'col-' + scoreLimitKey
- var scoreModuleHtml = self.generateScoreBox(scoreLimitKey, isAddHalf, topicScore)
- //解答题分值上限配置
- scorePartEl
- .html(scoreModuleHtml)
- .attr('class', 'scortColumn clearfix ' + colClass)
- .parent('.module')
- .attr('scoreLimit', scoreLimitKey)
- .attr('isAddHalf', isAddHalf)
- },
- generateScoreBox: function (scoreLimitKey, isAddHalf, topicScore) {
- var self = this
- function rendScore(score) {
- return '<span>' + score + '</span>'
- }
- var bit = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
- //各个分值对应的分值 布局格式
- var scoreLimitMap = {
- '16': [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16],
- '15': [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15],
- '29': {
- tenPlace: [1, 2],
- bit: bit
- },
- '49': {
- tenPlace: [1, 2, 3, 4],
- bit: bit
- },
- '69': {
- tenPlace: [1, 2, 3, 4, 5, 6],
- bit: bit
- }
- }
- var scoreLimit = scoreLimitMap[scoreLimitKey]
- var scoreModuleHtml = ''
- var scoreLimitArr = []
- var noScoringW = 42
- let pw = $('#printcontent').width();
- noScoringW = pw/17
- // switch (self.paper) {
- // case 'A4':
- // case '16K':
- // noScoringW = 22
- // break
- // default:
- // noScoringW = 42
- // break
- // }
- if (~'16|15'.indexOf(scoreLimitKey)) {
- if (Number(topicScore) < Number(scoreLimitKey)) {
- for (let index = 0; index < topicScore; index++) {
- scoreLimitArr.push(index + 1)
- }
- } else {
- scoreLimitArr = scoreLimit
- }
- } else {
- scoreLimitArr.push('十位')
- scoreLimitArr = scoreLimitArr.concat(scoreLimit.tenPlace)
- scoreLimitArr.push('个位')
- scoreLimitArr = scoreLimitArr.concat(scoreLimit.bit)
- }
- //是否增加0.5分机制
- isAddHalf && scoreLimitArr.push('0.5')
- scoreLimitArr.forEach(function (score, index) {
- scoreModuleHtml += rendScore(score)
- })
- if (Number(topicScore) < Number(scoreLimitKey) && Number(scoreLimitKey) < 17) {
- let width = (15 - topicScore) * noScoringW;
- if (width < 48) {
- width = 48
- }
- scoreModuleHtml += "<span class='no-scoring' style='flex: initial; width:" + width + "px; color: #dddddd;'>禁打分区</span>"
- }
- return scoreModuleHtml
- },
- editNoScoringWidth: function () {
- let pw = $('#printcontent').width();
-
- $('.scortColumn').each(function(i,k){
- let kL = $(k).find('span').length;
- let kw = pw/17*(16-kL);
- if(kw<48){
- kw = 48
- }
- $(k).find('.no-scoring').width(kw);
- })
- },
- //是否有装订线
- ifBindingLine: function () {
- var self = this
- var curPageEl = self.$firstPageContent
- var isUseClass = self.hasBindingLine ? 'addClass' : 'removeClass'
- var isHideBinding = self.hasBindingLine ? 'show' : 'hide'
- var isHideExamineeInfo = !self.hasBindingLine ? 'show' : 'hide'
- $('#printcontent')
- [isUseClass]('hasBindingLine')
- .find('.bindingLine')
- [isHideBinding]()
- $('#examineeInfoForLayout')[isHideExamineeInfo]()
- //隐藏考生的姓名 班级信息也会影响布局
- self.changePrintArea(curPageEl)
- },
- //是否显示信息栏
- isShowPaperMsg: function () {
- var self = this
- if (self.hasPaperMsg) {
- // let examInfo ={}
- // var examInfoHtml = self.tpls.examInfoTpl.substitute(examInfo)
- // $('#examInfo').html(examInfoHtml)
- self.showExamInfoHtml();
- self.getSaveSubjectInfo(self.questionMap)
- $('#examInfo').css('display', 'flex');
- $('#hasPaperMsg').find('.h_radioItem').eq(0).addClass('checked')
- $('#hasPaperMsg').find('.h_radioItem').eq(1).removeClass('checked')
- } else {
- $('#hasPaperMsg').find('.h_radioItem').eq(0).removeClass('checked')
- $('#hasPaperMsg').find('.h_radioItem').eq(1).addClass('checked')
- $('#printcontent').find('#examInfo').html('');
- $('#examInfo').css('display', 'none');
- }
- },
- //是否只使用条形码
- isOnlyBarCode: function () {
- var self = this
- return self.examNumberConfig.barCode && !self.examNumberConfig.ticketNumber
- },
- //判断当前选中个数
- getExamConfigSeledCount: function () {
- var self = this
- var seledCount = 0
- //条形码 和 考号 至少选择一个
- for (var examKey in self.examNumberConfig) {
- if (self.examNumberConfig[examKey]) {
- seledCount += 1
- }
- }
- return seledCount
- },
- //选择考号版式
- selExamNumberStyle: function ($this, singleStatus) {
- var self = this
- var value = $this.attr('data-value')
- //当前选考号配置的数量
- var curExamConfigCount = self.getExamConfigSeledCount()
- if (!singleStatus && curExamConfigCount === 1) {
- hgc_layer.msg('不使用二维码的情况下,填涂考号和条形码至少选择一个')
- $this.trigger('click')
- return
- }
- self.examNumberConfig[value] = singleStatus
- $('#hgc_examNumber .' + value)[singleStatus ? 'show' : 'hide']()
- //只使用条形码
- var isOnlyBarCode = self.isOnlyBarCode()
- $('#hgc_examNumber').css('display', isOnlyBarCode ? 'none' : 'flex')
- $('#hgc_examNumberForOnlyBarcode').css(
- 'display',
- isOnlyBarCode ? 'flex' : 'none'
- )
- self.changePrintArea(self.$firstPageContent)
- },
- //选择信息栏显示模块
- selExamInfoStyle: function ($this, singleStatus) {
- var self = this
- let value = $this.attr('data-value');
- self.examInfoConfig[value] = singleStatus;
- },
- //更新label显示文本
- refrushPageLabel: function () {
- var self = this
- $('.pageLabel').each(function (index, $label) {
- var curTotalPage = index + 1
- var currentPaper = Math.ceil((index + 1) / (self.columns * 2))
- //第一张纸 正面1 正面2 第一张至反面1 反面2
- var paperDirection =
- (curTotalPage % (self.columns * 2)
- ? curTotalPage % (self.columns * 2)
- : self.columns * 2) <= self.columns
- ? '正面'
- : '反面'
- var pageForPaperDirection =
- curTotalPage % self.columns ? curTotalPage % self.columns : self.columns
- var currentPaperPage = paperDirection + pageForPaperDirection
- var labelHtml = self.tpls.pageLabelTpl.substitute({
- currentPage: curTotalPage,
- totalPage: self.totalPage,
- currentPaper: currentPaper,
- currentPaperPage: currentPaperPage
- })
- $(this).html(labelHtml)
- })
- },
- //重新计算同一题相同模块的
- //存储当前超出缺没有被执行超出事件的模块
- forgetOverPage: null,
- saveForgetPage: function (forgetPage) {
- var self = this
- //之前当前被遗忘的分页在前面,就可以直接替换
- if (self.forgetOverPage) {
- if (forgetPage.index() < self.forgetOverPage.index()) {
- self.forgetOverPage = forgetPage
- }
- } else {
- self.forgetOverPage = forgetPage
- }
- },
- resetPrevEditorContent: function ($surplusModule, $prevModule) {
- var self = this
- var surplusModuleContentHeight = self.calcEditorContentHeight(
- $surplusModule.find('.w-e-text')
- )
- var prevPage = $prevModule.closest('.pageContent')
- var prevPageContentHeight = prevPage.height() - self.pagePadding * 2
- //内容区域
- var $prevContentArea = $prevModule.find('.w-e-text-container')
- var prevEditorIndex = $prevModule.attr('data-editorIndex')
- var surplusEditorIndex = $surplusModule.attr('data-editorIndex')
- var surplusEditorContent = self.editorArea[
- 'editor' + surplusEditorIndex
- ].txt
- .html()
- .clearFixible()
- var prevEditorContent = self.editorArea['editor' + prevEditorIndex].txt
- .html()
- .clearFixible()
- var prevCalcHeight = $prevContentArea.height() + surplusModuleContentHeight
- self.editorArea['editor' + prevEditorIndex].txt.html(
- (
- prevEditorContent +
- surplusEditorContent +
- self.tpls.flexibleIconTpl
- ).replace(self.replaceEditorRegexp, '')
- )
- $prevContentArea.height(prevCalcHeight)
- if (self.getOverHeight($prevModule) > 0) {
- //之前当前被遗忘的分页在前面,就可以直接替换
- self.saveForgetPage(prevPage)
- }
- },
- /**
- * 删除一个分页超出的部分
- * @param {*} $delBtn 删除按钮
- * @param {el} type 下面两种类型的值 over surplus
- * @param {boolean} isUserTrigger 是否用户主动手动触发---触发
- * 1 上一页有超出模块,下一页的补充模块需要删除的情况
- * 2 上一页有剩余空间,下一页的补充模块一样需要删除的情况
- * 两种情况计算当前需要删除的补充模块的上一个模块的方式有所不同
- */
- //判断是不是补充模块
- isSurplusModule: function (module) {
- return typeof module.attr('isSurplus') === 'string'
- },
- //需要把内容部分全部移到上面的部分,然后上面的高度要重置一下
- delPageOverPart: function ($delBtn, type, isUserTrigger) {
- var self = this
- var answerModel = $delBtn.closest('.short-answer')
- var delModel = $delBtn.closest('.module')
- var delPage = delModel.closest('.pageContent')
- var prevPage = delPage.prev()
- //默认上一页有超出模块的时候计算方式
- var memoryPrevModule = delModel
- .closest('.answerModule')
- .prev('.answerModule')
- .children('.module:last()')
- var prevPageLastEditor = memoryPrevModule.children('.editorContent')
- //如果是上一页有剩余空间才来的话
- if (type === 'surplus') {
- var loopPrevPage = delPage.prev()
- while (!memoryPrevModule.length) {
- memoryPrevModule = loopPrevPage.find('.module:last()')
- loopPrevPage = loopPrevPage.prev()
- }
- }
- self.resetPrevEditorContent(delModel, memoryPrevModule)
- prevPageLastEditor.height(
- prevPageLastEditor.height() - self.modulePaddingBottom
- )
- delModel.remove()
- self.updatePageElement(delPage, answerModel)
- //判断上一个模块是否是第一个链接模块
- // if (prevPageLastModule.attr('data-linkparm') === '1') {
- // prevPageLastModule.removeAttr('data-linkparm')
- // }
- if (!answerModel.children('.module').length) answerModel.remove()
- if (isUserTrigger) {
- self.changePrintArea(delPage)
- }
- },
- /**
- * 获取超出当前page的模块 作答大题区域模块 作答小题区域模块
- * @return {answerModule,subjectModule}
- */
- getOverModule: function (curPageEl) {
- var self = this
- var overPart = false
- //当前第几页,用做后面计算的高度距离的倍数
- var times = curPageEl.index() + 1
- //判断超出当前页面的条件
- var overHeight =
- self.pageHeight * times + self.layoutPadding - self.pagePadding
- //判断当前区域是否超出
- function isOver(el) {
- var moduleTop =
- $(el).outerHeight() + $(el).offset().top + $('#contentWrap').scrollTop()
- return moduleTop >= overHeight
- }
- /**
- * 1 判断当前页面里面的答题区域内容是否超过了当前页面所能承受的内容的高度
- * a 如果超出了,从当前移动的那个模块开始向后判断,取出所有超出的模块
- * I 在下一页的排版中,如果下一页存在直接插入最前面,如果不存在,直接新建一页==>>然后循环【1】操作
- * b 如果没有超出直接退出
- */
- //需要判断当前page里面所有模块是否有超出
- //当前答题卡区域
- var curDtkPartEl = curPageEl.children('.dtk-content')
- if (curDtkPartEl.height() + self.pagePadding * 2 >= self.pageHeight) {
- //区分原题题干和答题区域
- var shortAnswerEl = [].splice.call(
- curDtkPartEl.children('.answerModule'),
- 0
- )
- //var shortAnswerEl = objectiveModule.concat(shortANswerModule)
- for (var i = 0, ilen = shortAnswerEl.length; i < ilen; i++) {
- var shortAnswerItem = $(shortAnswerEl[i])
- //找到第一个超过当前页面的元素,把这个以及以后的模块提取出来在下一个版面进行重新排版
- //得到第一个大题的index 第一个大题下面小题的index
- if (isOver(shortAnswerItem)) {
- var answerType = shortAnswerItem.attr('data-type')
- var isChooseAnswer = answerType === 'chooseAnswer'
- var hasObjective = shortAnswerItem.find('.originSubjectInfo').length
- var isObjective = answerType === 'objective'
- var childrenSelector =
- isChooseAnswer && hasObjective
- ? ''
- : isObjective
- ? '.objectiveItem'
- : '.module'
- var moduleEl = $(shortAnswerItem).children(childrenSelector)
- for (var m = 0, mlen = moduleEl.length; m < mlen; m++) {
- var moduleItem = moduleEl.eq(m)
- if (isOver(moduleItem)) {
- var subjectModule = null
- //选做题如果题干信息超出的话,也特殊模块超出,因为选做题模块可能很长
- var objectiveModule = null
- if (isChooseAnswer) {
- if (moduleItem[0].tagName === 'H3') {
- objectiveModule = moduleItem
- if (moduleItem.next().length) {
- subjectModule = moduleItem.next()
- }
- } else {
- subjectModule = moduleItem
- }
- } else {
- subjectModule = moduleItem
- }
- overPart = {
- curPage: curPageEl,
- //当前超出的answerModule
- answerModule: shortAnswerItem,
- //当前超出的module
- subjectModule: subjectModule,
- //当前超出的选做题题干信息
- objectiveModule: objectiveModule
- }
- return overPart
- }
- }
- }
- }
- }
- return overPart
- },
- //获取超出模块高度
- getOverHeight: function (el) {
- var self = this
- var curPageEl = $(el).closest('.pageContent')
- //当前第几页,用做后面计算的高度距离的倍数
- var times = curPageEl.index() + 1
- var overHeight =
- self.pageHeight * times + self.layoutPadding - self.pagePadding
- var moduleTop =
- $(el).outerHeight() + $(el).offset().top + $('#contentWrap').scrollTop()
- return moduleTop - overHeight - 4
- },
- //根据缩放的要求拓宽需要打印的区域
- /*
- * 1拓宽打印区域
- * 2减小打印区域
- */
- changePrintArea: function (curPageEl) {
- var self = this
- if (self.forgetOverPage && self.forgetOverPage[0] === curPageEl[0]) {
- self.forgetOverPage = null
- }
- //找出超出的区域
- var overPart = self.getOverModule(curPageEl)
- if (overPart) {
- //填空题选择题特殊对待
- var moduleType = overPart.answerModule.attr('data-type')
- if (moduleType === 'fillInBlank') {
- self.addPrintForFillInBlank(curPageEl, overPart)
- } else if (~moduleType.indexOf('Select') ||~moduleType.indexOf('uncertainOption')) {
- self.addPrintForSelect(curPageEl, overPart, moduleType)
- } else if (moduleType === 'objective') {
- self.addPrintForObjective(curPageEl, overPart)
- self.judegeImgsLoaded('.objectiveItem')
- } else {
- self.addPrintForAnswer(curPageEl, overPart)
- }
- } else {
- self.reducePrintArea(curPageEl)
- }
- },
- showExamInfoHtml: function () {
- if(!this.hasPaperMsg){
- return false
- }
- let examInfoHtml = '';
- if (this.examInfoConfig.wpTimes) {
- if(this.examInfoConfigText.wpTimes == undefined) {
- this.examInfoConfigText.wpTimes = ''
- }
- examInfoHtml += '<span>时间:<input class="input-examInfo time" name="wpTimes" maxlength="3" value="' + this.examInfoConfigText.wpTimes + '"></input>分钟</span>'
- }
- if (this.examInfoConfig.fullScore) {
- if(this.examInfoConfigText.fullScore == undefined) {
- this.examInfoConfigText.fullScore = ''
- }
- examInfoHtml += '<span>满分:<input readonly="readonly" class="input-examInfo fraction" name="fullScore" maxlength="3" value="' + this.examInfoConfigText.fullScore + '"></input>分</span>'
- }
- if (this.examInfoConfig.wpAuthor) {
- if(this.examInfoConfigText.wpAuthor == undefined) {
- this.examInfoConfigText.wpAuthor = ''
- }
- examInfoHtml += '<span>命卷人:<input class="input-examInfo" name="wpAuthor" maxlength="9" value="' + this.examInfoConfigText.wpAuthor + '"></input></span>'
- }
- if (this.examInfoConfig.wpReviewer) {
- if(this.examInfoConfigText.wpReviewer == undefined) {
- this.examInfoConfigText.wpReviewer = ''
- }
- examInfoHtml += '<span>审核人:<input class="input-examInfo" name="wpReviewer" maxlength="9" value="' + this.examInfoConfigText.wpReviewer + '"></input></span>'
- }
- examInfoHtml += '<div class="btn-examInfo"></div>'
- $('#examInfo').html(examInfoHtml);
- if (examInfoHtml.length < 33) {
- $('#hasPaperMsg').find('.h_radioItem').removeClass('checked')
- $('#hasPaperMsg').find('.h_radioItem').eq(1).addClass('checked')
- $('#examInfo').css('display', 'none')
- } else {
- $('#hasPaperMsg').find('.h_radioItem').removeClass('checked')
- $('#hasPaperMsg').find('.h_radioItem').eq(0).addClass('checked')
- $('#examInfo').css('display', 'flex')
- }
- },
- //重新计算填空题渲染数据,改变填空题手动打分分值样式
- calcFillInBlankData: function (modelId, scoreStyle) {
- var fillInBlankData = this.questionMap[modelId].pages
- for (var pageKey in fillInBlankData) {
- if (fillInBlankData[pageKey].length) {
- fillInBlankData[pageKey] = fillInBlankData[pageKey].map(function (
- item
- ) {
- item.scoreStyle = scoreStyle
- return item
- })
- }
- }
- },
- //题干区域超出
- addPrintForObjective: function (curPageEl, overPart) {
- var self = this
- var curPageIndex = curPageEl.index()
- var times = curPageIndex + 1
- var part = overPart.subjectModule
- //判断超出简答题区域
- var overAnswerModule = overPart.answerModule
- //超出区域模块的题型
- var overAnswerModuleType = overAnswerModule.attr('data-type') || 'objective'
- var resetEditorIds = []
- //简答小题
- var subjectHtml = ''
- //合并的简答题区域
- var overAnswerHtml = ''
- //通过缩放确定每个页面需要移除的元素
- var removeElements = []
- var nextPageEl = curPageEl.next()
- //首先判断是要删除下一个分页的补充模块如果下一个分页存在的话
- var nextPageFirstModule = null
- if (nextPageEl.length) {
- nextPageFirstModule = nextPageEl.find('.module').eq(0)
- }
- while (part.length) {
- subjectHtml += self.addNewModuleForObjective(
- part,
- overAnswerModuleType,
- removeElements
- )
- part = part.next()
- }
- //根据module 的data-type来确定使用的module 模板
- var tplForTypeMap = {
- singleSelect: 'selectTpl',
- moreSelect: 'selectTpl',
- fillInBlank: 'answerModulForFillInBlankTpl',
- answer: 'answerModuleTpl',
- chooseAnswer: 'answerModuleTpl',
- mustAnswer: 'answerModuleTpl',
- objective: 'objectiveWrapTpl'
- }
- //超出模块
- while (overAnswerModule.length) {
- var editModuleHtml = ''
- var moduleTitle = ''
- overAnswerModuleType = overAnswerModule.attr('data-type')
- var modelId = overAnswerModule.attr('data-modelId')
- var isObjective = overAnswerModuleType === 'objective'
- var direction = overAnswerModule.attr('data-direction')
- var isSelect = ~overAnswerModuleType.indexOf('Select')
- //如果是当前超出模块,则直接用上面的多余的moduleHtml来填充
- //否则,直接用answerModule的内容来填充
- if (overAnswerModule[0] === overPart.answerModule[0]) {
- editModuleHtml = subjectHtml
- } else {
- //如果下一个大模块是选做题,并且只有选做题提文字信息
- if (
- overAnswerModuleType === 'chooseAnswer' &&
- !overAnswerModule.find('.module').length &&
- overAnswerModule.children().length &&
- overAnswerModule.find('.originSubjectInfo').length
- ) {
- var objectiveReg = /<div class="originSubjectInfo">(.*)<\/div>/
- var objectiveRegG = /<div class="originSubjectInfo">(.*)<\/div>/g
- //超出的选做题标题元素
- var overAnswerModuleH3Html = overAnswerModule.find('h3')[0].outerHTML
- //超出选做题标题的题干内容
- var overAnswerModuleH3ObjectiveHtml = overAnswerModuleH3Html.match(
- objectiveReg
- )[1]
- var nextPageFirstH3 = nextPageFirstAnswerModule.children('h3')
- if (nextPageFirstH3.length) {
- var nextPageFIrstH3ObjectiveHtml = nextPageFirstH3
- .children('.originSubjectInfo')
- .html()
- //如果下一页存在选做题h3 则 需要拿当前的h3 做替换
- nextPageFirstH3[0].outerHTML = overAnswerModuleH3Html.replace(
- objectiveRegG,
- '<div class="originSubjectInfo">' +
- overAnswerModuleH3ObjectiveHtml +
- nextPageFIrstH3ObjectiveHtml +
- '</div>'
- )
- } else {
- //如果下一页没有标题,直接插入到下一个模块的
- // subjectHtml = nextPageFirstH3.children('.originSubjectInfo').prepend(overAnswerModule[0].outerHTML.replace(objectiveRegG,'<div class="originSubjectInfo">'+curPageH3ObjectiveHtml+'<\/div>'))
- subjectHtml = overAnswerModule.children('h3')[0].outerHTML
- nextPageFirstAnswerModule.prepend(subjectHtml)
- }
- overAnswerModule.remove()
- break
- }
- var isSelect = ~overAnswerModuleType.indexOf('Select')
- var isFillInBlank = overAnswerModuleType === 'fillInBlank'
- self.resetPageDataForSubject(
- overAnswerModule,
- times,
- resetEditorIds,
- nextPageEl
- )
- if (isSelect || isFillInBlank) {
- moduleTitle = self.titleHtml(self.questionMap[modelId].bigTitle)
- if (isSelect) {
- editModuleHtml =
- '<div class="single-option more-option clearfix">' +
- overAnswerModule.find('.single-option').html() +
- '</div>'
- }
- }
- if (!isSelect) editModuleHtml = overAnswerModule.html()
- removeElements.push(overAnswerModule)
- }
- overAnswerHtml += self.tpls[
- tplForTypeMap[overAnswerModuleType]
- ].substitute({
- editModule: editModuleHtml,
- moduleType: overAnswerModuleType,
- selectType: overAnswerModuleType,
- selectContent: editModuleHtml,
- direction: direction,
- title: moduleTitle
- })
- overAnswerModule = overAnswerModule.next()
- }
- /**
- * 【优化】
- * 模块删除关系需要优化
- */
- removeElements.forEach(function (element) {
- $(element).remove()
- })
- if (!overPart.answerModule.children('.objectiveItem').length)
- overPart.answerModule.remove()
- //是否存在下一个分页
- if (nextPageEl.length) {
- nextPageEl.children('.dtk-content').prepend(overAnswerHtml)
- if (self.isSurplusModule(nextPageFirstModule)) {
- self.delPageOverPart(nextPageFirstModule.children('.delBtn'), 'over')
- }
- } else {
- self.addPage(overAnswerHtml)
- nextPageEl = $('#printcontent').children('.pageContent:last()')
- }
- //重置富文本
- resetEditorIds.length && self.resetAddNewModuleEditor(resetEditorIds)
- //递归轮询判断
- self.changePrintArea(nextPageEl)
- },
- //超出的大模块计算
- addPrintForAnswerModule: function (
- overPart,
- curPageIndex,
- subjectHtml,
- resetEditorIds,
- removeElements,
- nextPageEl
- ) {
- var self = this
- var moduleTitle = ''
- var overAnswerHtml = ''
- var overAnswerModule = overPart.answerModule
- //根据module 的data-type来确定使用的module 模板
- var tplForTypeMap = {
- singleSelect: 'selectAnswerTpl',
- moreSelect: 'selectAnswerTpl',
- uncertainOption: 'selectAnswerTpl',
- fillInBlank: 'answerModulForFillInBlankTpl',
- answer: 'answerModuleTpl',
- chooseAnswer: 'answerModuleTpl',
- mustAnswer: 'answerModuleTpl',
- objective: 'objectiveWrapTpl'
- }
- //超出模块 选择-填空
- while (overAnswerModule.length) {
- var editModuleHtml = ''
- var overAnswerModuleType = overAnswerModule.attr('data-type')
- var modelId = overAnswerModule.attr('data-modelId')
- var direction = overAnswerModule.attr('data-direction')
- //如果是当前超出模块,则直接用上面的多余的moduleHtml来填充
- //否则,直接用answerModule的内容来填充
- if (overAnswerModule[0] === overPart.answerModule[0]) {
- editModuleHtml = subjectHtml
- } else {
- //如果下一个大模块是选做题,并且只有选做题提文字信息
- if (
- overAnswerModuleType === 'chooseAnswer' &&
- !overAnswerModule.find('.module').length &&
- overAnswerModule.children().length &&
- overAnswerModule.find('.originSubjectInfo').length
- ) {
- var objectiveReg = /<div class="originSubjectInfo">(.*)<\/div>/
- var objectiveRegG = /<div class="originSubjectInfo">(.*)<\/div>/g
- //超出的选做题标题元素
- var overAnswerModuleH3Html = overAnswerModule.find('h3')[0].outerHTML
- //超出选做题标题的题干内容
- var overAnswerModuleH3ObjectiveHtml = overAnswerModuleH3Html.match(
- objectiveReg
- )[1]
- var nextPageFirstH3 = nextPageFirstAnswerModule.children('h3')
- if (nextPageFirstH3.length) {
- var nextPageFIrstH3ObjectiveHtml = nextPageFirstH3
- .children('.originSubjectInfo')
- .html()
- //如果下一页存在选做题h3 则 需要拿当前的h3 做替换
- nextPageFirstH3[0].outerHTML = overAnswerModuleH3Html.replace(
- objectiveRegG,
- '<div class="originSubjectInfo">' +
- overAnswerModuleH3ObjectiveHtml +
- nextPageFIrstH3ObjectiveHtml +
- '</div>'
- )
- } else {
- //如果下一页没有标题,直接插入到下一个模块的
- // subjectHtml = nextPageFirstH3.children('.originSubjectInfo').prepend(overAnswerModule[0].outerHTML.replace(objectiveRegG,'<div class="originSubjectInfo">'+curPageH3ObjectiveHtml+'<\/div>'))
- subjectHtml = overAnswerModule.children('h3')[0].outerHTML
- nextPageFirstAnswerModule.prepend(subjectHtml)
- }
- overAnswerModule.remove()
- break
- }
- var isSelect = ~overAnswerModuleType.indexOf('Select')
- var isFillInBlank = overAnswerModuleType === 'fillInBlank'
- self.resetPageDataForSubject(
- overAnswerModule,
- curPageIndex,
- resetEditorIds,
- nextPageEl
- )
- if (isSelect || isFillInBlank) {
- moduleTitle = self.titleHtml(self.questionMap[modelId].bigTitle)
- if (isSelect) {
- editModuleHtml = overAnswerModule.html()
- }
- }
- if (!isSelect) editModuleHtml = overAnswerModule.html()
- removeElements.push(overAnswerModule)
- }
- overAnswerHtml += self.tpls[
- tplForTypeMap[overAnswerModuleType]
- ].substitute({
- editModule: editModuleHtml,
- moduleType: overAnswerModuleType,
- selectType: overAnswerModuleType,
- selectContent: editModuleHtml,
- direction: direction,
- title: moduleTitle,
- modelId: modelId
- })
- overAnswerModule = overAnswerModule.next()
- }
- return overAnswerHtml
- },
- /**
- * 超出情况
- * ** 如果下一页的模块有补充模块,最终都需要删除,增加新的补充模块
- * 1 如果剩余解答区域小于默认解答区域高度--则直接全部拿到下一页,高度和下一个区域的补充模块高度累加,下一页的补充模块自动移除
- * 2 如果剩余解答区域大于默认解答区域高度--则超出部分高度和之前下一区域的补充模块高度累加,下一页补充模块高度自动移除
- * 缺失情况
- * 1 如果剩余空间大于下一个模块
- * -如果是补充模块,直接拿上来,高度累加该补充模块的高度
- * -如果不是补充模块,直接拿上来,然后递归下一页的下一个模块,直到该页面没有剩余空间
- * 2 如果剩余空间小于下一个模块
- * a如果有标题
- * - 如果小于标题加题号的空间,则不动,递归下一页的缺失情况
- * - 如果大于标题加题号的空间,则直接拿上去,下一页保留多余高度的作答区域 (可以高度缩小直接拿上去,然后再补一个剩余高度的拓展模块)
- * b如果没有标题(小题或者补充模块)
- * - 如果下一页的第一个模块是补充模块,直接缩小对应的高度,上一个页面增加对应的高度
- * - 如果下一个面是小题模块,则直接拿上去,下一页保留多余高度的作答区域 (可以高度缩小直接拿上去,然后再补一个剩余高度的拓展模块)
- */
- addPrintForAnswer: function (curPageEl, overPart) {
- var self = this
- var curPageIndex = curPageEl.index()
- var times = curPageIndex + 1
- var part = overPart.subjectModule
- //判断超出简答题区域
- var overAnswerModule = overPart.answerModule
- //超出区域模块的题型
- var overAnswerModuleType = overAnswerModule.attr('data-type')
- //简答小题
- var subjectHtml = ''
- //合并的简答题区域
- var overAnswerHtml = ''
- //判断是否是当前鼠标操作答题区域的坐标
- //var curOperation = part[0] === self.curDtkModelEl[0]
- //通过缩放确定每个页面需要移除的元素
- var removeElements = []
- //需要重置富文本编辑功能区域的id
- var resetEditorIds = []
- //判断是否有需要新增的富文本
- var hasNewRichText = false
- //超出的富文本的内容部分
- var editorOverContent = ''
- var nextPageEl = curPageEl.next()
- //首先判断是要删除下一个分页的补充模块如果下一个分页存在的话
- var nextPageFirstModule = null
- var nextPageFirstAnswerModule = null
- if (nextPageEl.length) {
- nextPageFirstModule = nextPageEl.find('.module').eq(0)
- nextPageFirstAnswerModule = nextPageEl.find('.answerModule').eq(0)
- }
- while (part && part.length) {
- /**
- * 如果是当前缩放的模块超出,直接在下一模块新建当前模块的子模块
- * 如果不是,则直接拷贝超出模块所有内容到下一页
- */
- //当前缩放的模块没有超出规定区域 则超出的所有模块全局复制
- if (part !== overPart.subjectModule) {
- //1 新增新模块resetEditorIds removeElements
- subjectHtml += self.addNewModule(
- part,
- overAnswerModuleType,
- resetEditorIds,
- removeElements
- )
- } else {
- //如果剩余模块的高度小于 最小高度,直接放到下一页
- var surplusHeight = self.getOverHeight(part)
- if (part.outerHeight() - surplusHeight <= 100) {
- //判断超出简答题区域
- var overAnswerModule = part.closest('.answerModule')
- //超出区域模块的题型
- var overAnswerModuleType = overAnswerModule.attr('data-type')
- //1 新增新模块resetEditorIds removeElements
- subjectHtml += self.addNewModule(
- part,
- overAnswerModuleType,
- resetEditorIds,
- removeElements
- )
- } else {
- //1 拓展新模块
- hasNewRichText = true
- //当前超出的模块height
- //计算超出文本内容区域,同时原来的富文本区域对应超出的内容
- var overContentObj = self.getOverContent(
- part,
- surplusHeight,
- removeElements
- )
- editorOverContent = overContentObj.overContent
- var editorOverHeight = overContentObj.overHeight
- subjectHtml += self.expandModule(part, editorOverHeight)
- }
- }
- part = part.next()
- }
- //当前超出小模块只是选做题题干信息
- if (!subjectHtml) {
- var removeTemps = []
- var $itemBodys = overPart.objectiveModule.find('.questionItemBody')
- for (var i = 0; i < $itemBodys.length; i++) {
- var $itemBody = $itemBodys.eq(i)
- if (self.getOverHeight($itemBody) > 0) {
- subjectHtml += $itemBody[0].outerHTML
- removeTemps.push($itemBody)
- }
- }
- var objectiveReg = /<div class="originSubjectInfo">(.*)<\/div>/
- var objectiveRegG = /<div class="originSubjectInfo">(.*)<\/div>/g
- var curPageH3ObjectiveHtml = overPart.objectiveModule[0].outerHTML.match(
- objectiveReg
- )[1]
- if (removeTemps.length >= $itemBodys.length) {
- //如果下一页存在标题
- var nextPageFirstH3 = nextPageFirstAnswerModule.children('h3')
- if (nextPageFirstH3.length) {
- var nextPageFirstH3Html = nextPageFirstH3
- .children('.originSubjectInfo')
- .html()
- subjectHtml = overPart.objectiveModule[0].outerHTML.replace(
- objectiveRegG,
- '<div class="originSubjectInfo">' +
- curPageH3ObjectiveHtml +
- nextPageFirstH3Html +
- '</div>'
- )
- nextPageFirstH3[0].outerHTML = subjectHtml
- } else {
- subjectHtml = overPart.objectiveModule[0].outerHTML.replace(
- objectiveRegG,
- '<div class="originSubjectInfo">' +
- curPageH3ObjectiveHtml +
- '</div>'
- )
- nextPageFirstAnswerModule.prepend(subjectHtml)
- }
- overPart.objectiveModule.closest('.answerModule').remove()
- } else {
- //如果下一页存在标题
- var nextPageFirstH3 = nextPageFirstAnswerModule.children('h3')
- if (nextPageFirstH3.length) {
- nextPageFirstH3.children('.originSubjectInfo').prepend(subjectHtml)
- } else {
- //overPart.objectiveModule[0].outerHTML.replace(objectiveRegG,'');
- nextPageFirstAnswerModule.prepend(
- '<h3><div class="originSubjectInfo">' + subjectHtml + '</div></h3>'
- )
- }
- removeTemps.forEach(function (el) {
- $(el).remove()
- })
- }
- self.changePrintArea(nextPageEl)
- return
- }
- //计算超出大模块
- overAnswerHtml += self.addPrintForAnswerModule(
- overPart,
- times,
- subjectHtml,
- resetEditorIds,
- removeElements,
- nextPageEl
- )
- //重置上一页第一个超出模块的高度 = pageHeight - subject.offset().top - subjectModullePadding的模块高度
- //上一个页面其他剩余模块的所占的高度
- //如果上一页本来就是一个超出的模块,那modulePadding 就要少点了打分区域的高度
- var linkparm = overPart.subjectModule.attr('data-linkparm')
- var isLinkparmModule = linkparm && linkparm !== '1'
- var preOtherModuleHeight =
- overPart.subjectModule.offset().top +
- $('#contentWrap').scrollTop() +
- self.pagePadding +
- self.modulePadding -
- (isLinkparmModule ? 30 : 0)
- //上一个页面第一个超出模块所能占用的高度
- var preFirstOverModuleHeight =
- self.pageHeight * times - preOtherModuleHeight
- overPart.subjectModule
- .children('.editorContent')
- .height(preFirstOverModuleHeight)
- // overPart.subjectModule
- // .children('.editorContent')
- // .css('min-height',preFirstOverModuleHeight)
- /**
- * 【优化】
- * 模块删除关系需要优化
- */
- removeElements.forEach(function (element) {
- $(element).remove()
- })
- if (
- !overPart.answerModule.children('.module').length &&
- !overPart.answerModule.find('h3').length
- )
- overPart.answerModule.remove()
- //是否存在下一个分页
- if (nextPageEl.length) {
- nextPageEl.children('.dtk-content').prepend(overAnswerHtml)
- } else {
- self.addPage(overAnswerHtml)
- nextPageEl = $('#printcontent').children('.pageContent:last()')
- }
- //curOperation
- hasNewRichText &&
- self.createShortAnswer(editorIndexUp != '' ? editorIndexUp : self.editorIndex, editorOverContent)
- //下一页存在上一页最后一个模块的拓展模块,也必须等上一页的新拓展(超出模块)放到下一页之后再执行老拓展模块的删除
- //因为删除功能会进行下一页是否有内容模块,对下一页整个页面进行选择性的删除,如果删除了下一页,超出的内容就不知道放到哪里了
- if (nextPageFirstModule && self.isSurplusModule(nextPageFirstModule)) {
- self.delPageOverPart(nextPageFirstModule.children('.delBtn'), 'over')
- }
- //重置富文本
- self.resetAddNewModuleEditor(resetEditorIds)
- //递归轮询判断
- self.changePrintArea(nextPageEl)
- },
- //填空题超出
- addPrintForFillInBlank: function (curPageEl, overPart) {
- var self = this
- var part = overPart.subjectModule
- var modelId = overPart.answerModule.attr('data-modelId')
- var curPageIndex = curPageEl.index() + 1
- //合并的简答题区域
- var overAnswerHtml = ''
- //通过缩放确定每个页面需要移除的元素
- var removeElements = []
- //需要重置富文本编辑功能区域的id
- var resetEditorIds = []
- var nextPageEl = curPageEl.next()
- //首先判断是要删除下一个分页的补充模块如果下一个分页存在的话
- var nextPageFirstModule = null
- if (nextPageEl.length) {
- nextPageFirstModule = nextPageEl.find('.module').eq(0)
- //按照模块id 归类删除
- nextPageEl.find('.answerModule').each(function () {
- if ($(this).attr('data-modelId') === modelId) {
- $(this).remove()
- }
- })
- }
- //当前超出的模块height
- var overHeight = self.getOverHeight(part)
- //一行几栏
- var $firstColForInfoEl = part.children('.subjectCol')
- var dataColumns = $firstColForInfoEl.attr('data-column')
- var scoreStyle = $firstColForInfoEl.attr('data-scoreStyle')
- var columns = dataColumns ? +dataColumns : 1
- var rowLineHeight = $firstColForInfoEl.attr('data-rowlineheight')
- //计算每个填空题item的高度 默认40 padding 10 border 1
- var fillInBlankItemHeight = (+rowLineHeight || 40) + 11
- //当前模块有几个填空题
- var fillInBlankCount = part.find('.subjectItem').length
- //最后一排几个
- var lastRowCount =
- fillInBlankCount % columns ? fillInBlankCount % columns : columns
- //需要复制几个填空题
- //超出的行数量
- var overRows = Math.ceil(overHeight / fillInBlankItemHeight)
- //如果最后一行计算最后一行有几个
- var copyFillInBlankLength = lastRowCount + (overRows - 1) * columns
- var curModuleDataIndex = 'page' + curPageIndex
- var nextExpendDataIndex = 'page' + (curPageIndex + 1)
- var modelData = self.questionMap[modelId]
- var modelPagesData = modelData.pages
- var nextExpendDataLength = modelPagesData[curModuleDataIndex].length
- if(modelPagesData[curModuleDataIndex].length<1){
- let upModuleDataIndex = 'page' + (curPageIndex -1)
- modelPagesData[curModuleDataIndex] = modelPagesData[upModuleDataIndex]
- modelPagesData[upModuleDataIndex] = []
- nextExpendDataLength = modelPagesData[curModuleDataIndex].length
- }
- copyFillInBlankLength =
- copyFillInBlankLength > nextExpendDataLength
- ? nextExpendDataLength
- : copyFillInBlankLength
- //原页面保留的题目
- modelPagesData[nextExpendDataIndex] =
- modelPagesData[nextExpendDataIndex] || []
- let modelPagesDatas = JSON.parse(JSON.stringify(modelPagesData))
- modelPagesData = modelPagesDatas
- modelPagesData[nextExpendDataIndex] = modelPagesData[curModuleDataIndex]
- .splice(nextExpendDataLength - copyFillInBlankLength)
- .concat(modelPagesData[nextExpendDataIndex])
- modelData.pages = modelPagesData
- // var renderData = self.formatRenderDataForFillInBlank(modelPagesData[curModuleDataIndex], modelData.scoreStyle)
- var originPageRetainHtml = self.getFillInBlankHtml(
- self.formatRenderDataForFillInBlank(modelPagesData[curModuleDataIndex], modelData.scoreStyle)
- )
- var overFillInBlankItemsHtml = self.getFillInBlankHtml(
- // modelPagesData[nextExpendDataIndex]
- self.formatRenderDataForFillInBlank(modelPagesData[nextExpendDataIndex], modelData.scoreStyle)
- )
- if (!originPageRetainHtml) {
- removeElements.push(part.closest('.completion-topic'))
- } else {
- part.find('.subjectCol').html(originPageRetainHtml)
- }
- //超出的放在新页面上 如果原页面没有保留模块则需要加上title 并且需要setting按钮
- overFillInBlankItemsHtml =
- self.titleHtml(!originPageRetainHtml ? modelData.bigTitle : '') +
- self.tpls.fillInBlankContentTpl.substitute({
- addFillInBlankHtml: overFillInBlankItemsHtml,
- columns: columns,
- scoreStyle: scoreStyle,
- rowLineHeight: rowLineHeight,
- settingBtn: !originPageRetainHtml
- ? self.tpls.fillInBlankSettingBtnTpl
- : ''
- })
- //计算超出大模块
- //判断超出简答题区域
- var overAnswerModule = overPart.answerModule
- overAnswerHtml += self.addPrintForAnswerModule(
- overPart,
- curPageIndex,
- overFillInBlankItemsHtml,
- resetEditorIds,
- removeElements,
- nextPageEl
- )
- /**
- * 【优化】
- * 模块删除关系需要优化
- */
- removeElements.forEach(function (element) {
- $(element).remove()
- })
- //是否存在下一个分页
- if (nextPageEl.length) {
- nextPageEl.children('.dtk-content').prepend(overAnswerHtml)
- if (self.isSurplusModule(nextPageFirstModule)) {
- self.delPageOverPart(nextPageFirstModule.children('.delBtn'), 'over')
- }
- } else {
- self.addPage(overAnswerHtml)
- nextPageEl = $('#printcontent').children('.pageContent:last()')
- }
- //重置富文本
- self.resetAddNewModuleEditor(resetEditorIds)
- //递归轮询判断
- self.changePrintArea(nextPageEl)
- },
- //选择题超出
- /**
- *
- * @param {*} curPageEl
- * @param {*} overPart
- */
- addPrintForSelect: function (curPageEl, overPart, type) {
- var self = this
- //是否存在下一页
- var nextPageEl = curPageEl.next()
- //超出选择题的题目
- var curPageIndex = curPageEl.index()+1
- // var curPageIndex = curPageEl.index()==0?curPageEl.index()+1:curPageEl.index()
- //合并的简答题区域
- var overAnswerHtml = ''
- //通过缩放确定每个页面需要移除的元素
- var removeElements = []
- //需要重置富文本编辑功能区域的id
- var resetEditorIds = []
- //当前超出的模块height
- var part = overPart.subjectModule
- var modelId = overPart.answerModule.attr('data-modelId')
- var modDataType = overPart.answerModule.attr('data-type')
- var selectItemType = overPart.answerModule.attr('data-direction')
-
- //模块数据
- var curModuleDataIndex = 'page' + curPageIndex
- var nextExpendDataIndex = 'page' + (curPageIndex + 1)
- var modelData = self.questionMap[modelId]
- var modelPagesData = modelData.pages
- if(modelPagesData[curModuleDataIndex].length<1){
- let upModuleDataIndex = 'page' + (curPageIndex -1)
- modelPagesData[curModuleDataIndex] = modelPagesData[upModuleDataIndex]
- modelPagesData[upModuleDataIndex] = []
- }
- //每小题的高度
- var overHeight = self.getOverHeight(part)
- // 单个选项高度
- let optItemHeight = overPart.answerModule.find('.single-option li').eq(0).outerHeight()
-
- //20 选择题一个题组的padding值
- var selectItemHeight = optItemHeight * 5 + 20
- if(selectItemType=='vertical'){
- selectItemHeight = optItemHeight + 20
- }
- //针对选择题竖版一行排几个
- var curConfigForLine =
- self.config[self.direction][self.hasBindingLine ? 'yesLine' : 'noLine']
- var rowLength = curConfigForLine[self.columns]
- //一共多少个选择ul module
- var optionsModuleLength = part.children('.single-option').length
- //当前布局下面有几排
- var optionsRowLength = Math.floor(part.outerHeight() / selectItemHeight)
- //一排几个options 模块
- var optionsModule = rowLength / 5
- //最后一个排放几个选项
- // var lastRowOptionLength =
- // optionsModuleLength - (optionsRowLength - 1) * optionsModule
- var lastRowOptionLength =
- modelPagesData[curModuleDataIndex].length -
- (optionsRowLength - 1) * optionsModule * 5
- //如果当前页面超过一排的情况下,则超出的数量需要计算到最后一排没有排满的情况
- /**
- * 超出的计算单位以 一整排为单位
- * 每一排的一列以5题为单位 计算
- *
- */
- //计算超出多少小题
- var overSelectItemsLength
- var overRowLength = Math.ceil(overHeight / selectItemHeight)
- if (overRowLength <= 1) {
- overSelectItemsLength = lastRowOptionLength
- } else {
- overSelectItemsLength =
- (overRowLength - 1) * rowLength + lastRowOptionLength
- }
- var nextExpendDataLength = modelPagesData['page' + curPageIndex].length
- //超出的放在新页面上,顺表保存一份用来给下一次使用
- modelPagesData[nextExpendDataIndex] =
- modelPagesData[nextExpendDataIndex] || []
- let modelPagesDatas = JSON.parse(JSON.stringify(modelPagesData))
- modelPagesData = modelPagesDatas
- modelPagesData[nextExpendDataIndex] = modelPagesData[curModuleDataIndex]
- .splice(nextExpendDataLength - overSelectItemsLength)
- .concat(modelPagesData[nextExpendDataIndex])
- //首先判断是要删除下一个分页的补充模块如果下一个分页存在的话
- var nextPageFirstModule = null
- var nextPageFirstAnswerModule = null
- if (nextPageEl.length) {
- nextPageFirstAnswerModule = nextPageEl.find('.answerModule').eq(0)
- nextPageFirstModule = nextPageEl.find('.module').eq(0)
- //按照模块id 归类删除
- nextPageEl.find('.answerModule').each(function () {
- if ($(this).attr('data-modelId') === modelId) {
- $(this).remove()
- }
- })
- }
- //计算留在当前页面的和下一个页面的数据
- var originPageRetainHtml = self.getSingleSelectHtml(
- modelPagesData[curModuleDataIndex]
- )
- var overSelectItemsHtml = self.getSingleSelectHtml(
- modelPagesData[nextExpendDataIndex]
- )
- let btnHtml = '<div class="settingBtn" data-type="' + modDataType + '"></div><div class="delTopicBtn" data-type="' + modDataType + '">X</div>'
- if (!originPageRetainHtml) {
- removeElements.push(part.closest('.single-select'))
- } else {
- part.html(btnHtml + originPageRetainHtml)
- }
- overSelectItemsHtml =
- self.titleHtml(!originPageRetainHtml ? modelData.bigTitle : '') +
- self.tpls.selectContentTpl.substitute({
- selectContent: overSelectItemsHtml,
- moduleType: overPart.answerModule.attr('data-type')
- })
- var overAnswerModule = overPart.answerModule
- overAnswerHtml += self.addPrintForAnswerModule(
- overPart,
- curPageIndex,
- overSelectItemsHtml,
- resetEditorIds,
- removeElements,
- nextPageEl
- )
- /**
- * 【优化】
- * 模块删除关系需要优化
- */
- removeElements.forEach(function (element) {
- $(element).remove()
- })
- //是否存在下一个分页
- if (nextPageEl.length) {
- nextPageEl.children('.dtk-content').prepend(overAnswerHtml)
- if (self.isSurplusModule(nextPageFirstModule)) {
- self.delPageOverPart(nextPageFirstModule.children('.delBtn'), 'over')
- }
- } else {
- self.addPage(overAnswerHtml)
- nextPageEl = $('#printcontent').children('.pageContent:last()')
- }
- //重置富文本
- self.resetAddNewModuleEditor(resetEditorIds)
- //递归轮询判断
- self.changePrintArea(nextPageEl)
- },
- //重新计算分页数据
- resetPageDataForSubject: function (
- overAnswerModule,
- curPageIndex,
- resetEditorIds,
- nextPageEl
- ) {
- var self = this
- //page data index
- var curModuleDataIndex = 'page' + curPageIndex
- var nextExpendDataIndex = 'page' + (curPageIndex + 1)
- var overModuleType = overAnswerModule.attr('data-type')
- //如果下一个页面的第一个模块是选择题或者填空题的补充模块,则特殊处理
- var isSelect = ~overModuleType.indexOf('Select')
- var isFillInBlank = overModuleType === 'fillInBlank'
- if (isSelect || isFillInBlank) {
- var modelId = overAnswerModule.attr('data-modelId')
- // var modelPagesData = self.questionMap[modelId].pages
- var modelPagesData = JSON.parse(JSON.stringify(self.questionMap[modelId].pages))
- var bigTitle = self.questionMap[modelId].bigTitle
- var nextHasData = false
- modelPagesData[nextExpendDataIndex] =
- modelPagesData[nextExpendDataIndex] || []
- modelPagesData[curModuleDataIndex] =
- modelPagesData[curModuleDataIndex] || []
- var nextExpendData = modelPagesData[nextExpendDataIndex]
- var curModuleData = modelPagesData[curModuleDataIndex]
- if (nextExpendData.length) {
- nextHasData = true
- modelPagesData[nextExpendDataIndex] = curModuleData.concat(
- nextExpendData
- )
- } else {
- modelPagesData[nextExpendDataIndex] = [].concat(curModuleData)
- }
- modelPagesData[curModuleDataIndex].length = 0
- //如果是选择题下一页的数据处理
- if (isSelect) {
- if (nextHasData) {
- var $expendModule = overAnswerModule.find('.singleContent')
- var $nextRemoveModule = nextPageEl.find('.single-select').eq(0)
- var $expendHtml =
- self.titleHtml(bigTitle) +
- self.getSingleSelectHtml(modelPagesData[curModuleDataIndex])
- $expendModule.html($expendHtml)
- //如果下一页的第一个模块是当前超出这个模块的补充模块,则直接删除
- if ($nextRemoveModule.attr('data-modelId') === modelId) {
- $nextRemoveModule.remove()
- }
- }
- } else if (overModuleType === 'fillInBlank') {
- if (nextHasData) {
- var $expendModule = overAnswerModule.find('.subjectCol')
- var $nextRemoveModule = nextPageEl.find('.completion-topic').eq(0)
- var $expendHtml = self.getFillInBlankHtml(
- modelPagesData[nextExpendDataIndex]
- )
- $expendModule.html($expendHtml)
- //如果下一页的第一个模块是当前超出这个模块的补充模块,则直接删除
- if ($nextRemoveModule.attr('data-modelId') === modelId) {
- $nextRemoveModule.remove()
- }
- }
- }
- } else {
- //解答题重置富文本
- //2 判断是否有需要重置的富文本
- var editorEls = overAnswerModule.find('.editorContent')
- editorEls.length &&
- editorEls.each(function () {
- resetEditorIds.push({
- editorId: $(this).attr('id'),
- toolbarId: $(this).prev().attr('id')
- })
- })
- }
- },
- //新建分栏
- /**
- * @param {上一栏超出的模块html} overAnswerHtml
- */
- addPage: function (overAnswerHtml) {
- var self = this
- //新建的分页
- self.totalPage++
- self.currentPage++
- self.currentPaper = Math.ceil(self.totalPage / (self.columns * 2))
- //第一张纸 正面1 正面2 第一张至反面1 反面2
- var paperDirection =
- (self.totalPage % (self.columns * 2)
- ? self.totalPage % (self.columns * 2)
- : self.columns * 2) <= self.columns
- ? '正面'
- : '反面'
- var pageForPaperDirection =
- self.totalPage % self.columns ? self.totalPage % self.columns : 2
- var currentPaperPage = paperDirection + pageForPaperDirection
- //新建page
- var newPage = self.tpls.pageModuleTpl.substitute({
- subjectModule: overAnswerHtml,
- currentPage: self.currentPage,
- totalPage: self.totalPage,
- currentPaper: self.currentPaper,
- currentPaperPage: currentPaperPage
- })
- $('#printcontent').append(newPage)
- self.refrushPageLabel()
- },
- //重新初始化移动的富文本题目编辑区域
- resetAddNewModuleEditor: function (resetEditorIds) {
- var self = this
- /**
- * editorId
- * toolbarId
- */
- resetEditorIds.forEach(function (resetEditorId) {
- if (!$('#' + resetEditorId.toolbarId).length) return
- // var editorIndex = resetEditorId.editorId.match(/\d+/g)[0]
- // var reg = /(?<=editorContent).+(?=")/;
- var reg = /([^editorContent]+)$/;
- var editorIndex = resetEditorId.editorId.match(reg)[1];
- var editTopic = {};
- jQuery.each(self.questionMap, function (i, bigTopic) {
- jQuery.each(bigTopic.questions, function (j, Topic) {
- if (editorIndex == Topic.questionNum) {
- editTopic = Topic
- }
- })
- })
- let topicType = editTopic.questionTypeId
- if (topicType == 7) {
- topicType = editTopic.markQuestionType
- }
- $('#' + resetEditorId.toolbarId).html('')
- var editor = new self.EDITOR(
- '#' + resetEditorId.toolbarId,
- '#' + resetEditorId.editorId
- )
- editor.customConfig.menus = topicType == '7c' ? self.EDITOR_CONFIG_ZW : self.EDITOR_CONFIG
- editor.customConfig.onfocus = function () {
- if (!self.isCanEditCard) return
- $('#' + resetEditorId.editorId)
- .siblings('.toolbar')
- .addClass('seled')
- }
- editor.customConfig.onblur = function () {
- //如果当前答题卡模板不在编辑状态,或者 正在使用公式编辑器,都不用启动这个事件
- if (!self.isCanEditCard || self.formulaing) return
- $('#' + resetEditorId.editorId)
- .siblings('.toolbar')
- .removeClass('seled')
- //过滤所有的空标签 换行产生的标签
- var newEditorHtml = editor.txt
- .html()
- .replace(self.replaceEditorRegexp, '')
- editor.txt.html(newEditorHtml)
- }
- editor.customConfig.linkImgCallback = function (url) {
- editor.$textElem.find('img').forEach(function (el) {
- var src = $(el).attr('src')
- if (src === url) {
- $(el).addClass('customImg')
- }
- return false
- })
- }
- // 关闭粘贴样式的过滤
- editor.customConfig.pasteFilterStyle = true
- editor.customConfig.customUploadImg = function (files, insert) {
- self.addImgToEditor(files, editor)
- }
- //#747474
- editor.create()
- //记录模块信息
- var editorText = self.editorArea['editor' + editorIndex].txt
- .html()
- .clearFixible()
- if (!~editorText.indexOf('flexible_icon')) {
- //设置图片伸缩使用icon
- editorText += self.tpls.flexibleIconTpl
- }
- editor.txt.html(editorText)
- self.editorArea['editor' + editorIndex] = editor
- })
- },
- //可编辑区域
- editorArea: {},
- editorIndex: 0,
- editorAreaOriginContent: {},
- //解答题区域添加图片
- addImgToEditor: function (files, editor) {
- var self = this
- var uploadForm = new FormData()
- uploadForm.append('editor_file', files[0])
- $.ajax({
- url: self.apis.uploadFileApi,
- method: 'POST',
- processData: false,
- contentType: false,
- dataType: 'json',
- data: uploadForm,
- success: function (result) {
- var imgTpl =
- '<img style="max-height:calc(100% - {maxHeight}px);" src="{imgUrl}" class="customImg">'
- var editorContetEl = editor.$textContainerElem.children('.w-e-text')
- var contentHeihgt = self.calcEditorContentHeight($(editorContetEl))
- var maxHeight = contentHeihgt + 64
- editor.txt.html(
- editor.txt.html() +
- imgTpl.substitute({ maxHeight: maxHeight, imgUrl: result.data })
- )
- }
- })
- },
- //创建作答区域模块
- createShortAnswer: function (editorIndex, originContent, topicType) {
- var self = this
- originContent = originContent || ''
- //this.createShortAnswer("#toolbar2", "#editorContent2", 2);
- if (!$('#toolbar' + editorIndex).length) return
- var editor = new self.EDITOR(
- '#toolbar' + editorIndex,
- '#editorContent' + editorIndex
- )
- // 自定义菜单配置
- editor.customConfig.menus = topicType == '7c' ? self.EDITOR_CONFIG_ZW : self.EDITOR_CONFIG
- editor.customConfig.onfocus = function () {
- if (!self.isCanEditCard) return
- $('#editorContent' + editorIndex)
- .siblings('.toolbar')
- .addClass('seled')
- }
- editor.customConfig.onblur = function () {
- if (!self.isCanEditCard || self.formulaing) return
- $('#editorContent' + editorIndex)
- .siblings('.toolbar')
- .removeClass('seled')
- //过滤所有的空标签 换行产生的标签
- var newEditorHtml = editor.txt
- .html()
- .replace(self.replaceEditorRegexp, '')
- editor.txt.html(newEditorHtml)
- }
- //网络图片自定义类名
- editor.customConfig.linkImgCallback = function (url) {
- editor.$textElem.find('img').forEach(function (el) {
- var src = $(el).attr('src')
- if (src === url) {
- $(el).addClass('customImg')
- }
- return false
- })
- }
- // 关闭粘贴样式的过滤
- editor.customConfig.pasteFilterStyle = false
- //editor.customConfig.uploadImgShowBase64 = true
- editor.customConfig.customUploadImg = function (files, insert) {
- self.addImgToEditor(files, editor)
- }
- editor.create()
- //记录模块信息
- var editorText = editor.txt.html().clearFixible()
- if (!~editorText.indexOf('flexible_icon')) {
- //设置图片伸缩使用icon
- editorText += self.tpls.flexibleIconTpl
- }
- editorText += originContent.clearFixible()
- editor.txt.html(editorText.replace(self.replaceEditorRegexp, ''))
- // if(editorIndexUp==''){
- self.editorIndex = editorIndex
- // }
- editorIndexUp = ''
- self.editorArea['editor' + editorIndex] = editor
- },
- //答题区域文本图片位置更换
- shortAnswerImgPositionChange: function () {
- var self = this
- var curOpratorImg = null
- var fa = null
- $('#hgc_print').on('mousedown', '.editorContent .customImg', function (e) {
- e.preventDefault()
- var moveImgEl = $(this)[0]
- var boundaryEl = $(moveImgEl).closest('.module')[0]
- var flexibleIcon = $(this).closest('.module').find('.flexible_icon')[0]
- var moveElHeight = moveImgEl.offsetHeight
- var moveElWidth = moveImgEl.offsetWidth
- var oldX = e.clientX
- var oldY = e.clientY
- var startLeft = moveImgEl.offsetLeft
- var startTop = moveImgEl.offsetTop
- document.onmousemove = function (ev) {
- var maxTop =
- boundaryEl.offsetHeight - self.modulePaddingBottom - moveElHeight
- var maxLeft =
- boundaryEl.offsetWidth - self.modulePaddingSide - moveElWidth
- var distanceX = ev.clientX - oldX
- var distanceY = ev.clientY - oldY
- var newLeft = startLeft + distanceX
- var newTop = startTop + distanceY
- if (newLeft <= self.modulePaddingSide / 2)
- newLeft = self.modulePaddingSide / 2
- if (newTop <= self.modulePaddingTop) newTop = self.modulePaddingTop
- if (newTop >= maxTop) newTop = maxTop
- if (newLeft >= maxLeft) newLeft = maxLeft
- moveImgEl.style.left = newLeft + 'px'
- moveImgEl.style.top = newTop + 'px'
- flexibleIcon.style.left = newLeft + moveElWidth - 20 + 'px'
- flexibleIcon.style.top = newTop + moveElHeight - 20 + 'px'
- }
- document.onmouseup = function () {
- document.onmousemove = null
- document.onmouseup = null
- flexibleIcon.style.display = 'none'
- }
- })
- function resetFlexibleIcon($flexibleIcon, $curImg) {
- $flexibleIcon.css({
- left: parseFloat($curImg.css('left')) + $curImg.width() - 20,
- top: parseFloat($curImg.css('top')) + $curImg.height() - 20
- })
- }
- //图片缩放
- $('#hgc_print').on('mouseover', '.editorContent .customImg', function (e) {
- //缩放icon
- var $curImg = $(this)
- var $curModule = $curImg.closest('.module')
- var $flexibleIcon = $curModule.find('.flexible_icon')
- $flexibleIcon.show()
- curOpratorImg = $curImg[0]
- fa = $curModule[0]
- $flexibleIcon.show()
- resetFlexibleIcon($flexibleIcon, $curImg)
- })
- $('#hgc_print').on('mouseout', '.editorContent .customImg', function (e) {
- e.stopPropagation()
- //缩放icon
- var $curImg = $(this)
- var $curModule = $curImg.closest('.module')
- var $flexibleIcon = $curModule.find('.flexible_icon')
- $flexibleIcon.hide()
- })
- $('#hgc_print').on('mouseover', '.editorContent .flexible_icon', function (
- e
- ) {
- //缩放icon
- var $curImg = $(this)
- var $curModule = $curImg.closest('.module')
- var $flexibleIcon = $curModule.find('.flexible_icon')
- $flexibleIcon.show()
- })
- //图片缩放
- $('#hgc_print').on('mousedown', '.editorContent .flexible_icon', function (
- e
- ) {
- // 阻止冒泡,避免缩放时触发移动事件
- e.stopPropagation()
- e.preventDefault()
- var $flexibleIcon = $(this)
- var pos = {
- w: curOpratorImg.offsetWidth,
- h: curOpratorImg.offsetHeight,
- x: e.clientX,
- y: e.clientY
- }
- fa.onmousemove = function (ev) {
- ev.preventDefault()
- // 设置图片的最小缩放为30*30
- var w = Math.max(30, ev.clientX - pos.x + pos.w)
- var h = Math.max(30, ev.clientY - pos.y + pos.h)
- // console.log(w,h)
- // 设置图片的最大宽高
- w =
- w >= fa.offsetWidth - curOpratorImg.offsetLeft
- ? fa.offsetWidth - curOpratorImg.offsetLeft
- : w
- h =
- h >= fa.offsetHeight - curOpratorImg.offsetTop
- ? fa.offsetHeight - curOpratorImg.offsetTop
- : h
- curOpratorImg.style.width = w + 'px'
- curOpratorImg.style.height = h + 'px'
- resetFlexibleIcon($flexibleIcon, $(curOpratorImg))
- // console.log(box.offsetWidth,box.offsetHeight)
- }
- fa.onmouseup = function () {
- fa.onmousemove = null
- fa.onmouseup = null
- }
- })
- },
- //新模块 part
- addNewModule: function (part, moduleType, resetEditorIds, removeElements) {
- var self = this
- var moduleTitle = ''
- var modulePrev = part.prev()
- var hasTitle = modulePrev.length && modulePrev[0].tagName === 'H3'
- //1 新增新模块resetEditorIds removeElements
- //2 判断是否有需要重置的富文本
- var editorEl = part.children('.editorContent')
- if (editorEl.length) {
- resetEditorIds.push({
- editorId: editorEl.attr('id'),
- toolbarId: editorEl.prev().attr('id')
- })
- }
- //3 移除老模块
- removeElements.push(part)
- if (hasTitle) {
- //self.titleHtml(modulePrev.html())
- moduleTitle = modulePrev[0].outerHTML
- removeElements.push(modulePrev)
- }
- return moduleTitle + part[0].outerHTML
- },
- addNewModuleForObjective: function (part, moduleType, removeElements) {
- var self = this
- var moduleTitle = ''
- var modulePrev = part.prev()
- var hasTitle = modulePrev.length && modulePrev[0].tagName === 'H3'
- //3 移除老模块
- removeElements.push(part)
- if (hasTitle) {
- moduleTitle = self.singleSelectObjectiveTitle
- removeElements.push(modulePrev)
- }
- return moduleTitle + part[0].outerHTML
- },
- //拿到富文本超出的内容 顺便计算一下下一个模块该有的最低高度
- getOverContent: function (part, surplusHeight, removeElements) {
- var self = this
- var editorContentEl = part.find('.w-e-text')
- var overContent = []
- var overHeight = 0
- //富文本可视化高度
- var surplusEditorViewportHeight =
- // editorContentEl.height() - surplusHeight + 30
- editorContentEl.height() - surplusHeight
- //看看当前富文本内容的高度有没有被超出的高度区域截掉
- var editorContentHeight = self.calcEditorContentHeight(editorContentEl)
- //如果剩余高度还能装的下答题文本 直接返回空
- if (surplusEditorViewportHeight > editorContentHeight)
- return {
- overContent: overContent.reverse().join(''),
- overHeight: overHeight
- }
- //当前超出富文本内容元素集合,倒序递归删除放到下一页
- var editorContentElements = [].slice
- .call(part.find('.w-e-text').children(), 0)
- .reverse()
- for (var i = 0, elItem; (elItem = editorContentElements[i++]);) {
- if ($(elItem).hasClass("flexible_icon")) continue
- if (editorContentHeight < surplusEditorViewportHeight) break
-
- var elItemHeight = $(elItem).height() + 10
- if ($(elItem).hasClass("en")){
- elItemHeight = 34
- }
- editorContentHeight -= elItemHeight
- overHeight += elItemHeight
- removeElements.push($(elItem))
- overContent.push(elItem.outerHTML)
- }
- return {
- overContent: overContent.reverse().join(''),
- overHeight: overHeight > surplusHeight ? overHeight + 50 : surplusHeight
- }
- },
- //上一个模块的拓展模块
- expandModule: function (part, nextContentMinHeight) {
- var self = this
- var titleNumber = part.attr('title-number')
- var partEditorIndexUp = part.attr('data-editorindex')
- //当前超出的模块height
- var overHeight = self.getOverHeight(part)
- var $nextPage = part.closest('.pageContent').next()
- var $nextPageFirstModule = $nextPage.find('.module').eq(0)
- var $nextPageModuleTitleNumber = $nextPageFirstModule.attr('title-number')
- overHeight =
- overHeight < self.moduleMinHeight ? self.moduleDefaultHeihgt : overHeight
- //如果下一页已经存在当前模块的 高度累加
- if ($nextPageModuleTitleNumber === titleNumber) {
- overHeight += 0 //$nextPageFirstModule.height()
- }
- //如果该模块超出区域 这需要通过linkparam 去 排列超出的顺序
- editorIndexUp = titleNumber + '-' + editorIndexLi
- if(partEditorIndexUp!=undefined){
- editorIndexUp = partEditorIndexUp+'-' + editorIndexLi
- }
- ++editorIndexLi
-
- var linkparm = 1
- var cutId = editorIndexUp
- //如果该模块是首次超出 则直接从1开始计数,否则从当前位置开始计数
- if (!part.attr('data-linkparm')) {
- part.attr({
- 'data-cutId': editorIndexUp,
- 'data-linkparm': linkparm
- })
- linkparm++
- } else {
- linkparm = +part.attr('data-linkparm')
- cutId = +part.attr('data-cutId')
- linkparm++
- }
- return self.tpls.overModuleTpl.substitute({
- overIndex: editorIndexUp,
- cutId: cutId,
- linkparm: linkparm,
- titleNumber: titleNumber,
- editorContentHeight:
- overHeight < nextContentMinHeight ? nextContentMinHeight : overHeight
- })
- },
- reduceFillInBlank: function (part, surplusHeight, $dtKContent) {
- var self = this
- var curPageIndex = $dtKContent.closest('.pageContent').index() + 1
- var fromPageIndex = part.closest('.pageContent').index() + 1
- var $answerModule = part.closest('.answerModule')
- var modelId = $answerModule.attr('data-modelId')
- var modelData = self.questionMap[modelId]
- var modelPagesData = modelData.pages
- //一行几栏
- var $firstColForInfoEl = part.children('.subjectCol')
- var dataColumns = $firstColForInfoEl.attr('data-column')
- var columns = dataColumns ? +dataColumns : 1
- //计算每个填空题item的高度
- var rowLinHeight = $firstColForInfoEl.attr('data-rowlineheight')
- var fillInBlankItemHeight = (+rowLinHeight || 40) + 11
- var scoreStyle = $firstColForInfoEl.attr('data-scoreStyle')
- //需要复制几个填空题-如果有标题要减去比哀痛的高度
- if (part.prev().length && part.prev()[0].tagName === 'H3') {
- surplusHeight -= part.prev().height()
- }
- var copyFillInBlankLength =
- Math.floor(surplusHeight / fillInBlankItemHeight) * columns
- //原页面保留的题目
- //超出的放在新页面上
- var curModuleDataIndex = 'page' + curPageIndex
- var nextExpendDataIndex = 'page' + fromPageIndex
- modelPagesData[curModuleDataIndex] =
- modelPagesData[curModuleDataIndex] || []
- modelPagesData[curModuleDataIndex] = modelPagesData[
- curModuleDataIndex
- ].concat(
- modelPagesData[nextExpendDataIndex].splice(0, copyFillInBlankLength)
- )
- //原页面残留
- var originPageRetainHtml = self.getFillInBlankHtml(
- modelPagesData[curModuleDataIndex]
- )
- //新页面超出
- var overFillInBlankItemsHtml = self.getFillInBlankHtml(
- modelPagesData[nextExpendDataIndex]
- )
- var $overFillInBlank = part.closest('.completion-topic')
- var $overDtkContent = $overFillInBlank.closest('.dtk-content')
- $overFillInBlank.remove()
- if (overFillInBlankItemsHtml) {
- overFillInBlankItemsHtml =
- self.titleHtml(originPageRetainHtml ? '' : modelData.bigTitle) +
- self.tpls.fillInBlankContentTpl.substitute({
- addFillInBlankHtml: overFillInBlankItemsHtml,
- columns: columns,
- scoreStyle: scoreStyle,
- rowLinHeight: rowLinHeight,
- settingBtn: originPageRetainHtml
- ? ''
- : self.tpls.fillInBlankSettingBtnTpl
- })
- overFillInBlankItemsHtml = self.tpls.answerModulForFillInBlankTpl.substitute(
- {
- editModule: overFillInBlankItemsHtml,
- moduleType: 'fillInBlank',
- modelId: modelId
- }
- )
- $overDtkContent.prepend(overFillInBlankItemsHtml)
- }
- //老页面残留填空题模块--寻找模块id 相同的模块
- var $prevFillInBlank = { length: 0 }
- $dtKContent.find('.completion-topic').each(function () {
- if ($(this).attr('data-modelId') === modelId) {
- $prevFillInBlank = $(this)
- }
- })
- if (!$prevFillInBlank.length) {
- originPageRetainHtml =
- self.titleHtml(modelData.bigTitle) +
- self.tpls.fillInBlankContentTpl.substitute({
- addFillInBlankHtml: originPageRetainHtml,
- columns: columns,
- scoreStyle: scoreStyle,
- rowLinHeight: rowLinHeight,
- settingBtn: self.tpls.fillInBlankSettingBtnTpl
- })
- originPageRetainHtml = self.tpls.answerModulForFillInBlankTpl.substitute({
- editModule: originPageRetainHtml,
- moduleType: 'fillInBlank',
- modelId: modelId
- })
- $dtKContent.append(originPageRetainHtml)
- } else {
- $prevFillInBlank.find('.subjectCol').html(originPageRetainHtml)
- }
- return !overFillInBlankItemsHtml
- },
- reduceSingleSelect: function (part, surplusHeight, $dtKContent) {
- var self = this
- var curPageIndex = $dtKContent.closest('.pageContent').index()==0?$dtKContent.closest('.pageContent').index() + 1:$dtKContent.closest('.pageContent').index()
- // var fromPageIndex = part.closest('.pageContent').index()==0?part.closest('.pageContent').index() + 1:part.closest('.pageContent').index()
- var fromPageIndex = curPageIndex +1
- var $answerModule = part.closest('.answerModule')
- var type = $answerModule.attr('data-type')
- var modelId = $answerModule.attr('data-modelId')
- var direction = $answerModule.attr('data-direction')
- var prevTag = part.prev()[0]
- if (prevTag && prevTag.tagName === 'H3') {
- surplusHeight -= part.prev().height()
- }
- //每小题的高度
- var selectItemHeight = $('.single-option').eq(0).outerHeight()
- //当前超出的模块height
- if (Math.floor(surplusHeight / selectItemHeight) < 1) return
- //针对选择题竖版一行排几个
- /**
- * 超出的计算单位以 一整排为单位
- * 每一排的一列以5题为单位 计算
- */
- var rowSubjectNum =
- self.config[self.direction][self.hasBindingLine ? 'yesLine' : 'noLine'][
- self.columns
- ]
- //计算超出多少小题
- var overSelectItemsLength =
- Math.floor(surplusHeight / selectItemHeight) * rowSubjectNum
- //该模块的数据
- var modelPagesData = self.questionMap[modelId].pages
- //超出的放在新页面上
- var curModuleDataIndex = 'page' + curPageIndex
- var nextExpendDataIndex = 'page' + fromPageIndex
- modelPagesData[curModuleDataIndex] =
- modelPagesData[curModuleDataIndex] || []
- modelPagesData[curModuleDataIndex] = modelPagesData[
- curModuleDataIndex
- ].concat(
- modelPagesData[nextExpendDataIndex].splice(0, overSelectItemsLength)
- )
- //计算留在当前页面的和下一个页面的数据
- var originPageRetainHtml = self.getSingleSelectHtml(
- modelPagesData[curModuleDataIndex]
- )
- var overSelectItemsHtml = self.getSingleSelectHtml(
- modelPagesData[nextExpendDataIndex]
- )
- //超出页面的数据处理
- var $overAnswerModule = part.closest('.single-select')
- var $overDtkContent = $overAnswerModule.closest('.dtk-content')
- $overAnswerModule.remove()
- if (overSelectItemsHtml) {
- //获取超出选择题区域模块html
- //selectContent, title, direction, hasTitle
- overSelectItemsHtml = self.getSelectRenderContent({
- selectContent: overSelectItemsHtml,
- moduleType: type,
- direction: direction,
- hasTitle: originPageRetainHtml ? false : true,
- bigTitle: self.questionMap[modelId].bigTitle,
- modelId: modelId
- })
- $overDtkContent.prepend(overSelectItemsHtml)
- }
- //老页面残留填空题模块处理
- var $originAnswerModule = self.getAnswerModuleForModelId(modelId)
- if (!$originAnswerModule || !$originAnswerModule.length) {
- //获取整个选择题区域模块html
- originPageRetainHtml = self.getSelectRenderContent({
- selectContent: originPageRetainHtml,
- direction: direction,
- moduleType: type,
- bigTitle: self.questionMap[modelId].bigTitle,
- modelId: modelId
- })
- $dtKContent.append(originPageRetainHtml)
- } else {
- let btnHtml = '<div class="settingBtn" data-type="' + type + '"></div><div class="delTopicBtn" data-type="' + type + '">X</div>'
- $originAnswerModule.find('.singleContent').html(btnHtml + originPageRetainHtml)
- }
- return !overSelectItemsHtml
- },
- reducePrintArea: function (curPageEl) {
- var self = this
- var nextPage = curPageEl.next()
- if (!nextPage.length) {
- //在delPageOverModule 的方法中可能存在被遗忘的超出模块此时做重置
- if (self.forgetOverPage) {
- self.changePrintArea(self.forgetOverPage)
- }
- return
- }
- var curPageIndex = curPageEl.index()
- //当前模块下面所有的模块都可以上移,只要当前剩余空间足够大
- var canUpMovePage = $('#printcontent').children(
- '.pageContent:gt(' + curPageIndex + ')'
- )
- /**
- * 首先通过判断当前页面的剩余空间是否够下一个页面的第一个模块使用
- * 1 如果下一页第一个是第一页的模块补充模块 直接合并
- * 2 如果下一页第一个不是补充模块,如果上一页的空间大于当前这一页
- * a. 直接把标题带着第一个模块一起拿上去
- * b. 如果是一个小题 直接把当前小题拿上去,归并到上一个页面的大题下面
- */
- //var answerModule = [].splice.call(canUpMovePage.find('.answerModule'), 0)
- //var objectiveModule = [].splice.call(canUpMovePage.find('.objectiveModule'), 0)
- var nextPageAllModule = [].splice.call(
- canUpMovePage.find('.answerModule'),
- 0
- )
- var isContiune = true
- nextPageAllModule.forEach(function (answerEl, index) {
- if (!isContiune) return false
- var firstAnswer = $(answerEl)
- var nextUpPage = firstAnswer.closest('.pageContent')
- var answerModuleType = firstAnswer.attr('data-type')
- //题干信息
- var isObjective = answerModuleType === 'objective'
- var isSelect = ~answerModuleType.indexOf('Select') || ~answerModuleType.indexOf('uncertainOption')
- var isFillInBlank = answerModuleType === 'fillInBlank'
- var isChooseAnswer = answerModuleType === 'chooseAnswer'
- var firstModule = firstAnswer.children('.module').eq(0)
- var curPageContent = curPageEl.children('.dtk-content')
- //具体分页内容容器的宽度
- var contentAndHeight = curPageContent.outerHeight()
- //当前分页剩余空间
- var surplusHeight = curPageEl.height() - contentAndHeight
- if (surplusHeight <= 10) {
- //如果当前分页超出直接重新计算排版方式
- if (
- surplusHeight < -10 &&
- curPageEl.find('.answerModule:last()').children('.module').length
- ) {
- self.changePrintArea(curPageEl)
- }
- isContiune = false
- return false
- }
- if (isFillInBlank) {
- //下一页面第一个填空题的高度
- var firstModuleHeight = self.getNextPageFirstModuleHeight(
- firstModule,
- 'fillInBlank'
- )
- if (surplusHeight >= firstModuleHeight) {
- self.reduceFillInBlank(firstModule, surplusHeight, curPageContent)
- self.updatePageElement(nextUpPage, firstAnswer)
- } else {
- isContiune = false
- return false
- }
- } else if (isSelect) {
- var firstModuleHeight = self.getNextPageFirstModuleHeight(
- firstModule,
- 'singleSelect'
- )
- if (surplusHeight >= firstModuleHeight) {
- self.reduceSingleSelect(firstModule, surplusHeight, curPageContent)
- self.updatePageElement(nextUpPage, firstAnswer)
- } else {
- isContiune = false
- return false
- }
- } else if (isObjective) {
- $(answerEl)
- .children('.objectiveItem')
- .each(function (idx, moduleEl) {
- //解答题一个小题就是一个module
- firstModule = $(moduleEl)
- contentAndHeight = curPageContent.outerHeight()
- surplusHeight = curPageEl.height() - contentAndHeight
- //下一个页面第一个解答题模块
- var firstModuleHeight = self.getNextPageFirstModuleHeight(
- firstModule,
- 'objective'
- )
- if (surplusHeight >= firstModuleHeight) {
- self.copyModuleForObjective(firstModule, firstAnswer, curPageEl)
- self.updatePageElement(nextUpPage, firstAnswer, 'objective')
- } else {
- isContiune = false
- return false
- }
- })
- } else {
- //选做题特殊处理,题干信息一个一个往上拿
- var $chooseAnswerObjectiveItems = $(answerEl).find('.questionItemBody')
- //如果有单独的模块还是可以
- // && !$(answerEl).children('.module').length
- if (isChooseAnswer && $chooseAnswerObjectiveItems.length) {
- contentAndHeight = curPageContent.outerHeight()
- surplusHeight =
- curPageEl.height() -
- contentAndHeight -
- $(answerEl).find('h3').children('span').height()
- var removeItems = []
- $chooseAnswerObjectiveItems.each(function () {
- //如果上一页有选做题模块
- var prePageLastAnswer = curPageEl.find('.answerModule:last')
- var prevLastModuleIsChooseAnswer = prePageLastAnswer.length
- ? prePageLastAnswer.attr('data-type') === 'chooseAnswer'
- : false
- var $item = $(this)
- var itemHeight = $(this).height()
- var itemHtml = $(this)[0].outerHTML
- if (surplusHeight > itemHeight) {
- if (prePageLastAnswer.length && prevLastModuleIsChooseAnswer) {
- prePageLastAnswer
- .children('h3')
- .children('.originSubjectInfo')
- .append(itemHtml)
- surplusHeight -= itemHeight
- removeItems.push($item)
- } else {
- //如果上一页没有多选题模块
- //1 先拿到当前多选题的基础信息
- var $h3 = $(answerEl).find('h3')
- var baseInfo = $h3[0].outerHTML.replace(
- /<div class="originSubjectInfo">(.*)<\/div>/g,
- '<div class="originSubjectInfo">' + itemHtml + '</div>'
- )
- curPageContent.append(
- '<div class="short-answer answerModule" data-type="chooseAnswer">' +
- baseInfo +
- '</div>'
- )
- surplusHeight -= itemHeight
- removeItems.push($item)
- }
- } else {
- isContiune = false
- return false
- }
- })
- if (removeItems.length >= $chooseAnswerObjectiveItems.length) {
- $(answerEl).find('h3').remove()
- } else {
- if (removeItems.length) {
- removeItems.forEach(function (el) {
- $(el).remove()
- })
- $(answerEl)
- .find('h3')
- .html(
- '<div class="originSubjectInfo">' +
- $(answerEl)
- .find('h3')
- .children('.originSubjectInfo')
- .html() +
- '</div>'
- )
- }
- }
- self.updatePageElement(nextUpPage, firstAnswer, 'chooseAnswer')
- //self.reducePrintArea(nextPage)
- return
- }
- $(answerEl)
- .children('.module')
- .each(function (idx, moduleEl) {
- var resetEditorIds = []
- //解答题一个小题就是一个module
- firstModule = $(moduleEl)
- contentAndHeight = curPageContent.outerHeight()
- surplusHeight = curPageEl.height() - contentAndHeight
- //如果是补充模块--直接删除再计算其他高度
- if (self.isSurplusModule(firstModule)) {
- self.delPageOverPart(firstModule.find('.delBtn'), 'surplus')
- return
- }
- //下一个页面第一个解答题模块
- var firstModuleHeight = self.getNextPageFirstModuleHeight(
- firstModule,
- 'answer'
- )
- if (surplusHeight >= firstModuleHeight) {
- self.copyModuleToSurplus(
- firstModule,
- firstAnswer,
- curPageEl,
- resetEditorIds
- )
- } else {
- //判断是否是一个大题的开始
- var modulePrev = firstModule.prev()
- var hasTitle = modulePrev.length && modulePrev[0].tagName === 'H3'
- var titleHeight = hasTitle ? modulePrev.height() : 0
- if (surplusHeight <= titleHeight + 100) {
- isContiune = false
- return false
- } else {
- self.copyModuleToSurplus(
- firstModule,
- firstAnswer,
- curPageEl,
- resetEditorIds
- )
- if (self.getOverHeight(curPageEl.find('.module:last()'))) {
- self.saveForgetPage(curPageEl)
- }
- }
- }
- self.updatePageElement(nextUpPage, firstAnswer)
- //重置富文本
- self.resetAddNewModuleEditor(resetEditorIds)
- })
- }
- })
- self.changePrintArea(nextPage)
- },
- //复制一个模块到上一个页面的剩余空间 type whole | few表示整体模块上移还是部分模块上去
- copyModuleToSurplus: function (
- firstModule,
- firstAnswer,
- curPageEl,
- resetEditorIds
- ) {
- var self = this
- //判断是否是一个大题的开始
- var modulePrev = firstModule.prev()
- var hasTitle = modulePrev.length && modulePrev[0].tagName === 'H3'
- var moduleType = firstAnswer.attr('data-type')
- var modelId = firstAnswer.attr('data-modelId')
- var cloneHtml = ''
- //准备重新初始化富文本所需要的 editorId
- var editorEl = firstModule.children('.editorContent')
- if (editorEl.length) {
- resetEditorIds.push({
- editorId: editorEl.attr('id'),
- toolbarId: editorEl.prev().attr('id')
- })
- }
- //如果没有标题 则认为是 上一页最后一大题的一个小题
- var moduleHtml = firstModule[0].outerHTML
- var $dtkContent = curPageEl.children('.dtk-content')
- var $shortAnswerLast = curPageEl.find('.short-answer:last()')
- if (hasTitle) {
- var editModuleHtml = modulePrev[0].outerHTML + moduleHtml
- cloneHtml = self.tpls.answerModuleTpl.substitute({
- editModule: editModuleHtml,
- moduleType: moduleType,
- modelId: modelId
- })
- $dtkContent.append(cloneHtml)
- modulePrev.remove()
- } else {
- var $shortAnswerLast = curPageEl.find('.short-answer:last()')
- cloneHtml = moduleHtml
- //可能中间出现真空区域
- if (!$shortAnswerLast.length) {
- cloneHtml = self.tpls.answerModuleTpl.substitute({
- editModule: cloneHtml,
- moduleType: moduleType,
- modelId: modelId
- })
- $dtkContent.append(cloneHtml)
- } else {
- $shortAnswerLast.append(cloneHtml)
- }
- }
- //清理模块
- firstModule.remove()
- },
- //题干信息copy
- copyModuleForObjective: function (firstModule, firstAnswer, curPageEl) {
- var self = this
- //判断是否是一个大题的开始
- var modulePrev = firstModule.prev()
- var hasTitle = modulePrev.length && modulePrev[0].tagName === 'H3'
- var cloneHtml = ''
- //如果没有标题 则认为是 上一页最后一大题的一个小题
- var moduleHtml = firstModule[0].outerHTML
- // self.tpls.objectiveItemTpl.substitute({
- // content: firstModule.html()
- // })
- var $dtkContent = curPageEl.children('.dtk-content')
- if (hasTitle) {
- var editModuleHtml = modulePrev[0].outerHTML + moduleHtml
- cloneHtml = self.tpls.objectiveWrapTpl.substitute({
- editModule: editModuleHtml
- })
- $dtkContent.append(cloneHtml)
- modulePrev.remove()
- } else {
- var $shortAnswerLast = curPageEl.find('.objectiveModule:last()')
- cloneHtml = moduleHtml
- //可能中间出现真空区域
- if (!$shortAnswerLast.length) {
- cloneHtml = self.tpls.objectiveWrapTpl.substitute({
- editModule: cloneHtml
- })
- $dtkContent.append(cloneHtml)
- } else {
- $shortAnswerLast.append(cloneHtml)
- }
- }
- //清理模块
- firstModule.remove()
- },
- //获取当前也页面的剩余空间
- getCurPageSurplusHeight: function (curPageEl) {
- var curPageContent = curPageEl.children('.dtk-content')
- //具体分页内容容器的宽度
- var contentAndHeight = curPageContent.outerHeight()
- //当前分页剩余空间
- return curPageEl.height() - contentAndHeight
- },
- //获取下一个页面第一个模块的高度,用来和上一个页面的剩余高度做对比
- getNextPageFirstModuleHeight: function (firstModule, type) {
- var self = this
- //判断是否是一个大题的开始
- var modulePrev = firstModule.prev()
- var hasTitle = modulePrev.length && modulePrev[0].tagName === 'H3'
- //如果包含title 必须满足上一页面剩余的高度大于 当前页面第一个模块的高度加上模块对应title的高度
- //留点空间余地不能抵到最底下
- var titleHeight = (hasTitle ? modulePrev.height() : 0) + 10
- //type包含选择,填空,解答题
- if (type === 'fillInBlank') {
- var firstFillInBlank = firstModule.find('.subjectItem').eq(0)
- return firstFillInBlank.outerHeight() + titleHeight
- } else if (~type.indexOf('Select')) {
- var firstSelect = firstModule.find('.single-option').eq(0)
- return firstSelect.outerHeight() + titleHeight
- } else {
- return firstModule.outerHeight() + titleHeight
- }
- },
- //页面之间模版串位之后更新每个页面的元素
- updatePageElement: function (nextUpPage, firstAnswer, type) {
- var self = this
- //题干信息单独处理
- var nextPage = nextUpPage
- var isObjective = type === 'objective'
- //选做题如果有题干信息
- var isChooseAnswer =
- type === 'chooseAnswer' && firstAnswer.find('.originSubjectInfo').length
- if (firstAnswer) {
- if (
- !firstAnswer.children(isObjective ? '.objectiveItem' : '.module')
- .length &&
- !isChooseAnswer
- ) {
- firstAnswer.remove()
- }
- }
- if (
- !nextPage.find('.answerModule').length &&
- !nextPage.find('.objectiveModule').length
- ) {
- // 判断当前页面是否最后一页----如果最后一页为空才直接删除该页面
- // 选择题和填空题的数据是根据页面显示的,如果你删除了,选择题和填空题的数据就错位了
- if ($('#printcontent .pageContent').length === nextPage.index() + 1) {
- var prevPage = nextPage.prev()
- nextPage.remove()
- self.currentPage--
- //新建的分页
- self.totalPage--
- self.refrushPageLabel()
- if (prevPage.length) {
- self.updatePageElement(prevPage)
- }
- }
- }
- },
- //新页面预览
- previewPrintDiv: function (printPart) {
- var self = this
- var priviewHtml = self.formatPrintHtml(printPart, 'preview')
- var iframe = document.createElement('iframe')
- iframe.setAttribute('id', 'preview-iframe')
- document.body.appendChild(iframe)
- var doc = iframe.contentWindow.document
- doc.write(
- '<link rel="stylesheet" type="text/css" href="' + printCssPath + '">'
- )
- doc.write(priviewHtml)
- if (isShowPreview > -1) {
- $('body').append('<div class="h_btn previewbackbtn"><a href="javascript:;" class="btn-go-back">返回</a></div>')
- } else {
- $('body').append('<div id="closeIframeBtn" class="h_btn">关闭</div>')
- $('body').on('click', '#closeIframeBtn', function () {
- $('#preview-iframe').remove()
- $(this).remove()
- })
- }
- },
- //保存题目坐标信息
- //保存的时候传点坐标和原图
- /**
- *
- timu:{"KeGuanTi":5,"TianKongTi":10,"ZhuGuanTi":1,"XuanZuoTi":0}
- sheet_answer:{"1":"A","2":"A","3":"A","4":"A","5":"A"}
- 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"}
- title:22
- exam_id:17464269385543527633
- position
- imgFiles:[fileobj,fileobj]
- */
- //保存题目定位点的时候 获取 题目数量 分数 等信息
- getSaveSubjectInfo: function (questionClassify) {
- var self = this
- var title = self.$dtkName.val()
- // examInfo
- //信息栏
- //数量
- var timu = {
- KeGuanTi: 0,
- TianKongTi: 0,
- ZhuGuanTi: 0,
- XuanZuoTi: 0
- }
- //选择题答案
- var sheet_answer = {}
- //每题对应分数
- var sheet_score = {}
- // 半对分
- var sheet_halfscore = {}
- // 总分
- var scoreAll = 0
- let pId = 0
- var key = 0
- for (var uid in questionClassify) {
- questionClassify[uid].questions.forEach(function (question, index) {
- //计算每个题目数量
- var type = question.questionTypeId
- if (~[1, 2, 11].indexOf(type)) {
- timu.KeGuanTi += 1
- } else if (type === 5) {
- timu.TianKongTi += 1
- } else if (type === 7) {
- timu.ZhuGuanTi += 1
- } else {
- timu.XuanZuoTi += 1
- }
- key += 1
- if(question.answer!=''){
- sheet_answer[key] = question.answer
- }
-
- sheet_score[key] = '' + question.fullScore
- sheet_halfscore[key] = question.halfScore
- if (type == 17) {
- if (pId != question.topicNo)
- scoreAll = scoreAll + Number(question.fullScore)
- pId = question.topicNo
- } else {
- scoreAll = scoreAll + Number(question.fullScore)
- }
- })
- }
- self.savePrintInfo = {
- title: title,
- timu: timu,
- sheet_answer: sheet_answer,
- sheet_score: sheet_score,
- sheet_halfscore: sheet_halfscore
- }
- self.examInfoConfigText.wpTimes = $('#examInfo input[name|="wpTimes"]').val()
- // self.examInfoConfigText.fullScore = $('#examInfo input[name|="fullScore"]').val()
- self.examInfoConfigText.fullScore = scoreAll
- self.examInfoConfigText.wpAuthor = $('#examInfo input[name|="wpAuthor"]').val()
- self.examInfoConfigText.wpReviewer = $('#examInfo input[name|="wpReviewer"]').val()
- self.examInfoConfigText.fullScore =
- self.showExamInfoHtml()
- },
- //printcontent --- printPart
- savePrintPosition: function (printPart, cb) {
- var self = this
- // 给模块标题设置高度
- $('.answerModule').find('h3').each(function (){
- $(this).css('height',$(this).height())
- })
- var position = self.getPositions()
- //保存当前坐标点用于和下次一点击保存做对比,如果没有变化就可以防止重复提交
- self.saveLocationPosition = JSON.stringify(position)
- //console.log(JSON.stringify(position, null, 4))
- var printHtml = self.formatPrintHtml(printPart)
- var iframe = document.createElement('iframe')
- iframe.setAttribute('id', 'print-iframe')
- iframe.setAttribute('style', 'position:fixed;')
- document.body.appendChild(iframe)
- var doc = iframe.contentWindow.document
- doc.write(
- '<link rel="stylesheet" type="text/css" href="' + printCssPath + '">'
- )
- doc.write(printHtml)
- doc.close()
- iframe.contentWindow.focus()
- iframe.contentWindow.onload = function () {
- var pages = doc.getElementsByClassName('printIframeContent')
- //生成的pdf所需要的html
- var pdfHtml = (
- self.tpls.htmlSkeleton +
- printHtml +
- '</body></html>'
- ).replace(/\'/g, '"')
- hgc_layer.msg('pdf生成中,请稍后...', { time: 0, shade: 0.4 })
-
- $.post(
- self.apis.getOnlinePdfApi,
- {
- width: self.config.width + 'mm',
- height: self.config.height + 'mm',
- identifier: self.identifier,
- examGroupId:self.examGroupId || '26566294892575975',
- pdfHtml: pdfHtml
- },
- function (res) {
- var pdfFileUrl = ''
- let resData = JSON.parse(res)
- if(resData.success==1){
- pdfFileUrl = resData.data
- // hgc_layer.closeAll()
- // location.href = self.apis.downloadPdfUrl + self.identifier
- } else {
- hgc_layer.msg(resData.message)
- return false
- }
- //处理模版html
- var pdfHtmlStream = new Blob([pdfHtml], {
- type: 'text/plain;charset=utf-8'
- })
- self.savePrintInfo.title = self.$dtkName.val()
- self.savePrintInfo.pdfHtml = pdfHtml
- self.savePrintInfo.position = position
- //pdf 模版唯一标识符--主要用于创建考试页面模版下载
- self.savePrintInfo.identifier = self.identifier
- self.savePrintInfo.examGroupId = self.examGroupId
- self.savePrintInfo.useQrCode = self.useQrCode ? 1 : 0
- self.savePrintInfo.columns = self.columns
- self.savePrintInfo.pdfTemplate = pdfHtmlStream
- self.savePrintInfo.pdf_url = pdfFileUrl
- var formData = new FormData()
- formData.append('pdfTemplate', pdfHtmlStream, 'pdfTepmlate.txt')
- //pdf链接
- formData.append('pdf_url', pdfFileUrl)
- //针对全学科,在保留题型数据的同时,也需要当前定位点的所有信息
- if (isNewBuild) {
- var questions = []
- var buildQuestions = self.questionMap
- for (var modelId in buildQuestions) {
- questions = questions.concat(buildQuestions[modelId].questions)
- }
- //题号重新排序
- let PositionData = JSON.parse(JSON.stringify(questions))
- function compare(key){
- return function(value1,value2){
- var val1=value1[key];
- var val2=value2[key];
- return val1-val2;
- }
- }
- PositionData.sort(compare('questionNum'));
- jQuery.each( PositionData, function( i, topicItem ) {
- topicItem.name = i+1
- });
- jQuery.each( questions, function( q, questionsItem ) {
- questionsItem.isEdit = false
- });
- let score = {};
- let halfScore = {};
- let answer = {};
- jQuery.each( questions, function( j, paperTopicItem ) {
- jQuery.each( PositionData, function( k, topicAllItem ) {
- if(!paperTopicItem.isEdit){
- if(paperTopicItem.questionNum == topicAllItem.questionNum){
- let topic = JSON.parse(JSON.stringify(topicAllItem))
- let key = topic.name.toString();
- paperTopicItem.questionNum = topic.name.toString()
- paperTopicItem.isEdit = true
- if(paperTopicItem.answer!=''){
- answer[key] = paperTopicItem.answer
- }
- score[key] = '' + paperTopicItem.fullScore
- halfScore[key] = paperTopicItem.halfScore
- }
- }
- });
- });
- self.savePrintInfo.sheet_score = score;
- self.savePrintInfo.sheet_halfscore = halfScore;
- self.savePrintInfo.sheet_answer = answer;
- self.savePrintInfo.question_info = {
- content: questions
- }
- console.log(JSON.stringify(self.savePrintInfo))
- //全学科,该页面还是做编辑使用,不做任何的操作
- localStorage.setItem(
- 'savePrintInfo',
- JSON.stringify(self.savePrintInfo)
- )
- hgc_layer.closeAll()
- self.isCanEditCard = false
- self.changeCardEditStatus()
- // location.href = document.referrer
- // if(localStorage.referrerUrl){
- // var referrerUrl = JSON.parse(localStorage.getItem('referrerUrl'));
- // window.location.href = referrerUrl+"/isCardReturn=true"
- // }else{
- // window.history.back();
- // }
- return
- }
- for (var field in self.savePrintInfo) {
- if (typeof self.savePrintInfo[field] === 'object') {
- formData.append(field, JSON.stringify(self.savePrintInfo[field]))
- } else {
- formData.append(field, self.savePrintInfo[field])
- }
- }
- //localStorage.setItem('savePrintInfo',JSON.stringify(self.savePrintInfo))
- /**
- * 新页面需要特殊处理的地方
- * var pdfHtmlStream = new Blob([pdfHtml], {
- type: 'text/plain;charset=utf-8'
- })
- * formData.append('pdfTemplate', pdfHtmlStream, 'pdfTepmlate.txt')
- * imgFiles
- * formData.append('imgFiles' + index, img)
- *
- * examNumberConfig
- */
- $.ajax({
- //'//192.168.1.51/index.php/print/saveCardOnline' + loginStatus,
- url: self.apis.saveTopicsDetailsApi,
- method: 'POST',
- processData: false,
- contentType: false,
- dataType: 'json',
- data: formData,
- success: function (data) {
- hgc_layer.closeAll()
- if (data.success === 1) {
- hgc_layer.msg('保存成功')
- self.isCanEditCard = false
- self.changeCardEditStatus()
- self.alreadySave = true
- //如果使用二维码
- //考号 和 条形码 都没有了,导致试卷内所有定位点错误,需要重新保存定位点
- cb && cb()
- } else {
- hgc_layer.msg('保存失败')
- }
- }
- })
- document.body.removeChild(iframe)
- }
- )
- }
- },
- //重置学生状态
- resetExamStudentStatus: function (cb) {
- var self = this
- $.post(
- self.apis.resetExamStudentApi,
- {
- schoolId: this.schoolId,
- examGroupId: this.examGroupId
- },
- function (res) {
- // console.log(res)
- cb && cb()
- }
- )
- },
- //后台批量生成examgroupid下面的所有考试
- batchGeneratePdf: function () {
- var self = this
- var printHtml = self.formatPrintHtml('printcontent')
- var pdfHtml = (
- self.tpls.htmlSkeleton +
- printHtml +
- '</body></html>'
- ).replace(/\'/g, '"')
- var batchParams = {
- width: self.config.width + 'mm',
- height: self.config.height + 'mm',
- examGroupId: self.examGroupId,
- examIds: self.examIds,
- schoolId: self.schoolId,
- direction: self.direction,
- pdfTpl: pdfHtml
- //savedInfoUrl: 'http://zxhx-test.cn-bj.ufileos.com/zsyas2%2Fcardonline%2F3865%2F2020%2F04%2F10%2F565798454967058432.zip?r=888'
- }
- // hgc_layer.msg('学生模板批量生成中,请稍后...', { time: 0, shade: 0.4 })
- $.ajax({
- url: self.apis.batchGeneratePdfApi,
- method: 'POST',
- data: batchParams,
- success: function (res) {
- hgc_layer.closeAll()
- hgc_layer.msg(res.msg)
- }
- })
- // batchInstance = $.post(self.apis.batchGeneratePdfApi, batchParams, function(res) {
- // })
- },
- downLoadPdf: function () {
- var self = this
- if (!self.alreadySave && !isNewBuild) {
- hgc_layer.msg('请先保存答题卡')
- return
- }
- //如果是创建答题卡,直接下载即可
- if (isNewBuild) {
- hgc_layer.msg('pdf生成中,请稍后...', { time: 0, shade: 0.4 })
- var printHtml = self.formatPrintHtml('printcontent')
- var pdfHtml = (
- self.tpls.htmlSkeleton +
- printHtml +
- '</body></html>'
- ).replace(/\'/g, '"')
- $.post(
- self.apis.getOnlinePdfApi,
- {
- width: self.config.width + 'mm',
- height: self.config.height + 'mm',
- identifier: self.identifier,
- examGroupId:self.examGroupId,
- pdfHtml: pdfHtml
- },
- function (res) {
- let resData = JSON.parse(res)
- if(resData.success==1){
- hgc_layer.closeAll()
- // location.href = self.apis.downloadPdfUrl + self.identifier
- location.href = self.apis.downOnlinePdfApi + '?url=' + resData.data + '&title=pdf-'+self.examGroupId+'.pdf'
- // location.href = resData.data
- } else {
- hgc_layer.msg(resData.message)
- }
-
- }
- )
- return
- }
- var downloadUrl =
- // self.apis.downPdfApi + '?exam_group_id=' + self.examGroupId
- self.apis.downOnlinePdfApi + '?url=' + self.downPdfUrl + '&title='+self.examGroupId
- location.href = downloadUrl
- },
- /**
- * 处理需要打印的html
- * 返回处理之后直接可以打印的html
- */
- formatPrintHtml: function (elId, type) {
- //format-需要打印的iframe里面的内容
- //origin-原网页的内容
- var self = this
- $('#examInfo').find('.input-examInfo').each(function(i ,item){
- $(this).attr('value',$(this).val())
- })
- //type 预览效果存储的html 和 用于转pdf 的不一样
- var isPreview = type === 'preview'
- var $formatContent = $('#formatContent').html($('#' + elId).html())
- var $formatPageContent = $formatContent.children('.pageContent')
- var $formatPageObjective = $formatPageContent.find('.objectiveItem')
- var $formatDtkTitle = $formatPageContent.eq(0).find('.dtkName')
- var $formatDtkNoticeDetail = $formatPageContent.eq(0).find('.noticeDetail')
- var $formatShortAnswer = $formatContent.find('.short-answer')
- var $originShortAnswer = $('#' + elId + ' .short-answer')
- var $originShortAnswer = $('#' + elId + ' .short-answer')
- var $originDtkTitle = $('#' + elId + ' .pageContent')
- .eq(0)
- .find('.dtkName')
- //设置每个分页的高度
- $formatPageContent.height(self.config.height + 'mm')
- $formatPageContent.find('.pageLabel .size').remove()
- //设置答题卡title
- $formatDtkTitle.html($originDtkTitle.children('textarea').val())
- //设置注意事项-所有标题预览页面不可编辑
- $formatDtkNoticeDetail.prop('contenteditable', false)
- $formatPageContent.find('h3').prop('contenteditable', false)
- $formatPageObjective.prop('contenteditable', false)
- //模块格式化html
- $originShortAnswer.each(function (index, el) {
- $(el)
- .children('.module')
- .each(function (idx, elm) {
- var $formatModuleItem = $formatShortAnswer
- .eq(index)
- .children('.module')
- .eq(idx)
- var $scortColumn = $(elm).children('.scortColumn')
- var $chooseArea = $(elm).children('.selTopic')
- var editorIndex = $(elm).attr('data-editorIndex')
- if (!editorIndex) return
- //富文本编辑内容
- var textareaContent = self.editorArea[
- 'editor' + editorIndex
- ].txt.html()
- //打分区域
- var scortAreaContent = $scortColumn.length
- ? $scortColumn[0].outerHTML
- : ''
- //多选区域
- var chooseAreaHtml = ''
- if ($chooseArea.length) {
- chooseAreaHtml += $chooseArea[0].outerHTML
- }
- //height content
- var modulePrintHeight = self.unitConversion.pxConversionMm(
- $(elm).height()
- )
- $formatModuleItem
- .height(modulePrintHeight + 'mm')
- .html(
- scortAreaContent +
- chooseAreaHtml +
- '<div class="modulePosition">' +
- textareaContent +
- '</div>'
- )
- })
- })
- //第三方静态资源识别
- var linkSrc = ''
- var scriptSrc = ''
- //用几张纸
- var paperLength = Math.ceil($formatPageContent.length / self.columns)
- paperLength = paperLength < 2 ? paperLength + 1 : paperLength
- var printHtmlForPaperHtml = ''
- for (var j = 0; j < paperLength; j++) {
- var printHtml = ''
- //判断奇数页 还是 偶数页
- var isEvenPaper = !((j + 1) % 2)
- var isFirstPaper = !j
- var scanDotPaperIndex = (j + 1) % 2 ? 1 : 2
- for (var k = 0; k < self.columns; k++) {
- var pageItem = $formatPageContent.eq(j * self.columns + k)
- var pageClass = pageItem.attr('class') || 'pageContent'
- var dtkContentHtml = pageItem.length
- ? pageItem.html()
- : self.tpls.forbiddenAreaTpl
- var bindingLineHtml = ''
- //奇数页面装订线在左边,偶数页面装订线在右边
- //奇数页面的第一个分栏 和 偶数页面的最后一个分栏 加上装订线,除了第一个
- if (self.hasBindingLine) {
- if (isEvenPaper && k + 1 === self.columns) {
- bindingLineHtml = self.tpls.bindLineTpl.substitute({ pos: 'right' })
- } else if (!isEvenPaper && !k && !isFirstPaper) {
- bindingLineHtml = self.tpls.bindLineTpl.substitute({ pos: 'left' })
- }
- }
- printHtml +=
- '<div class="' +
- pageClass +
- '" style="break-after: page;height:' +
- self.config.height +
- 'mm">' +
- bindingLineHtml +
- dtkContentHtml +
- '</div>'
- }
- var scanDotHtml = self.tpls['scanDotPaper' + scanDotPaperIndex]
- printHtmlForPaperHtml += self.tpls.printIframeContentTpl.substitute({
- bindingLine: self.hasBindingLine ? 'hasBindingLine' : '',
- previewClass: isPreview ? 'previewIframe' : '',
- columns: self.columns,
- widthMm: self.config.width,
- printHtml: printHtml + scanDotHtml,
- linkSrc: linkSrc,
- scriptSrc: scriptSrc
- })
- }
- //清空
- $('#formatContent').html('')
- return printHtmlForPaperHtml
- },
- //获取定位的基准点
- getPositionOriginPoint: function () {
- var self = this
- //每个分页的定位基准点都是当前分页的左上角
- self.printAreaLeft = $('#printcontent').offset().left
- self.printAreaTop = $('#printcontent').offset().top
- },
- //获取扫描点信息
- getScanPointInfo: function (currentPaper) {
- var self = this
- self.dotWidth = 40
- self.dotHeight = 20
- //大定位点上下间隙
- self.dotTBGap = 20
- //为了区分正反面,大定位点上面中间的那个点,需要正反面反向偏移一定距离
- self.offsetDistance = self.pageWidth / 2 - 50
- //获取页面的扫描点
- /**
- * 1.产品定义的区域
- * 2.客观题区域
- * 3.图片考号区域
- * 4.选做题区域
- */
- var hasBinding = self.hasBindingLine
- var pagePaddingSide = self.pagePaddingSide + (hasBinding ? 20 : 0)
- var location = [
- //上左
- {
- x: pagePaddingSide * self.dpiRadio,
- y: self.dotTBGap * self.dpiRadio,
- width: self.dotWidth * self.dpiRadio,
- height: self.dotHeight * self.dpiRadio,
- type: 1
- },
- //上右
- {
- x:
- (self.pageWidth - self.pagePaddingSide - self.dotWidth) *
- self.dpiRadio,
- y: self.dotTBGap * self.dpiRadio,
- width: self.dotWidth * self.dpiRadio,
- height: self.dotHeight * self.dpiRadio,
- type: 1
- },
- //下右
- {
- x: (self.pageWidth - self.pagePaddingSide - self.dotWidth) *
- self.dpiRadio,
- y: (self.pageHeight - self.dotTBGap - self.dotHeight) * self.dpiRadio,
- width: self.dotWidth * self.dpiRadio,
- height: self.dotHeight * self.dpiRadio,
- type: 1
- },
- //下左
- {
- x: pagePaddingSide * self.dpiRadio,
- y: (self.pageHeight - self.dotTBGap - self.dotHeight) * self.dpiRadio,
- width: self.dotWidth * self.dpiRadio,
- height: self.dotHeight * self.dpiRadio,
- type: 1
- }
- ]
- if (currentPaper === 1) {
- //上靠左边
- location.splice(1, 0, {
- x: self.offsetDistance * self.dpiRadio,
- y: self.dotTBGap * self.dpiRadio,
- width: self.dotWidth * self.dpiRadio,
- height: self.dotHeight * self.dpiRadio,
- type: 1
- })
- } else {
- //上靠右边
- location.splice(1, 0, {
- x: (self.pageWidth - self.offsetDistance - self.dotWidth) *
- self.dpiRadio,
- y: self.dotTBGap * self.dpiRadio,
- width: self.dotWidth * self.dpiRadio,
- height: self.dotHeight * self.dpiRadio,
- type: 1
- })
- }
- return location
- },
- getElementWidth: function (el, type) {
- var self = this
- var width = $(el).outerWidth()
- return width * self.dpiRadio
- },
- getElementHeight: function (el, type) {
- var self = this
- var height = $(el).outerHeight()
- return height * self.dpiRadio
- },
- getPositions: function () {
- var self = this
- /**
- * {paper,direction,hasBindingLine,examNumberConfig:{barCode,ticketNumber},useQrCode}
- */
- //Math.ceil(self.totalPage / self.columns)
- //每次获取每张纸的每一页定位信息,先确定 x轴,y轴的定位基准点
- self.getPositionOriginPoint()
- //是否合并题卡信息
- var $chooseAnswerInfo = $('.answerModule[data-type="chooseAnswer"]')
- var isConcat =
- self.isSubjectInfoToCard &&
- $('.objectiveItem').length &&
- $chooseAnswerInfo.length &&
- $chooseAnswerInfo.find('.originSubjectInfo').length
- //存储供新建答题卡的以及答题卡信息使用
- var memoryDtkInfo = {}
- if (isNewBuild) {
- var buildQuestions = self.questionMap
- if(self.$dtkName.val()){
- self.savePrintInfo.title = self.$dtkName.val()
- }
- // self.savePrintInfo.title = self.$dtkName.val()
- memoryDtkInfo = {
- ...self.savePrintInfo,
- buildQuestions,
- examInfoConfigText:self.examInfoConfigText,
- examInfoConfig:self.examInfoConfig,
- hasPaperMsg:self.hasPaperMsg
- }
- }
- var printPositionInfo = {
- totalPage: 2,
- //准考证类型
- school_card_status: self.school_card_status,
- //需要记录本次的paperTplType 是否为题卡合一
- isSubjectInfoToCard: self.isSubjectInfoToCard,
- //选做题题干信息单独保存
- chooseAnswerStemInfo: isConcat
- ? encodeURIComponent(
- $chooseAnswerInfo.find('.originSubjectInfo')[0].outerHTML
- )
- : '',
- //纸张大小、方向、分栏、装订线、考号配置等,需要记忆布局
- columns: self.columns,
- paper: self.paper,
- direction: self.direction,
- hasBindingLine: self.hasBindingLine,
- examNumberConfig: self.examNumberConfig,
- useQrCode: self.useQrCode,
- width: self.config.width,
- height: self.config.height,
- ...memoryDtkInfo,
- pages: []
- }
- //每张纸的一面
- var examNumberAreaData = self.getExamNumberPosition()
- var paperPosition = {
- 1: {
- pageNo: 1,
- //四个定位点信息
- location: self.getScanPointInfo(1),
- //条形码
- studentcode_bar: examNumberAreaData.studentcode_bar,
- //准考证号码
- studentcode_fill: examNumberAreaData.studentcode_fill,
- //缺考标记定位信息
- absent: self.getAbsentMarkPostion(),
- //学生二维码信息
- QrCode: self.getQrCodePosition(),
- //打印区域宽高
- imge: {
- width: self.pageWidth * self.dpiRadio, //self.config.width,
- height: self.pageHeight * self.dpiRadio //self.config.height
- },
- //题目坐标信息
- questions: []
- },
- 2: {
- pageNo: 2,
- //四个定位点信息
- location: self.getScanPointInfo(2),
- //打印区域宽高
- imge: {
- width: self.pageWidth * self.dpiRadio, //self.config.width,
- height: self.pageHeight * self.dpiRadio //self.config.height
- },
- //题目坐标信息
- questions: []
- }
- }
- //首先获取每个纸张一页的扫描点信息
- $('#printcontent .pageContent').each(function (pageIndex, pageItem) {
- var $pageItem = $(pageItem)
- //判断纸张的第一面还是第二面 or 正面还是反面
- var paperNo = Math.ceil((pageIndex + 1) / self.columns)
- $pageItem.find('.answerModule').each(function (k, moduleItem) {
- var type = $(moduleItem).attr('data-type')
- var modelId = $(moduleItem).attr('data-modelId')
- var moduleInfo = {
- type: self.questionTypeMapForPhp[type],
- modelId: modelId
- }
- var positionInfos = []
- switch (type) {
- case 'singleSelect':
- case 'moreSelect':
- case 'uncertainOption':
- positionInfos = self.getSingleSelectPositions(
- moduleItem,
- moduleInfo
- )
- break
- case 'answer':
- case 'mustAnswer':
- positionInfos = self.getAswerPositions(moduleItem, moduleInfo)
- break
- case 'chooseAnswer':
- positionInfos = self.getChooseAswerPositions(moduleItem, moduleInfo)
- break
- case 'fillInBlank':
- positionInfos = self.getFillInBlankPOsitions(moduleItem, moduleInfo)
- break
- }
- paperPosition[paperNo].questions = paperPosition[
- paperNo
- ].questions.concat(positionInfos)
- })
- })
- //题号重新排序
- let PositionData = JSON.parse(JSON.stringify(paperPosition))
- let TopicAll = [];
- jQuery.each(PositionData, function (i, val) {
- TopicAll = TopicAll.concat(val.questions)
- });
- function compare(key) {
- return function (value1, value2) {
- var val1 = value1[key];
- var val2 = value2[key];
- return val1 - val2;
- }
- }
- TopicAll.sort(compare('id'));
- let no = 0
- let pId = 0
- jQuery.each(TopicAll, function (i, topicItem) {
- if (topicItem.ChooseNum === undefined) {
- if (pId == topicItem.id) {
- topicItem.name = no
- } else {
- topicItem.name = no + 1
- no = no + 1
- }
- pId = topicItem.id
- } else {
- if (pId == topicItem.id) {
- topicItem.name = no
- } else {
- let tName = '';
- for (let ChooseNum = 0; ChooseNum < Number(topicItem.ChooseNum); ChooseNum++) {
- tName = tName + (tName != '' ? ',' : '') + (no + 1)
- no = no + 1
- }
- topicItem.name = tName
- pId = topicItem.id
- }
-
- }
- });
- jQuery.each(paperPosition, function (i, paperTopic) {
- jQuery.each(paperTopic.questions, function (j, paperTopicItem) {
- jQuery.each(TopicAll, function (k, topicAllItem) {
- if (!paperTopicItem.name) {
- if (Number(paperTopicItem.id) == Number(topicAllItem.id)) {
- let topic = JSON.parse(JSON.stringify(topicAllItem))
- paperTopicItem.id = topic.name.toString();
- paperTopicItem.name = topic.id;
- }
- }
- });
- });
- });
- for (var paperKey in paperPosition) {
- printPositionInfo.pages.push(paperPosition[paperKey])
- }
- printPositionInfo.identifier = self.identifier;
- // console.log(printPositionInfo)
- return printPositionInfo
- },
- //获取填空题获取选择题的题干信息
- getStemInfo: function () {
- var self = this
- var memoryObjectiveHtmls = ''
- $('.objectiveItem').each(function () {
- memoryObjectiveHtmls += encodeURIComponent($(this)[0].outerHTML) + '|end|'
- })
- return memoryObjectiveHtmls
- },
- //准考证和条形码区域
- getExamNumberPosition: function () {
- var self = this
- //是否使用二维码
- if (self.useQrCode) return {}
- //是否只是使用条形码
- var isOnlyBarCode = self.isOnlyBarCode()
- //判断显示的是准考证号还是条形码
- var isTicketNumber = self.examNumberConfig.ticketNumber
- var isBarCode = self.examNumberConfig.barCode
- var studentcodePosition = {
- studentcode_bar: {},
- studentcode_fill: {}
- }
- //准考证号
- if (isTicketNumber) {
- var numberWidth = false
- var numberHeight = false
- var $ticketNumberCol = $('#hgc_examNumber ul.ticketNumber').children(
- '.numberCol'
- )
- studentcodePosition.studentcode_fill = {
- object: []
- }
- $ticketNumberCol.each(function (k, numberColItem) {
- var group = []
- var $ticketNumberItem = $(numberColItem).find('i')
- $ticketNumberItem.each(function (m, numberItem) {
- var numberPosition = self.getItemPosition(numberItem, 'examNumber')
- numberWidth = numberWidth || self.getElementWidth(numberItem)
- numberHeight = numberHeight || self.getElementHeight(numberItem)
- group.push({
- x: numberPosition.x,
- y: numberPosition.y,
- width: numberWidth,
- height: numberHeight,
- optName: m
- })
- })
- studentcodePosition.studentcode_fill.object.push({
- group: group
- })
- })
- }
- //条形码
- if (isBarCode) {
- var examMarkEl = isOnlyBarCode
- ? $('#hgc_examNumberForOnlyBarcode .barCode')
- : $('#hgc_examNumber .barCode')
- var barCodePosition = self.getItemPosition(examMarkEl, 'barCode')
- studentcodePosition.studentcode_bar = {
- object: {
- x: barCodePosition.x,
- y: barCodePosition.y,
- width: self.getElementWidth(examMarkEl),
- height: self.getElementHeight(examMarkEl)
- }
- }
- }
- return studentcodePosition
- },
- //缺考标记
- getAbsentMarkPostion: function () {
- var self = this
- var $absentMark = $('.absentMark')
- var absentMarkPosition = self.getItemPosition($absentMark)
- var absentWidth = self.getElementWidth($absentMark)
- var absentHeight = self.getElementHeight($absentMark)
- return {
- x: absentMarkPosition.x,
- y: absentMarkPosition.y,
- width: absentWidth,
- height: absentHeight
- }
- },
- //二维码定位信息
- getQrCodePosition: function () {
- var self = this
- var $dtkEwm = $('#dtkEwm')
- var dtkEwmPosition = self.getItemPosition($dtkEwm)
- var dtkEwmWidth = self.getElementWidth($dtkEwm)
- var dtkEwmHeight = self.getElementHeight($dtkEwm)
- //if (!self.useQrCode) return {}
- return {
- x: dtkEwmPosition.x,
- y: dtkEwmPosition.y,
- width: dtkEwmWidth,
- height: dtkEwmHeight
- }
- },
- //单选题坐标获取
- getSingleSelectPositions: function (moduleItem, moduleInfo) {
- var self = this
- var optionInfos = []
- var direction = $(moduleItem).attr('data-direction')
- $(moduleItem)
- .find('li')
- .each(function (i, optionItems) {
- var optionInfo = {
- type: moduleInfo.type,
- modelId: moduleInfo.modelId,
- answer: $(optionItems).attr('data-answer'),
- score: {
- full: 5
- },
- id: $(optionItems).attr('title-number'),
- opt: [],
- direction: direction
- }
- $(optionItems)
- .children('span')
- .each(function (k, option) {
- var optionPosition = self.getItemPosition(option, 'select')
- var width = self.getElementWidth(option)
- var height = self.getElementHeight(option)
- var optName = $(option).attr('data-option')
- optionInfo.opt.push({
- x: optionPosition.x,
- y: optionPosition.y,
- width: width,
- height: height,
- optName: optName
- })
- })
- optionInfos.push(optionInfo)
- })
- return optionInfos
- },
- //填空题
- getFillInBlankPOsitions: function (moduleItem, moduleInfo) {
- var self = this
- var optionInfos = []
- $(moduleItem)
- .find('.subjectItem')
- .each(function (i, optionItems) {
- var $subjectCol = $(optionItems).parent('.subjectCol')
- var $score = $(optionItems).children('strong')
- var column = $subjectCol.attr('data-column')
- var scoreStyle = $subjectCol.attr('data-scoreStyle')
- var rowLineHeight = $subjectCol.attr('data-rowLineHeight')
- var optionPosition = self.getItemPosition(optionItems, 'fillInBlank')
- var width = self.getElementWidth(optionItems, 'fillInBlank')
- var height = self.getElementHeight(optionItems, 'fillInBlank')
- var scorePosition = self.getItemPosition($score)
- var scoreWidth = self.getElementWidth($score)
- var scoreHeight = self.getElementHeight($score)
- var optionInfo = {
- type: moduleInfo.type,
- modelId: moduleInfo.modelId,
- scorebox: {
- type: 3,
- Score: scoreStyle.split('/'),
- x: scorePosition.x,
- y: scorePosition.y,
- width: scoreWidth,
- height: scoreHeight
- },
- score: {
- full: 5
- },
- column: column || 1,
- scoreStyle: scoreStyle || '',
- rowLinHeight: rowLineHeight || '',
- id: $(optionItems).attr('title-number'),
- cut: {
- x: optionPosition.x,
- y: optionPosition.y,
- width: width,
- height: height
- }
- }
- optionInfos.push(optionInfo)
- })
- return optionInfos
- },
- //解答题坐标获取
- //针对全学科的记忆布局不同,全学科记忆布局都是一套数据源
- getAswerPositions: function (moduleItem, moduleInfo) {
- var self = this
- var answerInfos = []
- var modelId = $(moduleItem).attr('data-modelid');
- $(moduleItem)
- .find('.module')
- .each(function (m, moduleEl) {
- var marktype = 0;
- var modulePositon = self.getItemPosition(moduleEl, 'answer')
- var width = self.getElementWidth(moduleEl, 'answer')
- var height = self.getElementHeight(moduleEl, 'answer')
- var titleNumber = $(moduleEl).attr('title-number') //questionNum
- var isAddHalf = false
- self.questionMap[modelId].questions.forEach(function (item) {
- if (item.questionNum == titleNumber) {
- marktype = item.marktype ? item.marktype : 0;
- }
- })
- isAddHalf = self.questionMap[modelId].dialogData.isAddHalf
- //分值格式
- var $scoreColumn = $(moduleEl).children('.scortColumn')
- var scoreLimit = $(moduleEl).attr('scorelimit') || '16'
- var limit = $(moduleEl).attr('data-fullscore') || '16'
- // var isAddHalf = $(moduleEl).attr('isAddHalf') === 'true'
- var scorePosition = self.getItemPosition($scoreColumn)
- var scoreWidth = self.getElementWidth($scoreColumn, 'answer')
- var scoreHeight = self.getElementHeight($scoreColumn, 'answer')
- let noScoringWidth = $($scoreColumn).find('.no-scoring').width();
- if (noScoringWidth != null) {
- scoreWidth = scoreWidth - noScoringWidth
- }
- /**
- * "scorebox":{
- "type":1,
- "Score":[2, 3,5]
- limit:16
- "x":1517.4015748031497,
- "y":20,
- "width":40,
- "height":20,
- }
- point:1 表示最后一个是0.5分 0表示没有0.5
- type 1: 16 limit:12 OR 14 OR 16
- type 2: 29/49 limit: 29 49
- type 3:具体分值在score里面给出枚举: 2 3 5 , 2 3 4 6 limit 无效
- */
- //判断当前区域是否有超出的链接模块
- var linkParm = +$(moduleEl).attr('data-linkparm') || 0
- var cutId = $(moduleEl).attr('data-cutId')
- var editorId = $(moduleEl).attr('data-editorindex')
- var answerInfo = {
- type: moduleInfo.type,
- modelId: moduleInfo.modelId,
- id: titleNumber,
- marktype: marktype,
- scoreLimit: scoreLimit,
- editorId: editorId,
- contents: encodeURIComponent(
- self.editorArea['editor' + editorId].txt.html().replace(/<!--[\w\W\r\n]*?-->/gim, '')
- ),
- cut: {
- x: modulePositon.x,
- y: modulePositon.y,
- width: width,
- height: height,
- cutid: cutId,
- linkparm: linkParm
- },
- scorebox: {
- type: ~'16|15'.indexOf(Number(scoreLimit)) ? '1' : '2',
- limit: limit,
- point: isAddHalf ? 1 : 2,
- x: scorePosition.x,
- y: scorePosition.y,
- width: scoreWidth,
- height: scoreHeight
- }
- }
- answerInfos.push(answerInfo)
- })
- return answerInfos
- },
- //选做题坐标获取
- getChooseAswerPositions: function (moduleItem, moduleInfo) {
- var self = this
- var chooseAnswerInfos = []
- var modelId = $(moduleItem).attr('data-modelid');
- $(moduleItem)
- .find('.module')
- .each(function (n, moduleEl) {
- var modulePositon = self.getItemPosition(moduleEl, 'chooseAnswer')
- var width = self.getElementWidth(moduleEl, 'answer')
- var height = self.getElementHeight(moduleEl, 'answer')
- var titleNumber = $(moduleEl).attr('title-number')
- var scoreLimit = $(moduleEl).attr('scorelimit') || '16'
- var limit = $(moduleEl).attr('data-fullscore') || '16'
- //分值格式
- var $scoreColumn = $(moduleEl).children('.scortColumn')
- var scoreLimit = $(moduleEl).attr('scorelimit') || '16'
- // var isAddHalf = $(moduleEl).attr('isAddHalf') === 'true'
- isAddHalf = self.questionMap[modelId].dialogData.isAddHalf
- var scorePosition = self.getItemPosition($scoreColumn)
- var scoreWidth = self.getElementWidth($scoreColumn, 'answer')
- var scoreHeight = self.getElementHeight($scoreColumn, 'answer')
- let noScoringWidth = $($scoreColumn).find('.no-scoring').width();
- if (noScoringWidth != null) {
- scoreWidth = scoreWidth - noScoringWidth
- }
- //是否是上一题的补充区域
- //判断当前区域是否有超出的链接模块
- var linkParm = +$(moduleEl).attr('data-linkparm') || 0
- var cutId = $(moduleEl).attr('data-cutId')
- var editorId = $(moduleEl).attr('data-editorindex')
- //选择题目数量
- var selCount = 1
- for (var choosePage in self.chooseAnswer) {
- var pageChooseAnswer = self.chooseAnswer[choosePage]
- if (pageChooseAnswer.length) {
- selCount = pageChooseAnswer[0].required
- break
- }
- }
- let bigTopicData = self.questionMap[moduleInfo.modelId]
- var chooseAnswerInfo = {
- type: moduleInfo.type,
- modelId: moduleInfo.modelId,
- id: titleNumber,
- ChooseNum: bigTopicData.commonFields.ChooseNum,
- scoreLimit: scoreLimit,
- editorId: editorId,
- select: selCount,
- contents: encodeURIComponent(
- self.editorArea['editor' + editorId].txt.html().replace(/<!--[\w\W\r\n]*?-->/gim, '')
- ),
- total: titleNumber.split(',').length,
- scorebox: {
- type: ~'15|16'.indexOf(Number(scoreLimit)) ? '1' : '2',
- limit: limit,
- point: isAddHalf ? 1 : 2,
- x: scorePosition.x,
- y: scorePosition.y,
- width: scoreWidth,
- height: scoreHeight
- },
- selectqts: [
- {
- cut: {
- x: modulePositon.x,
- y: modulePositon.y,
- width: width,
- height: height,
- cutid: cutId,
- linkparm: linkParm
- },
- opt: []
- }
- ]
- }
- $(moduleEl)
- .find('.selTopic span')
- .each(function (l, selItem) {
- var optName = $(selItem).attr('data-titleNumber')
- var selItemPosition = self.getItemPosition(selItem, 'selTopic')
- var width = self.getElementWidth(selItem)
- var height = self.getElementHeight(selItem)
- var optNameAbc = String.fromCharCode(65 + l)
- ////console.log(width,height)
- chooseAnswerInfo.selectqts[0].opt.push({
- optName: optNameAbc,
- width: width,
- height: height,
- x: selItemPosition.x,
- y: selItemPosition.y
- })
- })
- chooseAnswerInfos.push(chooseAnswerInfo)
- })
- return chooseAnswerInfos
- },
- /**
- *
- * @param {想要定位的元素} el
- * @param {打印区域靠左距离} printAreaLeft
- * @param {打印区域靠右距离} printAreaTop
- * @param {是不是富文本解答题} isModule
- * 如果是分栏 偶数页面的X轴定位点都要 加一个固定分页的宽
- */
- getItemPosition: function (el, moduleType) {
- var self = this
- if (!$(el).length) return {}
- var curPage = $(el).closest('.pageContent')
- var curPageIndex = curPage.index() + 1
- var positionY = $(el).offset().top - self.printAreaTop
- var positionX = $(el).offset().left - self.printAreaLeft
- //定位坐标向右偏移位置
- var columnLeft = 0
- //是否第一面
- var isFirstPaper = curPageIndex <= self.columns
- //考虑分栏的定位点
- //当前在第几栏
- var curPageColumns =
- curPageIndex % self.columns ? curPageIndex % self.columns : self.columns
- //一栏宽度
- var oneColumnsWidth = self.pageWidth / self.columns
- columnLeft = oneColumnsWidth * (curPageColumns - 1)
- //有装订线的情况需要第一页减去多余的
- if (self.hasBindingLine) {
- positionX -= 20
- }
- if (curPageIndex > 1) {
- positionY -= (curPageIndex - 1) * self.pageHeight
- }
- return {
- x: (positionX + columnLeft - self.pagePaddingSide) * self.dpiRadio,
- y: (positionY - 20) * self.dpiRadio
- }
- },
- /**
- *
- * 添加题目
- * 根据题目类型,重置 该题型的所有数据
- */
- appendSubject: function (buildQuestions, modelId) {
- var self = this
- var questionModel = buildQuestions[modelId]
- var modelRenderKey = self.questionTypeMapForC[questionModel.questionType]
- var $lastPage = $('#printcontent .pageContent:last()')
- var $lastPageContent = $lastPage.children('.dtk-content')
- var currentPage = $lastPage.index() + 1
- questionModel.pages = questionModel.pages || {}
- questionModel.pages['page' + currentPage] = questionModel.questions
- //新加分页字段,重新设置
- localStorage.setItem('buildQuestions', JSON.stringify(buildQuestions))
- self.questionMap = buildQuestions
- //渲染右侧操作栏 题目列表信息 -- 可重复执行
- self.renderSubjectListInfo(buildQuestions)
- //保存题目定位点的时候 获取 题目数量 分数 等信息 -- 可重复执行
- self.getSaveSubjectInfo(buildQuestions)
- //模块渲染
- self[modelRenderKey + 'Render'](questionModel, $lastPageContent)
- self.changePrintArea($lastPage)
- },
- //编辑试题
- editSubject: function (buildQuestions, modelId) {
- var self = this
- var questionModel = buildQuestions[modelId]
- var modelRenderKey = self.questionTypeMapForC[questionModel.questionType]
- var $changePage = null
- var $replaceEl = null
- $('.answerModule').each(function () {
- if ($(this).attr('data-modelId') === modelId) {
- if ($changePage) {
- $(this).remove()
- } else {
- $changePage = $(this).closest('.pageContent')
- $replaceEl = $(this)
- }
- }
- })
- var currentPage = $changePage.index() + 1
- questionModel.pages = questionModel.pages || {}
- questionModel.pages['page' + currentPage] = questionModel.questions
- //重新设置
- localStorage.setItem('buildQuestions', JSON.stringify(buildQuestions))
- //渲染右侧操作栏 题目列表信息 -- 可重复执行
- self.renderSubjectListInfo(buildQuestions)
- //保存题目定位点的时候 获取 题目数量 分数 等信息 -- 可重复执行
- self.getSaveSubjectInfo(buildQuestions)
- //模块渲染
- self[modelRenderKey + 'Render'](questionModel, null, $replaceEl)
- // selectStyleChange: function($this, direction)
- // fillInBlankStyleChange: function($this, column, rowLinHeight, scoreStyle)
- // shortAnswerStyleChange: function($this, scoreLimitKey, isAddHalf)
- var $settingBtn = self.getSettingBtn(modelId)
- if (~modelRenderKey.indexOf('Select') || ~modelRenderKey.indexOf('uncertainOption')) {
- var direction = questionModel.direction ? 'vertical' : 'horizontal'
- self.selectStyleChange($settingBtn, direction)
- } else if (modelRenderKey === 'fillInBlank') {
- var columns = questionModel.columns
- var rowLineHeight = questionModel.rowLineHeight
- var scoreStyle = questionModel.scoreStyle
- self.fillInBlankStyleChange(
- $settingBtn,
- columns,
- rowLineHeight,
- scoreStyle
- )
- } else {
- var isAddHalf = questionModel.isAddHalf
- var scoreLimit = questionModel.scoreLimit
- // self.shortAnswerStyleChange($settingBtn, scoreLimit, isAddHalf)
- }
- this.initPageTopic();
- },
- initPageTopic() {
- $('.h_radioItem.checked').eq(1).click();
- $('.pageContent').each(function () {
- if ($(this).children().eq(0).children().length == 0) {
- $(this).remove();
- }
- })
- $(".pageContent .totalPage").html($('.pageContent').length)
- self.totalPage = $('.pageContent').length
- }
- }
- $(function () {
- Print.init(sizeConfig)
- })
|