common.js 268 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456
  1. var VarValue = [];
  2. var VarSnapshotTime = {};
  3. var alarmColorData = {};
  4. var intervalTimers = [];
  5. var PAGEROOTDIR = decodeURIComponent(location.href);
  6. var $window = $window || $(window);
  7. var _exchangeCount = 0;
  8. (function () {
  9. var index = PAGEROOTDIR.lastIndexOf('/Html5/') === -1 ? (PAGEROOTDIR.lastIndexOf('/html5/') === -1 ? -1 : PAGEROOTDIR.lastIndexOf('/html5/')) : PAGEROOTDIR.lastIndexOf('/Html5/');
  10. if (index !== -1) {
  11. PAGEROOTDIR = PAGEROOTDIR.substr(0, index + 7);
  12. } else {
  13. PAGEROOTDIR = (location.origin || location.protocol + '//' + location.host) + '/';
  14. }
  15. })();
  16. function Cmd(CmdStr) {
  17. var a;
  18. try {
  19. eval('a = ' + CmdStr + ";");
  20. } catch (err) {
  21. a = 0;
  22. alert("表达式错误: " + CmdStr + "\n请在组态程序中修正后重新发布!");
  23. }
  24. return a;
  25. }
  26. ht.Chart = function (option, w, h) {
  27. var self = this,
  28. view = self._view = document.createElement('div');
  29. view.style.width = w + 'px';
  30. view.style.height = h + 'px';
  31. view.style.position = 'absolute';
  32. view.style.setProperty('box-sizing', 'border-box', null);
  33. self._option = option;
  34. self._chart = echarts.init(self.getView());
  35. if (option)
  36. self._chart.setOption(option);
  37. self._FIRST = true;
  38. };
  39. function getDateString(d) {
  40. var curr_date = d.getDate();
  41. var curr_month = d.getMonth() + 1;
  42. var curr_year = d.getFullYear();
  43. var hr = d.getHours();
  44. var min = d.getMinutes();
  45. var sec = d.getSeconds();
  46. var dateStr = curr_year + "/" + curr_month + "/" + curr_date + " " + hr + ":" + min + ":" + sec;
  47. return dateStr;
  48. }
  49. function GetDital(value, number) {
  50. var returnValue = value;
  51. if (returnValue == null || returnValue == undefined)
  52. return 0;
  53. var valuearr = returnValue.toString().split('.');
  54. var decimalCount = valuearr.length < 2 ? 0 : valuearr[1].length;
  55. if (typeof (returnValue) === 'number') {
  56. if (isNaN(returnValue)) {
  57. return 0;
  58. } else {
  59. if (number < 0) {
  60. return decimalCount <= 7 ? returnValue : returnValue.toFixed(7);
  61. } else {
  62. if (number > 7) {
  63. number = 7;
  64. }
  65. return decimalCount <= number ? returnValue : returnValue.toFixed(number);
  66. }
  67. }
  68. }
  69. if (typeof (returnValue) === 'string') {
  70. if (isNaN(returnValue)) {
  71. return 0;
  72. } else {
  73. returnValue = parseFloat(returnValue);
  74. if (number < 0) {
  75. return decimalCount <= 7 ? returnValue : returnValue.toFixed(7);
  76. } else {
  77. if (number > 7) {
  78. number = 7;
  79. }
  80. return decimalCount <= number ? returnValue : returnValue.toFixed(number);
  81. }
  82. }
  83. }
  84. if (returnValue === true) {
  85. return 1;
  86. }
  87. return 0;
  88. }
  89. ht.Default.def('ht.Chart', Object, {
  90. ms_v: 1,
  91. ms_fire: 1,
  92. ms_ac: ['chart', 'option', 'isFirst', 'view'],
  93. validateImpl: function () {
  94. var self = this,
  95. chart = self._chart;
  96. chart.resize();
  97. if (self._FIRST) {
  98. self._FIRST = false;
  99. //chart.restore();
  100. }
  101. },
  102. setSize: function (w, h) {
  103. var view = this._view;
  104. view.style.width = w + 'px';
  105. view.style.height = h + 'px';
  106. }
  107. });
  108. ht.DataModel.prototype.isAutoAdjustIndex = function () {
  109. return false;
  110. };
  111. function submitAddSingle(varName, value, time, quality, desc, groupid) {
  112. if (!isdowncontrol()) {
  113. return;
  114. }
  115. // var device;
  116. // if (varName.indexOf('.') != -1) {
  117. // device = varName.split('.')[0];
  118. // }
  119. // desc = desc + ":" + value;
  120. if (isAuthEnable == "True" && groupid >= 0) {
  121. getAuthInfoByGroupId(groupid, function (data) {
  122. if (data) {
  123. sendRequest(varName, value, time, quality, desc, groupid);
  124. }
  125. });
  126. } else if (isAuthEnable == "True" && groupid == -1) {
  127. sendRequest(varName, value, time, quality, desc, groupid);
  128. } else {
  129. sendRequest(varName, value, time, quality, desc, groupid, false);
  130. }
  131. }
  132. function sendRequest(varName, value, time, quality, desc, groupid, isAddOpera) {
  133. isAddOpera = isAddOpera === undefined ? true : isAddOpera;
  134. var data = {
  135. TagName: varName,
  136. Time: time,
  137. Value: value,
  138. Quality: quality
  139. };
  140. if (data.Time === "") {
  141. //var d = new Date();
  142. //var curr_date = d.getDate();
  143. //var curr_month = d.getMonth() + 1;
  144. //var curr_year = d.getFullYear();
  145. //var hr = d.getHours();
  146. //var min = d.getMinutes();
  147. //var sec = d.getSeconds();
  148. //var dateStr = curr_year + "/" + curr_month + "/" + curr_date + " " + hr + ":" + min + ":" + sec;
  149. //data.Time = dateStr;
  150. data.Time = "1900-01-01 00:00:00";
  151. }
  152. var jsonStr = JSON.stringify(data);
  153. $.ajax({
  154. url: "http://" + webServiceIP + ":" + webServicePort + "/api/Snapshot/?isSingleData=True",
  155. type: "POST",
  156. data: jsonStr,
  157. contentType: "application/json; charset=utf-8",
  158. success: function (data) {
  159. if (data || data == "True") {
  160. if (isAddOpera) {
  161. //将当前记录写入到操作记录中
  162. addOpera(varName, varName.split('.')[0], value, groupid, desc, quality, function (data) {
  163. });
  164. }
  165. }
  166. if ((typeof data == 'string') && data.constructor == String) //数据库版本2.x
  167. {
  168. if (data !== "True")
  169. GD.createErrorDialog(300, 160, data);
  170. } else ////数据库版本3.x
  171. {
  172. var errorList = data.ErrorList;
  173. if (errorList != null && errorList.length > 0) {
  174. GD.createErrorDialog(300, 160, errorList[0].ErrorMsg);
  175. }
  176. }
  177. },
  178. error: function (data) {
  179. if (data.responseText === "")
  180. GD.createErrorDialog(300, 160, '网络链接错误');
  181. else
  182. GD.createErrorDialog(300, 160, data.responseText);
  183. },
  184. complete: function (XHR, TS) {
  185. XHR = null;
  186. },
  187. });
  188. }
  189. function getHisTrendData(option, cmdStr, dictagdesc, callBack, areaStyleShow) {
  190. var paras = cmdStr.split('&');
  191. str = "http://" + webServiceIP + ":" + webServicePort +
  192. "/api/HistoryInterval?tagName="; //+ cmdStr;
  193. str = str + encodeURIComponent(paras[0]) + "&" + paras[1] + "&" + paras[2] + "&" + paras[3] + "&" + paras[4];
  194. //str = encodeURI(str);
  195. $.ajax({
  196. url: str,
  197. type: 'GET',
  198. dataType: 'json',
  199. cache: false,
  200. success: function (data) {
  201. if (data === null) {
  202. var k = 0;
  203. var test_data = {};
  204. for (tag in dictagdesc) {
  205. test_data[tag] = [];
  206. option.series[k] = {};
  207. option.series[k].name = dictagdesc[tag];
  208. option.series[k].type = 'line';
  209. option.series[k].showSymbol = false;
  210. option.series[k].sampling = 'average';
  211. option.series[k].symbol = "none";
  212. option.series[k].animation = false;
  213. if (option.yAxis && option.yAxis.length > 1) {
  214. dictagdesc[tag + 'index'] && (option.series[k].yAxisIndex = dictagdesc[tag + 'index']);
  215. }
  216. if (areaStyleShow) {
  217. option.series[k].areaStyle = {
  218. normal: {}
  219. };
  220. }
  221. //option.legend.data.push(tag);
  222. // option.legend.data.push(dictagdesc[tag]);
  223. for (var i = 0; i < 1; i++) {
  224. var currentTime = Date.now();
  225. test_data[tag][i] = {
  226. name: currentTime,
  227. value: [
  228. currentTime,
  229. null
  230. ]
  231. };
  232. }
  233. option.series[k].data = test_data[tag];
  234. k++;
  235. }
  236. }
  237. //return;
  238. else {
  239. var hisValues = data;
  240. //判断快照是否为空
  241. var k = 0;
  242. var date = [];
  243. var test_data = {};
  244. if (hisValues != null) {
  245. for (tag in hisValues) {
  246. test_data[tag] = [];
  247. option.series[k] = {};
  248. //option.series[k].name = tag;
  249. option.series[k].name = dictagdesc[tag];
  250. option.series[k].type = 'line';
  251. option.series[k].showSymbol = false;
  252. option.series[k].sampling = 'average';
  253. option.series[k].symbol = "none";
  254. option.series[k].animation = false;
  255. if (option.yAxis && option.yAxis.length > 1) {
  256. dictagdesc[tag + 'index'] && (option.series[k].yAxisIndex = dictagdesc[tag + 'index']);
  257. }
  258. if (areaStyleShow) {
  259. option.series[k].areaStyle = {
  260. normal: {}
  261. };
  262. }
  263. //option.legend.data.push(tag);
  264. option.legend && option.lengend[0] && option.lengend[0].data.push(dictagdesc[tag]);
  265. for (var i = 0; i < hisValues[tag].length; i++) {
  266. var time = hisValues[tag][i].Time;
  267. var timepts = time.split(' ');
  268. var timepars = timepts[0].split('/');
  269. if (timepars[1] < 10) {
  270. time = time.replace("/" + timepars[1] + "/",
  271. "/0" + timepars[1] + "/");
  272. }
  273. if (timepars[2] < 10) {
  274. time = time.replace("/" + timepars[2] + " ",
  275. "/0" + timepars[2] + " ");
  276. }
  277. //2017-04-01 15:34:28.000
  278. time = time.replace("/", "-");
  279. time = time.replace("/", "-");
  280. time = time.replace(" ", "T");
  281. var tagTime = moment(time).format();
  282. var tagValue = parseFloat(hisValues[tag][i].Value).toFixed(2);
  283. test_data[tag][i] = {
  284. name: tagTime,
  285. value: [
  286. tagTime,
  287. tagValue
  288. ]
  289. };
  290. }
  291. option.series[k].data = test_data[tag];
  292. k++;
  293. }
  294. }
  295. }
  296. callBack(option);
  297. return test_data;
  298. },
  299. complete: function (XHR, TS) {
  300. XHR = null;
  301. },
  302. error: function (data) {
  303. var k = 0;
  304. var test_data = {};
  305. for (tag in dictagdesc) {
  306. test_data[tag] = [];
  307. option.series[k] = {};
  308. option.series[k].name = dictagdesc[tag];
  309. option.series[k].type = 'line';
  310. option.series[k].showSymbol = false;
  311. option.series[k].sampling = 'average';
  312. option.series[k].symbol = "none";
  313. option.series[k].animation = false;
  314. //option.legend.data.push(tag);
  315. // option.legend.data.push(dictagdesc[tag]);
  316. for (var i = 0; i < 1; i++) {
  317. var currentTime = new Date();
  318. test_data[tag][i] = {
  319. name: currentTime,
  320. value: [
  321. currentTime,
  322. null
  323. ]
  324. };
  325. }
  326. option.series[k].data = test_data[tag];
  327. k++;
  328. }
  329. callBack(option);
  330. return test_data;
  331. }
  332. });
  333. }
  334. function getHisScatterData(chart, option, cmdStr, dictagdesc, pointArr, typeArr, digit, ymin, ymax, deviceType) {
  335. var paras = cmdStr.split('&');
  336. str = "http://" + webServiceIP + ":" + webServicePort + "/api/HistoryInterval?tagName=";
  337. paras[0] = encodeURIComponent(paras[0]);
  338. str = str + paras.join('&');
  339. // str = str + encodeURIComponent(paras[0]) + "&" + paras[1] + "&" + paras[2] + "&" + paras[3] + "&" + paras[4] + "&" + paras[5];
  340. var type = paras[paras.length-1].split('=')[1];
  341. // 标准数据
  342. var _standerdData = {
  343. 'UP1500-70': [
  344. [3, 3.12],
  345. [3.5, 21.87],
  346. [4, 46.99],
  347. [4.5, 76.41],
  348. [5, 111.05],
  349. [5.5, 153.66],
  350. [6, 206.11],
  351. [6.5, 268.91],
  352. [7, 342.59],
  353. [7.5, 427.81],
  354. [8, 525.33],
  355. [8.5, 638.43],
  356. [9, 755.38],
  357. [9.5, 880.36],
  358. [10, 1007.83],
  359. [10.5, 1136.81],
  360. [11, 1259.98],
  361. [11.5, 1375.27],
  362. [12, 1477.2],
  363. [12.5, 1500],
  364. [13, 1500],
  365. [13.5, 1500],
  366. [14, 1500],
  367. [14.5, 1500],
  368. [15, 1500],
  369. [15.5, 1500],
  370. [16, 1500],
  371. [16.5, 1500],
  372. [17, 1500],
  373. [17.5, 1500],
  374. [18, 1500],
  375. [18.5, 1500],
  376. [19, 1500],
  377. [19.5, 1500],
  378. [20, 1500],
  379. [20.5, 1500],
  380. [21, 1500],
  381. [21.5, 1500],
  382. [22, 1500],
  383. [22.5, 1500],
  384. [23, 1500],
  385. [23.5, 1500],
  386. [24, 1500],
  387. [24.5, 1500],
  388. [25, 1500]
  389. ],
  390. 'UP1500-77': [
  391. [3, 9.61],
  392. [3.5, 32.66],
  393. [4, 62.2],
  394. [4.5, 98.55],
  395. [5, 141.4],
  396. [5.5, 194.47],
  397. [6, 260.73],
  398. [6.5, 338.4],
  399. [7, 428.8],
  400. [7.5, 535.47],
  401. [8, 658.98],
  402. [8.5, 794.86],
  403. [9, 941.5],
  404. [9.5, 1097.29],
  405. [10, 1253.7],
  406. [10.5, 1405.08],
  407. [11, 1500],
  408. [11.5, 1500],
  409. [12, 1500],
  410. [12.5, 1500],
  411. [13, 1500],
  412. [13.5, 1500],
  413. [14, 1500],
  414. [14.5, 1500],
  415. [15, 1500],
  416. [15.5, 1500],
  417. [16, 1500],
  418. [16.5, 1500],
  419. [17, 1500],
  420. [17.5, 1500],
  421. [18, 1500],
  422. [18.5, 1500],
  423. [19, 1500],
  424. [19.5, 1500],
  425. [20, 1500],
  426. [20.5, 1500],
  427. [21, 1500],
  428. [21.5, 1500],
  429. [22, 1500],
  430. [22.5, 1500],
  431. [23, 1500],
  432. [23.5, 1500],
  433. [24, 1500],
  434. [24.5, 1500],
  435. [25, 1500]
  436. ],
  437. 'UP1500-82': [
  438. [3, 13.45],
  439. [3.5, 40.61],
  440. [4, 75.35],
  441. [4.5, 117.73],
  442. [5, 167.55],
  443. [5.5, 231.09],
  444. [6, 305.77],
  445. [6.5, 398.23],
  446. [7, 506.15],
  447. [7.5, 631.44],
  448. [8, 775.54],
  449. [8.5, 933.21],
  450. [9, 1101.82],
  451. [9.5, 1274.34],
  452. [10, 1451.66],
  453. [10.5, 1500],
  454. [11, 1500],
  455. [11.5, 1500],
  456. [12, 1500],
  457. [12.5, 1500],
  458. [13, 1500],
  459. [13.5, 1500],
  460. [14, 1500],
  461. [14.5, 1500],
  462. [15, 1500],
  463. [15.5, 1500],
  464. [16, 1500],
  465. [16.5, 1500],
  466. [17, 1500],
  467. [17.5, 1500],
  468. [18, 1500],
  469. [18.5, 1500],
  470. [19, 1500],
  471. [19.5, 1500],
  472. [20, 1500],
  473. [20.5, 1500],
  474. [21, 1500],
  475. [21.5, 1500],
  476. [22, 1500],
  477. [22.5, 1500],
  478. [23, 1500],
  479. [23.5, 1500],
  480. [24, 1500],
  481. [24.5, 1500],
  482. [25, 1500]
  483. ],
  484. 'UP1500-86': [
  485. [3, 15.25],
  486. [3.5, 45.21],
  487. [4, 82.31],
  488. [4.5, 130.21],
  489. [5, 185.47],
  490. [5.5, 255.27],
  491. [6, 337.94],
  492. [6.5, 439.39],
  493. [7, 558.02],
  494. [7.5, 695.24],
  495. [8, 852.84],
  496. [8.5, 1022.71],
  497. [9, 1200.46],
  498. [9.5, 1384.56],
  499. [10, 1500],
  500. [10.5, 1500],
  501. [11, 1500],
  502. [11.5, 1500],
  503. [12, 1500],
  504. [12.5, 1500],
  505. [13, 1500],
  506. [13.5, 1500],
  507. [14, 1500],
  508. [14.5, 1500],
  509. [15, 1500],
  510. [15.5, 1500],
  511. [16, 1500],
  512. [16.5, 1500],
  513. [17, 1500],
  514. [17.5, 1500],
  515. [18, 1500],
  516. [18.5, 1500],
  517. [19, 1500],
  518. [19.5, 1500],
  519. [20, 1500],
  520. [20.5, 1500],
  521. [21, 1500],
  522. [21.5, 1500],
  523. [22, 1500],
  524. [22.5, 1500],
  525. [23, 1500],
  526. [23.5, 1500],
  527. [24, 1500],
  528. [24.5, 1500],
  529. [25, 1500]
  530. ],
  531. 'UP1500-97': [
  532. [3, 35.99],
  533. [3.5, 70.24],
  534. [4, 118.45],
  535. [4.5, 189.36],
  536. [5, 271.06],
  537. [5.5, 373.13],
  538. [6, 485.66],
  539. [6.5, 618.62],
  540. [7, 773.69],
  541. [7.5, 938.57],
  542. [8, 1134],
  543. [8.5, 1325],
  544. [9, 1500],
  545. [9.5, 1500],
  546. [10, 1500],
  547. [10.5, 1500],
  548. [11, 1500],
  549. [11.5, 1500],
  550. [12, 1500],
  551. [12.5, 1500],
  552. [13, 1500],
  553. [13.5, 1500],
  554. [14, 1500],
  555. [14.5, 1500],
  556. [15, 1500],
  557. [15.5, 1500],
  558. [16, 1500],
  559. [16.5, 1500],
  560. [17, 1500],
  561. [17.5, 1500],
  562. [18, 1500],
  563. [18.5, 1500],
  564. [19, 1500],
  565. [19.5, 1500],
  566. [20, 1500],
  567. [20.5, 1500],
  568. [21, 1500],
  569. [21.5, 1500],
  570. [22, 1500],
  571. [22.5, 1500],
  572. [23, 1500],
  573. [23.5, 1500],
  574. [24, 1500],
  575. [24.5, 1500],
  576. [25, 1500]
  577. ],
  578. 'UP2000-87': [
  579. [3, 39.13],
  580. [3.5, 69.2],
  581. [4, 115.97],
  582. [4.5, 169.56],
  583. [5, 237.72],
  584. [5.5, 322.17],
  585. [6, 424.52],
  586. [6.5, 543.48],
  587. [7, 681.04],
  588. [7.5, 839.33],
  589. [8, 1017.78],
  590. [8.5, 1218.45],
  591. [9, 1434.4],
  592. [9.5, 1664.34],
  593. [10, 1901.03],
  594. [10.5, 2000],
  595. [11, 2000],
  596. [11.5, 2000],
  597. [12, 2000],
  598. [12.5, 2000],
  599. [13, 2000],
  600. [13.5, 2000],
  601. [14, 2000],
  602. [14.5, 2000],
  603. [15, 2000],
  604. [15.5, 2000],
  605. [16, 2000],
  606. [16.5, 2000],
  607. [17, 2000],
  608. [17.5, 2000],
  609. [18, 2000],
  610. [18.5, 2000],
  611. [19, 2000],
  612. [19.5, 2000],
  613. [20, 2000],
  614. [20.5, 2000],
  615. [21, 2000],
  616. [21.5, 2000],
  617. [22, 2000],
  618. [22.5, 2000],
  619. [23, 2000],
  620. [23.5, 2000],
  621. [24, 2000],
  622. [24.5, 2000],
  623. [25, 2000]
  624. ],
  625. 'UP2000-96': [
  626. [3, 21.9],
  627. [3.5, 50.77],
  628. [4, 93.07],
  629. [4.5, 152.92],
  630. [5, 224.24],
  631. [5.5, 313.3],
  632. [6, 421.61],
  633. [6.5, 549.9],
  634. [7, 700.66],
  635. [7.5, 873.8],
  636. [8, 1072.22],
  637. [8.5, 1296.27],
  638. [9, 1535.54],
  639. [9.5, 1776.91],
  640. [10, 2000],
  641. [10.5, 2000],
  642. [11, 2000],
  643. [11.5, 2000],
  644. [12, 2000],
  645. [12.5, 2000],
  646. [13, 2000],
  647. [13.5, 2000],
  648. [14, 2000],
  649. [14.5, 2000],
  650. [15, 2000],
  651. [15.5, 2000],
  652. [16, 2000],
  653. [16.5, 2000],
  654. [17, 2000],
  655. [17.5, 2000],
  656. [18, 2000],
  657. [18.5, 2000],
  658. [19, 2000],
  659. [19.5, 2000],
  660. [20, 2000],
  661. [20.5, 2000],
  662. [21, 2000],
  663. [21.5, 2000],
  664. [22, 2000],
  665. [22.5, 2000],
  666. [23, 2000],
  667. [23.5, 2000],
  668. [24, 2000],
  669. [24.5, 2000],
  670. [25, 2000]
  671. ],
  672. 'UP2000-103': [
  673. [3, 25.84],
  674. [3.5, 59.25],
  675. [4, 110.59],
  676. [4.5, 176.41],
  677. [5, 256.57],
  678. [5.5, 358.22],
  679. [6, 480.73],
  680. [6.5, 625.08],
  681. [7, 793.84],
  682. [7.5, 989.98],
  683. [8, 1212.58],
  684. [8.5, 1458.06],
  685. [9, 1705.04],
  686. [9.5, 1961.65],
  687. [10, 2000],
  688. [10.5, 2000],
  689. [11, 2000],
  690. [11.5, 2000],
  691. [12, 2000],
  692. [12.5, 2000],
  693. [13, 2000],
  694. [13.5, 2000],
  695. [14, 2000],
  696. [14.5, 2000],
  697. [15, 2000],
  698. [15.5, 2000],
  699. [16, 2000],
  700. [16.5, 2000],
  701. [17, 2000],
  702. [17.5, 2000],
  703. [18, 2000],
  704. [18.5, 2000],
  705. [19, 2000],
  706. [19.5, 2000],
  707. [20, 2000],
  708. [20.5, 2000],
  709. [21, 2000],
  710. [21.5, 2000],
  711. [22, 2000],
  712. [22.5, 2000],
  713. [23, 2000],
  714. [23.5, 2000],
  715. [24, 2000],
  716. [24.5, 2000],
  717. [25, 2000]
  718. ],
  719. 'UP2000-105': [
  720. [3, 31.9],
  721. [3.5, 67.13],
  722. [4, 123.02],
  723. [4.5, 190.82],
  724. [5, 276.72],
  725. [5.5, 384.98],
  726. [6, 515.37],
  727. [6.5, 669.48],
  728. [7, 850.74],
  729. [7.5, 1058.97],
  730. [8, 1289.89],
  731. [8.5, 1536.96],
  732. [9, 1787.9],
  733. [9.5, 2000],
  734. [10, 2000],
  735. [10.5, 2000],
  736. [11, 2000],
  737. [11.5, 2000],
  738. [12, 2000],
  739. [12.5, 2000],
  740. [13, 2000],
  741. [13.5, 2000],
  742. [14, 2000],
  743. [14.5, 2000],
  744. [15, 2000],
  745. [15.5, 2000],
  746. [16, 2000],
  747. [16.5, 2000],
  748. [17, 2000],
  749. [17.5, 2000],
  750. [18, 2000],
  751. [18.5, 2000],
  752. [19, 2000],
  753. [19.5, 2000],
  754. [20, 2000],
  755. [20.5, 2000],
  756. [21, 2000],
  757. [21.5, 2000],
  758. [22, 2000],
  759. [22.5, 2000],
  760. [23, 2000],
  761. [23.5, 2000],
  762. [24, 2000],
  763. [24.5, 2000],
  764. [25, 2000]
  765. ],
  766. 'UP2000-111': [
  767. [3, 41.47],
  768. [3.5, 81.58],
  769. [4, 140.27],
  770. [4.5, 214.03],
  771. [5, 309.1],
  772. [5.5, 428.09],
  773. [6, 571.28],
  774. [6.5, 739.81],
  775. [7, 937.01],
  776. [7.5, 1165.17],
  777. [8, 1408.25],
  778. [8.5, 1645.76],
  779. [9, 1882.77],
  780. [9.5, 2000],
  781. [10, 2000],
  782. [10.5, 2000],
  783. [11, 2000],
  784. [11.5, 2000],
  785. [12, 2000],
  786. [12.5, 2000],
  787. [13, 2000],
  788. [13.5, 2000],
  789. [14, 2000],
  790. [14.5, 2000],
  791. [15, 2000],
  792. [15.5, 2000],
  793. [16, 2000],
  794. [16.5, 2000],
  795. [17, 2000],
  796. [17.5, 2000],
  797. [18, 2000],
  798. [18.5, 2000],
  799. [19, 2000],
  800. [19.5, 2000],
  801. [20, 2000],
  802. [20.5, 2000],
  803. [21, 2000],
  804. [21.5, 2000],
  805. [22, 2000],
  806. [22.5, 2000],
  807. [23, 2000],
  808. [23.5, 2000],
  809. [24, 2000],
  810. [24.5, 2000],
  811. [25, 2000]
  812. ],
  813. 'UP2000-115': [
  814. [3, 20.62],
  815. [3.5, 86.52],
  816. [4, 159.21],
  817. [4.5, 245.16],
  818. [5, 346.11],
  819. [5.5, 463.73],
  820. [6, 619.51],
  821. [6.5, 786.99],
  822. [7, 985.67],
  823. [7.5, 1229],
  824. [8, 1510],
  825. [8.5, 1862],
  826. [9, 2000],
  827. [9.5, 2000],
  828. [10, 2000],
  829. [10.5, 2000],
  830. [11, 2000],
  831. [11.5, 2000],
  832. [12, 2000],
  833. [12.5, 2000],
  834. [13, 2000],
  835. [13.5, 2000],
  836. [14, 2000],
  837. [14.5, 2000],
  838. [15, 2000],
  839. [15.5, 2000],
  840. [16, 2000],
  841. [16.5, 2000],
  842. [17, 2000],
  843. [17.5, 2000],
  844. [18, 2000],
  845. [18.5, 2000],
  846. [19, 2000],
  847. [19.5, 2000],
  848. [20, 2000],
  849. [20.5, 2000],
  850. [21, 2000],
  851. [21.5, 2000],
  852. [22, 2000],
  853. [22.5, 2000],
  854. [23, 2000],
  855. [23.5, 2000],
  856. [24, 2000],
  857. [24.5, 2000],
  858. [25, 2000]
  859. ],
  860. 'UP2000-121': [
  861. [3, 32.728],
  862. [3.5, 102.384],
  863. [4, 186.87],
  864. [4.5, 290.566],
  865. [5, 415.484],
  866. [5.5, 550.916],
  867. [6, 711.338],
  868. [6.5, 893.586],
  869. [7, 1068.206],
  870. [7.5, 1249.736],
  871. [8, 1462.6],
  872. [8.5, 1731.828],
  873. [9, 1911.05],
  874. [9.5, 2000],
  875. [10, 2000],
  876. [10.5, 2000],
  877. [11, 2000],
  878. [11.5, 2000],
  879. [12, 2000],
  880. [12.5, 2000],
  881. [13, 2000],
  882. [13.5, 2000],
  883. [14, 2000],
  884. [14.5, 2000],
  885. [15, 2000],
  886. [15.5, 2000],
  887. [16, 2000],
  888. [16.5, 2000],
  889. [17, 2000],
  890. [17.5, 2000],
  891. [18, 2000],
  892. [18.5, 2000],
  893. [19, 2000],
  894. [19.5, 2000],
  895. [20, 2000]
  896. ],
  897. 'UP2100-121': [
  898. [3, 19.99],
  899. [3.5, 52.61],
  900. [4, 139.07],
  901. [4.5, 245.15],
  902. [5, 367.82],
  903. [5.5, 515.07],
  904. [6, 691.68],
  905. [6.5, 900.32],
  906. [7, 1144],
  907. [7.5, 1424],
  908. [8, 1745],
  909. [8.5, 2100],
  910. [9, 2100],
  911. [9.5, 2100],
  912. [10, 2100],
  913. [10.5, 2100],
  914. [11, 2100],
  915. [11.5, 2100],
  916. [12, 2100],
  917. [12.5, 2100],
  918. [13, 2100],
  919. [13.5, 2100],
  920. [14, 2100],
  921. [14.5, 2100],
  922. [15, 2100],
  923. [15.5, 2100],
  924. [16, 2100],
  925. [16.5, 2100],
  926. [17, 2100],
  927. [17.5, 2100],
  928. [18, 2100],
  929. [18.5, 2100],
  930. [19, 2100],
  931. [19.5, 2100],
  932. [20, 2100],
  933. [20.5, 2100],
  934. [21, 2100],
  935. [21.5, 2100],
  936. [22, 2100],
  937. [22.5, 2100],
  938. [23, 2100],
  939. [23.5, 2100],
  940. [24, 2100],
  941. [24.5, 2100],
  942. [25, 2100]
  943. ],
  944. 'UP3000-108': [
  945. [3, 112.73],
  946. [3.5, 192.94],
  947. [4, 286.15],
  948. [4.5, 397.02],
  949. [5, 528.27],
  950. [5.5, 683],
  951. [6, 865.06],
  952. [6.5, 1073.3],
  953. [7, 1310.46],
  954. [7.5, 1573.22],
  955. [8, 1855.97],
  956. [8.5, 2147.44],
  957. [9, 2437.76],
  958. [9.5, 2735.59],
  959. [10, 2997.89],
  960. [10.5, 2997.89],
  961. [11, 2997.89],
  962. [11.5, 2997.89],
  963. [12, 2997.89],
  964. [12.5, 2997.89],
  965. [13, 2997.89],
  966. [13.5, 2997.89],
  967. [14, 2997.89],
  968. [14.5, 2997.89],
  969. [15, 2997.89],
  970. [15.5, 2997.89],
  971. [16, 2997.89],
  972. [16.5, 2997.89],
  973. [17, 2997.89],
  974. [17.5, 2997.89],
  975. [18, 2997.89],
  976. [18.5, 2997.89],
  977. [19, 2997.89],
  978. [19.5, 2997.89],
  979. [20, 2997.89],
  980. [20.5, 2997.89],
  981. [21, 2997.89],
  982. [21.5, 2997.89],
  983. [22, 2997.89],
  984. [22.5, 2997.89],
  985. [23, 2997.89],
  986. [23.5, 2997.89],
  987. [24, 2997.89],
  988. [24.5, 2997.89],
  989. [25, 2997.89]
  990. ],
  991. 'UP2000-129': [
  992. [3, 39.46343239],
  993. [3.5, 125.6432788],
  994. [4, 219.4714609],
  995. [4.5, 329.5487529],
  996. [5, 457.4521127],
  997. [5.5, 607.3637197],
  998. [6, 787.3911529],
  999. [6.5, 997.9767531],
  1000. [7, 1233.68128],
  1001. [7.5, 1463.094124],
  1002. [8, 1689.342548],
  1003. [8.5, 1895.26058],
  1004. [9, 2000],
  1005. [9.5, 2000],
  1006. [10, 2000],
  1007. [10.5, 2000],
  1008. [11, 2000],
  1009. [11.5, 2000],
  1010. [12, 2000],
  1011. [12.5, 2000],
  1012. [13, 2000],
  1013. [13.5, 2000],
  1014. [14, 2000],
  1015. [14.5, 2000],
  1016. [15, 2000],
  1017. [15.5, 2000],
  1018. [16, 2000],
  1019. [16.5, 2000],
  1020. [17, 2000],
  1021. [17.5, 2000],
  1022. [18, 2000],
  1023. [18.5, 2000],
  1024. [19, 2000],
  1025. [19.5, 2000],
  1026. [20, 2000]
  1027. ],
  1028. 'UP3000-146': [
  1029. [3, 77.147],
  1030. [3.5, 185.877636],
  1031. [4, 293.9956907],
  1032. [4.5, 428.4692409],
  1033. [5, 594.4768116],
  1034. [5.5, 785.2404187],
  1035. [6, 1007.887492],
  1036. [6.5, 1258.856802],
  1037. [7, 1525.997884],
  1038. [7.5, 1808.595136],
  1039. [8, 2096.963],
  1040. [8.5, 2438.74932],
  1041. [9, 2667.47688],
  1042. [9.5, 2828],
  1043. [10, 2929.1],
  1044. [10.5, 2985],
  1045. [11, 3000],
  1046. [11.5, 3000],
  1047. [12, 3000],
  1048. [12.5, 3000],
  1049. [13, 3000],
  1050. [13.5, 3000],
  1051. [14, 3000],
  1052. [14.5, 3000],
  1053. [15, 3000],
  1054. [15.5, 3000],
  1055. [16, 3000],
  1056. [16.5, 3000],
  1057. [17, 3000],
  1058. [17.5, 3000],
  1059. [18, 3000],
  1060. [18.5, 3000],
  1061. [19, 3000],
  1062. [19.5, 3000],
  1063. [20, 3000]
  1064. ],
  1065. 'UPT300-16': [
  1066. [0.7,0],
  1067. [0.8,3.21709],
  1068. [0.9,12.2613],
  1069. [1,23.3403],
  1070. [1.1,36.9281],
  1071. [1.2,53.3618],
  1072. [1.3,72.7074],
  1073. [1.4,95.261],
  1074. [1.5,121.28],
  1075. [1.6,151.017],
  1076. [1.7,184.635],
  1077. [1.8,220.949],
  1078. [1.9,259.063],
  1079. [2,298.231],
  1080. [3,300.023],
  1081. [4,300.023]
  1082. ],
  1083. 'ErrorData': [
  1084. [0.7,0],
  1085. [0.8,2.944],
  1086. [0.9,11.232],
  1087. [1,20.324],
  1088. [1.1,34.9281],
  1089. [1.2,50.3618],
  1090. [1.3,68.7074],
  1091. [1.4,86.261],
  1092. [1.5,113.28],
  1093. [1.6,131.017],
  1094. [1.7,166.635],
  1095. [1.8,203.949],
  1096. [1.9,235.063],
  1097. [2,268.231],
  1098. [2.1,268.231],
  1099. [2.2,268.231],
  1100. [2.3,268.231],
  1101. [2.4,268.231],
  1102. [2.5,268.231],
  1103. [2.6,268.231],
  1104. [2.7,268.231],
  1105. [2.8,268.231],
  1106. [2.9,268.231],
  1107. [3,272.023],
  1108. [3.1,272.023],
  1109. [3.2,272.023],
  1110. [3.3,272.023],
  1111. [3.4,272.023],
  1112. [3.5,272.023],
  1113. [3.6,272.023],
  1114. [3.7,272.023],
  1115. [3.8,272.023],
  1116. [3.9,272.023],
  1117. [4,272.023]
  1118. ]
  1119. }
  1120. var standerdData = chart._standerdData;
  1121. function percent5Filter(speedValue, powerValue, dtype, low, high) {
  1122. var standerdValue,
  1123. bigValue,
  1124. smallValue,
  1125. percent;
  1126. low = low || 0.95;
  1127. high = high || 1.05;
  1128. if (!standerdData[dtype] && !standerdData[dtype].data) {
  1129. return true;
  1130. }
  1131. for (var i = 1, len = standerdData[dtype].data.length; i < len; i++) {
  1132. if (standerdData[dtype].data[i - 1][0] <= speedValue && standerdData[dtype].data[i][0] >= speedValue) {
  1133. bigValue = standerdData[dtype].data[i];
  1134. smallValue = standerdData[dtype].data[i - 1];
  1135. break;
  1136. }
  1137. }
  1138. if (!bigValue || !smallValue) {
  1139. return false;
  1140. }
  1141. standerdValue = (bigValue[1] - smallValue[1]) / (bigValue[0] - smallValue[0]) * (speedValue - smallValue[0]) + smallValue[1];
  1142. percent = Math.abs(powerValue / standerdValue);
  1143. return (percent <= high && percent >= low);
  1144. }
  1145. function getStanderdData(standerdDataKey) {
  1146. if (!standerdData[standerdDataKey]) return ;
  1147. return {
  1148. "name": standerdDataKey,
  1149. "data": standerdData[standerdDataKey].data,
  1150. "type": "line", "symbolSize": 5, "smooth": true,
  1151. "itemStyle": {
  1152. "normal": {
  1153. "color": standerdData[standerdDataKey].color
  1154. }
  1155. },
  1156. "lineStyle": {
  1157. "normal": {
  1158. "width": 2,
  1159. "type": "solid"
  1160. }
  1161. },
  1162. "zlevel": 0,
  1163. "z": 2,
  1164. "coordinateSystem": "cartesian2d",
  1165. "legendHoverLink": true,
  1166. "hoverAnimation": true,
  1167. "clipOverflow": true,
  1168. "label": {
  1169. "normal": {
  1170. "position": "top"
  1171. },
  1172. "emphasis": {
  1173. "position": "top"
  1174. }
  1175. },
  1176. "step": false,
  1177. "smoothMonotone": null,
  1178. "symbol": "emptyCircle",
  1179. "symbolRotate": null,
  1180. "showSymbol": true,
  1181. "showAllSymbol": false,
  1182. "connectNulls": false,
  1183. "sampling": "none",
  1184. "animationEasing": "linear",
  1185. "progressive": 0,
  1186. "hoverLayerThreshold": null
  1187. }
  1188. }
  1189. $.ajax({
  1190. url: str,
  1191. type: 'GET',
  1192. dataType: 'json',
  1193. cache: false,
  1194. success: function (data) {
  1195. if (data === null) { } else {
  1196. var hisValues = data;
  1197. var k = 0,
  1198. isChaoLiuNeng;
  1199. (function () {
  1200. var key;
  1201. for (var k in standerdData) {
  1202. if (standerdData.hasOwnProperty(k)) {
  1203. key = k;
  1204. break;
  1205. }
  1206. }
  1207. if (key.substr(0,3) === 'UPT') {
  1208. isChaoLiuNeng = key;
  1209. }
  1210. })();
  1211. // 潮流能假数据
  1212. if (isChaoLiuNeng && (typeArr[0] === '1' || typeArr[0] === '0')) {
  1213. (function () {
  1214. var key ;
  1215. for (var k in standerdData) {
  1216. if (standerdData.hasOwnProperty(k)) {
  1217. key = k;
  1218. break ;
  1219. }
  1220. }
  1221. var errData = key ? (standerdData[key].data || _standerdData.ErrorData) : _standerdData.ErrorData, t;
  1222. var xData = [], yData = [];
  1223. hisValues = {};
  1224. t = moment(Date.now()).format('YYYY-MM-DD HH-mm-ss');
  1225. for (var i = 0, len = errData.length; i < len; i++) {
  1226. xData.push({
  1227. "Ms": 0,
  1228. "Value": errData[i][0],
  1229. "Time": t
  1230. });
  1231. yData.push({
  1232. "Ms": 0,
  1233. "Value": errData[i][1] - Math.random()*50,
  1234. "Time": t
  1235. });
  1236. }
  1237. for (var i = 0, len = pointArr.length; i < len; i++) {
  1238. hisValues[pointArr[i][0]+'trendX'] = xData;
  1239. hisValues[pointArr[i][1]+'trendY'] = yData;
  1240. }
  1241. })();
  1242. }
  1243. for (var key in hisValues) {
  1244. for (var i = 1, len = hisValues[key].length; i < len; i++) {
  1245. if (hisValues[key][i - 1].Value !== 'NaN' && hisValues[key][i].Value === 'NaN') {
  1246. hisValues[key][i].Value = hisValues[key][i - 1].Value;
  1247. }
  1248. }
  1249. }
  1250. for (var i = 0; i < pointArr.length; i++) {
  1251. var seriesdata = [];
  1252. seriesdata.length = 0;
  1253. var type = typeArr[i];
  1254. if (type == "0" && i == 0) {
  1255. var data1 = hisValues[pointArr[i][0]];
  1256. var data2 = hisValues[pointArr[i][1]];
  1257. if (typeof data1 == "undefined" || typeof data2 == "undifined") continue;
  1258. if (data1.length == data2.length) {
  1259. for (var j = 0; j < data1.length; j++) {
  1260. var partaldata = [];
  1261. partaldata.length = 0;
  1262. partaldata.push(GetDital(parseFloat(data1[j].Value), digit));
  1263. partaldata.push(GetDital(parseFloat(data2[j].Value), digit));
  1264. seriesdata.push(partaldata);
  1265. }
  1266. }
  1267. } else if (type == "1") {
  1268. var data1 = hisValues[pointArr[i][0] + "trendX"];
  1269. var data2 = hisValues[pointArr[i][1] + "trendY"];
  1270. option.series[k].type = "line";
  1271. option.series[i].symbol = 'emptyCircle';
  1272. if (typeof data1 != "undefined" && data2 != "undefined") {
  1273. if (data1.length == data2.length) {
  1274. for (var j = 0; j < data1.length; j++) {
  1275. var partaldata = [];
  1276. partaldata.length = 0;
  1277. if (data1[j].Value != "NaN" && data2[j].Value != "NaN" && data1[j].Value >= ymin && data1[j].Value <= ymax && data2[j].Value <= ymax && data2[j].Value >= ymin) {
  1278. partaldata.push(GetDital(parseFloat(data1[j].Value), digit));
  1279. partaldata.push(GetDital(parseFloat(data2[j].Value), digit));
  1280. seriesdata.push(partaldata);
  1281. }
  1282. }
  1283. }
  1284. }
  1285. } else {
  1286. var data1 = hisValues[pointArr[i][0] + "purveX"];
  1287. var data2 = hisValues[pointArr[i][1] + "purveY"];
  1288. var dType = deviceType[pointArr[i][0]];
  1289. option.series[k].type = "scatter";
  1290. option.series[i].symbol = 'circle';
  1291. if (typeof data1 == "undefined" || typeof data2 == "undifined") continue;
  1292. if (data1.length == data2.length) {
  1293. for (var j = 0; j < data1.length; j++) {
  1294. var partaldata = [];
  1295. partaldata.length = 0;
  1296. // 过滤%5
  1297. if (isChaoLiuNeng) {
  1298. // dType = 'UPT300-16';
  1299. if (percent5Filter(parseFloat(data1[j].Value), parseFloat(data2[j].Value), isChaoLiuNeng, 0.95, 1.1)) {
  1300. partaldata.push(GetDital(parseFloat(data1[j].Value), digit));
  1301. partaldata.push(GetDital(parseFloat(data2[j].Value), digit));
  1302. seriesdata.push(partaldata);
  1303. }
  1304. } else {
  1305. partaldata.push(GetDital(parseFloat(data1[j].Value), digit));
  1306. partaldata.push(GetDital(parseFloat(data2[j].Value), digit));
  1307. seriesdata.push(partaldata);
  1308. }
  1309. }
  1310. }
  1311. }
  1312. option.series[k].data = seriesdata;
  1313. k++;
  1314. }
  1315. }
  1316. },
  1317. error: function () {
  1318. console.log('error');
  1319. },
  1320. complete: function (XHR, TS) {
  1321. //typeArr 0,1为曲线,2为散点 曲线图设置为多选,散点图设置为单选
  1322. var sers = option.series, hasStd1 = false, hasStd2 = false, hasStd3 = false, hasStd4 = false, newSeries = [], tempSelected;
  1323. if (true || typeArr[0] === '1' || typeArr[0] === '0') {
  1324. if (!chart._hadSetStanderdData) {
  1325. chart._standCurvalLine = chart._standCurvalLine || [];
  1326. chart._standCurvalLine.length = 0;
  1327. for (var key in standerdData) {
  1328. if (!standerdData.hasOwnProperty(key)) continue;
  1329. if (sers) {
  1330. sers.push(getStanderdData(key));
  1331. }
  1332. if (option.legend && option.legend[0] && option.legend[0].data) {
  1333. option.legend[0].data.indexOf(key) === -1 && option.legend[0].data.unshift(key);
  1334. }
  1335. }
  1336. chart._standCurvalLine.push(key);
  1337. chart._hadSetStanderdData = true;
  1338. }
  1339. option.legend && option.legend[0] && (option.legend[0].selectedMode = 'multiple');
  1340. if (typeArr[0] !== '1' && typeArr[0] !== '0') {
  1341. if (option && option.legend && option.legend[0]) {
  1342. tempSelected = detectSelectedLegend(option.legend[0].selected, 1);
  1343. }
  1344. for (var i = 0, len = chart._standCurvalLine.length; i < len; i++) {
  1345. if (option.legend[0].selected.hasOwnProperty(chart._standCurvalLine[i]))
  1346. tempSelected[chart._standCurvalLine[i]] = option.legend[0].selected[chart._standCurvalLine[i]]
  1347. }
  1348. option.legend[0].selected = tempSelected;
  1349. } else {
  1350. if (option && option.legend && option.legend[0]) {
  1351. option.legend[0].selected = detectSelectedLegend(option.legend[0].selected, 8);
  1352. }
  1353. }
  1354. } else { }
  1355. chart.clear();
  1356. chart.setOption(option, true);
  1357. XHR = null;
  1358. }
  1359. });
  1360. }
  1361. // 检测被选中的图例是否超过了limit个,如果超过只保留前面的,后面的设置为false
  1362. function detectSelectedLegend(selected, limit) {
  1363. var result = {};
  1364. var selectedCount = 0;
  1365. for (var key in selected) {
  1366. if (selected[key]) {
  1367. selectedCount++;
  1368. }
  1369. if (selectedCount > limit) {
  1370. result[key] = false;
  1371. } else {
  1372. result[key] = selected[key];
  1373. }
  1374. }
  1375. return result;
  1376. }
  1377. //获取标签点名称
  1378. function getPointsSelect(pageIndex, count, tablename, tagDesc, tagsDataModel, form) {
  1379. var start = (pageIndex - 1) * count;
  1380. str = "http://" + webServiceIP + ":" + webServicePort + "/api/Point?start=" + start + "&count=" + count + "&filter=" + tagDesc + "&tabfilter=" + tablename;
  1381. str = encodeURI(str);
  1382. $.ajax({
  1383. url: str,
  1384. type: 'GET',
  1385. dataType: 'json',
  1386. cache: false,
  1387. success: function (data) {
  1388. if (data == null) return;
  1389. pointpros = data.PointsPros;
  1390. if (pointpros == null) {
  1391. form.v('pagecount', "1");
  1392. return;
  1393. } else {
  1394. var pageCount = Math.ceil(data.Count / count);
  1395. form.v('pagecount', pageCount.toString());
  1396. }
  1397. var datalen = pointpros.length;
  1398. for (var i = 0; i < datalen; i++) {
  1399. datas = new ht.Data();
  1400. datas.setId(i + 1);
  1401. datas.a('index', (i + 1).toString());
  1402. datas.a('configPointDesc', pointpros[i].Desc);
  1403. datas.a('configPointName', pointpros[i].TagName);
  1404. datas.a('pintunit', pointpros[i].Uint);
  1405. datas.a('pointtype', pointpros[i].Type);
  1406. datas.a('snapvalue', "");
  1407. datas.a('timestamp', "");
  1408. tagsDataModel.add(datas);
  1409. }
  1410. tagsDataModel.sm().ss(data);
  1411. },
  1412. complete: function (XHR, TS) {
  1413. XHR = null;
  1414. }
  1415. });
  1416. }
  1417. function getKeyFromDic(dic, value) {
  1418. for (var key in dic) {
  1419. if (dic[key] == value) {
  1420. return key;
  1421. }
  1422. }
  1423. }
  1424. function SetRotatPositionRelative(Node1, Node2, Angle) {
  1425. var x = Node1.getPosition().x - Node2.getPosition().x;
  1426. var y = Node1.getPosition().y - Node2.getPosition().y;
  1427. Node1.setPosition(Math.cos(Angle) * x - Math.sin(Angle) * y + Node2.getPosition().x, Math.cos(Angle) * y + Math.sin(Angle) * x + Node2.getPosition().y);
  1428. }
  1429. function SetRotatPositionAbsolute(Node1, x0, y0, Angle) {
  1430. var x = Node1.getPosition().x - x0;
  1431. var y = Node1.getPosition().y - y0;
  1432. Node1.setPosition(Math.cos(Angle) * x - Math.sin(Angle) * y + x0, Math.cos(Angle) * y + Math.sin(Angle) * x + y0);
  1433. }
  1434. var dataModel, graphView, view, selectionModel, serialData, $view;
  1435. function initPage() {
  1436. dataModel = dataModel || new ht.DataModel();
  1437. graphView = graphView || new ht.graph.GraphView(dataModel);
  1438. view = view || graphView.getView();
  1439. graphView.enableFlow();
  1440. graphView.enableToolTip();
  1441. selectionModel = selectionModel || dataModel.getSelectionModel();
  1442. view.className = 'main';
  1443. // $view = $(view);
  1444. // document.body.appendChild(view);
  1445. // window.addEventListener('resize', function(e) {
  1446. //graphView.invalidate();
  1447. // graphView.fitContent(false, 0, true);
  1448. // }, false);
  1449. graphView.graphViewList = graphView.graphViewList || [];
  1450. serialData = serialData || dataModel.serialize();
  1451. }
  1452. function hisRefresh(option, chart) {
  1453. str = "http://" + webServiceIP + ":" + webServicePort + "/api/Snapshot?tagName=" + "demo.demo_ai001,demo.demo_ai002,demo.demo_ai003,demo.demo_ai004";
  1454. //str = encodeURI(str);
  1455. $.ajax({
  1456. url: str,
  1457. type: 'GET',
  1458. dataType: 'json',
  1459. cache: false,
  1460. success: function (data) {
  1461. if (data === null)
  1462. return;
  1463. var snapshots = eval(data);
  1464. //判断快照是否为空
  1465. if (snapshots != null) {
  1466. var newOption = {};
  1467. var varList = testHisOption.legend.data;
  1468. var dataChanged = false;
  1469. newOption.series = option.series;
  1470. for (var i = 0; i < snapshots.length; i++) {
  1471. var index = varList.indexOf(snapshots[i].TagName);
  1472. if (index >= 0 && index < varList.length) {
  1473. var tagValue = parseFloat(snapshots[i].Value);
  1474. var tagTime = new Date(snapshots[i].Time);
  1475. var len = newOption.series[index].data.length;
  1476. if (len == undefined || len <= 0 || newOption.series[index].data[len - 1][0].toString() !== tagTime.toString() || newOption.series[index].data[len - 1][1] !== tagValue) {
  1477. dataChanged = true;
  1478. var newData = [];
  1479. newData.push(tagTime);
  1480. newData.push(tagValue.toFixed(2));
  1481. newOption.series[index].data.push(newData);
  1482. if (newOption.series[index].data.length > 20000) {
  1483. newOption.series[index].data.splice(0, newOption.series[index].data.length - 20000);
  1484. }
  1485. }
  1486. }
  1487. }
  1488. if (dataChanged) {
  1489. chart.setOption(newOption);
  1490. }
  1491. }
  1492. },
  1493. complete: function (XHR, TS) {
  1494. XHR = null;
  1495. }
  1496. });
  1497. }
  1498. function getDivText(id) {
  1499. return $(id).text();
  1500. }
  1501. function creatTree(tree, treeDataModel, parent) {
  1502. var data = new ht.Data();
  1503. data.setName(tree.name);
  1504. treeDataModel.add(data);
  1505. if (parent !== undefined)
  1506. data.setParent(parent);
  1507. if (tree.child !== undefined) {
  1508. for (var i = 0; i < tree.child.length; i++) {
  1509. creatTree(tree.child[i], treeDataModel, data);
  1510. }
  1511. }
  1512. return data;
  1513. }
  1514. var dataAdapter = {
  1515. IP: webServiceIP,
  1516. port: webServicePort,
  1517. init: function () {
  1518. this.IP = webServiceIP;
  1519. this.port = webServicePort;
  1520. }
  1521. };
  1522. function getTableHisData(paneNode, cmdStr, dm, columns, rows) {
  1523. var paras = cmdStr.split('&');
  1524. str = "http://" + webServiceIP + ":" + webServicePort + "/api/HistoryInterval?tagName="; //+ cmdStr;
  1525. str = str + encodeURIComponent(paras[0]) + "&" + paras[1] + "&" + paras[2] + "&" + paras[3] + "&" + paras[4] + "&" + paras[5] + "&" + paras[6];
  1526. dm.clear();
  1527. $.ajax({
  1528. url: str,
  1529. type: 'GET',
  1530. dataType: 'json',
  1531. cache: false,
  1532. success: function (hisdata) {
  1533. if (hisdata === null) return;
  1534. var data = hisdata["Datas"];
  1535. var pageCount = hisdata["PageCount"];
  1536. paneNode.v("pagecount", pageCount.toString());
  1537. if (data === null)
  1538. return;
  1539. var hisValues = eval(data);
  1540. if (hisValues != null) {
  1541. var once = false;
  1542. }
  1543. var length = 0;
  1544. for (var key in hisValues) {
  1545. if (hisValues[key].length > length) {
  1546. length = hisValues[key].length;
  1547. }
  1548. }
  1549. var tagInfos = getTagInfos(columns, rows);
  1550. var tagInfosArr = tagInfos.split(",");
  1551. //var rowArr=rows.split(",");
  1552. //var rowCount=rowArr.length;
  1553. //var columnsArr=columns.split(",");
  1554. //var columnsCount=columnsArr.length;
  1555. var rowArr, rowCount, columnsArr, columnsCount;
  1556. if (columns == "") {
  1557. rowArr = rows.split(",");
  1558. columnsArr = rowArr;
  1559. rowCount = 1;
  1560. columnsCount = columnsArr.length;
  1561. } else {
  1562. rowArr = rows.split(",");
  1563. rowCount = rowArr.length;
  1564. columnsArr = columns.split(",");
  1565. columnsCount = columnsArr.length;
  1566. }
  1567. for (var i = 0; i < length; i++) {
  1568. if (rowCount <= 0) return;
  1569. if (columnsCount > 0) {
  1570. var index = 0,
  1571. data = new ht.Data(),
  1572. rowIndex = 0;
  1573. for (var j = 0; j < tagInfosArr.length; j++) {
  1574. if (columns != "") {
  1575. var indicatorName = columnsArr[index].split(":")[0];
  1576. if (typeof hisValues[tagInfosArr[j]] == "undefined") {
  1577. data.a(indicatorName, "无");
  1578. } else {
  1579. var value = hisValues[tagInfosArr[j]][i]["Value"];
  1580. data.a(indicatorName, GetDital(value, 2));
  1581. }
  1582. if (index == 0) {
  1583. if (columns != "") {
  1584. data.a("shebei", rowArr[rowIndex].split(":")[1]);
  1585. }
  1586. if (hisValues[tagInfosArr[j]]) {
  1587. data.a("time", hisValues[tagInfosArr[j]][i]["Time"]);
  1588. index = index + 1;
  1589. }
  1590. } else if (index == columnsCount - 1) {
  1591. if (rowArr[rowIndex].split(":")[2] != "false") {
  1592. dm.add(data);
  1593. }
  1594. index = 0;
  1595. rowIndex = rowIndex + 1;
  1596. data = new ht.Data();
  1597. } else {
  1598. index = index + 1;
  1599. }
  1600. } else {
  1601. var indicatorName = columnsArr[j].split(":")[0];
  1602. if (!data.a("time")) {
  1603. data.a("time", hisValues[tagInfosArr[j]][i]["Time"]);
  1604. }
  1605. var value = hisValues[tagInfosArr[j]][i]["Value"];
  1606. data.a(indicatorName, GetDital(value, 2));
  1607. if (j == tagInfosArr.length - 1) {
  1608. dm.add(data);
  1609. }
  1610. }
  1611. }
  1612. }
  1613. }
  1614. return;
  1615. },
  1616. complete: function (XHR, TS) {
  1617. XHR = null;
  1618. }
  1619. });
  1620. }
  1621. var drawPoints = function (g, points, segments) {
  1622. var reverse = false;
  1623. /*
  1624. if(g.beginPath){
  1625. g.beginPath();
  1626. }else{
  1627. reverse = true;
  1628. }
  1629. if(isList(points)){
  1630. points = points._as;
  1631. }
  1632. if(isList(segments)){
  1633. segments = segments._as;
  1634. }
  1635. */
  1636. if (segments && segments.length) {
  1637. var pointIndex = 0,
  1638. segment, p0, p1, p2,
  1639. segmentIndex = 0,
  1640. segmentCount = segments.length;
  1641. for (; segmentIndex < segmentCount; segmentIndex++) {
  1642. segment = segments[segmentIndex];
  1643. // 1: moveTo
  1644. if (1 === segment) {
  1645. p0 = points[pointIndex++];
  1646. g.moveTo(p0.x, reverse ? -p0.y : p0.y);
  1647. }
  1648. // 2: lineTo
  1649. else if (2 === segment) {
  1650. p0 = points[pointIndex++];
  1651. g.lineTo(p0.x, reverse ? -p0.y : p0.y);
  1652. }
  1653. // 3: quadraticCurveTo
  1654. else if (3 === segment) {
  1655. p0 = points[pointIndex++];
  1656. p1 = points[pointIndex++];
  1657. g.quadraticCurveTo(p0.x, reverse ? -p0.y : p0.y, p1.x, reverse ? -p1.y : p1.y);
  1658. }
  1659. // 4: bezierCurveTo
  1660. else if (4 === segment) {
  1661. p0 = points[pointIndex++];
  1662. p1 = points[pointIndex++];
  1663. p2 = points[pointIndex++];
  1664. g.bezierCurveTo(p0.x, reverse ? -p0.y : p0.y, p1.x, reverse ? -p1.y : p1.y, p2.x, reverse ? -p2.y : p2.y);
  1665. }
  1666. // 5: closePath
  1667. else if (5 === segment) {
  1668. g.closePath();
  1669. }
  1670. }
  1671. if (segment !== 5) {
  1672. g.closePath();
  1673. }
  1674. } else {
  1675. var point, i, value, n = points.length;
  1676. if (n > 0) {
  1677. point = points[0];
  1678. g.moveTo(point.x, reverse ? -point.y : point.y);
  1679. for (i = 1; i < n; i++) {
  1680. value = points[i];
  1681. g.lineTo(value.x, reverse ? -value.y : value.y);
  1682. }
  1683. //if(closePath){
  1684. g.closePath();
  1685. //}
  1686. }
  1687. }
  1688. };
  1689. function getVarValue(tag) {
  1690. if (tag === undefined || tag === null) {
  1691. return 0;
  1692. }
  1693. if ($.isNumeric(tag)) {
  1694. return tag;
  1695. }
  1696. if (window[tag] !== undefined) {
  1697. return window[tag];
  1698. }
  1699. // for(var i=0; i <varList.length;i++){
  1700. // if(tag.toLowerCase() === varList[i].toLowerCase()){
  1701. // if(Number(VarValue[i]) && Math.ceil(VarValue[i]) !== VarValue[i]){
  1702. // try{
  1703. // return VarValue[i].toFixed(2);
  1704. // }
  1705. // catch(err) {
  1706. // return 0;
  1707. // }
  1708. // }
  1709. // else{
  1710. // return VarValue[i];
  1711. // }
  1712. // }
  1713. // }
  1714. var t = tag.toLowerCase();
  1715. var v = varListObj[t];
  1716. if (varListObj.hasOwnProperty(t)) {
  1717. if (Number(v) && Math.ceil(v) !== v) {
  1718. try {
  1719. return v.toFixed(2);
  1720. } catch (err) {
  1721. return 0;
  1722. }
  1723. } else {
  1724. return v;
  1725. }
  1726. }
  1727. varList.push(tag);
  1728. VarValue.push(0);
  1729. varListObj[t] = 0;
  1730. GD.throttle(GD.GetTagsProperty, 3 * 1000);
  1731. return 0;
  1732. }
  1733. //获取变色值
  1734. function getColorValue(labelStr1, tag, labelStr2) {
  1735. if (window[tag] !== undefined) {
  1736. return window[tag];
  1737. }
  1738. for (var i = 0; i < varList.length; i++) {
  1739. if (tag && tag.toLowerCase() === varList[i].toLowerCase()) {
  1740. if (Number(VarValue[i]) && Math.ceil(VarValue[i]) !== VarValue[i]) {
  1741. try {
  1742. var html = "";
  1743. //判断该测点是否在报警中和已确认两个报警状态中
  1744. if (alarmColorData[tag.toLowerCase()]) {
  1745. html = '<span style="color:' + alarmColorData[tag.toLowerCase()] + '">' + labelStr1 + VarValue[i].toFixed(2) + labelStr2 + '</span>';
  1746. } else {
  1747. html = '<span>' + labelStr1 + VarValue[i].toFixed(2) + labelStr2 + '</span>';
  1748. }
  1749. return html;
  1750. } catch (err) {
  1751. return 0;
  1752. }
  1753. } else {
  1754. var html = "";
  1755. //判断该测点是否在报警中和已确认两个报警状态中
  1756. if (alarmColorData[tag.toLowerCase()]) {
  1757. html = '<span style="color:' + alarmColorData[tag.toLowerCase()] + '">' + labelStr1 + VarValue[i] + labelStr2 + '</span>';
  1758. } else {
  1759. html = '<span>' + labelStr1 + VarValue[i] + labelStr2 + '</span>';
  1760. }
  1761. return html;
  1762. }
  1763. }
  1764. }
  1765. if (tag) {
  1766. varList.push(tag);
  1767. VarValue.push(0);
  1768. return '<span>' + labelStr1 + '0' + labelStr2 + '</span>';
  1769. }
  1770. }
  1771. function checkNumber(number) {
  1772. var re = /^(-)?\d+(\.\d+)?$/;
  1773. return re.test(number);
  1774. }
  1775. //获取控件的值
  1776. function getControlValue(node, isNumber) {
  1777. var value;
  1778. if (node.getSelectedItem) {
  1779. value = node.getSelectedItem();
  1780. }
  1781. if (node.getValue) {
  1782. value = node.getValue();
  1783. }
  1784. if (isNumber) {
  1785. if (checkNumber(value)) {
  1786. return value;
  1787. } else {
  1788. return 0;
  1789. }
  1790. } else {
  1791. return value;
  1792. }
  1793. }
  1794. //设置填充颜色透明度
  1795. function setShapeOpacity(node, opacity, nodename) {
  1796. var nodebackStyle, backcolor, nodegradientcolor, gradientcolor, bc, sc;
  1797. if (!isTextComps(node)) {
  1798. bc = node.s("shape.background") || '';
  1799. nodebackStyle = bc.split(',');
  1800. if (nodebackStyle.length >= 3) {
  1801. backcolor = node.getStyle("shape.background").replace(nodebackStyle[3] || 1, opacity + ')');
  1802. node.s({
  1803. 'shape.background': backcolor
  1804. });
  1805. }
  1806. sc = node.s("shape.gradient.color") || '';
  1807. nodegradientcolor = sc.split(',');
  1808. if (nodegradientcolor.length >= 3) {
  1809. gradientcolor = node.getStyle("shape.gradient.color").replace(nodegradientcolor[3] || 1, opacity + ')');
  1810. node.s({
  1811. 'shape.gradient.color': gradientcolor
  1812. });
  1813. }
  1814. } else {
  1815. if (!node.a("node.background")) {
  1816. return;
  1817. }
  1818. bc = node.a("node.background") || '';
  1819. nodebackStyle = bc.split(',');
  1820. if (nodebackStyle.length >= 3) {
  1821. backcolor = bc.replace(nodebackStyle[3] || 1, opacity + ')');
  1822. node.a('node.background', backcolor);
  1823. }
  1824. sc = node.a("node.gradientcolor") || '';
  1825. nodegradientcolor = sc.split(',');
  1826. if (nodegradientcolor.length >= 3) {
  1827. gradientcolor = sc.replace(nodegradientcolor[3] || 1, opacity + ')');
  1828. node.a('node.gradientcolor', gradientcolor);
  1829. }
  1830. }
  1831. }
  1832. //设置边框透明度
  1833. function setBorderOpacity(node, opacity, nodename) {
  1834. var nodeborderStyle, nodebordercolor;
  1835. if (!isTextComps(node)) {
  1836. nodeborderStyle = node.s("shape.border.color").split(',');
  1837. if (nodeborderStyle.length >= 3) {
  1838. nodebordercolor = node.getStyle("shape.border.color").replace(nodeborderStyle[3], opacity + ')');
  1839. node.s({
  1840. 'shape.border.color': nodebordercolor
  1841. });
  1842. }
  1843. } else {
  1844. if (!node.a("node.color")) {
  1845. return;
  1846. }
  1847. nodeborderStyle = node.a("node.color").split(',');
  1848. if (nodeborderStyle.length >= 3) {
  1849. nodebordercolor = node.a('node.color').replace(nodeborderStyle[3], opacity + ')');
  1850. node.a('node.color', nodebordercolor);
  1851. }
  1852. }
  1853. }
  1854. //设置边框线样式
  1855. function setDashStyle(node, nodename, dashstyle, nodenamewidth) {
  1856. if (!nodenamewidth) {
  1857. return;
  1858. }
  1859. if (!isTextComps(node)) {
  1860. if (getDashStyle(dashstyle).length > 0) {
  1861. node.s({
  1862. 'shape.border.width': nodenamewidth
  1863. });
  1864. node.s({
  1865. 'shape.border.pattern': getDashStyle(dashstyle)
  1866. });
  1867. } else {
  1868. node.s({
  1869. 'shape.border.width': 0
  1870. });
  1871. }
  1872. } else {
  1873. if (getDashStyle(dashstyle).length > 0) {
  1874. node.a('node.borderwidth', nodenamewidth);
  1875. node.a('node.borderPattern', getDashStyle(dashstyle));
  1876. } else {
  1877. node.a('node.borderwidth', 0);
  1878. }
  1879. }
  1880. }
  1881. function setColor(node, nodename, targetcolor, colortypestr) {
  1882. if (!isTextComps(node)) {
  1883. if (colortypestr == "backColor") {
  1884. node.s('shape.background', targetcolor);
  1885. } else if (colortypestr == "foreColor") {
  1886. node.s('shape.gradient.color', targetcolor);
  1887. } else if (colortypestr == "lineColor") {
  1888. node.s('shape.border.color', targetcolor);
  1889. }
  1890. } else {
  1891. if (colortypestr == "textBackColor") {
  1892. node.a('node.background', targetcolor);
  1893. } else if (colortypestr == "textForeColor") {
  1894. node.a('node.gradientcolor', targetcolor);
  1895. } else if (colortypestr == "textColor") {
  1896. node.a('node.color', targetcolor);
  1897. } else if (colortypestr == "backColor") {
  1898. node.a('node.background', targetcolor);
  1899. } else if (colortypestr == "foreColor") {
  1900. node.a('node.gradientcolor', targetcolor);
  1901. } else if (colortypestr == "lineColor") {
  1902. node.a('node.color', targetcolor);
  1903. }
  1904. }
  1905. }
  1906. //获取虚线类型
  1907. function getDashStyle(dashstyle) {
  1908. if (dashstyle === "Solid") {
  1909. return [0, 0];
  1910. } else if (dashstyle === "LinePoint") {
  1911. return [3, 3];
  1912. } else if (dashstyle === "LineSegment") {
  1913. return [8, 8];
  1914. } else {
  1915. return [];
  1916. }
  1917. }
  1918. var getCoorPosition = function (a, r) {
  1919. var x = r * Math.cos(a);
  1920. var y = r * Math.sin(a);
  1921. return {
  1922. x: x + r,
  1923. y: y + r
  1924. };
  1925. }
  1926. var getCoorList = function (a, b, r) {
  1927. var list = new ht.List();
  1928. list.add(getCoorPosition(a, r));
  1929. list.add(getCoorPosition(b, r));
  1930. return list;
  1931. }
  1932. var getMaxValue = function (value, maxValue, minValue) {
  1933. if (value > maxValue) {
  1934. return maxValue;
  1935. } else if (value < minValue) {
  1936. return minValue;
  1937. } else {
  1938. return value;
  1939. }
  1940. }
  1941. var createTableAttr = function (rowheight, rowlinevisible, rowaltercolor, isrowalter, headcolor, headGradientcolor, columnlinevisible, linecolor, backcolor, fontsize, fontcolor, fontfamily) {
  1942. var obj = new Object();
  1943. obj.rowheight = rowheight;
  1944. obj.rowlinevisible = rowlinevisible;
  1945. obj.rowaltercolor = rowaltercolor;
  1946. obj.isrowalter = isrowalter;
  1947. obj.headcolor = headcolor;
  1948. obj.headGradientcolor = headGradientcolor;
  1949. obj.columnlinevisible = columnlinevisible;
  1950. obj.linecolor = linecolor;
  1951. obj.backcolor = backcolor;
  1952. obj.fontsize = fontsize;
  1953. obj.fontcolor = fontcolor;
  1954. obj.fontfamily = fontfamily;
  1955. return obj;
  1956. }
  1957. var setTableStyle = function (htmodel, obj) {
  1958. var htmodelView = htmodel.getTableView();
  1959. var htmodelHead = htmodel.getTableHeader();
  1960. htmodelView.setRowHeight((obj.rowheight || 25) * ratio.ratioY);
  1961. htmodelHead.setHeight((obj.headheight || 25) * ratio.ratioY);
  1962. htmodelView.setRowLineVisible(obj.rowlinevisible);
  1963. htmodelView.setColumnLineVisible(obj.columnlinevisible);
  1964. htmodelHead.setColumnLineVisible(obj.columnlinevisible);
  1965. htmodelHead.setColumnLineColor(obj.linecolor);
  1966. htmodelView.setColumnLineColor(obj.linecolor);
  1967. htmodelView.setRowLineColor(obj.linecolor);
  1968. htmodelHead.setColumnLineColor(obj.linecolor);
  1969. htmodelView.setScrollBarColor(obj.scrollBarColor || 'rgba(122,122,122,0.7)');
  1970. //htmodel.getView().style.backgroundColor="red";
  1971. htmodelView.getLabelColor = function () {
  1972. return obj.fontcolor
  1973. };
  1974. htmodelView.getLabelFont = function () {
  1975. return obj.bodyfontstyle + ' ' + obj.fontsize * ratio.ratioY + "px " + obj.fontfamily
  1976. };
  1977. htmodelHead.getLabelColor = function () {
  1978. return obj.headFontColor;
  1979. }
  1980. htmodelHead.getLabelFont = function () {
  1981. return obj.headerfontstyle + ' ' + obj.headerfontsize * ratio.ratioY + 'px ' + obj.headerfontfamily;
  1982. }
  1983. htmodelView.drawRowBackground = function (g, data, selected, x, y, width, height) {
  1984. if (obj.isrowalter) {
  1985. var index = htmodelView.getRowIndex(data);
  1986. if (index % 2 == 0) {
  1987. g.fillStyle = obj.backcolor;
  1988. } else {
  1989. g.fillStyle = obj.rowaltercolor;
  1990. }
  1991. g.beginPath();
  1992. g.rect(x, y, width, height);
  1993. g.fill();
  1994. }
  1995. };
  1996. if (!!obj.headerbackimage) {
  1997. $(htmodelHead.getView()).css({
  1998. background: 'url(' + PAGEROOTDIR + obj.headerbackimage + ') no-repeat center center',
  1999. }).addClass('back-size100');
  2000. } else {
  2001. htmodelHead.getView().style.background = "-webkit-linear-gradient(" + obj.headcolor + "," + obj.headGradientcolor + ")"; //obj.headcolor+obj.headGradientcolor;//表头背景颜色
  2002. }
  2003. }
  2004. var isTextComps = function (node) {
  2005. if (node && node.getImage && node.getImage() == "node_image") {
  2006. return false;
  2007. } else {
  2008. return true;
  2009. }
  2010. }
  2011. //修改渐变方式
  2012. var setPrimitiveGradientType = function (node, gradienttype, nodename) {
  2013. if (!isTextComps(node)) {
  2014. if (gradienttype == "NoFill") {
  2015. node.s("shape.gradient", "");
  2016. node.s("shape.background", "");
  2017. node.s("shape.gradient.color", "");
  2018. } else {
  2019. node.s("shape.gradient", gradienttype);
  2020. }
  2021. } else {
  2022. //restRect.a("restRect"+".gradient","linear.north");
  2023. if (gradienttype == "NoFill") {
  2024. node.a("node.background", "");
  2025. node.a("node.gradient", "");
  2026. node.a("node.gradientcolor", "");
  2027. } else {
  2028. node.a("node.gradient", gradienttype);
  2029. }
  2030. }
  2031. }
  2032. //修改填充图形的渐变方式
  2033. // var setFillShapeColor=function(node,value,nodename,gradienttype,backcolor,forecolor,directfunc,borderfillwidth){
  2034. // node.a(nodename+".isFill","true");
  2035. // node.a(nodename+".borderwidth",borderfillwidth);
  2036. // if(value>1) {value=1}
  2037. // if(value<0) {value=0}
  2038. // var width= node.originWidth || node.getWidth();
  2039. // var height= node.originHeight || node.getHeight();
  2040. // var fillold= 0,fillrect= 0,rectFill=[0,0,0,0],rectOld=[0,0,0,0];
  2041. // if(directfunc==="Horizontal"){
  2042. // fillold=height*(1-value);
  2043. // fillrect=height*value;
  2044. // rectFill=[0,fillold,width,fillrect];
  2045. // rectOld=[0,0,width,fillold];
  2046. // }else{
  2047. // fillold=width*(1-value);
  2048. // fillrect=width*value;
  2049. // rectFill=[0,0,fillrect,height];
  2050. // rectOld=[fillrect,0,fillold,height];
  2051. // }
  2052. // if(node.a(nodename+".original")!=null){
  2053. // node.a(nodename+".original",rectOld);
  2054. // }
  2055. // if(node.a(nodename+".fillrect")!=null){
  2056. // node.a(nodename+".fillrect",rectFill);
  2057. // }
  2058. // if(gradienttype=="NoFill") {
  2059. // node.a(nodename+".fillbackcolor","");
  2060. // node.a(nodename+".fillgradient","");
  2061. // node.a(nodename+".fillgradientcolor","");
  2062. // }else{
  2063. // node.a(nodename+".fillgradient",gradienttype);
  2064. // }
  2065. // node.a(nodename+'.fillbackcolor',backcolor);
  2066. // node.a(nodename+'.fillgradientcolor',forecolor);
  2067. // }
  2068. var setFillShapeColor = function (node, value, nodename, gradienttype, backcolor, forecolor, directfunc) {
  2069. var borderfillwidth = node.borderFillwidth || 0;
  2070. node.a( "node.isFill", "true");
  2071. node.a( "node.borderwidth", borderfillwidth);
  2072. if (value > 1) {
  2073. value = 1
  2074. }
  2075. if (value < 0) {
  2076. value = 0
  2077. }
  2078. var width = node.getWidth();
  2079. var height = node.getHeight();
  2080. var fillold = 0,
  2081. fillrect = 0,
  2082. rectFill = [0, 0, 0, 0],
  2083. rectOld = [0, 0, 0, 0];
  2084. if (directfunc === "fromBottomToTop") {
  2085. fillold = height * (1 - value);
  2086. fillrect = height * value;
  2087. rectFill = [0, fillold, width, fillrect];
  2088. rectOld = [0, 0, width, fillold];
  2089. } else if (directfunc === "fromLeftToRight") {
  2090. fillold = width * (1 - value);
  2091. fillrect = width * value;
  2092. rectFill = [0, 0, fillrect, height];
  2093. rectOld = [fillrect, 0, fillold, height];
  2094. } else if (directfunc === "fromTopToBottom") {
  2095. fillold = height * (1 - value);
  2096. fillrect = height * value;
  2097. rectFill = [0, 0, width, fillrect];
  2098. rectOld = [0, fillrect, width, fillold];
  2099. } else if (directfunc === "fromRightToLeft") {
  2100. fillold = width * (1 - value);
  2101. fillrect = width * value;
  2102. rectFill = [fillold, 0, fillrect, height];
  2103. rectOld = [0, 0, fillold, height];
  2104. }
  2105. if (node.a( "node.original") != null) {
  2106. node.a( "node.original", rectOld);
  2107. }
  2108. if (node.a( "node.fillrect") != null) {
  2109. node.a( "node.fillrect", rectFill);
  2110. }
  2111. if (gradienttype == "NoFill") {
  2112. node.a( "node.fillbackcolor", "");
  2113. node.a( "node.fillgradient", "");
  2114. node.a( "node.fillgradientcolor", "");
  2115. } else {
  2116. node.a( "node.fillgradient", gradienttype);
  2117. }
  2118. node.a( 'node.fillbackcolor', backcolor);
  2119. node.a( 'node.fillgradientcolor', forecolor);
  2120. }
  2121. //将像素位置转换为HT位置
  2122. function toScreenPosition(p) {
  2123. var tx = graphView.tx();
  2124. var ty = graphView.ty();
  2125. var scale = graphview.getZoom();
  2126. return {
  2127. x: p.x * scale + tx,
  2128. y: p.y * scale + ty
  2129. };
  2130. }
  2131. //风机矩阵
  2132. var GraphPaneContainer = function (paneDataModel, x, y, width, height, backColor) {
  2133. var graphView = this._graphView = new ht.graph.GraphView(paneDataModel);
  2134. this._view = this._graphView.getView();
  2135. var style = this._view.style;
  2136. style.width = width + "px";
  2137. style.height = height + "px";
  2138. this.invalidate();
  2139. //graphView.fitContent(false,0,true);
  2140. };
  2141. ht.Default.def(GraphPaneContainer, Object, {
  2142. getView: function () {
  2143. return this._view;
  2144. },
  2145. getGraphView: function () {
  2146. return this._graphView;
  2147. },
  2148. invalidate: function () {
  2149. //ht.Default.callLater(this.validate, this);
  2150. },
  2151. validate: function () {
  2152. //var height = this._view.clientHeight;
  2153. //if(height < 0) height = 0;
  2154. //this._graphView.getView().style.height = height + 'px';
  2155. //this._graphView.invalidate();
  2156. }
  2157. });
  2158. function addNodeToContainer(quanjuDataModel, paneContainer, graphPane, nodesList) {
  2159. if (nodesList.length <= 0) return;
  2160. var paneDataModel = graphPane.getDataModel();
  2161. var containerBlockList = [],
  2162. block, nodes, node, width, maxWidth = 0,
  2163. maxNode, nx;
  2164. var allowChildScale = !!paneContainer._allowChildScale;
  2165. // paneDataModel._libModel = paneDataModel._libModel || new LibModel();
  2166. for (var i = 0; i < nodesList.length; i++) {
  2167. block = nodesList[i];
  2168. nodes = block.childNodes;
  2169. maxWidth = 0;
  2170. block.scalable = allowChildScale;
  2171. for (var j = 0, len = nodes.length; j < len; j++) {
  2172. node = nodes[j];
  2173. if (typeof node == 'undefined') continue;
  2174. node.scalable = allowChildScale;
  2175. // width = node.getWidth();
  2176. // if (width > maxWidth) {
  2177. // maxWidth = width;
  2178. // maxNode = node;
  2179. // }
  2180. // 图元容器内的图形不缩放,把已缩放的恢复
  2181. if (!allowChildScale) {
  2182. resizeOneNodes(node, 1 / ratio.ratioX, 1 / ratio.ratioY, true);
  2183. }
  2184. if (node._nodeType === 'pieDoughnut') { // 如果是环形图,要把内部的另外两个node也移动
  2185. (function () {
  2186. nx = node.__background;
  2187. nx && quanjuDataModel.remove(nx);
  2188. nx && paneDataModel.add(nx);
  2189. node.addChild(nx);
  2190. nx = node.__text;
  2191. nx && quanjuDataModel.remove(nx);
  2192. nx && paneDataModel.add(nx);
  2193. node.addChild(nx);
  2194. nx = node.__pie;
  2195. nx && quanjuDataModel.remove(nx);
  2196. nx && paneDataModel.add(nx);
  2197. node.addChild(nx);
  2198. })();
  2199. }
  2200. quanjuDataModel.remove(node);
  2201. paneDataModel.add(node);
  2202. }
  2203. // block.maxWidth = block.getWidth();
  2204. // block.maxNode = block;
  2205. // 重新计算图元大小
  2206. block.calcSize();
  2207. block.nodeList = nodes;
  2208. containerBlockList.push(block);
  2209. // dataModel._libModel.remove(block);
  2210. // paneDataModel._libModel.add(block);
  2211. }
  2212. graphPane.blockList = containerBlockList;
  2213. //把事件添加到容器上的graphView
  2214. copyEventFromView(graphPane, paneContainer)
  2215. }
  2216. function copyEventFromView(targetGraphView, targetGraphViewContainer) {
  2217. var eventList,
  2218. type,
  2219. offset,
  2220. beforeShow;
  2221. setTimeout(function () {
  2222. eventList = view && view.eventList || {};
  2223. for (var key in eventList) {
  2224. if (eventList.hasOwnProperty(key)) {
  2225. if (key === 'contextMenu') {
  2226. beforeShow = eventList[key].beforeShow || function () { };
  2227. eventList[key].beforeShow = function (e) {
  2228. if (targetGraphView && targetGraphView.getDataAt(e)) {
  2229. e.originEvent && e.originEvent.stopPropagation();
  2230. }
  2231. beforeShow.call(this, e, targetGraphView);
  2232. }
  2233. eventList[key].addTo(targetGraphView.getView())
  2234. } else {
  2235. targetGraphView.getView()['on'+key] = function (e) {
  2236. type = e.type;
  2237. offset = targetGraphViewContainer.getPosition();
  2238. // if (targetGraphView.getDataAt(e) && type !== 'mousemove') {
  2239. // e.stopPropagation();
  2240. // }
  2241. if (typeof eventList[type] === 'function') {
  2242. eventList[type](e, targetGraphView, {
  2243. x: offset.x - targetGraphViewContainer.getWidth() / 2,
  2244. y: offset.y - targetGraphViewContainer.getHeight() / 2
  2245. });
  2246. }
  2247. e.preventDefault();
  2248. };
  2249. }
  2250. }
  2251. }
  2252. }, 800)
  2253. }
  2254. function nodesToMap(mapcontainer, mapnode, nodes, nodenameDataModel, nodenameGraphView) {
  2255. if (nodes.length <= 0) return;
  2256. var position, lonLat, diagonalPoint, w, h, n, ns, z, isFixed,
  2257. offset = mapcontainer.getPosition();
  2258. graphView.graphViewList = graphView.graphViewList || [];
  2259. graphView.graphViewList.push(nodenameGraphView);
  2260. for (var i = 0; i < nodes.length; i++) {
  2261. ns = nodes[i] && nodes[i].node;
  2262. isFixed = nodes[i] && nodes[i].isFixed;
  2263. if (!ns) {
  2264. continue;
  2265. }
  2266. if (ns._baseClass && ns._baseClass.match('ht.lib.')) {
  2267. ns = ns.childNodes;
  2268. } else {
  2269. ns = [ns];
  2270. }
  2271. for (var j = 0, len = ns.length; j < len; j++) {
  2272. n = ns[j];
  2273. position = n.getPosition();
  2274. dataModel.remove(n);
  2275. w = n.getWidth();
  2276. h = n.getHeight();
  2277. lonLat = mapnode.pixelToPoint({
  2278. x: position.x - offset.x,
  2279. y: position.y - offset.y
  2280. });
  2281. diagonalPoint = mapnode.pixelToPoint({
  2282. x: position.x + w - offset.x,
  2283. y: position.y + h - offset.y
  2284. });
  2285. n.lonLat = lonLat;
  2286. n.diagonalPoint = diagonalPoint;
  2287. n.isFixed = isFixed;
  2288. if (isFixed) {
  2289. z = graphView.getZoom();
  2290. n.originPositionAndSize = {
  2291. x: (position.x - offset.x + mapcontainer.getWidth() / 2) * z,
  2292. y: (position.y - offset.y + mapcontainer.getHeight() / 2) * z,
  2293. w: n.getWidth(),
  2294. h: n.getHeight()
  2295. }
  2296. n.lonLat = null;
  2297. n.diagonalPoint = null;
  2298. }
  2299. nodenameDataModel.add(n);
  2300. }
  2301. }
  2302. //把事件添加到地图上的graphView
  2303. copyEventFromView(nodenameGraphView, mapcontainer)
  2304. }
  2305. ;
  2306. (function (window, BMap) {
  2307. if (!BMap) return;
  2308. BMap.HtNodeOverlay = function (htNode) {
  2309. this._htNode = htNode;
  2310. };
  2311. BMap.HtNodeOverlay.prototype = new BMap.Overlay();
  2312. BMap.HtNodeOverlay.prototype.initialize = function (map) {
  2313. var markerPane, mapSize, div, dataModel, graphView, node, view, w, h, self;
  2314. markerPane = map.getPanes().markerPane;
  2315. this._map = map;
  2316. self = this;
  2317. dataModel = new ht.DataModel;
  2318. graphView = new ht.graph.GraphView(dataModel);
  2319. view = graphView.getView();
  2320. node = this._htNode;
  2321. this._graphView = graphView;
  2322. this._dataModel = dataModel;
  2323. this._view = view;
  2324. w = node.getWidth();
  2325. h = node.getHeight();
  2326. node.setPosition(w / 2 + 1, h / 2 + 1);
  2327. view.style.width = w + 2 + 'px';
  2328. view.style.height = h + 2 + 'px';
  2329. view.style.postion = 'absolute';
  2330. view.style.overflow = 'visible';
  2331. graphView.setEditable = function (editable) {
  2332. var self = this;
  2333. this.setInteractors([])
  2334. }
  2335. graphView.setEditable(false);
  2336. markerPane.appendChild(view);
  2337. dataModel.add(node);
  2338. setTimeout(function () {
  2339. self.resetPosition();
  2340. }, 200)
  2341. return view;
  2342. }
  2343. BMap.HtNodeOverlay.prototype.draw = function () {
  2344. this.resetPosition();
  2345. }
  2346. BMap.HtNodeOverlay.prototype.resetPosition = function () {
  2347. var htNode = this._htNode;
  2348. var position = this._map.pointToOverlayPixel(htNode.lonLat);
  2349. var width = htNode.getWidth();
  2350. var height = htNode.getHeight();
  2351. var graphView = this._graphView;
  2352. var view = this._view;
  2353. view.style.left = position.x - width / 2 + 'px';
  2354. view.style.top = position.y - height / 2 + 'px';
  2355. }
  2356. BMap.HtNodeOverlay.prototype.show = function () {
  2357. var view = this._view;
  2358. view.style.display = '';
  2359. }
  2360. BMap.HtNodeOverlay.prototype.hide = function () {
  2361. var view = this._view;
  2362. view.style.display = 'none';
  2363. }
  2364. })(window, window.BMap);
  2365. function resetPosition(map, mapDataModel, mapGraphView, zoom) {
  2366. mapGraphView.tx(0);
  2367. mapGraphView.ty(0);
  2368. mapDataModel.each(function (data) {
  2369. var lonLat, position, diagonalPixel, w, h, z;
  2370. if (data instanceof ht.Node) {
  2371. if (!!data.lonLat && !data.isFixed) {
  2372. lonLat = data.lonLat;
  2373. position = map.pointToPixel(lonLat);
  2374. if (!!zoom) {
  2375. diagonalPixel = map.pointToPixel(data.diagonalPoint);
  2376. w = diagonalPixel.x - position.x;
  2377. h = diagonalPixel.y - position.y;
  2378. data.setWidth(w);
  2379. data.setHeight(h);
  2380. }
  2381. data.setPosition(position.x, position.y);
  2382. } else if (!!data.lonLat && data.isFixed) {
  2383. lonLat = data.lonLat;
  2384. position = map.pointToPixel(lonLat);
  2385. data.setPosition(position.x, position.y);
  2386. data.lonLat = null;
  2387. } else if (!!data.originPositionAndSize && data.isFixed) {
  2388. z = graphView.getZoom();
  2389. position = data.originPositionAndSize;
  2390. data.setPosition(position.x * z, position.y * z);
  2391. data.setWidth(position.w * z);
  2392. data.setHeight(position.h * z);
  2393. }
  2394. }
  2395. });
  2396. }
  2397. //将节点绑定到地图上
  2398. /*function createPageTooltip(node,x,y,backcolor,str){
  2399. node.setPosition(x+node.getWidth()*0.5,y+(node.getHeight()*0.5));
  2400. node.setHtml('<div style="border-radius: 4px; padding: 10px; color: #fff; background-color: ' + backcolor + ';">' + str + '</div>');
  2401. node.s('2d.visible',true);
  2402. }
  2403. function changeToolTipContent(node,backcolor,str){
  2404. if(typeof node!="undefined"){
  2405. node.setHtml('<div style="border-radius: 4px; padding: 10px; color: #fff; background-color: ' + backcolor + ';">' + str + '</div>');
  2406. }
  2407. }*/
  2408. function createPageTooltip(node, x, y, headStrInfo, bodyStrInfo,pos) {
  2409. GD.hideTagInfo();
  2410. pos = pos || 'def';
  2411. node.setPosition(x + node.getWidth() * 0.5, y + (node.getHeight() * 0.5));
  2412. node.setHtml('<div class="tooltip" ><div class="tooltop" style="background-color:' + headStrInfo.backColor + ';color:' + headStrInfo.fontColor + ';font:' + headStrInfo.fontSize + 'px ' + headStrInfo.fontFamily + ';padding:'+headStrInfo.padding+';"><span></span>' +
  2413. '<ul><li>' + headStrInfo.value + '</li></ul></div><div class="toolcon" style="background-color:' + bodyStrInfo.backColor + ';color:' + bodyStrInfo.fontColor + ';font:' + bodyStrInfo.fontSize + 'px ' + bodyStrInfo.fontFamily + ';padding:'+bodyStrInfo.padding+';"><ul><li>' +
  2414. bodyStrInfo.value + '</li></ul>' +
  2415. '</div></div>');
  2416. node.s('2d.visible', true);
  2417. node.tip = null;
  2418. // console.log(node.getWidth()+"-------------"+node.getHeight());
  2419. // console.log(x+"-------------"+y);
  2420. switch(pos.toLowerCase()){
  2421. case "up":
  2422. x=x-node.getWidth()/2,
  2423. y=y-node.getHeight()
  2424. break;
  2425. case "down":
  2426. x=x-node.getWidth()/2,
  2427. y=y+node.getHeight()/2
  2428. break;
  2429. case "left":
  2430. x=x-node.getWidth(),
  2431. y=y-node.getHeight()/2
  2432. break;
  2433. case "right":
  2434. x=x+node.getWidth()/2,
  2435. y=y-node.getHeight()/2
  2436. break;
  2437. case "leftup":
  2438. x=x-node.getWidth(),
  2439. y=y-node.getHeight()
  2440. break;
  2441. case "leftdown":
  2442. x=x-node.getWidth()
  2443. break;
  2444. case "rightup":
  2445. y=y-node.getHeight()
  2446. break;
  2447. }
  2448. //console.log(x+"-------------"+y);
  2449. createDomToolTip(node, x, y);
  2450. }
  2451. function changeToolTipContent(node, headStrInfo, bodyStrInfo) {
  2452. if (typeof node != "undefined" && node.s('2d.visible') === true) {
  2453. var html = '<div class="tooltop" style="background-color:' + headStrInfo.backColor + ';color:' + headStrInfo.fontColor + ';font:' + headStrInfo.fontSize + 'px ' + headStrInfo.fontFamily + ';padding:'+headStrInfo.padding+ ';"><span></span>' +
  2454. '<ul><li>' + headStrInfo.value + '</li></ul></div><div class="toolcon" style="background-color:' + bodyStrInfo.backColor + ';color:' + bodyStrInfo.fontColor + ';font:' + bodyStrInfo.fontSize + 'px ' + bodyStrInfo.fontFamily + ';padding:'+bodyStrInfo.padding+ ';"><ul><li>' +
  2455. bodyStrInfo.value + '</li></ul>' +
  2456. '</div>';
  2457. node.setHtml('<div class="tooltip">' + html + '</div>');
  2458. if (typeof node.getStyle === 'function' && node.getStyle('2d.visible'))
  2459. createDomToolTip(node, 0, 0, html);
  2460. }
  2461. }
  2462. function changeToolTipContentColor(node, headStrInfo, bodyStrInfo) {
  2463. if (typeof node != "undefined" && node.s('2d.visible') === true) {
  2464. var html = '<div class="tooltop" style="background-color:' + headStrInfo.backColor + ';color:' + headStrInfo.fontColor + ';font:' + headStrInfo.fontSize + 'px ' + headStrInfo.fontFamily +';padding:'+headStrInfo.padding+ ';"><span></span>' +
  2465. '<ul><li>' + headStrInfo.value + '</li></ul></div><div class="toolcon" style="background-color:' + bodyStrInfo.backColor + ';color:' + bodyStrInfo.fontColor + ';font:' + bodyStrInfo.fontSize + 'px ' + bodyStrInfo.fontFamily +';padding:'+bodyStrInfo.padding+ ';"><ul><li>' +
  2466. bodyStrInfo.value + '</li></ul>' +
  2467. '</div>';
  2468. node.setHtml('<div class="tooltip">' + html + '</div>');
  2469. if (typeof node.getStyle === 'function' && node.getStyle('2d.visible'))
  2470. createDomToolTip(node, 0, 0, html);
  2471. }
  2472. }
  2473. function getAlarmDataColor() {
  2474. var flagnum = 'datacolor'
  2475. var eventName = "/alarm/GetTagState";
  2476. if (window.socket != null && window.socket != "") {
  2477. socket.alarmPost(eventName, varList, function (data) {
  2478. if (data && data.success) {
  2479. var result = data.data;
  2480. alarmColorData = {};
  2481. for (var i = 0; i < result.length; i++) {
  2482. //报警中和已确认的变色
  2483. if (result[i].state == 2 || result[i].state == 4) {
  2484. alarmColorData[result[i].name.toLowerCase()] = ARGB2HexString(result[i].color);
  2485. }
  2486. }
  2487. }
  2488. });
  2489. }
  2490. }
  2491. function createDomToolTip(node, x, y, content) {
  2492. var $tip = node.tip || $(node.getHtml());
  2493. if (content) {
  2494. $tip.html(content);
  2495. return;
  2496. }
  2497. // 先隐藏其它悬浮窗,页面内只能同时有一个
  2498. destoryDomToolTip();
  2499. var totalWidth = $window.width();
  2500. var totalHeight = $window.height();
  2501. var nodeWidth = node.getWidth();
  2502. var nodeHeight = node.getHeight();
  2503. if (x + nodeWidth > totalWidth) {
  2504. x = x - nodeWidth;
  2505. }
  2506. if (y + nodeHeight > totalHeight) {
  2507. y = y - nodeHeight;
  2508. }
  2509. $tip.width('auto');
  2510. $tip.height('auto');
  2511. $tip.css({
  2512. position: 'absolute',
  2513. top: y,
  2514. left: x
  2515. })
  2516. $('body').append($tip);
  2517. node.tip = $tip;
  2518. }
  2519. function destoryDomToolTip() {
  2520. $('.tooltip').remove();
  2521. }
  2522. function canvasTextAutoLine(str, initX, initY, width, height, lineHeight, align, fillstyle, font, maucount, g) {
  2523. g.fillStyle = fillstyle;
  2524. g.font = font;
  2525. g.textAlign = align;
  2526. var ctx = g;
  2527. if (typeof str == "number") {
  2528. str = str.toString();
  2529. }
  2530. if (align == "center") {
  2531. initX += width * 0.5;
  2532. }
  2533. if (align == "right") {
  2534. initX += width;
  2535. }
  2536. var totalwidth = ctx.measureText(str).width;
  2537. var lineCount = Math.floor(totalwidth / width) + maucount;
  2538. initY = (height - (lineCount - 1) * lineHeight) / 2;
  2539. var lineWidth = 0;
  2540. var lastSubStrIndex = 0;
  2541. // for (var i = 0; i < str.length; i++) {
  2542. // lineWidth += ctx.measureText(str[i]).width;
  2543. // if (lineWidth > width || (str[i] == "\$" && str[i + 1] == "\#")) {
  2544. // ctx.fillText(str.substring(lastSubStrIndex, i).replace("\$\#", "\n"), initX, initY);
  2545. // initY += lineHeight;
  2546. // lineWidth = 0;
  2547. // lastSubStrIndex = i;
  2548. // }
  2549. // if (i == str.length - 1) {
  2550. // ctx.fillText(str.substring(lastSubStrIndex, i + 1).replace("\$\#", "\n"), initX, initY);
  2551. // }
  2552. // }
  2553. ctx.textBaseLine = 'top';
  2554. var _width = ctx.measureText('口').width;
  2555. var _count = Math.floor(width / _width);
  2556. var _lineCount = Math.ceil(str.length / _count);
  2557. var _height = _lineCount * lineHeight;
  2558. if (_height > height) {
  2559. initY = 0;
  2560. } else {
  2561. initY = (height-_height) * 0.5;
  2562. }
  2563. ctx.wrapFillText(str, initX, initY+lineHeight, width, lineHeight);
  2564. g.closePath();
  2565. }
  2566. if (CanvasRenderingContext2D.prototype.ellipse == undefined) {
  2567. CanvasRenderingContext2D.prototype.ellipse = function (x, y, radiusX, radiusY, rotation, startAngle, endAngle, antiClockwise) {
  2568. this.save();
  2569. this.translate(x, y);
  2570. this.rotate(rotation);
  2571. this.scale(radiusX, radiusY);
  2572. this.arc(0, 0, 1, startAngle, endAngle, antiClockwise);
  2573. this.restore();
  2574. }
  2575. }
  2576. if (!CanvasRenderingContext2D.prototype.wrapFillText) {
  2577. CanvasRenderingContext2D.prototype.wrapFillText = function(value, x, y, maxWidth, lineHeight) {
  2578. var ctx = this;
  2579. var fillStyle = this.font;
  2580. var getTextSize = (ht && ht.Default && ht.Default.getTextSize) || function(fillStyle, value) {
  2581. return {
  2582. width: ctx.measureText(value).width + 20,
  2583. height: ctx.measureText('口').width + 4
  2584. }
  2585. }
  2586. var textSize = getTextSize(fillStyle, value) || {};
  2587. if (textSize.width < maxWidth) {
  2588. ctx.fillText(value, x, y);
  2589. return;
  2590. }
  2591. lineHeight = lineHeight || textSize.height;
  2592. var arr = value.split('');
  2593. var testLine = '', line, l = arr.length - 1, lineCount = 0;
  2594. for (var i = 0, a; a = arr[i]; i++) {
  2595. line = testLine;
  2596. testLine += a;
  2597. if (ctx.measureText(testLine).width > maxWidth) {
  2598. if (testLine.length <= 1) {
  2599. line = a;
  2600. }
  2601. ctx.fillText(line, x, y + lineCount * lineHeight);
  2602. testLine = testLine.substr(line.length);
  2603. len = 0;
  2604. lineCount++;
  2605. }
  2606. }
  2607. testLine.length && ctx.fillText(testLine, x, y + lineCount * lineHeight);
  2608. }
  2609. }
  2610. //绘制圆角矩形
  2611. function drawRoundRect(g, x, y, width, height, nwidth, nheight, bordercolor, borderwidth) {
  2612. var nleft = x,
  2613. ntop = y,
  2614. rectwidth = width,
  2615. rectheight = height;
  2616. if (nwidth <= 0) {
  2617. nwidth = 1;
  2618. }
  2619. if (nheight <= 0) {
  2620. nheight = 1;
  2621. }
  2622. nwidth = nwidth * 2;
  2623. nheight = nheight * 2;
  2624. if (nwidth > rectwidth) {
  2625. nwidth = rectwidth;
  2626. }
  2627. if (nheight > rectheight) {
  2628. nheight = rectheight;
  2629. }
  2630. g.beginPath();
  2631. g.strokeStyle = bordercolor;
  2632. g.lineWidth = borderwidth || 1;
  2633. g.ellipse(nleft + 0.5 * nwidth, ntop + nheight * 0.5, nwidth * 0.5, nheight * 0.5, 0, Math.PI, Math.PI * 1.5);
  2634. g.lineTo((nleft + rectwidth - nwidth * 0.5), ntop);
  2635. g.ellipse(nleft + rectwidth - nwidth * 0.5, ntop + nheight * 0.5, nwidth * 0.5, nheight * 0.5, 0, Math.PI * 1.5, Math.PI * 2);
  2636. g.lineTo((nleft + rectwidth), ntop + rectheight - nheight * 0.5);
  2637. g.ellipse(nleft + rectwidth - nwidth * 0.5, ntop + rectheight - nheight * 0.5, nwidth * 0.5, nheight * 0.5, 0, 0, Math.PI * 0.5);
  2638. g.lineTo((nleft + 0.5 * nwidth), ntop + rectheight);
  2639. g.ellipse(nleft + 0.5 * nwidth, ntop + rectheight - nheight * 0.5, nwidth * 0.5, nheight * 0.5, 0, Math.PI * 0.5, Math.PI);
  2640. g.closePath();
  2641. g.stroke();
  2642. }
  2643. //绘制矩形
  2644. function drawRect(g, x, y, w, h, bordercolor) {
  2645. g.beginPath();
  2646. g.moveTo(x, y);
  2647. g.lineTo(w, y);
  2648. g.lineTo(w, h);
  2649. g.lineTo(x, h);
  2650. g.closePath();
  2651. if (!!bordercolor) {
  2652. g.strokeStyle = bordercolor;
  2653. g.stroke();
  2654. }
  2655. }
  2656. function getArrMatch(arr, str) {
  2657. if (arr.length <= 0) return;
  2658. for (var i = 0; i < arr.length; i++) {
  2659. var index = str.indexOf(arr[i]);
  2660. if (index > 0) {
  2661. return arr[i];
  2662. }
  2663. }
  2664. }
  2665. function setSnapshotValue(dataModel) {
  2666. var datas = dataModel._datas._as;
  2667. for (var i = 0; i < datas.length; i++) {
  2668. var data = dataModel.getDataById(datas[i]._id);
  2669. var tagname = data.a("configPointName");
  2670. data.a("snapvalue", getVarValue(tagname));
  2671. //VarSnapshotTime[tagname.toLowerCase()]
  2672. data.a("timestamp", VarSnapshotTime[tagname.toLowerCase()]);
  2673. }
  2674. }
  2675. //导出csv文件
  2676. function exportCsv(obj) {
  2677. var title = obj.title;
  2678. var titleForKey = obj.titleForKey;
  2679. var data = obj.data;
  2680. var str = [];
  2681. str.push(obj.title.join(",") + "\n");
  2682. for (var i = 0; i < data.length; i++) {
  2683. var temp = [];
  2684. for (var j = 0; j < titleForKey.length; j++) {
  2685. temp.push(data[i][titleForKey[j]]);
  2686. }
  2687. str.push(temp.join(",") + "\n");
  2688. }
  2689. var uri = 'data:text/csv;charset=utf-8,' + encodeURIComponent(str.join(""));
  2690. var downloadLink = document.createElement("a");
  2691. downloadLink.href = uri;
  2692. downloadLink.download = "export" + moment(new Date).format("YYYYMDDTHHmmss") + ".csv";
  2693. document.body.appendChild(downloadLink);
  2694. downloadLink.click();
  2695. document.body.removeChild(downloadLink);
  2696. }
  2697. /*
  2698. 十进制颜色值转16进制字符串
  2699. */
  2700. function ARGB2HexString(argbValue) {
  2701. if (argbValue > 0) {
  2702. var argbValue = parseInt(argbValue, 10);
  2703. var colorValue = argbValue.toString(16);
  2704. if (colorValue.length < 6) {
  2705. colorValue += "00";
  2706. }
  2707. }
  2708. return '#' + colorValue;
  2709. }
  2710. function exportInterExcel(starttime, endtime, interval, valueType, tagsInfo) {
  2711. if (!tagsInfo) {
  2712. tagsInfo = "";
  2713. }
  2714. var uri = "beginTime=" + starttime;
  2715. uri += "&endTime=" + endtime;
  2716. uri += "&interval=" + interval;
  2717. uri += "&tagName=" + encodeURIComponent(tagsInfo);
  2718. uri += "&valueType=" + valueType;
  2719. var link = document.createElement("a");
  2720. link.download = "exportExcel";
  2721. link.href = "http://" + webServiceIP + ":" + webServicePort +
  2722. "/api/ExportToExcelInterpo?" + encodeURI(uri);
  2723. link.click();
  2724. }
  2725. //获取百分比数据
  2726. function getPercentValue(value, min, max) {
  2727. if (!jQuery.isNumeric(Number(value))) {
  2728. return 0;
  2729. }
  2730. if (!jQuery.isNumeric(Number(min))) {
  2731. return 0;
  2732. }
  2733. if (!jQuery.isNumeric(Number(max))) {
  2734. return 0;
  2735. }
  2736. return (Number(value) - Number(min)) / (Number(max) - Number(min)) * 100;
  2737. }
  2738. // dataModel里所有的节点重新设置大小和位置
  2739. function resizeAllNodes(dm, ratioX, ratioY) {
  2740. if (!ratioX || !ratioY) {
  2741. return;
  2742. }
  2743. dm.each(function (d) {
  2744. resizeOneNodes(d, ratioX, ratioY);
  2745. })
  2746. // 重新计算图元大小
  2747. if (dm === dataModel) {
  2748. _libModel.each(function (data) {
  2749. resizeOneNodes(data, ratioX, ratioY);
  2750. })
  2751. }
  2752. }
  2753. function resizeOneNodes(d, ratioX, ratioY, force) {
  2754. var w, h, x, y, p, pas, _ratioX, _ratioY, _ratio, rotation;
  2755. if ((d.scalable === false || d.__parentLib || d.__blockChild) && !force) {
  2756. return;
  2757. }
  2758. ratioX = ratioX || graphView.ratioX;
  2759. ratioY = ratioY || graphView.ratioY;
  2760. if (d && typeof d.getRotation === 'function') {
  2761. rotation = d.getRotation() * 180 / Math.PI;
  2762. } else {
  2763. rotation = 0;
  2764. }
  2765. _ratio = GD.getRatioWithRotation(rotation * Math.PI / 180, ratioX, ratioY);
  2766. if (d._zoomBy) {
  2767. if (d._zoomBy === 'False' || d._zoomBy === 'false') {
  2768. _ratioX = 1;
  2769. _ratioY = 1;
  2770. } else if (d._zoomBy === 'Default') {
  2771. _ratioX = _ratio.ratioX;
  2772. _ratioY = _ratio.ratioY;
  2773. } else if (d._zoomBy === 'X') {
  2774. _ratioX = _ratio.ratioX;
  2775. _ratioY = _ratio.ratioX;
  2776. } else if (d._zoomBy === 'Y') {
  2777. _ratioX = _ratio.ratioY;
  2778. _ratioY = _ratio.ratioY;
  2779. }
  2780. } else {
  2781. _ratioX = _ratio.ratioX;
  2782. _ratioY = _ratio.ratioY;
  2783. }
  2784. w = d.getWidth();
  2785. h = d.getHeight();
  2786. p = d.getPosition();
  2787. x = p.x + 5;
  2788. y = p.y + 5;
  2789. d.originWidth = d.originWidth || w;
  2790. d.originHeight = d.originHeight || h;
  2791. d.originPosition = d.originPosition || p;
  2792. w *= _ratioX;
  2793. h *= _ratioY;
  2794. if (!!d.isEqualRatio) {
  2795. d.lastWidth = d.lastWidth || d.originWidth;
  2796. d.lastHeight = d.lastHeight || d.originHeight;
  2797. d.lastWidth *= _ratioX;
  2798. d.lastHeight *= _ratioY;
  2799. w = d.lastWidth > d.lastHeight ? d.lastHeight : d.lastWidth;
  2800. h = w;
  2801. }
  2802. d.setWidth(w);
  2803. d.setHeight(h);
  2804. d.setPosition(x * ratioX, y * ratioY);
  2805. if (d.originPositionAndSize) {
  2806. pas = d.originPositionAndSize;
  2807. pas.x *= ratioX;
  2808. pas.y *= ratioY;
  2809. pas.w *= _ratioX;
  2810. pas.h *= _ratioY;
  2811. }
  2812. }
  2813. // 绘制椭圆
  2814. function drawEllipse(ctx, x, y, w, h) {
  2815. var kappa = .5522848,
  2816. ox = (w / 2) * kappa, // control point offset horizontal
  2817. oy = (h / 2) * kappa, // control point offset vertical
  2818. xe = x + w, // x-end
  2819. ye = y + h, // y-end
  2820. xm = x + w / 2, // x-middle
  2821. ym = y + h / 2; // y-middle
  2822. ctx.beginPath();
  2823. ctx.moveTo(x, ym);
  2824. ctx.bezierCurveTo(x, ym - oy, xm - ox, y, xm, y);
  2825. ctx.bezierCurveTo(xm + ox, y, xe, ym - oy, xe, ym);
  2826. ctx.bezierCurveTo(xe, ym + oy, xm + ox, ye, xm, ye);
  2827. ctx.bezierCurveTo(xm - ox, ye, x, ym + oy, x, ym);
  2828. ctx.closePath(); // not used correctly, see comments (use to close off open path)
  2829. // ctx.stroke();
  2830. }
  2831. // 显示页面
  2832. function showPage() {
  2833. // graphView.setDataModel(dataModel);
  2834. graphView.tx(0);
  2835. graphView.ty(0);
  2836. graphView.setZoom(1);
  2837. document.body.appendChild(view);
  2838. setTimeout(function () {
  2839. window.refreshAlarmInfoWindow && refreshAlarmInfoWindow();
  2840. }, 500)
  2841. }
  2842. // 固定列表格
  2843. ; (function (W, $, ht) {
  2844. if (!ht) {
  2845. return;
  2846. }
  2847. ht.widget = ht.widget || {};
  2848. ht.widget.FrozenTable = function (dm) {
  2849. var self = this;
  2850. dm = dm || new ht.DataModel();
  2851. this._borderPane = new ht.widget.BorderPane();
  2852. this._frozenTablePane = new ht.widget.TablePane(dm);
  2853. this._normalTablePane = new ht.widget.TablePane(dm);
  2854. this._frozenTableHeader = this._frozenTablePane.getTableHeader();
  2855. this._frozenTableView = this._frozenTablePane.getTableView();
  2856. this._normalTableHeader = this._normalTablePane.getTableHeader();
  2857. this._normalTableView = this._normalTablePane.getTableView();
  2858. this._dm = dm;
  2859. this._selectionModel = dm.getSelectionModel();
  2860. this.init();
  2861. }
  2862. ht.Default.def('ht.widget.FrozenTable', Object, {
  2863. init: function () {
  2864. var frozenTableView = this.getFrozenTableView();
  2865. var normalTableView = this.getNormalTableView();
  2866. frozenTableView.setScrollBarSize(0);
  2867. this._borderPane.setLeftView(this._frozenTablePane, 200);
  2868. this._borderPane.setCenterView(this._normalTablePane);
  2869. frozenTableView.mp(function (e) {
  2870. if (e.property === 'translateY') {
  2871. normalTableView.ty(e.newValue);
  2872. }
  2873. });
  2874. normalTableView.mp(function (e) {
  2875. if (e.property === 'translateY') {
  2876. frozenTableView.ty(e.newValue);
  2877. }
  2878. });
  2879. this._setColumnClickEvent();
  2880. this._setDrawColumnFunc();
  2881. this.setAutoHideScrollBar(false);
  2882. },
  2883. getFrozenTableView: function () {
  2884. return this._frozenTableView;
  2885. },
  2886. getFrozenTableHeader: function () {
  2887. return this._frozenTableHeader;
  2888. },
  2889. setFrozentableScrollBarColor: function (color) {
  2890. this._normalTableView.setScrollBarColor(color);
  2891. },
  2892. getFrozentableScrollBarColor: function () {
  2893. return this._normalTableView.getScrollBarColor();
  2894. },
  2895. setFrozentableScrollBarSize: function (size) {
  2896. this._normalTableView.setScrollBarSize(size)
  2897. },
  2898. getFrozentableScrollBarSize: function () {
  2899. return this._normalTableView.getScrollBarSize();
  2900. },
  2901. getNormalTableView: function () {
  2902. return this._normalTableView;
  2903. },
  2904. getNormalTableHeader: function () {
  2905. return this._normalTableHeader;
  2906. },
  2907. getDataModel: function () {
  2908. return this._normalTableView.getDataModel();
  2909. },
  2910. getSelectionModel: function () {
  2911. return this._dm.getSelectionModel();;
  2912. },
  2913. calcColumnWidthByDisplayName: function (displayName, fontsize) {
  2914. fontsize = fontsize || 12;
  2915. fontsize *= 0.5;
  2916. var nameLen = GD.getStrLength(displayName);
  2917. return Math.ceil((nameLen + 4) * fontsize);
  2918. },
  2919. addColumns: function (columns) {
  2920. var frozenColumns = [];
  2921. var normalColumns = [];
  2922. var frozenTableWidth = 0;
  2923. var that = this;
  2924. function sortColumns(a, b) {
  2925. if (a.sortId > b.sortId) {
  2926. return 1;
  2927. } else if (a.sortId < b.sortId) {
  2928. return -1;
  2929. }
  2930. return 0;
  2931. }
  2932. for (var i = 0, len = columns.length; i < len; i++) {
  2933. if (!columns[i]) {
  2934. continue;
  2935. }
  2936. columns[i].sortable = false;
  2937. columns[i].width = columns[i].width ? columns[i].width : this.calcColumnWidthByDisplayName(columns[i].displayName);
  2938. if (!!columns[i].isFrozenColumn) {
  2939. frozenColumns.push(columns[i]);
  2940. if (columns[i].visible)
  2941. frozenTableWidth += columns[i].width;
  2942. } else {
  2943. normalColumns.push(columns[i]);
  2944. }
  2945. }
  2946. frozenColumns.sort(sortColumns);
  2947. normalColumns.sort(sortColumns);
  2948. frozenTableWidth += this._frozenTableView.isCheckMode() ? this._frozenTableView.getCheckColumn().getWidth() : 0;
  2949. this._frozenTableView.addColumns(frozenColumns);
  2950. this._normalTableView.addColumns(normalColumns);
  2951. this._borderPane.setLeftWidth(frozenTableWidth);
  2952. },
  2953. resetLeftPaneWidth: function () {
  2954. var w = 0;
  2955. columnModel = this._frozenTableView.getColumnModel();
  2956. columnModel.each(function (data) {
  2957. if (data.isVisible())
  2958. w += data.getWidth();
  2959. });
  2960. this._borderPane.setLeftWidth(w);
  2961. },
  2962. getBorderPane: function () {
  2963. return this._borderPane;
  2964. },
  2965. isCheckMode: function () {
  2966. return this._frozenTableView.isCheckMode();
  2967. },
  2968. setCheckMode: function (checkMode, fontOption) {
  2969. var that = this;
  2970. this._frozenTableView.setCheckMode(checkMode);
  2971. },
  2972. selectAll: function () {
  2973. var selectModel = this.getSelectionModel();
  2974. selectModel.selectAll();
  2975. },
  2976. invertSelection: function () {
  2977. var tableModel = this._dm;
  2978. var selectModel = this.getSelectionModel();
  2979. tableModel.each(function (item) {
  2980. if (selectModel.contains(item)) {
  2981. selectModel.removeSelection(item);
  2982. } else {
  2983. selectModel.appendSelection(item);
  2984. }
  2985. })
  2986. },
  2987. clearSelection: function () {
  2988. var selectionModel = this.getSelectionModel();
  2989. selectionModel.clearSelection();
  2990. },
  2991. setRowHeight: function (rowHeight) {
  2992. this._frozenTableView.setRowHeight(rowHeight);
  2993. this._normalTableView.setRowHeight(rowHeight);
  2994. this._normalTableHeader.setHeight(rowHeight);
  2995. this._frozenTableHeader.setHeight(rowHeight);
  2996. },
  2997. getRowHeight: function () {
  2998. return this._normalTableView.getHeight();
  2999. },
  3000. setHeaderHeight: function (height) {
  3001. if (!$.isNumeric(height)) {
  3002. return this;
  3003. }
  3004. height += 0;
  3005. this._frozenTableHeader.setHeight(height);
  3006. this._normalTableHeader.setHeight(height);
  3007. },
  3008. getHeaderHeight: function () {
  3009. return this._normalTableHeader.getHeight();
  3010. },
  3011. setBackground: function (backColor) {
  3012. this.getFrozenTableView().getView().style.background = backColor;
  3013. this.getNormalTableView().getView().style.background = backColor;
  3014. },
  3015. getCheckIcon: function (unSelData, selData) {
  3016. var sm = this._selectionModel;
  3017. this._selData = selData;
  3018. this._unSelData = unSelData;
  3019. this._frozenTableView.getCheckIcon = function (d) {
  3020. if (sm.contains(d)) {
  3021. return selData
  3022. }
  3023. return unSelData;
  3024. };
  3025. },
  3026. setHeaderGradientColor: function (headColor, headGradientcolor) {
  3027. this.getFrozenTableHeader().getView().style.background = "-webkit-linear-gradient(" + headColor + "," + headGradientcolor + ")"; //obj.headcolor+obj.headGradientcolor;//表头背景颜色
  3028. this.getNormalTableHeader().getView().style.background = "-webkit-linear-gradient(" + headColor + "," + headGradientcolor + ")"; //obj.headcolor+obj.headGradientcolor;//表头背景颜色
  3029. },
  3030. getLabelColor: function (fontColor) {
  3031. this.getFrozenTableHeader().getLabelColor = function () {
  3032. return fontColor;
  3033. }
  3034. this.getNormalTableHeader().getLabelColor = function () {
  3035. return fontColor;
  3036. }
  3037. },
  3038. getLabelFont: function (fontSize, fontFamily, fontStyle) {
  3039. this.getFrozenTableHeader().getLabelFont = function () {
  3040. return fontStyle + ' ' + fontSize * ratio.ratioY + "px " + fontFamily;
  3041. }
  3042. this.getNormalTableHeader().getLabelFont = function () {
  3043. return fontStyle + ' ' + fontSize * ratio.ratioY + "px " + fontFamily;
  3044. }
  3045. },
  3046. setHeaderLabelFont: function (fontSize, fontFamily, fontStyle) {
  3047. // this._headerLabelFont = fontStyle + ' ' + fontSize + "px " + fontFamily;
  3048. this._headerFontStyle = fontStyle;
  3049. this._headerFontSize = fontSize;
  3050. this._headerFontFamily = fontFamily;
  3051. },
  3052. setBodyLabelFont: function (fontSize, fontFamily, fontStyle) {
  3053. // this._bodyLabelFont = fontStyle + ' ' + fontSize + "px " + fontFamily;
  3054. this._bodyFontStyle = fontStyle;
  3055. this._bodyFontSize = fontSize;
  3056. this._bodyFontFamily = fontFamily;
  3057. },
  3058. getHeaderLabelFont: function () {
  3059. return this._headerFontStyle + ' ' + this._headerFontSize * ratio.ratioY + "px " + this._headerFontFamily;
  3060. },
  3061. getBodyLabelFont: function () {
  3062. return this._bodyFontStyle + ' ' + this._bodyFontSize * ratio.ratioY + "px " + this._bodyFontFamily;
  3063. },
  3064. setRowLineColor: function (lineColor) {
  3065. this._frozenTableView.setRowLineColor(lineColor);
  3066. this._normalTableView.setRowLineColor(lineColor);
  3067. // this._frozenTableHeader.setRowLineColor(lineColor);
  3068. // this._normalTableHeader.setRowLineColor(lineColor);
  3069. },
  3070. getRowLineColor: function () {
  3071. return this._normalTableView.getRowLineColor();
  3072. },
  3073. getColumnLineColor: function () {
  3074. return this._normalTableHeader.getColumnLineColor();
  3075. },
  3076. setColumnLineColor: function (lineColor) {
  3077. this._frozenTableHeader.setColumnLineColor(lineColor);
  3078. this._normalTableHeader.setColumnLineColor(lineColor);
  3079. this._frozenTableView.setColumnLineColor(lineColor);
  3080. this._normalTableView.setColumnLineColor(lineColor);
  3081. },
  3082. isColumnLineVisible: function () {
  3083. return this._normalTableHeader.isColumnLineVisible();
  3084. },
  3085. setColumnLineVisible: function (isVisible) {
  3086. this._normalTableHeader.setColumnLineVisible(isVisible);
  3087. this._frozenTableHeader.setColumnLineVisible(isVisible);
  3088. this._frozenTableView.setColumnLineVisible(isVisible);
  3089. this._normalTableView.setColumnLineVisible(isVisible);
  3090. },
  3091. setRowLineVisible: function (isVisible) {
  3092. this.getFrozenTableView().setRowLineVisible(isVisible);
  3093. this.getNormalTableView().setRowLineVisible(isVisible);
  3094. },
  3095. drawRowBackground: function (backColor, isRowAlter, rowAlterColor, selectedRowColor) {
  3096. var tableView,
  3097. self = this;
  3098. selectedRowColor = selectedRowColor || 'rgba(100, 100, 100, 0.3)';
  3099. function drawRowBack(g, data, selected, x, y, width, height) {
  3100. var index = this.getRowIndex(data);
  3101. if (isRowAlter) {
  3102. if (index % 2 == 0) {
  3103. g.fillStyle = backColor;
  3104. } else {
  3105. g.fillStyle = rowAlterColor;
  3106. }
  3107. } else {
  3108. g.fillStyle = backColor;
  3109. }
  3110. if (selected && selectedRowColor) {
  3111. g.fillStyle = selectedRowColor
  3112. }
  3113. g.beginPath();
  3114. g.rect(x, y, width, height);
  3115. g.fill();
  3116. }
  3117. self.getFrozenTableView().drawRowBackground = function () {
  3118. tableView = self.getFrozenTableView();
  3119. drawRowBack.apply(tableView, arguments);
  3120. }
  3121. self.getNormalTableView().drawRowBackground = function () {
  3122. tableView = self.getNormalTableView();
  3123. drawRowBack.apply(tableView, arguments);
  3124. }
  3125. },
  3126. drawCell: function (g, data, selected, column, x, y, w, h, tableView) {
  3127. var tagName = data._name + column._name;
  3128. var name = column.getName();
  3129. var columnData = column[name] || {};
  3130. var textAlign = 'center' || column.getAlign();
  3131. var text = data.a(name) || 0;
  3132. var color = columnData.a('color') || 'balck',
  3133. font = columnData.a('fontStyle') || null;
  3134. var selectedColor = columnData.a('selectedRowColor') || 'rgba(100, 100, 100, 0.3)';
  3135. var statusMap = columnData.a('statusMap') || [];
  3136. var statusArr = [];
  3137. var status = '';
  3138. var _x, _y;
  3139. function drawRoundRectPath(cxt, x, y, width, height, radius) {
  3140. cxt.moveTo(x + radius, y);
  3141. cxt.lineTo(x + width - radius, y);
  3142. cxt.arc(x + width - radius, y + radius, radius, Math.PI * 1.5, Math.PI * 2);
  3143. cxt.lineTo(x + width, y + height - radius);
  3144. cxt.arc(x + width - radius, y + height - radius, radius, 0, Math.PI * 0.5);
  3145. cxt.lineTo(x + radius, y + height);
  3146. cxt.arc(x + radius, y + height - radius, radius, Math.PI * 0.5, Math.PI);
  3147. cxt.lineTo(x, y + radius);
  3148. cxt.arc(x + radius, y + radius, radius, Math.PI, Math.PI * 1.5);
  3149. cxt.closePath();
  3150. }
  3151. // draw background
  3152. // g.fillStyle = selected ? selectedColor : 'rgba(0,0,0,0)';
  3153. // g.beginPath();
  3154. // g.rect(x, y, w, h);
  3155. // g.fill();
  3156. if (statusMap.length > 0) {
  3157. for (var i = 0, len = statusMap.length; i < len; i++) {
  3158. sk = statusMap[i] || {};
  3159. pt = parseFloat(text);
  3160. if (sk.min === 'min' && pt < sk.max) {
  3161. status = sk;
  3162. break;
  3163. }
  3164. if (pt >= sk.min && sk.max === 'max') {
  3165. status = sk;
  3166. break;
  3167. }
  3168. if ((pt >= sk.min && pt < sk.max) || (pt === sk.min && pt === sk.max)) {
  3169. status = sk;
  3170. break;
  3171. }
  3172. }
  3173. switch (textAlign) {
  3174. case 'center':
  3175. _x = x + w * 0.1;
  3176. _y = y + h / 4;
  3177. break;
  3178. case 'right':
  3179. _x = x + w * 0.2;
  3180. _y = y + h / 4;
  3181. break;
  3182. case 'left':
  3183. _x = x;
  3184. _y = y + h / 4;
  3185. break;
  3186. default:
  3187. _x = x;
  3188. _y = y + h / 4;
  3189. break;
  3190. }
  3191. status = status || {};
  3192. color = status.backColor || 'rgba(0,0,0,0)';
  3193. g.beginPath();
  3194. // g.fillStyle = selected ? ht.Default.darker(color) : color;
  3195. g.fillStyle = selected ? color : color;
  3196. drawRoundRectPath(g, _x, _y, w * 0.8, h * 0.5, 4);
  3197. g.fill();
  3198. }
  3199. // draw label
  3200. color = columnData.a('color');
  3201. // color = selected ? ht.Default.darker(color) : color;
  3202. //判断是否报警变色
  3203. if (alarmColorData[tagName.toLowerCase()]) {
  3204. color = alarmColorData[tagName.toLowerCase()];
  3205. }
  3206. if (status) {
  3207. color = status.fontColor;
  3208. text = status.text;
  3209. }
  3210. var textWidth = this.calcColumnWidthByDisplayName(text, this._bodyFontSize * ratio.ratioY);
  3211. if (textWidth > column.getWidth()) {
  3212. column.setWidth(textWidth);
  3213. this.resetLeftPaneWidth();
  3214. }
  3215. ht.Default.drawText(g, text, font, color, x, y, w, h, textAlign);
  3216. },
  3217. refresh: function (columnDM) {
  3218. var frozenTableView = this.getFrozenTableView(),
  3219. normalTableView = this.getNormalTableView(),
  3220. frozenTableColumnModel = frozenTableView.getColumnModel(),
  3221. normalTableColumnModel = normalTableView.getColumnModel(),
  3222. tempData;
  3223. columnDM && columnDM.each(function (cd) {
  3224. tempData = frozenTableColumnModel.getDataByTag(cd.a('name')) || normalTableColumnModel.getDataByTag(cd.a('name'));
  3225. tempData.setVisible(cd.a('visible'));
  3226. });
  3227. frozenTableView.redraw();
  3228. normalTableView.redraw();
  3229. },
  3230. redraw: function () {
  3231. var frozenTableView = this.getFrozenTableView(),
  3232. normalTableView = this.getNormalTableView();
  3233. frozenTableView.redraw();
  3234. normalTableView.redraw();
  3235. },
  3236. addRowData: function () {
  3237. var columnDM = this.getCustomDM('columnDM');
  3238. var rowDM = this.getCustomDM('rowDM');
  3239. var tableModel = this.getDataModel();
  3240. rowDM.each(function (data) {
  3241. var rowName = data.a('name');
  3242. var rowDisplayName = data.a('displayName');
  3243. var d = new ht.Data();
  3244. columnDM.each(function (dt) {
  3245. var columnName = dt.a('name');
  3246. var tag = '' + rowName + columnName;
  3247. d.a(columnName, getVarValue(tag));
  3248. if (columnName === 'device') {
  3249. d.a(columnName, rowDisplayName);
  3250. }
  3251. })
  3252. d.setName(rowName);
  3253. d.setTag(rowName);
  3254. d.a('displayName', rowDisplayName);
  3255. d.a('visible', data.a('visible'));
  3256. d.a('name', rowName);
  3257. tableModel.add(d);
  3258. })
  3259. },
  3260. refreshRowData: function () {
  3261. var tableModel = this.getDataModel(),
  3262. attrObj,
  3263. rowName;
  3264. tableModel.each(function (data) {
  3265. attrObj = data.getAttrObject();
  3266. rowName = data.getName();
  3267. for (var key in attrObj) {
  3268. if (attrObj.hasOwnProperty(key)) {
  3269. if (key === 'visible' || key === 'device' || key === 'displayName' || key === 'name') {
  3270. continue;
  3271. }
  3272. data.a(key, getVarValue(rowName + key));
  3273. }
  3274. }
  3275. });
  3276. this.getFrozenTableView().invalidateModel();
  3277. this.getNormalTableView().invalidateModel();
  3278. },
  3279. refreshStyleRowData: function (data) {
  3280. var tabledata = data;
  3281. var tableModel = this.getDataModel(),
  3282. attrObj,
  3283. rowName;
  3284. tableModel.each(function (data) {
  3285. attrObj = data.getAttrObject();
  3286. rowName = data.getName();
  3287. for (var i = 0; i < tabledata.length; i++) {
  3288. //var obj=tabledata[i]._attrObject;
  3289. if (attrObj.name == tabledata[i].name) {
  3290. data.a('visible', tabledata[i].visible);
  3291. break;
  3292. }
  3293. }
  3294. for (var key in attrObj) {
  3295. if (attrObj.hasOwnProperty(key)) {
  3296. if (key === 'visible' || key === 'device' || key === 'displayName' || key === 'name') {
  3297. continue;
  3298. }
  3299. data.a(key, getVarValue(rowName + key));
  3300. }
  3301. }
  3302. });
  3303. this.getFrozenTableView().invalidateModel();
  3304. this.getNormalTableView().invalidateModel();
  3305. },
  3306. addCustomDM: function (dmName, dm) {
  3307. if (this['_' + dmName]) {
  3308. return;
  3309. }
  3310. if (dm.constructor === ht.DataModel) {
  3311. this['_' + dmName] = dm;
  3312. } else {
  3313. this['_' + dmName] = new ht.DataModel();
  3314. }
  3315. },
  3316. getCustomDM: function (dmName) {
  3317. return this['_' + dmName];
  3318. },
  3319. setVisibleFunc: function (func) {
  3320. this.getNormalTableView().setVisibleFunc(func);
  3321. this.getFrozenTableView().setVisibleFunc(func);
  3322. },
  3323. getFrozenColumnModel: function () {
  3324. return this.getFrozenTableView().getColumnModel();
  3325. },
  3326. getNormalColumnModel: function () {
  3327. return this.getNormalTableView().getColumnModel();
  3328. },
  3329. clear: function () {
  3330. return this._dm.clear();
  3331. },
  3332. setAutoHideScrollBar: function (autoHide) {
  3333. this._normalTableView.setAutoHideScrollBar(autoHide);
  3334. },
  3335. defaultDisplayGridLine: function (display, rowCount, colCount) {
  3336. if (!display) {
  3337. return;
  3338. }
  3339. var dm = this.getDataModel();
  3340. for (var i = 0; i < rowCount; i++) {
  3341. var data = new ht.Data();
  3342. dm.add(data);
  3343. }
  3344. var columns = [];
  3345. for (i = 0; i < colCount; i++) {
  3346. var col = {};
  3347. col.displayName = '';
  3348. col.width = 100;
  3349. col.width = 100;
  3350. col.align = 'center';
  3351. if (i === 0) {
  3352. col.isFrozenColumn = true;
  3353. col.displayName = '时间';
  3354. } else {
  3355. col.isFrozenColumn = false;
  3356. }
  3357. columns.push(col);
  3358. }
  3359. this.addColumns(columns);
  3360. },
  3361. setDataModel: function (dataModel) {
  3362. this._dm = dataModel;
  3363. this._normalTableView.setDataModel(dataModel);
  3364. this._frozenTableView.setDataModel(dataModel);
  3365. },
  3366. sort: function (sortColumn, sortOrder) {
  3367. var newDM = new ht.DataModel();
  3368. var len = this._dm._datas._as.length;
  3369. if (sortOrder === 'default') {
  3370. if (this._defaultDM) {
  3371. // this.setDataModel(this._defaultDM);
  3372. this._copyDM2DataModel(this._defaultDM);
  3373. }
  3374. this._defaultDM = null;
  3375. return;
  3376. }
  3377. if (!this._defaultDM) {
  3378. this._defaultDM = new ht.DataModel();
  3379. this._defaultDM.deserialize(this._dm.serialize());
  3380. }
  3381. for (var i = 0; i < len; i++) {
  3382. newDM.add(this.getOrderData(sortColumn, sortOrder));
  3383. }
  3384. // this.setDataModel(newDM);
  3385. this._copyDM2DataModel(newDM);
  3386. },
  3387. getOrderData: function (sortColumn, sortOrder) {
  3388. var datas = this._dm._datas._as;
  3389. var data = datas[0];
  3390. var d1, d2;
  3391. for (var i = 1, len = datas.length; i < len; i++) {
  3392. d1 = data.a(sortColumn);
  3393. d2 = datas[i].a(sortColumn);
  3394. if ($.isNumeric(d1)) {
  3395. d1 = d1 - 0;
  3396. }
  3397. if ($.isNumeric(d2)) {
  3398. d2 = d2 - 0;
  3399. }
  3400. if (sortOrder === 'desc' || sortOrder === 'Desc' || sortOrder === 'DESC') {
  3401. d1 < d2 && (data = datas[i]);
  3402. } else {
  3403. d1 > d2 && (data = datas[i]);
  3404. }
  3405. }
  3406. this._dm.remove(data);
  3407. return data;
  3408. },
  3409. _copyDM2DataModel: function (dm1, dm2) {
  3410. if (!dm1) return;
  3411. var dm2 = dm2 || this.getDataModel();
  3412. dm2.clear();
  3413. dm2.deserialize(dm1.serialize());
  3414. },
  3415. _setColumnClickEvent: function () {
  3416. var that = this;
  3417. function func(column, event) {
  3418. var columnName = column.getName() || column.a('name') || column.getDisplayName() || column.a('displayName') || '';
  3419. var sortOrder = column.getSortOrder() || 'asc';
  3420. that.sort(columnName, sortOrder);
  3421. that._clearColumnIcon();
  3422. if (sortOrder === 'asc') {
  3423. column.setSortOrder('desc');
  3424. } else if (sortOrder === 'desc') {
  3425. column.setSortOrder('default');
  3426. } else if (sortOrder === 'default') {
  3427. column.setSortOrder('asc');
  3428. }
  3429. column._isCustomSortColumn = true;
  3430. }
  3431. this.onColumnClicked = func;
  3432. this._frozenTableView.onColumnClicked = func;
  3433. this._normalTableView.onColumnClicked = func;
  3434. },
  3435. _clearColumnIcon: function () {
  3436. var frozenColumnModel = this._frozenTableView.getColumnModel();
  3437. var normalColumnModel = this._normalTableView.getColumnModel();
  3438. frozenColumnModel.each(function (data) {
  3439. data._isCustomSortColumn = false;
  3440. data.setSortOrder('asc');
  3441. });
  3442. normalColumnModel.each(function (data) {
  3443. data._isCustomSortColumn = false;
  3444. data.setSortOrder('asc');
  3445. });
  3446. },
  3447. _setDrawColumnFunc: function (func) {
  3448. var that = this;
  3449. function defaultFunc(g, column, x, y, width, height) {
  3450. var displayName = column.getDisplayName() || column.a('displayName') || column.getName();
  3451. var color = column.getColor() || column.a('color') || "black";
  3452. var font = that.getHeaderLabelFont() || null;
  3453. var checkIcon;
  3454. if (column === that._frozenTableView.getCheckColumn()) {
  3455. if (that._frozenTableHeader._checkIcon === 'uncheck') {
  3456. checkIcon = that._unSelData;
  3457. } else {
  3458. checkIcon = that._selData;
  3459. }
  3460. ht.Default.drawImage(g, checkIcon, x + (width - checkIcon.width) * 0.5, y + (height - checkIcon.height) * 0.5, checkIcon.width, checkIcon.height, column, that._normalTableView);
  3461. return;
  3462. };
  3463. ht.Default.drawText(g, displayName, font, color, x, y, width, height, 'center');
  3464. that._selectAllBtn && that._selectAllBtn.setLabelFont(that.getHeaderLabelFont());
  3465. that._selectInvertBtn && that._selectInvertBtn.setLabelFont(that.getHeaderLabelFont());
  3466. var sortIcon, sortOrder;
  3467. sortOrder = column.hasOwnProperty('_sortOrder') ? column._sortOrder : '';
  3468. // 三种状态循环
  3469. switch (sortOrder) {
  3470. case 'desc':
  3471. sortIcon = that._normalTableHeader.getSortAscIcon();
  3472. break;
  3473. case 'default':
  3474. sortIcon = that._normalTableHeader.getSortDescIcon();
  3475. break;
  3476. case 'asc':
  3477. default:
  3478. sortIcon = null;
  3479. break;
  3480. }
  3481. if (!column._isCustomSortColumn) {
  3482. sortIcon = null;
  3483. }
  3484. ht.Default.drawImage(g, sortIcon, x + width - 14, y + (height - 16) * 0.5, 16, 16, column, that._normalTableView);
  3485. }
  3486. func = func || defaultFunc;
  3487. this._frozenTableHeader.drawColumn = func;
  3488. this._normalTableHeader.drawColumn = func;
  3489. },
  3490. validate: function () {
  3491. this._frozenTableView.validate();
  3492. this._normalTableView.validate();
  3493. }
  3494. })
  3495. })(window, jQuery, ht);
  3496. function batchOpertation(tagfirststr, tagsencondstr, value, quality, desc, groupid) {
  3497. if (tagfirststr.length <= 0) return;
  3498. var tagFirstNames = tagfirststr.split(";");
  3499. if (tagFirstNames.length <= 0) return;
  3500. var dataList = [],
  3501. groupid = groupid || 0;
  3502. for (var i = 0; i < tagFirstNames.length; i++) {
  3503. var data = {
  3504. TagName: tagFirstNames[i] + tagsencondstr,
  3505. Time: "",
  3506. Value: value,
  3507. Quality: quality
  3508. };
  3509. if (data.Time === "") {
  3510. data.Time = "1900-01-01 00:00:00";
  3511. }
  3512. dataList.push(data);
  3513. }
  3514. if (isAuthEnable == "True" && groupid >= 0) {
  3515. getAuthInfoByGroupId(groupid, function (data) {
  3516. if (data) {
  3517. submitBatch(dataList, desc);
  3518. }
  3519. });
  3520. } else if (isAuthEnable == "True" && groupid == -1) {
  3521. submitBatch(dataList, desc);
  3522. } else {
  3523. submitBatch(dataList, desc);
  3524. }
  3525. // submitBatch(dataList, desc, groupid);
  3526. }
  3527. function submitBatch(_data, desc) {
  3528. desc = desc || '';
  3529. if (!isdowncontrol()) {
  3530. return;
  3531. }
  3532. var jsonStr = JSON.stringify(_data);
  3533. $.ajax({
  3534. url: "http://" + webServiceIP + ":" + webServicePort + "/api/Snapshot/",
  3535. type: "POST",
  3536. data: jsonStr,
  3537. contentType: "application/json; charset=utf-8",
  3538. success: function (data) {
  3539. if ((typeof data == 'string') && data.constructor == String) //数据库版本2.x
  3540. {
  3541. if (data !== "True")
  3542. GD.createErrorDialog(360, 160, data);
  3543. } else ////数据库版本3.x
  3544. {
  3545. var errorList = data.ErrorList;
  3546. if (errorList != null && errorList.length > 0) {
  3547. GD.createErrorDialog(360, 160, errorList[0].ErrorMsg);
  3548. } else {
  3549. (function () {
  3550. var varName, value, groupid, d, quality;
  3551. groupid = GD.getParams('userGroup') || 0;
  3552. for (var i = 0, len = _data.length; i < len; i++) {
  3553. d = _data[i];
  3554. varName = d.TagName || '';
  3555. value = d.Value;
  3556. quality = d.Quality;
  3557. addOpera(varName, varName.split('.')[0], value, groupid, desc, quality, function (data) {
  3558. });
  3559. }
  3560. })();
  3561. }
  3562. }
  3563. },
  3564. error: function (data) {
  3565. if (data.responseText === "")
  3566. GD.createErrorDialog(360, 160, '网络链接错误');
  3567. else
  3568. GD.createErrorDialog(360, 160, data.responseText);
  3569. },
  3570. complete: function (XHR, TS) {
  3571. XHR = null;
  3572. }
  3573. });
  3574. }
  3575. function convertNumberToIntAndFloat(text, precision) {
  3576. var result = {},
  3577. textArr,
  3578. textObj;
  3579. text = parseFloat(text);
  3580. text = text ? text : 0;
  3581. precision = parseInt(precision);
  3582. precision = precision !== precision ? 2 : precision;
  3583. text = text.toFixed(precision, 10);
  3584. textArr = text.split('.');
  3585. result.int = textArr[0];
  3586. result.float = textArr[1] || '0';
  3587. return result;
  3588. }
  3589. function searchStrToObj(searchStr) {
  3590. var searchArr, tempArr, result = {};
  3591. searchStr = searchStr || window.location.search;
  3592. searchStr = decodeURIComponent(searchStr);
  3593. searchStr = searchStr.indexOf('?') === -1 ? searchStr : searchStr.substr(searchStr.indexOf('?') + 1);
  3594. searchArr = searchStr.split('&');
  3595. for (var i = 0, len = searchArr.length; i < len; i++) {
  3596. if (searchArr[i].indexOf('=') === -1) {
  3597. continue;
  3598. }
  3599. tempArr = searchArr[i].split('=');
  3600. if (!!tempArr[1]) {
  3601. result[tempArr[0]] = tempArr[1];
  3602. }
  3603. }
  3604. return result;
  3605. }
  3606. ; (function (W, $, ht) {
  3607. if (!ht) {
  3608. return;
  3609. }
  3610. W.pageContainerFactory = function (x, y, width, height, angle, src) {
  3611. var htmlNode = new ht.HtmlNode();
  3612. var $content, timer;
  3613. $content = $('<iframe src="' + src + '" name="pageContainer" width = ' + width + ' height = ' + height + ' frameborder="0" ></iframe>');
  3614. htmlNode.setScalable(false);
  3615. htmlNode.setPadding(0);
  3616. htmlNode.setHtml($content[0]);
  3617. htmlNode.setWidth(width);
  3618. htmlNode.setHeight(height);
  3619. htmlNode.setPosition(x, y);
  3620. htmlNode.setRotation(angle * Math.PI / 180);
  3621. htmlNode.s({
  3622. '2d.selectable': true,
  3623. '2d.movable': false
  3624. })
  3625. htmlNode.__clickable = false;
  3626. htmlNode.changeSrc = function (src) {
  3627. if (!src) {
  3628. return;
  3629. }
  3630. $content.attr('src', src);
  3631. }
  3632. htmlNode.changeWidth = function (width) {
  3633. $content.attr('width', width);
  3634. htmlNode.setWidth(width);
  3635. }
  3636. htmlNode.changeHeight = function (height) {
  3637. $content.attr('height', height);
  3638. htmlNode.setHeight(height);
  3639. }
  3640. htmlNode.changeAttr = function (src, width, height) {
  3641. this.changeSrc(src);
  3642. this.changeWidth(width);
  3643. this.changeHeight(height);
  3644. }
  3645. htmlNode.refresh = function () {
  3646. $content.attr('src', $content.attr('src'));
  3647. }
  3648. htmlNode.resizeContent = function (ratioX, ratioY, zoom) {
  3649. var self = this;
  3650. $content.on('load', function () {
  3651. $content[0].contentWindow.postMessage({
  3652. action: 'resizeNodes',
  3653. args: {
  3654. ratioX: ratioX,
  3655. ratioY: ratioY,
  3656. zoom: zoom
  3657. }
  3658. }, '*');
  3659. });
  3660. }
  3661. return htmlNode;
  3662. }
  3663. })(window, jQuery, ht);
  3664. (function (W, $, ht) {
  3665. if (!ht || !$) {
  3666. return;
  3667. }
  3668. W.paginationFactory = function (totalPages, visiblePages, currentPage) {
  3669. var $pagination = $('<ul class="pagination"></ul>');
  3670. $.jqPaginator($pagination, {
  3671. totalPages: totalPages,
  3672. visiblePages: visiblePages || 5,
  3673. currentPage: currentPage || 1,
  3674. prev: '<li class="prev"><a href="javascript:;">上一页</a></li>',
  3675. next: '<li class="next"><a href="javascript:;">下一页</a></li>',
  3676. page: '<li class="page"><a href="javascript:;">{{page}}</a></li>',
  3677. onPageChange: function (num, type) {
  3678. typeof $pagination.onPageChange === 'function' && $pagination.onPageChange(num, type);
  3679. }
  3680. });
  3681. return $pagination;
  3682. }
  3683. })(window, jQuery, ht);
  3684. // 监听对象属性变化方法
  3685. (function () {
  3686. if (!Object.prototype.watch) {
  3687. Object.defineProperty(Object.prototype, "watch", {
  3688. enumerable: false,
  3689. configurable: true,
  3690. writable: false,
  3691. value: function (prop, handler) {
  3692. var
  3693. oldval = this[prop],
  3694. newval = oldval,
  3695. getter = function () {
  3696. return newval;
  3697. },
  3698. setter = function (val) {
  3699. oldval = newval;
  3700. return newval = handler.call(this, prop, oldval, val);
  3701. };
  3702. if (delete this[prop]) { // can't watch constants
  3703. Object.defineProperty(this, prop, {
  3704. get: getter,
  3705. set: setter,
  3706. enumerable: true,
  3707. configurable: true
  3708. });
  3709. }
  3710. }
  3711. });
  3712. }
  3713. // object.unwatch
  3714. if (!Object.prototype.unwatch) {
  3715. Object.defineProperty(Object.prototype, "unwatch", {
  3716. enumerable: false,
  3717. configurable: true,
  3718. writable: false,
  3719. value: function (prop) {
  3720. var val = this[prop];
  3721. delete this[prop]; // remove accessors
  3722. this[prop] = val;
  3723. }
  3724. });
  3725. }
  3726. })();
  3727. var getIndicatorAndSheBeiArr = function (equipObj, indicatorObj) {
  3728. var obj = {};
  3729. var shebeiArr = [];
  3730. var indicatorArr = [];
  3731. var colorArr = [];
  3732. var statisticsTypeObj = {};
  3733. var tagArr = [],
  3734. tag;
  3735. for (var i = 0; i < indicatorObj.length; i++) {
  3736. var dName = indicatorObj[i]["displayName"] || indicatorObj[i]["Desc"];
  3737. indicatorArr.push(dName);
  3738. colorArr.push(indicatorObj[i]['color']);
  3739. }
  3740. for (var j = 0; j < equipObj.length; j++) {
  3741. shebeiArr.push(equipObj[j]["displayName"]);
  3742. }
  3743. for (var i = 0, len = equipObj.length; i < len; i++) {
  3744. for (var j = 0, leng = indicatorObj.length; j < leng; j++) {
  3745. tag = '' + equipObj[i].Name + indicatorObj[j].Name;
  3746. tagArr.push(tag);
  3747. var statisticsType = indicatorObj[j]['statisticsType'];
  3748. if (statisticsType) {
  3749. switch (statisticsType.toLowerCase()) {
  3750. case 'min':
  3751. statisticsType = 'Min';
  3752. break;
  3753. case 'max':
  3754. statisticsType = 'Max';
  3755. break;
  3756. case 'avg':
  3757. case 'calcavg':
  3758. statisticsType = 'CalcAvg';
  3759. break;
  3760. case 'difference':
  3761. statisticsType = 'Difference';
  3762. break;
  3763. case 'total':
  3764. statisticsType = 'Total';
  3765. break;
  3766. case 'poweravg':
  3767. statisticsType = 'PowerAvg';
  3768. break;
  3769. }
  3770. }
  3771. statisticsTypeObj[tag] = statisticsType
  3772. }
  3773. }
  3774. obj["shebeiArr"] = shebeiArr;
  3775. obj["indicatorArr"] = indicatorArr;
  3776. obj['tagArr'] = tagArr;
  3777. obj['colorArr'] = colorArr;
  3778. obj['statisticsTypeObj'] = statisticsTypeObj;
  3779. return obj;
  3780. };
  3781. //获取series
  3782. var getIndicatorOrShebeiInfo = function (equipObj, indicatorObj, seriesStyle) {
  3783. var series = [];
  3784. for (var i = 0; i < indicatorObj.length; i++) {
  3785. var seriesData = [],
  3786. _type = indicatorObj[i]['DrawType'] === 0 ? 'bar' : 'line',
  3787. _smooth = indicatorObj[i]['DrawType'] === 2;
  3788. for (var j = 0; j < equipObj.length; j++) {
  3789. var tagValue = '' + equipObj[j].Name + indicatorObj[i].Name;
  3790. seriesData.push(parseFloat(getVarValue(tagValue)));
  3791. }
  3792. series.push({
  3793. name: indicatorObj[i]["displayName"] || indicatorObj[i]["Desc"],
  3794. type: _type,
  3795. smooth: _smooth,
  3796. data: seriesData,
  3797. itemStyle: {
  3798. normal: {
  3799. shadowBlur: 10,
  3800. shadowOffsetX: 10,
  3801. shadowOffsetY: 10,
  3802. shadowColor: seriesStyle.shadowColor,
  3803. // color: indicatorObj[i].color
  3804. },
  3805. emphasis: {
  3806. shadowBlur: 10,
  3807. shadowOffsetX: 10,
  3808. shadowOffsetY: 10,
  3809. shadowColor: seriesStyle.shadowColor
  3810. }
  3811. }
  3812. });
  3813. }
  3814. return series;
  3815. }
  3816. // 获取相对时间,如昨天,今天,明天,上周,本周,上个月,本月, 上一年,本年等, 传入参数为一个固定时间,原样返回
  3817. function getRelativeDate(paras, format, beginOrEnd) {
  3818. var d = new Date();
  3819. var typeMap = {
  3820. date: 'YYYY-MM-DD',
  3821. time: 'HH:mm:ss',
  3822. datetime: 'YYYY-MM-DD HH:mm:ss',
  3823. year: 'YYYY',
  3824. month: 'YYYY-MM'
  3825. }
  3826. function formatDate(date, format) {
  3827. var result = moment(date).format(typeMap[format] || typeMap.datetime);
  3828. return result === 'Invalid date' ? date : result;
  3829. }
  3830. function calcRelativeDate(date, type) {
  3831. var count = parseInt(type);
  3832. if (count !== count) {
  3833. return type;
  3834. }
  3835. var t = type.substr(count.toString().length);
  3836. switch (t) {
  3837. case 'h':
  3838. case 'hour':
  3839. date.setHours(date.getHours() - count);
  3840. break;
  3841. case 'd':
  3842. case 'day':
  3843. date.setDate(date.getDate() - count);
  3844. break;
  3845. case 'm':
  3846. case 'month':
  3847. date.setMonth(date.getMonth() - count);
  3848. break;
  3849. case 'y':
  3850. case 'year':
  3851. date.setFullYear(date.getFullYear() - count);
  3852. break;
  3853. default:
  3854. date = type;
  3855. break;
  3856. }
  3857. return date;
  3858. }
  3859. if ('begin' === beginOrEnd) {
  3860. d.setHours(0);
  3861. d.setMinutes(0);
  3862. d.setSeconds(0);
  3863. d.setMilliseconds(0);
  3864. } else if ('end' === beginOrEnd) {
  3865. d.setHours(23);
  3866. d.setMinutes(59);
  3867. d.setSeconds(59);
  3868. d.setMilliseconds(0);
  3869. }
  3870. if (paras === '') { // 如果参数为空则返回当前时间
  3871. return formatDate(d, format);
  3872. }
  3873. d = calcRelativeDate(d, paras);
  3874. return formatDate(d, format);
  3875. }
  3876. // tabView 中添加tab
  3877. function createTab(tabView, item) {
  3878. var tabModel = tabView.getTabModel();
  3879. var tab = new ht.Tab();
  3880. tab.setName(item.name);
  3881. tab.setTag(item.name);
  3882. // tab.setView(item.innerView);
  3883. tab.setView(item.view);
  3884. tab.a('currentData', item.currentData);
  3885. // tab.a('curAlarmIndex', item.curAlarmIndex); index
  3886. tab.a('curAlarmIndex', item.index);
  3887. tabModel.add(tab);
  3888. if (item.selected) {
  3889. tabModel.getSelectionModel().setSelection(tab);
  3890. }
  3891. }
  3892. // 创建带有tab页的弹窗 config: {title: '', titleIcon: ''}, tabConfig: [{name: '', view: '', selected: false}]
  3893. function createDialogWithTabView(config, tabConfig, twinkle, tablestyle) {
  3894. var dialog = new ht.widget.Dialog();
  3895. var tabView = new ht.widget.TabView();
  3896. tabConfig.forEach(function (item, index) {
  3897. createTab(tabView, item);
  3898. });
  3899. // tabView.setTabBackground('rgb(12, 77, 85)');
  3900. tabView.setLabelColor(tablestyle.paneSysFontColor);
  3901. tabView.setTabBackground(tablestyle.paneSysBackColor);
  3902. tabView.onTabChanged = tabConfig.onTabChanged;
  3903. config.content = tabView;
  3904. dialog.setConfig(config);
  3905. dialog.tabView = tabView;
  3906. dialog.tabModel = tabView.getTabModel();
  3907. var $dialog = $(dialog.getView());
  3908. var $dialogContainer = $dialog.find('.dialog-container');
  3909. var $dialogContainerTitle = $dialogContainer.find('.dialog-container-title');
  3910. var twinkleFlag = false;
  3911. var dialogHeight = $dialogContainer.height();
  3912. var dialogTop = parseInt($dialogContainer.css('top'));
  3913. var dialogTitleHeight = $dialogContainerTitle.height() || 24;
  3914. $dialogContainer.css({
  3915. 'zIndex': 99,
  3916. 'top': '',
  3917. 'left': '',
  3918. 'right': '5px',
  3919. 'bottom': '28px'
  3920. });
  3921. $dialogContainerTitle.find('span').html('待确认故障<strong>10</strong>项');
  3922. dialog.$dialogTitle = $dialogContainerTitle.find('span>strong');
  3923. var $minimize = $('<strong>—<strong>');
  3924. $minimize.click(function (e) {
  3925. e.stopPropagation();
  3926. var str = $minimize.text();
  3927. if (str === '—') {
  3928. $dialogContainerTitle.siblings().css('display', 'none');
  3929. $minimize.text('+');
  3930. $dialogContainer.css({
  3931. top: dialogTop + dialogHeight - dialogTitleHeight,
  3932. height: 'auto'
  3933. });
  3934. } else {
  3935. $dialogContainer.css({
  3936. top: dialogTop,
  3937. height: dialogHeight
  3938. });
  3939. $dialogContainerTitle.siblings().css('display', '');
  3940. $minimize.text('—');
  3941. }
  3942. });
  3943. $dialogContainerTitle.find('.dialog-title-controls').html($minimize);
  3944. setTimeout(function () {
  3945. $dialogContainer.css('opacity', 0.3);
  3946. $dialogContainer.off('mouseenter').on('mouseenter', function (e) {
  3947. e.stopPropagation();
  3948. $dialogContainer.css('opacity', 1);
  3949. }).off('mouseleave').on('mouseleave', function (e) {
  3950. e.stopPropagation();
  3951. $dialogContainer.css('opacity', 0.3);
  3952. });
  3953. }, 3000);
  3954. if (twinkle) {
  3955. setInterval(function () {
  3956. // var bkc = twinkleFlag ? 'rgb(249, 37, 38)' : 'rgb(12, 77, 85)';
  3957. var bkc = twinkleFlag ? tablestyle.paneTitleChangeBackColor : tablestyle.paneTitleBackColor;
  3958. $dialogContainerTitle.css('backgroundColor', bkc);
  3959. $dialogContainer.css('backgroundColor', bkc);
  3960. twinkleFlag = !twinkleFlag;
  3961. }, 1000);
  3962. }
  3963. return dialog;
  3964. }
  3965. function createDialogAlarm(alarmInfoDialog, config, twinkle, tablestyle, sysname) {
  3966. var dialog;
  3967. if (typeof (alarmInfoDialog) == "undefined") {
  3968. dialog = new ht.widget.Dialog();
  3969. } else {
  3970. dialog = alarmInfoDialog
  3971. }
  3972. dialog.setConfig(config);
  3973. var $dialog = $(dialog.getView());
  3974. var $dialogContainer = $dialog.find('.dialog-container');
  3975. var $dialogContainerTitle = $dialogContainer.find('.dialog-container-title');
  3976. var twinkleFlag = false;
  3977. var dialogHeight = $dialogContainer.height();
  3978. var dialogTop = parseInt($dialogContainer.css('top'));
  3979. var dialogTitleHeight = $dialogContainerTitle.height() || 28;
  3980. var ensureBtnWidth = parseInt(tablestyle.paneBtnWidth) || 50,
  3981. ensureBtnHeight = parseInt(tablestyle.paneBtnHeight) || 26;
  3982. var $dialogBtns = $dialogContainer.find('.dialog-container-buttons');
  3983. $dialogBtns.css('padding-bottom', '10px');
  3984. $dialogBtns.css('padding-right', ensureBtnWidth / 2 + 'px');
  3985. var $btn = $dialogBtns.find('.dialog-button');
  3986. var $content = $('<div></div>');
  3987. $content.css({
  3988. position: 'absolute',
  3989. width: ensureBtnWidth,
  3990. height: ensureBtnHeight,
  3991. lineHeight: ensureBtnHeight + 'px',
  3992. backgroundColor: tablestyle.paneBtnBackColor,
  3993. textAlign: 'center',
  3994. fontSize: tablestyle.paneBtnFontSize + 'px',
  3995. color: tablestyle.paneBtnFontColor,
  3996. fontFamily: tablestyle.paneBtnFontFamily,
  3997. cursor: 'pointer'
  3998. })
  3999. $content.text('确 认');
  4000. $btn.prepend($content).find('canvas').css({ visibility: 'hidden' });
  4001. $dialogContainer.css({
  4002. 'zIndex': 99,
  4003. 'top': '',
  4004. 'left': '',
  4005. 'right': '5px',
  4006. 'bottom': '28px'
  4007. });
  4008. // $dialogContainerTitle.find('span').html('待确认故障<strong>10</strong>项');
  4009. $dialogContainerTitle.find('span').html(sysname);
  4010. $dialogContainerTitle.find('span').css('color', tablestyle.paneTitleFontColor);
  4011. $dialogContainerTitle.find('span').css('font', tablestyle.paneTitleFontSize + 'px ' + tablestyle.paneTitleFontFamily);
  4012. dialog.$dialogTitle = $dialogContainerTitle.find('span>strong');
  4013. var $minimize = $('<strong>—<strong>');
  4014. $minimize.click(function (e) {
  4015. e.stopPropagation();
  4016. var str = $minimize.text();
  4017. if (str === '—') {
  4018. $dialogContainerTitle.siblings().css('display', 'none');
  4019. $minimize.text('+');
  4020. $dialogContainer.css({
  4021. top: dialogTop + dialogHeight - dialogTitleHeight,
  4022. height: 'auto'
  4023. });
  4024. } else {
  4025. $dialogContainer.css({
  4026. top: dialogTop,
  4027. height: dialogHeight
  4028. });
  4029. $dialogContainerTitle.siblings().css('display', '');
  4030. $minimize.text('—');
  4031. }
  4032. });
  4033. $dialogContainerTitle.find('.dialog-title-controls').html($minimize);
  4034. setTimeout(function () {
  4035. $dialogContainer.css('opacity', 0.78);
  4036. $dialogContainer.off('mouseenter').on('mouseenter', function (e) {
  4037. e.stopPropagation();
  4038. $dialogContainer.css('opacity', 1);
  4039. }).off('mouseleave').on('mouseleave', function (e) {
  4040. e.stopPropagation();
  4041. $dialogContainer.css('opacity', 0.78);
  4042. });
  4043. }, 3000);
  4044. if (twinkle) {
  4045. setInterval(function () {
  4046. var bkc = twinkleFlag ? tablestyle.paneTitleChangeBackColor : tablestyle.paneTitleBackColor;
  4047. $dialogContainerTitle.css('backgroundColor', bkc);
  4048. $dialogContainer.css('backgroundColor', bkc);
  4049. twinkleFlag = !twinkleFlag;
  4050. }, 1000);
  4051. }
  4052. return dialog;
  4053. }
  4054. function loadScript(url, callback) {
  4055. callback = callback || function () { };
  4056. var script = document.createElement("script")
  4057. script.type = "text/javascript";
  4058. if (script.readyState) { //IE
  4059. script.onreadystatechange = function () {
  4060. if (script.readyState == "loaded" ||
  4061. script.readyState == "complete") {
  4062. script.onreadystatechange = null;
  4063. callback();
  4064. }
  4065. };
  4066. } else { //Others
  4067. script.onload = function () {
  4068. callback();
  4069. };
  4070. script.onerror = function (e) {
  4071. GD.createErrorDialog(420, 160, '页面不存在或路径设置有误,请查正后重新发布!');
  4072. }
  4073. }
  4074. script.src = url;
  4075. document.body.appendChild(script);
  4076. }
  4077. // var relies = [PAGEROOTDIR + 'script/a.js', PAGEROOTDIR + 'script/a1.js'];
  4078. function loadScripts(urls, callback) {
  4079. callback = callback || function () { };
  4080. var loader = function (src, handler) {
  4081. var script = document.createElement('script');
  4082. script.type = 'text/javascript';
  4083. script.src = src;
  4084. script.onload = function () {
  4085. script.onload = null;
  4086. script.onerror = null;
  4087. handler();
  4088. };
  4089. script.onerror = function () {
  4090. script.onload = null;
  4091. script.onerror = null;
  4092. callback({
  4093. message: src + '依赖未加载成功!'
  4094. });
  4095. };
  4096. var head = document.getElementsByTagName('head')[0];
  4097. (head || document.body).appendChild(script);
  4098. };
  4099. (function run() {
  4100. if (urls.length > 0) {
  4101. loader(urls.shift(), run);
  4102. } else {
  4103. callback();
  4104. }
  4105. })();
  4106. }
  4107. function clearDataModel (data) {
  4108. // 清理echarts图表
  4109. if (data.getHtml && typeof data.getHtml === 'function') {
  4110. var htmlData = data.getHtml(),
  4111. op;
  4112. if (htmlData._chart && typeof htmlData._chart.setOption === 'function') {
  4113. htmlData._chart.setOption({}, true);
  4114. htmlData._chart.clear && htmlData._chart.clear();
  4115. htmlData._chart = null;
  4116. }
  4117. if (typeof htmlData.getDataModel === 'function') {
  4118. var dm = htmlData.getDataModel();
  4119. dm.each(clearDataModel);
  4120. dm.clear();
  4121. }
  4122. }
  4123. if (data.setHtml && typeof data.setHtml === 'function') {
  4124. data.setHtml(document.createElement('div'));
  4125. }
  4126. // 清理图元
  4127. if (data.__parent) {
  4128. data.__parent.childNodes && (data.__parent.childNodes.length = 0);
  4129. data.__parentLib = null;
  4130. data.__parent = null;
  4131. }
  4132. data.localDynamicVar = null;
  4133. if(data.hasOwnProperty("setImage")){data.setImage(null)}; 
  4134. data._attrObj = null;
  4135. data.setWidth = null;
  4136. data.setHeight = null;
  4137. data.refresh && (data.refresh = null);
  4138. data.refreshText && (data.refreshText = null);
  4139. data.setOption && (data.setOption = null);
  4140. data._initSize && (data._initSize = null);
  4141. }
  4142. function destoryScript() {
  4143. // 清理interval定时器
  4144. for (var i = 0, len = intervalTimers.length; i < len; i++) {
  4145. clearInterval(intervalTimers[i]);
  4146. }
  4147. intervalTimers.length = 0;
  4148. // 删除body内的script标签
  4149. $(document.body).find('script').remove();
  4150. // 清除dataModel
  4151. // window.dataModel && window.dataModel.clear();
  4152. if (window.dataModel) {
  4153. dataModel.each(clearDataModel)
  4154. dataModel.clear();
  4155. }
  4156. // 清除图元model
  4157. window._libModel && window._libModel.clear();
  4158. // 清除自定义事件
  4159. $window.off('graphViewZoomEnded');
  4160. window.onkeydown = null;
  4161. // 清除缓存数据
  4162. alarmColorData = {};
  4163. // 删除添加的图片
  4164. deleteCustomImage();
  4165. // 删除DOM绑定的事件
  4166. (function () {
  4167. var ctm,
  4168. globalVarName,
  4169. eventNameList = ['handleScroll', 'adjustTranslateY', 'adjustTranslateX', '']
  4170. if (typeof graphView !== 'undefined') {
  4171. graphView._focusData = null;
  4172. graphView._lastHoverData = null;
  4173. graphView._pageBackgroundNode = null;
  4174. if (graphView.graphViewList) {
  4175. graphView.graphViewList.length = 0;
  4176. }
  4177. }
  4178. if (window.view) {
  4179. if (view.eventList && !GD.isEmptyObj(view.eventList)) {
  4180. view.eventList = {};
  4181. view.onkeydown = null;
  4182. }
  4183. $(view).remove();
  4184. view._ht = null;
  4185. view = null;
  4186. }
  4187. while (window.contextMenuOnViewList && (ctm = contextMenuOnViewList.shift())) {
  4188. if (ctm instanceof ht.widget.ContextMenu) {
  4189. ctm.afterShow = null;
  4190. ctm.beforeShow = null;
  4191. ctm.dispose();
  4192. ctm = null;
  4193. }
  4194. }
  4195. if (window.globalVarNameList) {
  4196. while (globalVarName = globalVarNameList.shift()) {
  4197. if (!window[globalVarName]) continue;
  4198. if (typeof window[globalVarName].getView === 'function') {
  4199. var $view = $(window[globalVarName].getView());
  4200. // $view.off('')
  4201. $view.remove();
  4202. }
  4203. window[globalVarName] = null;
  4204. }
  4205. }
  4206. window.GD && (GD.GetTagsProperty = null);
  4207. })();
  4208. window.zoomNodeList && (window.zoomNodeList.length = 0);
  4209. // 清除socketio中绑定的事件
  4210. // for (var key in socket._callbackDic) {
  4211. // if (socket._callbackDic.hasOwnProperty(key)) {
  4212. // socket._callbackDic[key] = null;
  4213. // }
  4214. // }
  4215. // 清除body内容
  4216. $('a.btn').off('mouseup, mousedown').remove();
  4217. $('div.ht-widget-contextmenu').remove();
  4218. $('div.tooltip').remove();
  4219. $('div.main').remove();
  4220. $('span[gcuielement="gcStringWidthSpan"]').remove();
  4221. }
  4222. function loadPage(hash) {
  4223. hash = hash || location.hash;
  4224. hash = decodeURIComponent(hash);
  4225. hash = hash.match(/^#/) ? hash.substr(1) : hash;
  4226. hash = hash.replace(/\\/g, '/');
  4227. // for (var i = 0, len = intervalTimers.length; i < len; i++) {
  4228. // clearInterval(intervalTimers[i]);
  4229. // }
  4230. if (!hash) return location.reload();
  4231. var flag = 0;
  4232. if (!GD.isLogin() && !GD.isFreeVisitPage(hash) && isAuthEnable !== "False") {
  4233. GD.createErrorDialog(300, 160, '您还没有登录!页面将在3秒后自动跳转到登录页面!');
  4234. setTimeout(function () {
  4235. dialogTip.dialog && dialogTip.dialog.hide();
  4236. var page = GD.getFreeVisitPage();
  4237. if (!page) {
  4238. GD.createErrorDialog(300, 160, '请先配置登录页面!');
  4239. return;
  4240. }
  4241. location.hash = page;
  4242. }, 3000)
  4243. return;
  4244. }
  4245. loadScript(PAGEROOTDIR + hash + '.js', function () {
  4246. var relies = GD && GD.relationship && GD.relationship[hash] || [];
  4247. for (var timer; timer = intervalTimers.pop();) {
  4248. clearInterval(timer);
  4249. }
  4250. // relies.push(hash + '.js');
  4251. for (var i = 0, len = relies.length; i < len; i++) {
  4252. relies[i] = PAGEROOTDIR + relies[i];
  4253. }
  4254. // destoryScript();
  4255. loadScripts(relies, function cb (err) {
  4256. if (err) {
  4257. destoryScript();
  4258. return console.log(err.message);
  4259. }
  4260. if (typeof window.init === 'function') {
  4261. var t = setTimeout(function () {
  4262. destoryScript();
  4263. init();
  4264. clearTimeout(t);
  4265. }, 0)
  4266. }
  4267. })
  4268. })
  4269. var hashArr = hash.split('/');
  4270. document.title = hashArr[hashArr.length - 1];
  4271. }
  4272. function deleteCustomImage() {
  4273. var imageMap = ht.Default.getImageMap();
  4274. for (var key in imageMap) {
  4275. if (key && imageMap.hasOwnProperty(key) && key.substr(0, 6) === 'image_') {
  4276. imageMap[key] = null;
  4277. }
  4278. }
  4279. }
  4280. ////--------------------获取报警区域-------------------------
  4281. // function getAlarmAreas() {
  4282. // var reqData = {
  4283. // "method": "GetAreas",
  4284. // "param": {}
  4285. // };
  4286. // var eventName = "/alarm/doservice";
  4287. // if (socket != null && socket != "") {
  4288. // socket.post(eventName, reqData, function (data) {
  4289. // if (data.success) {
  4290. // var DataType = data.data.data;
  4291. // for (var i = 0; i < DataType.length; i++) {
  4292. // alarmAreaDicName[DataType[i].area_name] = DataType[i];
  4293. // alarmAreasDic[DataType[i].id] = DataType[i].area_name;
  4294. // }
  4295. // }
  4296. // });
  4297. // }
  4298. // }
  4299. // hack onpushstate
  4300. ; (function (window, history) {
  4301. var pushState = history.pushState;
  4302. history.pushState = function () {
  4303. if (typeof window.onpushstate === 'function') {
  4304. window.onpushstate.apply(history, arguments);
  4305. }
  4306. return pushState.apply(history, arguments);
  4307. }
  4308. })(window, window.history);
  4309. window.onload = function () {
  4310. if (document.hasOwnProperty("ontouchstart")) {
  4311. istouched = true;
  4312. }
  4313. if (location.hash) {
  4314. return loadPage();
  4315. }
  4316. if (PAGENAME)
  4317. location.hash = PAGENAME;
  4318. return;
  4319. }
  4320. window.onhashchange = function (e) {
  4321. _exchangeCount++;
  4322. if (_exchangeCount > 100) {
  4323. _exchangeCount = 0;
  4324. return this.location.reload();
  4325. }
  4326. loadPage();
  4327. }
  4328. // libModel class
  4329. var LibModel = function () {
  4330. this.libModelMap = {};
  4331. this.libModelArray = [];
  4332. }
  4333. LibModel.prototype = {
  4334. add: function (key, value) {
  4335. if (value._baseClass && value._baseClass.match('ht.lib.')) {
  4336. this.libModelMap[key] = value;
  4337. this.libModelArray.push(value);
  4338. }
  4339. return this;
  4340. },
  4341. clear: function () {
  4342. for (var i = 0, len = this.libModelArray.length; i < len; i++) {
  4343. this.libModelArray[i] = null;
  4344. }
  4345. for (var key in this.libModelMap) {
  4346. if (this.libModelMap.hasOwnProperty(key)) {
  4347. this.libModelMap[key] = null;
  4348. }
  4349. }
  4350. this.libModelArray = [];
  4351. this.libModelMap = {};
  4352. },
  4353. getDataByKey: function (key) {
  4354. return this.libModelMap[key];
  4355. },
  4356. each: function (func) {
  4357. if (typeof func === 'function') {
  4358. for (var i = 0, len = this.libModelArray.length; i < len; i++) {
  4359. func(this.libModelArray[i], i);
  4360. }
  4361. }
  4362. },
  4363. remove: function (data) {
  4364. for (var key in this.libModelMap) {
  4365. if (this.libModelMap.hasOwnProperty(key) && this.libModelMap[key] === data) {
  4366. this.libModelMap[key] = null;
  4367. }
  4368. }
  4369. if (this.libModelArray.indexOf(data) != -1) {
  4370. this.libModelArray.splice(this.libModelArray.indexOf(data), 1);
  4371. }
  4372. },
  4373. // 页面缩放后有问题,待完善
  4374. getDataAt: function (e) {
  4375. var x = e.x,
  4376. y = e.y;
  4377. var result;
  4378. this.each(function (data) {
  4379. var w = data.getWidth(),
  4380. h = data.getHeight(),
  4381. p = data.getPosition();
  4382. px = p.x,
  4383. py = p.y,
  4384. w2 = w * 0.5,
  4385. h2 = h * 0.5;
  4386. if ((px - w2) < x && (px + w2) > x && (py + h2) > y && (py - h2) < y) {
  4387. result = data;
  4388. }
  4389. });
  4390. return result;
  4391. }
  4392. }
  4393. var _libModel = new LibModel();
  4394. function resetPageToDefaultSizeAndPosition(gv) {
  4395. gv = gv || window.graphView;
  4396. if (!gv) {
  4397. return;
  4398. }
  4399. gv.setZoom(1);
  4400. gv.tx(0);
  4401. gv.ty(0);
  4402. if (!(gv.tx() === 0 || gv.ty() === 0 || gv.getZoom() === 1)) {
  4403. setTimeout(function () {
  4404. resetPageToDefaultSizeAndPosition(gv);
  4405. }, 100)
  4406. }
  4407. }
  4408. // localstorage 保存 页面参数
  4409. ; (function (W, storage) {
  4410. var pageParamsName = 'pageParams';
  4411. // 保存参数到localstorage
  4412. function setParams(params, paramsName) {
  4413. var errFlag = false;
  4414. paramsName = paramsName || pageParamsName;
  4415. if (!params) {
  4416. storage.setItem(paramsName, '{}');
  4417. return;
  4418. }
  4419. if (typeof params === 'string') {
  4420. storage.setItem(paramsName, params);
  4421. return;
  4422. }
  4423. if (typeof params === 'object') {
  4424. try {
  4425. params = JSON.stringify(params);
  4426. } catch (error) {
  4427. console.log(error.message);
  4428. storage.setItem(paramsName, '{}');
  4429. errFlag = true;
  4430. }
  4431. if (errFlag) return;
  4432. storage.setItem(paramsName, params);
  4433. return;
  4434. }
  4435. console.log('页面传递的参数不合法!');
  4436. storage.setItem(paramsName, '{}');
  4437. }
  4438. function getParams(paramsName) {
  4439. paramsName = paramsName || pageParamsName;
  4440. var params = storage.getItem(paramsName),
  4441. errFlag = false;
  4442. try {
  4443. params = JSON.parse(params);
  4444. } catch (error) {
  4445. console.log(error.message);
  4446. errFlag = true;
  4447. }
  4448. if (errFlag) {
  4449. return {};
  4450. }
  4451. return params;
  4452. }
  4453. // 将传递的参数赋值给页面上的变量
  4454. function useParams(paramsName) {
  4455. paramsName = paramsName || pageParamsName;
  4456. var params = getParams(paramsName);
  4457. for (var key in params) {
  4458. if (params.hasOwnProperty(key)) {
  4459. if (!(window[key] === undefined)) {
  4460. window[key] = params[key];
  4461. }
  4462. }
  4463. }
  4464. removeParams(paramsName);
  4465. }
  4466. // 删除参数
  4467. function removeParams(paramsName) {
  4468. paramsName = paramsName || pageParamsName;
  4469. storage.removeItem(paramsName);
  4470. }
  4471. // 判断用户是否已经登录
  4472. function isLogin() {
  4473. var t = localStorage.getItem('token');
  4474. if (t && t.length > 100) {
  4475. return true;
  4476. }
  4477. return false;
  4478. }
  4479. // 判断页面是否可访问
  4480. function isFreeVisitPage(page) {
  4481. page = page || location.hash.substr(1);
  4482. page = decodeURIComponent(page);
  4483. if (window.__FVPAGE && __FVPAGE[0] === page) {
  4484. return true;
  4485. }
  4486. return false;
  4487. }
  4488. // 获取不登录时可打开的页面
  4489. function getFreeVisitPage() {
  4490. if (window.__FVPAGE) {
  4491. return __FVPAGE[0];
  4492. }
  4493. return '';
  4494. }
  4495. W.GD = W.GD || {};
  4496. GD.setParams = setParams;
  4497. GD.isLogin = isLogin;
  4498. GD.getFreeVisitPage = getFreeVisitPage;
  4499. GD.isFreeVisitPage = isFreeVisitPage;
  4500. GD.getParams = getParams;
  4501. GD.useParams = useParams;
  4502. GD.removeParams = removeParams;
  4503. })(window, localStorage);
  4504. // 保存页面要传递的参数
  4505. function saveLocalParams(paramsObj) {
  4506. if (typeof paramsObj !== 'object') {
  4507. return;
  4508. }
  4509. GD.setParams(paramsObj);
  4510. }
  4511. ; (function (W) { //页面显示相关
  4512. var GD = W.GD || {};
  4513. // 根据旋转角度计算缩放比例
  4514. function getRatioWithRotation(rotation, ratio) {
  4515. var abs = Math.abs,
  4516. cos = Math.cos,
  4517. sin = Math.sin;
  4518. var ratioX, ratioY;
  4519. var args = Array.prototype.slice.call(arguments, 0);
  4520. if (args.length === 2) {
  4521. if (!ratio) {
  4522. return {
  4523. ratioX: 1,
  4524. ratioY: 1
  4525. }
  4526. }
  4527. ratioX = ratio.ratioX;
  4528. ratioY = ratio.ratioY;
  4529. } else if (args.length >= 3) {
  4530. ratioX = args[1];
  4531. ratioY = args[2];
  4532. }
  4533. if (rotation === 0 || !ratioX || !ratioY) {
  4534. return {
  4535. ratioX: ratioX,
  4536. ratioY: ratioY
  4537. }
  4538. }
  4539. if (rotation < 0) {
  4540. rotation = rotation % (2 * Math.PI) + 2 * Math.PI;
  4541. }
  4542. var ro = rotation % Math.PI;
  4543. if (ro < Math.PI * 0.25) {
  4544. rotation = 0;
  4545. } else if (ro <= Math.PI * 0.75) {
  4546. rotation = 90 * Math.PI / 180;
  4547. } else {
  4548. rotation = Math.PI;
  4549. }
  4550. var _ratioX, _ratioY;
  4551. _ratioX = abs(cos(rotation) * ratioX - sin(rotation) * ratioY);
  4552. _ratioY = abs(sin(rotation) * ratioX + cos(rotation) * ratioY);
  4553. return {
  4554. ratioX: _ratioX,
  4555. ratioY: _ratioY
  4556. }
  4557. }
  4558. // 组旋转
  4559. function groupRotat(bound, node, angle, ratio) {
  4560. if (!angle || !bound || !node) {
  4561. return;
  4562. }
  4563. ratio = ratio || {
  4564. ratioX: 1,
  4565. ratioY: 1
  4566. };
  4567. if (node.scalable === false) { // 如果图元没有缩放就直接旋转
  4568. SetRotatPositionRelative(node, bound, angle);
  4569. node.setRotation(angle + node.getRotation());
  4570. return;
  4571. }
  4572. // 还原大小,位置
  4573. var boundWidth = bound.getWidth(),
  4574. boundHeight = bound.getHeight(),
  4575. boundPosition = bound.getPosition(),
  4576. boundRotation = typeof bound.getRotation === 'function' ? bound.getRotation() : 0,
  4577. boundRatio = getRatioWithRotation(boundRotation, ratio);
  4578. var nodeWidth = node.getWidth(),
  4579. nodeHeight = node.getHeight(),
  4580. nodePosition = node.getPosition(),
  4581. nodeRotation = typeof node.getRotation === 'function' ? node.getRotation() : 0,
  4582. nodeRatio = getRatioWithRotation(nodeRotation, ratio);
  4583. if (node._zoomBy === 'False') {
  4584. nodeRatio.ratioX = 1;
  4585. nodeRatio.ratioY = 1;
  4586. } else if (node._zoomBy === 'X') {
  4587. nodeRatio.ratioY = nodeRatio.ratioX;
  4588. } else if (node._zoomBy === 'Y') {
  4589. nodeRatio.ratioX = nodeRatio.ratioY;
  4590. }
  4591. bound.setWidth(boundWidth / boundRatio.ratioX);
  4592. bound.setHeight(boundHeight / boundRatio.ratioY);
  4593. bound.setPosition(boundPosition.x / ratio.ratioX, boundPosition.y / ratio.ratioY);
  4594. node.setWidth(nodeWidth / nodeRatio.ratioX);
  4595. node.setHeight(nodeHeight / nodeRatio.ratioY);
  4596. node.setPosition(nodePosition.x / ratio.ratioX, nodePosition.y / ratio.ratioY);
  4597. // 旋转
  4598. SetRotatPositionRelative(node, bound, angle);
  4599. if (node._baseClass && node._baseClass.match('^ht.lib')) {
  4600. node.setRotation(angle + nodeRotation, { x: node.getPosition().x - bound.getPosition().x, y: node.getPosition().y - bound.getPosition().y });
  4601. } else {
  4602. node.setRotation(angle + nodeRotation);
  4603. }
  4604. // 缩放
  4605. var _ratio = GD.getRatioWithRotation(angle + nodeRotation, ratio);
  4606. if (node._zoomBy === 'False') {
  4607. _ratio.ratioX = 1;
  4608. _ratio.ratioY = 1;
  4609. } else if (node._zoomBy === 'X') {
  4610. _ratio.ratioY = _ratio.ratioX;
  4611. } else if (node._zoomBy === 'Y') {
  4612. _ratio.ratioX = _ratio.ratioY;
  4613. }
  4614. bound.setWidth(bound.getWidth() * boundRatio.ratioX);
  4615. bound.setHeight(bound.getHeight() * boundRatio.ratioY);
  4616. bound.setPosition(bound.getPosition().x * ratio.ratioX, bound.getPosition().y * ratio.ratioY);
  4617. node.setWidth(node.getWidth() * _ratio.ratioX);
  4618. node.setHeight(node.getHeight() * _ratio.ratioY);
  4619. node.setPosition(node.getPosition().x * ratio.ratioX, node.getPosition().y * ratio.ratioY);
  4620. }
  4621. // 计算旋转角度
  4622. function calcRotation(rotation) {
  4623. if (rotation < 0) {
  4624. rotation = rotation % (2 * Math.PI) + 2 * Math.PI;
  4625. }
  4626. var ro = rotation % Math.PI;
  4627. if (ro < Math.PI * 0.25) {
  4628. rotation = 0;
  4629. } else if (ro <= Math.PI * 0.75) {
  4630. rotation = 90 * Math.PI / 180;
  4631. } else {
  4632. rotation = Math.PI;
  4633. }
  4634. return rotation;
  4635. }
  4636. function showTagInfo(tagsInfoDic, tagName, mouseX, mouseY) {
  4637. hideTagInfo();
  4638. if ($('div.tooltip div.tooltop').length > 0) {
  4639. return ;
  4640. }
  4641. // if (tagName.match(/{/)) {
  4642. // tagName = tagName.replace(/{/g, '').replace(/}/g, '');
  4643. // tagName = window[tagName] || '';
  4644. // }
  4645. var _tagName = tagName && tagName.toLowerCase && tagName.toLowerCase();
  4646. var $div = $('<div class="tag-info"></div>'),
  4647. clientWidth = $window.width(),
  4648. clientHeight = $window.height();
  4649. var tagInfo = tagsInfoDic[_tagName] || tagsInfoDic[tagName];
  4650. if (!tagInfo) return;
  4651. var x, y, width = 300, height = 350;
  4652. x = (mouseX + width) >= (clientWidth - 10) ? mouseX - width : mouseX + 8;
  4653. y = (mouseY + height) >= (clientHeight - 10) ? mouseY - height : mouseY + 8;
  4654. $div.css({
  4655. minWidth: 100,
  4656. minHeight: 100,
  4657. maxWidth: width,
  4658. maxHeight: height,
  4659. top: y,
  4660. left: x,
  4661. position: 'absolute',
  4662. zIndex: 99
  4663. });
  4664. var desc = tagInfo.Desc,
  4665. lowLimit = tagInfo.LowLimit,
  4666. highLimit = tagInfo.HighLimit,
  4667. unit = tagInfo.Unit;
  4668. var titleStr = '<li><span>标签名称:</span><span>' + tagName + '</span></li>',
  4669. descStr = '<li><span>描述:</span><span>' + desc + '</span></li>',
  4670. lowLimitStr = '<li><span>量程上限:</span><span>' + lowLimit + '</span></li>',
  4671. highLimitStr = '<li><span>量程下限:</span><span>' + highLimit + '</span></li>',
  4672. unitStr = '<li><span>单位:</span><span>' + unit + '</span></li>',
  4673. snapshort = '<li><span>快照值:</span><span class="snapshot">' + getVarValue(_tagName) + '</span></li>',
  4674. snapShotTimeStr = '<li><span>快照时间:</span><span class="snapshottime">' + moment(VarSnapshotTime[_tagName]).format("YYYY/MM/DD HH:mm:ss") + '</span></li>';
  4675. var htmlStr = '<ul>' + titleStr + descStr + unitStr + snapshort + snapShotTimeStr + '</ul>'
  4676. $div.html(htmlStr);
  4677. $(document.body).append($div);
  4678. var $width = $div.outerWidth(),
  4679. $height = $div.outerHeight();
  4680. x = (mouseX + $width) >= (clientWidth - 10) ? mouseX - $width - 8 : mouseX + 8;
  4681. y = (mouseY + $height) >= (clientHeight - 10) ? mouseY - $height - 8 : mouseY + 8;
  4682. $div.css({
  4683. top: y,
  4684. left: x
  4685. })
  4686. var $snapshot = $div.find('.snapshot'),
  4687. $snapshottime = $div.find('.snapshottime');
  4688. showTagInfo.timer && clearInterval(showTagInfo.timer);
  4689. showTagInfo.timer = setInterval(function () {
  4690. $snapshot.text(getVarValue(_tagName));
  4691. $snapshottime.text(moment(VarSnapshotTime[_tagName]).format("YYYY/MM/DD HH:mm:ss"));
  4692. }, 1000);
  4693. }
  4694. function hideTagInfo() {
  4695. $('div.tag-info').remove();
  4696. showTagInfo.timer && clearInterval(showTagInfo.timer);
  4697. }
  4698. function resetNodeBorderWidth(nodeList, value) {
  4699. var node, n, w, attr, fw, wv;
  4700. nodeList = nodeList || zoomNodeList;
  4701. for (var i = 0, len = nodeList.length; i < len; i++) {
  4702. node = nodeList[i];
  4703. n = node.node;
  4704. w = n.borderWidth;
  4705. fw = n.borderFillwidth || 0;
  4706. attr = node.attr;
  4707. wv = w * value;
  4708. if (n.a && (typeof n.a === 'function')) {
  4709. if (n.a('node.isFill') === 'true' || n.a('node.isFill') === true) {
  4710. n.borderFillwidth = wv;
  4711. } else {
  4712. n.a(attr, wv);
  4713. n._nodeType === 'roundrect' ? n._borderWidth = wv : '';
  4714. }
  4715. }
  4716. }
  4717. }
  4718. function setPageSizeWithRatio(value, ratio, backSize) {
  4719. var ox, oy, rx, ry, browserWidth, browserHeight, ps;
  4720. if (!value) return;
  4721. ratio = ratio || window.ratio || {};
  4722. backSize = backSize || window.backSize || {}
  4723. // 还原
  4724. ox = 1 / ratio.ratioX;
  4725. oy = 1 / ratio.ratioY;
  4726. browserWidth = $window.innerWidth();
  4727. browserHeight = $window.innerHeight();
  4728. if (value === 'adaptWidth') { // 适应宽度
  4729. ry = rx = browserWidth / backSize.width;
  4730. } else if (value === 'adaptHeight') { // 适应高度
  4731. rx = ry = browserHeight / backSize.height;
  4732. } else if (value === 'adaptBrowser') { // 适应浏览器窗口
  4733. rx = browserWidth / backSize.width;
  4734. ry = browserHeight / backSize.height;
  4735. } else if (value === 'originSize') { // 原始大小
  4736. rx = 1;
  4737. ry = 1;
  4738. } else if ($.isNumeric(value)) { // 数字
  4739. rx = ry = value;
  4740. } else if (value === 'autoResize') {
  4741. browserWidth = browserWidth < PageAdaptMode.minWidth ? PageAdaptMode.minWidth : browserWidth;
  4742. browserHeight = browserHeight < PageAdaptMode.minHeight ? PageAdaptMode.minHeight : browserHeight;
  4743. rx = browserWidth / backSize.width;
  4744. ry = browserHeight / backSize.height;
  4745. if (rx > ry) {
  4746. rx = ry;
  4747. } else {
  4748. ry = rx;
  4749. }
  4750. }
  4751. if ($.isNumeric(value)) {
  4752. ratio.ratioX = ratio.originRatioX * value;
  4753. ratio.ratioY = ratio.originRatioY * value;
  4754. GD.resizePage(ratio.ratioX*ox, ratio.ratioY*oy);
  4755. } else {
  4756. ratio.ratioX = rx;
  4757. ratio.ratioY = ry;
  4758. ratio.originRatioX = rx;
  4759. ratio.originRatioY = ry;
  4760. GD.resizePage(ox * rx, oy * ry);
  4761. }
  4762. setPageToCenterOrLeftTop();
  4763. autoToggleScrollBar();
  4764. setTimeout(function () {
  4765. graphView.tx(0);
  4766. graphView.ty(0);
  4767. graphView.redraw();
  4768. }, 0)
  4769. GD.setParams({
  4770. value: value
  4771. }, 'pageSizeRatioValue')
  4772. }
  4773. function autoToggleScrollBar() {
  4774. var browserWidth = $window.innerWidth(),
  4775. browserHeight = $window.innerHeight();
  4776. graphView.setScrollBarVisible(false);
  4777. // 页面宽度大于浏览器窗口宽度时显示滚动条,并且允许页面横向拖动,小于时禁止,页面可用鼠标缩放时页面仍可拖动
  4778. if (backSize.width * ratio.ratioX > browserWidth + 1) {
  4779. graphView.setScrollBarVisible(true);
  4780. graphView.adjustTranslateX = function (value) {
  4781. var offsetX = browserWidth - backSize.width * ratio.ratioX;
  4782. (value > 0) && (value = 0);
  4783. (value < offsetX && offsetX < 0) && (value = offsetX);
  4784. return value
  4785. };
  4786. } else {
  4787. !window.PAGESCALABLE && (graphView.adjustTranslateX = function () { return 0 });
  4788. }
  4789. // 页面高度大于浏览器窗口高度时显示滚动条,并且允许页面纵向拖动,小于时禁止,页面可用鼠标缩放时页面仍可拖动
  4790. if (backSize.height * ratio.ratioY > browserHeight + 1) {
  4791. graphView.setScrollBarVisible(true);
  4792. graphView.adjustTranslateY = function (value) {
  4793. var offsetY = browserHeight - backSize.height * ratio.ratioY;
  4794. (value > 0) && (value = 0);
  4795. (value < offsetY && offsetY < 0) && (value = offsetY);
  4796. return value
  4797. };
  4798. } else {
  4799. !window.PAGESCALABLE && (graphView.adjustTranslateY = function () { return 0 });
  4800. }
  4801. // 如果允许页面可用鼠标拖动,页面可用鼠标缩放时页面仍可拖动
  4802. if (graphView.isScrollBarVisible()) {
  4803. graphView.setPannable(true);
  4804. graphView.setMovableFunc(function (data) { return true });
  4805. } else {
  4806. if (!window.PAGESCALABLE) {
  4807. graphView.setPannable(false);
  4808. graphView.setMovableFunc(function (data) { return false });
  4809. }
  4810. }
  4811. }
  4812. function setPageToCenterOrLeftTop() { // position 默认为‘center’, 如果为leftTop,则移到到左上角
  4813. var browserHeight = $window.innerHeight(),
  4814. browserWidth = $window.innerWidth(),
  4815. offsetX, offsetY,
  4816. cx,cy,backSize = getBackSize();
  4817. var pageBackground = graphView && graphView._pageBackgroundNode,
  4818. bp;
  4819. if (!pageBackground) return;
  4820. if (backSize.width < browserWidth - 2) {
  4821. cx = browserWidth * 0.5;
  4822. } else {
  4823. cx = pageBackground.getWidth() * 0.5;
  4824. }
  4825. if (backSize.height < browserHeight -2) {
  4826. cy = browserHeight * 0.5;
  4827. } else {
  4828. cy = pageBackground.getHeight() * 0.5;
  4829. }
  4830. bp = pageBackground.getPosition();
  4831. offsetX = cx - bp.x;
  4832. offsetY = cy - bp.y;
  4833. window.dataModel && dataModel.each(function (data) {
  4834. if (!(data.__parentLib && data.__parentLib.match(/^ht.lib/) || data.__blockChild)) {
  4835. var p = data.getPosition();
  4836. data.setPosition(p.x + offsetX, p.y + offsetY);
  4837. }
  4838. });
  4839. window._libModel && _libModel.each(function (data) {
  4840. var p = data.getPosition();
  4841. data.setPosition(p.x + offsetX, p.y + offsetY);
  4842. })
  4843. }
  4844. function resizePage(ratioX, ratioY) {
  4845. var windowHeight = window.innerHeight,
  4846. windowWidth = window.innerWidth;
  4847. ratioX = ratioX || windowWidth / browserSize.width,
  4848. ratioY = ratioY || windowHeight / browserSize.height;
  4849. browserSize.width = windowWidth;
  4850. browserSize.height = windowHeight;
  4851. $window.trigger('beforeResize');
  4852. resizeAllNodes(dataModel, ratioX, ratioY);
  4853. var graphViewList = graphView && graphView.graphViewList || [];
  4854. for (var i = 0, len = graphViewList.length; i < len; i++) {
  4855. resizeAllNodes(graphViewList[i].getDataModel(), ratioX, ratioY);
  4856. }
  4857. showPage();
  4858. $window.trigger('resizeOver');
  4859. }
  4860. // 线段中箭头使用,返回的角度为线段终点的角度。
  4861. function calcRotationByStartAndEnd(startPoint, endPoint) {
  4862. var args = Array.prototype.slice.call(arguments, 0),
  4863. atan = Math.atan,
  4864. sx, sy, ex, ey, x, y;
  4865. if (!args.length) return 0;
  4866. if (args.length === 2 && args[0] && args[0].length && args[1] && args[1].length) {
  4867. sx = args[0][0];
  4868. sy = args[0][1];
  4869. ex = args[1][0];
  4870. ey = args[1][1];
  4871. } else if (args.length === 4) {
  4872. sx = args[0];
  4873. sy = args[1];
  4874. ex = args[2];
  4875. ey = args[3];
  4876. } else {
  4877. return 0;
  4878. }
  4879. x = ex - sx;
  4880. y = ey - sy;
  4881. if (x === 0 && y > 0) {
  4882. return Math.PI;
  4883. }
  4884. if (x === 0 && y < 0) {
  4885. return 0;
  4886. }
  4887. if (x > 0 && y === 0) {
  4888. return Math.PI * 0.5;
  4889. }
  4890. if (x < 0 && y === 0) {
  4891. return -Math.PI * 0.5;
  4892. }
  4893. if (x > 0 && y > 0) {
  4894. return Math.PI - atan(x / y);
  4895. }
  4896. if (x > 0 && y < 0) {
  4897. return atan(x / (-y));
  4898. }
  4899. if (x < 0 && y < 0) {
  4900. return -1 * (atan(x / y));
  4901. }
  4902. if (x < 0 && y > 0) {
  4903. return atan((-x) / (y)) - Math.PI;
  4904. }
  4905. }
  4906. function createAlarmSoundConfigDialog(width, height, x, y, angle, styleOption) {
  4907. styleOption = styleOption || {};
  4908. var comboboxValues = styleOption.comboboxValues || [],
  4909. comboboxValue = styleOption.comboboxValue || '',
  4910. comboboxBorderColor = styleOption.comboboxBorderColor || 'black',
  4911. comboboxFontColor = styleOption.comboboxFontColor || 'black',
  4912. comboboxBackgroundColor = styleOption.comboboxBackgroundColor || 'white',
  4913. comboboxSelectBackgroundColor = styleOption.comboboxSelectBackgroundColor || 'gray',
  4914. comboboxIconColor = styleOption.comboboxIconColor || 'gray',
  4915. labelColor = styleOption.labelColor || 'black',
  4916. labelFontSize = styleOption.labelFontSize || 10,
  4917. labelFontFamily = styleOption.labelFontFamily || 'Microsoft Yahei',
  4918. inputBorderColor = styleOption.inputBorderColor || 'black',
  4919. inputBackgroundColor = styleOption.inputBackgroundColor || 'rgba(0,0,0,0)',
  4920. inputFontColor = styleOption.inputFontColor || 'black',
  4921. buttonLabelColor = styleOption.buttonLabelColor || 'black',
  4922. buttonBackgroundColor = styleOption.buttonBackgroundColor || 'rgba(0,0,0,0)',
  4923. buttonSelectBackgroundColor = styleOption.buttonSelectBackgroundColor || 'rgba(0,0,0,0)',
  4924. paneBackgroundColor = styleOption.paneBackgroundColor || 'rgba(0,0,0,0)';
  4925. var fileInput = document.createElement('input');
  4926. fileInput.type = 'file';
  4927. fileInput.style.display = 'none';
  4928. fileInput.accept = '.mp3, .wav, .ogg';
  4929. document.body.appendChild(fileInput);
  4930. var borderPane = new ht.widget.BorderPane();
  4931. var formPane = new ht.widget.FormPane();
  4932. var combobox = new ht.widget.ComboBox();
  4933. combobox.setValues(comboboxValues);
  4934. combobox.setValue(comboboxValue);
  4935. var soundinput = new ht.widget.TextField();
  4936. var formatinput = new ht.widget.TextField();
  4937. var displayInfoInput = new ht.widget.TextField();
  4938. var playTimeDisplayInfoInput = new ht.widget.TextField();
  4939. var playtimeinput = new ht.widget.TextField();
  4940. var uploadbtn = new ht.widget.Button();
  4941. var changesoundbtn = new ht.widget.Button();
  4942. var changeplaytimebtn = new ht.widget.Button();
  4943. var $soundText = $('<span>声音:</span>');
  4944. var $formatLabel = $('<span>支持格式:&nbsp;mp3,wav或其它支持的格式</span>');
  4945. var $playTimeLabel = $('<span>播放时长:</span>');
  4946. var $playTimeUnitLabel = $('<span>S/次</span>');
  4947. var alarmLevelList = [];
  4948. uploadbtn.setLabel('上传');
  4949. changesoundbtn.setLabel('删除');
  4950. changeplaytimebtn.setLabel('保存');
  4951. function setButtonStyle(button, clickFunc) {
  4952. var $mask = $('<div style="background-color: rgba(0,0,0,0.1); width: 100%; height: 100%; position: absolute; top:0;left:0"></div>');
  4953. var buttonView = button.getView();
  4954. buttonView.className = 'uploadbutton';
  4955. button.setWidth(80);
  4956. button.setBackground('rgba(0,0,0,0)');
  4957. button.setSelectBackground('rgba(0,0,0,0)');
  4958. button.setLabelColor(buttonLabelColor);
  4959. button.setLabelSelectColor(buttonLabelColor);
  4960. button.setBorderColor('rgba(0,0,0,0)');
  4961. $(buttonView).css({
  4962. overflow: 'hidden',
  4963. cursor: 'pointer',
  4964. backgroundColor: buttonBackgroundColor
  4965. }).off('click').on('click', function () {
  4966. clickFunc = clickFunc || function () { };
  4967. clickFunc();
  4968. }).off('mousedown').on('mousedown', function () {
  4969. $(this).css({
  4970. backgroundColor: buttonSelectBackgroundColor
  4971. })
  4972. }).off('mouseup').on('mouseup', function () {
  4973. $(this).css({
  4974. backgroundColor: buttonBackgroundColor
  4975. })
  4976. }).hover(function () {
  4977. $(this).prepend($mask)
  4978. .css({
  4979. borderBottom: '1px solid ' + buttonLabelColor
  4980. });
  4981. }, function () {
  4982. $mask.remove();
  4983. $(this).css({
  4984. border: 'none'
  4985. })
  4986. });
  4987. }
  4988. function setComboboxStyle(combobox) {
  4989. var $comboboxView = $(combobox.getView()),
  4990. dropDownIcon = combobox.getDropDownIcon();
  4991. dropDownIcon.comps[0].borderColor = comboboxIconColor;
  4992. combobox.setDropDownIcon(dropDownIcon);
  4993. $comboboxView.css({
  4994. borderColor: comboboxBorderColor
  4995. });
  4996. combobox.setBackground(comboboxBackgroundColor);
  4997. combobox.setLabelColor(comboboxFontColor);
  4998. combobox.setSelectBackground(comboboxSelectBackgroundColor);
  4999. }
  5000. function setTextFieldStyle(textField) {
  5001. var $textFieldView = $(textField.getElement());
  5002. textField.setBackground(inputBackgroundColor);
  5003. $textFieldView.css({
  5004. 'border': 'none',
  5005. color: inputFontColor,
  5006. borderBottom: '1px solid ' + inputBorderColor
  5007. })
  5008. if (playtimeinput === textField) {
  5009. $textFieldView.css({
  5010. textAlign: 'center'
  5011. })
  5012. }
  5013. if (displayInfoInput === textField || playTimeDisplayInfoInput === textField) {
  5014. $textFieldView.css({
  5015. border: 'none'
  5016. })
  5017. }
  5018. // textField.setLabelColor('rgba(255, 0,0,1)');
  5019. }
  5020. function setLabelStyle($label) {
  5021. $label.css({
  5022. color: labelColor,
  5023. fontSize: labelFontSize,
  5024. fontFamily: labelFontFamily,
  5025. fontWeight: 400
  5026. })
  5027. }
  5028. function getSoundFileList(callback) {
  5029. callback = callback || function () { };
  5030. socket.alarmPost('/alarm/GetFilesList', {}, function (data) {
  5031. var result;
  5032. if (data.success) {
  5033. result = data.data && data.data.data || [];
  5034. if (!result.length) {
  5035. displayInfoInput.setValue('您还没有上传过声音文件,请先上传!');
  5036. // clearDisplayInfo(3);
  5037. } else {
  5038. combobox.setValues(result);
  5039. combobox.setValue(result[0]);
  5040. }
  5041. } else {
  5042. }
  5043. callback(data.success);
  5044. });
  5045. }
  5046. function getAlarmLevel(callback) {
  5047. callback = callback || function () { };
  5048. var reqData = {
  5049. "method": "GetLevels",
  5050. "param": {}
  5051. };
  5052. // var flagnum = getFlag();
  5053. var flagnum = "level";
  5054. var eventName = "/alarm/doservice?" + flagnum;;
  5055. socket.alarmPost(eventName, reqData, callback);
  5056. }
  5057. function setAlarmLevels(alarmLevels, callback) {
  5058. var len = alarmLevels.length,
  5059. count = 0,
  5060. alarmLevel,
  5061. reqData = {
  5062. "method": "UpdateLevel"
  5063. }
  5064. callback = callback || function () { };
  5065. for (var i = 0; i < len; i++) {
  5066. alarmLevel = alarmLevels[i];
  5067. reqData.param = alarmLevel;
  5068. socket.alarmPost('/alarm/doservice/?updatelevel', reqData, function (data) {
  5069. if (data.success) {
  5070. count++;
  5071. if (count >= len) {
  5072. callback();
  5073. }
  5074. }
  5075. })
  5076. }
  5077. }
  5078. function clearDisplayInfo(delay, infoinput) {
  5079. setTimeout(function () {
  5080. infoinput.setValue('');
  5081. }, delay * 1000)
  5082. }
  5083. function getalarmLevelList() {
  5084. getAlarmLevel(function (data) {
  5085. if (data.success) {
  5086. alarmLevelList = data.data && data.data.data || [];
  5087. if (alarmLevelList.length) {
  5088. playtimeinput.setValue(alarmLevelList[0].duration);
  5089. } else {
  5090. displayInfoInput.setValue('请先配置报警级别!');
  5091. }
  5092. } else {
  5093. alarmLevelList = [];
  5094. }
  5095. });
  5096. }
  5097. getSoundFileList();
  5098. getalarmLevelList();
  5099. formPane.addRow([combobox, null], [0.85, 0.15]);
  5100. formPane.addRow([displayInfoInput], [1]);
  5101. formPane.addRow([$soundText[0], soundinput, null, uploadbtn, changesoundbtn], [50, 0.5, 0.1, 40, 40, 0.22]);
  5102. formPane.addRow([null], [1]);
  5103. formPane.addRow([$formatLabel[0], null, null, '', ''], [50, 0.5, 0.1, 0.05, 0.05, 0.22]);
  5104. formPane.addRow([null], [1]);
  5105. formPane.addRow([$playTimeLabel[0], playtimeinput, $playTimeUnitLabel[0], null, null], [60, 60, 0.1, 0.4, 40, 0.22]);
  5106. formPane.addRow([playTimeDisplayInfoInput], [1]);
  5107. formPane.addRow([null], [1]);
  5108. formPane.addRow([null, changeplaytimebtn, null], [0.5, 40, 0.5]);
  5109. function setStyle() {
  5110. setButtonStyle(uploadbtn, function () {
  5111. fileInput.click();
  5112. });
  5113. // 删除
  5114. setButtonStyle(changesoundbtn, function () {
  5115. var fname = soundinput.getValue();
  5116. if (!fname) return;
  5117. if (!confirm('您确定要删除这个声音文件吗?')) return;
  5118. socket.alarmPost('/alarm/deletefile', {
  5119. "name": fname
  5120. }, function (data) {
  5121. if (data.success && data.data && data.data.data) {
  5122. displayInfoInput.setValue('删除文件成功!');
  5123. clearDisplayInfo(3, clearDisplayInfo);
  5124. getSoundFileList();
  5125. } else {
  5126. displayInfoInput.setValue('删除文件失败,请重试!');
  5127. clearDisplayInfo(3, clearDisplayInfo);
  5128. }
  5129. })
  5130. });
  5131. // 保存
  5132. setButtonStyle(changeplaytimebtn, function () {
  5133. var duration = playtimeinput.getValue(),
  5134. soundFileName = soundinput.getValue(),
  5135. alarmLevel;
  5136. if (!alarmLevelList.length) {
  5137. playTimeDisplayInfoInput.setValue('请先设置完报警级别再配置报警声音!');
  5138. clearDisplayInfo(3, playTimeDisplayInfoInput);
  5139. return;
  5140. }
  5141. if (!duration) {
  5142. playTimeDisplayInfoInput.setValue('请设置播放时长!');
  5143. clearDisplayInfo(3, playTimeDisplayInfoInput);
  5144. return;
  5145. }
  5146. if (!$.isNumeric(duration)) {
  5147. playTimeDisplayInfoInput.setValue('播放时长只能设置为整数!');
  5148. clearDisplayInfo(3, playTimeDisplayInfoInput);
  5149. return;
  5150. }
  5151. if (duration <= 0) {
  5152. playTimeDisplayInfoInput.setValue('播放时长只能设置为大于0的整数!');
  5153. clearDisplayInfo(3, playTimeDisplayInfoInput);
  5154. return;
  5155. }
  5156. if (!soundFileName) {
  5157. playTimeDisplayInfoInput.setValue('请选择或上传报警声音!');
  5158. clearDisplayInfo(3, playTimeDisplayInfoInput);
  5159. return;
  5160. }
  5161. for (var i = 0, len = alarmLevelList.length; i < len; i++) {
  5162. alarmLevel = alarmLevelList[i];
  5163. alarmLevel.duration = duration - 0;
  5164. alarmLevel['wave_file'] = soundFileName;
  5165. for (var key in alarmLevel) {
  5166. if (alarmLevel.hasOwnProperty(key)) {
  5167. alarmLevel[key] = {
  5168. value: alarmLevel[key]
  5169. }
  5170. }
  5171. }
  5172. }
  5173. setAlarmLevels(alarmLevelList, function () {
  5174. playTimeDisplayInfoInput.setValue('保存成功!');
  5175. clearDisplayInfo(3, playTimeDisplayInfoInput);
  5176. getalarmLevelList();
  5177. })
  5178. });
  5179. setComboboxStyle(combobox);
  5180. setTextFieldStyle(soundinput);
  5181. soundinput.setEditable(false);
  5182. setTextFieldStyle(displayInfoInput);
  5183. displayInfoInput.setEditable(false);
  5184. setTextFieldStyle(playTimeDisplayInfoInput);
  5185. playTimeDisplayInfoInput.setEditable(false);
  5186. setTextFieldStyle(formatinput);
  5187. setTextFieldStyle(playtimeinput);
  5188. setLabelStyle($soundText);
  5189. setLabelStyle($formatLabel);
  5190. setLabelStyle($playTimeLabel);
  5191. setLabelStyle($playTimeUnitLabel);
  5192. $(borderPane.getView()).css({
  5193. background: paneBackgroundColor
  5194. })
  5195. combobox.onValueChanged = function () {
  5196. soundinput.setValue(combobox.getValue());
  5197. }
  5198. $(fileInput).off().on('change', function () {
  5199. if (typeof FileReader !== 'function') {
  5200. displayInfoInput.setValue('您使用的浏览器版本太低,请更换高版本的浏览器!');
  5201. clearDisplayInfo(3, displayInfoInput);
  5202. return;
  5203. }
  5204. var f = fileInput.files && fileInput.files[0] || '';
  5205. var fname = f.name || '',
  5206. size = f.size;
  5207. var fileList = combobox.getValues();
  5208. if (!f) return;
  5209. if (size > 1024 * 1024 * 2) {
  5210. displayInfoInput.setValue('您选择的声音文件太大了,请更换声音文件!');
  5211. clearDisplayInfo(3, displayInfoInput);
  5212. return;
  5213. }
  5214. if (fileList.indexOf(fname) !== -1) {
  5215. if (!confirm("您选择的文件名在服务器已保存的文件名冲突,继续上传将会覆盖原有的文件,是否继续?")) {
  5216. return;
  5217. }
  5218. }
  5219. var reader = new FileReader();
  5220. reader.onload = function (e) {
  5221. var result = this.result;
  5222. // 发送给后端
  5223. socket.alarmPost('/alarm/UploadFile', {
  5224. "data": result,
  5225. "name": fname
  5226. }, function (data) {
  5227. var result;
  5228. if (data.success) {
  5229. result = data.data && data.data.data;
  5230. if (result) {
  5231. displayInfoInput.setValue('上传成功!');
  5232. clearDisplayInfo(3, displayInfoInput);
  5233. getSoundFileList(function (success) {
  5234. if (success) {
  5235. combobox.setValue(fname);
  5236. }
  5237. })
  5238. }
  5239. } else {
  5240. displayInfoInput.setValue('上传是发生错误,请重新上传!');
  5241. clearDisplayInfo(3, displayInfoInput);
  5242. }
  5243. }, 20)
  5244. }
  5245. reader.readAsDataURL(f);
  5246. });
  5247. }
  5248. setStyle();
  5249. borderPane.setCenterView(formPane);
  5250. var htmlNode = new ht.HtmlNode();
  5251. borderPane.setWidth(width);
  5252. borderPane.setHeight(height);
  5253. htmlNode.setHtml(borderPane);
  5254. htmlNode.setPosition(x, y);
  5255. htmlNode.setSize(width, height);
  5256. htmlNode.setPadding(0);
  5257. htmlNode.setScalable(false);
  5258. htmlNode.s({
  5259. '2d.selectable': true,
  5260. '2d.moveable': false
  5261. });
  5262. htmlNode.setComboboxValues = function (values) {
  5263. combobox.setValues(values);
  5264. }
  5265. htmlNode.setComboboxValue = function (value) {
  5266. combobox.setValue(value);
  5267. }
  5268. dataModel.add(htmlNode);
  5269. return htmlNode;
  5270. }
  5271. function getFullParams (params, node) {
  5272. if (!node) {
  5273. return params;
  5274. }
  5275. if (node.__parent && node.__parent.localVarObj) {
  5276. $.extend(params, node.__parent.localVarObj);
  5277. }
  5278. if (node.__parent && typeof node.__parent.localDynamicVar === 'function') {
  5279. $.extend(params, node.__parent.localDynamicVar());
  5280. }
  5281. if (typeof node.localDynamicVar === 'function') {
  5282. $.extend(params, node.localDynamicVar());
  5283. }
  5284. return params;
  5285. }
  5286. function getBackSize () {
  5287. var result = {};
  5288. var back = graphView._pageBackgroundNode,
  5289. w = back.getWidth(),
  5290. h = back.getHeight();
  5291. result.width = w;
  5292. result.height = h;
  5293. return result;
  5294. }
  5295. GD.getFullParams = getFullParams;
  5296. GD.createAlarmSoundConfigDialog = createAlarmSoundConfigDialog;
  5297. GD.resetNodeBorderWidth = resetNodeBorderWidth;
  5298. GD.getRatioWithRotation = getRatioWithRotation;
  5299. GD.groupRotat = groupRotat;
  5300. GD.showTagInfo = showTagInfo;
  5301. GD.hideTagInfo = hideTagInfo;
  5302. GD.calcRotation = calcRotation;
  5303. GD.setPageSizeWithRatio = setPageSizeWithRatio;
  5304. GD.autoToggleScrollBar = autoToggleScrollBar;
  5305. GD.setPageToCenterOrLeftTop = setPageToCenterOrLeftTop;
  5306. GD.resizePage = resizePage;
  5307. GD.calcRotationByStartAndEnd = calcRotationByStartAndEnd;
  5308. W.GD = GD;
  5309. })(window);
  5310. // 页面控件
  5311. (function (W) {
  5312. var GD = W.GD || {};
  5313. function createButton(w, h, x, y, angle, option) {
  5314. var htmlNode = new ht.HtmlNode(),
  5315. $btnView = $('<a class="btn btn-default"><i></i></a>'),
  5316. text = option.text || 'Text',
  5317. visible = !!option.visible,
  5318. backColor = option.backColor || 'rgba(220,220,220,1)',
  5319. fontSize = option.fontSize || 12,
  5320. fontFamily = option.fontFamily || '"Microsoft YaHei"',
  5321. fontColor = option.fontColor || 'rgba(255, 255, 255, 1)',
  5322. textAlign = option.textAlign || 'center',
  5323. btnBorderRadius = option.borderRaidus || '2px',
  5324. btnBorderColor = option.borderColor || '#ccc',
  5325. btnShadowColor = option.shadowColor || '#333',
  5326. btnHoverShadowColor = option.hoverShadowColor || '#eee',
  5327. bold = !!option.bold,
  5328. italic = !!option.italic,
  5329. underline = !!option.underline,
  5330. deleteline = !!option.deleteline,
  5331. icon = option.icon,
  5332. backImage = option.backImage,
  5333. clickFunc = option.clickFunc,
  5334. labelFont = fontSize * ratio.ratioY + 'px ' + fontFamily,
  5335. transparentColor = 'rgba(0,0,0,0)',
  5336. $mask = $('<div class="button-mask"></div>'),
  5337. _ratio = GD.getRatioWithRotation(angle, ratio);
  5338. bold && (labelFont = 'bold ' + labelFont);
  5339. italic && (labelFont = 'italic ' + labelFont);
  5340. var setWidth = htmlNode.setWidth,
  5341. setHeight = htmlNode.setHeight;
  5342. var btn = new ht.widget.Button(),
  5343. btnbg;
  5344. btn.setLabel(text);
  5345. btn.setBackground(transparentColor);
  5346. btn.setSelectBackground(transparentColor);
  5347. btn.setBorderColor(transparentColor);
  5348. btn.setLabelFont(labelFont);
  5349. btn.setLabelColor(fontColor);
  5350. icon && btn.setIcon(PAGEROOTDIR + icon);
  5351. $btnView = $(btn.getView());
  5352. if (backImage) {
  5353. if (!backImage.match(/^http:|^https:/)) {
  5354. backImage = PAGEROOTDIR + backImage;
  5355. }
  5356. $btnView.css({
  5357. backgroundImage: 'url('+ backImage +')',
  5358. backgroundPosition: 'center center',
  5359. backgroundRepeat: 'no-repeat',
  5360. backgroundSize: '100% 100%'
  5361. })
  5362. // btnbg = new ht.Node();
  5363. // btnbg.setWidth(w);
  5364. // btnbg.setHeight(h);
  5365. // btnbg.setPosition(x, y);
  5366. // btnbg.setRotation(angle);
  5367. // btnbg.setImage(backImage);
  5368. // dataModel.add(btnbg);
  5369. } else {
  5370. $btnView.css({
  5371. background: backColor
  5372. })
  5373. }
  5374. htmlNode._$btnView = $btnView;
  5375. htmlNode.setHtml(btn);
  5376. htmlNode.setScalable(false);
  5377. htmlNode.setPadding(0);
  5378. htmlNode.setWidth(w);
  5379. htmlNode.setHeight(h);
  5380. htmlNode.setPosition(x, y);
  5381. htmlNode.setRotation(angle);
  5382. htmlNode._btn = btn;
  5383. htmlNode.s({
  5384. '2d.selectable': false,
  5385. '2d.movable': false,
  5386. '2d.visible': visible
  5387. });
  5388. htmlNode.setLabelColor = function (fc) {
  5389. this._$btnView.css({
  5390. color: fc
  5391. });
  5392. };
  5393. htmlNode.setLabel = function (label) {
  5394. this._btn.setLabel(label);
  5395. };
  5396. htmlNode.setLabelFont = function (lf) {
  5397. this._btn.setLabelFont(lf);
  5398. };
  5399. htmlNode.getLabelFont = function () {
  5400. return this._btn.getLabelFont();
  5401. };
  5402. htmlNode.setBackground = function (bg) {
  5403. this._$btnView.css({
  5404. backgroundColor: bg
  5405. })
  5406. };
  5407. htmlNode.addEvent = function (eventname, func) {
  5408. $btnView = htmlNode._$btnView;
  5409. func = typeof func === 'function' ? func : function () { };
  5410. $btnView.on(eventname, function (e) {
  5411. func.call(htmlNode, e);
  5412. });
  5413. };
  5414. (function ($btnView, $mask, htmlNode, btnbg) {
  5415. $btnView.css({
  5416. 'borderRadius': btnBorderRadius,
  5417. 'overflow': 'hidden',
  5418. 'padding': 0,
  5419. 'margin': 0,
  5420. 'textAlign': textAlign,
  5421. cursor: 'pointer',
  5422. borderColor: btnBorderColor,
  5423. boxShadow: '0 0 5px ' + btnShadowColor,
  5424. }).hover(function () {
  5425. $btnView.append($mask).css({
  5426. boxShadow: '0 0 5px ' + btnHoverShadowColor
  5427. })
  5428. }, function () {
  5429. $mask.remove();
  5430. $btnView.css({
  5431. boxShadow: '0 0 5px ' + btnShadowColor
  5432. })
  5433. }).on('mousedown', function () {
  5434. $btnView.parent().css({
  5435. padding: '1px 0 0 1px'
  5436. })
  5437. // if (btnbg) {
  5438. // var p = btnbg.getPosition();
  5439. // btnbg.setPosition({
  5440. // x: p.x + 1,
  5441. // y: p.y + 1
  5442. // })
  5443. // }
  5444. }).on('mouseup', function () {
  5445. $btnView.parent().css({
  5446. padding: 0
  5447. });
  5448. // if (btnbg) {
  5449. // var p = btnbg.getPosition();
  5450. // btnbg.setPosition({
  5451. // x: p.x - 1,
  5452. // y: p.y - 1
  5453. // })
  5454. // }
  5455. }).find('canvas').css({
  5456. 'top': 0,
  5457. 'left': 0,
  5458. });
  5459. if (option.clickFunc) {
  5460. htmlNode.addEvent('click', option.clickFunc);
  5461. }
  5462. var setHeight = htmlNode.setHeight;
  5463. htmlNode.setHeight = function (height) {
  5464. var labelFont = fontSize * ratio.ratioY + 'px ' + fontFamily;
  5465. bold && (labelFont = 'bold ' + labelFont);
  5466. italic && (labelFont = 'italic ' + labelFont);
  5467. btn.setLabelFont(labelFont);
  5468. setHeight.call(htmlNode, height);
  5469. }
  5470. })($btnView, $mask, htmlNode, btnbg);
  5471. dataModel.add(htmlNode);
  5472. return htmlNode;
  5473. }
  5474. function createMessageDialog(width, height, content, surefunc, canclefunc, borderColor, btns, title, x, y) {
  5475. var messageDialog = createMessageDialog._messageDialog || new ht.widget.Dialog();
  5476. var content = '<p class="dialog-content-custom">' + content + '</p>',
  5477. position;
  5478. borderColor = borderColor || 'rgb(47, 131, 217)';
  5479. title = title || '提示';
  5480. btns = btns || [{
  5481. label: "确认",
  5482. className: 'dialog-button-confirm'
  5483. }, {
  5484. label: "取消",
  5485. className: 'dialog-button-cancel'
  5486. }];
  5487. if (messageDialog.isShowing()) {
  5488. messageDialog.hide();
  5489. }
  5490. if (x && y) {
  5491. position = {x: x, y: y};
  5492. } else {
  5493. position = 'center';
  5494. }
  5495. messageDialog.setConfig({
  5496. title: title,
  5497. titleAlign: "left",
  5498. closable: true,
  5499. draggable: true,
  5500. //maximizable: true,
  5501. position: position,
  5502. width: width,
  5503. height: height,
  5504. content: content,
  5505. contentPadding: 20,
  5506. buttons: btns,
  5507. buttonsAlign: "center",
  5508. action: function (item, e) {
  5509. if (item.label == "确认" || item.label === '确定') {
  5510. surefunc();
  5511. messageDialog.hide();
  5512. }
  5513. else {
  5514. canclefunc();
  5515. messageDialog.hide();
  5516. }
  5517. }
  5518. });
  5519. messageDialog.setModal(false);
  5520. createMessageDialog._messageDialog = messageDialog;
  5521. var $messageView = $(messageDialog.getView());
  5522. setDialogStyle($messageView, borderColor, width, height);
  5523. messageDialog.show();
  5524. }
  5525. function createErrorDialog(width, height, content, surefunc, canclefunc) {
  5526. surefunc = surefunc || function () { };
  5527. canclefunc = canclefunc || function () { };
  5528. createMessageDialog(width, height, content, surefunc, canclefunc, 'rgb(207,145,38)', [{
  5529. label: '确定',
  5530. className: 'dialog-button-confirm'
  5531. }])
  5532. }
  5533. function setDialogStyle($dialogView, borderColor, width, height) {
  5534. $dialogView.css({
  5535. zIndex: 100
  5536. }).find('.dialog-container').css({
  5537. border: '5px solid ' + borderColor,
  5538. padding: 0,
  5539. borderRadius: 5,
  5540. minWidth: width,
  5541. minHeight: height,
  5542. // overflow: 'hidden',
  5543. boxShadow: '3px 3px 8px rgb(50,50,50)'
  5544. }).find('.dialog-container-title').css({
  5545. backgroundColor: borderColor,
  5546. height: 30,
  5547. boxShadow: '0 2px 6px rgb(50,50,50)',
  5548. left: -5,
  5549. top: -5,
  5550. width: width,
  5551. position: 'absolute',
  5552. padding: '0 20px 0 20px',
  5553. borderRadius: 5,
  5554. lineHeight: '30px'
  5555. }).find('.dialog-title-control').css({
  5556. marginTop: 2
  5557. }).end().end().find('.dialog-container-buttons').css({
  5558. bottom: 5
  5559. }).find('.dialog-button-confirm').css({
  5560. background: borderColor,
  5561. marginRight: 20
  5562. });
  5563. }
  5564. function setupDatePicker(dateDiv, datePickerInstance) {
  5565. var currentValue;
  5566. var $dateDiv = $(dateDiv);
  5567. $dateDiv.on('click', function (e) {
  5568. $dateDiv.focus();
  5569. }).on('keyup', function (e) {
  5570. datePickerInstance.hint($dateDiv.val());
  5571. if (e.keyCode === 13) {
  5572. currentValue = $dateDiv.val();
  5573. $('span.laydate-btns-clear').trigger('click');
  5574. datePickerInstance.config.value = currentValue;
  5575. $dateDiv.val(currentValue);
  5576. $dateDiv.blur();
  5577. datePickerInstance._instance && datePickerInstance._instance.checkDate();
  5578. }
  5579. }).on('blur', function (e) {
  5580. $dateDiv.val(currentValue);
  5581. }).on('focus', function (e) {
  5582. currentValue = $dateDiv.val();
  5583. });
  5584. }
  5585. function setFrozentableStyle(frozenTable, styleObj) {
  5586. var rowHeight = styleObj.rowHeight || 20,
  5587. rowLineVisible = styleObj.rowLineVisible,
  5588. columnLineVisible = styleObj.columnLineVisible,
  5589. isRowAlter = styleObj.isRowAlter,
  5590. rowAlterColor = styleObj.rowAlterColor || 'rgba(0,0,0,0)',
  5591. selectedRowColor = styleObj.selectedRowColor || 'rgba(0,0,0,0)',
  5592. backColor = styleObj.backColor || 'rgb(255,255,255)',
  5593. headColor = styleObj.headColor || 'rgb(125, 125, 125)',
  5594. headGradientColor = styleObj.headGradientColor || 'rgb(125, 125, 125)',
  5595. fontColor = styleObj.fontColor || 'black',
  5596. fontSize = styleObj.fontSize || 12,
  5597. fontFamily = styleObj.fontFamily || '"Microsoft YaHei"',
  5598. headerFontSize = styleObj.headerFontSize || 14,
  5599. headerFontFamily = styleObj.headerFontFamily || '"Microsoft Yahei"',
  5600. headerFontStyle = styleObj.headerFontStyle || 'normal',
  5601. headerHeight = styleObj.headerHeight || 26,
  5602. headerBackImage = styleObj.headerBackImage,
  5603. bodyFontStyle = styleObj.bodyFontStyle || 'normal',
  5604. scrollBarColor = styleObj.scrollBarColor || 'rgba(100, 100, 100, 0.3)',
  5605. lineColor = styleObj.lineColor;
  5606. frozenTable.setRowHeight(rowHeight);
  5607. frozenTable.setRowLineVisible(rowLineVisible);
  5608. frozenTable.setColumnLineVisible(columnLineVisible);
  5609. frozenTable.drawRowBackground('rgba(0,0,0,0)', isRowAlter, rowAlterColor, selectedRowColor);
  5610. frozenTable.setBackground(backColor);
  5611. frozenTable.setHeaderGradientColor(headColor, headGradientColor);
  5612. frozenTable.getLabelColor(fontColor);
  5613. frozenTable.getLabelFont(fontSize, fontFamily);
  5614. frozenTable.setBodyLabelFont(fontSize, fontFamily, bodyFontStyle);
  5615. frozenTable.setHeaderLabelFont(headerFontSize, headerFontFamily, headerFontStyle);
  5616. frozenTable.setHeaderHeight(headerHeight);
  5617. frozenTable.setRowLineColor(lineColor);
  5618. frozenTable.setColumnLineColor(lineColor);
  5619. frozenTable.setFrozentableScrollBarColor(scrollBarColor);
  5620. if (headerBackImage) {
  5621. var $tableheaderbg = $('<div></div>');
  5622. $tableheaderbg.css({
  5623. height: headerHeight,
  5624. left: 0,
  5625. right: 0,
  5626. top: 0,
  5627. position: 'absolute',
  5628. backgroundImage: 'url(' + PAGEROOTDIR + headerBackImage + ')',
  5629. backgroundSize: '100% 100%',
  5630. backgroundRepeat: 'no-repeat',
  5631. backgroundPosition: 'center center'
  5632. });
  5633. $(frozenTable.getBorderPane().getView()).css({ overflow: 'visible' }).prepend($tableheaderbg);
  5634. }
  5635. }
  5636. function createPagenation() {
  5637. var toolbar = new ht.widget.Tollbar();
  5638. var items = [
  5639. {
  5640. label: "<<",
  5641. action: function () {
  5642. pageinputHis.value = 1;
  5643. alarmHisSearch();
  5644. },
  5645. unfocusable: true
  5646. },
  5647. {
  5648. label: "<",
  5649. action: function () {
  5650. if (Number(pageinputHis.value) > 1) {
  5651. pageinputHis.value = Number(pageinputHis.value) - 1;
  5652. alarmHisSearch();
  5653. }
  5654. },
  5655. unfocusable: true
  5656. },
  5657. {
  5658. label: '页:',
  5659. element: pageinputHis,
  5660. unfocusable: true
  5661. },
  5662. {
  5663. label: '>',
  5664. action: function () {
  5665. if (Number(pageinputHis.value) < Number(pageCountHis.getValue())) {
  5666. pageinputHis.value = Number(pageinputHis.value) + 1;
  5667. alarmHisSearch();
  5668. }
  5669. },
  5670. unfocusable: true
  5671. },
  5672. {
  5673. label: ">>",
  5674. action: function () {
  5675. pageinputHis.value = pageCountHis.getValue();
  5676. alarmHisSearch();
  5677. },
  5678. unfocusable: true
  5679. },
  5680. {
  5681. label: '共 100 页',
  5682. unfocusable: true
  5683. },
  5684. {
  5685. id: 'bottomtoolbarseprator',
  5686. selected: false,
  5687. unfocusable: true,
  5688. button: {
  5689. width: ((width * 0.5) - 130),
  5690. editable: false,
  5691. background: 'rgba(0,0,0,0)',
  5692. selectBackground: 'rgba(0,0,0,0)',
  5693. borderColor: 'rgba(0,0,0,0)',
  5694. }
  5695. }
  5696. ]
  5697. };
  5698. function testSearchTime(startTime, endTime) {
  5699. if (!startTime || !endTime) {
  5700. GD.createErrorDialog(360, 240, '请先选择查询时间段!');
  5701. return false;
  5702. }
  5703. var st = +new Date(startTime),
  5704. et = +new Date(endTime);
  5705. if (st >= et) {
  5706. GD.createErrorDialog(360, 240, '开始时间应小于结束时间!');
  5707. return false;
  5708. }
  5709. return true;
  5710. }
  5711. GD.getRectJSON = (function () {
  5712. function rectClip (g, width, height, data) {
  5713. width = data.getWidth();
  5714. height = data.getHeight();
  5715. drawRect(g, 0, 0, width, height);
  5716. g.clip();
  5717. }
  5718. function ovalClip (g, width, height, data) {
  5719. width = data.getWidth();
  5720. height = data.getHeight();
  5721. drawEllipse(g, 0, 0, width, height);
  5722. g.clip();
  5723. }
  5724. function arcClip (g, width, height, data) {}
  5725. var rectJSON = {
  5726. width: {value: 100, func: 'attr@node.width'},
  5727. height: {value: 100, func: 'attr@node.height'},
  5728. clip: rectClip,
  5729. comps: [
  5730. {
  5731. type: {value: 'rect', func: 'attr@node.type'},
  5732. rect: {value: [0, 0, '', ''], func: 'attr@node.rect'},
  5733. background: {value: '', func: 'attr@node.background'},
  5734. gradientColor: {value: '', func: 'attr@node.gradientcolor'},
  5735. gradient: {value: '', func: 'attr@node.gradient'}
  5736. },
  5737. {
  5738. type: 'rect',
  5739. rect: {value: [0,0,0,0], func: 'attr@node.fillrect'},
  5740. background: {value: '', func: 'attr@node.fillbackcolor'},
  5741. gradientColor: {value: '', func: 'attr@node.fillgradientcolor'},
  5742. gradient: {value: '', func: 'attr@node.fillgradient'},
  5743. },
  5744. {
  5745. type: {value: 'rect', func: 'attr@node.type'},
  5746. rect: {value: [0, 0, 0, 0], func: 'attr@node.rect'},
  5747. borderWidth: {value: 2, func: 'attr@node.borderwidth'},
  5748. borderColor: {value: '', func: 'attr@node.color'},
  5749. borderPattern:{value: [0,0], func: 'attr@node.borderPattern'}
  5750. }
  5751. ]
  5752. }, ovalJSON = {
  5753. width: {value: 100, func: 'attr@node.width'},
  5754. height: {value: 100, func: 'attr@node.height'},
  5755. clip: ovalClip,
  5756. comps: [
  5757. {
  5758. type: {value: 'rect', func: 'attr@node.type'},
  5759. rect: {value: [0, 0, 0, 0], func: 'attr@node.rect'},
  5760. background: {value: '', func: 'attr@node.background'},
  5761. gradientColor: {value: '', func: 'attr@node.gradientcolor'},
  5762. gradient: {value: '', func: 'attr@node.gradient'},
  5763. arcFrom: {value: 0, func: 'attr@node.arcFrom'},
  5764. arcTo: {value: 0, func: 'attr@node.arcTo'},
  5765. arcClose: {value: false, func: 'attr@node.arcClose'},
  5766. },
  5767. {
  5768. type: 'rect',
  5769. rect: {value: [0,0,0,0], func: 'attr@node.fillrect'},
  5770. background: {value: '', func: 'attr@node.fillbackcolor'},
  5771. gradientColor: {value: '', func: 'attr@node.fillgradientcolor'},
  5772. gradient: {value: '', func: 'attr@node.fillgradient'},
  5773. },
  5774. {
  5775. type: {value: 'rect', func: 'attr@node.type'},
  5776. rect: {value: [0, 0, '', ''], func: 'attr@node.rect'},
  5777. borderWidth: {value: 2, func: 'attr@node.borderwidth'},
  5778. borderColor: {value: '', func: 'attr@node.color'},
  5779. borderPattern:{value: [0,0], func: 'attr@node.borderPattern'},
  5780. arcFrom: {value: 0, func: 'attr@node.arcFrom'},
  5781. arcTo: {value: 0, func: 'attr@node.arcTo'},
  5782. arcClose: {value: false, func: 'attr@node.arcClose'},
  5783. }
  5784. ]
  5785. }, arcJSON = {
  5786. width: {value: 100, func: 'attr@node.width'},
  5787. height: {value: 100, func: 'attr@node.height'},
  5788. clip: arcClip,
  5789. comps: [
  5790. {
  5791. type: {value: 'rect', func: 'attr@node.type'},
  5792. rect: {value: [0, 0, 0, 0], func: 'attr@node.rect'},
  5793. background: {value: '', func: 'attr@node.background'},
  5794. gradientColor: {value: '', func: 'attr@node.gradientcolor'},
  5795. gradient: {value: '', func: 'attr@node.gradient'},
  5796. arcFrom: {value: 0, func: 'attr@node.arcFrom'},
  5797. arcTo: {value: 0, func: 'attr@node.arcTo'},
  5798. arcClose: {value: false, func: 'attr@node.arcClose'},
  5799. arcOval: {value: true, func: 'attr@node.arcOval'}
  5800. },
  5801. {
  5802. type: 'rect',
  5803. rect: {value: [0,0,0,0], func: 'attr@node.fillrect'},
  5804. background: {value: '', func: 'attr@node.fillbackcolor'},
  5805. gradientColor: {value: '', func: 'attr@node.fillgradientcolor'},
  5806. gradient: {value: '', func: 'attr@node.fillgradient'},
  5807. },
  5808. {
  5809. type: {value: 'rect', func: 'attr@node.type'},
  5810. rect: {value: [0, 0, '', ''], func: 'attr@node.rect'},
  5811. borderWidth: {value: 2, func: 'attr@node.borderwidth'},
  5812. borderColor: {value: '', func: 'attr@node.color'},
  5813. borderPattern:{value: [0,0], func: 'attr@node.borderPattern'},
  5814. arcFrom: {value: 0, func: 'attr@node.arcFrom'},
  5815. arcTo: {value: 0, func: 'attr@node.arcTo'},
  5816. arcClose: {value: false, func: 'attr@node.arcClose'},
  5817. arcOval: {value: true, func: 'attr@node.arcOval'}
  5818. }
  5819. ]
  5820. }
  5821. return function (width, height, type, arcFrom, arcTo, arcClose) {
  5822. var json;
  5823. if (type === 'oval') {
  5824. json = ovalJSON;
  5825. } else if (type === 'rect') {
  5826. json = rectJSON;
  5827. } else if (type === 'arc') {
  5828. json = arcJSON;
  5829. }
  5830. return json;
  5831. }
  5832. })();
  5833. GD.getTextJSON = (function () {
  5834. var json = {
  5835. width: {value: 100, func: 'attr@node.width'},
  5836. height: {value: 100, func: 'attr@node.height'},
  5837. comps: [
  5838. {
  5839. type: 'rect',
  5840. rect: {value: [0, 0, 0, 0], func: 'attr@node.rect'},
  5841. borderWidth: {value: 0, func: 'attr@node.borderwidth'},
  5842. borderColor: {value: '', func: 'attr@node.bordercolor'},
  5843. gradient: {value:'', func: 'attr@node.gradient'},
  5844. background:{value:'', func: 'attr@node.background'},
  5845. gradientColor:{value:'', func: 'attr@node.gradientcolor'},
  5846. },
  5847. {
  5848. type:'text',
  5849. text: {value:'', func: 'attr@node.text'},
  5850. align: {value: '', func: 'attr@node.textalign'},
  5851. vAlign: {value: '', func: 'attr@node.textvAlign'},
  5852. rect: {value: [0, 0, 0, 0], func: 'attr@node.textrect'},
  5853. color: {value:'', func: 'attr@node.color'},
  5854. font: {value: '', func: 'attr@node.font'},
  5855. visible: {value: true, func: 'attr@node.textvisible'}
  5856. },
  5857. {
  5858. type: {value: function (){}, func: 'attr@node.textfunc'},
  5859. visible: {value: true, func: 'attr@node.linefeed'}
  5860. },
  5861. {
  5862. type: 'shape',
  5863. borderWidth: {value: 1, func: 'attr@node.underlineBorderWidth'},
  5864. borderColor: {value:'', func: 'attr@node.color'},
  5865. points:{value: '', func: 'attr@node.underlinepoints'},
  5866. segments: [1, 2],
  5867. visible: {value: true, func: 'attr@node.underlinevisible'}
  5868. }
  5869. ]
  5870. };
  5871. return function (width, height, isLineFeed, lineFeed, showUnderLine, fontStyle) {
  5872. return json;
  5873. }
  5874. })();
  5875. GD.getPolyLineJSON = (function () {
  5876. var json;
  5877. return function () {
  5878. json = json || {
  5879. width: {value: 1, func: 'attr@node.width'},
  5880. height: {value: 1, func: 'attr@node.height'},
  5881. comps: [
  5882. {
  5883. type: 'shape',
  5884. points: {value: [], func: 'attr@node.points'},
  5885. segments: {value: [], func: 'attr@node.segments'},
  5886. borderWidth:{value:1, func: 'attr@node.borderwidth'},
  5887. borderColor:{value: 'rgb(0,0,0)', func: 'attr@node.color'},
  5888. closePath:false,
  5889. dash: false,
  5890. borderPattern:{value:getDashStyle(""), func: 'attr@node.borderPattern'}
  5891. },
  5892. {
  5893. type: 'triangle',
  5894. background:{value:'rgb(0,0,0)', func: 'attr@node.background'},
  5895. gradient: {value:'rgb(0,0,0)', func: 'attr@node.gradient'},
  5896. gradientColor:{value:'rgb(0,0,0)', func: 'attr@node.gradientcolor'},
  5897. rect:{value: [], func: 'attr@node.endCompspts'},
  5898. rotation:{value: 0, func: 'attr@node.endRotation'},
  5899. offsetX:{value: 0, func: 'attr@node.offsetEndX'},
  5900. offsetY:{value: 0, func: 'attr@node.offsetEndY'},
  5901. },
  5902. {
  5903. type: 'triangle',
  5904. background:{value:'@backcolor@', func: 'attr@node.background'},
  5905. gradient: {value:'rgb(0,0,0)', func: 'attr@node.gradient'},
  5906. gradientColor:{value:'rgb(0,0,0)', func: 'attr@node.gradientcolor'},
  5907. rect:{value: [], func: 'attr@node.startCompspts'},
  5908. rotation:{value:0, func: 'attr@node.startRotation'},
  5909. offsetY:{value: 0, func: 'attr@node.offsetStartY'},
  5910. offsetX:{value: 0, func: 'attr@node.offsetStartX'}
  5911. }
  5912. ]
  5913. }
  5914. return json;
  5915. };
  5916. })();
  5917. GD.getPolyGonJSON = (function () {
  5918. var json;
  5919. return function getPolyGonJSON() {
  5920. json = json || {
  5921. width:{value: 10, func: 'attr@node.width'},
  5922. height:{value: 10, func: 'attr@node.height'},
  5923. clip: {value: function(){}, func: 'attr@node.clip'},
  5924. comps: [
  5925. {
  5926. type: {value: 'rect', func: 'attr@node.type'},
  5927. points:{value: [], func: 'attr@node.comsPoints'},
  5928. segments: {value: [], func: 'attr@node.segments'},
  5929. closePath: {value: true, func: 'attr@node.closePath'},
  5930. borderWidth: {value:1, func: 'attr@node.borderwidth'},
  5931. borderColor:{value: 'rgb(0,0,0)', func: 'attr@node.color'},
  5932. background:{value:'rgb(0,0,0)', func: 'attr@node.background'},
  5933. gradient: {value:'', func: 'attr@node.gradient'},
  5934. gradientColor:{value:'rgb(0,0,0)', func: 'attr@node.gradientcolor'},
  5935. // borderPattern:{value:"", func: 'attr@node.borderPattern'},
  5936. isFill:{value:"false", func: 'attr@node.isFill'}
  5937. },
  5938. {
  5939. type: 'rect',
  5940. rect: {value:[0,0,0,0], func: 'attr@node.original'},
  5941. background:{value:'rgb(0,0,0)', func: 'attr@node.background'},
  5942. gradient: {value:'', func: 'attr@node.gradient'},
  5943. gradientColor:{value:'rgb(0,0,0)', func: 'attr@node.gradientcolor'},
  5944. },
  5945. {
  5946. type: 'rect',
  5947. rect: {value:[0,0,0,0], func: 'attr@node.fillrect'},
  5948. background:{value:'rgb(0,0,0)', func: 'attr@node.fillbackcolor'},
  5949. gradient: {value:'', func: 'attr@node.fillgradient'},
  5950. gradientColor:{value:'rgb(0,0,0)', func: 'attr@node.fillgradientcolor'}
  5951. },
  5952. {
  5953. type: {value: 'rect', func: 'attr@node.type'},
  5954. points:{value: [], func: 'attr@node.comsPoints'},
  5955. segments: {value: [], func: 'attr@node.segments'},
  5956. closePath: {value: true, func: 'attr@node.closePath'},
  5957. borderWidth: {value:1, func: 'attr@node.borderwidth'},
  5958. borderColor:{value: 'rgb(0,0,0)', func: 'attr@node.color'},
  5959. borderJoin: 'miter',
  5960. borderPattern:{value:"", func: 'attr@node.borderPattern'}
  5961. }
  5962. ]
  5963. }
  5964. return json;
  5965. }
  5966. })();
  5967. GD.getBowJSON = (function () {
  5968. var json;
  5969. return function getBowJson() {
  5970. json = json || {
  5971. width: {value: 10, func: 'attr@node.width'},
  5972. height: {value: 10, func: 'attr@node.height'},
  5973. comps: [
  5974. {
  5975. type: 'arc',
  5976. rect: {value: [0, 0, 100, 100], func: 'attr@node.rect'},
  5977. arcFrom:{value: 0, func: 'attr@node.arcFrom'},
  5978. arcTo:{value: 0, func: 'attr@node.arcTo'},
  5979. arcClose: false,
  5980. arcOval:true,
  5981. borderWidth: {value:1, func: 'attr@node.borderwidth'},
  5982. borderColor:{value: 'rgb(0,0,0)', func: 'attr@node.color'},
  5983. background:{value:'rgb(0,0,0)', func: 'attr@node.background'},
  5984. dash: false,
  5985. gradient: {value:'', func: 'attr@node.gradient'},
  5986. gradientColor:{value:'rgb(0,0,0)', func: 'attr@node.gradientcolor'},
  5987. borderPattern:{value:'', func: 'attr@node.borderPattern'}
  5988. },
  5989. {
  5990. type:'shape',
  5991. borderWidth:{value:1, func: 'attr@node.borderwidth'},
  5992. borderColor: {value: 'rgb(0,0,0)', func: 'attr@node.borderColor'},
  5993. points:{value: [], func: 'attr@node.points'},
  5994. borderPattern:{value:getDashStyle("@borderPattern@"), func: 'attr@node.borderPattern'},
  5995. segments: [1,2]
  5996. }
  5997. ]
  5998. }
  5999. return json;
  6000. }
  6001. })();
  6002. // 创建报警弹窗
  6003. (function (w) {
  6004. var alarmWindow = {};
  6005. function createAlarmWindow(callback) {
  6006. callback = callback || function () { };
  6007. function createTabTitle (index, isCurrent, title, k) {
  6008. var str = '<li data-target="item'+ index +'" data-index="'+ k +'" class="item'+ index +' '+ (isCurrent ? 'current': '') +'">'+ title +'</li>';
  6009. return str;
  6010. }
  6011. function createTabContent (index, isCurrent, contentObj) {
  6012. var arr = [];
  6013. arr.push('<li class="item'+ index +' '+ (isCurrent ? 'current': '') +'">');
  6014. arr.push('<ul class="alarm-window-body-content-data">');
  6015. arr.push('<li class="clearfix"><span>设备编号:</span> <p class="alarm-fannumber">'+ contentObj.alarmAreaName +'</p></li>');
  6016. arr.push('<li class="clearfix"><span>故障名称:</span> <p class="alarm-name">'+ contentObj.alarmDesc +'</p></li>');
  6017. arr.push('<li class="clearfix">');
  6018. arr.push('<span>故障时间:</span>');
  6019. arr.push('<p>');
  6020. arr.push('<span class="alarm-date">'+ contentObj.alarmTime.split(' ')[0] +'</span>');
  6021. arr.push('<span class="alarm-time">'+ contentObj.alarmTime.split(' ')[1] +'</span>');
  6022. arr.push('</p></li></ul></li>');
  6023. return arr.join('');
  6024. }
  6025. function createDom() {
  6026. var htmlStr = '',
  6027. htmlArr = [];
  6028. htmlArr.push('<div class="alarm-window-container noselect">');
  6029. htmlArr.push('<div class="alarm-window-head">');
  6030. htmlArr.push('<h3><span>待确认故障</span><strong class="alarm-count">3</strong><span>项</span></h3>');
  6031. htmlArr.push('<div class="alarm-window-head-btns"><span data-state="max" class="alarm-window-head-btns-toggle">-</span></div>');
  6032. htmlArr.push('</div>');
  6033. htmlArr.push('<div class="alarm-window-body">');
  6034. htmlArr.push('<div class="alarm-window-body-tab">');
  6035. htmlArr.push('<ul class="alarm-window-tab-title-container">');
  6036. // htmlArr.push('<li data-target="item0" class="item0 current">t1</li>');
  6037. // htmlArr.push('<li data-target="item1" class="item1">t2</li>');
  6038. // htmlArr.push('<li data-target="item2" class="item2">t3</li>');
  6039. // htmlArr.push('<li data-target="item3" class="item3">t4</li>');
  6040. htmlArr.push('</ul>');
  6041. htmlArr.push('</div>');
  6042. htmlArr.push('<div class="alarm-window-body-content">');
  6043. htmlArr.push('<div data-flag="flag1" class="alarm-window-body-flag"></div>')
  6044. htmlArr.push('<ul class="alarm-window-body-content-container">');
  6045. // htmlArr.push('<li class="item0 fcjk current">');
  6046. // htmlArr.push('<ul class="alarm-window-body-content-data">');
  6047. // htmlArr.push('<li class="clearfix"><span>风机编号:</span> <p class="alarm-fannumber">发电机启动</p></li>');
  6048. // htmlArr.push('<li class="clearfix"><span>故障名称:</span> <p class="alarm-name">发电机启动异常发电机启动异常发电机启动</p></li>');
  6049. // htmlArr.push('<li class="clearfix">');
  6050. // htmlArr.push('<span>故障时间:</span>');
  6051. // htmlArr.push('<p>');
  6052. // htmlArr.push('<span class="alarm-date">2018-1-30</span>');
  6053. // htmlArr.push('<span class="alarm-time">10:30:00</span>');
  6054. // htmlArr.push('</p></li></ul></li>');
  6055. // htmlArr.push('<li class="item1 nlpt">b2</li>');
  6056. // htmlArr.push('<li class="item2 jkpg">b3</li>');
  6057. // htmlArr.push('<li class="item3 zcgl">b4</li>');
  6058. htmlArr.push('</ul>');
  6059. htmlArr.push('</div>');
  6060. htmlArr.push('<div class="alarm-window-body-btns">');
  6061. htmlArr.push('<div><span class="alarm-window-confirmbtn">确认</span></div>');
  6062. htmlArr.push('</div></div></div>');
  6063. return $(htmlArr.join(''))[0];
  6064. }
  6065. function addEventToDom(dom) {
  6066. var $alarmWindow = $(dom),
  6067. $alarmTab = $alarmWindow.find('.alarm-window-body-tab'),
  6068. $alarmContent = $alarmWindow.find('.alarm-window-body-content'),
  6069. $tabBtns = $alarmTab.find('li'),
  6070. $contents = $alarmContent.find('li'),
  6071. $confirmBtn = $alarmWindow.find('.alarm-window-confirmbtn'),
  6072. $headToggleBtn = $alarmWindow.find('.alarm-window-head-btns-toggle');
  6073. $tabBtns.off('click').on('click', function () {
  6074. var $this = $(this),
  6075. target = '.' + $this.data('target'),
  6076. index = $this.data('index');
  6077. $tabBtns.removeClass('current');
  6078. $this.addClass('current');
  6079. $contents.removeClass('current').parent().find(target).addClass('current');
  6080. // 将当前标签对应的数据设置为当前数据,确认时使用
  6081. alarmWindow.currentData = alarmWindow.alarmData && alarmWindow.alarmData[index];
  6082. });
  6083. $headToggleBtn.off('click').on('click', function () {
  6084. var state = $headToggleBtn.data('state');
  6085. if (state === 'max') {
  6086. $headToggleBtn.text('+');
  6087. $headToggleBtn.data('state', 'min');
  6088. alarmWindow.alarmWindowMinify();
  6089. } else {
  6090. $headToggleBtn.text('-');
  6091. $headToggleBtn.data('state', 'max');
  6092. alarmWindow.alarmWindowReduction();
  6093. }
  6094. }).off('mousedown').on('mousedown', function (e) {
  6095. e.stopPropagation();
  6096. })
  6097. $confirmBtn.off('click').on('click', function () {
  6098. callback();
  6099. });
  6100. $alarmWindow.off('mouseenter').on('mouseenter', function (e) {
  6101. e.stopPropagation();
  6102. if (!alarmWindow.isHide())
  6103. $alarmWindow.stop().fadeTo(300, 1);
  6104. }).off('mouseleave').on('mouseleave', function (e) {
  6105. e.stopPropagation();
  6106. if (!alarmWindow.isHide())
  6107. $alarmWindow.stop().fadeTo(1000, 0.3);
  6108. })
  6109. }
  6110. function bindDataToDom(dataObj) {
  6111. if (!dataObj) return;
  6112. var $dom = alarmWindow._$dom || $(alarmWindow._dom),
  6113. $tabTitleContainer = $dom.find('.alarm-window-tab-title-container'),
  6114. $contentContainer = $dom.find('.alarm-window-body-content-container'),
  6115. $count = alarmWindow._$count || $dom.find('.alarm-count'),
  6116. d, i = 0, isCurrent;
  6117. alarmWindow.alarmData = dataObj;
  6118. $tabTitleContainer.children().remove();
  6119. $contentContainer.children().remove();
  6120. for (var key in dataObj) {
  6121. if (key !== 'count' && dataObj.hasOwnProperty(key)) {
  6122. d = dataObj[key];
  6123. if (!d) continue;
  6124. $tabTitleContainer.append($(createTabTitle(i, !!d.isCurrent, d.systemName, key)));
  6125. $contentContainer.append($(createTabContent(i, !!d.isCurrent, d)));
  6126. if (d.isCurrent) {
  6127. alarmWindow.currentData = d;
  6128. }
  6129. i++;
  6130. }
  6131. }
  6132. $count.text(dataObj.count || 0);
  6133. }
  6134. function refreshData(data) {
  6135. // 如果数据条数为0则隐藏弹窗
  6136. if (!data || !data.count) {
  6137. alarmWindow.alarmWindowHide();
  6138. return;
  6139. }
  6140. bindDataToDom(data);
  6141. if (alarmWindow.isHide()) {
  6142. alarmWindow.alarmWindowShow();
  6143. }
  6144. }
  6145. function alarmWindowMinify() {
  6146. var $dom = alarmWindow._$dom || $(alarmWindow._dom);
  6147. $dom.addClass('alarm-window-minify');
  6148. $dom.css({
  6149. left: 'auto',
  6150. top: 'auto'
  6151. })
  6152. }
  6153. function alarmWindowReduction() {
  6154. var $dom = alarmWindow._$dom || $(alarmWindow._dom);
  6155. $dom.removeClass('alarm-window-minify');
  6156. }
  6157. function alarmWindowDragable(dragable) {
  6158. if (!dragable) return;
  6159. var $dom = alarmWindow._$dom || $(alarmWindow._dom),
  6160. $head = $dom.find('.alarm-window-head'),
  6161. $h3 = $head.find('h3'),
  6162. $body = $(document.body),
  6163. mousemoveFunc, offsetX, offsetY,
  6164. $window = $(window),
  6165. mousemoveFunc = function (e) {
  6166. var clientX = e.clientX,
  6167. clientY = e.clientY;
  6168. var l = clientX - offsetX,
  6169. t = clientY - offsetY,
  6170. wx = $window.width(),
  6171. wh = $window.height(),
  6172. w = $dom.width(),
  6173. h = $dom.height(),
  6174. ox = wx - w,
  6175. oh = wh - h;
  6176. l = l <= 0 ? 0 : l;
  6177. t = t <= 0 ? 0 : t;
  6178. l = l >= ox ? ox : l;
  6179. t = t >= oh ? oh : t;
  6180. $dom.css({
  6181. left: l,
  6182. top: t
  6183. })
  6184. }
  6185. $h3.on('mousedown', function (evt) {
  6186. evt.stopPropagation();
  6187. })
  6188. $head.on('mousedown', function (evt) {
  6189. evt.stopPropagation();
  6190. offsetX = evt.offsetX,
  6191. offsetY = evt.offsetY;
  6192. $body.on('mousemove', mousemoveFunc)
  6193. })
  6194. $body.on('mouseup', function (e) {
  6195. $body.off('mousemove', mousemoveFunc);
  6196. }).on('mouseleave', function () {
  6197. $body.off('mousemove', mousemoveFunc);
  6198. })
  6199. }
  6200. function alarmWindowHide() {
  6201. var $dom = alarmWindow._$dom || $(alarmWindow._dom);
  6202. alarmWindow._isHide = true;
  6203. $dom.stop().hide();
  6204. }
  6205. function alarmWindowShow() {
  6206. var $dom = alarmWindow._$dom || $(alarmWindow._dom);
  6207. alarmWindow._isHide = false;
  6208. $dom.stop().show();
  6209. }
  6210. function delayFade(t) {
  6211. var $dom = alarmWindow._$dom || $(alarmWindow._dom);
  6212. setTimeout(function () {
  6213. if (!alarmWindow.isHide())
  6214. $dom.stop().fadeTo(500, 0.3);
  6215. }, t);
  6216. }
  6217. function isHide() {
  6218. return alarmWindow._isHide;
  6219. }
  6220. function setFlagShaly() {
  6221. var $dom = alarmWindow._$dom || $(alarmWindow._dom),
  6222. $flag = $dom.find('.alarm-window-body-flag');
  6223. alarmWindow._timer && clearInterval(alarmWindow._timer);
  6224. alarmWindow._timer = setInterval(function () {
  6225. var flag = $flag.data('flag');
  6226. if (flag === 'flag1') {
  6227. $flag.data('flag', 'flag2');
  6228. $flag.css({
  6229. backgroundPosition: 'right center'
  6230. })
  6231. } else {
  6232. $flag.data('flag', 'flag1');
  6233. $flag.css({
  6234. backgroundPosition: 'left center'
  6235. })
  6236. }
  6237. }, 500)
  6238. }
  6239. alarmWindow._dom = alarmWindow._dom || createDom();
  6240. alarmWindow.refreshData = refreshData;
  6241. alarmWindow.alarmWindowMinify = alarmWindowMinify;
  6242. alarmWindow.alarmWindowReduction = alarmWindowReduction;
  6243. alarmWindow.alarmWindowDragable = alarmWindowDragable;
  6244. alarmWindow.alarmWindowShow = alarmWindowShow;
  6245. alarmWindow.alarmWindowHide = alarmWindowHide;
  6246. alarmWindow.addEventToDom = addEventToDom;
  6247. alarmWindow.isHide = isHide;
  6248. alarmWindow.delayFade = delayFade;
  6249. alarmWindow.setFlagShaly = setFlagShaly;
  6250. alarmWindow.delayFade(3000);
  6251. alarmWindowHide();
  6252. return alarmWindow;
  6253. }
  6254. w.createAlarmWindow = createAlarmWindow;
  6255. })(GD);
  6256. GD.testSearchTime = testSearchTime;
  6257. GD.createPagenation = createPagenation;
  6258. GD.setFrozentableStyle = setFrozentableStyle;
  6259. GD.setupDatePicker = setupDatePicker;
  6260. GD.setDialogStyle = setDialogStyle;
  6261. GD.createMessageDialog = createMessageDialog;
  6262. GD.createErrorDialog = createErrorDialog;
  6263. GD.createButton = createButton;
  6264. W.GD = GD;
  6265. })(window);
  6266. // http
  6267. (function (W) {
  6268. var GD = W.GD || {};
  6269. function getHisTrendData(cmdStr, callback) {
  6270. var paras = cmdStr.split('&'), result;
  6271. str = "http://" + webServiceIP + ":" + webServicePort + "/api/HistoryInterval?tagName=";
  6272. str = str + encodeURIComponent(paras[0]) + "&" + paras[1] + "&" + paras[2] + "&" + paras[3] + "&" + paras[4];
  6273. $.ajax({
  6274. url: str,
  6275. type: 'GET',
  6276. dataType: 'json',
  6277. cache: false,
  6278. success: function (data) {
  6279. result = data;
  6280. },
  6281. complete: function (XHR, TS) {
  6282. XHR = null;
  6283. callback(result);
  6284. },
  6285. error: function (data) {
  6286. result = null;
  6287. }
  6288. });
  6289. }
  6290. GD.getHisTrendData = getHisTrendData;
  6291. W.GD = GD;
  6292. })(window);
  6293. // 封装socketio
  6294. (function (W, io) {
  6295. var GD = W.GD || {};
  6296. if (!io) {
  6297. return
  6298. };
  6299. var TIMEOUTERRORDATA = {
  6300. success: false,
  6301. error: {
  6302. code: 408,
  6303. detail: '请求超时',
  6304. status: 'Request Timeout'
  6305. },
  6306. api: ''
  6307. },
  6308. LOGOUTERRORDATA = {
  6309. success: false,
  6310. error: {
  6311. code: 401,
  6312. detail: '用户未登录',
  6313. status: 'User Logout'
  6314. },
  6315. api: ''
  6316. };
  6317. // 封装sokcetio
  6318. function IO(url, params) {
  6319. this._url = url;
  6320. this._params = params;
  6321. this.socketio = io(url, params);
  6322. this._alarmPostCount = 0;
  6323. this._callbackDic = {};
  6324. this.init();
  6325. }
  6326. IO.prototype = {
  6327. init: function () {
  6328. var that = this,
  6329. callback;
  6330. // console.log(_data);
  6331. // 接收到数据时回调
  6332. function cb(data) {
  6333. data = JSON.parse(data);
  6334. var eventName = data.api,
  6335. timenum;
  6336. if (eventName == "alarmservice.call") {
  6337. timenum = data.body && data.body.json && data.body.json.split('{')[0];
  6338. if (that._callbackDic["alarmservice.call"]) {
  6339. if (typeof that._callbackDic[eventName][timenum] === 'function') {
  6340. that._callbackDic[eventName][timenum](that._depackAlarmData(data));
  6341. that._callbackDic[eventName][timenum] = null;
  6342. }
  6343. }
  6344. } else if (eventName === "alarmservice.sub") {
  6345. callback = that._callbackDic["alarmservice.sub"] || function () { };
  6346. callback(that._depackAlarmData(data));
  6347. } else {
  6348. // 清除接收消息事件
  6349. if (typeof that._callbackDic[eventName] === 'function') {
  6350. that._callbackDic[eventName](data);
  6351. that._callbackDic[eventName] = null;
  6352. }
  6353. }
  6354. callback = null;
  6355. }
  6356. that.socketio.on('message', cb);
  6357. },
  6358. on: function (eventName, callback) {
  6359. callback = callback || function () { };
  6360. this.socketio.on(eventName, function (result) {
  6361. var data;
  6362. try {
  6363. data = JSON.parse(result);
  6364. } catch (error) {
  6365. data = {
  6366. success: false,
  6367. error: {
  6368. code: '417',
  6369. detail: '返回参数格式错误',
  6370. status: 'format error'
  6371. },
  6372. api: eventName
  6373. }
  6374. }
  6375. callback(data)
  6376. });
  6377. },
  6378. alarmOn: function (eventname, callback) {
  6379. var that = this;
  6380. callback = callback || {};
  6381. that.on(eventName, function (result) {
  6382. var _result = {};
  6383. if (result && result.success) {
  6384. _result = that._depackAlarmData(result);
  6385. } else {
  6386. _result = result;
  6387. }
  6388. _result.api = eventname;
  6389. callback(_result);
  6390. })
  6391. },
  6392. post: function (eventName, data, callback, timeout) {
  6393. var that = this;
  6394. var args;
  6395. if (!that.socketio.connected) {
  6396. if (that.socketio.reconnection === false) {
  6397. return;
  6398. }
  6399. args = Array.prototype.slice.call(arguments, 0);
  6400. (function (args, that) {
  6401. setTimeout(function () {
  6402. that.post.apply(that, args);
  6403. }, 100)
  6404. })(args, that);
  6405. return;
  6406. }
  6407. timeout = timeout || 8;
  6408. if (typeof data === 'function') {
  6409. callback = data;
  6410. data = {};
  6411. } else {
  6412. data = data || {};
  6413. callback = callback || function () { }
  6414. }
  6415. var header = {},
  6416. _data = {};
  6417. if (eventName != 'auth.authenticate') {
  6418. var token = localStorage.getItem('token');
  6419. if (!token) {
  6420. // 如果没有token,未登录,返回未登录信息
  6421. LOGOUTERRORDATA.api = eventName;
  6422. callback(LOGOUTERRORDATA);
  6423. return;
  6424. }
  6425. token = token.replace(/^\s+/g, '').replace(/\s+$/g, '').replace(/^"/g, '').replace(/"$/g, '');
  6426. // 删除token两端的 "
  6427. // token = token.substr(1, token.length-2);
  6428. header.token = token;
  6429. _data.header = header;
  6430. }
  6431. _data.api = eventName;
  6432. _data.request = data;
  6433. _data = JSON.stringify(_data);
  6434. that._callbackDic[eventName] = callback;
  6435. // 发送请求
  6436. that.socketio.emit('message', _data, function () { });
  6437. // 开始计时,5S未收到返回会超时,并回调超时信息。
  6438. var timer = setTimeout(function () {
  6439. // 清除接收消息事件,避免重复接收
  6440. TIMEOUTERRORDATA.api = eventName;
  6441. var cb;
  6442. //返回超时信息
  6443. cb = that._callbackDic[eventName];
  6444. if (typeof cb === 'function') {
  6445. cb(TIMEOUTERRORDATA);
  6446. that._callbackDic[eventName] = null;
  6447. }
  6448. }, timeout * 1000);
  6449. },
  6450. /**
  6451. * 请求数据:
  6452. * {
  6453. * "method": "GetGroups",
  6454. * "param": {}
  6455. * }
  6456. * 返回格式:
  6457. * {
  6458. * success: true,
  6459. * data: {
  6460. * data: {
  6461. * user: 'admin'
  6462. * }
  6463. * }
  6464. * }
  6465. * 错误时:
  6466. * {
  6467. * success: false,
  6468. * data: {},
  6469. * error: {
  6470. * code: '400',
  6471. * status: 'bad request',
  6472. * detail: '无效的请求参数'
  6473. * }
  6474. * }
  6475. *
  6476. */
  6477. alarmPost: function (eName, data, callback, timeout) {
  6478. var that = this;
  6479. var args, _data = {};
  6480. if (!that.socketio.connected) {
  6481. if (that.socketio.reconnection === false) { // 如果没有自动重连,直接返回
  6482. return;
  6483. }
  6484. args = Array.prototype.slice.call(arguments, 0);
  6485. (function (args, that) {
  6486. setTimeout(function () {
  6487. that.alarmPost.apply(that, args);
  6488. }, 100);
  6489. })(args, that);
  6490. return;
  6491. }
  6492. timeout = timeout || 10;
  6493. if (typeof data === 'function') {
  6494. callback = data;
  6495. data = {};
  6496. } else {
  6497. data = data || {};
  6498. callback = callback || function () { }
  6499. }
  6500. var _data = {};
  6501. var eventName = eName.split('?')[0];
  6502. var flag = '_';
  6503. var postApi;
  6504. that._alarmPostCount += 1;
  6505. if (that._alarmPostCount > 100) {
  6506. that._alarmPostCount = 1;
  6507. }
  6508. flag += that._alarmPostCount;
  6509. // 配合报警服务,把数据序列化
  6510. if (eventName === '/alarm/SubscribeNotify') {
  6511. _data.json = flag + JSON.stringify({
  6512. data: data
  6513. });
  6514. postApi = "alarmservice.sub";
  6515. // 保存回调函数
  6516. // that._callbackDic[postApi] = that._callbackDic[postApi] || [];
  6517. that._callbackDic[postApi] = callback;
  6518. } else {
  6519. _data.json = flag + JSON.stringify({
  6520. data: data,
  6521. url: eventName
  6522. });
  6523. postApi = "alarmservice.call";
  6524. // 保存回调函数
  6525. that._callbackDic[postApi] = that._callbackDic[postApi] || {};
  6526. that._callbackDic[postApi][flag] = callback;
  6527. }
  6528. var token = localStorage.getItem('token'),
  6529. header = {},
  6530. alarmData = {};
  6531. if (!token) {
  6532. // 如果没有token,未登录,返回未登录信息
  6533. LOGOUTERRORDATA.api = postApi;
  6534. callback(LOGOUTERRORDATA);
  6535. return;
  6536. }
  6537. token = token.replace(/^\s+/g, '').replace(/\s+$/g, '').replace(/^"/g, '').replace(/"$/g, '');
  6538. // 删除token两端的 "
  6539. // token = token.substr(1, token.length-2);
  6540. header.token = token;
  6541. alarmData.header = header;
  6542. alarmData.api = postApi;
  6543. alarmData.request = _data;
  6544. alarmData = JSON.stringify(alarmData)
  6545. that.socketio.send(alarmData);
  6546. // that.post(postApi, alarmData, function (result) {
  6547. // var _result = {},
  6548. // jsonStr; //
  6549. // if (result && result.success) {
  6550. // _result = that._depackAlarmData(result);
  6551. // } else {
  6552. // _result = result;
  6553. // }
  6554. // _result.api = eventName;
  6555. // callback(_result);
  6556. // }, timeout)
  6557. },
  6558. reconnect: function (callback) {
  6559. callback = callback || function () { };
  6560. this.socketio.reconnect(callback);
  6561. },
  6562. disconnect: function (callback) {
  6563. callback = callback || function () { };
  6564. this.socketio.disconnect(callback);
  6565. },
  6566. getNewToken: function () {
  6567. },
  6568. _depackAlarmData: function (result) {
  6569. var _result = {},
  6570. jsonStr, flagnum;
  6571. try {
  6572. if (result.api == "alarmservice.call") {
  6573. flagnum = result.body.json.split('{')[0];
  6574. jsonStr = GD.deEscape(result.body.json.substring(result.body.json.indexOf('{')));
  6575. if (jsonStr[jsonStr.length - 1] != '}') {
  6576. jsonStr += '}';
  6577. }
  6578. _result = JSON.parse(jsonStr);
  6579. _result.flagnum = flagnum;
  6580. } else if (result.api == "alarmservice.sub") {
  6581. jsonStr = GD.deEscape(result.body.json);
  6582. _result = JSON.parse(jsonStr);
  6583. }
  6584. _result.success = true;
  6585. } catch (error) {
  6586. _result.success = false;
  6587. _result.data = {};
  6588. _result.error = {
  6589. code: "",
  6590. status: '',
  6591. detail: error.message
  6592. }
  6593. }
  6594. return _result;
  6595. },
  6596. _packAlarmData: function () {
  6597. }
  6598. }
  6599. GD.io = function (url, params) {
  6600. return new IO(url, params);
  6601. }
  6602. W.GD = GD;
  6603. })(window, _io);
  6604. // webAPI交互
  6605. (function (W) {
  6606. var GD = W.GD || {};
  6607. GD.exportElectricIndicates = function (beginTime, endTime, tags, typeArr) {
  6608. tags = tags.join(',');
  6609. var uri = 'tags=' + tags + "&";
  6610. uri += 'beginTime=' + beginTime + "&";
  6611. uri += 'endTime=' + endTime + '&';
  6612. uri += 'valueType=' + typeArr.join(',');
  6613. var link = document.createElement("a");
  6614. link.download = "exportExcel";
  6615. link.href = "http://" + webServiceIP + ":" + webServicePort +
  6616. "/api/ExportToExcelInterpo?" + encodeURIComponent(uri);
  6617. link.click();
  6618. };
  6619. GD.exportArrToCsv = function exportTagsToCSV(arr, fileName) {
  6620. fileName = fileName || 'data';
  6621. if (!arr) return;
  6622. var tempArr = [], result;
  6623. for (var i = 0, len = arr.length; i < len; i++) {
  6624. tempArr.push(arr[i].join(','));
  6625. }
  6626. result = tempArr.join('\r\n');
  6627. result = '\uFEFF' + result;
  6628. var blob = new Blob([result], { type: 'text/csv;charset=UTF-8' });//
  6629. saveAs(blob, fileName + Date.now() + '.csv');
  6630. }
  6631. GD.getCurrentUserName = function (fromService) {
  6632. var localParams = GD.getParams('user') || {};
  6633. if (!fromService) {
  6634. return localParams.name || '';
  6635. }
  6636. }
  6637. GD.getCurrentUserGroup = function (groupid) {
  6638. return ''
  6639. }
  6640. W.GD = GD;
  6641. })(window);
  6642. (function (W) {
  6643. var GD = W.GD || {};
  6644. function deEscape(str) {
  6645. if (!str) {
  6646. return "";
  6647. }
  6648. // str = str.replace(/\u0000/g, "");
  6649. // str = unescape(str.replace(/\\(u[0-9a-fA-F]{4})/g, '%$1'));
  6650. str = unescape(str.replace(/\\(u[0-9a-fA-F]{4})/gm, ''));
  6651. return str;
  6652. }
  6653. function eascape(str) {
  6654. return str;
  6655. }
  6656. function getStrLength(str) {
  6657. if (!str) return 0;
  6658. str.toString && (str = str.toString());
  6659. return str.replace(/[^\x00-\xff]/g, "01").length;
  6660. }
  6661. // 节流函数
  6662. function throttle(func, time) {
  6663. time = time || 200;
  6664. func = typeof func === 'function' ? func : function () { };
  6665. func._timer_ && clearTimeout(func._timer_);
  6666. var args = Array.prototype.slice.call(arguments, 2);
  6667. func._timer_ = setTimeout(function () {
  6668. func._timer_ = null;
  6669. func.apply(null, args);
  6670. }, time)
  6671. }
  6672. function getSearchObjFromUrl(urlStr) {
  6673. urlStr = urlStr || location.href;
  6674. var index,
  6675. searchStr,
  6676. searchArr,
  6677. tempArr,
  6678. searchObj = {};
  6679. index = urlStr.indexOf('?') === -1 ? 0 : urlStr.indexOf('?') + 1;
  6680. var searchStr = urlStr.substr(index);
  6681. var searchArr = searchStr.split('&');
  6682. for (var i = 0, len = searchArr.length; i < len; i++) {
  6683. tempArr = searchArr[i].split('=');
  6684. if (tempArr[0] && tempArr[1]) {
  6685. searchObj[tempArr[0]] = tempArr[1];
  6686. }
  6687. }
  6688. return searchObj;
  6689. }
  6690. function removeRepeated(arr, changeOrigin) {
  6691. var obj = {}, newArr = [], temp;
  6692. for (var i = 0, len = arr.length; i < len; i++) {
  6693. temp = arr[i];
  6694. if (!obj[temp]) {
  6695. newArr.push(temp);
  6696. obj[temp] = true;
  6697. }
  6698. }
  6699. if (changeOrigin) {
  6700. arr.length = 0;
  6701. for (i = 0, len = newArr.length; i < len; i++) {
  6702. arr.push(newArr[i]);
  6703. }
  6704. }
  6705. return newArr;
  6706. }
  6707. function getMaxAndMinFromSeries(series) {
  6708. var max = min = 0,
  6709. s, d, l, v;
  6710. for (var i = 0, len = series.length; i < len; i++) {
  6711. s = series[i];
  6712. d = s.data || [];
  6713. for (var j = 0, l = d.length; j < l; j++) {
  6714. v = d[j] - 0;
  6715. max = v > max ? v : max;
  6716. min = v < min ? v : min;
  6717. }
  6718. }
  6719. return {
  6720. max: max,
  6721. min: min
  6722. }
  6723. }
  6724. function getRelativeDate(dt, format, beginOrEnd) {
  6725. var d = new Date();
  6726. var typeMap = {
  6727. date: 'YYYY-MM-DD',
  6728. time: 'HH:mm:ss',
  6729. datetime: 'YYYY-MM-DD HH:mm:ss',
  6730. year: 'YYYY',
  6731. month: 'YYYY-MM'
  6732. }
  6733. dt = $.trim(dt);
  6734. var count = parseInt(dt),
  6735. type = dt.substr(count.toString().length),
  6736. result;
  6737. function formatDate(date, format) {
  6738. var result = moment(date).format(typeMap[format] || typeMap.datetime);
  6739. return result;
  6740. }
  6741. function calcRelativeDate(date, type, bod) {
  6742. switch (type) {
  6743. case 'h':
  6744. case 'hour':
  6745. date.setHours(date.getHours() - count);
  6746. if (bod === 'begin') {
  6747. date.setMinutes(0);
  6748. date.setSeconds(0);
  6749. date.setMilliseconds(0);
  6750. }
  6751. if (bod === 'end' && count !== 0) {
  6752. date.setMinutes(59);
  6753. date.setSeconds(59);
  6754. date.setMilliseconds(0);
  6755. }
  6756. break;
  6757. case 'd':
  6758. case 'day':
  6759. date.setDate(date.getDate() - count);
  6760. if (bod === 'begin') {
  6761. date.setHours(0);
  6762. date.setMinutes(0);
  6763. date.setSeconds(0);
  6764. date.setMilliseconds(0);
  6765. }
  6766. if (bod === 'end' && count !== 0) {
  6767. date.setHours(23);
  6768. date.setMinutes(59);
  6769. date.setSeconds(59);
  6770. date.setMilliseconds(0);
  6771. }
  6772. break;
  6773. case 'm':
  6774. case 'month':
  6775. date.setMonth(date.getMonth() - count);
  6776. if (bod === 'begin') {
  6777. date.setDate(1);
  6778. date.setHours(0);
  6779. date.setMinutes(0);
  6780. date.setSeconds(0);
  6781. date.setMilliseconds(0);
  6782. }
  6783. if (bod === 'end' && count !== 0) {
  6784. date.setMonth(date.getMonth() + 1);
  6785. date.setDate(1);
  6786. date.setHours(0);
  6787. date.setMinutes(0);
  6788. date.setSeconds(0);
  6789. date.setMilliseconds(0);
  6790. date = new Date(+new Date(date) - 1000);
  6791. }
  6792. break;
  6793. case 'y':
  6794. case 'year':
  6795. date.setFullYear(date.getFullYear() - count);
  6796. if (bod === 'begin') {
  6797. date.setMonth(0);
  6798. date.setDate(1);
  6799. date.setHours(0);
  6800. date.setMinutes(0);
  6801. date.setSeconds(0);
  6802. date.setMilliseconds(0);
  6803. }
  6804. if (bod === 'end' && count !== 0) {
  6805. date.setFullYear(date.getFullYear() + 1);
  6806. date.setMonth(0);
  6807. date.setDate(1);
  6808. date.setHours(0);
  6809. date.setMinutes(0);
  6810. date.setSeconds(0);
  6811. date.setMilliseconds(0);
  6812. date = new Date(+new Date(date) - 1000);
  6813. }
  6814. break;
  6815. default:
  6816. date = dt;
  6817. }
  6818. return date;
  6819. }
  6820. result = calcRelativeDate(d, type, beginOrEnd);
  6821. return formatDate(result, typeMap[format]);
  6822. }
  6823. function isEmptyObj(obj) {
  6824. for (var key in obj) {
  6825. if (obj.hasOwnProperty(key)) {
  6826. return false;
  6827. }
  6828. }
  6829. return true;
  6830. }
  6831. var measureCanvasText = (function () {
  6832. var canvas = document.createElement('canvas'),
  6833. ctx = canvas.getContext('2d');
  6834. return function (text, fontStyle) {
  6835. ctx.font = fontStyle;
  6836. return ctx.measureText(text).width;
  6837. }
  6838. })();
  6839. function eval(str) {
  6840. var fun = new Function('return ' + str);
  6841. var result;
  6842. try {
  6843. result = fun();
  6844. } catch (error) {
  6845. console.log(error.message);
  6846. result = error;
  6847. }
  6848. return result;
  6849. }
  6850. GD.eval = eval;
  6851. GD.isEmptyObj = isEmptyObj;
  6852. GD.deEscape = deEscape;
  6853. GD.getRelativeDate = getRelativeDate;
  6854. GD.getMaxAndMinFromSeries = getMaxAndMinFromSeries;
  6855. GD.eascape = eascape;
  6856. GD.getStrLength = getStrLength;
  6857. GD.measureCanvasText = measureCanvasText;
  6858. GD.throttle = throttle;
  6859. GD.getSearchObjFromUrl = getSearchObjFromUrl;
  6860. GD.removeRepeated = removeRepeated;
  6861. W.GD = GD;
  6862. })(window);
  6863. $window.off('customEventJump').on('customEventJump', function (e, args) {
  6864. if (!args || !args.hash) return;
  6865. var hash = window.location.hash || '#';
  6866. hash = hash.substr(1);
  6867. if (args.params) {
  6868. saveLocalParams && saveLocalParams(args.params);
  6869. }
  6870. window.location.hash = args && args.hash;
  6871. if (hash === args.hash) {
  6872. loadPage(hash);
  6873. }
  6874. });
  6875. $window.off('customEventSetPageSizeWithRatio').on('customEventSetPageSizeWithRatio', function (e, args) {
  6876. var ratio = args && args.ratio;
  6877. if (!ratio) return;
  6878. window.GD && GD.setPageSizeWithRatio(ratio);
  6879. });
  6880. // 当页面被嵌入其它框架时(跨域),将登录后的用户信息、token信息通过查询字符串传给,加载common时将信息保存到localStorage
  6881. (function () {
  6882. var search = location.search;
  6883. if (!search) return;
  6884. var obj = searchStrToObj(search) || {};
  6885. if (obj.user) {
  6886. localStorage.setItem('user', obj.user);
  6887. }
  6888. if (obj.token) {
  6889. localStorage.setItem('token', obj.token);
  6890. }
  6891. if (obj.userGroup) {
  6892. localStorage.setItem('userGroup', obj.userGroup);
  6893. }
  6894. if (obj.userLevel) {
  6895. localStorage.setItem('userLevel', obj.userLevel);
  6896. }
  6897. if (obj.extra) {
  6898. localStorage.setItem('extra', obj.extra);
  6899. }
  6900. })();
  6901. function createHisBackDialog(callback) {
  6902. var stopTime = 0;
  6903. var time = new Date();
  6904. var cur_month = (time.getMonth() + 1) < 10 ? "0" + (time.getMonth() + 1) : (time.getMonth() + 1);
  6905. var cur_day = time.getDate() < 10 ? "0" + time.getDate() : time.getDate();
  6906. var cur_hour = time.getHours() < 10 ? "0" + time.getHours() : time.getHours();
  6907. var cur_minu = time.getMinutes() < 10 ? "0" + time.getMinutes() : time.getMinutes();
  6908. var cur_sec = time.getSeconds() < 10 ? "0" + time.getSeconds() : time.getSeconds();
  6909. var beginDate = time.getFullYear() + "-" + cur_month + "-" + cur_day + "T" + cur_hour + ":" + cur_minu + ":" + cur_sec;
  6910. var endDate = beginDate;
  6911. var nowspeed = 1, dataTime = "";
  6912. var htmlStr = '',
  6913. htmlArr = [],
  6914. ptime = "",
  6915. interTimers = [];
  6916. htmlArr.push('<div id="content">');
  6917. htmlArr.push('<label for="startTime">起始时间:<input type="datetime-local" step=1 name="beginDate" id="beginDate" style = "padding-left:3px;width:180px;height:23px;font-size:12px;background-color:rgba(255,255,255,1);" value="' + beginDate + '" /></label>&nbsp;&nbsp;&nbsp;');
  6918. htmlArr.push('<label for="endTime">结束时间:<input type="datetime-local" step=1 name="endDate" id="endDate" style = "padding-left:3px;width:180px;height:23px;font-size:12px;background-color:rgba(255,255,255,1);" value="' + endDate + '" /></label>');
  6919. htmlArr.push('<br/><input type="text" id="showTime" disabled="disabled" style="width:160px;height:23px;" name="showTime" value="' + dataTime + '"></input> x<span id="nowspeed">1</span>');
  6920. htmlArr.push('<input type="button" style="width:60px;height:23px;margin-right:5px;margin-left:60px;" id="palyTime" name="palyTime" value="播放"></input>');
  6921. htmlArr.push('<input type="button" style="width:60px;height:23px;margin-right:5px;" id="addSpeed" name="addSpeed" value="加速"></input>');
  6922. htmlArr.push('<input type="button" style="width:60px;height:23px;margin-right:5px;" id="slowSpeed" name="slowSpeed" value="减速"></input>');
  6923. htmlArr.push('<input type="button" style="width:60px;height:23px;margin-right:5px;" id="closeBtn" name="closeBtn" value="退出"></input>');
  6924. htmlArr.push('</div>');
  6925. htmlStr = $(htmlArr.join(''))[0];
  6926. // console.log(htmlStr);
  6927. dialog.setConfig({
  6928. title: "历史回放",
  6929. closable: true,
  6930. draggable: true,
  6931. width: 530,
  6932. height: 100,
  6933. contentPadding: 5,
  6934. titleBackground: '#8DB6CD',
  6935. content: htmlStr,
  6936. buttons: [
  6937. ],
  6938. buttonsAlign: "right"
  6939. });
  6940. dialog.setModal(false);
  6941. dialog.show();
  6942. $("#palyTime").click(function () {
  6943. if ($("#palyTime").val() == "播放") {
  6944. ptime = $("#beginDate").val().replace("T", " ");
  6945. var end = $("#endDate").val().replace("T", " ");
  6946. var beginTime = new Date(ptime).getTime();
  6947. var endTime = new Date(end).getTime();
  6948. //点击播放页面停止取快照
  6949. if (stopTime == 0) {
  6950. clearInterval(intervalTimers[0]);
  6951. intervalTimers.shift(intervalTimers[0]);
  6952. stopTime++;
  6953. }
  6954. $("#palyTime").val("暂停");
  6955. var timeid = setInterval(function () {
  6956. if (beginTime > endTime) {
  6957. clearInterval(interTimers[0]);
  6958. interTimers.shift(interTimers[0]);
  6959. $("#palyTime").val("播放");
  6960. } else {
  6961. $("#showTime").val(moment(ptime).format("YYYY/MM/DD h:mm:ss"));
  6962. if (varList.length <= 0) {
  6963. return;
  6964. }
  6965. var cmdStr = "";
  6966. var ajaxdata = {};
  6967. var ajaxtype = 'GET';
  6968. var str = "http://" + webServiceIP + ":" + webServicePort +
  6969. "/api/History?tagName=";
  6970. for (var i = 0; i < varList.length; i++) {
  6971. cmdStr += encodeURIComponent(varList[i]) + ","
  6972. }
  6973. cmdStr = cmdStr.substring(0, cmdStr.length - 1);
  6974. str = str + cmdStr + "&Time=" + ptime;
  6975. if (str.length > 2000) {
  6976. para = encodeURIComponent(cmdStr);
  6977. str = "http://" + webServiceIP + ":" + webServicePort + "/api/History";
  6978. ajaxdata = { 'tagname': cmdStr,'time':ptime };
  6979. ajaxtype = 'POST';
  6980. }
  6981. $.ajax({
  6982. url: str,
  6983. type: ajaxtype,
  6984. dataType: 'json',
  6985. data: ajaxdata,
  6986. cache: false,
  6987. success: function (data) {
  6988. if (data === null) return;
  6989. var hisdata = data;
  6990. if (hisdata != null) {
  6991. for (var tagName in hisdata) {
  6992. // console.log(moment(ptime).format("yyyy-MM-dd hh:mm:ss"));
  6993. //console.log(hisdata[tagName].Time.toString("yyyy-MM-dd hh:mm:ss"));
  6994. if (moment(ptime).format("YYYY-MM-DD h:mm:ss") == moment(hisdata[tagName].Time).format("YYYY-MM-DD h:mm:ss")) {
  6995. if (parseFloat(hisdata[tagName].Value).toString() == hisdata[tagName].Value) {
  6996. varListObj[tagName.toLowerCase()] = parseFloat(hisdata[tagName].Value);
  6997. VarSnapshotTime[tagName.toLowerCase()] = hisdata[tagName].Time;
  6998. } else {
  6999. varListObj[tagName.toLowerCase()] = hisdata[tagName].Value;
  7000. VarSnapshotTime[tagName.toLowerCase()] = hisdata[tagName].Time;
  7001. }
  7002. }
  7003. }
  7004. }
  7005. ptime = getDateString(new Date(beginTime + nowspeed * 1000));
  7006. beginTime = new Date(ptime).getTime();
  7007. }
  7008. })
  7009. }
  7010. }, 1000);
  7011. interTimers.push(timeid);
  7012. } else {
  7013. clearInterval(interTimers[0]);
  7014. interTimers.shift(interTimers[0]);
  7015. $("#palyTime").val("播放");
  7016. }
  7017. });
  7018. //加速
  7019. $("#addSpeed").click(function () {
  7020. if (nowspeed >= 128) {
  7021. nowspeed = 128;
  7022. } else {
  7023. nowspeed = nowspeed * 2;
  7024. }
  7025. $("#nowspeed").html(nowspeed);
  7026. });
  7027. //减速
  7028. $("#slowSpeed").click(function () {
  7029. if (nowspeed <= 1) {
  7030. nowspeed = 1;
  7031. } else {
  7032. nowspeed = nowspeed / 2;
  7033. }
  7034. $("#nowspeed").html(nowspeed);
  7035. });
  7036. $("#closeBtn").click(function () {
  7037. clearInterval(interTimers[0]);
  7038. interTimers.shift(interTimers[0]);
  7039. intervalTimers.unshift(setInterval(callback, 1000));
  7040. dialog.hide();
  7041. });
  7042. }
  7043. function savehtmlToJpg() {
  7044. //直接选择要截图的dom,就能截图,但是因为canvas的原因,生成的图片模糊
  7045. html2canvas(document.getElementsByClassName("main")[0]).then(function (canvas) {
  7046. document.body.appendChild(canvas);
  7047. })
  7048. //创建一个新的canvas
  7049. var canvas2 = document.createElement("canvas");
  7050. let _canvas = document.getElementsByClassName("main")[0];
  7051. var w = parseInt(window.getComputedStyle(_canvas).width);
  7052. var h = parseInt(window.getComputedStyle(_canvas).height);
  7053. //将canvas画布放大若干倍,然后盛放在较小的容器内,就显得不模糊了
  7054. canvas2.width = w * 2;
  7055. canvas2.height = h * 2;
  7056. canvas2.style.width = w + "px";
  7057. canvas2.style.height = h + "px";
  7058. // canvas2.width = w ;
  7059. // canvas2.height = h ;
  7060. // canvas2.style.width = w + "px";
  7061. // canvas2.style.height = h + "px";
  7062. //可以按照自己的需求,对context的参数修改,translate指的是偏移量
  7063. var context = canvas2.getContext("2d");
  7064. context.scale(2, 2);
  7065. html2canvas(document.getElementsByClassName("main")[0], { canvas: canvas2 }).then(function (canvas) {
  7066. document.body.appendChild(canvas);
  7067. var aLink = document.createElement('a');
  7068. //canvas转换成url,然后利用a标签的download属性,直接下载,绕过上传服务器再下载
  7069. var blob = base64Img2Blob(canvas.toDataURL("image/png")); //new Blob([content]);
  7070. var evt = document.createEvent("HTMLEvents");
  7071. evt.initEvent("click", false, false);//initEvent 不加后两个参数在FF下会报错
  7072. aLink.download = "下载图片.png";
  7073. aLink.href = URL.createObjectURL(blob);
  7074. aLink.dispatchEvent(evt);
  7075. aLink.click();
  7076. });
  7077. }
  7078. function base64Img2Blob(code) {
  7079. var parts = code.split(';base64,');
  7080. var contentType = parts[0].split(':')[1];
  7081. var raw = window.atob(parts[1]);
  7082. var rawLength = raw.length;
  7083. var uInt8Array = new Uint8Array(rawLength);
  7084. for (var i = 0; i < rawLength; ++i) {
  7085. uInt8Array[i] = raw.charCodeAt(i);
  7086. }
  7087. return new Blob([uInt8Array], { type: contentType });
  7088. }