shr.js 137 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890
  1. /*
  2. * 描述:shr命名空间构造器
  3. * @class 用来构建js 对象的命名空间
  4. * @constructor
  5. * @return 返回构造完成的命名空间(JS对象)
  6. */
  7. var Namespace = {
  8. /*
  9. * 描述:注册命名空间
  10. * @param {String} fullNS 命名空间名称
  11. * @return 返回造建完成的命名空间
  12. */
  13. register : function(fullNS) {
  14. var nsArray = fullNS.split('.');
  15. var sEval = "";
  16. var sNS = "";
  17. for (var i = 0; i < nsArray.length; i++) {
  18. if (i != 0)
  19. sNS += ".";
  20. sNS += nsArray[i];
  21. sEval += "if (typeof(" + sNS + ") == 'undefined') " + sNS
  22. + " = new Object();"
  23. }
  24. if (sEval != "")
  25. return eval(sEval);
  26. }
  27. };
  28. /**
  29. * 重写jquery init方法来过滤下selector中的特殊字符
  30. * 不能处理"#test1,#test2"多个选择器的情况
  31. */
  32. var selector_special_char_regex = /[!"#$%&'()*+,.\/:;<=>?@\[\\\]\^`{|}~]/g;
  33. var waf = $;
  34. var shr = $;
  35. var _top = getTop();
  36. var _ajaxFnCache = $.ajax;
  37. $.ajax = function (url, options){
  38. // toodo 参考 jquery.js ajax实现
  39. if ( typeof url === "object" ) {
  40. options = url;
  41. url = undefined;
  42. }
  43. options = options || {};
  44. //shr.dealPostParam会修改options,防止影响外部参数引用
  45. var newOptions = $.extend(true,{},options);
  46. shr.dealPostParam( newOptions );
  47. return _ajaxFnCache(url, newOptions);
  48. };
  49. function detectBrowser () {
  50. // Useragent RegExp
  51. var rwebkit = /(webkit)[ \/]([\w.]+)/;
  52. var ropera = /(opera)(?:.*version)?[ \/]([\w.]+)/;
  53. var rmsie = /(msie) ([\w.]+)/;
  54. var rmozilla = /(mozilla)(?:.*? rv:([\w.]+))?/;
  55. var browser = {};
  56. // Use of jQuery.browser is frowned upon.
  57. // More details: http://docs.jquery.com/Utilities/jQuery.browser
  58. var uaMatch = function( ua ) {
  59. ua = ua.toLowerCase();
  60. var match = rwebkit.exec( ua ) ||
  61. ropera.exec( ua ) ||
  62. rmsie.exec( ua ) ||
  63. ua.indexOf("compatible") < 0 && rmozilla.exec( ua ) ||
  64. [];
  65. return { browser: match[1] || "", version: match[2] || "0" };
  66. }
  67. var browserMatch = uaMatch( window.navigator.userAgent );
  68. if ( browserMatch.browser ) {
  69. browser[ browserMatch.browser ] = true;
  70. browser.version = browserMatch.version;
  71. }
  72. // Deprecated, use jQuery.browser.webkit instead
  73. if ( browser.webkit ) {
  74. browser.safari = true;
  75. }
  76. return browser;
  77. }
  78. shr.extend({
  79. /**
  80. * 解决jQuery高版本下不支持浏览器检测问题
  81. */
  82. browser: jQuery.browser || detectBrowser(),
  83. initPrivacyAgreement: function(options){
  84. var $mask = $('<div id="shr-mask-agreement"><div>').appendTo($('body'));
  85. $mask.css({
  86. "display" : "block",
  87. "color" : "#fff",
  88. "position" : "fixed",
  89. "top" : "0px",
  90. "left" : "0px",
  91. "background-color" : 'black',
  92. "opacity" : 0.4,
  93. "-moz-opacity" : 0.4,
  94. "filter" : "alpha(opacity=" + (0.4 * 100) + ")",
  95. "width" : "100%",
  96. "height" : "100%",
  97. "z-index": "1024"
  98. });
  99. $('html').css({'overflow':'hidden'});
  100. var tpl = [
  101. '<div class="privacyPolicy">',
  102. '<div class="title" title="${name}">${name}</div>',
  103. '<div class="content">$${content}</div>',
  104. '<div class="privacyPolicyFoot">',
  105. '<button id="privacyAgree" type="button" class="shrbtn">' + $.shrI18n.privacy.msg2 +'</button>',
  106. '<button id="privacyReject" type="button" class="shrbtn">' + $.shrI18n.privacy.msg14 +'</button>',
  107. '</div>',
  108. '</div>'
  109. ].join('');
  110. var privacyHtml = juicer(tpl,options.data);
  111. $("body").append(privacyHtml);
  112. $('#privacyAgree').click(function(){
  113. if (typeof options.agree !== "function") return;
  114. options.agree();
  115. });
  116. $('#privacyReject').click(function(){
  117. if (typeof options.reject !== "function") return;
  118. options.reject();
  119. });
  120. },
  121. hidePrivacyAgreement: function(){
  122. var iframes = top.document.getElementsByTagName('iframe');
  123. if(iframes.length > 0) {
  124. for(var i = 0;i < iframes.length;i++) {
  125. mask = iframes[i].contentWindow.document.getElementById('shr-mask-agreement');
  126. $(mask).remove();
  127. }
  128. }
  129. $("div#shr-mask-agreement").remove();
  130. $("div#shr-mask-agreement", top.parent.document).remove();
  131. $('html').css({'overflow':'visible'});
  132. $('.privacyPolicy').remove();
  133. },
  134. startMask: function(opacity, load){
  135. opacity = (opacity || 0.16);
  136. if(load) {
  137. var $mask = $('<div id="shr-mask"><img src="/shr/styles/images/loading.gif" style="position:absolute;left:50%;top:50%;margin-left:-40px;margin-top:-40px;"><div>').appendTo($('body'));
  138. $mask.css({
  139. "display" : "block",
  140. "color" : "#fff",
  141. "position" : "fixed",
  142. "top" : "0px",
  143. "left" : "0px",
  144. "background-color" : 'gray',
  145. "opacity" : opacity,
  146. "-moz-opacity" : opacity,
  147. "filter" : "alpha(opacity=" + (opacity * 100) + ")",
  148. "width" : "100%",
  149. "height" : "100%",
  150. "z-index": "9999"
  151. });
  152. return;
  153. }
  154. var $mask = $('<div id="shr-mask"><div>').appendTo($('body'));
  155. $mask.css({
  156. "display" : "block",
  157. "color" : "#fff",
  158. "position" : "fixed",
  159. "top" : "0px",
  160. "left" : "0px",
  161. "background-color" : 'black',
  162. "opacity" : opacity,
  163. "-moz-opacity" : opacity,
  164. "filter" : "alpha(opacity=" + (opacity * 100) + ")",
  165. "width" : "100%",
  166. "height" : "100%",
  167. "z-index": "1024"
  168. });
  169. },
  170. //重写eval方法
  171. codeEval: function ( code ){
  172. var script;
  173. if ( code ) {
  174. var data_key = '_process_json_data_'+parseInt(shr.randMath());
  175. code = 'window["'+data_key+'"]=('+code+');'
  176. script = document.createElement("script");
  177. script.text = code;
  178. document.head.appendChild( script ).parentNode.removeChild( script );
  179. return window[data_key];
  180. }
  181. return null;
  182. },
  183. //附件上传中需要用到的fileUUID
  184. getAttachmentFileUUID: function(){
  185. if( $(".attachmentUploadArea").length > 0
  186. && $(".attachmentUploadArea").hasClass('standardAttachment')){
  187. var mainPageDom = $(".attachmentUploadArea").closest(".view_mainPage");
  188. var uuid = '';
  189. //多行表单的时候需要取view_mainPage上的uuid去拿viewPage
  190. if(mainPageDom.length && mainPageDom.attr('id')){
  191. uuid = mainPageDom.attr('id');
  192. }
  193. var currentPage = shr.getCurrentViewPage(uuid);
  194. var attachmentFileUUID = currentPage ? currentPage.attachmentFileUUID: '';
  195. return attachmentFileUUID;
  196. }
  197. },
  198. //生成附件fileUUID
  199. generateAttachmentFileUUID : function(){
  200. var attachmentFileUUID = '';
  201. if ($(".attachmentUploadArea").length > 0) {
  202. attachmentFileUUID = shr.generateUUID();
  203. }
  204. return attachmentFileUUID;
  205. },
  206. //在接口中设置附件上传中需要用到的UUID
  207. _addAttachmentFileUUID : function(data){
  208. if(data){
  209. var attachmentFileUUID = shr.getAttachmentFileUUID();
  210. if( $(".attachmentUploadArea").length > 0
  211. && $(".attachmentUploadArea").hasClass('standardAttachment')
  212. && attachmentFileUUID ){
  213. data.fileUUID = attachmentFileUUID;
  214. }
  215. }
  216. },
  217. //生成UUID
  218. generateUUID: function() {
  219. var uuid = '';
  220. var d = new Date().getTime();
  221. if (window.performance && typeof window.performance.now === "function") {
  222. d += performance.now();
  223. }
  224. uuid = 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c) {
  225. var r = (d + Math.random() * 16) % 16 | 0;
  226. d = Math.floor(d / 16);
  227. return (c == 'x' ? r : (r & 0x3 | 0x8)).toString(16);
  228. });
  229. return uuid;
  230. },
  231. //随机数
  232. randMath: function(number){
  233. number = number? number : 100000;
  234. var seed = (new Date()).getTime();
  235. function r(){
  236. seed = (seed*9301+49297)%233280;
  237. return seed/(233280.0);
  238. }
  239. return Math.ceil(r()*number);
  240. },
  241. stopMask: function(){
  242. //对于界面存在多个iframe时,关闭提示不能移除所有遮罩
  243. var iframes = top.document.getElementsByTagName('iframe');
  244. if(iframes.length > 0) {
  245. for(var i = 0;i < iframes.length;i++) {
  246. mask = iframes[i].contentWindow.document.getElementById('shr-mask');
  247. $(mask).remove();
  248. }
  249. }
  250. $("div#shr-mask").remove();
  251. },
  252. // 增加一个关闭Mask的方法,用来提示浏览器缩放时的关闭。
  253. stopAllMask: function(){
  254. //对于界面存在多个iframe时,关闭提示不能移除所有遮罩
  255. var iframes = top.document.getElementsByTagName('iframe');
  256. if(iframes.length > 0) {
  257. for(var i = 0;i < iframes.length;i++) {
  258. mask = iframes[i].contentWindow.document.getElementById('shr-mask');
  259. $(mask).remove();
  260. }
  261. }
  262. $("div#shr-mask").remove();
  263. $("div#shr-mask", top.parent.document).remove();
  264. },
  265. /**
  266. * 获取当前的语言类型
  267. * 判断语言类型规则:当字符串中存在中午字符、英文字符和数字时,规则是中文字符安>英文字符>数字
  268. * @param {value}
  269. */
  270. getValueLanguageType: function(value) {
  271. if(escape(value).indexOf('%u') > -1) {
  272. return 'zh_CN';
  273. }else if(/[a-z]/i.test(value)) {
  274. return 'en_US';
  275. }else{
  276. return 'number';
  277. }
  278. },
  279. getCommonForUrl: function (someWindow, re) {
  280. if (!someWindow) {
  281. someWindow = _top;
  282. }
  283. var ret = re.exec(someWindow.location.href);
  284. return (ret && ret.length > 1) ? ret[1] : '';
  285. },
  286. /**
  287. * 过滤掉jquery选择器中的特殊字符串
  288. */
  289. filterSelectorSpecialChar: function (selector) {
  290. var _selector = selector;
  291. if (typeof selector == "string") {
  292. _selector = selector.replace(selector_special_char_regex, "\\$&");
  293. }
  294. return _selector;
  295. },
  296. /**
  297. * 描述:获取当前语种标识
  298. * zh_CN |中文
  299. *en_US |英文
  300. *zh_TW |繁体
  301. */
  302. getContext: function () {
  303. if (!shr.context) {
  304. shr.context = { locale: window.contextLanguage };
  305. }
  306. return shr.context;
  307. },
  308. //处理安全漏洞扫描出来的json注入
  309. explainJson: function( data ) {
  310. var rvalidescape = /\\(?:["\\\/bfnrt]|u[0-9a-fA-F]{4})/g;
  311. var rvalidtokens = /"[^"\\\n\r]*"|true|false|null|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?/g;
  312. var rvalidbraces = /(?:^|:|,)(?:\s*\[)+/g;
  313. var rvalidchars = /^[\],:{}\s]*$/;
  314. if ( typeof data !== "string" || !data ) {
  315. return null;
  316. }
  317. // Make sure leading/trailing whitespace is removed (IE can't handle it)
  318. data = jQuery.trim( data );
  319. // Make sure the incoming data is actual JSON
  320. // Logic borrowed from http://json.org/json2.js
  321. if ( rvalidchars.test(data.replace(rvalidescape, "@").replace(rvalidtokens, "]").replace(rvalidbraces, "")) ) {
  322. // Try to use the native JSON parser first
  323. return window.JSON && window.JSON.parse ?window.JSON.parse( data ) : (new Function("return " + data))();
  324. } else {
  325. jQuery.error( "Invalid JSON: " + data );
  326. }
  327. },
  328. /**
  329. * 根据语言环境获取多语言字段对应语言值
  330. * 作用:当前的en_US,zh_CN,zh_TW环境与l1,l2,13的映射
  331. * @param lan en_US、zh_CN、zh_TW 可以通过shr.getContext().locale或者window.contextLanguage获取
  332. * @return l1、l2、13
  333. * */
  334. getFieldLangByContext: function (lan) {
  335. var locale = 'zh_CN';
  336. if(lan){
  337. locale = lan;
  338. }else if(shr.getContext().locale){
  339. locale = shr.getContext().locale;
  340. }
  341. var each = null;
  342. for (var i = 0, total = window.languageMappingList.length;i<total;i++){
  343. each = window.languageMappingList[i];
  344. if(each['locale'] == locale){
  345. return each['lang'];
  346. }
  347. }
  348. return 'l2';
  349. },
  350. /**
  351. * 校验是否有xss注入
  352. */
  353. verifyXss: function(targetVal,noVerify){
  354. if(noVerify) return;
  355. //过滤script|link|style|iframe标签
  356. var reg1 = /<(script|link|style|iframe)(.|\n)*\/\1>\s*/ig;
  357. //过滤on开头的标签属性
  358. var reg2 = /\s*(ontoggle|ondragend|onunload|onsubmit|onscroll|onclick|onchange|onblur|onbefore|onafter|onactivate|onselect|onload|onkey|onfocus|onhelp|ondrop|onfinish|onerror|eval|expression|onclick|ondbclick|onmousedown|onmouseup|prompt)\s*=/ig;
  359. //过滤src和href的伪协议
  360. var reg3 = /\s*(href|src)\s*=/ig;
  361. //过滤alert的伪协议
  362. var reg4 = /\s*(alert|confirm(?!\s*ed))\s*/ig;
  363. if(reg1.test(targetVal) || reg2.test(targetVal) || reg3.test(targetVal) || reg4.test(targetVal)){
  364. return true;
  365. }else{
  366. return false;
  367. }
  368. },
  369. /**
  370. * xss过滤
  371. */
  372. xssFilter: function(targetVal){
  373. //XSS过滤
  374. if((typeof targetVal) != 'string'){
  375. return targetVal;
  376. }
  377. if(shr.verifyXss(targetVal)){
  378. // 1.前端简单转义,主要对 < > 处理 2,服务端对特殊字符拦截
  379. return $.htmlEncode(targetVal);
  380. }else{
  381. return targetVal;
  382. }
  383. },
  384. /**
  385. * 防止恶意url
  386. */
  387. safeUrl: function(url, whiteChars){
  388. var strRegex = '^((https|http|ftp)://)?'//(https或http或ftp):// 可有可无
  389. + '(([\\w_!~*\'()\\.&=+$%-]+: )?[\\w_!~*\'()\\.&=+$%-]+@)?' //ftp的user@ 可有可无
  390. + '(([0-9]{1,3}\\.){3}[0-9]{1,3}' // IP形式的URL- 3位数字.3位数字.3位数字.3位数字
  391. + '|' // 允许IP和DOMAIN(域名)
  392. + '(localhost)|' //匹配localhost
  393. + '([\\w_!~*\'()-]+\\.)*' // 域名- 至少一个[英文或数字_!~*\'()-]加上.
  394. + '\\w+\\.' // 一级域名 -英文或数字 加上.
  395. + '[a-zA-Z]{1,6})' // 顶级域名- 1-6位英文
  396. + '(:[0-9]{1,5})?' // 端口- :80 ,1-5位数字
  397. + '((/?)|' // url无参数结尾 - 斜杆或这没有
  398. + '(/[\\w_!~*\'()\\.;?:@&=+$,%#-]+)+/?)$';//请求参数结尾- 英文或数字和[]内的各种字符
  399. var re=new RegExp(strRegex,'i');//i不区分大小写
  400. //将url做uri转码后再匹配,解除请求参数中的中文和空字符影响
  401. if (re.test(encodeURI(url))) {
  402. return url;
  403. }else {
  404. return url;
  405. }
  406. },
  407. /**
  408. * 获取协议和域名
  409. */
  410. getProtocolAndDomain: function (someWindow) {
  411. var re = (/^((?:http|https)(?:\:\/\/)[^\/]+)/i);
  412. return this.getCommonForUrl(someWindow, re);
  413. },
  414. /**
  415. * 获取协议
  416. */
  417. getProtocol: function (someWindow) {
  418. var _window = (someWindow || _top);
  419. return _window.location.protocol;
  420. },
  421. /**
  422. * 获取域名
  423. */
  424. getDomain: function (someWindow) {
  425. var _window = (someWindow || _top);
  426. return _window.location.host;
  427. },
  428. /**
  429. * 获取serviceId
  430. */
  431. getServiceId: function (someWindow) {
  432. var _win = _top;
  433. if (someWindow) {
  434. _win = someWindow;
  435. }
  436. return shr.getUrlRequestParam('serviceId', _win.location.href);
  437. },
  438. /**
  439. * F7请求头的特征值
  440. */
  441. getXShrEncryptF7Value: function(){
  442. return window.systemParamForShr['encryptDB']+'_'+window.systemParamForShr['encryptUser']+'_'+window.systemParamForShr['encryptContext'];
  443. },
  444. /**
  445. * 获取数据中心
  446. */
  447. getDataCenter: function () {
  448. var dataCenter = _top.localStorage.getItem('FAccountDCName');
  449. if (dataCenter === 'undefined') {
  450. return;
  451. }
  452. return dataCenter;
  453. },
  454. /**
  455. * 提供通用的SessionStorage存储方法
  456. * 整个系统最好统一调用此方法
  457. * @param key 关键字 必须
  458. * @param billId 表单Id 可选
  459. * @param value 必须
  460. */
  461. setSessionStorage:function(key,billId,value){
  462. sessionStorage.setItem(this.genStorageKey(key,billId),value);
  463. },
  464. /**提供通用的SessionStorage获取方法
  465. * 整个系统最好统一调用此方法
  466. * @param key 关键字 必须
  467. * @param billId 表单Id 可选
  468. * @param value 必须
  469. */
  470. getSessionStorage:function(key,billId){
  471. return sessionStorage.getItem(this.genStorageKey(key,billId));
  472. },
  473. /**
  474. * 提供通用的LocalStorage 存入方法
  475. * 整个系统最好统一调用此方法
  476. * @param key 关键字 必须
  477. * @param billId 表单Id 可选
  478. * @param value 必须
  479. */
  480. setLocalStorage:function(key,billId,value){
  481. localStorage.setItem(this.genStorageKey(key,billId),value);
  482. },
  483. /**
  484. * 提供通用的LocalStorage 获取方法
  485. * 整个系统最好统一调用此方法
  486. * @param key 关键字 必须
  487. * @param billId 表单Id 可选
  488. */
  489. getLocalStorage:function(key,billId){
  490. return localStorage.getItem(this.genStorageKey(key,billId));
  491. },
  492. /**
  493. * SessionStorage 或者 LocalStorage 的key的生成方式,以contextId+key[+单据id(可选)]
  494. */
  495. genStorageKey:function(key,billId){
  496. if(key == 'data-navigationData'){
  497. return 'data-navigationData';
  498. }
  499. var key = window.systemParamForShr.encryptContext + '#' + key;
  500. if(billId){
  501. key += '#' + billId;
  502. }
  503. return key;
  504. },
  505. /**
  506. * 提供通用的LocalStorage 值移除方法
  507. * 整个系统最好统一调用此方法
  508. * @param key 关键字 必须
  509. * @param billId 表单Id 可选
  510. */
  511. removeLocalStorageItem:function(key,billId){
  512. localStorage.removeItem(this.genStorageKey(key,billId));
  513. },
  514. /**
  515. * 提供通用的SessionStorage 值移除方法
  516. * 整个系统最好统一调用此方法
  517. * @param key 关键字 必须
  518. * @param billId 表单Id 可选
  519. */
  520. removeSessionStorageItem:function(key,billId){
  521. sessionStorage.removeItem(this.genStorageKey(key,billId));
  522. },
  523. /**
  524. * 获取浏览器类型
  525. */
  526. getBowserInfo : function(){
  527. var Sys = {};
  528. var ua = navigator.userAgent.toLowerCase();
  529. var s;
  530. (s = ua.match(/rv:([\d.]+)\) like gecko/)) ? Sys.ie = s[1] :
  531. (s = ua.match(/msie ([\d.]+)/)) ? Sys.ie = s[1] :
  532. (s = ua.match(/firefox\/([\d.]+)/)) ? Sys.firefox = s[1] :
  533. (s = ua.match(/chrome\/([\d.]+)/)) ? Sys.chrome = s[1] :
  534. (s = ua.match(/opera.([\d.]+)/)) ? Sys.opera = s[1] :
  535. (s = ua.match(/version\/([\d.]+).*safari/)) ? Sys.safari = s[1] : 0;
  536. if (Sys.ie) return { browser : "IE" , version :Sys.ie};
  537. if (Sys.firefox) return { browser : "Firefox" , version :Sys.firefox};
  538. if (Sys.chrome) return { browser : "Chrome" , version :Sys.chrome };
  539. if (Sys.opera) return { browser : "Opera" , version :Sys.opera };
  540. if (Sys.safari) return { browser : "Safari" ,version : Sys.safari };
  541. },
  542. /**
  543. *描述:ajax请求超时时间
  544. */
  545. ajaxTimeout: 600000,
  546. /**
  547. * ajax请求时出现阻塞提示最小间隔时间
  548. */
  549. blockMinTime: 100,
  550. dynamicURL: '/dynamic.do',
  551. openServiceURL: '/shr/msf/service.do',
  552. getTreeDataURL: '/dynamic.do?method=getTreeData',
  553. /**
  554. * 描述:注册命名空间,并返回
  555. * @param {String} 名称空间路径
  556. */
  557. registerNamespace : function(ns){
  558. var nsArray = fullNS.split('.');
  559. var sEval = "";
  560. var sNS = "";
  561. for (var i = 0; i < nsArray.length; i++) {
  562. if (i != 0)
  563. sNS += ".";
  564. sNS += nsArray[i];
  565. sEval += "if (typeof(" + sNS + ") == 'undefined') " + sNS
  566. + " = new Object();"
  567. }
  568. if (sEval != "")
  569. return eval(sEval);
  570. },
  571. /**
  572. * 描述:shr 的js 类继承
  573. * @param {subClass} 当前类
  574. * @param {superClass} 需要继承的超类
  575. */
  576. inherit : function(subClass, superClass) {
  577. if(superClass==null) return ;
  578. var Fun = function(){};//用一个空的函数作为中间缓冲,如果直接用父类的实例作为原型,可能有潜在问题,如计算量超大等
  579. Fun.prototype = superClass.prototype;
  580. subClass.prototype = new Fun();
  581. subClass.prototype.constructor = subClass;
  582. //提供 superClass 属性,这个属性可以弱化父类子类之间的耦合
  583. //否则,在子类中调用父类的构造函数就需要指明父类,此时只需调用这个属性即可
  584. subClass.superClass = superClass.prototype;
  585. if(superClass.prototype.constructor == Object.prototype.constructor){
  586. superClass.prototype.constructor = superClass;
  587. }
  588. },
  589. /**
  590. * 描述:shr 的js 类定义
  591. * @param subClassName 当前类
  592. * @param superClass 超类
  593. * @param prototype 当前类体
  594. * @return 返回创建好的JS类
  595. */
  596. defineClass:function(subClassName,superClass,prototype){
  597. var clzPath=subClassName.substr(0,subClassName.lastIndexOf('.'));
  598. var ns=Namespace.register(clzPath);
  599. var subClass=eval(subClassName + "=function(){};");
  600. shr.inherit(subClass,superClass);
  601. for(var p in prototype){
  602. eval(subClassName + ".prototype." + p.toString() + "=prototype." + p.toString());
  603. }
  604. },
  605. /**
  606. * 描述: 创建对象
  607. * @param {clazz} 创建该类的对象
  608. */
  609. createObject:function(clazz){
  610. var obj=new clazz();
  611. if(clazz.superClass!=null){
  612. obj.superClass=clazz.superClass;
  613. }
  614. //对JS类中的方法 作AOP处理
  615. shr.aspectClassFun(clazz,obj);
  616. return obj;
  617. },
  618. /**
  619. * 描述:对JS类中的方法作AOP处理
  620. * @param {} url
  621. * @return {}
  622. */
  623. aspectClassFun:function(clazz,object){
  624. var clazz_temp=clazz;
  625. while(clazz_temp!=null && clazz_temp!=undefined) {
  626. for(var p in clazz_temp.prototype){
  627. var methodName=p.toString();
  628. var beforeMethodFun=p.toString() + "_before";
  629. var afterMethodFun=p.toString() + "_after";
  630. var aroundMethodFun=p.toString() + "_replace";
  631. if(eval("object." + beforeMethodFun)!=null) {
  632. shr.aspectBefore(object,p.toString(),eval("object." + beforeMethodFun));
  633. }
  634. if(eval("object." + afterMethodFun)!=null){
  635. shr.aspectAfter(object,p.toString(),eval("object." + afterMethodFun));
  636. }
  637. if(eval("object." + aroundMethodFun)!=null){
  638. shr.aspectAround(object,p.toString(),eval("object." + aroundMethodFun));
  639. }
  640. }
  641. clazz_temp=clazz_temp.superClass;
  642. }
  643. },
  644. /**
  645. * 描述:JS类方法调用代理
  646. * @param method 方法名称
  647. * @param clazz JS类名称
  648. * @param obj 调用对象
  649. */
  650. proxyCall:function(methodName,objectName){
  651. var fun=null;
  652. if(objectName==null){
  653. objectName="jsBinder";
  654. }
  655. if( typeof(methodName)=="object") {
  656. fun=methodName;
  657. }
  658. else {
  659. if(typeof(objectName)=="object"){
  660. fun=eval(objectName[methodName]);
  661. }
  662. else {
  663. fun=eval(objectName + "." + methodName);
  664. }
  665. }
  666. if (!fun) {
  667. return;
  668. }
  669. var paramArray=[];
  670. if(arguments.length>2) {
  671. paramArray=new Array();
  672. for(var nIndex=2;nIndex<arguments.length;nIndex++) {
  673. paramArray.push(arguments[nIndex]);
  674. }
  675. }
  676. fun.apply(objectName,paramArray);
  677. },
  678. getCurrentViewPage: function(source) {
  679. var viewPageManager = window.viewPageManager;
  680. if (typeof(viewPageManager) == 'undefined') {
  681. return null;
  682. }
  683. if (typeof source == 'undefined' || source == '') {
  684. return viewPageManager['emptyObject'];
  685. }
  686. var ui = viewPageManager[source];
  687. if (ui) {
  688. return ui;
  689. }
  690. var $viewPage = $(source).closest('.view_mainPage');
  691. if ($viewPage) {
  692. var id = $viewPage.attr('id');
  693. if ($.isEmptyObject(id)) {
  694. id = 'emptyObject';
  695. }
  696. return viewPageManager[id];
  697. } else {
  698. return null;
  699. }
  700. },
  701. registerViewPage: function(key, viewPage) {
  702. if ($.isEmptyObject(key)) {
  703. key = 'emptyObject';
  704. }
  705. var viewPageManager = window.viewPageManager;
  706. if (typeof(viewPageManager) == 'undefined') {
  707. viewPageManager = {};
  708. window.viewPageManager = viewPageManager;
  709. }
  710. viewPageManager[key] = viewPage;
  711. },
  712. unRegisterViewPage: function(key) {
  713. if ($.isEmptyObject(key)) {
  714. key = 'emptyObject';
  715. }
  716. var viewPageManager = window.viewPageManager;
  717. if (viewPageManager) {
  718. delete viewPageManager[key];
  719. }
  720. },
  721. // 新增打开新窗口的方法,url需要调用者提供
  722. openNew: function (url, someWindow) {
  723. if (!someWindow) {
  724. someWindow = _top;
  725. }
  726. void(someWindow.open(url));
  727. },
  728. //检测数组中是否包含某个字符串
  729. arrayIndexOf: function(arr,key){
  730. if(!Array.isArray(arr)){
  731. return -1;
  732. }
  733. var bol = -1;
  734. arr.forEach(function(item,index){
  735. if(item === key){
  736. bol = index;
  737. }
  738. });
  739. return bol;
  740. },
  741. redirect: function(url, params) {
  742. var newUrl = url;
  743. if (params && typeof(params) == "object") {
  744. if (newUrl.indexOf('?') == -1) {
  745. newUrl = newUrl + '?';
  746. }
  747. if (newUrl.charAt(newUrl.length - 1) != '?') {
  748. newUrl = newUrl + '&';
  749. }
  750. newUrl = newUrl + $.param(params);
  751. }
  752. shr.hideErrorMsg();
  753. document.location.replace(newUrl);
  754. },
  755. urlLocate: function(url, params) {
  756. var newUrl = url;
  757. if (params && typeof(params) == "object") {
  758. if (newUrl.indexOf('?') == -1) {
  759. newUrl = newUrl + '?';
  760. }
  761. if (newUrl.charAt(newUrl.length - 1) != '?') {
  762. newUrl = newUrl + '&';
  763. }
  764. newUrl = newUrl + $.param(params);
  765. }
  766. shr.hideErrorMsg();
  767. document.location.href = newUrl;
  768. },
  769. assembleModel: function(fields, context, uuid) {
  770. var model = new Object();
  771. if (fields) {
  772. var fieldName, value;
  773. for (var i = 0, length = fields.length; i < length; i++) {
  774. fieldName = fields[i];
  775. if(!this.isNoEditPermField(fieldName)){ //无编辑权限字段不参与提交
  776. value = this.getFieldValue(fieldName, uuid);
  777. this.setModelFieldValue(model, fieldName, value);
  778. }
  779. }
  780. }
  781. var uiObject = shr.getCurrentViewPage(uuid);
  782. if (uiObject) {
  783. // add id field
  784. model.id = uiObject.billId;
  785. // add entity name
  786. model._entityName = uiObject.view_model;
  787. }
  788. return model;
  789. },
  790. assembleTemplateModel: function(fields, context, uuid) {
  791. var model = new Object();
  792. if (fields) {
  793. var fieldName, value;
  794. for (var i = 0, length = fields.length; i < length; i++) {
  795. fieldName = fields[i];
  796. value = this.getTemplateFieldValue(fieldName, uuid);
  797. this.setTamplateModelFieldValue(model, fieldName, value);
  798. }
  799. }
  800. return model;
  801. },
  802. getTemplateFieldValue: function(fieldName, uuid, context) {
  803. var id = this.getRealId(fieldName, uuid);
  804. var $element = $('#' + id, context);
  805. var value;
  806. var ctrlrole = $element.attr('ctrlrole');
  807. var isToTemplate = $element.attr('istotemplate');
  808. if(isToTemplate == 'false') return;
  809. if(ctrlrole) {
  810. ctrlrole = ctrlrole.toLowerCase();
  811. }
  812. if (ctrlrole == 'checkbox') {
  813. value = $element.shrCheckbox('getValue');
  814. }else if(ctrlrole == 'text') {
  815. value = $element.shrTextField('getValue');
  816. }else if(ctrlrole == 'promptbox') {
  817. value = $element.shrPromptBox('getValue');
  818. }else if(ctrlrole == 'datepicker') {
  819. value = $element.shrDatePicker('getValue');
  820. }else if(ctrlrole == 'datetimepicker') {
  821. value = $element.shrDateTimePicker('getValue');
  822. }else if(ctrlrole == 'textarea') {
  823. value = $element.shrTextarea('getValue');
  824. }else if(ctrlrole == 'radio') {
  825. value = $element.shrRadio('getValue');
  826. }else if(ctrlrole == 'select') {
  827. value = $element.shrSelect('getValue');
  828. }
  829. return value;
  830. },
  831. /*
  832. * url 目标url
  833. * arg 需要替换的参数名称
  834. * arg_val 替换后的参数的值
  835. * return url 参数替换后的url
  836. */
  837. changeURLArg: function (url, arg, arg_val) {
  838. var pattern = arg + '=([^&]*)';
  839. var replaceText = arg + '=' + arg_val;
  840. if (url.match(pattern)) {
  841. var tmp = '/(' + arg + '=)([^&]*)/gi';
  842. tmp = url.replace(eval(tmp), replaceText);
  843. return tmp;
  844. } else {
  845. if (url.match('[\?]')) {
  846. return url + '&' + replaceText;
  847. } else {
  848. return url + '?' + replaceText;
  849. }
  850. }
  851. return url + '\n' + arg + '\n' + arg_val;
  852. },
  853. convertId: function(id) {
  854. return id.replace(/\./g, '_');
  855. },
  856. strToEscape: function(str) {
  857. return str.replace(/&/g, '&amp;');
  858. },
  859. htmlEncode: function(value) {
  860. return $('<div/>').text(value).html();
  861. },
  862. htmlDecode: function(value) {
  863. return $('<div/>').html(value).text();
  864. },
  865. /**
  866. * 转义符换成普通字符
  867. */
  868. strEscape: function (str) {
  869. var arrEntities = { 'lt': '<', 'gt': '>', 'nbsp': ' ', 'amp': '&', 'quot': '"' };
  870. var result = '';
  871. if (str) {
  872. result = str.replace(/&(lt|gt|nbsp|amp|quot);/ig, function (all, t) {
  873. return arrEntities[t];
  874. });
  875. }
  876. return result;
  877. },
  878. getRealId: function(id, uuid) {
  879. id = this.convertId(id);
  880. if (uuid) {
  881. id = id + uuid;
  882. }
  883. return id;
  884. },
  885. getValueByRole: function (role, $element, id, context, isFromWF) {
  886. var value;
  887. var handler = {
  888. 'checkbox': function(){
  889. var value;
  890. if (typeof $element.attr("checked") == 'undefined') {
  891. value = 0;
  892. } else {
  893. var _v_ = $element.shrCheckbox('getValue');
  894. if(_v_){
  895. value= 1;
  896. }else{
  897. value = 0;
  898. }
  899. }
  900. return value;
  901. },
  902. 'editGrid': function () {
  903. var collection = $element.jqGrid('getAllPageData');
  904. return collection;
  905. },
  906. 'shrMultiLangBox': function () {
  907. return $element.shrMultiLangBox('getTransformedValue');
  908. },
  909. 'datetimepicker': function(){
  910. return $element.shrDateTimePicker('getValue');
  911. },
  912. 'numberField': function () {
  913. return $element.shrNumberField('getValue');
  914. },
  915. 'shrFieldDisplay': function() {
  916. return $element.shrFieldDisplay('getOriginalValue') || $element.shrFieldDisplay('getValue');
  917. }
  918. }
  919. //兼容ie下select控件'01'value值会被浏览器改变为'1'
  920. if(shr.getBowserInfo().browser == 'IE'){
  921. handler.select = function() {
  922. return $element.shrSelect('getValue').value;
  923. }
  924. }
  925. //查看状态下的分录role为grid
  926. if(role === 'grid' && _self.getOperateState() === 'VIEW'){
  927. role = 'editGrid';
  928. }
  929. if (handler.hasOwnProperty(role)) {
  930. value = handler[role]();
  931. } else {
  932. value = shr.createObject(shr.framework.Widget).getInputValue(id, context, isFromWF);
  933. }
  934. return value;
  935. },
  936. getFieldValue: function (fieldName, uuid, context) {
  937. var id = this.getRealId(fieldName, uuid);
  938. var $element = $('#' + id, context);
  939. var role = $element.attr('ctrlrole');
  940. var value = this.getValueByRole(role, $element, id, context,false);
  941. return value;
  942. },
  943. /**
  944. * 根据字段id和方法名来执行方法
  945. * 使用该方法的前提是具有ctrlrole属性,并且组件中有传入的方法名对应的方法
  946. * fieldId:是字段的id
  947. * methodName:方法名
  948. * arguments:执行的方法要传递的参数
  949. * context:上下文,可选参数,如果某些iframe中获取不到元素,则需要传上下文
  950. */
  951. execByFieldIdAndMethod: function (fieldId, methodName, _arguments, context) {
  952. var id = this.getRealId(fieldId);
  953. var $element = $('#' + id, context);
  954. try {
  955. if ($element.length == 0) {
  956. throw 'can not find the suitable element';
  957. }
  958. var ctrlrole = $element.attr('ctrlrole');
  959. if (!ctrlrole) {
  960. throw 'this elment has no ctrlrole attribute'
  961. }
  962. var componentName = this.getComponentNameByCtrlrole(ctrlrole);
  963. if (_arguments) {
  964. return $element[componentName](methodName, _arguments);
  965. }
  966. return $element[componentName](methodName);
  967. } catch (e) {
  968. console.error(e);
  969. }
  970. },
  971. /**
  972. * 根据字段id和方法名来执行方法
  973. * 使用该方法的前提是具有ctrlrole属性,并且组件中有传入的方法名对应的方法
  974. * $element:是jquery对象
  975. * methodName:方法名
  976. * arguments:执行的方法要传递的参数
  977. */
  978. execByElementAndMethod: function ($element, methodName, _arguments) {
  979. try {
  980. if ($element.length == 0) {
  981. throw 'can not find the suitable element';
  982. }
  983. var ctrlrole = $element.attr('ctrlrole');
  984. if (!ctrlrole) {
  985. throw 'this elment has no ctrlrole attribute'
  986. }
  987. var componentName = this.getComponentNameByCtrlrole(ctrlrole);
  988. if (_arguments) {
  989. return $element[componentName](methodName, _arguments);
  990. }
  991. return $element[componentName](methodName);
  992. } catch (e) {
  993. console.error(e);
  994. }
  995. },
  996. /**
  997. * 根据ctrlrole获取对应的组件名称
  998. */
  999. getComponentNameByCtrlrole: function (ctrlrole) {
  1000. var componentName;
  1001. var mapping = {
  1002. 'checkbox': 'shrCheckbox',
  1003. 'radio':'shrRadio',
  1004. 'select':'shrSelect',
  1005. 'text':'shrTextField',
  1006. 'shrSetIndexCode':'shrSetIndexCode',
  1007. 'shrDetailTips':'shrDetailTips',
  1008. 'shrFastFilter':'shrFastFilter',
  1009. 'shrGridConfig':'shrGridConfig',
  1010. 'shrIconUpload':'shrIconUpload',
  1011. 'intlCell':'shrIntlCell',
  1012. 'shrMessageTips':'shrMessageTips',
  1013. 'multiSelect':'shrMultiSelect',
  1014. 'shrSaveFilterSchemeDialog':'shrSaveFilterSchemeDialog',
  1015. 'shrSpreadChooseAll':'shrSpreadChooseAll',
  1016. 'shrTableDialog':'shrTableDialog',
  1017. 'textarea':'shrTextarea',
  1018. 'shrMultiLangBox': 'shrMultiLangBox',
  1019. 'datetimepicker': 'shrDateTimePicker',
  1020. 'dateSpanPicker':'shrDateSpanPicker',
  1021. 'numberField': 'shrNumberField',
  1022. 'shrFieldDisplay': 'shrFieldDisplay',
  1023. 'promptBox':'shrPromptBox',
  1024. }
  1025. if (mapping.hasOwnProperty(ctrlrole)) {
  1026. componentName = mapping[ctrlrole];
  1027. }else{
  1028. throw 'can not find the suitable component';
  1029. }
  1030. return componentName;
  1031. },
  1032. setModelFieldValue: function(model, fieldName, value) {
  1033. if (fieldName.indexOf('.') != -1) {
  1034. var fields = fieldName.split('.');
  1035. var subModel;
  1036. for (var i = 0, length = fields.length - 1; i < length; i++) {
  1037. fieldName = fields[i];
  1038. subModel = model[fieldName];
  1039. if (typeof subModel == 'undefined') {
  1040. subModel = {};
  1041. model[fieldName] = subModel;
  1042. }
  1043. model = subModel;
  1044. }
  1045. fieldName = fields[fields.length - 1];
  1046. }
  1047. model[fieldName] = value;
  1048. },
  1049. setTamplateModelFieldValue: function(model, fieldName, value) {
  1050. if (fieldName.indexOf('.') != -1) {
  1051. var fields = fieldName.split('.');
  1052. fieldName = fields.join('_');
  1053. }
  1054. model[fieldName] = value;
  1055. },
  1056. /**
  1057. * 增加表单数据进行加密传输
  1058. * 表单数据有些格式数据会被防火墙或者网络安全策略拦截,导致保存失败
  1059. * @param data
  1060. */
  1061. encryptFormModelData:function(data){
  1062. var option={model:data.model};
  1063. var encryptObj = shr.encryptForObj(option, null);
  1064. data.model = encryptObj.obj['model'];
  1065. data.encryptKeys='encryptKeys:' + $.allEncrypt('model');
  1066. },
  1067. addEncryptParams:function(postData,key,value){
  1068. var option ={};
  1069. option[key]=value;
  1070. var encryptObj = $.encryptForObj(option, null);
  1071. $.extend(postData, encryptObj.obj);
  1072. if (!postData.encryptKeys){
  1073. postData.encryptKeys = encryptObj.keyStr;
  1074. } else if(shr.arrayIndexOf(postData.encryptKeys.split(','),encryptObj.keyStr) == -1 && key != 'encryptKeys') {
  1075. postData.encryptKeys = postData.encryptKeys+','+ encryptObj.keyStr;
  1076. }
  1077. },
  1078. /**
  1079. * 增加接口数据进行加密传输
  1080. * @param postData
  1081. */
  1082. addEncryptPostData: function(postData,isAllEncrypt){
  1083. if(postData){
  1084. var encryptKeysStr = postData.encryptKeys;
  1085. var needEncryptKey = shr.needEncryptKey();
  1086. if(encryptKeysStr && encryptKeysStr.indexOf('encryptKeys:') != -1){
  1087. encryptKeysStr = $.allDecrypt(encryptKeysStr.substring(12,encryptKeysStr.length));
  1088. }else if(encryptKeysStr && encryptKeysStr.indexOf('encryptKeys:') < 0){
  1089. var optEncryptKeysArray = encryptKeysStr.split(',');
  1090. optEncryptKeysArray.forEach(function(item){
  1091. if(shr.arrayIndexOf(needEncryptKey,item) < 0){
  1092. needEncryptKey.push(item);
  1093. }
  1094. });
  1095. }
  1096. if(postData.encryptKeys && encryptKeysStr){
  1097. var encryptKeys = encryptKeysStr;
  1098. for(var key in postData){
  1099. if(shr.arrayIndexOf(encryptKeys.split(','),key) != -1 && key != 'encryptKeys'){
  1100. try {
  1101. if($.allDecrypt(postData[key])){
  1102. postData[key] = $.allDecrypt(postData[key]);
  1103. }
  1104. } catch (error) {}
  1105. }
  1106. }
  1107. postData.encryptKeys = '';
  1108. }else if(!postData.encryptKeys){
  1109. postData.encryptKeys = '';
  1110. }
  1111. }
  1112. for(var key in postData){
  1113. if(postData[key] && !Array.isArray(postData[key])){
  1114. if(!isAllEncrypt && shr.arrayIndexOf(needEncryptKey,key) >= 0){
  1115. shr.addEncryptParams(postData, key, postData[key]);
  1116. }else if(isAllEncrypt && shr.arrayIndexOf(['method','serviceName','uipk','encryptKeys'],key) < 0){
  1117. shr.addEncryptParams(postData, key, postData[key]);
  1118. }
  1119. }
  1120. }
  1121. if(postData.encryptKeys){
  1122. postData.encryptKeys = 'encryptKeys:' + $.allEncrypt(postData.encryptKeys);
  1123. }
  1124. },
  1125. needEncryptKey: function(){
  1126. return ['filterItems','filter',
  1127. 'fastFilterItems','sorterItems','advancedFilter','custom_params',
  1128. 'tree_params','columnModel','queryMode','exportPrivteProtected',
  1129. 'keyField','dataPerm','fieldName_key','searchFilterItems','categoryFilter',
  1130. 'contractFilter','dynamicSql','model','order'];
  1131. },
  1132. //将url参数转换成对象类型,并且参数值做了 decodeURIComponent,所以 仅供与dealPostParam去使用,别的地方不可以使用
  1133. urlParamsToObject: function(url) {
  1134. var queryString = url.split('?').length > 1?url.split('?')[1]:'';
  1135. var paramsArr = queryString.split('&');
  1136. var paramObj = {};
  1137. for ( var i = 0; i < paramsArr.length; i++) {
  1138. var pos = paramsArr[i].indexOf('=');// 查找name=value
  1139. if (pos == -1) continue;// 如果没有找到就跳过
  1140. var argname = paramsArr[i].substring(0, pos);// 提取name
  1141. var value = paramsArr[i].substring(pos + 1);// 提取value
  1142. try {
  1143. paramObj[argname] = decodeURIComponent(value);
  1144. } catch (error) {
  1145. paramObj[argname] = value;
  1146. }
  1147. }
  1148. return paramObj;
  1149. },
  1150. dealPostParam: function(option){
  1151. var isHasKey = false;
  1152. var isUrlHasKey = false;
  1153. if(option.data){
  1154. if(option.data.noEncrypt) return;
  1155. var encryptKey = shr.needEncryptKey();
  1156. var optEncryptKeys = option.data.encryptKeys;
  1157. if(optEncryptKeys && optEncryptKeys.indexOf('encryptKeys:') < 0){
  1158. var optEncryptKeysArray = optEncryptKeys.split(',');
  1159. optEncryptKeysArray.forEach(function(item){
  1160. if(shr.arrayIndexOf(shr.needEncryptKey(),item) < 0){
  1161. encryptKey.push(item);
  1162. }
  1163. });
  1164. }
  1165. for(var item in option.data){
  1166. if(shr.arrayIndexOf(encryptKey,item) >= 0){
  1167. isHasKey = true;
  1168. }
  1169. }
  1170. if(option.url.indexOf('/shr/dynamic.do') >= 0){
  1171. encryptKey.forEach(function(item){
  1172. if(option.url.indexOf(item) >= 0){
  1173. isUrlHasKey = true;
  1174. }
  1175. });
  1176. }
  1177. }
  1178. if(option.url.indexOf('getListData') >= 0 || isUrlHasKey){
  1179. var paramObj = shr.urlParamsToObject(option.url);
  1180. option.url = option.url.split('?')[0];
  1181. $.extend(option.data,paramObj);
  1182. shr.addEncryptPostData(option.data);
  1183. option.type = 'POST';
  1184. }else if(option.data && option.data.method == 'callService'){
  1185. shr.addEncryptPostData(option.data,true);
  1186. }else if(option.data && option.data.method == 'exportToExcel'
  1187. || option.data && option.data.method == 'newTask'){
  1188. shr.addEncryptPostData(option.data);
  1189. }else if(option.data && option.data.method == 'getCompareResults'){
  1190. option.data.a = $.allEncrypt(option.data.a);
  1191. option.data.b = $.allEncrypt(option.data.b);
  1192. option.data.encryptKeys='encryptKeys:' + $.allEncrypt('a,b');
  1193. }else if(isHasKey){
  1194. shr.addEncryptPostData(option.data);
  1195. }
  1196. },
  1197. doAction: function(option) {
  1198. //shr.dealPostParam会修改options,防止影响外部参数引用
  1199. var option = $.extend(true,{},option);
  1200. // disible button
  1201. if (option.target) {
  1202. var $target = $(option.target);
  1203. if ($target.is('button')) {
  1204. $target.addClass('shrbtn-disabled');
  1205. $target.attr('disabled', 'disabled');
  1206. }
  1207. }
  1208. //拼接请求URL
  1209. if(option.url == null){
  1210. if(option.param != null) {
  1211. option.url = "?method=" + option.action + "&" + option.param;
  1212. }
  1213. else {
  1214. option.url="?method=" + option.action;
  1215. }
  1216. }
  1217. //默认传输格式为json
  1218. if(option.dataType==null){
  1219. option.dataType = "json";
  1220. }
  1221. //默认请求超时时间为ajaxTimeout
  1222. if(option.timeout==null) {
  1223. option.timeout=this.ajaxTimeout;
  1224. }
  1225. //默认表单名称为form
  1226. /*if(option.form==null){
  1227. option.form="form";
  1228. }*/
  1229. //默认提交方式为异步方式
  1230. if(option.async==null){
  1231. option.async=true;
  1232. }
  1233. //默认阻塞界面
  1234. if(option.showBlock == null){
  1235. option.showBlock = true;
  1236. }
  1237. // add check data
  1238. this._addCommonExtParam( option );
  1239. this.dealPostParam( option );
  1240. //var timer=null;
  1241. var requestOption = {
  1242. url: option.url,
  1243. data: option.data,
  1244. /* 默认ajax数据交互格式为json */
  1245. dataType: option.dataType,
  1246. type: option.type,
  1247. async: option.async,
  1248. timeout: option.timeout,
  1249. success: function(obj, textStatus) {
  1250. if (option.showBlock == true) {
  1251. clearTimeout(timer);
  1252. $.block.hide();
  1253. }
  1254. if(obj == null){
  1255. option.success(null);
  1256. return ;
  1257. }
  1258. if (option.dataType == 'json') {
  1259. //自行处理返回
  1260. if(option.ignoreHandlerMessage && option.ignoreHandlerMessage == true){
  1261. option.success(obj, textStatus);
  1262. return;
  1263. }
  1264. if(obj.result == "success") {
  1265. var message = obj.successMessage;
  1266. if (!message) {
  1267. message = $.shrI18n.common.tips.operateSuccess;
  1268. }
  1269. shr.showSuccess({
  1270. message: message,
  1271. hideAfter: 3
  1272. });
  1273. //如果是portal跳转过来,top为0,否则为60px
  1274. if (isFromPortal()) {
  1275. $("ul[class='messenger messenger-fixed messenger-theme-air messenger-on-top messenger-theme-future']").css('top', 0);
  1276. } else {
  1277. $("ul[class='messenger messenger-fixed messenger-theme-air messenger-on-top messenger-theme-future']").css('top', '60px');
  1278. }
  1279. //调用回调函数
  1280. if(option.success) {
  1281. option.success(obj.data, obj.uiItems, obj.script);
  1282. }
  1283. } else if(obj.result == "error") {
  1284. var message = obj.summary;
  1285. // if (!$.isEmptyObject(obj.detailInfo)) {
  1286. // message = message + '<br>' + obj.detailInfo;
  1287. // }
  1288. if (!message) {
  1289. message = $.shrI18n.common.tips.operateFail;
  1290. }
  1291. shr.showError({message: message});
  1292. //调用回调函数
  1293. if(option.error) {
  1294. option.error(obj.data, obj.uiItems, obj.script);
  1295. }
  1296. }
  1297. } else {
  1298. if(option.success != null) {
  1299. shr.showInfo({
  1300. message: $.shrI18n.common.tips.operateSuccess,
  1301. hideAfter: 3
  1302. });
  1303. shr.stopAllMask();
  1304. //调用回调函数
  1305. if(option.success) {
  1306. option.success(obj);
  1307. }
  1308. }
  1309. }
  1310. },
  1311. error:function(response, textStatus, errorThrown) {
  1312. return shr.handleError(option, response, textStatus, errorThrown);
  1313. },
  1314. complete:function(jqXHR, textStatus){
  1315. if(option.complete && waf.isFunction(option.complete)){
  1316. option.complete.call(this, jqXHR, textStatus);
  1317. }
  1318. /*if (option.showBlock == true) {
  1319. clearTimeout(timer);
  1320. $.block.hide();
  1321. }*/
  1322. if (option.target) {
  1323. var $target = $(option.target);
  1324. if ($target.is('button')) {
  1325. $target.removeClass('shrbtn-disabled');
  1326. $target.removeAttr('disabled');
  1327. }
  1328. }
  1329. }
  1330. };
  1331. var messageOptions = {
  1332. //successMessage : '操作成功!',
  1333. errorMessage : $.shrI18n.common.tips.operateFail,
  1334. progressMessage : $.shrI18n.common.tips.operating,
  1335. showCloseButton: true,
  1336. singleton: true,
  1337. hideAfter: null
  1338. };
  1339. shr.msgHideAll();
  1340. //锁定BODY
  1341. if (option.showBlock == true) {
  1342. /*$.block.show({
  1343. text: '正在执行,请稍候...'
  1344. });*/
  1345. timer = setTimeout(function() {
  1346. $.block.show({
  1347. text: $.shrI18n.common.loadingText.runningPlsWait
  1348. });
  1349. }, shr.blockMinTime);
  1350. }
  1351. _top.Messenger().run(messageOptions, requestOption);
  1352. /*//锁定BODY
  1353. if(option.showBlock==true){
  1354. timer=setTimeout(function(){
  1355. waf.block.show({text:waf.localeResourceObj.AJAX_ASYNC_BLOCK_INFO});
  1356. },
  1357. 500);
  1358. }*/
  1359. /*报出提交事件 */
  1360. /*$('#' + option.form).trigger("onSubmit");
  1361. 提交
  1362. $('#' + option.form).ajaxSubmit(requestOption);*/
  1363. },
  1364. //检测数组中是否包含某个字符串
  1365. arrayIndexOf: function(arr,key){
  1366. if(!Array.isArray(arr)){
  1367. return -1;
  1368. }
  1369. var bol = -1;
  1370. arr.forEach(function(item,index){
  1371. if(item === key){
  1372. bol = index;
  1373. }
  1374. });
  1375. return bol;
  1376. },
  1377. /**
  1378. * 判断是否是一个json
  1379. */
  1380. isJSON: function(str) {
  1381. if (typeof str == 'string') {
  1382. try {
  1383. var obj = JSON.parse(str);
  1384. if(typeof obj == 'object' && obj ){
  1385. return true;
  1386. }else{
  1387. return false;
  1388. }
  1389. } catch(e) {
  1390. return false;
  1391. }
  1392. }
  1393. },
  1394. doWithBatchAction: function(option) {
  1395. //shr.dealPostParam会修改options,防止影响外部参数引用
  1396. var option = $.extend(true,{},option);
  1397. // disible button
  1398. if (option.target) {
  1399. var $target = $(option.target);
  1400. if ($target.is('button')) {
  1401. $target.addClass('shrbtn-disabled');
  1402. $target.attr('disabled', 'disabled');
  1403. }
  1404. }
  1405. //拼接请求URL
  1406. if(option.url == null){
  1407. if(option.param != null) {
  1408. option.url = "?method=" + option.action + "&" + option.param;
  1409. }
  1410. else {
  1411. option.url="?method=" + option.action;
  1412. }
  1413. }
  1414. //默认传输格式为json
  1415. if(option.dataType==null){
  1416. option.dataType = "json";
  1417. }
  1418. //默认请求超时时间为ajaxTimeout
  1419. if(option.timeout==null) {
  1420. option.timeout=this.ajaxTimeout;
  1421. }
  1422. //默认表单名称为form
  1423. /*if(option.form==null){
  1424. option.form="form";
  1425. }*/
  1426. //默认提交方式为异步方式
  1427. if(option.async==null){
  1428. option.async=true;
  1429. }
  1430. //默认阻塞界面
  1431. if(option.showBlock == null){
  1432. option.showBlock = true;
  1433. }
  1434. // add check data
  1435. this._addCommonExtParam( option );
  1436. shr.dealPostParam( option );
  1437. //var timer=null;
  1438. var requestOption = {
  1439. url: option.url,
  1440. data: option.data,
  1441. /* 默认ajax数据交互格式为json */
  1442. dataType: option.dataType,
  1443. type: option.type,
  1444. async: option.async,
  1445. timeout: option.timeout,
  1446. success: function(obj, textStatus) {
  1447. if (option.showBlock == true) {
  1448. clearTimeout(timer);
  1449. $.block.hide();
  1450. }
  1451. if(obj == null){
  1452. option.success(null);
  1453. return ;
  1454. }
  1455. if (option.dataType == 'json') {
  1456. if(obj.result == "success") {
  1457. // var message = obj.successMessage;
  1458. // if (!message) {
  1459. // message = '操作成功!';
  1460. // }
  1461. // shr.showInfo({
  1462. // message: message,
  1463. // hideAfter: 3
  1464. // });
  1465. //调用回调函数
  1466. if(option.success) {
  1467. option.success(obj.data, obj.uiItems, obj.script);
  1468. }
  1469. } else if(obj.result == "error") {
  1470. var message = obj.summary;
  1471. // if (!$.isEmptyObject(obj.detailInfo)) {
  1472. // message = message + '<br>' + obj.detailInfo;
  1473. // }
  1474. if (!message) {
  1475. message = $.shrI18n.common.tips.operateFail;
  1476. }
  1477. shr.showError({message: message});
  1478. //调用回调函数
  1479. if(option.error) {
  1480. option.error(obj.data, obj.uiItems, obj.script);
  1481. }
  1482. }
  1483. } else {
  1484. if(option.success != null) {
  1485. // shr.showInfo({
  1486. // message: "操作成功!",
  1487. // hideAfter: 3
  1488. // });
  1489. //调用回调函数
  1490. if(option.success) {
  1491. option.success(obj);
  1492. }
  1493. }
  1494. }
  1495. },
  1496. error:function(response, textStatus, errorThrown) {
  1497. return shr.handleError(option, response, textStatus, errorThrown);
  1498. },
  1499. complete:function(jqXHR, textStatus){
  1500. if(option.complete && waf.isFunction(option.complete)){
  1501. option.complete.call(this, jqXHR, textStatus);
  1502. }
  1503. /*if (option.showBlock == true) {
  1504. clearTimeout(timer);
  1505. $.block.hide();
  1506. }*/
  1507. if (option.target) {
  1508. var $target = $(option.target);
  1509. if ($target.is('button')) {
  1510. $target.removeClass('shrbtn-disabled');
  1511. $target.removeAttr('disabled');
  1512. }
  1513. }
  1514. }
  1515. };
  1516. var messageOptions = {
  1517. //successMessage : '操作成功!',
  1518. errorMessage : $.shrI18n.common.tips.operateFail,
  1519. progressMessage : $.shrI18n.common.tips.operating,
  1520. showCloseButton: true,
  1521. singleton: true,
  1522. hideAfter: null
  1523. };
  1524. shr.msgHideAll();
  1525. //锁定BODY
  1526. if (option.showBlock == true) {
  1527. /*$.block.show({
  1528. text: '正在执行,请稍候...'
  1529. });*/
  1530. timer = setTimeout(function() {
  1531. $.block.show({
  1532. text: $.shrI18n.common.loadingText.runningPlsWait
  1533. });
  1534. }, shr.blockMinTime);
  1535. }
  1536. var messageFun;
  1537. if($.isFunction(_top.Messenger)){
  1538. messageFun = _top.Messenger();
  1539. }else{
  1540. messageFun = Messenger();
  1541. }
  1542. messageFun.run(messageOptions, requestOption);
  1543. /*//锁定BODY
  1544. if(option.showBlock==true){
  1545. timer=setTimeout(function(){
  1546. waf.block.show({text:waf.localeResourceObj.AJAX_ASYNC_BLOCK_INFO});
  1547. },
  1548. 500);
  1549. }*/
  1550. /*报出提交事件 */
  1551. /*$('#' + option.form).trigger("onSubmit");
  1552. 提交
  1553. $('#' + option.form).ajaxSubmit(requestOption);*/
  1554. },
  1555. /**
  1556. *此请求,要求success函数一定要进行回调重写
  1557. */
  1558. doAjaxNeedSuccess: function(option) {
  1559. option.successResultSelfHandler = true;
  1560. return $.doAjax(option);
  1561. },
  1562. doAjax: function(option) {
  1563. //拼接请求URL
  1564. if(option.url == null && option.action){
  1565. if(option.param != null) {
  1566. option.url = "?method=" + option.action + "&" + option.param;
  1567. } else {
  1568. option.url= "?method=" + option.action;
  1569. }
  1570. }
  1571. if (option.data && !(option.data.method) && option.action) {
  1572. option.data.method = option.action;
  1573. }
  1574. //默认传输格式为json
  1575. if(option.dataType==null){
  1576. option.dataType = "json";
  1577. }
  1578. //默认请求超时时间为ajaxTimeout
  1579. if(option.timeout==null) {
  1580. option.timeout=this.ajaxTimeout;
  1581. }
  1582. //默认表单名称为form
  1583. /*if(option.form==null){
  1584. option.form="form";
  1585. }*/
  1586. //默认提交方式为异步方式
  1587. if(option.async==null){
  1588. option.async=true;
  1589. }
  1590. //默认阻塞界面
  1591. /*if(option.showBlock==null){
  1592. option.showBlock = true;
  1593. }*/
  1594. // add check data
  1595. this._addCommonExtParam( option );
  1596. //var timer=null;
  1597. var requestOption = {
  1598. url: option.url,
  1599. data: option.data,
  1600. /* 默认ajax数据交互格式为json */
  1601. dataType: option.dataType,
  1602. type: option.type,
  1603. async: option.async,
  1604. timeout: option.timeout,
  1605. error: function(response, textStatus, errorThrown) {
  1606. if(option.error && $.isFunction(option.error)){
  1607. return option.error.call(this, response, textStatus, errorThrown);
  1608. } else {
  1609. return shr.handleError(option, response, textStatus, errorThrown);
  1610. }
  1611. },
  1612. complete: function(jqXHR, textStatus){
  1613. if(option.complete && $.isFunction(option.complete)){
  1614. option.complete.call(this, jqXHR, textStatus);
  1615. }
  1616. if (option.showBlock == true) {
  1617. clearTimeout(timer);
  1618. $.block.hide();
  1619. }
  1620. }
  1621. };
  1622. if (option.success) {
  1623. requestOption.success = function(obj, textStatus) {
  1624. //解锁BODY
  1625. if (option.showBlock == true) {
  1626. clearTimeout(timer);
  1627. $.block.hide();
  1628. }
  1629. if(obj == null){
  1630. option.success(null);
  1631. return ;
  1632. }
  1633. if(option.successResultSelfHandler === true){
  1634. option.success(obj, textStatus);
  1635. return;
  1636. }
  1637. if (option.dataType == 'json') {
  1638. if(obj.result == "success") {
  1639. if(option.success != null) {
  1640. //调用回调函数
  1641. option.success(obj.data, obj.uiItems, obj.script);
  1642. }
  1643. } else if(obj.result == "error") {
  1644. //$('body').html(obj);
  1645. //var message = obj.summary + '<br>' + obj.detailInfo;
  1646. var message = obj.summary;
  1647. shr.showError({message: message});
  1648. if(option.error != null) {
  1649. option.error(obj);
  1650. }
  1651. } else {
  1652. option.success(obj);
  1653. }
  1654. } else {
  1655. if(option.success != null) {
  1656. //调用回调函数
  1657. option.success(obj);
  1658. }
  1659. }
  1660. };
  1661. }
  1662. //锁定BODY
  1663. if (option.showBlock == true) {
  1664. timer = setTimeout(function() {
  1665. $.block.show({
  1666. text: $.shrI18n.common.loadingText.runningPlsWait
  1667. });
  1668. }, shr.blockMinTime);
  1669. }
  1670. if(option.contentType){
  1671. requestOption.contentType = option.contentType;
  1672. }
  1673. if(option.headers){
  1674. requestOption.headers = option.headers;
  1675. }
  1676. return $.ajax(requestOption);
  1677. },
  1678. /**
  1679. * 判断是否是session失效,重定向到登录页面
  1680. */
  1681. checkIsRedirectLogin: function(response) {
  1682. var content;
  1683. if (typeof response == 'string') {
  1684. content = response;
  1685. } else if (typeof response == 'object' && response.responseText) {
  1686. content = response.responseText;
  1687. }
  1688. if (content && content.indexOf('action="login?') != -1) {
  1689. shr.redirectLogin();
  1690. return true;
  1691. }
  1692. return false;
  1693. },
  1694. /**
  1695. * 重定向登录页面
  1696. */
  1697. redirectLogin: function() {
  1698. _top.location.href = _top.location.href
  1699. },
  1700. doGet: function(option) {
  1701. //拼接请求URL
  1702. if(option.url == null){
  1703. if(option.param != null) {
  1704. option.url = "?method=" + option.action + "&" + option.param;
  1705. }
  1706. else {
  1707. option.url="?method=" + option.action;
  1708. }
  1709. }
  1710. //默认传输格式为json
  1711. if(option.dataType==null){
  1712. option.dataType = "html";
  1713. }
  1714. //默认请求超时时间为ajaxTimeout
  1715. if(option.timeout==null) {
  1716. option.timeout=this.ajaxTimeout;
  1717. }
  1718. //默认提交方式为异步方式
  1719. if(option.async==null){
  1720. option.async = true;
  1721. }
  1722. //添加shruicode
  1723. this._addShruicode( option.data );
  1724. //var timer=null;
  1725. var url = option.url;
  1726. var requestOption = {
  1727. url: option.url,
  1728. data: option.data,
  1729. /* 默认ajax数据交互格式为json */
  1730. dataType: option.dataType,
  1731. type: option.type,
  1732. async: option.async,
  1733. timeout: option.timeout,
  1734. success: function(obj, textStatus) {
  1735. //obj返回可能为空
  1736. var $response;
  1737. try {
  1738. $response = $(obj);
  1739. }catch (e){
  1740. console.log('response data exception: null data response.');
  1741. }
  1742. if ($response && $response.filter('meta[content=error-page]').length > 0) {
  1743. var regexp1 = /<script .*?src=\"(.+)\"><\/script>/g;
  1744. var regexp2 = /<script>([\s\S]*)<\/script>/g;
  1745. var codes1 = [];
  1746. var result = obj.replace(regexp1,function(script,code){
  1747. codes1.push(code);
  1748. return '';
  1749. });
  1750. var codes2 = [];
  1751. result = obj.replace(regexp2,function(script,code){
  1752. codes2.push(code);
  1753. return '';
  1754. });
  1755. var container = _top.document.body;
  1756. container.innerHTML = result;
  1757. codes1.forEach(function(code){
  1758. var script = document.createElement('script');
  1759. script.type = 'text/javascript';
  1760. script.src = code;
  1761. container.appendChild(script);
  1762. });
  1763. codes2.forEach(function(code){
  1764. var script = document.createElement('script');
  1765. script.innerHTML = code;
  1766. container.appendChild(script);
  1767. });
  1768. return;
  1769. }
  1770. if(obj == null){
  1771. option.success(null);
  1772. return ;
  1773. }
  1774. if(option.success != null) {
  1775. //调用回调函数
  1776. option.success(obj);
  1777. }
  1778. },
  1779. error:function(response, textStatus, errorThrown) {
  1780. return shr.handleError(option, response, textStatus, errorThrown);
  1781. },
  1782. complete:function(jqXHR, textStatus){
  1783. // TODO 稍后补充
  1784. }
  1785. };
  1786. /*var messageOptions = {
  1787. errorMessage : '操作失败!',
  1788. //progressMessage : '操作中',
  1789. showCloseButton: true,
  1790. singleton: true,
  1791. hideAfter: null
  1792. };
  1793. //shr.msgHideAll();
  1794. _top.Messenger().run(messageOptions, requestOption);*/
  1795. $.ajax(requestOption);
  1796. },
  1797. handleError: function(option, response, textStatus, errorThrown) {
  1798. // 同一用户登录,踢出的时候,还有未完成的ajax请求,返回退出页面这里,特殊处理
  1799. if((response.responseText && response.responseText.indexOf("window.logoutHR()") !=-1 ) || (response.responseText && response.responseText.indexOf("#reloadtips") !=-1)){
  1800. window.location = '/shr/reloadtips.jsp';
  1801. return ;
  1802. }
  1803. if (shr.checkIsRedirectLogin(response)) {
  1804. return false;
  1805. }
  1806. if (option.showBlock == true) {
  1807. clearTimeout(timer);
  1808. $.block.hide();
  1809. }
  1810. var message;
  1811. if ((response != null ? response.status : void 0) === 404) {
  1812. message = $.shrI18n.common.loadingText.pageNotFound;
  1813. } else {
  1814. var nExMsgStartIdx = response.responseText && response.responseText.indexOf("<title>");
  1815. var nExMsgEndIdx = response.responseText && response.responseText.indexOf("</title>");
  1816. var strErrorSummary = response.responseText && response.responseText.substr(nExMsgStartIdx + 7, nExMsgEndIdx - nExMsgStartIdx - 7);
  1817. if (strErrorSummary != '') {
  1818. message = strErrorSummary;
  1819. } else {
  1820. nExMsgStartIdx = response.responseText && response.responseText.indexOf("{");
  1821. nExMsgEndIdx = response.responseText && response.responseText.indexOf("}");
  1822. strErrorSummary = response.responseText && response.responseText.substr(nExMsgStartIdx, nExMsgEndIdx+1);
  1823. try{
  1824. var _tempError_ = JSON.parse(strErrorSummary);
  1825. if(_tempError_ && _tempError_ instanceof Object && _tempError_['summary']){
  1826. message = _tempError_['summary'];
  1827. }else{
  1828. message = response.responseText;
  1829. }
  1830. }catch(error){
  1831. console.log(error);
  1832. message = response.responseText;
  1833. }
  1834. }
  1835. }
  1836. shr.showError({message: message});
  1837. //console.log('ajax error, url: ' + option.url + '?' + $.param(option.data));
  1838. return false;
  1839. },
  1840. /**
  1841. * 处理OSF入参加密
  1842. * @data 为OSF信息
  1843. * @param 为OSF需要传入的参数
  1844. */
  1845. handlerServiceParam:function(data, param){
  1846. if(data.inputParams || data.inputParams.length == 0){
  1847. return;
  1848. }
  1849. if(!data.encryptKey){
  1850. return;
  1851. }
  1852. $.each(param, function(name, value) {
  1853. if(shr.isNeedEncryptParam(name,data.inputParams)){
  1854. param[name] = this.encryptForAes_CBC(value, data.encryptKey);
  1855. }
  1856. });
  1857. },
  1858. /**
  1859. * 判断OSF中参数是否需要加密的参数
  1860. * @name 参数名称
  1861. * @inputParams OSF参数集合
  1862. */
  1863. isNeedEncryptParam:function(name, inputParams){
  1864. for (var i = 0,total = inputParams.length; i < total; i++) {
  1865. if(name==inputParams[i]['paramName']){
  1866. return true;
  1867. }
  1868. }
  1869. return false;
  1870. },
  1871. /**
  1872. * @option 中
  1873. * 新增属性isEncrypt 标记返回值是否已经加密
  1874. * 新增属性encryptKey 配置isEncrypt标记进行cbc解密,需要调用(this.decryptForAes_CBC)
  1875. * OSF的参数中某个具体参数需要进行加密传输,需要调用(this.encryptForAes_CBC)
  1876. */
  1877. callService: function(option) {
  1878. if ($.isEmptyObject(option)) {
  1879. return;
  1880. }
  1881. // url
  1882. var url = shr.getContextPath() + '/shr/msf/service.do';
  1883. option.url = url;
  1884. // data
  1885. var param = shr.getRequestParam(option);
  1886. param.method = 'callService';
  1887. param.serviceName = option.serviceName;
  1888. delete option.serviceName;
  1889. option.data = param;
  1890. //强制POST请求
  1891. option.type = 'POST';
  1892. // 默认为同步
  1893. if (typeof option.async == 'undefined') {
  1894. option.async = false;
  1895. }
  1896. return this.doRemoteCall(option);
  1897. },
  1898. // private
  1899. getRequestParam: function(option) {
  1900. var param;
  1901. if (option.param) {
  1902. param = option.param;
  1903. // 如参数中的对象参数进行处理,如果为对象则转换为JSON格式
  1904. $.each(param, function(name, value) {
  1905. if ($.isPlainObject(value)) {
  1906. param[name] = $.toJSON(value);
  1907. }
  1908. });
  1909. delete option.param;
  1910. } else {
  1911. param = {};
  1912. }
  1913. return param;
  1914. },
  1915. doRemoteCall: function(option) {
  1916. var xhr = $.doAjax(option);
  1917. if (option.async) {
  1918. return xhr;
  1919. }else {
  1920. var response;
  1921. if(xhr.adapteOSFResponseDataFormat && xhr.isOSFRequest){
  1922. response = xhr.responseJSON;
  1923. } else {
  1924. response = shr.explainJson(xhr.responseText);
  1925. }
  1926. if (response && response.data) {
  1927. return response.data;
  1928. } else {
  1929. return response;
  1930. }
  1931. }
  1932. },
  1933. callHandler: function(option) {
  1934. if ($.isEmptyObject(option)) {
  1935. return;
  1936. }
  1937. // url
  1938. var url = shr.getContextPath() + shr.dynamicURL;
  1939. option.url = url;
  1940. // data
  1941. var param = shr.getRequestParam(option);
  1942. param.method = option.action;
  1943. param.handler = option.handler;
  1944. delete option.action;
  1945. delete option.handler;
  1946. option.data = param;
  1947. //option.showBlock = true;
  1948. // 默认为异步
  1949. if (typeof option.async == 'undefined') {
  1950. option.async = true;
  1951. }
  1952. // 默认为get请求
  1953. if (typeof option.type == 'undefined') {
  1954. option.type = 'GET';
  1955. }
  1956. return this.doRemoteCall(option);
  1957. },
  1958. remoteCall: function(option) {
  1959. // 这里加一个变量用来控制,参数是否需要转化,isTransformParam = true时,不需要对参数进行转化,直接用传进来的参数即可
  1960. var isTransformParam = option.isTransformParam || false;
  1961. if ($.isEmptyObject(option)) {
  1962. return;
  1963. }
  1964. // url
  1965. if (typeof option.url == 'undefined') {
  1966. option.url = shr.getContextPath() + shr.dynamicURL;
  1967. }
  1968. // data
  1969. var param
  1970. if (!isTransformParam) {
  1971. param = shr.getRequestParam(option);
  1972. } else {
  1973. param = option.param
  1974. }
  1975. param.method = option.method;
  1976. param.uipk = option.uipk;
  1977. delete option.method;
  1978. delete option.uipk;
  1979. option.data = param;
  1980. // 默认为异步
  1981. if (typeof option.async == 'undefined') {
  1982. option.async = true;
  1983. }
  1984. // 默认为POST请求
  1985. if (typeof option.type == 'undefined') {
  1986. option.type = 'POST';
  1987. }
  1988. return this.doRemoteCall(option);
  1989. },
  1990. /**
  1991. * 添加自定义统计事件
  1992. */
  1993. trackEvent: function(category, action, opt_label, opt_value) {
  1994. var hmt = shr.getOwnerWindow()._hmt;
  1995. if (hmt) {
  1996. if ($.isEmptyObject(category)) {
  1997. category = document.location.href;
  1998. }
  1999. hmt.push(['_trackEvent', category, action, opt_label, opt_value]);
  2000. }
  2001. },
  2002. /**
  2003. * 获得数据所存放的位置
  2004. */
  2005. getOwnerWindow: function() {
  2006. var win;
  2007. if (window.parent != window) {
  2008. // 表示存在父窗口
  2009. win = window.parent;
  2010. } else {
  2011. win = window;
  2012. }
  2013. return window;
  2014. },
  2015. /**
  2016. * 描述:获取URL所对应的参数数组
  2017. * @param {url} url 路径
  2018. * @return 返回URL后追加的参数数组
  2019. */
  2020. getUrlParams : function(url) {
  2021. var args = new Object();
  2022. var query = location.search.substring(1);// 获取查询串
  2023. var pairs = query.split("&");// 在逗号处断开
  2024. for ( var i = 0; i < pairs.length; i++) {
  2025. var pos = pairs[i].indexOf('=');// 查找name=value
  2026. if (pos == -1)
  2027. continue;// 如果没有找到就跳过
  2028. var argname = pairs[i].substring(0, pos);// 提取name
  2029. var value = pairs[i].substring(pos + 1);// 提取value
  2030. args[argname] = unescape(value);// 存为属性
  2031. }
  2032. return args;
  2033. },
  2034. getUrlRequestParam : function(param, url) {
  2035. if (typeof url == 'undefined') {
  2036. url = location.href;
  2037. }
  2038. var paraString = url.substring(url.indexOf("?") + 1, url.length).split("&"),
  2039. paraObj = {};
  2040. //url中参数格式含a=&&这种的容错处理 2017/06/28 tiangang_yang
  2041. for (i = 0; /* j = paraString[i] ;*/i < paraString.length; i++) {
  2042. var j = paraString[i];
  2043. paraObj[j.substring(0, j.indexOf("=")).toLowerCase()] = j
  2044. .substring(j.indexOf("=") + 1, j.length);
  2045. }
  2046. var returnValue = paraObj[param.toLowerCase()];
  2047. if (typeof (returnValue) == 'undefined' || returnValue == 'undefined') {
  2048. return "";
  2049. } else {
  2050. if (returnValue.charAt(returnValue.length - 1) == '#') {
  2051. returnValue = returnValue.substr(0, returnValue.length - 1);
  2052. }
  2053. return decodeURIComponent(returnValue);
  2054. }
  2055. },
  2056. /**
  2057. * 描述:获取页面根路径
  2058. * @return 返回页面根路径 如:http://{domain}:{port}/{当前应用实例名称}
  2059. */
  2060. getContextPath:function() {
  2061. var contextPath = window._contextPath;
  2062. if (typeof contextPath == 'undefined') {
  2063. var href = window.location.href;
  2064. var host = window.location.host;
  2065. var f1 = href.substring(href.indexOf(host))
  2066. var f2 = f1.substring(f1.indexOf("/"));
  2067. var next = f2.indexOf('/', 1);
  2068. if (next != -1) {
  2069. contextPath = f2.substring(0, next);
  2070. } else {
  2071. contextPath = '';
  2072. }
  2073. }
  2074. return contextPath;
  2075. },
  2076. getOpenServiceFullPath: function() {
  2077. return shr.getContextPath() + shr.openServiceURL;
  2078. },
  2079. showInfo: function(options) {
  2080. shr.msgHideAll();
  2081. options = $.extend({
  2082. type: 'info',
  2083. hideAfter: 3,
  2084. showCloseButton: true
  2085. }, options);
  2086. if($.isFunction(_top.Messenger)) {
  2087. _top.Messenger().post(options);
  2088. }else{
  2089. Messenger().post(options);
  2090. }
  2091. },
  2092. showSuccess: function(options) {
  2093. shr.msgHideAll();
  2094. options = $.extend({
  2095. type: 'success',
  2096. hideAfter: 3,
  2097. showCloseButton: true
  2098. }, options);
  2099. if($.isFunction(_top.Messenger)) {
  2100. _top.Messenger().post(options);
  2101. }else{
  2102. Messenger().post(options);
  2103. }
  2104. },
  2105. showError: function(options) {
  2106. shr.msgHideAll();
  2107. if ($.isEmptyObject(options.message)) {
  2108. return;
  2109. }
  2110. options = $.extend({
  2111. type: 'error',
  2112. hideAfter: null,
  2113. showCloseButton: true
  2114. }, options);
  2115. if($.isFunction(_top.Messenger)) {
  2116. _top.Messenger().post(options);
  2117. }else{
  2118. Messenger().post(options);
  2119. }
  2120. },
  2121. showWarning: function(options) {
  2122. shr.msgHideAll();
  2123. shr.stopAllMask();
  2124. if ($.isEmptyObject(options.message)) {
  2125. return;
  2126. }
  2127. options = $.extend({
  2128. type: 'warning',
  2129. hideAfter: null,
  2130. showCloseButton: true
  2131. }, options);
  2132. if($.isFunction(_top.Messenger)) {
  2133. _top.Messenger().post(options);
  2134. }else{
  2135. Messenger().post(options);
  2136. }
  2137. },
  2138. // 增加一个有遮罩的提示,用来处理当浏览器缩放和窗口变小时 使用。
  2139. showMaskWarning: function(options) {
  2140. shr.msgHideAll();
  2141. shr.stopMask();
  2142. shr.stopAllMask();
  2143. if ($.isEmptyObject(options.message)) {
  2144. return;
  2145. }
  2146. var actionsObj = {};
  2147. actionsObj[$.shrI18n.common.buttonName.noMoreReminders] = {
  2148. action: function() {
  2149. $.stopAllMask();
  2150. shr.msgHideAll();
  2151. localStorage.setItem(shr.getUserInfo().id + '#ScreenZoom', $.toJSON({'noMoreReminders': 1}));
  2152. $(top.window).off('resize', throttle(addWindowResize, 500));
  2153. }
  2154. }
  2155. actionsObj[$.shrI18n.common.buttonName.close] = {
  2156. action: function() {
  2157. $.stopAllMask();
  2158. shr.msgHideAll();
  2159. }
  2160. }
  2161. options = $.extend({
  2162. type: 'warning',
  2163. hideAfter: null,
  2164. showCloseButton: false,
  2165. actions: actionsObj
  2166. }, options);
  2167. _top.Messenger().post(options);
  2168. shr.startMask();
  2169. },
  2170. // 添加args支持确认的时候的参数传递 格式如[a, b, c] 数组形式
  2171. showConfirm: function(message, action, cancel, args) {
  2172. shr.msgHideAll();
  2173. shr.startMask();
  2174. $('#shr-mask').css({'z-index':1050});
  2175. var messageFun;
  2176. if($.isFunction(_top.Messenger)){
  2177. messageFun = _top.Messenger();
  2178. }else{
  2179. messageFun = Messenger();
  2180. }
  2181. var msg = messageFun.post({
  2182. message: message,
  2183. hideAfter: null,
  2184. showCloseButton: true,
  2185. close: function(){
  2186. shr.stopMask();
  2187. },
  2188. actions: {
  2189. retry: {
  2190. label: $.shrI18n.common.title.confirm,
  2191. auto: false,
  2192. delay: 0,
  2193. showCloseButton: true,
  2194. action: function() {
  2195. shr.msgHideAll();
  2196. shr.stopMask();
  2197. if (action && $.isFunction(action)) {
  2198. if(args){
  2199. action.apply(this,args);
  2200. }else{
  2201. action.apply(this);
  2202. }
  2203. }
  2204. }
  2205. },
  2206. cancel: {
  2207. label: $.shrI18n.common.title.close,
  2208. action: function() {
  2209. shr.msgHideAll();
  2210. shr.stopMask();
  2211. if (cancel && $.isFunction(cancel)) {
  2212. if(args){
  2213. cancel.apply(this,args);
  2214. }else{
  2215. cancel.apply(this);
  2216. }
  2217. } else {
  2218. return msg.cancel();
  2219. }
  2220. }
  2221. }
  2222. }
  2223. });
  2224. return msg;
  2225. },
  2226. msgHideAll: function(){
  2227. var topElem = getTop();
  2228. if(topElem && typeof(topElem.Messenger) != 'undefined'){
  2229. topElem.Messenger().hideAll();
  2230. }
  2231. },
  2232. /**
  2233. * 描述:判断当前传递的json对象是否为枚举类型
  2234. */
  2235. isEnumValue:function(json){
  2236. if(!json || json == null) return false;
  2237. if(json.isenum!==undefined && json.alias!==undefined && json.value!==undefined){
  2238. return true;
  2239. }
  2240. return false;
  2241. },
  2242. hideErrorMsg: function() {
  2243. var historyMsg = _top.Messenger().history;
  2244. if (historyMsg) {
  2245. var msg;
  2246. for (var i = 0, length = historyMsg.length; i < length; i++) {
  2247. msg = historyMsg[i].msg;
  2248. if (msg.shown && msg.options.type != 'info') {
  2249. shr.msgHideAll();
  2250. return;
  2251. }
  2252. }
  2253. }
  2254. },
  2255. blockModal: function(hasBg){
  2256. var opts = {
  2257. lines: 10, // The number of lines to draw
  2258. length: 10, // The length of each line
  2259. width: 5, // The line thickness
  2260. radius: 10, // The radius of the inner circle
  2261. corners: 1, // Corner roundness (0..1)
  2262. rotate: 0, // The rotation offset
  2263. direction: 1, // 1: clockwise, -1: counterclockwise
  2264. color: '#000', // #rgb or #rrggbb
  2265. speed: 1.4, // Rounds per second
  2266. trail: 100, // Afterglow percentage
  2267. shadow: false, // Whether to render a shadow
  2268. hwaccel: false, // Whether to use hardware acceleration
  2269. className: 'spinner', // The CSS class to assign to the spinner
  2270. zIndex: 2e9, // The z-index (defaults to 2000000000)
  2271. top: 'auto', // Top position relative to parent in px
  2272. left: 'auto' // Left position relative to parent in px
  2273. };
  2274. var modal = _top.$.scojs_modal({
  2275. width: 0,
  2276. height: 0,
  2277. top: -1000
  2278. });
  2279. if(!hasBg){
  2280. modal.show();
  2281. }
  2282. var target = _top.document.getElementById('wrap');
  2283. var spinner = new Spinner(opts).spin(target);
  2284. var blockModal = {"modal": modal, "spinner": spinner};
  2285. return blockModal;
  2286. },
  2287. destroyBlockModal: function(blockModal){
  2288. blockModal.modal.destroy();
  2289. blockModal.spinner.stop();
  2290. },
  2291. /**
  2292. * 获得页面对应的短网址
  2293. */
  2294. getShortUrl: function() {
  2295. var doc;
  2296. if ($('#workArea').length > 0) {
  2297. doc = $('#workArea')[0].contentDocument;
  2298. } else {
  2299. doc = document;
  2300. }
  2301. var realUrl = this.getPageUrl(document);
  2302. var response = shr.callService({
  2303. serviceName: 'url2short',
  2304. type: 'POST',
  2305. param: {
  2306. url: realUrl
  2307. }
  2308. });
  2309. if (response) {
  2310. var breadcrumb = shrDataManager.pageNavigationStore.getDatas();
  2311. var names = [];
  2312. for (var i = 0, length = breadcrumb.length; i < length; i++) {
  2313. if (i != 0) {
  2314. names.push(' / ');
  2315. }
  2316. names.push(breadcrumb[i].name);
  2317. }
  2318. if (names.length == 0) {
  2319. names.push(doc.title);
  2320. }
  2321. return {
  2322. shortUrl: response.short,
  2323. desc: names.join('')
  2324. }
  2325. }
  2326. },
  2327. /**
  2328. * 根据短网址显示页面
  2329. */
  2330. renderPage: function(short) {
  2331. var response = shr.callService({
  2332. serviceName: 'short2url',
  2333. type: 'POST',
  2334. param: {
  2335. id: short
  2336. }
  2337. });
  2338. if (response && response.url) {
  2339. var url = shr.getContextPath() + response.url;
  2340. if ($('#workArea').length > 0) {
  2341. $('#workArea')[0].contentDocument.location.replace(url);
  2342. } else {
  2343. document.location.href = url;
  2344. }
  2345. }
  2346. },
  2347. getPageUrl: function(document) {
  2348. if (typeof document == 'undefined') {
  2349. document = window.document;
  2350. }
  2351. var url = document.location.href;
  2352. var contextPath = shr.getContextPath();
  2353. return url.substr(url.indexOf(contextPath) + contextPath.length);
  2354. },
  2355. loadScript: function(url, callback) {
  2356. if (callback) {
  2357. return $LAB.script(url).wait(callback);
  2358. } else {
  2359. return $LAB.script(url);
  2360. }
  2361. },
  2362. loadCss: function(url){
  2363. var link = document.createElement('link');
  2364. link.type = 'text/css';
  2365. link.rel = 'stylesheet';
  2366. link.href = url;
  2367. document.getElementsByTagName('head')[0].appendChild(link);
  2368. },
  2369. //默认设置workArea高度, 如需设置其他高度, 则传入iframe的id
  2370. setIframeHeight: function(iframeId) {
  2371. var _self = this;
  2372. if (typeof iframeId == 'undefined') {
  2373. iframeId = shr.getUrlRequestParam('iframe');
  2374. }
  2375. if(iframeId && iframeId != null){
  2376. id = iframeId;
  2377. } else {
  2378. id = 'workArea';
  2379. }
  2380. var _iframe = $('#'+id)[0];
  2381. if(!_iframe){ //在iframe中调用时需要通过父页面获取iframe标签
  2382. _iframe = $('#'+id, parent.document)[0];
  2383. }
  2384. setTimeout(function() {
  2385. if (_iframe){
  2386. if ($(_iframe).attr('autoHeight') == 'false') {
  2387. return;
  2388. }
  2389. var _iframeHeight = null;
  2390. if (_iframe.contentDocument && _iframe.contentDocument.body.offsetHeight){
  2391. _iframeHeight = _iframe.contentDocument.body.offsetHeight;
  2392. } else if (_iframe.Document && _iframe.Document.body.scrollHeight){
  2393. _iframeHeight = _iframe.Document.body.scrollHeight;
  2394. }
  2395. if(id === 'workArea'){
  2396. var excludeIframeHeight = _self.getWorkareaVisibleHeight();
  2397. if(_iframeHeight <= excludeIframeHeight){
  2398. _iframe.height = excludeIframeHeight;
  2399. }else{
  2400. _iframe.height = _iframeHeight;
  2401. }
  2402. } else {
  2403. //_iframe.height = _iframeHeight + 60;
  2404. //_iframe.height = _iframeHeight;
  2405. var $iframe = $(_iframe);
  2406. $iframe.height(_iframeHeight + 20 );
  2407. var printMode = shr.getUrlRequestParam('printMode');
  2408. if (!printMode == 'true') {
  2409. var _iframeWidth = $iframe.parent().width();
  2410. $iframe.width(_iframeWidth);
  2411. }
  2412. }
  2413. // 如果当前window不是最顶部window,则递归调用setIframeHeight设置高度
  2414. if (!$.isWindow(parent)) {
  2415. if( parent.shr ){ // 解决父窗口不是s-HR页面登录的时候报错问题
  2416. parent.shr.setIframeHeight();
  2417. }
  2418. }
  2419. }
  2420. }, 100)
  2421. shr.setFixedBlockPosition();
  2422. },
  2423. getWorkareaVisibleHeight: function() {
  2424. var topWindow = $(_top.window);
  2425. var visibleHeight = topWindow.height();
  2426. var container = $('#home-container', topWindow[0].document);
  2427. //row-fluid的外边距为10
  2428. var container_margin = container.outerHeight(true) - container.outerHeight(),
  2429. row_margin_top = 0,
  2430. offset = 10;
  2431. var margin = container_margin + row_margin_top + offset;
  2432. return visibleHeight - margin;
  2433. },
  2434. getWorkarea: function() {
  2435. //判断当前界面是否是导航界面,如果是导航界面则去当前的界面进行渲染,不能取外层
  2436. if($('.wz_navi_new', _top.document).length > 0) {
  2437. return $('#workAreaDiv');
  2438. }else{
  2439. return $('#workAreaDiv', _top.document);
  2440. }
  2441. },
  2442. /**
  2443. * 构造动态URL
  2444. * @param value 需要打开的视图UIPK或是URL地址
  2445. * @param type URL类型,可传入的值:view,url。
  2446. * @param params 打开页面时需传递的参数
  2447. */
  2448. assembleURL: function(value, type, params) {
  2449. if (!value || !type) {
  2450. return;
  2451. }
  2452. if(value.indexOf("http") === 0 || value.indexOf("/easweb") === 0){
  2453. return value;
  2454. }
  2455. var url, options;
  2456. if (type.toLowerCase() == 'view') {
  2457. // 视图
  2458. url = shr.dynamicURL;
  2459. options = { uipk: value };
  2460. } else if (type.toLowerCase() == 'handler') {
  2461. // handler
  2462. url = shr.dynamicURL;
  2463. options = { handler: value };
  2464. } else {
  2465. // url
  2466. url = value;
  2467. options = {};
  2468. }
  2469. url = shr.getContextPath() + url;
  2470. if (params) {
  2471. $.extend(options, params);
  2472. }
  2473. url = this.appendParam(url, options);
  2474. return url;
  2475. },
  2476. appendParam: function(url, param) {
  2477. // append param
  2478. if (!$.isEmptyObject(param)) {
  2479. if (url.indexOf('?') == -1) {
  2480. url += '?';
  2481. } else {
  2482. url += '&';
  2483. }
  2484. url += $.param(param);
  2485. }
  2486. return url;
  2487. },
  2488. removeParam: function(url, param) {
  2489. // remove param
  2490. if ($.isEmptyObject(param)) {
  2491. return url;
  2492. }
  2493. var start = url.indexOf(param + '=');
  2494. if (start == -1) {
  2495. return url;
  2496. }
  2497. var end = url.indexOf('&', start + 1);
  2498. if (end == -1) {
  2499. end = url.length;
  2500. }
  2501. var c = url.charAt(start - 1);
  2502. if (c == '&') {
  2503. start = start - 1;
  2504. } else if (c == '?' && url.charAt(end) == '&') {
  2505. end = end + 1;
  2506. }
  2507. return url.substring(0, start) + url.substring(end);
  2508. },
  2509. assembleViewUrl: function(uipk, params) {
  2510. return shr.assembleURL(uipk, 'view', params);
  2511. },
  2512. assembleHandlerUrl: function(handler, action, params) {
  2513. if (params == 'undefined' || !params) {
  2514. params = {};
  2515. }
  2516. params.method = action;
  2517. return shr.assembleURL(handler, 'handler', params);
  2518. },
  2519. /**
  2520. * 加载页面
  2521. * @param value 需要打开的视图UIPK或是URL地址
  2522. * @param type URL类型,可传入的值:view,url。
  2523. * @param params 打开页面时需传递的参数
  2524. */
  2525. loadPage: function(value, type, params) {
  2526. var url = this.assembleURL(value, type, params);
  2527. if (url) {
  2528. this.urlLocate(url);
  2529. }
  2530. },
  2531. /**
  2532. * 是否是主工作区iframe
  2533. */
  2534. isWorkareaFrame: function() {
  2535. var inFrame = shr.getUrlRequestParam('inFrame');
  2536. if (inFrame && inFrame.indexOf('true') > -1) {
  2537. return true;
  2538. }
  2539. var iframeName = shr.getUrlRequestParam('iframe');
  2540. if (iframeName) {
  2541. value = iframeName == 'workArea';
  2542. } else {
  2543. value = $('#workArea', parent.document).length > 0;
  2544. }
  2545. return value;
  2546. },
  2547. /**
  2548. *菜单操作日志
  2549. */
  2550. operateLogger: function(value) {},
  2551. base64Encode: function(input) {
  2552. var _keyStr = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";
  2553. var output = "";
  2554. var chr1, chr2, chr3, enc1, enc2, enc3, enc4;
  2555. var i = 0;
  2556. input = shr.utf8Encode(input);
  2557. while (i < input.length) {
  2558. chr1 = input.charCodeAt(i++);
  2559. chr2 = input.charCodeAt(i++);
  2560. chr3 = input.charCodeAt(i++);
  2561. enc1 = chr1 >> 2;
  2562. enc2 = ((chr1 & 3) << 4) | (chr2 >> 4);
  2563. enc3 = ((chr2 & 15) << 2) | (chr3 >> 6);
  2564. enc4 = chr3 & 63;
  2565. if (isNaN(chr2)) {
  2566. enc3 = enc4 = 64;
  2567. } else if (isNaN(chr3)) {
  2568. enc4 = 64;
  2569. }
  2570. output = output + _keyStr.charAt(enc1) + _keyStr.charAt(enc2) + _keyStr.charAt(enc3) + _keyStr.charAt(enc4);
  2571. }
  2572. return output;
  2573. },
  2574. base64Decode:function(input){
  2575. var _keyStr = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";
  2576. var output = "";
  2577. var chr1, chr2, chr3, enc1, enc2, enc3, enc4;
  2578. var i = 0;
  2579. input = input.replace(/[^A-Za-z0-9\+\/\=]/g, "");
  2580. while (i < input.length) {
  2581. enc1 = _keyStr.indexOf(input.charAt(i++));
  2582. enc2 = _keyStr.indexOf(input.charAt(i++));
  2583. enc3 = _keyStr.indexOf(input.charAt(i++));
  2584. enc4 = _keyStr.indexOf(input.charAt(i++));
  2585. chr1 = (enc1 << 2) | (enc2 >> 4);
  2586. chr2 = ((enc2 & 15) << 4) | (enc3 >> 2);
  2587. chr3 = ((enc3 & 3) << 6) | enc4;
  2588. output = output + String.fromCharCode(chr1);
  2589. if (enc3 != 64) {
  2590. output = output + String.fromCharCode(chr2);
  2591. }
  2592. if (enc4 != 64) {
  2593. output = output + String.fromCharCode(chr3);
  2594. }
  2595. }
  2596. output = shr.utf8Encode(output);
  2597. return output;
  2598. },
  2599. /**
  2600. * encryptObj:{key: value, key: value} key:需要加密的字段; value: 需要加密的值;
  2601. * url: 必填,会将参数最终拼接在url上
  2602. * 加密 for url
  2603. */
  2604. encryptForUrl: function(encryptObj, url) {
  2605. var aKeys = Object.keys(encryptObj),
  2606. keyStr = aKeys.join(',');;
  2607. url = $.appendParam(url, {'encryptKeys': keyStr});
  2608. for(var n = 0; n < aKeys.length; n++) {
  2609. var key = aKeys[n];
  2610. var value = encryptObj[key];
  2611. var encode = $.allEncrypt(value);
  2612. url += '&'+key+'='+encode;
  2613. }
  2614. return url
  2615. },
  2616. /**
  2617. * encryptObj:{key: value, key: value} key:需要加密的字段; value: 需要加密的值;
  2618. * url: 选填,需要在url上添加时则传,否则不传
  2619. * 加密 for obj
  2620. */
  2621. encryptForObj: function(encryptObj, url) {
  2622. var aKeys = Object.keys(encryptObj),
  2623. obj = {},
  2624. keyStr = aKeys.join(',');
  2625. for(var n = 0; n < aKeys.length; n++) {
  2626. var key = aKeys[n];
  2627. var value = encryptObj[key];
  2628. var encode = $.allEncrypt(value);
  2629. obj[key] = encode;
  2630. }
  2631. url ? url = $.appendParam(url, {'encryptKeys': keyStr}) : null;
  2632. return {
  2633. obj: obj,
  2634. keyStr: keyStr,
  2635. url: url
  2636. }
  2637. },
  2638. /**
  2639. * 盐+base64加密
  2640. */
  2641. encryptForB64: function(value) {
  2642. if ($.isUndef(value)) {
  2643. return value;
  2644. }
  2645. var encode = $.base64Encode(value,"utf-8");
  2646. return '_SHRREQPARA_'+encode;
  2647. },
  2648. /**
  2649. * 盐+base64解密
  2650. */
  2651. decryptForB64: function(value) {
  2652. if ($.isUndef(value)) {
  2653. return value;
  2654. }
  2655. value= value.replace('_SHRREQPARA_','');
  2656. var decode = $.base64Decode(value,"utf-8");
  2657. return decode;
  2658. },
  2659. /**
  2660. * 盐+base64加密
  2661. */
  2662. encryptForB64PreFix: function(value,preFix) {
  2663. if ($.isUndef(value)) {
  2664. return value;
  2665. }
  2666. var encode = $.base64Encode(value,"utf-8");
  2667. return preFix + encode;
  2668. },
  2669. /**
  2670. * 盐+base64解密
  2671. */
  2672. decryptForB64PreFix: function(value,preFix) {
  2673. if ($.isUndef(value)) {
  2674. return value;
  2675. }
  2676. value= value.replace(preFix,'');
  2677. var decode = $.base64Decode(value,"utf-8");
  2678. return decode;
  2679. },
  2680. /**
  2681. * AES加密
  2682. */
  2683. encryptForAes: function(content, secretKey) {
  2684. if ($.isUndef(content)) {
  2685. return content;
  2686. }
  2687. var secretKey = secretKey || "g5AJVI7fQGWZKrdZ";
  2688. var key = CryptoJS.enc.Utf8.parse(secretKey);
  2689. var iv = shr.randomRange(16);
  2690. var srcs = CryptoJS.enc.Utf8.parse(content);
  2691. var encrypted = CryptoJS.AES.encrypt(srcs, key, { iv:CryptoJS.enc.Utf8.parse(iv), mode:CryptoJS.mode.CBC, padding: CryptoJS.pad.Pkcs7 });
  2692. return iv + encrypted.toString();
  2693. },
  2694. /**
  2695. * AES解密
  2696. */
  2697. decryptForAes: function(content, secretKey) {
  2698. if ($.isUndef(content)) {
  2699. return content;
  2700. }
  2701. var secretKey = secretKey || "g5AJVI7fQGWZKrdZ";
  2702. var key = CryptoJS.enc.Utf8.parse(secretKey);
  2703. var iv = content.slice(0, 16);
  2704. var realContent = content.slice(16, content.length);
  2705. var decrypted = CryptoJS.AES.decrypt(realContent, key, { iv:CryptoJS.enc.Utf8.parse(iv), mode:CryptoJS.mode.CBC, padding: CryptoJS.pad.Pkcs7 });
  2706. return decrypted.toString(CryptoJS.enc.Utf8);
  2707. },
  2708. /**
  2709. * AES-CBC加密
  2710. */
  2711. encryptForAes_CBC: function(content, secretKey) {
  2712. if ($.isUndef(content)) {
  2713. return content;
  2714. }
  2715. var secretKey = secretKey || "g5AJVI7fQGWZKrdZ";
  2716. var key = CryptoJS.enc.Utf8.parse(secretKey);
  2717. var iv = shr.randomRange(16);
  2718. var srcs = CryptoJS.enc.Utf8.parse(content);
  2719. var encrypted = CryptoJS.AES.encrypt(srcs, key, { iv:CryptoJS.enc.Utf8.parse(iv), mode:CryptoJS.mode.CBC, padding: CryptoJS.pad.Pkcs7 });
  2720. return iv + encrypted.toString();
  2721. },
  2722. /**
  2723. * AES-CBC解密
  2724. */
  2725. decryptForAes_CBC: function(content, secretKey) {
  2726. if ($.isUndef(content)) {
  2727. return content;
  2728. }
  2729. var secretKey = secretKey || "g5AJVI7fQGWZKrdZ";
  2730. var key = CryptoJS.enc.Utf8.parse(secretKey);
  2731. var iv = content.slice(0, 16);
  2732. var realContent = content.slice(16, content.length);
  2733. var decrypted = CryptoJS.AES.decrypt(realContent, key, { iv:CryptoJS.enc.Utf8.parse(iv), mode:CryptoJS.mode.CBC, padding: CryptoJS.pad.Pkcs7 });
  2734. return decrypted.toString(CryptoJS.enc.Utf8);
  2735. },
  2736. /**
  2737. * 总加密方法,根据window.shrUrlParamEncryptRule的取值去分发 'BASE64' / 'AES', 后续如果要添加新加密方法在这里加即可。
  2738. */
  2739. allEncrypt: function(value) {
  2740. var encryptWay = window.shrUrlParamEncryptRule || 'BASE64'; // 加密方式 根据后端传回
  2741. value = $.isUndef(value) ? value : encodeURIComponent(value);
  2742. var encryptMethod = {
  2743. 'BASE64': $.encryptForB64,
  2744. 'AES': $.encryptForAes_CBC
  2745. }
  2746. return encryptMethod[encryptWay](value)
  2747. },
  2748. /**
  2749. * 总解密方法,根据window.shrUrlParamEncryptRule的取值去分发 'BASE64' / 'AES', 后续如果要添加新解密方法在这里加即可。
  2750. * @param value
  2751. * @returns
  2752. */
  2753. allDecrypt:function(value){
  2754. try {
  2755. var encryptWay = window.shrUrlParamEncryptRule || 'BASE64'; // 解密方式 根据后端传回
  2756. if($.isUndef(value)){
  2757. return value;
  2758. }
  2759. var decryptMethod = {
  2760. 'BASE64': $.decryptForB64,
  2761. 'AES': $.decryptForAes_CBC
  2762. };
  2763. return decodeURIComponent(decryptMethod[encryptWay](value));
  2764. } catch (error) {
  2765. console.log(error);
  2766. return value;
  2767. }
  2768. },
  2769. utf8Encode: function(string){
  2770. if(!string){
  2771. string = '';
  2772. }
  2773. string = string.replace(/\r\n/g,"\n");
  2774. var utftext = "";
  2775. for (var n = 0; n < string.length; n++) {
  2776. var c = string.charCodeAt(n);
  2777. if (c < 128) {
  2778. utftext += String.fromCharCode(c);
  2779. } else if((c > 127) && (c < 2048)) {
  2780. utftext += String.fromCharCode((c >> 6) | 192);
  2781. utftext += String.fromCharCode((c & 63) | 128);
  2782. } else {
  2783. utftext += String.fromCharCode((c >> 12) | 224);
  2784. utftext += String.fromCharCode(((c >> 6) & 63) | 128);
  2785. utftext += String.fromCharCode((c & 63) | 128);
  2786. }
  2787. }
  2788. return utftext;
  2789. },
  2790. /**
  2791. * 是否是向导iframe
  2792. */
  2793. isWizardFrame: function() {
  2794. return $('#_wz_iframe', parent.document).length > 0;
  2795. },
  2796. /**
  2797. * 是否是新向导iframe
  2798. */
  2799. isNewWizardFrame: function() {
  2800. return $('.wz_navi_new ', parent.document).length > 0;
  2801. },
  2802. /**
  2803. * 定位至某个区域块
  2804. */
  2805. locateTo: function(newElement, complete, duration) {
  2806. var offsetTop;
  2807. if ($.isNumeric(newElement)) {
  2808. offsetTop = newElement;
  2809. } else {
  2810. offsetTop= $(newElement).offset().top;
  2811. }
  2812. var doc;
  2813. if (parent == window) {
  2814. doc = document;
  2815. } else if (parent == _top){
  2816. // in iframe
  2817. doc = parent.document;
  2818. // get parent offset
  2819. var iframeId = shr.getUrlRequestParam('iframe') || 'iframe';
  2820. var iframe_top = $('#' + iframeId, doc).offset() ? $('#' + iframeId, doc).offset().top : 0;
  2821. offsetTop += iframe_top;
  2822. }
  2823. // add header offset
  2824. var workarea = this.getWorkarea();
  2825. if (workarea.length > 0) {
  2826. //offsetTop -= workarea.offset().top;
  2827. offsetTop = offsetTop - (workarea.offset().top + 160);
  2828. }
  2829. var isIE = false;
  2830. if( "ActiveXObject" in window ){
  2831. isIE = true;
  2832. }
  2833. if ( isIE) {
  2834. doc.documentElement.scrollTop = offsetTop;
  2835. if (complete) {
  2836. complete.call(this);
  2837. }
  2838. } else {
  2839. if (typeof duration == 'undefined') {
  2840. duration = 500;
  2841. }
  2842. $('body,html', doc).animate({scrollTop: offsetTop}, duration, function() {
  2843. if (complete) {
  2844. complete.call(this);
  2845. }
  2846. });
  2847. }
  2848. },
  2849. closeWindow: function() {
  2850. window.open('','_self');
  2851. window.opener = null;
  2852. window.close();
  2853. },
  2854. /**
  2855. * 加载HTML片断
  2856. */
  2857. loadHTML: function(options) {
  2858. $.extend(options, {
  2859. dataType: 'html'
  2860. });
  2861. var success = options.success;
  2862. options.success = function(response) {
  2863. try{
  2864. var result = JSON.parse(response);
  2865. if(result && result.result === 'error'){
  2866. shr.showError({message: result.summary});
  2867. return;
  2868. }
  2869. }catch(e){
  2870. }
  2871. //var urlParams = shr.getUrlParams();
  2872. var repData = shr.callService({
  2873. serviceName:'getBizMultLanService',
  2874. param:{uipk:shr.getUrlRequestParam('uipk',options.url)},
  2875. type: 'POST',
  2876. async: false,
  2877. ignoreDataPerm: true,
  2878. });
  2879. window.contextLanguage = repData['contextLanguage'];
  2880. $.extend(window.jsBizMultLan, repData['jsBizMultLan']);
  2881. $.extend(window.utcData, repData['utcData']);
  2882. $.extend(window.numberFormat, repData['numberFormat']);
  2883. $.extend(window.languageMappingList, repData['languageMappingList']);
  2884. $.extend(window.isTCtoTWopen, repData['isTCtoTWopen']);
  2885. if (shr.checkIsRedirectLogin(response)) {
  2886. window.location.href = shr.getContextPath();
  2887. return;
  2888. }
  2889. var $content = $(response);
  2890. var item;
  2891. var scripts = [];
  2892. // 解析script标签,为手动加载script文件
  2893. for (var i = $content.length - 1; i >= 0; i--) {
  2894. item = $content[i];
  2895. if (item.tagName == 'SCRIPT' && item.getAttribute('src')) {
  2896. scripts.push(item.getAttribute('src'));
  2897. $content.splice(i, 1);
  2898. }
  2899. }
  2900. if (scripts.length > 0) {
  2901. scripts = scripts.reverse();
  2902. // 手动加载script文件,为解决不能调试的问题
  2903. shr.loadScript(scripts, function() {
  2904. if (success && $.isFunction(success)) {
  2905. success.call(this, $content);
  2906. }
  2907. });
  2908. } else {
  2909. if (success && $.isFunction(success)) {
  2910. success.call(this, $content);
  2911. }
  2912. }
  2913. }
  2914. shr.doGet(options);
  2915. },
  2916. setFixedBlockPosition: function() {
  2917. var bodywidth = $(window.top.document.body).width();
  2918. var iframewidth = $(window.top.document.body).find("#home-container").width();
  2919. if((bodywidth-iframewidth) < 20){
  2920. /*$(window._top.document.body).find("#adviseUp").css("right", 0);*/
  2921. $(window._top.document.body).find("#scrollUp").css("right", 0);
  2922. }else{
  2923. /*$(window._top.document.body).find("#adviseUp").css("left", iframewidth+(bodywidth-iframewidth)/2);*/
  2924. $(window._top.document.body).find("#scrollUp").css("left", iframewidth+(bodywidth-iframewidth)/2);
  2925. }
  2926. //根据窗口大小动态
  2927. $(window).resize(function(){
  2928. var bodywidth = $(window.top.document.body).width();
  2929. var iframewidth = $(window.top.document.body).find("#home-container").width();
  2930. if((bodywidth-iframewidth) < 20){
  2931. /*$(window._top.document.body).find("#adviseUp").css("right", 0);*/
  2932. $(window.top.document.body).find("#scrollUp").css("right", 0);
  2933. }else{
  2934. /*$(window._top.document.body).find("#adviseUp").css("left", iframewidth+(bodywidth-iframewidth)/2);*/
  2935. $(window.top.document.body).find("#scrollUp").css("left", iframewidth+(bodywidth-iframewidth)/2);
  2936. }
  2937. });
  2938. },
  2939. /**
  2940. * 获得当前登录用户信息
  2941. */
  2942. getUserInfo: function() {
  2943. var context = _top.document;
  2944. return {
  2945. id: $('#userId', context).val(),
  2946. number: $('#userNumber', context).val()
  2947. }
  2948. },
  2949. /**
  2950. * 获得页面信息
  2951. */
  2952. getPageInfo: function() {
  2953. var getPageCode = function(url) {
  2954. var uipk = shr.getUrlRequestParam('uipk', url);
  2955. if (uipk) {
  2956. return uipk;
  2957. }
  2958. var contextPath = shr.getContextPath();
  2959. var firstIndex = url.indexOf(contextPath) + contextPath.length;
  2960. var lastIndex = url.indexOf('?')
  2961. if (lastIndex == -1) {
  2962. lastIndex = url.length;
  2963. }
  2964. return url.substring(firstIndex, lastIndex);
  2965. };
  2966. var doc;
  2967. if ($('#workArea').length > 0) {
  2968. doc = $('#workArea')[0].contentDocument;
  2969. } else {
  2970. doc = document;
  2971. }
  2972. var serviceId = shr.getServiceId();
  2973. var param;
  2974. if (serviceId) {
  2975. param = {
  2976. category_code: serviceId,
  2977. page_code: getPageCode(doc.location.href),
  2978. page_desc: $('title', doc).data('value')
  2979. };
  2980. var service = shr.createObject(shr.base.ServiceData).getServiceById(serviceId);
  2981. var category;
  2982. if (service && service.category && service.category.length > 0) {
  2983. category = service.category[0];
  2984. } else {
  2985. category = '';
  2986. }
  2987. param.category_desc = category;
  2988. } else {
  2989. var title;
  2990. if (doc.location.href.indexOf('/home.do') >= 0) {
  2991. title = $.shrI18n.base.title.homePage;
  2992. } else {
  2993. title = $('title', doc).data('value')
  2994. }
  2995. param = {
  2996. page_code: getPageCode(doc.location.href),
  2997. page_desc: title
  2998. };
  2999. }
  3000. return param;
  3001. },
  3002. /**
  3003. * js设置placeholder,解决IE9下显示不了的问题
  3004. */
  3005. funPlaceholder: function(element) {
  3006. var placeholder = '';
  3007. if (element && !("placeholder" in document.createElement("input")) && (placeholder = element.getAttribute("placeholder"))) {
  3008. element.onfocus = function() {
  3009. if (this.value === placeholder) {
  3010. this.value = "";
  3011. }
  3012. this.style.color = '';
  3013. };
  3014. element.onblur = function() {
  3015. if (this.value === "") {
  3016. this.value = placeholder;
  3017. }
  3018. };
  3019. //样式初始化
  3020. if (element.value === "") {
  3021. element.value = placeholder;
  3022. }
  3023. }
  3024. },
  3025. /**
  3026. * 选择器中包含“.”导致JQuery选择器不可用,转义处理
  3027. */
  3028. selectorFormat : function (selectorStr){
  3029. return selectorStr.replace(/(:|\.|\[|\])/g, '\\$1');
  3030. },
  3031. /**
  3032. * 本窗口采用post方式加载某个URL,解决URL超长问题
  3033. */
  3034. reloadUrlByPost: function(url, param, name) {
  3035. if (!name) {
  3036. name = (new Date()).getTime();
  3037. }
  3038. name = 'urlpost_' + name;
  3039. var form = $('#' + name);
  3040. if (form.length > 0) {
  3041. form.remove();
  3042. }
  3043. var str = ['<form id="${name}" action="" method="post" target="${name}-frame"></form>',
  3044. '<iframe id="${name}-frame" name="${name}-frame" src="" style="display: none;"></iframe>'].join('');
  3045. $(juicer(str, {name: name})).appendTo('body');
  3046. form = $('#' + name);
  3047. // 将相应的参数值填充至form中
  3048. var option = {
  3049. url: url,
  3050. data: param
  3051. }
  3052. shr.dealPostParam(option);
  3053. var content = this.paramToInputHidden(option.data);
  3054. form.attr('action', option.url).append(content).submit();
  3055. },
  3056. /**
  3057. * 采用post方式打开新窗口,解决URL超长问题
  3058. */
  3059. openWindowByPost: function(url, param) {
  3060. $('#openwindow-form').remove();
  3061. window.open('', 'openwindow-frame');
  3062. var content = this.paramToInputHidden(param);
  3063. var str = '<form id="openwindow-form" action="" method="post" target="openwindow-frame"></form>';
  3064. $(str).attr('action', url).append(content).appendTo('body').submit();
  3065. },
  3066. /**
  3067. * 将参数转换为input hidden字符串
  3068. */
  3069. paramToInputHidden: function(param) {
  3070. var content = '', tpl = '<input type="hidden" name="${name}" value="${value}" />';
  3071. for (var key in param) {
  3072. content += juicer(tpl, {
  3073. name: key,
  3074. value: param[key]
  3075. });
  3076. }
  3077. return content;
  3078. },
  3079. /*
  3080. *检测 FlashPlayer
  3081. * */
  3082. getFlashVersion : function () {
  3083. var flashVer = NaN;
  3084. var ua = navigator.userAgent;
  3085. if (window.ActiveXObject) {
  3086. var swf = new ActiveXObject('ShockwaveFlash.ShockwaveFlash');
  3087. if (swf) {
  3088. flashVer = Number(swf.GetVariable('$version').split(' ')[1].replace(/\,/g, '.').replace(/^(\d+\.\d+).*$/, "$1"));
  3089. }
  3090. } else {
  3091. if (navigator.plugins && navigator.plugins.length > 0) {
  3092. var swf = navigator.plugins['Shockwave Flash'];
  3093. if (swf) {
  3094. var arr = swf.description.split(' ');
  3095. for (var i = 0, len = arr.length; i < len; i++) {
  3096. var ver = Number(arr[i]);
  3097. if (!isNaN(ver)) {
  3098. flashVer = ver;
  3099. break;
  3100. }
  3101. }
  3102. }
  3103. }
  3104. }
  3105. return flashVer;
  3106. },
  3107. /*
  3108. *检测 是否可以上传文件
  3109. * */
  3110. checkCanUpload :function(){
  3111. var _self = this;
  3112. var flashVer = shr.getFlashVersion();
  3113. if (!isNaN(flashVer)) {
  3114. ua = navigator.userAgent;
  3115. ua = ua.toLocaleLowerCase();
  3116. if (ua.match(/msie/) != null || ua.match(/trident/) != null) {
  3117. var browserType = "IE";
  3118. var browserVersion = ua.match(/msie ([\d.]+)/) != null ? ua.match(/msie ([\d.]+)/)[1] : ua.match(/rv:([\d.]+)/)[1];
  3119. }
  3120. if(browserVersion == "11.0" && flashVer <12){
  3121. shr.showError({
  3122. message: $.shrI18n.framework.tips.flashVersionRequirePrefix + flashVer +$.shrI18n.framework.tips.flashVersionRequireSuffix
  3123. });
  3124. return false;
  3125. }
  3126. return true;
  3127. } else {
  3128. shr.showError({
  3129. message: $.shrI18n.framework.tips.noInstallFlashSimple
  3130. });
  3131. return false
  3132. }
  3133. return true;
  3134. },
  3135. imCloudInstance: void(0),
  3136. // 真正初始化云之家消息组件
  3137. initImCloudRun: function (response) {
  3138. // if (!this.imCloudInstance) {
  3139. // this.imCloudInstance = new imCloud({ //组件初始化
  3140. // eid: response.eid, //填写企业id号
  3141. // data: response.data //填写上面步骤生成的加密字段
  3142. // });
  3143. // }
  3144. // 点击非控件区域,控件可关闭
  3145. $("iframe").on("load", function(event){//判断 iframe是否加载完成 这一步很重要
  3146. $("body",this.contentDocument).click(function(e){//添加点击事件
  3147. if($(e.target).closest('.im-wrap').length < 1 && !$('#im-session-left').is(':hidden')){
  3148. if(!$('#im-session-left').is(':hidden') && !$(e.target).hasClass('ot-del-person')){
  3149. $('.im-tray').click();
  3150. }
  3151. }
  3152. });
  3153. });
  3154. $(document).click(function(e){
  3155. if($(e.target).closest('.im-wrap').length < 1 && !$('#im-session-left').is(':hidden') && document.body.contains(e.target)){
  3156. if(!$('#im-session-left').is(':hidden') && !$(e.target).hasClass('ot-del-person')){
  3157. if($('.im-tray', window.parent.document).length > 0){
  3158. $('.im-tray', window.parent.document).click();
  3159. }else{
  3160. $('.im-tray').click();
  3161. }
  3162. }
  3163. }
  3164. })
  3165. return this.imCloudInstance;
  3166. },
  3167. // 初始化云之家消息组件
  3168. initImCloud: function (response) {
  3169. var _self = this;
  3170. if (_top.imCloud) {
  3171. if (!this.imCloudInstance) {
  3172. this.imCloudInstance = _top.imCloud;
  3173. }
  3174. _self.initImCloudRun(response);
  3175. } else {
  3176. try {
  3177. shr.loadScript('https://www.yunzhijia.com/imsdk/imcloud/js/imcloud.js', function () {
  3178. if (!this.imCloudInstance) {
  3179. this.imCloudInstance = new imCloud({ //组件初始化
  3180. eid: response.eid, //填写企业id号
  3181. data: response.data //填写上面步骤生成的加密字段
  3182. });
  3183. }
  3184. _self.initImCloudRun(response);
  3185. });
  3186. } catch (error) {
  3187. }
  3188. }
  3189. },
  3190. /**
  3191. * https://www.yunzhijia.com/imsdk/imcloud/js/imcloud.js
  3192. * 云之家消息组件集成
  3193. */
  3194. getIMCloudHubComponent: function(){
  3195. var _self = this;
  3196. shr.callService({
  3197. serviceName: 'getCloudHubParams',
  3198. async: true,
  3199. type: 'POST',
  3200. param: {},
  3201. success: function (response) {
  3202. if(!response.isShowCloudHub){
  3203. $('#loginCloudHub').hide();
  3204. $('.feedback-box').height(60);
  3205. $('.feedback-box .feedback-box-left i').css('marginTop','24px');
  3206. }
  3207. if(response.eid && response.data){
  3208. _self.initImCloud(response);
  3209. }
  3210. }
  3211. });
  3212. },
  3213. /**
  3214. * 导入
  3215. */
  3216. doImportData: function(curIOModelString, customData,classify,serviceId,permItemId,gridId) {
  3217. var self = shr.getCurrentViewPage();
  3218. if (typeof curIOModelString == 'undefined') {
  3219. curIOModelString = self.getImportModel();
  3220. }
  3221. var importDiv = $('#importDiv');
  3222. if (importDiv.length > 0) {
  3223. importDiv.data('curIOModelString', curIOModelString);
  3224. importDiv.data('customData', customData);
  3225. importDiv.data('classify', classify);
  3226. importDiv.dialog('open');
  3227. return;
  3228. }
  3229. // 未生成dialog
  3230. importDiv = $('<div id="importDiv"></div>').appendTo($('body'));
  3231. importDiv.data('curIOModelString', curIOModelString);
  3232. importDiv.data('customData', customData);
  3233. importDiv.data('classify', classify);
  3234. importDiv.data('serviceId', serviceId);
  3235. importDiv.data('permItemId', permItemId);
  3236. var _self = this;
  3237. // if(shr.checkCanUpload()){
  3238. importDiv.dialog({
  3239. autoOpen: true,
  3240. width: 708,
  3241. height: 700,
  3242. title: $.shrI18n.framework.title.importData,
  3243. resizable: true,
  3244. position: ['top','top'],
  3245. modal: true,
  3246. open: function(event, ui) {
  3247. if ($.browser.msie) {
  3248. var url = shr.assembleURL('com.kingdee.shr.io.app.ImportInfo', 'view', {
  3249. curIOModelString: curIOModelString,
  3250. customData: customData,
  3251. classify:classify,
  3252. serviceId:serviceId,
  3253. permItemId:permItemId
  3254. });
  3255. var content = '<iframe id="importFrame" name="importFrame" width="700" height="600" frameborder="0" scrolling="no" allowtransparency="true" src="' + url + '"></iframe>';
  3256. importDiv.append(content);
  3257. } else {
  3258. importDiv.css('padding', "0 20px");
  3259. var url = shr.assembleURL('com.kingdee.shr.io.app.ImportInfo$page', 'view');
  3260. shr.loadHTML({
  3261. url: url,
  3262. success: function(response) {
  3263. importDiv.append(response);
  3264. }
  3265. });
  3266. }
  3267. },
  3268. close: function(event, ui) {
  3269. importDiv.empty();
  3270. $(gridId).jqGrid("reloadGrid");
  3271. }
  3272. });
  3273. // }
  3274. $(".ui-dialog-titlebar-close").bind("click" , function(){
  3275. importDiv.dialog("close");
  3276. });
  3277. },
  3278. /**
  3279. * 组装 按钮数据权限 模型
  3280. */
  3281. getButtonDataPermissionModel:function(){
  3282. var model = [];
  3283. try {
  3284. if( jsBinder && jsBinder.assembleDataPermModel instanceof Function){
  3285. if( jsBinder.initData && jsBinder.initData.checkModel == "client" ){
  3286. model = jsBinder.assembleDataPermModel();
  3287. }
  3288. }
  3289. } catch (error) {// jsBinder 还没有生成,会异常,这里直接catch住,不处理
  3290. //console.warn("[ getButtonDataPermissionModel error ]");
  3291. }
  3292. return model;
  3293. },
  3294. addDataPermissionModel:function( data ){
  3295. if(data){
  3296. var dataPerm = this.getButtonDataPermissionModel();
  3297. if( dataPerm && dataPerm.length ){
  3298. data.dataPerm = shr.toJSON(dataPerm);
  3299. }
  3300. }
  3301. return data;
  3302. },
  3303. // 添加公共扩展参数
  3304. _addCommonExtParam:function( option ){
  3305. var data = option.data,ignoreDataPerm = false;
  3306. ignoreDataPerm = option.ignoreDataPerm;
  3307. // 添加按钮 数据 权限数据,如果忽略添加数据权限,不构造数据
  3308. if( !ignoreDataPerm ){
  3309. this.addDataPermissionModel( data );
  3310. // 客户端按钮数据权限,修改请求提交方式为POST,解决GET请求URL超长问题
  3311. option.type = 'POST';
  3312. }
  3313. if( data ){
  3314. var assigmentId = data['assigmentId'] || this.getAssignmentId();
  3315. data.assigmentId = assigmentId || "";
  3316. var ProcInstId = data['ProcInstId'] || this.getProcInstId();
  3317. data.ProcInstId = ProcInstId || "";
  3318. var msgId = data['msgId'] || this.getMsgId();
  3319. data.msgId = msgId || "";
  3320. }
  3321. // 添加权限项ID
  3322. this._addPermItemId( data );
  3323. //添加shruicode
  3324. this._addShruicode( data );
  3325. //添加uipk
  3326. this._addUipk(data);
  3327. //添加billId 工作流单据的所有单独请求都需要传入uipk,billId才能正确跳过数据验权
  3328. this._addBillId(data);
  3329. //添加附件fileUUID
  3330. this._addAttachmentFileUUID(data);
  3331. },
  3332. getProcInstId:function(){
  3333. var procInstId = shr.getUrlRequestParam('ProcInstId');
  3334. if(procInstId){
  3335. return procInstId;
  3336. }
  3337. procInstId = shr.getUrlRequestParam('proInstId');
  3338. if(procInstId){
  3339. return procInstId;
  3340. }
  3341. return '';
  3342. },
  3343. getMsgId:function(){
  3344. var msgId = shr.getUrlRequestParam('msgId');
  3345. if(msgId){
  3346. return msgId;
  3347. }
  3348. return '';
  3349. },
  3350. _addUipk:function(data){
  3351. if( data ){
  3352. var uipk = data['uipk'] || this.getUipk();
  3353. data.uipk = uipk || "";
  3354. }
  3355. },
  3356. getUipk:function(){
  3357. return shr.getUrlRequestParam('uipk');
  3358. },
  3359. _addShruicode:function(data){
  3360. if( data ){
  3361. var shruicode = data['shruicode'] || this.getShruicode();
  3362. data.shruicode = shruicode || "";
  3363. }
  3364. },
  3365. getShruicode:function(){
  3366. return shr.getUrlRequestParam('shruicode');
  3367. },
  3368. _addBillId:function(data){
  3369. if( data ){
  3370. var billId = data['billId'] || this.getBillId();
  3371. data.billId = billId || "";
  3372. }
  3373. },
  3374. getBillId:function(){
  3375. var billId = shr.getUrlRequestParam('billID');
  3376. if(!billId){
  3377. billId = shr.getUrlRequestParam('billId');
  3378. }
  3379. return billId;
  3380. },
  3381. _addPermItemId:function( data ){
  3382. if( data ){
  3383. // 优先获取button上的权限项ID, 如果获取button上的权限项ID为空 ,从url上获取
  3384. var permItemId = data['permItemId'] || this.getButtonPermItemId( data ) || this.getPermItemId();
  3385. data.permItemId = permItemId || "";
  3386. }
  3387. return data;
  3388. },
  3389. getButtonPermItemId:function( data ){
  3390. var permItemId = "", method = data.method;
  3391. if( method ){
  3392. try{
  3393. permItemId = $("#"+method).shrButton("getValue")["permItemId"];
  3394. }catch (error) {
  3395. }
  3396. }
  3397. return permItemId;
  3398. },
  3399. getPermItemId:function(_window){
  3400. var _win = _top;
  3401. if (_window) {
  3402. _win = _window;
  3403. }
  3404. return shr.getUrlRequestParam('permItemId', _win.location.href);
  3405. },
  3406. getCurrentPagePermItemId:function(){
  3407. var _permItemId = this.getCurrentPagePermItemIdByClient();
  3408. if(!_permItemId){
  3409. _permItemId = this.getCurrentPagePermItemIdByServer();
  3410. }
  3411. return _permItemId;
  3412. },
  3413. getCurrentPagePermItemIdByClient:function(){
  3414. var _permItemId = "";
  3415. try {
  3416. if( jsBinder && jsBinder.currentPagePermItemId ){
  3417. _permItemId = jsBinder.currentPagePermItemId;
  3418. }
  3419. } catch (error) {
  3420. }
  3421. return _permItemId;
  3422. },
  3423. getCurrentPagePermItemIdByServer:function(){
  3424. var _permItemId = "",
  3425. _uipk = shr.getUrlRequestParam("uipk") || "",
  3426. _method = shr.getUrlRequestParam("method") || "",
  3427. _permItemId = shr.getUrlRequestParam("permItemId") || "",
  3428. _serviceId = shr.getUrlRequestParam("serviceId") || "",
  3429. _shruicode = shr.getUrlRequestParam("shruicode") || "",
  3430. //应人事要求,从工作流过来的表单,如果们有method,并且url带有operateState,则将operateState小写作为method
  3431. _isShrBill = shr.getUrlRequestParam("isShrBill") || "";
  3432. if(_isShrBill && _isShrBill == 'true'){
  3433. var _operateState = shr.getUrlRequestParam("operateState");
  3434. if(_operateState && !_method){
  3435. _method = _operateState.toLowerCase();
  3436. }
  3437. }
  3438. shr.callService({
  3439. serviceName: 'getCurrentPagePermItemId',
  3440. param: {
  3441. uipk : _uipk,
  3442. methodName :_method,
  3443. permItemId :_permItemId,
  3444. serviceId :_serviceId,
  3445. shruicode:_shruicode
  3446. },
  3447. type: 'POST',
  3448. async: false,
  3449. success: function(data) {
  3450. _permItemId = data;
  3451. }
  3452. });
  3453. return _permItemId;
  3454. },
  3455. replaceAll:function( source,target,replacement ){
  3456. var reg = new RegExp(target,"g");
  3457. return source.replace(reg,replacement);
  3458. },
  3459. //获取浏览器缩放比例
  3460. detectZoom: function() {
  3461. var e = 0,
  3462. t = window.screen;
  3463. return (
  3464. void 0 !== window.devicePixelRatio
  3465. ? (e = window.devicePixelRatio)
  3466. : -1 !== navigator.userAgent.toLowerCase().indexOf('msie')
  3467. ? t.deviceXDPI && t.logicalXDPI && (e = t.deviceXDPI / t.logicalXDPI)
  3468. : void 0 !== window.outerWidth && void 0 !== window.innerWidth && (e = window.outerWidth / window.innerWidth),
  3469. e && (e = Math.round(100*e)),
  3470. (99 !== e && 101 !== e) || (e = 100),
  3471. e
  3472. )
  3473. },
  3474. /**
  3475. * 动态加载js、css文件
  3476. */
  3477. loadJsOrCssFile : function(filename, filetype){
  3478. if (filetype == "js"){
  3479. var fileref = document.createElement('script');
  3480. fileref.setAttribute("type","text/javascript");
  3481. fileref.setAttribute("src",filename);
  3482. } else if (filetype == "css"){
  3483. var fileref = document.createElement("link");
  3484. fileref.setAttribute("rel","stylesheet");
  3485. fileref.setAttribute("type","text/css");
  3486. fileref.setAttribute("href",filename);
  3487. }
  3488. if (typeof fileref != "undefined") document.getElementsByTagName("head")[0].appendChild(fileref);
  3489. },
  3490. /**
  3491. * 动态移除js、css文件
  3492. */
  3493. removeJsOrCssFile : function(filename,filetype){
  3494. var targetelement = (filetype == "js")? "script" :(filetype == "css")? "link" : "none";
  3495. var targetattr = (filetype == "js")?"src" : (filetype == "css")? "href" :"none";
  3496. var allsuspects = document.getElementsByTagName(targetelement);
  3497. for (var i = allsuspects.length; i >= 0;i--){
  3498. if (allsuspects[i] && allsuspects[i].getAttribute(targetattr) != null && allsuspects[i].getAttribute(targetattr).indexOf(filename)!=-1) allsuspects[i].parentNode.removeChild(allsuspects[i]);
  3499. }
  3500. },
  3501. /**
  3502. * 动态创建js、css文件
  3503. */
  3504. createJsOrCssFile : function (filename,filetype){
  3505. if (filetype=="js"){
  3506. var fileref=document.createElement('script')
  3507. fileref.setAttribute("type","text/javascript")
  3508. fileref.setAttribute("src",filename)
  3509. }
  3510. else if (filetype=="css"){
  3511. var fileref=document.createElement("link")
  3512. fileref.setAttribute("rel","stylesheet")
  3513. fileref.setAttribute("type","text/css")
  3514. fileref.setAttribute("href",filename)
  3515. }
  3516. return fileref
  3517. },
  3518. replaceJsOrCssFile : function (oldfilename,newfilename, filetype){
  3519. var targetelement=(filetype=="js")?"script" : (filetype=="css")? "link" :"none"
  3520. var targetattr=(filetype=="js")?"src" : (filetype=="css")? "href" :"none"
  3521. var allsuspects=document.getElementsByTagName(targetelement)
  3522. for (var i=allsuspects.length; i>=0;i--){
  3523. if (allsuspects[i] && allsuspects[i].getAttribute(targetattr)!=null &&allsuspects[i].getAttribute(targetattr).indexOf(oldfilename)!=-1){
  3524. var newelement=shr.createjscssfile(newfilename, filetype)
  3525. allsuspects[i].parentNode.replaceChild(newelement, allsuspects[i])
  3526. }
  3527. }
  3528. },
  3529. /**
  3530. * 获取一段字符串中,外部引入的js
  3531. */
  3532. getOutInputScripts: function (str) {
  3533. var html_pool = [];
  3534. var scripts = [];
  3535. var scriptText = '';
  3536. str = str.split(/<\/script>/i);
  3537. for (var i = 0; i < str.length; i++) {
  3538. html_pool[i] = str[i].replace(/<script[\s\S]*$/ig, "");
  3539. scripts[i] = {type: 'text/javascript', src: ''};
  3540. scriptText = str[i].substr(html_pool[i].length);
  3541. scripts[i].src = scriptText.substr(0, scriptText.indexOf('>') + 1);
  3542. scripts[i].src = scripts[i].src.match(/src\s*=\s*(\"([^\"]*)\"|\'([^\']*)\'|([^\s]*)[\s>])/i);
  3543. if(!scripts[i].src) {scripts.splice(i, 1);continue;}
  3544. if (scripts[i].src) {
  3545. if (scripts[i].src[2]) {
  3546. scripts[i].src = scripts[i].src[2];
  3547. }
  3548. else if (scripts[i].src[3]) {
  3549. scripts[i].src = scripts[i].src[3];
  3550. }
  3551. else if (scripts[i].src[4]) {
  3552. scripts[i].src = scripts[i].src[4];
  3553. }
  3554. else {
  3555. scripts[i].src = "";
  3556. }
  3557. }
  3558. }
  3559. return scripts;
  3560. },
  3561. formatMsg: function (){
  3562. // 数据长度为空,则直接返回
  3563. var result = '';
  3564. if (arguments.length == 0){
  3565. return result;
  3566. }
  3567. var str = arguments[0] ? arguments[0] : '';
  3568. var valArr = arguments[1] ? arguments[1] : [];
  3569. if(typeof str !== 'string' || Object.prototype.toString.call(valArr) !== '[object Array]'){
  3570. return result;
  3571. }
  3572. // 使用正则表达式,循环替换占位符数据
  3573. for (var i = 0; i < valArr.length; i++){
  3574. str = str.replace(new RegExp("\\{\\s*" + i + "\\s*\\}", "g"), valArr[i]);
  3575. }
  3576. result = str;
  3577. return result;
  3578. },
  3579. escapeSpecChar: function(srcString) {
  3580. // 转义之后的结果
  3581. var escapseResult = srcString;
  3582. // javascript正则表达式中的特殊字符
  3583. var jsSpecialChars = ["\\", "^", "$", "*", "?", ".", "+", "(", ")", "[",
  3584. "]", "|", "{", "}"];
  3585. // jquery中的特殊字符,不是正则表达式中的特殊字符
  3586. var jquerySpecialChars = ["~", "`", "@", "#", "%", "&", "=", "'", "\"",
  3587. ":", ";", "<", ">", ",", "/"];
  3588. for (var i = 0; i < jsSpecialChars.length; i++) {
  3589. escapseResult = escapseResult.replace(new RegExp("\\"
  3590. + jsSpecialChars[i], "g"), "\\"
  3591. + jsSpecialChars[i]);
  3592. }
  3593. for (var i = 0; i < jquerySpecialChars.length; i++) {
  3594. escapseResult = escapseResult.replace(new RegExp(jquerySpecialChars[i],
  3595. "g"), "\\" + jquerySpecialChars[i]);
  3596. }
  3597. return escapseResult;
  3598. },
  3599. isUndef: function(v) {
  3600. return v === undefined || v === null || v === "";
  3601. },
  3602. // 判断是否渲染了多页签
  3603. isRenderTabBar:function(){
  3604. return window._isTabBar === 'true' && $('#shrTabBar',top.document).length >0;
  3605. },
  3606. //获取assignmentID,提供公共方法进行调用
  3607. getAssignmentId: function (url) {
  3608. var assignID = shr.getUrlRequestParam("assignmentID", url);
  3609. if(!assignID){
  3610. assignID = shr.getUrlRequestParam("assignmentId", url);
  3611. }
  3612. if(!assignID){
  3613. assignID = shr.getUrlRequestParam("assigmentId", url);
  3614. }
  3615. return assignID;
  3616. },
  3617. isNoPermField: function(noPermFields, field){
  3618. if(null != noPermFields && noPermFields.length > 0){
  3619. for(var i=0;i<noPermFields.length;i++){
  3620. if(noPermFields[i].name == field) {
  3621. return true;
  3622. }
  3623. }
  3624. }
  3625. return false;
  3626. },
  3627. //是否无查看权限字段
  3628. isNoViewPermField: function (field) {
  3629. return this.isNoPermField(noPermFields, field);
  3630. },
  3631. //是否无编辑权限字段
  3632. isNoEditPermField: function (field) {
  3633. return this.isNoPermField(noEditPermFields, field);
  3634. },
  3635. /** 随机生成固定位数或者一定范围内的字符串数字组合
  3636. * @param {Number} min 范围最小值
  3637. * @param {Number} max 范围最大值,当不传递时表示生成指定位数的组合
  3638. * @param {String} charStr指定的字符串中生成组合
  3639. * @returns {String} 返回字符串结果
  3640. * */
  3641. randomRange: function(min, max, charStr){
  3642. var returnStr = "", //返回的字符串
  3643. range; //生成的字符串长度
  3644. //随机生成字符
  3645. var autoGetStr = function(){
  3646. var charFun = function(){
  3647. var n= Math.floor(Math.random()*62);
  3648. if(n<10){
  3649. return n; //1-10
  3650. }
  3651. else if(n<36){
  3652. return String.fromCharCode(n+55); //A-Z
  3653. }
  3654. else{
  3655. return String.fromCharCode(n+61); //a-z
  3656. }
  3657. }
  3658. while(returnStr.length< range){
  3659. returnStr += charFun();
  3660. }
  3661. };
  3662. //根据指定的字符串中生成组合
  3663. var accordCharStrGet = function(){
  3664. for(var i=0; i<range; i++){
  3665. var index = Math.round(Math.random() * (charStr.length-1));
  3666. returnStr += charStr.substring(index,index+1);
  3667. }
  3668. };
  3669. if(typeof min == 'undefined'){
  3670. min = 10;
  3671. }
  3672. if(typeof max == 'string'){
  3673. charStr = max;
  3674. }
  3675. range = ((max && typeof max == 'number') ? Math.round(Math.random() * (max-min)) + min : min);
  3676. if(charStr){
  3677. accordCharStrGet();
  3678. }else{
  3679. autoGetStr();
  3680. }
  3681. return returnStr;
  3682. },
  3683. //对象型数组根据对象的某个属性进行排序 type:默认是升序排序,传参DES则降序排列
  3684. compare: function(property, type) {
  3685. return function(a, b){
  3686. var value1 = a[property];
  3687. var value2 = b[property];
  3688. if(type == 'DES') {
  3689. return value2 - value1;
  3690. }else{
  3691. return value1 - value2;
  3692. }
  3693. }
  3694. },
  3695. //父界面直接调用jquery ui方法时,由于选择不同导致提示未初始化,所以采用增加方法的方式解决
  3696. setBreadcrumb: function(tabAndCard, switchNode) {
  3697. var breadcrumbItems = $('#breadcrumb').shrBreadcrumb('getItems');
  3698. var breadCrumbLocationTop = top.shr.getUrlRequestParam('breadCrumbLocationTop');
  3699. if(breadCrumbLocationTop == 'true') {
  3700. breadcrumbItems[0].location = 'top';
  3701. breadcrumbItems[1].location = 'top';
  3702. breadcrumbItems[2].location = 'top';
  3703. }
  3704. if(breadcrumbItems[0].location == undefined) {
  3705. breadcrumbItems[0].location = 'top';
  3706. if(tabAndCard) {
  3707. breadcrumbItems.splice(1, 0, tabAndCard.tabs);
  3708. breadcrumbItems.splice(2, 0, {url: parent.window.location + '&index=1', name: tabAndCard.cards.name, location: 'top'});
  3709. }
  3710. if(breadcrumbItems.length > 4 && switchNode) {
  3711. breadcrumbItems.splice(3, breadcrumbItems.length - 4);
  3712. }else if(breadcrumbItems.length > 5) {
  3713. breadcrumbItems.splice(3, breadcrumbItems.length - 5);
  3714. }
  3715. }else{
  3716. breadcrumbItems[0].location = 'top';
  3717. if(tabAndCard) {
  3718. if(breadcrumbItems[2].name != tabAndCard['cards'].name) {
  3719. breadcrumbItems.splice(2, 0, {url: parent.window.location + '&index=1', name: tabAndCard.cards.name, location: 'top'});
  3720. }
  3721. }
  3722. if(breadcrumbItems.length > 4 && switchNode) {
  3723. breadcrumbItems.splice(3, breadcrumbItems.length - 4);
  3724. }else if(breadcrumbItems.length > 5) {
  3725. breadcrumbItems.splice(3, breadcrumbItems.length - 5);
  3726. }
  3727. }
  3728. $('#breadcrumb').shrBreadcrumb('setItems', breadcrumbItems);
  3729. },
  3730. /**
  3731. * 适配OSF响应数据格式
  3732. */
  3733. adapteOSFResponseDataFormat: function( obj ) {
  3734. var returnObject = obj;
  3735. if( shr.isStandardOSFResponseFormatByResponseData( obj ) ) {
  3736. if(obj['errCode'] ==0){
  3737. if(obj['_e_x_t_d_'] && obj['_e_x_t_d_']['_e_s_k_'] && obj['_e_x_t_d_']['_d_k_']){
  3738. var esk = shr.decryptForAes_CBC(obj['_e_x_t_d_']['_e_s_k_'],obj['_e_x_t_d_']['_d_k_']);
  3739. returnObject = shr.decryptForAes_CBC(obj.data,esk);
  3740. }else{
  3741. returnObject = JSON.stringify( obj.data );
  3742. }
  3743. }else{
  3744. returnObject = null;
  3745. shr.showError({message: obj['errMsg']});
  3746. }
  3747. }
  3748. return returnObject;
  3749. },
  3750. isStandardOSFResponseFormatByResponseData: function( responseDataObject ) {
  3751. if( !$.isPlainObject( responseDataObject ) ) {
  3752. return false ;
  3753. }
  3754. // attribute list
  3755. var standardOSFResponseObjectProperties = ['errCode','bizCode','data','errMsg','_e_x_t_d_'];
  3756. for( var property in standardOSFResponseObjectProperties ) {
  3757. if( !responseDataObject.hasOwnProperty( standardOSFResponseObjectProperties[property] ) ) {
  3758. return false;
  3759. }
  3760. }
  3761. return true;
  3762. },
  3763. generateOSFSignature: function(openServiceUrl){
  3764. return shr.encryptForAes_CBC(openServiceUrl+','+Math.floor(Math.random() * (50000 - 1) + 1)+','+new Date().getTime());
  3765. },
  3766. /**
  3767. * 图片预览
  3768. * url: 需要预览图片的src,如果不存在url可以直接传null
  3769. * $picArr: 需要预览图片的jquery对象集合
  3770. */
  3771. previewPic: function(url, $picArr) {
  3772. var $topBody = $(window.top.document.body);
  3773. if(!url) {
  3774. $picArr.on('click', function() {
  3775. var index = getPreviewImgIndex($(this).attr('src'));
  3776. $topBody.append(getPicTemplate($(this).attr('src'), index));
  3777. $topBody.find('.zoomableContainer').data('imgArr', $picArr);
  3778. $topBody.find('.zoomableContainer').css('top', window.top.document.documentElement.scrollTop);
  3779. $topBody.css({'overflow': 'hidden'});
  3780. $topBody.css({'top': $(_top.document).scrollTop()});
  3781. previewPicListener();
  3782. });
  3783. }else{
  3784. $topBody.append(getPicTemplate(url));
  3785. }
  3786. var getPicTemplate = function(url, index) {
  3787. var picPreview = [
  3788. '<div class="zoomableContainer" style="width:100%;height:100%;position: absolute;top: 0;z-index: 9999;background-color: rgba(0, 0, 0, 0.7);text-align: center;">',
  3789. '<img id="previewClose" src="/shr/styles/images/attachment-icon-close.png" style="position: absolute;top: 25px;right: 30px;cursor:pointer;z-index: 99999">',
  3790. '<div style="margin:auto;width: 100%;height: 100%;overflow: hidden;justify-content: center;align-items: center;display: flex;position: relative;">',
  3791. '<img id="preViewImg" imgIndex="' + index + '" src="' + url + '" style="width: auto;transform: translate3d(0px, 0px, 0px) scale3d(1, 1, 1);position: absolute;cursor: move;">',
  3792. '</div>',
  3793. '<div class="bottomBtn" style="margin-top: 15px;position: absolute;left: calc(50% - 120px);bottom: 15px;">',
  3794. '<img id="previewPrev" src="/shr/styles/images/attachment_prev.png" style="cursor:pointer;">',
  3795. '<img id="previewDownload" src="/shr/styles/images/attachment_enlarge.png" style="cursor:pointer;margin-left: 20px;margin-right: 20px;">',
  3796. '<img id="previewRotate" src="/shr/styles/images/attachment_rotate.png" style="cursor:pointer;margin-left: 20px;margin-right: 20px;">',
  3797. '<img id="previewOrigin" src="/shr/styles/images/attachment_narrow.png" style="cursor:pointer;margin-left: 20px;margin-right: 20px;">',
  3798. '<img id="previewNext" src="/shr/styles/images/attachment_next.png" style="cursor:pointer;">',
  3799. '</div>',
  3800. '</div>'
  3801. ];
  3802. return picPreview.join('');
  3803. };
  3804. var previewPicListener = function() {
  3805. //放大
  3806. var $topBody = $(window.top.document.body);
  3807. var $preViewImg = $topBody.find('#preViewImg');
  3808. var imgArr = $topBody.find('.zoomableContainer').data('imgArr');
  3809. $topBody.find('#previewDownload').on('click', function(){
  3810. var scale = getPreviewPicScale();
  3811. var deg = getPreviewPicDeg();
  3812. $preViewImg.css('transform', 'translate3d(0px, 0px, 0px) scale3d(' + 1.2 * scale + ', ' + 1.2 * scale + ', 1) rotate(' + deg + 'deg)');
  3813. })
  3814. //翻转图片
  3815. $topBody.find('#previewRotate').on('click', function(){
  3816. var scale = getPreviewPicScale();
  3817. if(getPreviewPicDeg() == 0) {
  3818. $preViewImg.css('transform', 'translate3d(0px, 0px, 0px) scale3d(' + scale + ', ' + scale + ', 1) rotate(90deg)');
  3819. return;
  3820. }
  3821. if(getPreviewPicDeg() == 90) {
  3822. $preViewImg.css('transform', 'translate3d(0px, 0px, 0px) scale3d(' + scale + ', ' + scale + ', 1) rotate(180deg)');
  3823. return;
  3824. }
  3825. if(getPreviewPicDeg() == 180) {
  3826. $preViewImg.css('transform', 'translate3d(0px, 0px, 0px) scale3d(' + scale + ', ' + scale + ', 1) rotate(270deg)');
  3827. return;
  3828. }
  3829. if(getPreviewPicDeg() == -90) {
  3830. $preViewImg.css('transform', 'translate3d(0px, 0px, 0px) scale3d(' + scale + ', ' + scale + ', 1) rotate(0deg)');
  3831. return;
  3832. }
  3833. })
  3834. //缩小
  3835. $topBody.find('#previewOrigin').on('click', function(){
  3836. var scale = getPreviewPicScale();
  3837. var deg = getPreviewPicDeg();
  3838. $preViewImg.css('transform', 'translate3d(0px, 0px, 0px) scale3d(' + 0.8 * scale + ', ' + 0.8 * scale + ', 1) rotate(' + deg + 'deg)');
  3839. })
  3840. $topBody.find('#previewClose').on('click', function(){
  3841. $topBody.css({'overflow': 'auto'});
  3842. $topBody.find('#previewClose').parent().remove();
  3843. })
  3844. //上一张
  3845. $topBody.find('#previewPrev').on('click', function(){
  3846. var index = parseInt($preViewImg.attr('imgindex'));
  3847. if(index == imgArr.length - 1) {
  3848. $topBody.find('#previewNext').attr('src', '/shr/styles/images/attachment_next.png')
  3849. }
  3850. if(index == 1) {
  3851. $(this).attr('src', '/shr/styles/images/attachment_prev_disable.png')
  3852. }
  3853. if(index == 0) return;
  3854. $preViewImg.attr('src', $(imgArr[index - 1]).attr('src'));
  3855. $preViewImg.attr('imgindex', index - 1);
  3856. });
  3857. //下一张
  3858. $topBody.find('#previewNext').on('click', function(){
  3859. var index = parseInt($preViewImg.attr('imgindex'));
  3860. if(index == 0) {
  3861. $topBody.find('#previewPrev').attr('src', '/shr/styles/images/attachment_prev.png')
  3862. }
  3863. if(index == imgArr.length - 2) {
  3864. $(this).attr('src', '/shr/styles/images/attachment_next_disable.png')
  3865. }
  3866. if(index == imgArr.length - 1) return;
  3867. $preViewImg.attr('src', $(imgArr[index + 1]).attr('src'));
  3868. $preViewImg.attr('imgindex', index + 1);
  3869. });
  3870. //拖动图片
  3871. var canMove = false;
  3872. var dragX, dragY;
  3873. $preViewImg.on('mousedown', function(e) {
  3874. e.preventDefault()
  3875. canMove = true;
  3876. dragX = e.clientX - $preViewImg[0].offsetLeft;
  3877. dragY = e.clientY - $preViewImg[0].offsetTop;
  3878. });
  3879. $preViewImg.on('mousemove', function(e) {
  3880. e.preventDefault()
  3881. if(canMove) {
  3882. var left = e.clientX - dragX;
  3883. var top = e.clientY - dragY;
  3884. }
  3885. if(left < 0) {
  3886. left = left;
  3887. }else if(left > _top.window.innerWidth - $preViewImg[0].offsetWidth) {
  3888. left = left;
  3889. }
  3890. if(top < 0) {
  3891. top = top;
  3892. }else if(top > _top.window.innerHeight - $preViewImg[0].offsetHeight) {
  3893. top = top;
  3894. }
  3895. $preViewImg.css({
  3896. left: left + 'px',
  3897. top: top + 'px'
  3898. });
  3899. });
  3900. $preViewImg.on('mouseup', function(e) {
  3901. e.preventDefault()
  3902. canMove = false;
  3903. });
  3904. //滑动滚轮实现图片的放大和缩小
  3905. $preViewImg.on("mousewheel", function (e) {
  3906. e.preventDefault();
  3907. var deg = getPreviewPicDeg();
  3908. var scale = getPreviewPicScale();
  3909. var del = 0;
  3910. if(e.originalEvent.wheelDelta) {
  3911. del = e.originalEvent.wheelDelta;
  3912. }else if(e.originalEvent.detail) {
  3913. del = e.originalEvent.detail * -1;
  3914. }
  3915. if(del > 0) {
  3916. // 放大
  3917. $preViewImg.css('transform', 'translate3d(0px, 0px, 0px) scale3d(' + 1.2 * scale + ', ' + 1.2 * scale + ', 1) rotate(' + deg + 'deg)');
  3918. }else if(del < 0) {
  3919. // 缩小
  3920. $preViewImg.css('transform', 'translate3d(0px, 0px, 0px) scale3d(' + 0.8 * scale + ', ' + 0.8 * scale + ', 1) rotate(' + deg + 'deg)');
  3921. }
  3922. });
  3923. };
  3924. //获取图片当前的旋转角度
  3925. var getPreviewPicDeg = function() {
  3926. var $topBody = $(window.top.document.body);
  3927. var $preViewImg = $topBody.find('#preViewImg');
  3928. var values = $preViewImg.css('transform').split('(')[1].split(')')[0].split(',');
  3929. var deg = Math.round(Math.atan2(values[1], values[0]) * (180 / Math.PI));
  3930. return deg;
  3931. };
  3932. //获取图片当前的放大或者缩小值
  3933. var getPreviewPicScale = function() {
  3934. var $topBody = $(window.top.document.body);
  3935. var $preViewImg = $topBody.find('#preViewImg');
  3936. var values = $preViewImg.css('transform').split('(')[1].split(')')[0].split(',');
  3937. var scale = Math.sqrt(values[0] * values[0] + values[1] * values[1]);
  3938. return scale;
  3939. };
  3940. //获取点击预览时的图片数组下标
  3941. var getPreviewImgIndex = function(src) {
  3942. var imgArr = $picArr;
  3943. var index = 0;
  3944. for(var i = 0;i < imgArr.length;i++) {
  3945. if(src == $(imgArr[i]).attr('src')) {
  3946. index = i;
  3947. break;
  3948. }
  3949. }
  3950. return index;
  3951. };
  3952. }
  3953. });
  3954. /**
  3955. * jQuery JSON Plugin
  3956. * version: 2.3 (2011-09-17)
  3957. *
  3958. * This document is licensed as free software under the terms of the
  3959. * MIT License: http://www.opensource.org/licenses/mit-license.php
  3960. *
  3961. * Brantley Harris wrote this plugin. It is based somewhat on the JSON.org
  3962. * website's http://www.json.org/json2.js, which proclaims:
  3963. * "NO WARRANTY EXPRESSED OR IMPLIED. USE AT YOUR OWN RISK.", a sentiment that
  3964. * I uphold.
  3965. *
  3966. * It is also influenced heavily by MochiKit's serializeJSON, which is
  3967. * copyrighted 2005 by Bob Ippolito.
  3968. */
  3969. (function( $ ) {
  3970. var escapeable = /["\\\x00-\x1f\x7f-\x9f]/g,
  3971. meta = {
  3972. '\b': '\\b',
  3973. '\t': '\\t',
  3974. '\n': '\\n',
  3975. '\f': '\\f',
  3976. '\r': '\\r',
  3977. '"' : '\\"',
  3978. '\\': '\\\\'
  3979. };
  3980. $.ajaxSetup({
  3981. // add ext RequestHeader For OSF request.
  3982. beforeSend: function( jqXHR,ajaxOptions ) {
  3983. // if current request is OSF Request, then check adapteOSFResponseDataFormat. default value is true;
  3984. // if you want to use standard response data format ,then set options.adapteOSFResponseDataFormat = false;
  3985. var adapteOSFResponseDataFormat = ( ajaxOptions && ajaxOptions.adapteOSFResponseDataFormat ) ? ajaxOptions.adapteOSFResponseDataFormat : true;
  3986. var openServiceUrl = shr.getOpenServiceFullPath() ;
  3987. var _requsetUrl = ajaxOptions.url ;
  3988. var isOSFRequest = ( _requsetUrl && _requsetUrl.indexOf(openServiceUrl) >= 0 ) ? true : false ;
  3989. var isGetTreeDataURL = ( _requsetUrl && _requsetUrl.indexOf(shr.getTreeDataURL) >= 0 ) ? true : false ;
  3990. function getOSFReqHeaderSignature(ajaxOptions){
  3991. }
  3992. // set ajaxOptions.adapteOSFResponseDataFormat
  3993. ajaxOptions.adapteOSFResponseDataFormat = adapteOSFResponseDataFormat;
  3994. ajaxOptions.isOSFRequest = isOSFRequest;
  3995. if( isOSFRequest ) {
  3996. jqXHR.adapteOSFResponseDataFormat = adapteOSFResponseDataFormat;
  3997. jqXHR.isOSFRequest = isOSFRequest;
  3998. jqXHR.setRequestHeader("X-OSF-Signature", shr.generateOSFSignature(openServiceUrl));
  3999. }
  4000. if(isGetTreeDataURL){
  4001. jqXHR.setRequestHeader("x-shr-encrypt-F7", shr.getXShrEncryptF7Value());
  4002. }
  4003. },
  4004. // adapte OSF Response Data by extend dataFilter.
  4005. dataFilter: function( data, dataType ) {
  4006. var _options = this,jsonObj;
  4007. // if not OSFRequest, return original data
  4008. if( !( _options && _options.isOSFRequest ) ){
  4009. return data ;
  4010. }
  4011. if( _options && _options.adapteOSFResponseDataFormat ) {
  4012. if( data ){
  4013. jsonObj = ( shr.isJSON(data)) ? JSON.parse( data ) : data ;
  4014. // Judgment base on results
  4015. // need Judgment dataType,here is JSON Type, maybe text,xml and so on. to do other Logic .........
  4016. return shr.isStandardOSFResponseFormatByResponseData( jsonObj ) ? shr.adapteOSFResponseDataFormat( jsonObj ) : data;
  4017. }
  4018. }else{
  4019. return data;
  4020. }
  4021. }
  4022. });
  4023. /**
  4024. * jQuery.toJSON
  4025. * Converts the given argument into a JSON respresentation.
  4026. *
  4027. * @param o {Mixed} The json-serializble *thing* to be converted
  4028. *
  4029. * If an object has a toJSON prototype, that will be used to get the representation.
  4030. * Non-integer/string keys are skipped in the object, as are keys that point to a
  4031. * function.
  4032. *
  4033. */
  4034. $.toJSON = typeof JSON === 'object' && JSON.stringify
  4035. ? JSON.stringify
  4036. : function( o ) {
  4037. if ( o === null ) {
  4038. return 'null';
  4039. }
  4040. var type = typeof o;
  4041. if ( type === 'undefined' ) {
  4042. return undefined;
  4043. }
  4044. if ( type === 'number' || type === 'boolean' ) {
  4045. return '' + o;
  4046. }
  4047. if ( type === 'string') {
  4048. return $.quoteString( o );
  4049. }
  4050. if ( type === 'object' ) {
  4051. if ( typeof o.toJSON === 'function' ) {
  4052. return $.toJSON( o.toJSON() );
  4053. }
  4054. if ( o.constructor === Date ) {
  4055. var month = o.getUTCMonth() + 1,
  4056. day = o.getUTCDate(),
  4057. year = o.getUTCFullYear(),
  4058. hours = o.getUTCHours(),
  4059. minutes = o.getUTCMinutes(),
  4060. seconds = o.getUTCSeconds(),
  4061. milli = o.getUTCMilliseconds();
  4062. if ( month < 10 ) {
  4063. month = '0' + month;
  4064. }
  4065. if ( day < 10 ) {
  4066. day = '0' + day;
  4067. }
  4068. if ( hours < 10 ) {
  4069. hours = '0' + hours;
  4070. }
  4071. if ( minutes < 10 ) {
  4072. minutes = '0' + minutes;
  4073. }
  4074. if ( seconds < 10 ) {
  4075. seconds = '0' + seconds;
  4076. }
  4077. if ( milli < 100 ) {
  4078. milli = '0' + milli;
  4079. }
  4080. if ( milli < 10 ) {
  4081. milli = '0' + milli;
  4082. }
  4083. return '"' + year + '-' + month + '-' + day + 'T' +
  4084. hours + ':' + minutes + ':' + seconds +
  4085. '.' + milli + 'Z"';
  4086. }
  4087. if ( o.constructor === Array ) {
  4088. var ret = [];
  4089. for ( var i = 0; i < o.length; i++ ) {
  4090. ret.push( $.toJSON( o[i] ) || 'null' );
  4091. }
  4092. return '[' + ret.join(',') + ']';
  4093. }
  4094. var name,
  4095. val,
  4096. pairs = [];
  4097. for ( var k in o ) {
  4098. type = typeof k;
  4099. if ( type === 'number' ) {
  4100. name = '"' + k + '"';
  4101. } else if (type === 'string') {
  4102. name = $.quoteString(k);
  4103. } else {
  4104. // Keys must be numerical or string. Skip others
  4105. continue;
  4106. }
  4107. type = typeof o[k];
  4108. if ( type === 'function' || type === 'undefined' ) {
  4109. // Invalid values like these return undefined
  4110. // from toJSON, however those object members
  4111. // shouldn't be included in the JSON string at all.
  4112. continue;
  4113. }
  4114. val = $.toJSON( o[k] );
  4115. pairs.push( name + ':' + val );
  4116. }
  4117. return '{' + pairs.join( ',' ) + '}';
  4118. }
  4119. };
  4120. /**
  4121. * jQuery.evalJSON
  4122. * Evaluates a given piece of json source.
  4123. *
  4124. * @param src {String}
  4125. */
  4126. $.evalJSON = typeof JSON === 'object' && JSON.parse
  4127. ? JSON.parse
  4128. : function( src ) {
  4129. return eval('(' + src + ')');
  4130. };
  4131. /**
  4132. * jQuery.secureEvalJSON
  4133. * Evals JSON in a way that is *more* secure.
  4134. *
  4135. * @param src {String}
  4136. */
  4137. $.secureEvalJSON = typeof JSON === 'object' && JSON.parse
  4138. ? JSON.parse
  4139. : function( src ) {
  4140. var filtered =
  4141. src
  4142. .replace( /\\["\\\/bfnrtu]/g, '@' )
  4143. .replace( /"[^"\\\n\r]*"|true|false|null|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?/g, ']')
  4144. .replace( /(?:^|:|,)(?:\s*\[)+/g, '');
  4145. if ( /^[\],:{}\s]*$/.test( filtered ) ) {
  4146. return eval( '(' + src + ')' );
  4147. } else {
  4148. throw new SyntaxError( 'Error parsing JSON, source is not valid.' );
  4149. }
  4150. };
  4151. /**
  4152. * jQuery.quoteString
  4153. * Returns a string-repr of a string, escaping quotes intelligently.
  4154. * Mostly a support function for toJSON.
  4155. * Examples:
  4156. * >>> jQuery.quoteString('apple')
  4157. * "apple"
  4158. *
  4159. * >>> jQuery.quoteString('"Where are we going?", she asked.')
  4160. * "\"Where are we going?\", she asked."
  4161. */
  4162. $.quoteString = function( string ) {
  4163. if ( string.match( escapeable ) ) {
  4164. return '"' + string.replace( escapeable, function( a ) {
  4165. var c = meta[a];
  4166. if ( typeof c === 'string' ) {
  4167. return c;
  4168. }
  4169. c = a.charCodeAt();
  4170. return '\\u00' + Math.floor(c / 16).toString(16) + (c % 16).toString(16);
  4171. }) + '"';
  4172. }
  4173. return '"' + string + '"';
  4174. };
  4175. $.getUrlParam = function(name){
  4176. var reg = new RegExp("(^|&)"+ name +"=([^&]*)(&|$)");
  4177. var r = window.location.search.substr(1).match(reg);
  4178. // if (r!=null) return unescape(r[2]); return null;
  4179. if (r!=null) return decodeURIComponent(r[2]); return null;
  4180. }
  4181. })( jQuery );
  4182. /**
  4183. * 打开滚动条
  4184. * @param type
  4185. */
  4186. function openLoader(type, tip) {
  4187. if(!type) type = 1;
  4188. $("#loaderTip", _top.document).text(tip ? tip : $("#loaderTip" + type, _top.document).text());
  4189. $("#loader", _top.document).show().css("display", "block");
  4190. }
  4191. /**
  4192. * JSON转化时,对循环结构的转化则会出错
  4193. * 解决方法:避免对循环结构进行转化
  4194. */
  4195. JSON.stringifyOnce = function(obj, replacer, indent){
  4196. var printedObjects = [];
  4197. var printedObjectKeys = [];
  4198. function printOnceReplacer(key, value){
  4199. if ( printedObjects.length > 20000){
  4200. return 'object too long';
  4201. }
  4202. var printedObjIndex = false;
  4203. printedObjects.forEach(function(obj, index){
  4204. if(obj===value){
  4205. printedObjIndex = index;
  4206. }
  4207. });
  4208. if ( key == ''){
  4209. printedObjects.push(obj);
  4210. printedObjectKeys.push("root");
  4211. return value;
  4212. } else if (printedObjIndex+"" != "false" && typeof(value)=="object"){
  4213. if ( printedObjectKeys[printedObjIndex] == "root"){
  4214. return "(pointer to root)";
  4215. }else{
  4216. return "(see " + ((!!value && !!value.constructor) ? value.constructor.name.toLowerCase() : typeof(value)) + " with key " + printedObjectKeys[printedObjIndex] + ")";
  4217. }
  4218. } else {
  4219. var qualifiedKey = key || "(empty key)";
  4220. printedObjects.push(value);
  4221. printedObjectKeys.push(qualifiedKey);
  4222. if(replacer){
  4223. return replacer(key, value);
  4224. }else{
  4225. return value;
  4226. }
  4227. }
  4228. }
  4229. return JSON.stringify(obj, printOnceReplacer, indent);
  4230. };
  4231. /**
  4232. * 关闭滚动条
  4233. */
  4234. function closeLoader() {
  4235. $("#loader", _top.document).hide().css("display", "none");
  4236. }
  4237. $(document).ready(function() {
  4238. if(!window.console) {console={}; console.log = function(){};}
  4239. if ($.browser.msie && $.browser.version < 9) {
  4240. window.location.href = "browser/browser.html";
  4241. }
  4242. _top = getTop();
  4243. // IE9 support (input, textarea tag) placeholder attribute, use jQuery Placeholder Plugin v2.3.1
  4244. var textElements = $('input, textarea');
  4245. if( textElements && textElements.placeholder ){
  4246. try {
  4247. textElements.placeholder();
  4248. } catch (error) {
  4249. console.log( " placeholder init error " );
  4250. }
  4251. }
  4252. if(window.localStorage.getItem('screenModel') == 'true') {
  4253. $('#castScreenModel a').text($.shrI18n.common.screenModel.standScreenModel);
  4254. shr.loadCss('/shr/styles/castScreenModel.css');
  4255. }
  4256. // 使用节流函数来监听页面的缩放,间隔时间可自行设置,防止每次滚动实时监听导致卡顿。(当浏览器宽度小于1200时,不建议用户使用,当浏览器缩放时,提示用户复原)
  4257. // 并且增加“不再提醒”功能,如果用户点击了不再提醒,则通过localStorage存一个标识,和账号绑定,即该账号不会在当前设备上提示。
  4258. // 增加一个判断,当有些页面没有用户id时,则不进行缩放监听。
  4259. // var isScading = shr.getUserInfo().id;
  4260. // if (isScading) {
  4261. // try{
  4262. // var isPrompts = localStorage.getItem(isScading + '#ScreenZoom');
  4263. // if (!isPrompts) {
  4264. // addWindowResize();
  4265. // $(top.window).off('resize', throttle(addWindowResize, 500)).on('resize', throttle(addWindowResize, 500));
  4266. // }
  4267. // } catch (error){
  4268. // console.log(error);
  4269. // }
  4270. // }
  4271. $(document).on('click', function(e) {
  4272. if(e.target.className != 'parallelNodeNum' && e.target.className != 'rateProgress' && e.target.className != 'rateProgressImg') {
  4273. $(window.parent.document).find('.parallelNode').hide();
  4274. $(window.parent.document).find('.rateProgressToolsDiv').hide();
  4275. }
  4276. });
  4277. //console.log($('#breadcrumb').shrBreadcrumb('getItems'));
  4278. });
  4279. function addWindowResize() {
  4280. try{
  4281. // 再次增加一个判断,如果点了不再提醒,则直接返回
  4282. var isPrompts = localStorage.getItem(shr.getUserInfo().id + '#ScreenZoom');
  4283. if (isPrompts) {
  4284. return
  4285. }
  4286. var currentZoom = shr.detectZoom();
  4287. // 当缩放比例大于150或者小于100时,和当浏览器宽度小于1200时,提示!
  4288. if(currentZoom < 100 || currentZoom > 150 ) {
  4289. shr.showMaskWarning({
  4290. message: $.shrI18n.common.tips.screenZoom
  4291. });
  4292. } else if ($(top.window).width() < 1200) {
  4293. shr.showMaskWarning({
  4294. message: $.shrI18n.common.tips.screenWidth
  4295. });
  4296. }
  4297. } catch (error){
  4298. console.log(error);
  4299. }
  4300. }
  4301. // 节流函数,防止频繁触发,可以通过时间间隔来控制触发的间隔,即在规定时间间隔内只会触发一次。
  4302. function throttle(callback,delay){
  4303. var timer,
  4304. begin = new Date();
  4305. return function(){
  4306. var current = new Date();
  4307. clearTimeout(timer);
  4308. if(current - begin >= delay){
  4309. callback();
  4310. begin = current;
  4311. }else{
  4312. timer = setTimeout(function() {
  4313. callback();
  4314. },delay);
  4315. }
  4316. }
  4317. }
  4318. //内嵌入EAS页面时,改变Top指向
  4319. function getTop(){
  4320. // 当shr单据在门户中打开时,嵌套在iframe id='bill-frame'中,iframe的创建过程参考门户工作流 approve.js 492行
  4321. // shr单据在门户中打开时,从8.5版本发生变化,对应id为:$(".portal-page","#pageContainer").not(".hide").attr("id"); update by tiangang_yang 2018/03/07
  4322. // shr单据在门户中打开时,从8.5版本发生变化,根据class='portal-page'来获取; update by tiangang_yang 2018/06/25
  4323. return isFromPortal()?window:top;
  4324. }
  4325. function isFromPortal(){
  4326. var billFrame = (frameElement && (frameElement.getAttribute("id") == "bill-frame" || frameElement.getAttribute("id") == "billFrame"));
  4327. if(billFrame){
  4328. return frameElement;
  4329. }
  4330. //兼容portal-page
  4331. var billFrame2 = (frameElement && frameElement.getAttribute("class") == "portal-page");
  4332. if(billFrame2){
  4333. return billFrame2;
  4334. }
  4335. var billFrames = $(".portal-page","#pageContainer").not(".hide");
  4336. if(billFrames && billFrames.length >= 1){
  4337. return billFrames[0];
  4338. }
  4339. // 兼容bos的85版本新流程中心iframe的id改动,增加按proInstId参数判断 by wei_yw_yang 2019/11/12
  4340. var src = frameElement && frameElement.getAttribute("src");
  4341. var billFrame3 = (src && src.indexOf('&proInstId=') != -1);
  4342. if(billFrame3){
  4343. return billFrame3;
  4344. }
  4345. return null;
  4346. }
  4347. /**
  4348. * 描述:重写namedItem方法,解决IE下由于ID大小写问题导致窜行的问题。
  4349. * @author BJJLG
  4350. * @class
  4351. * @constructor
  4352. * @return
  4353. */
  4354. if (window.HTMLCollection){
  4355. HTMLCollection.prototype.namedItem = function(name){
  4356. var len = this.length,ret = null;
  4357. if(len>0){
  4358. for(var i=0;i<len;i++){
  4359. if(this[i].id && this[i].id == name){
  4360. ret = this[i];
  4361. break;
  4362. }
  4363. }
  4364. }
  4365. return ret;
  4366. }
  4367. }
  4368. //进入全屏
  4369. function enterfullscreen() {
  4370. var docElm = document.documentElement;
  4371. var requestMethod = docElm.requestFullScreen || //W3C
  4372. docElm.webkitRequestFullScreen || //FireFox
  4373. docElm.mozRequestFullScreen || //Chrome等
  4374. docElm.msRequestFullscreen; //IE11
  4375. if (requestMethod) {
  4376. requestMethod.call(docElm);
  4377. } else if (typeof window.ActiveXObject !== "undefined") {
  4378. var wscript = new ActiveXObject("WScript.Shell");
  4379. if (wscript !== null) {
  4380. wscript.SendKeys("{F11}");
  4381. }
  4382. }
  4383. }
  4384. function exitfullscreen() {
  4385. // 判断各种浏览器,找到正确的方法
  4386. var exitMethod = document.exitFullscreen || //W3C
  4387. document.mozCancelFullScreen || //FireFox
  4388. document.webkitExitFullscreen || //Chrome等
  4389. document.msExitFullscreen; //IE11
  4390. if (exitMethod) {
  4391. exitMethod.call(document);
  4392. } else if (typeof window.ActiveXObject !== "undefined") { //for Internet Explorer
  4393. var wscript = new ActiveXObject("WScript.Shell");
  4394. if (wscript !== null) {
  4395. wscript.SendKeys("{F11}");
  4396. }
  4397. }
  4398. }
  4399. function checkFull() {
  4400. return document.fullscreenElement ||
  4401. document.msFullscreenElement ||
  4402. document.mozFullScreenElement ||
  4403. document.webkitFullscreenElement;
  4404. }
  4405. /**
  4406. * 描述:重写Date,处理在不同时区的时候用中国时间格式横杆少一天,员工离职页点离职日期可以重现
  4407. */
  4408. try {
  4409. if(Intl && Intl.DateTimeFormat().resolvedOptions().timeZone != 'Asia/Shanghai'){
  4410. var OldDate = Date;
  4411. // 重写arguments[0]
  4412. Date = function () {
  4413. var datePattern = /^\d{4}-\d{2}-\d{2}$/;
  4414. // 检查日期字符串是否符合格式
  4415. var p = '';
  4416. // IOS环境,时间转化的问题,现在没有客户反馈暂时先不处理
  4417. // if (navigator.userAgent.includes('iPhone') || navigator.userAgent.includes('iPad')) {
  4418. // if (arguments.length > 0 && typeof (arguments[0]) === 'string' && arguments[0].includes('-')) {
  4419. // p = arguments[0].replace(/-/g, '/');
  4420. // arguments[0] = p;
  4421. // }
  4422. // }
  4423. if (arguments.length > 0 && typeof (arguments[0]) === 'string' && arguments[0].indexOf('-') >= 0 && datePattern.test(arguments[0])) {
  4424. //p = arguments[0] + ' 00:00:00'; IE不兼容这种写法
  4425. p = arguments[0].replace(/-/g, '/');
  4426. arguments[0] = p;
  4427. }
  4428. var arr = Array.prototype.slice.call(arguments);
  4429. var str = '';
  4430. if(arr.length == 1){
  4431. return new OldDate(arr[0]);
  4432. }else{
  4433. str = arr.join(',');
  4434. return eval('new OldDate(' + str + ')');
  4435. }
  4436. }
  4437. // 继承原型函数
  4438. Date.prototype = OldDate.prototype;
  4439. // 继承静态函数,过滤已有的静态函数和参数,取数组差集
  4440. var oldDateStaticParam = Object.getOwnPropertyNames(OldDate);
  4441. var dateStaticParam = Object.getOwnPropertyNames(Date);
  4442. var diffParam = [];
  4443. for (var i = 0; i < oldDateStaticParam.length; i++) {
  4444. var find = false;
  4445. for (var j = 0; j < dateStaticParam.length; j++) {
  4446. if (oldDateStaticParam[i] === dateStaticParam[j]) {
  4447. find = true;
  4448. break;
  4449. }
  4450. }
  4451. if (!find) {
  4452. diffParam.push(oldDateStaticParam[i]);
  4453. }
  4454. }
  4455. for (var i = 0; i < diffParam.length; i++) {
  4456. Date[diffParam[i]] = OldDate[diffParam[i]];
  4457. }
  4458. }
  4459. } catch (error) {
  4460. console.log(error);
  4461. }