| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844 |
- <!DOCTYPE html>
- <html lang="zh-CN">
- <head>
- <meta charset="UTF-8">
- <meta name="viewport"
- content="width=device-width, initial-scale=1.0, user-scalable=yes">
- <title>电力监测系统</title>
- <style>
- * {
- box-sizing: border-box;
- font-family: 'Inter', system-ui, 'Segoe UI', Roboto, 'Helvetica Neue', sans-serif;
- }
- body {
- background: #eef2f8;
- margin: 0;
- padding: 24px 20px;
- min-height: 100vh;
- }
- .dashboard { max-width: 1600px; width: 100%; margin: 0 auto; }
- .ws-status-bar {
- background: white; border-radius: 60px; padding: 8px 20px; margin-bottom: 20px;
- display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: 12px;
- box-shadow: 0 2px 8px rgba(0,0,0,0.05); border: 1px solid #e2edf7;
- }
- .ws-indicator { display: flex; align-items: center; gap: 8px; }
- .ws-led { width: 12px; height: 12px; border-radius: 50%; background-color: #aaa; transition: background-color 0.3s; }
- .ws-led.connected { background-color: #2ecc71; box-shadow: 0 0 6px #2ecc71; }
- .ws-led.disconnected { background-color: #e74c3c; }
- .ws-led.connecting { background-color: #f39c12; animation: pulse 1s infinite; }
- @keyframes pulse { 0% { opacity: 0.5; } 50% { opacity: 1; } 100% { opacity: 0.5; } }
- .ws-url { font-family: monospace; font-size: 0.8rem; color: #4a627a; }
- .reconnect-btn { background: #eef2f8; border: none; border-radius: 40px; padding: 4px 16px; font-size: 0.7rem; cursor: pointer; color: #1f6392; }
- .reconnect-btn:hover { background: #dfe7f0; }
- .tabs { display: flex; gap: 12px; margin-bottom: 24px; border-bottom: 2px solid #dfe8f0; padding-bottom: 8px; flex-wrap: wrap; }
- .tab-btn { background: none; border: none; padding: 10px 24px; font-size: 1rem; font-weight: 600; color: #6c8eae; cursor: pointer; border-radius: 40px; transition: all 0.2s; }
- .tab-btn.active { background: #1f6392; color: white; box-shadow: 0 4px 12px rgba(31,99,146,0.3); }
- .tab-btn:hover:not(.active) { background: #e2eaf1; color: #2c5a7a; }
- .tab-key-btn { background: none; border: none; padding: 10px 24px; font-size: 1rem; font-weight: 600; color: #6c8eae; cursor: pointer; border-radius: 10px;transition: all 0.2s; }
- .tab-key-btn.active { background: #a85b1b; color: white; box-shadow: 0 4px 12px rgba(241, 241, 240, 0.3); }
- .tab-key-btn:hover:not(.active) { background: #799143; color: #5a7e20; }
- .page { display: none; }
- .page.active-page { display: block; }
- .header { text-align: center; margin-bottom: 28px; }
- .header h1 { font-size: 1.7rem; font-weight: 600; background: linear-gradient(135deg, #1e2a3a, #0f2b3d); background-clip: text; -webkit-background-clip: text; color: transparent; margin: 0 0 6px 0; }
- .header p { color: #4a627a; font-size: 0.9rem; }
- .summary-panel {
- background: white; border-radius: 28px; padding: 16px 24px; margin-bottom: 20px;
- box-shadow: 0 4px 12px rgba(0,0,0,0.05); border: 1px solid #e2edf7;
- }
- .summary-title { text-align: center; font-size: 0.75rem; text-transform: uppercase; letter-spacing: 1px; color: #7c9ab8; margin-bottom: 16px; }
- .summary-grid { display: flex; flex-wrap: wrap; justify-content: center; gap: 24px; row-gap: 16px; }
- .summary-item { text-align: center; min-width: 120px; }
- .summary-label { font-size: 0.7rem; color: #7c9ab8; margin-bottom: 6px; }
- .summary-value { font-size: 1.4rem; font-weight: 700; color: #1e2f3c; }
- .summary-unit { font-size: 0.7rem; font-weight: 400; color: #7c9ab8; margin-left: 3px; }
- .table-wrapper {
- background: white; border-radius: 28px; box-shadow: 0 12px 30px rgba(0,0,0,0.08);
- overflow-x: auto; border: 1px solid #e2edf7; margin-bottom: 24px;
- }
- .power-table { width: 100%; border-collapse: separate; border-spacing: 0; min-width: 1300px; font-size: 0.85rem; }
- .power-table th { padding: 14px 10px; font-weight: 600; font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.4px; color: #2c5a7a; text-align: center; background: #f9fbfe; border-bottom: 2px solid #dfe8f0; }
- .power-table td { padding: 12px 10px; text-align: center; border-bottom: 1px solid #edf2f7; color: #1e2f3c; font-weight: 500; }
- .numeric-value { font-weight: 600; }
- .unit-sub { font-size: 0.65rem; font-weight: 400; color: #7c9ab8; margin-left: 2px; }
- .energy-cell { background: #f4faf7; font-weight: 700; color: #1a6e55; }
- .power-bg { background: #fef9e6; }
- .reactive-bg { background: #f0f0fe; }
- .pf-cell { background: #f5f0fc; font-weight: 700; color: #5e3a8c; }
- .channel-badge { display: inline-flex; align-items: center; gap: 6px; }
- .ch-icon { background: #eef2fa; border-radius: 30px; padding: 3px 8px; font-size: 0.65rem; font-weight: 600; color: #1f6392; }
- .ph-icon { color: #070707; font-weight: 700; background: #85ddb1; display: inline-block; padding: 3px 12px; border-radius: 10px; font-size: 0.75rem;}
- .action-btn { background: #eef2f8; border: none; padding: 5px 14px; border-radius: 40px; font-size: 0.7rem; font-weight: 600; cursor: pointer; color: #2c6282; min-width: 64px; }
- .action-btn:hover { background: #dfe7f0; }
- .delay-badge { background: #eef2fa; border-radius: 20px; padding: 3px 8px; font-size: 0.65rem; font-weight: 600; display: inline-block; min-width: 70px; text-align: center; }
- .delay-idle { background: #e8f0fe; color: #4f7ea0; }
- .channel-off td:not(.energy-cell) { opacity: 0.7; background-color: #fefcf5; }
- .status-on { color: #2c8f6e; font-weight: 700; background: #e0f2e9; display: inline-block; padding: 3px 12px; border-radius: 30px; font-size: 0.75rem; }
- .status-off { color: #b33; font-weight: 700; background: #ffe6e5; display: inline-block; padding: 3px 12px; border-radius: 30px; font-size: 0.75rem; }
- .action-bar { display: flex; justify-content: flex-end; gap: 12px; margin-bottom: 16px; padding: 8px 0; flex-wrap: wrap; }
- .action-bar .btn-config, .action-bar .btn-threshold, .action-bar .btn-reset,
- .action-bar .btn-on, .action-bar .btn-off, .action-bar .btn-alarm {
- background: #ffffffcc; backdrop-filter: blur(4px); border: 1px solid #cbdde9;
- border-radius: 40px; padding: 6px 18px; font-size: 0.75rem; font-weight: 600;
- cursor: pointer; position: relative;
- }
- .threshold-alarm { background-color: #ffe0e0 !important; color: #c00 !important; font-weight: 700; border-radius: 8px; }
- .threshold-low-alarm { background-color: #d4de94 !important; color: #c00 !important; font-weight: 700; border-radius: 8px; }
- .switch-btn { background: #eef2f8; border: none; padding: 5px 14px; border-radius: 40px; font-size: 0.7rem; font-weight: 600; cursor: pointer; color: #2c6282; min-width: 64px; }
- .switch-btn:hover { background: #dfe7f0; }
- .action-bar .btn-config, .action-bar .btn-threshold, .action-bar .btn-reset, .action-bar .btn-alarm { color: #1f6392; }
- .action-bar .btn-on { color: #2c8f6e; border-color: #2c8f6e; }
- .action-bar .btn-off { color: #b33; border-color: #b33; }
- .action-bar .btn-alarm { background: #fff3e0; border-color: #e6b800; color: #b8860b; }
- .action-bar .btn-alarm:hover { background: #ffe0b3; }
- .action-bar .btn-config:hover, .action-bar .btn-threshold:hover, .action-bar .btn-reset:hover,
- .action-bar .btn-on:hover, .action-bar .btn-off:hover { background: white; box-shadow: 0 2px 8px rgba(0,0,0,0.1); }
- .alarm-badge { position: absolute; top: -8px; right: -8px; background-color: #e74c3c; color: white; border-radius: 20px; padding: 2px 8px; font-size: 0.65rem; font-weight: 600; min-width: 22px; text-align: center; box-shadow: 0 1px 3px rgba(0,0,0,0.2); }
- .env-cards { display: flex; flex-wrap: wrap; gap: 20px; margin-bottom: 24px; justify-content: space-between; }
- .env-card { background: white; border-radius: 24px; padding: 16px 20px; flex: 1; min-width: 140px; text-align: center; box-shadow: 0 4px 12px rgba(0,0,0,0.05); border: 1px solid #e2edf7; transition: transform 0.2s; }
- .env-card:hover { transform: translateY(-3px); box-shadow: 0 8px 20px rgba(0,0,0,0.1); }
- .env-card .env-label { font-size: 0.8rem; text-transform: uppercase; color: #358ade; letter-spacing: 1px; margin-bottom: 8px; }
- .env-card .env-value { font-size: 1.8rem; font-weight: 700; color: #1e2f3c; }
- .env-card .env-unit { font-size: 0.8rem; font-weight: 400; color: #7c9ab8; margin-left: 4px; }
- .env-card.alarm-warning .env-value { color: #e67e22; }
- .env-card.alarm-danger .env-value { color: #e74c3c; }
- .live-footer { margin-top: 24px; display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: 12px; background: rgba(255,255,245,0.7); backdrop-filter: blur(4px); padding: 8px 20px; border-radius: 60px; }
- .footer-status { display: flex; align-items: center; gap: 12px; font-size: 0.75rem; color: #4f6f8f; }
- .channel-jump { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 20px; justify-content: center; }
- .jump-chip { background: #eef2f8; border-radius: 40px; padding: 4px 12px; font-size: 0.7rem; font-weight: 500; cursor: pointer; }
- .alarm-table { width: 100%; border-collapse: collapse; font-size: 0.8rem; }
- .alarm-table th, .alarm-table td { padding: 10px 8px; text-align: left; border-bottom: 1px solid #e2edf7; }
- .alarm-table th { background: #f8fafd; font-weight: 600; color: #2c5a7a; }
- .modal-overlay { position: fixed; top: 0; left: 0; width: 100%; height: 100%; background-color: rgba(0,0,0,0.5); backdrop-filter: blur(4px); display: flex; align-items: center; justify-content: center; z-index: 2000; visibility: hidden; opacity: 0; transition: visibility 0.2s, opacity 0.2s; }
- .modal-overlay.active { visibility: visible; opacity: 1; }
- .modal-container { background: white; border-radius: 32px; width: 90%; max-width: 950px; max-height: 85vh; display: flex; flex-direction: column; overflow: hidden; }
- .modal-header { padding: 18px 24px; border-bottom: 1px solid #e9edf2; display: flex; justify-content: space-between; align-items: center; background: #fafcff; }
- .modal-header h3 { margin: 0; font-size: 1.3rem; font-weight: 700; color: #1e2a3a; }
- .modal-close { background: none; border: none; font-size: 1.8rem; cursor: pointer; color: #8ba3bc; }
- .modal-body { padding: 20px 24px; overflow-y: auto; flex: 1; }
- .modal-footer { padding: 16px 24px; border-top: 1px solid #e9edf2; display: flex; justify-content: flex-end; gap: 12px; background: #fafcff; }
- .modal-card-overlay { position: fixed; top: 0; left: 0; width: 100%; height: 100%; background-color: rgba(0,0,0,0.5); backdrop-filter: blur(4px); display: flex; align-items: center; justify-content: center; z-index: 2000; visibility: hidden; opacity: 0; transition: visibility 0.2s, opacity 0.2s; }
- .modal-card-overlay.active { visibility: visible; opacity: 1; }
- .modal-card-container { background: white; border-radius: 32px; width: 90%; max-width: 400px; max-height: 65vh; display: flex; flex-direction: column; overflow: hidden; }
- .modal-card-header { padding: 18px 24px; border-bottom: 1px solid #e9edf2; display: flex; justify-content: space-between; align-items: center; background: #fafcff; }
- .modal-card-header h3 { margin: 0; font-size: 1.3rem; font-weight: 300; color: #1e2a3a; }
- .modal-card-close { background: none; border: none; font-size: 1.8rem; cursor: pointer; color: #8ba3bc; }
- .modal-card-body { padding: 20px 24px; overflow-y: auto; flex: 1; }
- .modal-card-footer { padding: 16px 24px; border-top: 1px solid #e9edf2; display: flex; justify-content: flex-end; gap: 12px; background: #fafcff; }
- .btn-cancel-modal { background: #eef2f8; border: none; border-radius: 40px; padding: 8px 22px; font-weight: 600; cursor: pointer; color: #2c6282; }
- .btn-confirm { background: #1f6392; color: white; border: none; border-radius: 40px; padding: 8px 22px; font-weight: 600; cursor: pointer; }
- .config-card { background: white; border-radius: 28px; box-shadow: 0 12px 30px rgba(0,0,0,0.08); padding: 28px 32px; max-width: 650px; margin: 0 auto; }
- .config-group { margin-bottom: 20px; }
- .config-group label { display: block; font-weight: 600; color: #2c5a7a; margin-bottom: 8px; font-size: 0.85rem; }
- .config-group input, .config-group select { width: 100%; padding: 12px 16px; border: 1px solid #cbdde9; border-radius: 28px; font-size: 0.9rem; background: #f9fbfe; }
- .save-config-btn { background: #1f6392; color: white; border: none; border-radius: 40px; padding: 12px 28px; font-size: 0.9rem; font-weight: 600; cursor: pointer; width: 100%; margin-top: 16px; }
- .save-config-btn:hover { background: #0e4b70; }
- .config-status { margin-top: 20px; padding: 12px; background: #e8f0fe; border-radius: 20px; font-size: 0.8rem; color: #2c5a7a; text-align: center; }
- .sub-hint { font-size: 0.7rem; color: #7c9ab8; margin-top: 4px; }
- .info-row { display: flex; justify-content: space-between; padding: 7px 0; border-bottom: 1px solid #e2edf7; }
- .info-label { font-weight: 600; color: #2c5a7a; }
- .info-value { font-weight: 500; color: #111111;}
- .datetime-set-group { display: flex; gap: 12px; margin-top: 8px; flex-wrap: wrap; }
- .datetime-set-group input { flex: 1; padding: 10px 14px; border: 1px solid #cbdde9; border-radius: 28px; }
- .btn-small { background: #eef2f8; border: none; border-radius: 40px; padding: 6px 18px; font-size: 0.75rem; font-weight: 600; cursor: pointer; color: #2c6282; }
- .btn-small:hover { background: #dfe7f0; }
- .btn-reboot { background: #eef2f8; border: none; border-radius: 40px; padding: 6px 18px; font-size: 0.75rem; font-weight: 700; cursor: pointer; color: #2c6282; }
- .btn-reboot:hover { background: #dfe7f0; }
- .config-row { background: #f9fbfe; border-radius: 20px; padding: 14px 18px; border: 1px solid #eef2f8; margin-bottom: 16px; }
- .config-row-title { font-weight: 700; font-size: 0.9rem; color: #2c5a7a; margin-bottom: 12px; }
- .config-inputs { display: flex; flex-wrap: wrap; gap: 16px; align-items: flex-end; }
- .config-item { display: flex; flex-direction: column; gap: 4px; min-width: 100px; }
- .config-item label { font-size: 0.75rem; font-weight: 600; color: #5f7e9c; }
- .config-item input { background: white; border: 1px solid #cbdde9; border-radius: 28px; padding: 8px 12px; width: 120px; font-size: 0.8rem; }
- .config-batch-row { background: #e7f0fd; border-radius: 20px; padding: 14px 18px; border: 1px solid #7386a3; margin-bottom: 16px; }
- .config-batch-item { display: flex; flex-direction: column; gap: 4px; min-width: 100px; }
- .config-batch-item label { font-size: 0.85rem; font-weight: 600; color: #114579; }
- .config-batch-item input { background: white; border: 1px solid #677883; border-radius: 28px; padding: 8px 12px; width: 120px; font-size: 0.8rem; }
- .save-channel-config-btn { background: #1f6392; color: white; border: none; border-radius: 32px; padding: 6px 20px; font-size: 0.7rem; font-weight: 600; cursor: pointer; margin-left: auto; }
- .channel-select-list { display: flex; flex-direction: column; gap: 12px; margin-bottom: 20px; }
- .channel-checkbox { display: flex; align-items: center; gap: 12px; padding: 8px 12px; background: #f9fbfe; border-radius: 40px; }
- .channel-checkbox input { width: 18px; height: 18px; cursor: pointer; }
- .channel-checkbox label { font-weight: 600; color: #1e2f3c; cursor: pointer; flex: 1; }
- .select-all-row { display: flex; gap: 16px; margin-bottom: 16px; padding-bottom: 12px; border-bottom: 1px solid #e2edf7; }
- .select-all-btn { background: #eef2f8; border: none; border-radius: 30px; padding: 6px 16px; font-size: 0.7rem; font-weight: 600; cursor: pointer; color: #2c6282; }
- .logout-btn { background: #eef2f8; border: 1px solid #cbdde9; border-radius: 40px; padding: 6px 18px; font-size: 0.7rem; font-weight: 600; cursor: pointer; color: #2c6282; margin-left: 12px; }
- .login-container { position: fixed; top: 0; left: 0; width: 100%; height: 100%; background: linear-gradient(135deg, #1e2f3c 0%, #0f2b3d 100%); display: flex; align-items: center; justify-content: center; z-index: 3000; transition: all 0.3s; }
- .login-card { background: white; border-radius: 48px; padding: 40px 36px; width: 90%; max-width: 420px; box-shadow: 0 25px 50px rgba(0,0,0,0.3); text-align: center; }
- .login-card h2 { font-size: 1.8rem; font-weight: 700; margin-bottom: 8px; background: linear-gradient(135deg, #1e2a3a, #1f6392); background-clip: text; -webkit-background-clip: text; color: transparent; }
- .login-input-group { margin-bottom: 24px; text-align: left; }
- .login-input-group label { display: block; font-weight: 600; color: #2c5a7a; margin-bottom: 8px; font-size: 0.8rem; }
- .login-input-group input { width: 100%; padding: 14px 18px; border: 1px solid #cbdde9; border-radius: 40px; font-size: 0.9rem; background: #f9fbfe; }
- .login-btn { background: #1f6392; color: white; border: none; border-radius: 40px; padding: 14px 28px; font-size: 1rem; font-weight: 700; cursor: pointer; width: 100%; transition: background 0.2s; }
- .login-btn:disabled { background: #9ab3c7; cursor: not-allowed; }
- .login-error { color: #e74c3c; font-size: 0.8rem; margin-top: 16px; min-height: 40px; }
- .hidden { display: none; }
- .add-user-btn { background: #1f6392; color: white; border: none; border-radius: 40px; padding: 8px 20px; margin-bottom: 16px; cursor: pointer; float: right; }
- .table-wrapper { background: white; border-radius: 28px; box-shadow: 0 12px 30px rgba(0,0,0,0.08); overflow-x: auto; border: 1px solid #e2edf7; margin-bottom: 24px; }
-
- .btn-icon { background: #eef2f8; border: none; padding: 4px 12px; border-radius: 30px; font-size: 0.7rem; margin: 0 4px; cursor: pointer; }
- .btn-icon.danger { color: #e74c3c; }
- .btn-icon.success { color: #2c8f6e; }
- .user-table { width: 100%; border-collapse: collapse; background: white; border-radius: 24px; overflow: hidden; }
- .user-table th, .user-table td { padding: 12px 16px; text-align: left; border-bottom: 1px solid #e2edf7; }
- .user-table th { background: #f8fafd; color: #2c5a7a; }
-
- </style>
- </head>
- <body>
- <!-- 登录页面 -->
- <div id="loginContainer" class="login-container">
- <div class="login-card">
- <h2>⚡ 电力监测系统</h2>
- <p>请输入凭证进行身份验证</p>
- <div class="login-input-group"><label>👤 用户名</label><input type="text" id="loginUsername" placeholder="admin" autocomplete="off"></div>
- <div class="login-input-group"><label>🔒 密码</label><input type="password" id="loginPassword" placeholder="******"></div>
- <button class="login-btn" id="loginBtn">登 录</button>
- <div id="loginErrorMsg" class="login-error"></div>
- </div>
- </div>
- <div id="dashboardApp" class="dashboard" style="display: none;">
-
- <div class="ws-status-bar">
- <div class="ws-indicator">
- <div class="ws-led" id="wsLed"></div>
- <span id="wsStatusText">未连接</span>
- </div>
- <div>
- <button class="logout-btn" id="logoutBtn">🚪 登出</button>
- <button class="reconnect-btn" id="reconnectBtn">🔌 重新连接</button>
- </div>
- </div>
-
- <div class="tabs">
- <button class="tab-btn active" data-page="monitor">📊 电力监测</button>
- <button class="tab-btn" data-page="network">🌐 网络配置</button>
- <button class="tab-btn" data-page="rs485">🔌 RS485配置</button>
- <button class="tab-btn" data-page="snmp">📡 SNMP配置</button>
- <button class="tab-btn" data-page="device">📟 设备信息</button>
- <button class="tab-btn" data-page="user">👥 用户管理</button>
- </div>
- <!-- 电力监测页面 -->
- <div id="monitorPage" class="page active-page">
- <div class="summary-panel">
- <div class="summary-title">📊 系统总览</div>
- <div class="summary-grid">
- <button class="tab-key-btn active" id="L1">L1</button>
- <button class="tab-key-btn" id="L2">L2</button>
- <button class="tab-key-btn" id="L3">L3</button>
- </div>
- <div class="summary-grid">
- <div class="summary-item"><div class="summary-label" id="All-V">总电压 (V)</div><div class="summary-value" id="totalVoltage">0.0<span class="summary-unit">V</span></div></div>
- <div class="summary-item"><div class="summary-label" id="All-I">总电流 (A)</div><div class="summary-value" id="totalCurrent">0.0<span class="summary-unit">A</span></div></div>
- <div class="summary-item"><div class="summary-label">总有功功率 (kW)</div><div class="summary-value" id="totalActivePower">0<span class="summary-unit">W</span></div></div>
- <div class="summary-item"><div class="summary-label">总无功功率 (kvar)</div><div class="summary-value" id="totalReactivePower">0<span class="summary-unit">var</span></div></div>
- <div class="summary-item"><div class="summary-label">总视在功率 (kVA)</div><div class="summary-value" id="totalApparentPower">0<span class="summary-unit">VA</span></div></div>
- <div class="summary-item"><div class="summary-label">总功率因数</div><div class="summary-value" id="totalPowerFactor">0.00<span class="summary-unit"></span></div></div>
- <div class="summary-item"><div class="summary-label">总耗电量(kWh)</div><div class="summary-value" id="totalConsumer">0.00<span class="summary-unit">kWh</span></div></div>
- </div>
- </div>
- <div class="action-bar">
- <button class="btn-config" id="openDelayConfigBtn">⚙️ 延时配置</button>
- <button class="btn-threshold" id="openThresholdConfigBtn">⚠️ 阈值配置</button>
- <button class="btn-reset" id="openResetEnergyModalBtn">↻ 重置耗电量(可选通道)</button>
- <button class="btn-on" id="allOnBtn">🔛 全部开启</button>
- <button class="btn-off" id="allOffBtn">⛔ 全部关闭</button>
- <button class="btn-on" id="cleanSoundLight">✏️ 清除声光报警</button>
- <button class="btn-alarm" id="openAlarmModalBtn">🔔 报警记录<span id="alarmCountBadge" class="alarm-badge" style="display:none;">0</span></button>
- </div>
- <div class="channel-jump" id="channelJumpContainer"></div>
- <div class="table-wrapper">
- <table class="power-table" id="powerTable">
- <thead>
- <tr><th>通道</th><th>相序</th><th>电压 (V)</th><th>电流 (A)</th><th>有功 (kW)</th><th>无功 (kvar)</th><th>视在 (kVA)</th><th>功率因数</th><th>频率 (Hz)</th><th>累计耗电 (kWh)</th><th>开关延时</th><th>开关状态</th><th>操作</th></tr>
- </thead>
- <tbody id="tableBody"><tr><td colspan="12">等待WebSocket数据...</td></tr></tbody>
- </table>
- </div>
- <div class="env-cards">
- <div class="env-card" id="tempCard"><div class="env-label">🌡️ 温度</div><div class="env-label" id="tempStatus">--</div><div class="env-value" id="tempValue">--<span class="env-unit">°C</span></div></div>
- <div class="env-card" id="humiCard"><div class="env-label">💧 湿度</div><div class="env-label" id="humiStatus">--</div><div class="env-value" id="humiValue">--<span class="env-unit">%RH</span></div></div>
- <div class="env-card" id="smokeCard"><div class="env-label">🔥 烟雾</div><div class="env-label" id="smokeStatus">--</div><div class="env-value" id="smokeValue">--<span class="env-unit">ppm</span></div></div>
- <div class="env-card" id="co2Card"><div class="env-label">🌫️ CO₂浓度</div><div class="env-label" id="co2Status">--</div><div class="env-value" id="co2Value">--<span class="env-unit">ppm</span></div></div>
- </div>
- </div>
- <!-- 网络配置页面 -->
- <div id="networkPage" class="page">
- <div class="header"><h1>🌐 网络配置</h1><p>配置设备网络参数 (IP/掩码/网关/DNS)</p></div>
- <div class="config-card">
- <div class="config-group"><label>📡 IP获取模式</label><select id="ipMode"><option value="auto">自动 (DHCP)</option><option value="manual">手动 (静态IP)</option></select></div>
- <div id="staticIpGroup">
- <div class="config-group"><label id="ip_lable">📌 IP地址</label><input type="text" id="ipAddress" placeholder="192.168.1.100"></div>
- <div class="config-group"><label id="mask_lable">🔗 子网掩码</label><input type="text" id="subnetMask" placeholder="255.255.255.0"></div>
- <div class="config-group"><label id="gate_lable">🚪 默认网关</label><input type="text" id="gateway" placeholder="192.168.1.1"></div>
- </div>
- <div class="config-group"><label>🌍 首选DNS服务器</label><input type="text" id="dns1" placeholder="114.114.114.114"></div>
- <div class="config-group"><label>🌍 备用DNS服务器</label><input type="text" id="dns2" placeholder="8.8.8.8"></div>
- <button class="save-config-btn" id="saveNetConfigBtn">💾 保存网络配置</button>
- <div class="config-status" id="netStatusMsg">当前配置: 未加载</div>
- </div>
- </div>
- <!-- RS485配置页面 -->
- <div id="rs485Page" class="page">
- <div class="header"><h1>🔌 RS485 通讯配置</h1><p>配置串口通讯参数 (主从机模式/地址/波特率)</p></div>
- <div class="config-card">
- <div class="config-group"><label>🎛️ 主从机模式</label><select id="rs485Mode"><option value="master">主机 (Master)</option><option value="slave">从机 (Slave)</option></select></div>
- <div class="config-group"><label>📍 设备地址 (1-247)</label><input type="number" id="rs485Addr" min="1" max="247" value="1" step="1"></div>
- <div class="config-group"><label>⚡ 波特率 (bps)</label>
- <select id="rs485Baudrate">
- <option value="9600">9600</option>
- <option value="19200">19200</option>
- <option value="38400">38400</option>
- <option value="57600">57600</option>
- <option value="115200">115200</option>
- </select>
- </div>
- <button class="save-config-btn" id="saveRs485ConfigBtn">💾 保存485配置</button>
- <div class="config-status" id="rs485StatusMsg">当前配置: 未加载</div>
- </div>
- </div>
- <!-- SNMP配置页面 -->
- <div id="snmpPage" class="page">
- <div class="header"><h1>📡 SNMP 配置</h1><p>配置简单网络管理协议参数 (社团名称/TRAP目标)</p></div>
- <div class="config-card">
- <div class="config-group"><label>🔐 只读社团名称 (Read-Only)</label><input type="text" id="snmpReadCommunity" placeholder="public" value="public"></div>
- <div class="config-group"><label>✏️ 读写社团名称 (Read-Write)</label><input type="text" id="snmpWriteCommunity" placeholder="private" value="private"></div>
- <div class="config-group"><label>🔌 TRAP状态</label><select id="snmpTrapStatus"><option value="open">开启 (Open)</option><option value="close">关闭 (Close)</option></select></div>
- <div class="config-group"><label id="trapAddr">📡 TRAP目标IP地址</label><input type="text" id="snmpTrapIp" placeholder="192.168.1.100"></div>
- <div class="sub-hint">TRAP将用于发送告警信息(如阈值超限、开关状态变化等)</div>
- <button class="save-config-btn" id="saveSnmpConfigBtn">💾 保存SNMP配置</button>
- <div class="config-status" id="snmpStatusMsg">当前配置: 未加载</div>
- </div>
- </div>
- <!-- 设备信息页面 -->
- <div id="devicePage" class="page">
- <div class="header"><h1>📟 设备信息</h1><p>查看和设置系统时间、固件版本等信息</p></div>
- <div class="config-card">
- <div class="info-row"><span class="info-label">设备型号:</span><span class="info-value">SmartPDU</span></div>
- <div class="info-row"><span class="info-label">通道数:</span><span class="info-value" id="deviceChannel"></span></div>
- <div class="info-row"><span class="info-label">供电类型:</span><span class="info-value" id="powerType"></span></div>
- <div class="info-row"><span class="info-label">控制板数:</span><span class="info-value" id="controlBoard"></span></div>
- <div class="info-row"><span class="info-label">序列号:</span><span class="info-value" id="serivalNumber">SN20241206001</span></div>
- <div class="info-row"><span class="info-label">软件版本:</span><span class="info-value" id="softVersion"></span></div>
- <div class="info-row"><span class="info-label">时区:</span><span class="info-value" id="zone"></span></div>
- <div class="info-row"><span class="info-label">当前系统时间:</span><span class="info-value" id="systemTimeDisplay">--:--:--</span></div>
- <div class="config-group" style="margin-top: 20px;">
- <label>⏰ 设置系统时间</label>
- <div class="config-card">
- <div class="config-group"><label>⚡ 时区</label>
- <select id="ntpZone">
- <option value="0">0</option>
- <option value="1">+1</option><option value="2">+2</option><option value="3">+3</option><option value="4">+4</option><option value="5">+5</option><option value="6">+6</option><option value="7">+7</option><option value="8">+8</option><option value="9">+9</option><option value="10">+10</option><option value="11">+11</option><option value="12">+12</option>
- <option value="-1">-1</option><option value="-2">-2</option><option value="-3">-3</option><option value="-4">-4</option><option value="-5">-5</option><option value="-6">-6</option><option value="-7">-7</option><option value="-8">-8</option><option value="-9">-9</option><option value="-10">-10</option><option value="-11">-11</option><option value="-12">-12</option>
- </select>
- </div>
- <div class="datetime-set-group">
- <input type="datetime-local" step="1" id="newSystemTime">
- <button class="btn-small" id="setSystemTimeBtn">同步时间</button>
- <button class="btn-reboot" id="setSystemRebootBtn">重启设备</button>
- </div>
- </div>
- </div>
- </div>
- </div>
- <!-- 用户管理界面 (新增) -->
- <div id="userPage" class="page">
- <div class="header"><h1>👥 用户管理</h1></div>
- <div style="display: flex; justify-content: space-between; align-items: center; margin-bottom: 20px;">
- <h3 style="margin:0;">用户列表</h3>
- <button class="add-user-btn" id="addUserBtn">➕ 新增用户</button>
- </div>
- <div class="table-wrapper" style="overflow-x: auto;">
- <table class="user-table" id="userTable">
- <thead><tr><th style="text-align:center;">用户名</th><th style="text-align:center;">角色</th><th style="text-align:center;">创建时间</th><th style="text-align:center;">操作</th></tr></thead>
- <tbody id="userTableBody"><tr><td colspan="3" style="text-align:center;">暂无用户数据</td></tr></tbody>
- </table>
- </div>
- </div>
- </div>
- <!-- 模态框 -->
- <div id="alarmModal" class="modal-overlay">
- <div class="modal-container">
- <div class="modal-header"><h3>🔔 报警记录</h3><button class="modal-close" id="closeAlarmModalBtn">×</button></div>
- <div class="modal-body"><div id="alarmListContainer"><div style="text-align:center;color:#888;padding:20px;">暂无报警记录</div></div></div>
- <div class="modal-footer"><button class="btn-cancel-modal" id="clearAlarmBtn">清空记录</button><button class="btn-cancel-modal" id="cancelAlarmModalBtn">关闭</button></div>
- </div>
- </div>
- <div id="delayModal" class="modal-overlay">
- <div class="modal-container">
- <div class="modal-header"><h3>⏱️ 通道延时设置</h3><button class="modal-close" id="closeDelayModalBtn">×</button></div>
- <div class="modal-body"><div id="delayGrid"></div></div>
- <div class="modal-footer"><button class="btn-cancel-modal" id="cancelDelayModalBtn">关闭</button></div>
- </div>
- </div>
- <div id="thresholdModal" class="modal-overlay">
- <div class="modal-container">
- <div class="modal-header"><h3>⚠️ 阈值配置</h3><button class="modal-close" id="closeThresholdModalBtn">×</button></div>
- <div class="modal-body"><div id="pathchGrid"></div><div id="thresholdGrid"></div></div>
- <div class="modal-footer"><button class="btn-cancel-modal" id="cancelThresholdModalBtn">关闭</button></div>
- </div>
- </div>
-
- <div id="resetEnergyModal" class="modal-overlay">
- <div class="modal-container">
- <div class="modal-header"><h3>↻ 选择要重置耗电量的通道</h3><button class="modal-close" id="closeResetModalBtn">×</button></div>
- <div class="modal-body">
- <div class="select-all-row"><button class="select-all-btn" id="selectAllChannels">全选</button><button class="select-all-btn" id="deselectAllChannels">全不选</button></div>
- <div class="channel-select-list" id="channelSelectList"></div>
- </div>
- <div class="modal-footer"><button class="btn-cancel-modal" id="cancelResetModalBtn">取消</button><button class="btn-confirm" id="confirmResetEnergyBtn">确认重置</button></div>
- </div>
- </div>
- <!-- Temp 模态框 -->
- <div id="tempCardModal" class="modal-card-overlay">
- <div class="modal-card-container">
- <div class="modal-card-header"><h3>🌡️ 温度配置</h3><button class="modal-card-close" id="closeTempModalBtn">×</button></div>
- <div class="modal-card-body">
- <div class="config-group"><label>🔺最大值</label><input type="text" id="tempMax" placeholder="25.5"></div>
- <div class="config-group"><label>🔻最小值</label><input type="text" id="tempMin" placeholder="12.6"></div>
- </div>
- <div class="modal-card-footer"><button class="btn-confirm" id="confirmTempThrBtn">提交</button></div>
- </div>
- </div>
- <div id="humiCardModal" class="modal-card-overlay">
- <div class="modal-card-container">
- <div class="modal-card-header"><h3>💧 湿度配置</h3><button class="modal-card-close" id="closeHumiModalBtn">×</button></div>
- <div class="modal-card-body">
- <div class="config-group"><label>🔺最大值</label><input type="text" id="humiMax" placeholder="80.5"></div>
- <div class="config-group"><label>🔻最小值</label><input type="text" id="humiMin" placeholder="50.6"></div>
- </div>
- <div class="modal-card-footer"><button class="btn-confirm" id="confirmHumiThrBtn">提交</button></div>
- </div>
- </div>
- <div id="smokeCardModal" class="modal-card-overlay">
- <div class="modal-card-container">
- <div class="modal-card-header"><h3>🔥 烟雾配置</h3><button class="modal-card-close" id="closeSmokeModalBtn">×</button></div>
- <div class="modal-card-body">
- <div class="config-group"><label>🔺最大值</label><input type="text" id="smokeMax" placeholder="25.5"></div>
- <div class="config-group"><label>🔻最小值</label><input type="text" id="smokeMin" placeholder="12.6"></div>
- </div>
- <div class="modal-card-footer"><button class="btn-confirm" id="confirmSmokeThrBtn">提交</button></div>
- </div>
- </div>
- <div id="co2CardModal" class="modal-card-overlay">
- <div class="modal-card-container">
- <div class="modal-card-header"><h3>🌫️ CO₂配置</h3><button class="modal-card-close" id="closeCo2ModalBtn">×</button></div>
- <div class="modal-card-body">
- <div class="config-group"><label>🔺最大值</label><input type="text" id="Co2Max" placeholder="25.5"></div>
- <div class="config-group"><label>🔻最小值</label><input type="text" id="Co2Min" placeholder="12.6"></div>
- </div>
- <div class="modal-card-footer"><button class="btn-confirm" id="confirmCo2ThrBtn">提交</button></div>
- </div>
- </div>
- <!-- 用户编辑模态框 -->
- <div id="userModal" class="modal-card-overlay">
- <div class="modal-card-container">
- <div class="modal-card-header"><h3 id="userModalTitle">编辑用户</h3><button class="modal-card-close" id="closeUserModalBtn">×</button></div>
- <div class="modal-body">
- <div class="config-group"><label>用户名</label><input type="text" id="userName" placeholder="请输入用户名" autocomplete="off"></div>
- <div class="config-group"><label>旧密码</label><input type="password" id="userOldPassword" placeholder="留空则不修改密码(编辑时)"></div>
- <div class="config-group"><label>新密码</label><input type="password" id="userNewPassword" placeholder="留空则不修改密码(编辑时)"></div>
- <div class="config-group"><label>角色</label><select id="userRole"><option value="superadmin">超级管理员</option><option value="admin">管理员</option><option value="user">普通用户</option></select></div>
- <div id="loginUpdateErrorMsg" class="login-error"></div>
- </div>
- <div class="modal-card-footer"><button class="btn-cancel-modal" id="cancelUserModalBtn">取消</button><button class="btn-confirm" id="confirmUserBtn">确认</button></div>
- </div>
- </div>
- <!-- 用户新增 -->
- <div id="userAddModal" class="modal-card-overlay">
- <div class="modal-card-container">
- <div class="modal-card-header"><h3 id="userAddModalTitle">新增用户</h3><button class="modal-card-close" id="closeUserAddModalBtn">×</button></div>
- <div class="modal-body">
- <div class="config-group"><label>用户名</label><input type="text" id="userAddName" placeholder="请输入用户名" autocomplete="off"></div>
- <div class="config-group"><label>密码</label><input type="password" id="userAddPassword" placeholder="留空则不修改密码(编辑时)"></div>
- <div class="config-group"><label>角色</label><select id="userAddRole"><option value="superadmin">超级管理员</option><option value="admin">管理员</option><option value="user">普通用户</option></select></div>
- <div id="loginAddErrorMsg" class="login-error"></div>
- </div>
- <div class="modal-card-footer"><button class="btn-cancel-modal" id="cancelUserAddModalBtn">取消</button><button class="btn-confirm" id="confirmUserAddBtn">确认</button></div>
- </div>
- </div>
-
- <script>
- const PKT_TYPE = function() {
- var len = 0;
- return {
- NEW_PKT_TYPE_DEVICE_INFO: len++,
- NEW_PKT_TYPE_ELE_INFO: len++,
- NEW_PKT_TYPE_SENSOR: len++,
- NEW_PKT_TYPE_NETWORK: len++,
- NEW_PKT_TYPE_RS485: len++,
- NEW_PKT_TYPE_SNMP: len++,
- NEW_PKT_TYPE_WANNING: len++,
- NEW_PKT_TYPE_NTP :len++,
- MEW_PKT_TYPE_LOGIN :len++,
- NEW_PKT_TYPE_USER :len++,
- }
- }();
- const SUB_POWER_TYPE = function() {
- var len = 0;
- return {
- NEW_SUB_PKT_TYPE_ELE_DATA_L1: len++,
- NEW_SUB_PKT_TYPE_ELE_DATA_L2: len++,
- NEW_SUB_PKT_TYPE_ELE_DATA_L3: len++,
- NEW_SUB_PKT_TYPE_ELE_DATA_INFO: len++,
- NEW_SUB_PKT_TYPE_ELE_DATA_ALL: len++,
- NEW_SUB_PKT_TYPE_ELE_DATA_THR: len++,
- NEW_SUB_PKT_TYPE_ELE_DELAY: len++,
- NEW_SUB_PKT_TYPE_ELE_CLEAR_CONSUMER: len++,
- NEW_SUB_PKT_TYPE_ELE_CTRL: len++,
- NEW_SUB_PKT_TYPE_ELE_ALL_CTRL: len++,
- NEW_SUB_PKT_TYPE_ELE_BATCH: len++,
- }
- }();
- const SUB_SENSOR_TYPE = function() {
- var len = 0;
- return {
- NEW_SUB_PKT_TYPE_HUMI: len++,
- NEW_SUB_PKT_TYPE_TEMP: len++,
- NEW_SUB_PKT_TYPE_SMOKE: len++,
- NEW_SUB_PKT_TYPE_CO2: len++,
- }
- }();
- const SUB_WANNING_TYPE = function(){
- var len = 0;
- return{
- NEW_SUB_PKT_TYPE_WANNING_CLEAN:len++,
- NEW_SUB_PKT_TYPE_WANNING_SOUND_LIGHT_CLEAN:len++,
- }
- }();
- const SUB_USER_TYPE = function(){
- var len = 0;
- return{
- NEW_SUB_PKT_TYPE_USER_INFO:len++,
- NEW_SUB_PKT_TYPE_USER_ADD:len++,
- NEW_SUB_PKT_TYPE_USER_UPDATE:len++,
- NEW_SUB_PKT_TYPE_USER_DELETE:len++,
- }
- }();
-
- function array_set(array, str, offset) {
- const encoder = new TextEncoder();
- const buffer = encoder.encode(str);
- array.set(buffer, offset);
- }
- function array_to_string(data) {
- const decoder = new TextDecoder('utf-8');
- const decoded = decoder.decode(data);
- const cleaned = decoded.replace(/\0/g, '');
- return cleaned;
- }
- function array_cat(a1, a2) {
- var tlen = a1.byteLength + a2.byteLength;
- var buffer = new ArrayBuffer(tlen);
- var vw = new Uint8Array(buffer);
- var vw1 = new Uint8Array(a1);
- for (var i = 0; i < a1.byteLength; i++) {
- vw[i] = vw1[i];
- }
- var vw2 = new Uint8Array(a2);
- for (var i = 0; i < a2.byteLength; i++) {
- vw[i + a1.byteLength] = vw2[i];
- }
- return buffer;
- }
-
- function bin_to_hdr(bin) {
- var tmp, length = 0;
- tmp = new DataView(bin, length); this.magic = tmp.getUint16(0, true); length += 2;
- tmp = new DataView(bin, length); this.addr = tmp.getUint8(0, true); length += 1;
- tmp = new DataView(bin, length); this.type = tmp.getUint8(0, true); length += 1;
- tmp = new DataView(bin, length); this.subtype = tmp.getUint8(0, true); length += 1;
- tmp = new DataView(bin, length); this.nack = tmp.getUint8(0, true); length += 1;
- tmp = new DataView(bin, length); this.flag = tmp.getUint32(0, true); length += 4;
- tmp = new DataView(bin, length); this.dlen = tmp.getUint32(0, true); length += 4;
- this.len = length;
- }
-
- function mk_hdr_bin(addr, type, subtype, nack, flag, dlen) {
- var tmp, length = 0;
- var t = MAGIC;
- var buffer = new ArrayBuffer(14);
- tmp = new DataView(buffer, length); tmp.setUint16(0, t, true); length += 2; //MAGIC
- tmp = new DataView(buffer, length); tmp.setUint8(0, addr, true); length += 1; //addr
- tmp = new DataView(buffer, length); tmp.setUint8(0, type, true); length += 1; //type
- tmp = new DataView(buffer, length); tmp.setUint8(0, subtype, true); length += 1; //subtype
- tmp = new DataView(buffer, length); tmp.setUint8(0, nack, true); length += 1; //nack
- tmp = new DataView(buffer, length); tmp.setUint32(0, flag, true); length += 4; //flag
- tmp = new DataView(buffer, length); tmp.setUint32(0, dlen, true); length += 4; //dlen
- return buffer;
- }
- function bin_to_device_info(bin) {
- var tmp, bin2, length = 0;
- tmp = new DataView(bin, length); this.chs = tmp.getUint8(0, true); length += 1;
- tmp = new DataView(bin, length); this.power_type = tmp.getInt8(0, true); length += 1;
- tmp = new DataView(bin, length); this.zone = tmp.getUint8(0, true); length += 1;
- tmp = new DataView(bin, length); this.board_cnt = tmp.getUint8(0, true); length += 1;
- this.soft_version = array_to_string(bin.slice(length, 32)); length += 32;
- this.hard_version = array_to_string(bin.slice(length, length + 32)); length += 32;
- this.date = array_to_string(bin.slice(length, length + 16)); length += 16;
- this.time = array_to_string(bin.slice(length, length + 16)); length += 16;
-
- this.len = length;
- }
- function bin_to_power_th(bin) {
- var tmp, length = 2;
- tmp = new DataView(bin, length); this.v_upper = tmp.getFloat32(0, true); length += 4;
- tmp = new DataView(bin, length); this.v_lower = tmp.getFloat32(0, true); length += 4;
- tmp = new DataView(bin, length); this.c_upper = tmp.getFloat32(0, true); length += 4;
- tmp = new DataView(bin, length); this.p_upper = tmp.getFloat32(0, true); length += 4;
- tmp = new DataView(bin, length); this.w_upper = tmp.getFloat32(0, true); length += 4;
- this.len = length;
- }
- function bin_to_sensor(bin){
- var tmp, length = 0;
- this.name = array_to_string(bin.slice(length, 32)); length += 32;
- tmp = new DataView(bin, length); this.status = tmp.getUint8(0, true); length += 1;
- tmp = new DataView(bin, length); this.v_max_wrn = tmp.getUint8(0, true); length += 1;
- tmp = new DataView(bin, length); this.v_min_wrn = tmp.getUint8(0, true); length += 1;
- tmp = new DataView(bin, length); this.value = tmp.getFloat32(0, true); length += 4;
- tmp = new DataView(bin, length); this.v_max = tmp.getFloat32(0, true); length += 4;
- tmp = new DataView(bin, length); this.v_min = tmp.getFloat32(0, true); length += 4;
- this.len = length;
- }
- function bin_to_network(bin)
- {
- var tmp, length = 0;
- tmp = new DataView(bin, length); this.mode = tmp.getUint8(0, true); length += 1;
- this.ipaddr = array_to_string(bin.slice(length, length+48)); length += 48;
- this.mask = array_to_string(bin.slice(length, length+48)); length += 48;
- this.gateway = array_to_string(bin.slice(length, length+48)); length += 48;
- this.dns1 = array_to_string(bin.slice(length, length+48)); length += 48;
- this.dns2 = array_to_string(bin.slice(length, length+48)); length += 48;
- this.len = length;
- }
- function bin_to_rs485(bin)
- {
- var tmp, length = 0;
- tmp = new DataView(bin, length); this.mode = tmp.getUint8(0, true); length += 1;
- tmp = new DataView(bin, length); this.addr = tmp.getUint8(0, true); length += 1;
- tmp = new DataView(bin, length); this.baud = tmp.getUint32(0, true); length += 4;
- this.len = length;
- }
-
- function bin_to_snmp(bin)
- {
- var tmp, length = 0;
- tmp = new DataView(bin, length); this.mode = tmp.getUint8(0, true); length += 1;
- tmp = new DataView(bin, length); this.version = tmp.getUint8(0, true); length += 1;
- this.publics = array_to_string(bin.slice(length, length+10)); length += 10;
- this.privates = array_to_string(bin.slice(length, length+10)); length += 10;
- tmp = new DataView(bin, length); this.trapmode = tmp.getUint8(0, true); length += 1;
- this.nms_ip = array_to_string(bin.slice(length, length+32)); length += 32;
- this.len = length;
- }
- function bin_to_login(bin)
- {
- var tmp, length = 0;
- tmp = new DataView(bin, length); this.flag = tmp.getUint8(0, true); length += 1;
- this.len = length;
- }
- function bin_to_user(bin)
- {
- var tmp, length = 0;
- tmp = new DataView(bin, length); this.flag = tmp.getUint8(0, true); length += 1;
- this.len = length;
- }
- function bin_to_user_cnt(bin)
- {
- var tmp,length = 0;
- tmp = new DataView(bin, length); this.cnt = tmp.getUint32(0, true); length += 4;
- this.len = length;
- }
- function bin_to_users(bin)
- {
- var tmp, length = 0;
- tmp = new DataView(bin, length); this.role = tmp.getUint32(0, true); length += 4;
- this.user = array_to_string(bin.slice(length, length+32)); length += 32;
- this.date = array_to_string(bin.slice(length, length+16)); length += 16;
- this.time = array_to_string(bin.slice(length, length+16)); length += 16;
- this.len = length;
- }
-
- function bin_to_wanning_count(bin)
- {
- var tmp, length = 0;
- tmp = new DataView(bin, length); this.count = tmp.getUint16(0, true); length += 2;
- this.len = length;
- }
- function bin_to_wanning(bin)
- {
- var tmp, length = 0;
- tmp = new DataView(bin, length); this.type = tmp.getUint8(0, true); length += 1;
- this.date = array_to_string(bin.slice(length, length+32)); length += 32;
- this.context = array_to_string(bin.slice(length, length+64)); length += 64;
- this.len = length;
- }
- function bin_to_power(bin) {
- var tmp, length = 0;
- tmp = new DataView(bin, length); this.voltage = tmp.getFloat32(0, true); length += 4;
- tmp = new DataView(bin, length); this.current = tmp.getFloat32(0, true); length += 4;
- tmp = new DataView(bin, length); this.power = tmp.getFloat32(0, true); length += 4;
- tmp = new DataView(bin, length); this.reactive_power = tmp.getFloat32(0, true); length += 4;
- tmp = new DataView(bin, length); this.app_power = tmp.getFloat32(0, true); length += 4;
- tmp = new DataView(bin, length); this.freq = tmp.getFloat32(0, true); length += 4;
- tmp = new DataView(bin, length); this.factor = tmp.getFloat32(0, true); length += 4;
- tmp = new DataView(bin, length); this.consump = tmp.getFloat32(0, true); length += 4;
- this.len = length;
- }
-
- function bin_to_power_info(bin) {
- var tmp, length = 0;
- this.name = array_to_string(bin.slice(length, 16)); length += 16;
- tmp = new DataView(bin, length); this.addr = tmp.getUint8(0, true); length += 1;
- tmp = new DataView(bin, length); this.sch = tmp.getUint8(0, true); length += 1;
- tmp = new DataView(bin, length); this.phse = tmp.getUint8(0, true); length += 1;
- tmp = new DataView(bin, length); this.phse1 = tmp.getUint8(0, true); length += 1;
- tmp = new DataView(bin, length); this.open = tmp.getUint8(0, true); length += 1;
- tmp = new DataView(bin, length); this.close = tmp.getUint8(0, true); length += 1;
- tmp = new DataView(bin, length); this.status = tmp.getUint8(0, true); length += 1;
- tmp = new DataView(bin, length); let val = tmp.getUint32(0, true); length += 4;
- this.l1_v_upper = (val & 0x1); this.l1_v_lower = (val & 0x2); this.l1_c_upper = (val & 0x4); this.l1_p_upper = (val & 0x8); this.l1_w_upper = (val & 0x10);
- this.l2_v_upper = (val & (1 << 8)); this.l2_v_lower = (val & (1 << 9)); this.l2_c_upper = (val & (1 << 10)); this.l2_p_upper = (val & (1 << 11)); this.l2_w_upper = (val & (1 << 12));
- this.l3_v_upper = (val & (1 << 16)); this.l3_v_lower = (val & (1 << 17)); this.l3_c_upper = (val & (1 << 18)); this.l3_p_upper = (val & (1 << 19)); this.l3_w_upper = (val & (1 << 20));
- this.ph_loss1 = (val & (1 << 24)); this.ph_loss2 = (val & (1 << 25)); this.ph_loss3 = (val & (1 << 26));
- this.len = length;
- }
- function ctrl_to_bin(data)
- {
- var bin, tmp, length = 0;
- bin = new ArrayBuffer(data.len);
- tmp = new DataView(bin, length); tmp.setUint8(0, data.sch, true); length +=1;
- tmp = new DataView(bin, length); tmp.setUint8(0, data.status, true); length +=1;
- return bin;
- }
- function reboot_to_bin(data)
- {
- var bin, tmp, length = 0;
- bin = new ArrayBuffer(data.len);
- tmp = new DataView(bin, length); tmp.setUint8(0, data.flag, true); length +=1;
- return bin;
- }
- function delay_to_bin(data)
- {
- var bin, tmp, length = 0;
- bin = new ArrayBuffer(data.len);
- tmp = new DataView(bin, length); tmp.setUint8(0, data.channel, true); length +=1;
- tmp = new DataView(bin, length); tmp.setUint8(0, data.open, true); length +=1;
- tmp = new DataView(bin, length); tmp.setUint8(0, data.close, true); length +=1;
- return bin;
- }
- function thr_to_bin(data)
- {
- var bin, tmp, length = 0;
- bin = new ArrayBuffer(data.len);
- tmp = new DataView(bin, length); tmp.setUint8(0, data.channel, true); length +=1;
- tmp = new DataView(bin, length); tmp.setUint16(0, data.en, true); length +=2;
- tmp = new DataView(bin, length); tmp.setFloat32(0, data.vmax, true); length +=4;
- tmp = new DataView(bin, length); tmp.setFloat32(0, data.vmin, true); length +=4;
- tmp = new DataView(bin, length); tmp.setFloat32(0, data.cmax, true); length +=4;
- tmp = new DataView(bin, length); tmp.setFloat32(0, data.pmax, true); length +=4;
- tmp = new DataView(bin, length); tmp.setFloat32(0, data.wmax, true); length +=4;
- return bin;
- }
- function clear_consumer_bin(data)
- {
- var bin, tmp, length = 0;
- bin = new ArrayBuffer(data.len);
- tmp = new DataView(bin, length); tmp.setUint8(0, data.channel, true); length +=1;
- return bin;
- }
-
- function all_contol_to_bin(data)
- {
- var bin, tmp, length = 0;
- bin = new ArrayBuffer(data.len);
- tmp = new DataView(bin, length); tmp.setUint8(0, data.status, true); length +=1;
- return bin;
- }
- function sensor_thr_to_bin(data)
- {
- var bin, tmp, length = 0;
- bin = new ArrayBuffer(data.len);
- tmp = new DataView(bin, length); tmp.setFloat32(0, data.vmax, true); length +=4;
- tmp = new DataView(bin, length); tmp.setFloat32(0, data.vmin, true); length +=4;
- return bin;
- }
- function network_to_bin(data)
- {
- var bin, tmp, length = 0;
- bin = new ArrayBuffer(data.len);
- tmp = new DataView(bin, length); tmp.setUint8(0, data.ipMode,true); length += 1;
- array_set(new Uint8Array(bin), data.ipAddress, length); length += 48;
- array_set(new Uint8Array(bin), data.subnetMask, length); length += 48;
- array_set(new Uint8Array(bin), data.gateway, length); length += 48;
- array_set(new Uint8Array(bin), data.dns1, length); length += 48;
- array_set(new Uint8Array(bin), data.dns2, length); length += 48;
- return bin;
- }
- function rs485_to_bin(data)
- {
- var bin, tmp, length = 0;
- bin = new ArrayBuffer(data.len);
- tmp = new DataView(bin, length); tmp.setUint8(0, data.rs485Mode,true); length += 1;
- tmp = new DataView(bin, length); tmp.setUint8(0, data.rs485Addr,true); length += 1;
- tmp = new DataView(bin, length); tmp.setUint32(0, data.rs485Baudrate,true); length += 4;
- return bin;
- }
- function snmp_to_bin(data)
- {
- var bin, tmp, length = 0;
- bin = new ArrayBuffer(data.len);
- tmp = new DataView(bin, length); tmp.setUint8(0, data.mode,true); length += 1;
- tmp = new DataView(bin, length); tmp.setUint8(0, data.version,true); length += 1;
- array_set(new Uint8Array(bin), data.snmpReadCommunity, length); length += 10;
- array_set(new Uint8Array(bin), data.snmpWriteCommunity, length); length += 10;
- tmp = new DataView(bin, length); tmp.setUint8(0, data.snmpTrapStatus,true); length += 1;
- array_set(new Uint8Array(bin), data.snmpTrapIp, length); length += 32;
- return bin;
- }
- function ntp_to_bin(data)
- {
- var bin, tmp, length = 0;
- bin = new ArrayBuffer(data.len);
- tmp = new DataView(bin, length); tmp.setInt8(0, data.ntpZone,true); length += 1;
- array_set(new Uint8Array(bin), data.ntpDateTime, length); length += 32;
- return bin;
- }
- function wanning_to_bin(data)
- {
- var bin, tmp, length = 0;
- bin = new ArrayBuffer(data.len);
- tmp = new DataView(bin, length); tmp.setUint8(0, data.value,true); length += 1;
- return bin;
- }
- function user_add_to_bin(data)
- {
- var bin, tmp, length = 0;
- bin = new ArrayBuffer(data.len);
- tmp = new DataView(bin, length); tmp.setUint8(0, data.role,true); length += 1;
- array_set(new Uint8Array(bin), data.user, length); length += 32;
- array_set(new Uint8Array(bin), data.password, length); length += 32;
- return bin;
- }
- function user_delete_to_bin(data)
- {
- var bin, tmp, length = 0;
- bin = new ArrayBuffer(data.len);
- array_set(new Uint8Array(bin), data.user, length); length += 32;
- return bin;
- }
-
- function user_update_to_bin(data)
- {
- var bin, tmp, length = 0;
- bin = new ArrayBuffer(data.len);
- tmp = new DataView(bin, length); tmp.setUint8(0, data.role,true); length += 1;
- array_set(new Uint8Array(bin), data.user, length); length += 32;
- array_set(new Uint8Array(bin), data.old_password, length); length += 32;
- array_set(new Uint8Array(bin), data.new_password, length); length += 32;
- return bin;
- }
- function pkt_to_bin(addr, type, subtype, nack, flag, js) {
- var tmp;
- var buffer = new mk_hdr_bin(addr, type, subtype, nack, flag, js.len);
- switch(type)
- {
- case PKT_TYPE.NEW_PKT_TYPE_DEVICE_INFO:
- {
- tmp = new reboot_to_bin(js);
- }
- break;
- case PKT_TYPE.NEW_PKT_TYPE_ELE_INFO:
- {
- switch(subtype)
- {
- case SUB_POWER_TYPE.NEW_SUB_PKT_TYPE_ELE_CTRL:
- {
- tmp = new ctrl_to_bin(js);
- }
- break;
- case SUB_POWER_TYPE.NEW_SUB_PKT_TYPE_ELE_DELAY:
- {
- tmp = new delay_to_bin(js);
- }
- break;
- case SUB_POWER_TYPE.NEW_SUB_PKT_TYPE_ELE_DATA_THR:
- case SUB_POWER_TYPE.NEW_SUB_PKT_TYPE_ELE_BATCH:
- {
- tmp = new thr_to_bin(js);
- }
- break;
- case SUB_POWER_TYPE.NEW_SUB_PKT_TYPE_ELE_CLEAR_CONSUMER:
- {
- tmp = new clear_consumer_bin(js);
- }
- break;
- case SUB_POWER_TYPE.NEW_SUB_PKT_TYPE_ELE_ALL_CTRL:
- {
- tmp = new all_contol_to_bin(js);
- }
- break;
- default:
- break;
- }
- }
- break;
- case PKT_TYPE.NEW_PKT_TYPE_SENSOR:
- {
- tmp = new sensor_thr_to_bin(js);
- }
- break;
- case PKT_TYPE.NEW_PKT_TYPE_NETWORK:
- {
- tmp = new network_to_bin(js);
- }
- break;
- case PKT_TYPE.NEW_PKT_TYPE_RS485:
- {
- tmp = new rs485_to_bin(js);
- }
- break;
- case PKT_TYPE.NEW_PKT_TYPE_SNMP:
- {
- tmp = new snmp_to_bin(js);
- }
- break;
- case PKT_TYPE.NEW_PKT_TYPE_NTP:
- {
- tmp = new ntp_to_bin(js);
- }
- break;
- case PKT_TYPE.NEW_PKT_TYPE_WANNING:
- {
- switch(subtype)
- {
- case SUB_WANNING_TYPE.NEW_SUB_PKT_TYPE_WANNING_CLEAN:
- {
- tmp = new wanning_to_bin(js);
- }
- break;
- case SUB_WANNING_TYPE.NEW_SUB_PKT_TYPE_WANNING_SOUND_LIGHT_CLEAN:
- {
- tmp = new wanning_to_bin(js);
- }
- break;
- default:
- break;
- }
- }
- break;
- case PKT_TYPE.NEW_PKT_TYPE_USER:
- {
- switch(subtype)
- {
- case SUB_USER_TYPE.NEW_SUB_PKT_TYPE_USER_ADD:
- {
- tmp = new user_add_to_bin(js);
- }
- break;
- case SUB_USER_TYPE.NEW_SUB_PKT_TYPE_USER_UPDATE:
- {
- tmp = new user_update_to_bin(js);
- }
- break;
- case SUB_USER_TYPE.NEW_SUB_PKT_TYPE_USER_DELETE:
- {
- tmp = new user_delete_to_bin(js);
-
- }
- break;
- }
- }
- break;
- default:
- break;
- }
- return array_cat(buffer, tmp);
- }
- function single_ctrl(channel,status)
- {
- data = {sch:0,status:0,len:2};
- data.sch = channel;
- data.status = status;
- a = pkt_to_bin(0, PKT_TYPE.NEW_PKT_TYPE_ELE_INFO, SUB_POWER_TYPE.NEW_SUB_PKT_TYPE_ELE_CTRL, 0, 0, data);
- ws.send(a);
- }
-
-
- function channel_set_delay(channel,open,close)
- {
- data = [];
- data.channel = channel;
- data.open = open;
- data.close = close;
- data.len = 3;
- a = pkt_to_bin(0, PKT_TYPE.NEW_PKT_TYPE_ELE_INFO, SUB_POWER_TYPE.NEW_SUB_PKT_TYPE_ELE_DELAY, 0, 0, data);
- ws.send(a);
- }
- function channel_set_thr(channel,vmax,vmin,cmax,pmax,wmax)
- {
- data = [];
- data.channel = channel;
- data.en=0x1F;
- data.vmax = vmax;
- data.vmin = vmin;
- data.cmax = cmax;
- data.pmax = pmax;
- data.wmax = wmax;
- data.len = 23;
- a = pkt_to_bin(0, PKT_TYPE.NEW_PKT_TYPE_ELE_INFO, SUB_POWER_TYPE.NEW_SUB_PKT_TYPE_ELE_DATA_THR, 0, 0, data);
- ws.send(a);
- }
- function batch_set_thr(channel,vmax,vmin,cmax,pmax,wmax)
- {
- data = [];
- data.channel = 0;
- data.en=0x1F;
- data.vmax = vmax;
- data.vmin = vmin;
- data.cmax = cmax;
- data.pmax = pmax;
- data.wmax = wmax;
- data.len = 23;
- a = pkt_to_bin(0, PKT_TYPE.NEW_PKT_TYPE_ELE_INFO, SUB_POWER_TYPE.NEW_SUB_PKT_TYPE_ELE_BATCH, 0, 0, data);
- ws.send(a);
- }
- function channel_clear_consumer(channel)
- {
- data = [];
- data.channel = channel;
- data.len = 1;
- a = pkt_to_bin(0, PKT_TYPE.NEW_PKT_TYPE_ELE_INFO, SUB_POWER_TYPE.NEW_SUB_PKT_TYPE_ELE_CLEAR_CONSUMER, 0, 0, data);
- ws.send(a);
- }
-
-
- function all_contrl(status)
- {
- data = [];
- data.status = status;
- data.len = 1;
- a = pkt_to_bin(0, PKT_TYPE.NEW_PKT_TYPE_ELE_INFO, SUB_POWER_TYPE.NEW_SUB_PKT_TYPE_ELE_ALL_CTRL, 0, 0, data);
- ws.send(a);
- }
- function set_sensor_thr(vmax,vmin,type)
- {
- data = [];
- data.vmax = vmax;
- data.vmin = vmin;
- data.len = 8;
- a = pkt_to_bin(0, PKT_TYPE.NEW_PKT_TYPE_SENSOR,type, 0, 0, data);
- console.log(data.vmax,data.vmin);
- ws.send(a);
- }
-
- function clean_alarm()
- {
- data = [];
- data.value = 0;
- data.len = 1;
- a = pkt_to_bin(0, PKT_TYPE.NEW_PKT_TYPE_WANNING,SUB_WANNING_TYPE.NEW_SUB_PKT_TYPE_WANNING_CLEAN, 0, 0, data);
- ws.send(a);
- }
- function clean_sound_light()
- {
- data = [];
- data.value = 0;
- data.len = 1;
- a = pkt_to_bin(0, PKT_TYPE.NEW_PKT_TYPE_WANNING,SUB_WANNING_TYPE.NEW_SUB_PKT_TYPE_WANNING_SOUND_LIGHT_CLEAN, 0, 0, data);
- ws.send(a);
- showToast("清除声光报警", 1000);
- }
-
- var temp = [];
- function bin_parse(bin) {
- var tmp, h = new bin_to_hdr(bin);
- if (h.nack == 1) {}
- var data = bin.slice(h.len);
- if (data.byteLength > 0 && h.dlen == data.byteLength) {
- switch (h.type) {
- case PKT_TYPE.NEW_PKT_TYPE_DEVICE_INFO:
- {
- h.device_info = new bin_to_device_info(data.slice(length));
- }
- break;
- case PKT_TYPE.NEW_PKT_TYPE_ELE_INFO:
- {
- var length = 0;
- switch(h.subtype)
- {
- case SUB_POWER_TYPE.NEW_SUB_PKT_TYPE_ELE_DATA_ALL:
- {
- h.power_all = new bin_to_power(data.slice(length));
- length += h.power_all.len;
- for(var i = 0; i < 3;i++)
- {
- temp[i] = new bin_to_power(data.slice(length));
- length += temp[i].len;
- }
- h.power_all_l = temp;
- }
- break;
- case SUB_POWER_TYPE.NEW_SUB_PKT_TYPE_ELE_DATA_INFO:
- {
- for(let i = 0;i < device_info.chs;i++)
- {
- temp[i] = new bin_to_power_info(data.slice(length));
- length += temp[i].len;
- }
- h.power_info = temp;
- }
- break;
- case SUB_POWER_TYPE.NEW_SUB_PKT_TYPE_ELE_DATA_L1:
- {
- for(var i = 0; i < device_info.chs;i++)
- {
- temp[i] = new bin_to_power(data.slice(length));
- length += temp[i].len;
- }
- h.power_data = temp;
- }
- break;
- case SUB_POWER_TYPE.NEW_SUB_PKT_TYPE_ELE_DATA_L2:
- {
- for(var i = 0; i < device_info.chs;i++)
- {
- temp[i] = new bin_to_power(data.slice(length));
- length += temp[i].len;
- }
- h.power_data1 = temp;
- }
- break;
- case SUB_POWER_TYPE.NEW_SUB_PKT_TYPE_ELE_DATA_L3:
- {
- for(var i = 0; i < device_info.chs;i++)
- {
- temp[i] = new bin_to_power(data.slice(length));
- length += temp[i].len;
- }
- h.power_data2 = temp;
- }
- break;
- case SUB_POWER_TYPE.NEW_SUB_PKT_TYPE_ELE_DATA_THR:
- {
- for(var i = 0; i < device_info.chs;i++)
- {
- temp[i] = new bin_to_power_th(data.slice(length));
- length += temp[i].len;
- }
- h.power_thr = temp;
- }
- break;
- default:
- break;
- }
- }
- break;
- case PKT_TYPE.NEW_PKT_TYPE_SENSOR:
- {
- var length = 0;
- for(let i =0;i < 4; i++)
- {
- temp[i] = new bin_to_sensor(data.slice(length));
- length += temp[i].len;
- }
- h.sensor_info = temp;
- }
- break;
- case PKT_TYPE.NEW_PKT_TYPE_NETWORK:
- {
- h.network = new bin_to_network(data.slice(length));
- }
- break;
- case PKT_TYPE.NEW_PKT_TYPE_RS485:
- {
- h.rs485 = new bin_to_rs485(data.slice(length));
- }
- break;
- case PKT_TYPE.NEW_PKT_TYPE_SNMP:
- {
- h.snmp = new bin_to_snmp(data.slice(length));
- }
- break;
- case PKT_TYPE.NEW_PKT_TYPE_WANNING:
- {
- var length = 0;
- h.wanni_count = new bin_to_wanning_count(data.slice(length));
- length += h.wanni_count.len;
- for(let i = 0; i < h.wanni_count.count;i++)
- {
- temp[i] = new bin_to_wanning(data.slice(length));
- length += temp[i].len;
- }
- h.wanning = temp;
- }
- break;
- case PKT_TYPE.NEW_PKT_TYPE_USER:
- {
- switch(h.subtype)
- {
- case SUB_USER_TYPE.NEW_SUB_PKT_TYPE_USER_INFO:
- {
- var length = 0;
- var tmp = [];
- h.user_count = new bin_to_user_cnt(data.slice(length));
- length += h.user_count.len;
- for(let i = 0; i < h.user_count.cnt;i++)
- {
- tmp[i] = new bin_to_users(data.slice(length));
- length += tmp[i].len;
- }
- h.users = tmp;
- }
- break;
- case SUB_USER_TYPE.NEW_SUB_PKT_TYPE_USER_ADD:
- {
- h.user_add = new bin_to_user(data.slice(length));
- }
- break;
- case SUB_USER_TYPE.NEW_SUB_PKT_TYPE_USER_DELETE:
- {
- h.user_delete = new bin_to_user(data.slice(length));
- }
- break;
- case SUB_USER_TYPE.NEW_SUB_PKT_TYPE_USER_UPDATE:
- {
- h.user_update = new bin_to_user(data.slice(length));
- }
- break;
- }
- }
- break;
- case PKT_TYPE.MEW_PKT_TYPE_LOGIN:
- {
- h.login = new bin_to_login(data.slice(length));
- }
- break;
- default:
- console.log("wrong hdr type: " + h.type);
- break;
- }
- }
- return h;
- };
- function openTempModal()
- {
- let vmax = tempValue.v_max;
- let vmin = tempValue.v_min;
- document.getElementById('tempMax').value=vmax.toFixed(2);
- document.getElementById('tempMin').value=vmin.toFixed(2);
- document.getElementById('tempCardModal').classList.add('active');
- }
-
- function openHumiModal()
- {
- let vmax = humiValue.v_max;
- let vmin = humiValue.v_min;
- document.getElementById('humiMax').value=vmax.toFixed(2);
- document.getElementById('humiMin').value=vmin.toFixed(2);
- document.getElementById('humiCardModal').classList.add('active');
- }
- function openSmokeModal()
- {
- let vmax = smokeValue.v_max;
- let vmin = smokeValue.v_min;
- document.getElementById('smokeMax').value=vmax.toFixed(2);
- document.getElementById('smokeMin').value=vmin.toFixed(2);
- document.getElementById('smokeCardModal').classList.add('active');
- }
- function openCo2Modal()
- {
- let vmax = co2Value.v_max;
- let vmin = co2Value.v_min;
- document.getElementById('Co2Max').value=vmax.toFixed(2);
- document.getElementById('Co2Min').value=vmin.toFixed(2);
- document.getElementById('co2CardModal').classList.add('active');
- }
- function openDelayModal() {
- const grid = document.getElementById('delayGrid');
- if (!grid) return;
- grid.innerHTML = '';
- for (let i = 0; i < device_info.chs; i++) {
- const delays = channelDelays[i];
- const rowDiv = document.createElement('div');
- rowDiv.className = 'config-row';
- rowDiv.innerHTML = '<div class="config-row-title">CH' + (i+1) + ' · ' + delays.name + '</div>' +
- '<div class="config-inputs">' +
- '<div class="config-item"><label>⏫ 开延时 (秒)</label><input type="number" step="0.1" min="0.3" max="10" id="onDelay_' + i + '" value="' + delays.onSec + '"></div>' +
- '<div class="config-item"><label>⏬ 关延时 (秒)</label><input type="number" step="0.1" min="0.3" max="10" id="offDelay_' + i + '" value="' + delays.offSec + '"></div>' +
- '<button class="save-channel-config-btn" data-channel="' + i + '">💾 保存本通道</button>' +
- '</div>';
- const saveBtn = rowDiv.querySelector('.save-channel-config-btn');
- saveBtn.addEventListener('click', (function(idx) {
- return function() {
- const onVal = parseFloat(document.getElementById('onDelay_' + idx).value);
- const offVal = parseFloat(document.getElementById('offDelay_' + idx).value);
- channel_set_delay(idx,onVal,offVal);
- showToast('通道 ' + (idx+1) + ' 延时已保存: 开' + onVal.toFixed(1) + 's / 关' + offVal.toFixed(1) + 's', 1200);
- };
- })(i));
- grid.appendChild(rowDiv);
- }
- document.getElementById('delayModal').classList.add('active');
- }
- function openThresholdModal() {
- const grid = document.getElementById('thresholdGrid');
- const patch_grid = document.getElementById('pathchGrid');
- if (!grid || !patch_grid) return;
- grid.innerHTML = '';
- patch_grid.innerHTML = '';
- if(device_info.chs > 0)
- {
- const rowDiv = document.createElement('div');
- rowDiv.className = 'config-batch-row';
- rowDiv.innerHTML = '<div class="config-row-title">批量设置'+'</div>' +
- '<div class="config-inputs">' +
- '<div class="config-batch-item"><label>🔻 电压最小值 (V)</label><input type="number" step="1" min="0" max="300" id="vMin_batch' + '" value="' + 0.00 + '"></div>' +
- '<div class="config-batch-item"><label>🔺 电压最大值 (V)</label><input type="number" step="1" min="0" max="300" id="vMax_batch' + '" value="' + 0.00 + '"></div>' +
- '<div class="config-batch-item"><label>⚡ 电流最大值 (A)</label><input type="number" step="5" min="0" max="200" id="iMax_batch' + '" value="' + 0.00 + '"></div>' +
- '<div class="config-batch-item"><label>🔋 功率最大值 (W)</label><input type="number" step="500" min="0" max="50000" id="pMax_batch' + '" value="' + 0.00 + '"></div>' +
- '<div class="config-batch-item"><label>📊 耗电量最大值 (kWh)</label><input type="number" step="50" min="0" max="10000" id="eMax_batch' + '" value="' + 0.00 + '"></div>' +
- '<button class="save-channel-config-btn" data-channel="'+ '">💾 保存</button>' +
- '</div>';
- const saveBtn = rowDiv.querySelector('.save-channel-config-btn');
- saveBtn.addEventListener('click',function() {
- const vMin = parseFloat(document.getElementById('vMin_batch').value);
- const vMax = parseFloat(document.getElementById('vMax_batch').value);
- const iMax = parseFloat(document.getElementById('iMax_batch').value);
- const pMax = parseFloat(document.getElementById('pMax_batch').value);
- const eMax = parseFloat(document.getElementById('eMax_batch').value);
- if (!isNaN(vMin) && !isNaN(vMax) && !isNaN(iMax) && !isNaN(pMax) && !isNaN(eMax)) {
- batch_set_thr(0,vMax,vMin,iMax,pMax,eMax);
- showToast('批量阈值' + '已配置', 1000);
- closeModal('thresholdModal');
- } else {
- showToast('请输入有效数值', 1000);
- }
- });
- patch_grid.appendChild(rowDiv);
- }
-
-
- for (let i = 0; i < device_info.chs; i++) {
- const thr = channelThresholds[i];
- const rowDiv = document.createElement('div');
- rowDiv.className = 'config-row';
- rowDiv.innerHTML = '<div class="config-row-title">CH' + (i+1) + ' · '+ (thr.name) + '</div>' +
- '<div class="config-inputs">' +
- '<div class="config-item"><label>🔻 电压最小值 (V)</label><input type="number" step="1" min="0" max="300" id="vMin_' + i + '" value="' + thr.vMin.toFixed(2) + '"></div>' +
- '<div class="config-item"><label>🔺 电压最大值 (V)</label><input type="number" step="1" min="0" max="300" id="vMax_' + i + '" value="' + thr.vMax.toFixed(2) + '"></div>' +
- '<div class="config-item"><label>⚡ 电流最大值 (A)</label><input type="number" step="5" min="0" max="200" id="iMax_' + i + '" value="' + thr.iMax.toFixed(2) + '"></div>' +
- '<div class="config-item"><label>🔋 功率最大值 (W)</label><input type="number" step="500" min="0" max="50000" id="pMax_' + i + '" value="' + thr.pMax.toFixed(2) + '"></div>' +
- '<div class="config-item"><label>📊 耗电量最大值 (kWh)</label><input type="number" step="50" min="0" max="10000" id="eMax_' + i + '" value="' + thr.eMax.toFixed(2) + '"></div>' +
- '<button class="save-channel-config-btn" data-channel="' + i + '">💾 保存本通道</button>' +
- '</div>';
- const saveBtn = rowDiv.querySelector('.save-channel-config-btn');
- saveBtn.addEventListener('click', (function(idx) {
- return function() {
- const vMin = parseFloat(document.getElementById('vMin_' + idx).value);
- const vMax = parseFloat(document.getElementById('vMax_' + idx).value);
- const iMax = parseFloat(document.getElementById('iMax_' + idx).value);
- const pMax = parseFloat(document.getElementById('pMax_' + idx).value);
- const eMax = parseFloat(document.getElementById('eMax_' + idx).value);
- if (!isNaN(vMin) && !isNaN(vMax) && !isNaN(iMax) && !isNaN(pMax) && !isNaN(eMax)) {
- channel_set_thr(idx,vMax,vMin,iMax,pMax,eMax)
- showToast('通道 ' + (idx+1) + ' 阈值已保存', 1000);
- } else {
- showToast('请输入有效数值', 1000);
- }
- };
- })(i));
- grid.appendChild(rowDiv);
- }
- document.getElementById('thresholdModal').classList.add('active');
- }
- function updateResetModalUI() {
- const container = document.getElementById('channelSelectList');
- if (!container) return;
- container.innerHTML = '';
- for (let i = 0; i < device_info.chs; i++) {
- const div = document.createElement('div');
- div.className = 'channel-checkbox';
- div.innerHTML = '<input type="checkbox" id="resetChk_' + i + '" ' + (currentSelectedChannels[i] ? 'checked' : '') + '>' +
- '<label for="resetChk_' + i + '">CH' + (i+1) + ' · '+(channelTelemetry[i].name) + ' (当前耗电: ' + ((channelTelemetry[i]?.energyKwh || 0).toFixed(2)) + ' kWh)</label>';
- const chk = div.querySelector('input');
- chk.addEventListener('change', (function(idx) {
- return function(e) { currentSelectedChannels[idx] = e.target.checked; };
- })(i));
- container.appendChild(div);
- }
- }
- function openResetEnergyModal() {
- for (let i = 0; i < device_info.chs; i++) currentSelectedChannels[i] = true;
- updateResetModalUI();
- document.getElementById('resetEnergyModal').classList.add('active');
- }
- function confirmResetEnergy() {
- const toReset = [];
- for (let i = 0; i < device_info.chs; i++) {
- if (currentSelectedChannels[i]) toReset.push(i);
- }
- if (toReset.length === 0) {
- showToast("未选择任何通道", 1000);
- return;
- }
- for (let idx of toReset) {
- channel_clear_consumer(idx);
- }
- //renderTable();
- const names = toReset.map(i => 'CH' + (i + 1)).join(', ');
- showToast('已重置 ' + names + ' 的耗电量', 1500);
- closeModal('resetEnergyModal');
- }
- function confirmTempThr() {
- valmax = document.getElementById('tempMax').value;
- valmin = document.getElementById('tempMin').value;
- set_sensor_thr(valmax,valmin,SUB_SENSOR_TYPE.NEW_SUB_PKT_TYPE_TEMP);
- showToast('设置温度阈值', 1500);
- closeModal('tempCardModal');
- }
- function confirmHumiThr() {
- valmax = document.getElementById('humiMax').value;
- valmin = document.getElementById('humiMin').value;
- set_sensor_thr(valmax,valmin,SUB_SENSOR_TYPE.NEW_SUB_PKT_TYPE_HUMI);
- showToast('设置湿度阈值', 1500);
- closeModal('humiCardModal');
- }
-
- function confirmSmokeThr() {
- valmax = document.getElementById('smokeMax').value;
- valmin = document.getElementById('smokeMin').value;
- set_sensor_thr(valmax,valmin,SUB_SENSOR_TYPE.NEW_SUB_PKT_TYPE_SMOKE);
- showToast('设置烟雾阈值', 1500);
- closeModal('smokeCardModal');
- }
- function confirmCo2Thr() {
- valmax = document.getElementById('Co2Max').value;
- valmin = document.getElementById('Co2Min').value;
- set_sensor_thr(valmax,valmin,SUB_SENSOR_TYPE.NEW_SUB_PKT_TYPE_CO2);
- showToast('设置Co2阈值', 1500);
- closeModal('co2CardModal');
- }
- function confirmNetwork()
- {
- ip_data=[];
- ip_data.ipMode = (document.getElementById('ipMode').value == "auto") ? 0 : 1;
- ip_data.ipAddress = document.getElementById('ipAddress').value;
- ip_data.subnetMask = document.getElementById('subnetMask').value;
- ip_data.gateway = document.getElementById('gateway').value;
- ip_data.dns1 = document.getElementById('dns1').value;
- ip_data.dns2 = document.getElementById('dns2').value;
- ip_data.len = 241;
- a = pkt_to_bin(0, PKT_TYPE.NEW_PKT_TYPE_NETWORK,0, 0, 0, ip_data);
- ws.send(a);
- }
- function confirmNtp()
- {
- ntp_data = [];
- ntp_data.ntpZone = document.getElementById('ntpZone').value;
- datetimeStr = document.getElementById('newSystemTime').value;
- ntp_data.len = 33;
- if (datetimeStr) {
- const newDate = new Date(datetimeStr);
- if (!isNaN(newDate.getTime()))
- {
- ntp_data.ntpDateTime = newDate.toLocaleString();
-
- a = pkt_to_bin(0, PKT_TYPE.NEW_PKT_TYPE_NTP,0, 0, 0, ntp_data);
- ws.send(a);
- showToast(newDate.toLocaleString(), 1000);
- }
- else
- showToast("无效的时间格式", 1000);
- } else showToast("请选择日期时间", 1000);
- }
- function rebootSystem()
- {
- data = [];
- data.flag = 1;
- data.len = 1;
- a = pkt_to_bin(0, PKT_TYPE.NEW_PKT_TYPE_DEVICE_INFO,0, 0, 0, data);
- ws.send(a);
- showToast("重启设备", 1000);
- }
- function selectAllChannels() {
- for (let i = 0; i < device_info.chs; i++) currentSelectedChannels[i] = true;
- updateResetModalUI();
- }
- function deselectAllChannels() {
- for (let i = 0; i < device_info.chs; i++) currentSelectedChannels[i] = false;
- updateResetModalUI();
- }
- function updateSummary() {
- let totalVoltage = 0.00, totalCurrent = 0.00, totalActivePower = 0.00, totalReactivePower = 0.00, totalApparentPower = 0.00, totalWeightedPf = 0.000,totalPf=0.00,totalConsumer= 0.00;
- if(device_info.chs > 0)
- {
- if(show_l_info == 0)
- {
- //总电压 (V)
- // document.getElementById('All-V').innerHTML = '<div class="summary-label" id="All-V">线电压 (V)</div>'
- // // document.getElementById('All-I').style.display = 'none';
- // // document.getElementById('totalCurrent').style.display ='none';
- // totalVoltage = all_channel.voltage;
- // totalCurrent = all_channel.current;
- // totalActivePower = all_channel.power;
- // totalReactivePower = all_channel.reactive_power;
- // totalApparentPower = all_channel.app_power;
- // totalPf = all_channel.factor;
- // totalConsumer = all_channel.consump;
- }else
- {
- document.getElementById('All-V').innerHTML = '<div class="summary-label" id="All-V">相电压 (V)</div>'
- totalVoltage = all_l_channel[show_l_info-1].voltage;
- totalCurrent = all_l_channel[show_l_info-1].current;
- totalActivePower = all_l_channel[show_l_info-1].power;
- totalReactivePower = all_l_channel[show_l_info-1].reactive_power;
- totalApparentPower = all_l_channel[show_l_info-1].app_power;
- totalPf = all_l_channel[show_l_info-1].factor;
- totalConsumer = all_l_channel[show_l_info-1].consump;
- }
- }
- document.getElementById('totalVoltage').innerHTML = totalVoltage.toFixed(2) + '<span class="summary-unit">V</span>';
- document.getElementById('totalCurrent').innerHTML = totalCurrent.toFixed(2) + '<span class="summary-unit">A</span>';
- document.getElementById('totalActivePower').innerHTML = totalActivePower.toLocaleString() + '<span class="summary-unit">kW</span>';
- document.getElementById('totalReactivePower').innerHTML = totalReactivePower.toLocaleString() + '<span class="summary-unit">kvar</span>';
- document.getElementById('totalApparentPower').innerHTML = totalApparentPower.toLocaleString() + '<span class="summary-unit">kVA</span>';
- document.getElementById('totalPowerFactor').innerHTML = totalPf.toFixed(3);
- document.getElementById('totalConsumer').innerHTML = totalConsumer.toFixed(2) + '<span class="summary-unit">kWh</span>';
- }
- function updateWsStatus(connected, message) {
- const led = document.getElementById('wsLed');
- const statusText = document.getElementById('wsStatusText');
- if (connected) {
- led.className = 'ws-led connected';
- statusText.innerHTML = '已连接';
- } else {
- led.className = 'ws-led disconnected';
- statusText.innerHTML = message || '未连接';
- }
- }
- function onWsMessage(event) {
- try {
- if (event.data instanceof ArrayBuffer) {
- var obj = bin_parse(event.data);
- if (obj.device_info != undefined) {
- if(device_info.chs != obj.device_info.chs)
- {
- device_info.chs = obj.device_info.chs;
- currentSelectedChannels = null;
- currentSelectedChannels = new Array(device_info.chs).fill(true);
- for (let i = 0; i < device_info.chs; i++) {
- channelThresholds[i] = {name:"smartPDU",vMin: 198, vMax: 242, iMax: 100, pMax: 15000, eMax: 500 };
- channelDelays[i] = {name:"smartPDU", onSec: 1.8, offSec: 1.5 };
- channelTelemetry[i] = {name:"smartPDU", voltage: 220, current: 30, activePower: 6600, reactivePower: 2500, apparentPower: 7000, powerFactor: 0.85, frequency: 50.00, energyKwh: 100 };
- channelTelemetry1[i] = {name:"smartPDU", voltage: 220, current: 30, activePower: 6600, reactivePower: 2500, apparentPower: 7000, powerFactor: 0.85, frequency: 50.00, energyKwh: 100 };
- channelTelemetry2[i] = {name:"smartPDU", voltage: 220, current: 30, activePower: 6600, reactivePower: 2500, apparentPower: 7000, powerFactor: 0.85, frequency: 50.00, energyKwh: 100 };
- channelSwitchStates[i] = true;
- channel_info[i] ={name:"SmartPDU",addr:0,sch:0,phse:0,phse1:1,open:1,close:1,status:1,
- l1_v_upper:0,l1_v_lower:0,l1_c_upper:0,l1_p_upper:0,l1_w_upper:0,
- l2_v_upper:0,l2_v_lower:0,l2_c_upper:0,l2_p_upper:0,l2_w_upper:0,
- l3_v_upper:0,l3_v_lower:0,l3_c_upper:0,l3_p_upper:0,l3_w_upper:0
- };
- }
- all_channel.voltage = 0;
- all_channel.current = 0;
- all_channel.power = 0;
- all_channel.reactive_power = 0;
- all_channel.app_power = 0;
- all_channel.factor = 0;
- renderTable();
-
- }
- device_info.chs = obj.device_info.chs;
- device_info.power_type = obj.device_info.power_type;
- device_info.zone = obj.device_info.zone;
- device_info.board_cnt = obj.device_info.board_cnt;
- device_info.soft_version = obj.device_info.soft_version;
- device_info.hard_version = obj.device_info.hard_version;
- device_info.date = obj.device_info.date;
- device_info.time = obj.device_info.time;
- updateDeviceStatusMsg();
- updateTimeDisplay();
- console.log('WebSocket收到: ', device_info.chs,device_info.date,device_info.time);
- }
- if (obj.power_data != undefined) {
- for (let i = 0; i < device_info.chs; i++) {
-
- channelTelemetry[i].voltage = obj.power_data[i].voltage;
- channelTelemetry[i].current = obj.power_data[i].current;
- channelTelemetry[i].activePower = obj.power_data[i].power;
- channelTelemetry[i].reactivePower = obj.power_data[i].reactive_power;
- channelTelemetry[i].apparentPower = obj.power_data[i].app_power;
- channelTelemetry[i].powerFactor = obj.power_data[i].factor;
- channelTelemetry[i].frequency = obj.power_data[i].freq;
- channelTelemetry[i].energyKwh = obj.power_data[i].consump;
- obj.power_data[i] = null;
- }
- //updateTableData();
- }
- if (obj.power_data1 != undefined) {
- for (let i = 0; i < device_info.chs; i++) {
-
- channelTelemetry1[i].voltage = obj.power_data1[i].voltage;
- channelTelemetry1[i].current = obj.power_data1[i].current;
- channelTelemetry1[i].activePower = obj.power_data1[i].power;
- channelTelemetry1[i].reactivePower = obj.power_data1[i].reactive_power;
- channelTelemetry1[i].apparentPower = obj.power_data1[i].app_power;
- channelTelemetry1[i].powerFactor = obj.power_data1[i].factor;
- channelTelemetry1[i].frequency = obj.power_data1[i].freq;
- channelTelemetry1[i].energyKwh = obj.power_data1[i].consump;
- obj.power_data1[i] = null;
- }
- //updateTableData();
- }
- if (obj.power_data2 != undefined) {
- for (let i = 0; i < device_info.chs; i++) {
-
- channelTelemetry2[i].voltage = obj.power_data2[i].voltage;
- channelTelemetry2[i].current = obj.power_data2[i].current;
- channelTelemetry2[i].activePower = obj.power_data2[i].power;
- channelTelemetry2[i].reactivePower = obj.power_data2[i].reactive_power;
- channelTelemetry2[i].apparentPower = obj.power_data2[i].app_power;
- channelTelemetry2[i].powerFactor = obj.power_data2[i].factor;
- channelTelemetry2[i].frequency = obj.power_data2[i].freq;
- channelTelemetry2[i].energyKwh = obj.power_data2[i].consump;
- obj.power_data2[i] = null;
- }
- //updateTableData();
- }
- if (obj.power_all != undefined) {
- all_channel = obj.power_all;
- obj.power_all = null;
- updateSummary();
- }
- if (obj.power_all_l != undefined) {
- all_l_channel = obj.power_all_l;
- obj.power_all_l = null;
- }
- if (obj.power_info != undefined) {
- channel_info = obj.power_info;
- for(let i =0;i < device_info.chs;i++)
- {
- channelDelays[i].onSec =channel_info[i].open;
- channelDelays[i].offSec = channel_info[i].close;
- channelDelays[i].name = channel_info[i].name;
- channelThresholds[i].name = channel_info[i].name;
- channelTelemetry[i].name = channel_info[i].name;
- }
- obj.power_info = null;
- updateTableData();
- }
- if (obj.power_thr != undefined) {
- for (let i = 0; i < device_info.chs; i++) {
- channelThresholds[i].vMax = obj.power_thr[i].v_upper;
- channelThresholds[i].vMin = obj.power_thr[i].v_lower;
- channelThresholds[i].iMax = obj.power_thr[i].c_upper;
- channelThresholds[i].pMax = obj.power_thr[i].p_upper;
- channelThresholds[i].eMax = obj.power_thr[i].w_upper;
- obj.power_thr[i] = null;
- }
- }
- if(obj.sensor_info != undefined)
- {
- humiValue = obj.sensor_info[0];
- tempValue = obj.sensor_info[1];
- smokeValue = obj.sensor_info[2];
- co2Value = obj.sensor_info[3];
- updateEnvDisplay();
- }
- if(obj.network != undefined)
- {
- netConfig.ipMode = (obj.network.mode == 0) ? "auto" : "manual";
- netConfig.ipAddress = obj.network.ipaddr;
- netConfig.subnetMask = obj.network.mask;
- netConfig.gateway = obj.network.gateway;
- netConfig.dns1 = obj.network.dns1;
- netConfig.dns2 = obj.network.dns2;
- loadNetConfig();
- }
- if(obj.rs485 != undefined)
- {
- rs485Config.mode = obj.rs485.mode == 0? "master" : "slave";
- rs485Config.address = obj.rs485.addr;
- rs485Config.baudrate = obj.rs485.baud;
- loadRs485Config();
- }
- if(obj.snmp != undefined)
- {
- snmpConfig.status = (obj.snmp.mode == 0)? "close" :"open";
- snmpConfig.readCommunity = obj.snmp.publics;
- snmpConfig.writeCommunity = obj.snmp.privates;
- snmpConfig.trapStatus = (obj.snmp.trapmode == 0)? "close" :"open";;
- snmpConfig.trapIp =obj.snmp.nms_ip;
- loadSnmpConfig();
- }
- if(obj.wanni_count != undefined)
- {
- //clearAlarm();
- alarmList = [];
- for(let i = 0; i < obj.wanni_count.count;i++)
- {
- addAlarm(obj.wanning[i],i);
- }
- updateAlarmBadge();
- updateAlarmUI();
- }
- if(obj.user_count != undefined )
- {
- user_count = obj.user_count;
- users = obj.users;
- renderUserTable();
- }
- if(obj.user_add != undefined )
- {
- const errorDiv = document.getElementById('loginAddErrorMsg');
- if(obj.user_add.flag == 1)
- {
-
- errorDiv.innerText = '用户已存在';
- }else if(obj.user_add.flag == 2)
- {
- errorDiv.innerText = '用户超过10';
- }else
- {
- errorDiv.innerTex='';
- closeModal('userAddModal');
- ws.send(mk_hdr_bin(0, PKT_TYPE.NEW_PKT_TYPE_USER,0, 0, 0));
- }
-
- }
- if(obj.user_update != undefined)
- {
- const errorDiv = document.getElementById('loginUpdateErrorMsg');
- if(obj.user_update.flag == 1)
- {
- errorDiv.innerText = '密码错误';
- }else
- {
- errorDiv.innerTex='';
- closeModal('userModal');
- ws.send(mk_hdr_bin(0, PKT_TYPE.NEW_PKT_TYPE_USER,0, 0, 0));
- }
-
- }
- if(obj.user_delete != undefined)
- {
- ws.send(mk_hdr_bin(0, PKT_TYPE.NEW_PKT_TYPE_USER,0, 0, 0));
- }
- }
- } catch (e) {
- console.error('解析WebSocket消息失败:', e);
- }
- }
- function sendSwitchCommand(channel, state) {
- if (ws && ws.readyState === WebSocket.OPEN) {
- showToast("发送指令: 通道" + (channel + 1) + " " + (state ? "开启" : "关闭"), 1000);
- } else {
- showToast("WebSocket未连接,无法发送指令", 1500);
- }
- }
- function sendAllSwitchCommand(state) {
- if (ws && ws.readyState === WebSocket.OPEN) {
- all_contrl(state);
- showToast("发送全部" + (state ? "开启" : "关闭") + "指令", 1000);
- } else {
- showToast("WebSocket未连接,无法发送指令", 1500);
- }
- }
- function deleteUserApi(userId) {
- let user = users[userId].user;
- userDeleteConfig(user);
- }
- function escapeHtml(str) { return str.replace(/[&<>]/g, function(m){ if(m==='&') return '&'; if(m==='<') return '<'; if(m==='>') return '>'; return m;}); }
- function openUserEditModal(userId) {
- // let user = usersList.find(u => u.id === userId);
- // if (!user) return;
- let i = userId;
- document.getElementById('userModalTitle').innerText = '编辑用户';
- document.getElementById('userName').value = users[userId].user;
- document.getElementById('userName').setAttribute('disabled','disabled');
- document.getElementById('userOldPassword').value = '';
- document.getElementById('userNewPassword').value = '';
- document.getElementById('userRole').value = (users[userId].role === 1 )? "superadmin" : (users[userId].role === 2 ) ? "admin" : "user";
- document.getElementById('userModal').classList.add('active');
- }
- function renderUserTable() {
- let tbody = document.getElementById('userTableBody');
- if (!tbody) return;
- if (!user_count.cnt) { tbody.innerHTML = '<tr><td colspan="3" style="text-align:center;">暂无用户数据</td></tr>'; return; }
- let html = '';
- for (let i = 0;i < user_count.cnt;i++) {
- let roleText = (users[i].role === 1) ? '超级管理员' : (users[i].role === 2 ? '管理员' : '普通用户');
- html += `<tr>
- <td style="text-align:center;">${escapeHtml(users[i].user)}</td>
- <td style="text-align:center;">${roleText}</td>
- <td style="text-align:center;">${users[i].date} ${users[i].time}</td>
- <td style="text-align:center;"><button class="btn-icon success" data-id="${i}" data-action="edit">编辑</button>
- <button class="btn-icon danger" data-id="${i}" data-action="delete">删除</button></td>
- </tr>`;
- }
- tbody.innerHTML = html;
- // 绑定编辑删除事件
- tbody.querySelectorAll('[data-action="edit"]').forEach(btn => {
- btn.addEventListener('click', (e) => { let id = parseInt(btn.getAttribute('data-id')); openUserEditModal(id); });
- });
- tbody.querySelectorAll('[data-action="delete"]').forEach(btn => {
- btn.addEventListener('click', (e) => { let id = parseInt(btn.getAttribute('data-id')); if(confirm('确定删除该用户吗?')) deleteUserApi(id); });
- });
- }
- function updateEnvDisplay() {
- document.getElementById('tempStatus').innerHTML= `<div class="${tempValue.status ? 'status-on' : 'status-off'}">${tempValue.status ? "在线" : "离线"}<div>`;
- document.getElementById('humiStatus').innerHTML= `<div class="${humiValue.status ? 'status-on' : 'status-off'}">${humiValue.status ? "在线" : "离线"}<div>`;
- document.getElementById('smokeStatus').innerHTML= `<div class="${smokeValue.status ? 'status-on' : 'status-off'}">${smokeValue.status ? "在线" : "离线"}<div>`
- document.getElementById('co2Status').innerHTML= `<div class="${co2Value.status ? 'status-on' : 'status-off'}">${co2Value.status ? "在线" : "离线"}<div>`
- document.getElementById('tempValue').innerHTML = tempValue.value.toFixed(2) + '<span class="env-unit">°C</span>';
- document.getElementById('humiValue').innerHTML = humiValue.value.toFixed(2) + '<span class="env-unit">%RH</span>';
- document.getElementById('smokeValue').innerHTML = Math.floor(smokeValue.value) + '<span class="env-unit">ppm</span>';
- document.getElementById('co2Value').innerHTML = Math.floor(co2Value.value) + '<span class="env-unit">ppm</span>';
- const tempCard = document.getElementById('tempCard');
- const humiCard = document.getElementById('humiCard');
- const smokeCard = document.getElementById('smokeCard');
- const co2Card = document.getElementById('co2Card');
- tempCard.classList.remove('alarm-warning', 'alarm-danger');
- humiCard.classList.remove('alarm-warning', 'alarm-danger');
- smokeCard.classList.remove('alarm-warning', 'alarm-danger');
- co2Card.classList.remove('alarm-warning', 'alarm-danger');
- if (tempValue.v_max_wrn) tempCard.classList.add('alarm-danger');
- else if(tempValue.v_min_wrn) tempCard.classList.add('alarm-warning');
- if (humiValue.v_max_wrn) humiCard.classList.add('alarm-danger');
- if (smokeValue.v_max_wrn) smokeCard.classList.add('alarm-danger');
- if (co2Value.v_max_wrn) co2Card.classList.add('alarm-danger');
- }
- function updateAlarmBadge() {
- const badge = document.getElementById('alarmCountBadge');
- if (badge) {
- const count = alarmList.length;
- if (count > 0) {
- badge.textContent = count > 10 ? '10' : count;
- badge.style.display = 'inline-flex';
- } else {
- badge.style.display = 'none';
- }
- }
- }
- function updateAlarmUI() {
- const container = document.getElementById('alarmListContainer');
- if (!container) return;
- if (alarmList.length === 0) {
- container.innerHTML = '<div style="text-align:center;color:#888;padding:20px;">暂无报警记录</div>';
- return;
- }
- let html = '<table class="alarm-table"><thead><tr><th>报警ID</th><th>时间</th><th>报警类型</th><th>详细信息</th></tr></thead><tbody>';
- for (let i = 0; i < alarmList.length; i++) {
- const a = alarmList[i];
- html += '<tr><td class="alarm-id">' + a.id + '</td><td>' + a.time + '</td><td><span style="background:#ffe0e0;padding:2px 8px;border-radius:20px;font-size:0.7rem;">' + a.type + '</span></td><td>' + a.message + '</td></tr>';
- }
- html += '</tbody></table>';
- container.innerHTML = html;
- }
- function clearAlarm() {
- clean_alarm();
- alarmList = [];
- showToast("报警记录已清空", 1000);
- }
- function showToast(msg, dur) {
- if (!dur) dur = 1500;
- const t = document.createElement('div');
- t.innerText = msg;
- t.style.cssText = 'position:fixed; bottom:70px; right:24px; background:#1e2f3ce6; color:#fff; padding:8px 20px; border-radius:40px; font-size:0.8rem; z-index:2100;';
- document.body.appendChild(t);
- setTimeout(function() {
- t.style.opacity = '0';
- setTimeout(function() {
- t.remove();
- }, 300);
- }, dur);
- }
-
- function updateTableData() {
- for (let i = 0; i < device_info.chs; i++) {
- //if (!tableRows[i]) continue;
- const row = tableRows[i];
- if (!row) continue;
- let tele= channelTelemetry[i]|| {};
- let target = channelSwitchStates[i];
- let delays = channelDelays[i];
- let thr = channelThresholds[i];
- let info = channel_info[i];
- if(device_info.power_type == 4 || device_info.power_type == 5)
- {
- if(info.phse == 1)
- {
- //tele = channelTelemetry[i];
- }else if(info.phse == 2)
- {
- tele = channelTelemetry1[i];
- }else if(info.phse == 3)
- {
- tele = channelTelemetry2[i];
- }
- }
-
- // 检查阈值告警
- const alarms = [];
- alarmClass = '';
- const cells = row.cells;
- if (cells[0]) {
- cells[0].innerHTML = '<div class="channel-badge"><span class="ch-icon">CH' + (i + 1) + '</span> <strong>' + (info.name) + '</strong></div>';
- //cells[0].className = 'channel-badge ';
- }
- if(cells[1])
- {
- cells[1].innerHTML = '<span class="ph-icon"><strong>'+'L'+info.phse+'</strong></span>'
- }
- if (cells[2]) {
- cells[2].innerHTML = (tele.voltage || 0).toFixed(2) + '<span class="unit-sub">V</span>' + (info.l1_v_lower || info.l2_v_lower || info.l3_v_lower ? '🔻' : (info.l1_v_upper || info.l2_v_upper || info.l3_v_upper ? '🔺' : ''));
- if(info.l1_v_lower || info.l2_v_lower || info.l3_v_lower) {
- alarmClass = 'threshold-low-alarm';
- }else if(info.l1_v_upper || info.l2_v_upper || info.l3_v_upper) {
- alarmClass = 'threshold-alarm';
- }
- cells[2].className = 'numeric-value ' + alarmClass;
- }
- // 电流 (第3列,索引2)
- if (cells[3]) {
- cells[3].innerHTML = (tele.current || 0).toFixed(2) + '<span class="unit-sub">A</span>';
- cells[3].className = 'numeric-value ' + ((info.l1_c_upper ||info.l2_c_upper || info.l3_c_upper) ? 'threshold-alarm' : '');
- }
- // 有功功率 (第4列,索引3)
- if (cells[4]) {
- cells[4].innerHTML = ((tele.activePower || 0).toLocaleString()) + '<span class="unit-sub">kW</span>';
- cells[4].className = 'numeric-value power-bg ' + (info.l1_p_upper || info.l2_p_upper || info.l3_p_upper? 'threshold-alarm' : '');
- }
- // 无功功率 (第5列,索引4)
- if (cells[5]) {
- cells[5].innerHTML = ((tele.reactivePower || 0).toLocaleString()) + '<span class="unit-sub">kvar</span>';
- cells[5].className = 'numeric-value reactive-bg';
- }
- // 视在功率 (第6列,索引5)
- if (cells[6]) {
- cells[6].innerHTML = ((tele.apparentPower || 0).toLocaleString()) + '<span class="unit-sub">kVA</span>';
- }
- // 功率因数 (第7列,索引6)
- if (cells[7]) {
- cells[7].innerHTML = (tele.powerFactor || 0).toFixed(3);
- }
- // 频率 (第8列,索引7)
- if (cells[8]) {
- cells[8].innerHTML = tele.frequency.toFixed(2) + '<span class="unit-sub">Hz</span>';
- }
- // 耗电量 (第9列,索引8)
- if (cells[9]) {
- cells[9].innerHTML = '<span class="energy-value">' + ((tele.energyKwh || 0).toFixed(2)) + '</span><span class="unit-sub">kWh</span>';
- cells[9].className = 'energy-cell numeric-value ' + (info.l1_w_upper || info.l2_w_upper || info.l3_w_upper ? 'threshold-alarm' : '');
- }
- // 开关延时 (第10列,索引9)
- if (cells[10]) {
- cells[10].innerHTML = '<div class="delay-badge delay-idle">开:' + (info.open) + 's/关:' + (info.close) + 's</div>';
- }
- // 开关状态 (第11列,索引10)
- if (cells[11]) {
- cells[11].innerHTML = '<span class="' + (info.status ? 'status-on' : 'status-off') + ' status-span">' + (info.status ? '开' : '关') + '</span>';
- }
- // 操作按钮 (第12列,索引11)
- if (cells[12]) {
- if (channelSwitchStates[i] != channel_info[i].status) {
- cells[12].innerHTML = '<div class="switch-control"><button class="switch-btn ' + (info.status ? 'switch-on' : 'switch-off') + '" data-idx="' + i + '">' + (info.status ? '关闭' : '打开') + '</button></div>';
- channelSwitchStates[i] = channel_info[i].status
- }
- }
- // 行样式
- if (target) {
- row.classList.remove('channel-off');
- row.classList.add('channel-on');
- } else {
- row.classList.remove('channel-on');
- row.classList.add('channel-off');
- }
- }
- }
- function renderTable() {
- const tbody = document.getElementById('tableBody');
- if (!tbody) return;
- tbody.innerHTML = '';
- tableRows = [];
- for (let i = 0; i < device_info.chs; i++) {
- const tele = channelTelemetry[i] || {};
- const target = channelSwitchStates[i];
- const delays = channelDelays[i];
- const thr = channelThresholds[i];
- const info = channel_info[i];
- const alarms = [];
- if (channel_info.l1_v_lower) alarms.push('欠压');
- if (channel_info.l1_v_upper) alarms.push('过压');
- if (channel_info.l1_c_upper) alarms.push('过流');
- if (channel_info.l1_p_upper) alarms.push('过功率');
- if (channel_info.l1_w_upper) alarms.push('能耗超限');
- const alarmClass = alarms.length > 0 ? 'threshold-alarm' : '';
- const row = document.createElement('tr');
- if (!info.status) row.classList.add('channel-off');
- channelSwitchStates[i] = channel_info[i].status;
- row.innerHTML = `
- <td><div class="channel-badge"><span class="ch-icon">CH${i+1}</span> <strong>${info.name} ${i+1}</strong></div></td>
- <td><span class="ph-icon"><strong>L${info.phse}</strong></span></td>
- <td class="numeric-value ${alarmClass}">${(tele.voltage || 0).toFixed(1)}<span class="unit-sub">V</span>${alarms.includes('欠压') ? '🔻' : (alarms.includes('过压') ? '🔺' : '')}</td>
- <td class="numeric-value ${alarms.includes('过流') ? 'threshold-alarm' : ''}">${(tele.current || 0).toFixed(2)}<span class="unit-sub">A</span></td>
- <td class="numeric-value power-bg ${alarms.includes('过功率') ? 'threshold-alarm' : ''}">${(tele.activePower || 0).toLocaleString()}<span class="unit-sub">W</span></td>
- <td class="numeric-value reactive-bg">${(tele.reactivePower || 0).toLocaleString()}<span class="unit-sub">kvar</span></td>
- <td class="numeric-value">${(tele.apparentPower || 0).toLocaleString()}<span class="unit-sub">kVA</span></td>
- <td class="pf-cell numeric-value">${(tele.powerFactor || 0).toFixed(3)}</td>
- <td class="numeric-value">${(tele.frequency || 50).toFixed(2)}<span class="unit-sub">Hz</span></td>
- <td class="energy-cell numeric-value ${alarms.includes('能耗超限') ? 'threshold-alarm' : ''}"><span class="energy-value">${(tele.energyKwh || 0).toFixed(2)}</span><span class="unit-sub">kWh</span></td>
- <td><div class="delay-badge delay-idle">开:${info.close.toFixed(1)}s/关:${info.open.toFixed(1)}s</div></td>
- <td><span class="${target ? 'status-on' : 'status-off'}">${info.status ? '开' : '关'}</span></td>
- <td><div class="switch-control"><button class="switch-btn ${info.status ? 'switch-on' : 'switch-off'}" data-idx="${i}">${info.status ? '关闭' : '打开'}</button></div></td>
- `;
- tbody.appendChild(row);
- tableRows.push(row)
- }
- tbody.removeEventListener('click', handleSwitchClick);
- tbody.addEventListener('click', handleSwitchClick);
- }
- function handleSwitchClick(e) {
- const btn = e.target.closest('.switch-btn');
- if (!btn) return;
- e.stopPropagation();
- const idx = parseInt(btn.getAttribute('data-idx'));
- if (!isNaN(idx) && idx >= 0 && idx < device_info.chs) {
- sendSwitchCommand(idx, !channelSwitchStates[idx]);
- }
- }
- function sendSwitchCommand(channel, state) {
- if (ws && ws.readyState === WebSocket.OPEN) {
- single_ctrl(channel,state);
- showToast("通道" + (channel + 1) + " " + (state ? "开启" : "关闭"), 1000);
- } else {
- showToast("WebSocket未连接,无法发送指令", 1500);
- }
- }
- function allOn() { sendAllSwitchCommand(true);}
- function allOff() { sendAllSwitchCommand(false);}
- function openAlarmModal() {
- updateAlarmUI();
- document.getElementById('alarmModal').classList.add('active');
- }
- function closeModal(modalId) {document.getElementById(modalId).classList.remove('active');}
- function loadNetConfig() {
- document.getElementById("ipMode").value = netConfig.ipMode;
- document.getElementById("ipAddress").value = netConfig.ipAddress;
- document.getElementById("subnetMask").value = netConfig.subnetMask;
- document.getElementById("gateway").value = netConfig.gateway;
- document.getElementById("dns1").value = netConfig.dns1;
- document.getElementById("dns2").value = netConfig.dns2;
- updateStaticIpFieldsEnable();
- updateNetStatusMsg();
- }
- function loadNtpConfig()
- {
- document.getElementById("ntpZone").value = ntpConfig.ntpZone;
- }
- function updateStaticIpFieldsEnable() {
- const isManual = document.getElementById("ipMode").value === "manual";
- console.log(document.getElementById("ipMode").value);
- ["ipAddress", "subnetMask", "gateway"].forEach(function(id) {
- const el = document.getElementById(id);
- if (el){
- //el.hidden = !isManual;
- isManual ? el.removeAttribute('disabled') : el.setAttribute('disabled','disabled');
- // if(isManual)
- // {
- // el.removeAttribute('disabled');
- // }else
- // {
- // el.setAttribute('disabled','disabled');
- // }
- }
- });
- // ["ip_lable","mask_lable","gate_lable"].forEach(function(id) {
- // const el = document.getElementById(id);
- // if (el){
- // el.style.display = (!isManual) ? 'none' : 'inline';
- // }
- // });
- }
- function saveNetConfig() {
- confirmNetwork();
- showToast("网络配置已保存", 1200);
- }
- function updateNetStatusMsg() {
- const msgDiv = document.getElementById("netStatusMsg");
- if (msgDiv) {
- const modeText = netConfig.ipMode === "auto" ? "自动(DHCP)" : "静态IP: " + netConfig.ipAddress;
- msgDiv.innerHTML = "📡 IP模式: " + modeText + "<br>🌐 DNS: " + netConfig.dns1 + " / " + netConfig.dns2;
- }
- }
- function loadRs485Config() {
- const saved = sessionStorage.getItem("powerMonitorRs485Config");
- document.getElementById("rs485Mode").value = rs485Config.mode;
- document.getElementById("rs485Addr").value = rs485Config.address;
- document.getElementById("rs485Baudrate").value = rs485Config.baudrate;
- updateRs485StatusMsg();
- }
- function saveRs485Config() {
- rs_data = [];
- rs_data.rs485Mode = (document.getElementById('rs485Mode').value == "master") ? 0 : 1;
- rs_data.rs485Addr = document.getElementById('rs485Addr').value || 1;
- rs_data.rs485Baudrate = document.getElementById('rs485Baudrate').value;
- rs_data.len = 6;
- if (rs_data.rs485Addr < 1) rs_data.rs485Addr = 1;
- if (rs_data.rs485Addr > 247) rs_data.rs485Addr = 247;
- a = pkt_to_bin(0, PKT_TYPE.NEW_PKT_TYPE_RS485,0, 0, 0, rs_data);
- ws.send(a);
- showToast("RS485配置已保存", 1200);
- }
- function updateRs485StatusMsg() {
- const msgDiv = document.getElementById("rs485StatusMsg");
- if (msgDiv) {
- const modeText = rs485Config.mode === "master" ? "主机模式" : "从机模式";
- msgDiv.innerHTML = "🔧 模式: " + modeText + " | 地址: " + rs485Config.address + " | 波特率: " + rs485Config.baudrate + " bps";
- }
- }
- function loadSnmpConfig() {
- document.getElementById("snmpReadCommunity").value = snmpConfig.readCommunity;
- document.getElementById("snmpWriteCommunity").value = snmpConfig.writeCommunity;
- document.getElementById("snmpTrapIp").value = snmpConfig.trapIp;
- document.getElementById("snmpTrapStatus").value = snmpConfig.trapStatus;
- updateSnmpEnable();
- updateSnmpStatusMsg();
- }
-
- function updateSnmpEnable()
- {
- const isManual = document.getElementById("snmpTrapStatus").value === "open";
- const el = document.getElementById("snmpTrapIp");
- if(el) el.hidden = !isManual;
- document.getElementById("trapAddr").style.display = !isManual ? 'none' :'inline';
- }
- function saveSnmpConfig() {
- snmp_data = [];
- snmp_data.mode = 1;
- snmp_data.version = 0;
- snmp_data.snmpReadCommunity = document.getElementById("snmpReadCommunity").value;
- snmp_data.snmpWriteCommunity = document.getElementById("snmpWriteCommunity").value;
- snmp_data.snmpTrapIp = document.getElementById("snmpTrapIp").value;
- snmp_data.snmpTrapStatus = document.getElementById("snmpTrapStatus").value == "open" ? 1 : 0;
- snmp_data.len = 55;
- a = pkt_to_bin(0, PKT_TYPE.NEW_PKT_TYPE_SNMP,0, 0, 0, snmp_data);
- ws.send(a);
- showToast("SNMP配置已保存", 1200);
- }
- function userAddConfig(user,password,role)
- {
- user_data = [];
- user_data.role = role;
- user_data.user = user;
- user_data.password = password;
- user_data.len = 65;
- a = pkt_to_bin(0, PKT_TYPE.NEW_PKT_TYPE_USER,SUB_USER_TYPE.NEW_SUB_PKT_TYPE_USER_ADD, 0, 0, user_data);
- ws.send(a);
- showToast("增加用户",user, 1200);
- }
- function userDeleteConfig(user)
- {
- user_data=[];
- user_data.user = user;
- user_data.len = 32;
- a = pkt_to_bin(0, PKT_TYPE.NEW_PKT_TYPE_USER,SUB_USER_TYPE.NEW_SUB_PKT_TYPE_USER_DELETE, 0, 0, user_data);
- ws.send(a);
- showToast("删除用户",user, 1200);
- }
- function userUpdateConfig(user,old_pass,new_pass,role)
- {
- user_data = [];
- user_data.role = role
- user_data.user = user;
- user_data.old_password = old_pass;
- user_data.new_password = new_pass;
- user_data.len = 97;
- a = pkt_to_bin(0, PKT_TYPE.NEW_PKT_TYPE_USER,SUB_USER_TYPE.NEW_SUB_PKT_TYPE_USER_UPDATE, 0, 0, user_data);
- ws.send(a);
- showToast("修改用户",user, 1200);
- }
- function updateSnmpStatusMsg() {
- const msgDiv = document.getElementById("snmpStatusMsg");
- if (msgDiv) {
- const trapInfo = snmpConfig.trapIp ? (snmpConfig.trapIp) : "未配置";
- msgDiv.innerHTML = "🔐 只读社团: " + snmpConfig.readCommunity + " | ✏️ 读写社团: " + snmpConfig.writeCommunity + "<br>📡 TRAP目标: " + trapInfo;
- }
- }
- function updateDeviceStatusMsg()
- {
- document.getElementById('deviceChannel').textContent = device_info.chs;
- document.getElementById("powerType").textContent = (device_info.power_type == 0)? 'AC-AC' : (device_info.power_type == 1)
- ? 'DC-DC' : (device_info.power_type == 3)
- ? 'AC3-AC3': (device_info.power_type == 4 || device_info.power_type == 5)
- ? 'AC3-AC1': (device_info.power_type == 6)
- ? 'AC3-AC2':'Other';
- document.getElementById("controlBoard").textContent = device_info.board_cnt;
- document.getElementById("softVersion").textContent = device_info.soft_version;
- document.getElementById("zone").textContent = device_info.zone;
- }
- function updateTimeDisplay() {
- const display = document.getElementById("systemTimeDisplay");
- if (display) {
- display.innerHTML = device_info.date + ' ' + device_info.time;
- }
- }
- function startTimeUpdater() {
- clearInterval(device_info_id);
- power_all_id = setInterval(function() { ws.send(mk_hdr_bin(0, PKT_TYPE.NEW_PKT_TYPE_ELE_INFO, SUB_POWER_TYPE.NEW_SUB_PKT_TYPE_ELE_DATA_ALL, 0, 0));}, 600);
- power_data_id = setInterval(function() {
- ws.send(mk_hdr_bin(0, PKT_TYPE.NEW_PKT_TYPE_ELE_INFO, SUB_POWER_TYPE.NEW_SUB_PKT_TYPE_ELE_DATA_L1, 0, 0));
- setTimeout(() => {ws.send(mk_hdr_bin(0, PKT_TYPE.NEW_PKT_TYPE_ELE_INFO, SUB_POWER_TYPE.NEW_SUB_PKT_TYPE_ELE_DATA_L2, 0, 0));},40);
- setTimeout(() => {ws.send(mk_hdr_bin(0, PKT_TYPE.NEW_PKT_TYPE_ELE_INFO, SUB_POWER_TYPE.NEW_SUB_PKT_TYPE_ELE_DATA_L3, 0, 0));},40);
- setTimeout(() => {ws.send(mk_hdr_bin(0, PKT_TYPE.NEW_PKT_TYPE_ELE_INFO, SUB_POWER_TYPE.NEW_SUB_PKT_TYPE_ELE_DATA_INFO, 0, 0));},40);
- }, 300);
- power_thr_id = setInterval(function() { ws.send(mk_hdr_bin(0, PKT_TYPE.NEW_PKT_TYPE_ELE_INFO, SUB_POWER_TYPE.NEW_SUB_PKT_TYPE_ELE_DATA_THR, 0, 0));}, 500);
- sensor_id = setInterval(function() { ws.send(mk_hdr_bin(0, PKT_TYPE.NEW_PKT_TYPE_SENSOR,0, 0, 0));}, 1000);
- wanning_id = setInterval(function() { ws.send(mk_hdr_bin(0, PKT_TYPE.NEW_PKT_TYPE_WANNING,0, 0, 0));}, 3000);
- }
- function setSystemTime(newDate) {
- systemTime = newDate;
- updateTimeDisplay();
- showToast("系统时间已更新为: " + systemTime.toLocaleString(), 1500);
- }
- function switchPage(pageId) {
- document.querySelectorAll('.page').forEach(function(p){ p.classList.remove('active-page'); });
- document.getElementById(pageId + 'Page').classList.add('active-page');
- document.querySelectorAll('.tab-btn').forEach(function(btn){ btn.classList.remove('active'); });
- document.querySelector('.tab-btn[data-page="' + pageId + '"]').classList.add('active');
- if(pageId == 'network')
- {
- clearInterval(power_all_id);
- clearInterval(power_thr_id);
- clearInterval(power_data_id);
- clearInterval(device_info_id);
- clearInterval(sensor_id);
- clearInterval(wanning_id);
- ws.send(mk_hdr_bin(0, PKT_TYPE.NEW_PKT_TYPE_NETWORK,0, 0, 0));
- }else if(pageId == 'rs485')
- {
- clearInterval(power_all_id);
- clearInterval(power_thr_id);
- clearInterval(power_data_id);
- clearInterval(device_info_id);
- clearInterval(sensor_id);
- clearInterval(wanning_id);
- ws.send(mk_hdr_bin(0, PKT_TYPE.NEW_PKT_TYPE_RS485,0, 0, 0));
- }else if(pageId == 'user')
- {
- clearInterval(power_all_id);
- clearInterval(power_thr_id);
- clearInterval(power_data_id);
- clearInterval(device_info_id);
- clearInterval(sensor_id);
- clearInterval(wanning_id);
- ws.send(mk_hdr_bin(0, PKT_TYPE.NEW_PKT_TYPE_USER,0, 0, 0));
- }
- else if(pageId =='monitor')
- {
- clearInterval(device_info_id);
- power_all_id = setInterval(function() { ws.send(mk_hdr_bin(0, PKT_TYPE.NEW_PKT_TYPE_ELE_INFO, SUB_POWER_TYPE.NEW_SUB_PKT_TYPE_ELE_DATA_ALL, 0, 0));}, 600);
- power_data_id = setInterval(function() {
- ws.send(mk_hdr_bin(0, PKT_TYPE.NEW_PKT_TYPE_ELE_INFO, SUB_POWER_TYPE.NEW_SUB_PKT_TYPE_ELE_DATA_L1, 0, 0));
- setTimeout(() => {ws.send(mk_hdr_bin(0, PKT_TYPE.NEW_PKT_TYPE_ELE_INFO, SUB_POWER_TYPE.NEW_SUB_PKT_TYPE_ELE_DATA_L2, 0, 0));},40);
- setTimeout(() => {ws.send(mk_hdr_bin(0, PKT_TYPE.NEW_PKT_TYPE_ELE_INFO, SUB_POWER_TYPE.NEW_SUB_PKT_TYPE_ELE_DATA_L3, 0, 0));},40);
- setTimeout(() => {ws.send(mk_hdr_bin(0, PKT_TYPE.NEW_PKT_TYPE_ELE_INFO, SUB_POWER_TYPE.NEW_SUB_PKT_TYPE_ELE_DATA_INFO, 0, 0));},40);
- }, 300);
- power_thr_id = setInterval(function() { ws.send(mk_hdr_bin(0, PKT_TYPE.NEW_PKT_TYPE_ELE_INFO, SUB_POWER_TYPE.NEW_SUB_PKT_TYPE_ELE_DATA_THR, 0, 0));}, 500);
- sensor_id = setInterval(function() { ws.send(mk_hdr_bin(0, PKT_TYPE.NEW_PKT_TYPE_SENSOR,0, 0, 0));}, 1000);
- wanning_id = setInterval(function() { ws.send(mk_hdr_bin(0, PKT_TYPE.NEW_PKT_TYPE_WANNING,0, 0, 0));}, 3000);
- }else if(pageId =='snmp')
- {
- clearInterval(power_all_id);
- clearInterval(power_thr_id);
- clearInterval(power_data_id);
- clearInterval(device_info_id);
- clearInterval(sensor_id);
- clearInterval(wanning_id);
- ws.send(mk_hdr_bin(0, PKT_TYPE.NEW_PKT_TYPE_SNMP, 0, 0, 0));
- }
- else if(pageId == 'device')
- {
- clearInterval(power_all_id);
- clearInterval(power_thr_id);
- clearInterval(power_data_id);
- clearInterval(sensor_id);
- clearInterval(wanning_id);
- ntpConfig.ntpZone = device_info.zone;
- loadNtpConfig();
- device_info_id = setInterval(function() { ws.send(mk_hdr_bin(0, PKT_TYPE.NEW_PKT_TYPE_DEVICE_INFO,0, 0, 0));}, 1000);
- }
- }
- function connectWebSocket() {
- const wsUrl = 'ws://' + window.location.host + '/ws';
- //const wsUrl = 'ws://' + '192.168.9.110' + '/ws';
- updateWsStatus(false, '正在连接...');
- const led = document.getElementById('wsLed');
- led.className = 'ws-led connecting';
- try {
- ws = new WebSocket(wsUrl);
- ws.onopen = function() {
- console.log('WebSocket连接成功');
- wsConnected = true;
- reconnectAttempts = 0;
- updateWsStatus(true, '已连接');
- ws.send(mk_hdr_bin(0, PKT_TYPE.NEW_PKT_TYPE_DEVICE_INFO, 0, 0, 0));
- };
- ws.binaryType = 'arraybuffer';
- ws.onmessage = onWsMessage;
- ws.onerror = function(error) { console.error('WebSocket错误:', error); updateWsStatus(false, '连接错误'); };
- ws.onclose = function() {
- console.log('WebSocket连接关闭');
- wsConnected = false;
- updateWsStatus(false, '连接已断开');
- if (reconnectTimer)
- clearTimeout(reconnectTimer);
- if (reconnectAttempts < maxReconnectAttempts) {
- reconnectAttempts++;
- reconnectTimer = setTimeout(function() {
- connectWebSocket();
- }, 3000);
- } else {
- updateWsStatus(false, '连接失败,请刷新页面重试');
- }
- };
- } catch(e) { console.error('创建WebSocket失败:', e); updateWsStatus(false, '创建连接失败'); }
- }
- function openAddUserModal() {
- currentEditUserId = null;
- document.getElementById('userModalTitle').innerText = '新增用户';
- document.getElementById('userName').value = '';
- document.getElementById('userAddPassword').value = '';
- document.getElementById('userAddModal').classList.add('active');
- }
- function confirmUserAddAction()
- {
- let username = document.getElementById('userAddName').value.trim();
- let password = document.getElementById('userAddPassword').value;
- let role_s = document.getElementById('userRole').value;
- let role = (role_s == "superadmin") ? 1 : (role_s == "admin") ? 2 : 3;
- if (!username || !password) { showToast("用户名或密码不能为空", 1000); return; }
- userAddConfig(username,password,role)
- // let editId = document.getElementById('editUserId').value;
- // if (editId) {
- // updateUserApi(parseInt(editId), username, password, role);
- // } else {
- // if (!password) { showToast("新增用户必须填写密码", 1000); return; }
- // addUserApi(username, password, role);
- // }
- //closeModal('userAddModal');
- }
- function confirmUserAction() {
- let username = document.getElementById('userName').value.trim();
- let old_password = document.getElementById('userOldPassword').value;
- let new_password = document.getElementById('userNewPassword').value;
- let role_s = document.getElementById('userRole').value;
- let role = (role_s == "superadmin") ? 1 : (role_s == "admin") ? 2 : 3;
- if(!old_password || !new_password)
- {
- showToast("编辑用户必须填写密码", 1000); return;
- }
- userUpdateConfig(username,old_password,new_password,role);
- // if (!username) { showToast("用户名不能为空", 1000); return; }
- // let editId = document.getElementById('editUserId').value;
- // if (editId) {
- // updateUserApi(parseInt(editId), username, password, role);
- // } else {
- // if (!password) { showToast("新增用户必须填写密码", 1000); return; }
- // addUserApi(username, password, role);
- // }
- // closeModal('userModal');
- }
- function initApp() {
- connectWebSocket();
- //ws.send(mk_hdr_bin(0, PKT_TYPE.NEW_PKT_TYPE_DEVICE_INFO, 0, 0, 0));
- startTimeUpdater();
- document.getElementById('openDelayConfigBtn').addEventListener('click', openDelayModal);
- document.getElementById('openThresholdConfigBtn').addEventListener('click', openThresholdModal);
- document.getElementById('openResetEnergyModalBtn').addEventListener('click', openResetEnergyModal);
- document.getElementById('allOnBtn').addEventListener('click', allOn);
- document.getElementById('allOffBtn').addEventListener('click', allOff);
- document.getElementById('openAlarmModalBtn').addEventListener('click', openAlarmModal);
- document.getElementById('cleanSoundLight').addEventListener('click', clean_sound_light);
- document.getElementById('tempCard').addEventListener('click',openTempModal);
- document.getElementById('humiCard').addEventListener('click',openHumiModal);
- document.getElementById('smokeCard').addEventListener('click',openSmokeModal);
- document.getElementById('co2Card').addEventListener('click',openCo2Modal);
- document.getElementById('setSystemRebootBtn').addEventListener('click',rebootSystem);
- document.getElementById('addUserBtn')?.addEventListener('click', openAddUserModal);
- document.getElementById('closeUserModalBtn')?.addEventListener('click',()=>closeModal('userModal'));
- document.getElementById('cancelUserModalBtn')?.addEventListener('click',()=>closeModal('userModal'));
- document.getElementById('closeUserAddModalBtn')?.addEventListener('click',()=>closeModal('userAddModal'));
- document.getElementById('cancelUserAddModalBtn')?.addEventListener('click',()=>closeModal('userAddModal'));
- document.getElementById('confirmUserAddBtn')?.addEventListener('click', confirmUserAddAction);
- document.getElementById('confirmUserBtn')?.addEventListener('click', confirmUserAction);
-
- // document.getElementById('ALL').addEventListener('click',function(){
- // show_l_info = 0;
- // document.getElementById('ALL').classList.add('active');
- // document.getElementById('L1').classList.remove('active');
- // document.getElementById('L2').classList.remove('active');
- // document.getElementById('L3').classList.remove('active');
- // });
- document.getElementById('L1').addEventListener('click',function(){
- show_l_info =1;
- //document.getElementById('ALL').classList.remove('active');
- document.getElementById('L1').classList.add('active');
- document.getElementById('L2').classList.remove('active');
- document.getElementById('L3').classList.remove('active');
- });
- document.getElementById('L2').addEventListener('click',function(){
- show_l_info = 2;
- //document.getElementById('ALL').classList.remove('active');
- document.getElementById('L1').classList.remove('active');
- document.getElementById('L2').classList.add('active');
- document.getElementById('L3').classList.remove('active');
- });
- document.getElementById('L3').addEventListener('click',function(){
- show_l_info = 3
- // document.getElementById('ALL').classList.remove('active');
- document.getElementById('L1').classList.remove('active');
- document.getElementById('L2').classList.remove('active');
- document.getElementById('L3').classList.add('active');
- });
- document.getElementById('closeAlarmModalBtn').addEventListener('click', function() {
- closeModal('alarmModal');
- });
- document.getElementById('cancelAlarmModalBtn').addEventListener('click', function() {
- closeModal('alarmModal');
- });
- document.getElementById('clearAlarmBtn').addEventListener('click', clearAlarm);
- document.getElementById('saveNetConfigBtn').addEventListener('click', saveNetConfig);
- document.getElementById('saveRs485ConfigBtn').addEventListener('click', saveRs485Config);
- document.getElementById('saveSnmpConfigBtn').addEventListener('click', saveSnmpConfig);
- document.getElementById('ipMode').addEventListener('change', updateStaticIpFieldsEnable);
- document.getElementById('snmpTrapStatus').addEventListener('change', updateSnmpEnable);
- document.getElementById('reconnectBtn').addEventListener('click', function() {
- if (ws) ws.close();
- connectWebSocket();
- });
- document.getElementById('setSystemTimeBtn').addEventListener('click', function() {
- confirmNtp();
- });
- const tabs = document.querySelectorAll('.tab-btn');
- for (let j = 0; j < tabs.length; j++) tabs[j].addEventListener('click', function() {
- switchPage(this.dataset.page);
- });
- document.getElementById('closeTempModalBtn').addEventListener('click', function() {
- closeModal('tempCardModal');
- });
- document.getElementById('closeHumiModalBtn').addEventListener('click', function() {
- closeModal('humiCardModal');
- });
- document.getElementById('closeSmokeModalBtn').addEventListener('click', function() {
- closeModal('smokeCardModal');
- });
- document.getElementById('closeCo2ModalBtn').addEventListener('click', function() {
- closeModal('co2CardModal');
- });
- document.getElementById('closeDelayModalBtn').addEventListener('click', function() {
- closeModal('delayModal');
- });
- document.getElementById('cancelDelayModalBtn').addEventListener('click', function() {
- closeModal('delayModal');
- });
- document.getElementById('closeThresholdModalBtn').addEventListener('click', function() {
- closeModal('thresholdModal');
- });
- document.getElementById('cancelThresholdModalBtn').addEventListener('click', function() {
- closeModal('thresholdModal');
- });
- document.getElementById('closeResetModalBtn').addEventListener('click', function() {
- closeModal('resetEnergyModal');
- });
- document.getElementById('cancelResetModalBtn').addEventListener('click', function() {
- closeModal('resetEnergyModal');
- });
- document.getElementById('confirmTempThrBtn').addEventListener('click', confirmTempThr);
- document.getElementById('confirmHumiThrBtn').addEventListener('click', confirmHumiThr);
- document.getElementById('confirmSmokeThrBtn').addEventListener('click', confirmSmokeThr);
- document.getElementById('confirmCo2ThrBtn').addEventListener('click', confirmCo2Thr);
- document.getElementById('confirmResetEnergyBtn').addEventListener('click', confirmResetEnergy);
- document.getElementById('selectAllChannels').addEventListener('click', selectAllChannels);
- document.getElementById('deselectAllChannels').addEventListener('click', deselectAllChannels);
- const modals = ['delayModal', 'thresholdModal', 'resetEnergyModal', 'alarmModal'];
- for (let k = 0; k < modals.length; k++)(function(id) {
- const el = document.getElementById(id);
- if (el) el.addEventListener('click', function(e) {
- if (e.target === document.getElementById(id)) closeModal(id);
- });
- })(modals[k]);
- document.getElementById('reconnectBtn').addEventListener('click',()=>{ if(ws)ws.close(); connectWebSocket(); });
- document.getElementById('logoutBtn').addEventListener('click',()=>{ sessionStorage.removeItem(STORAGE_KEY);
- if(ws && ws.readyState===WebSocket.OPEN)
- ws.close();
- if(power_all_id) clearInterval(power_all_id);
- if(power_data_id) clearInterval(power_data_id);
- if(power_thr_id) clearInterval(power_thr_id);
- if(sensor_id) clearInterval(sensor_id);
- if(wanning_id) clearInterval(wanning_id);
- if(device_info_id) clearInterval(device_info_id);
- document.getElementById('loginContainer').style.display='flex';
- document.getElementById('dashboardApp').style.display='none';
- document.getElementById('loginUsername').value='';
- document.getElementById('loginPassword').value='';
- document.getElementById('loginErrorMsg').innerText=''; });
-
- const pwdInput = document.getElementById('loginPassword');
- if (pwdInput) {
- pwdInput.addEventListener('keypress', (e) => { if (e.key === 'Enter') document.getElementById('loginBtn').click(); });
- }
- }
- function performLogin(username, password) {
- const errorDiv = document.getElementById('loginErrorMsg');
- if (!username || !password) { errorDiv.innerText = '请输入用户名和密码'; return; }
- errorDiv.innerText = '正在验证...';
- //const wsUrl = 'ws://192.168.9.110/ws';
- const wsUrl = 'ws://' + window.location.host + '/ws';
- tempws = new WebSocket(wsUrl);
- tempws.binaryType = 'arraybuffer';
- let responded = false;
- tempws.onopen = function() {
- const encoder = new TextEncoder();
- const unameBuf = new Uint8Array(32);
- const pwdBuf = new Uint8Array(32);
- unameBuf.set(encoder.encode(username).slice(0,32));
- pwdBuf.set(encoder.encode(password).slice(0,32));
- const payload = new ArrayBuffer(64);
- const view = new Uint8Array(payload);
- view.set(unameBuf,0); view.set(pwdBuf,32);
- const header = mk_hdr_bin(0,0x08,0,0,0,64);
- const fullMsg = array_cat(header,payload);
- tempws.send(fullMsg);
- };
- tempws.onmessage = function(event) {
- if(responded) return;
- try {
- if (event.data instanceof ArrayBuffer) {
- var obj = bin_parse(event.data);
- if (obj.login != undefined) {
- if(obj.login.flag === 1)
- {
- responded=true;
- tempws.close();
- errorDiv.innerText='';
- document.getElementById('loginContainer').style.display='none';
- document.getElementById('dashboardApp').style.display='block';
- sessionStorage.setItem(STORAGE_KEY,'true');
- initApp();
- }else if(obj.login.flag === 2)
- {
- responded=true;
- tempws.close();
- errorDiv.innerText='密码错误';
- }else if(obj.login.flag === 0)
- {
- responded=true;
- tempws.close();
- errorDiv.innerText='用户名错误';
- }
-
- }
- }
- }catch (e) {
- console.error('解析WebSocket消息失败:', e);
- }
- };
- tempws.onerror = function() {
- if(!responded){
- responded=true;
- errorDiv.innerText='连接服务器失败';
- }
- };
- tempws.onclose = function() { if(!responded) errorDiv.innerText='连接已断开'; };
- }
- const STORAGE_KEY = 'power_monitor_auth';
- const MAGIC = 0xdead;
- let power_all_id = 0;
- let power_thr_id = 0;
- let power_data_id = 0;
- let device_info_id = 0;
- let sensor_id = 0;
- let wanning_id = 0;
- let device_info = [];
- let channelDelays = [];
- let channelThresholds = [];
- let tempValue = [];
- let humiValue = [];
- let smokeValue = [];
- let co2Value = [];
- let currentSelectedChannels = [];
- let channelTelemetry = [];
- let channelTelemetry1 = [];
- let channelTelemetry2 = [];
- let channelSwitchStates = [];
- let envData = {temp: 25,humi: 50,smoke: 100,co2: 400};
- let alarmList = [];
- let nextAlarmId = 1;
- let all_channel = [];
- let all_l_channel = [];
- let channel_info = [];
- let update_flag = 0;
- let show_l_info = 0;
- let tableRows = [];
- let netConfig = {
- ipMode: "auto",
- ipAddress: "192.168.1.100",
- subnetMask: "255.255.255.0",
- gateway: "192.168.1.1",
- dns1: "114.114.114.114",
- dns2: "8.8.8.8"
- };
- let ntpConfig = {
- ntpZone:"8",
- };
- let rs485Config = {
- mode: "master",
- address: 1,
- baudrate: "9600"
- };
- let snmpConfig = {
- status : "open",
- readCommunity: "public",
- writeCommunity: "private",
- trapStatus: "open",
- trapIp: "",
- };
- let users = [];
- let user_cnt = [];
- let systemTime = new Date();
- // WebSocket 连接
- let ws = null;
- let wsConnected = false;
- let reconnectAttempts = 0;
- const maxReconnectAttempts = 10;
- let reconnectTimer = null;
- document.getElementById('loginBtn').addEventListener('click',()=>{
- let user=document.getElementById('loginUsername').value.trim();
- let pwd=document.getElementById('loginPassword').value;
- performLogin(user,pwd);
- });
- if(sessionStorage.getItem(STORAGE_KEY)==='true'){
- document.getElementById('loginContainer').style.display='none';
- document.getElementById('dashboardApp').style.display='block';
- initApp();
- } else {
- document.getElementById('loginContainer').style.display='flex';
- document.getElementById('dashboardApp').style.display='none';
- }
- </script>
- </body>
- </html>
|