| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142 |
- <!DOCTYPE html>
- <html lang="zh-CN">
- <head>
- <meta charset="UTF-8">
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
- <title>设备管理列表 - 爱智农</title>
- <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/tailwindcss@2.2.19/dist/tailwind.min.css">
- <link rel="stylesheet" href="https://at.alicdn.com/t/font_3114978_qe0b39no76.css">
- <link rel="stylesheet" href="../assets/css/global.css">
- <style>
- :root {
- --primary: #4CAF50;
- --primary-dark: #388E3C;
- --primary-light: #A5D6A7;
- --primary-bg: #F1F8E9;
- --success: #4CAF50;
- --warning: #FFC107;
- --danger: #F44336;
- --info: #2196F3;
- --disabled: #9E9E9E;
- --border: #E0E0E0;
- --text-primary: #212121;
- --text-secondary: #757575;
- --radius: 8px;
- }
-
- body {
- font-family: "PingFang SC", "Microsoft YaHei", sans-serif;
- background-color: #f5f7f9;
- color: var(--text-primary);
- margin: 0;
- padding: 0;
- min-height: 100vh;
- padding-top: 70px; /* 确保内容不被系统导航栏遮挡 */
- }
-
- .page-container {
- padding: 20px;
- position: relative;
- min-height: 100vh;
- width: 100%;
- max-width: 1400px;
- margin: 0 auto;
- box-sizing: border-box;
- }
-
- .card {
- background-color: white;
- border-radius: 8px;
- box-shadow: 0 2px 8px rgba(0,0,0,0.05);
- margin-bottom: 20px;
- }
-
- .table-container {
- position: relative;
- position: relative;
- overflow-x: auto;
- position: relative;
- }
-
- table {
- width: 100%;
- border-collapse: separate;
- border-spacing: 0;
- }
-
- th {
- white-space: nowrap;
- position: relative;
- overflow: visible;
- max-width: none;
- text-overflow: clip;
- white-space: nowrap;
- position: relative;
- background-color: #f9fafb;
- padding: 12px 16px;
- text-align: left;
- font-weight: 500;
- color: #6b7280;
- border-bottom: 1px solid #e5e7eb;
- white-space: nowrap;
- position: relative;
- }
-
- td {
- white-space: nowrap;
- max-width: 200px;
- overflow: hidden;
- text-overflow: ellipsis;
- white-space: nowrap;
- max-width: 200px;
- overflow: hidden;
- text-overflow: ellipsis;
- padding: 12px 16px;
- border-bottom: 1px solid #e5e7eb;
- white-space: nowrap;
- max-width: 200px;
- overflow: hidden;
- text-overflow: ellipsis;
- }
-
- /* 固定最后一列(操作列)样式 */
- .table-fixed-right {
- position: relative;
- }
-
- .table-fixed-right th:last-child,
- .table-fixed-right td:last-child {
- position: sticky;
- right: 0;
- z-index: 2;
- background-color: white;
- box-shadow: -5px 0 5px -5px rgba(0, 0, 0, 0.1);
- }
-
- .table-fixed-right th:last-child {
- background-color: #f9fafb;
- }
-
- /* 表格滚动控件 */
- .table-scroll-controls {
- display: none;
- position: absolute;
- top: 50%;
- transform: translateY(-50%);
- width: 100%;
- pointer-events: none;
- z-index: 3;
- }
-
- .table-scroll-btn {
- position: absolute;
- width: 32px;
- height: 32px;
- border-radius: 50%;
- background-color: rgba(255, 255, 255, 0.9);
- color: #4CAF50;
- border: 1px solid #e0e0e0;
- display: flex;
- align-items: center;
- justify-content: center;
- cursor: pointer;
- pointer-events: auto;
- box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
- z-index: 4;
- }
-
- .table-scroll-left {
- left: 10px;
- }
-
- .table-scroll-right {
- right: 10px;
- }
-
- .has-overflow .table-scroll-controls {
- display: block;
- }
-
- tr:hover {
- background-color: #f9fafb;
- }
-
- tr:hover td:last-child {
- background-color: #f9fafb;
- }
-
- .btn {
- display: inline-flex;
- align-items: center;
- justify-content: center;
- padding: 8px 16px;
- border-radius: 4px;
- font-weight: 500;
- cursor: pointer;
- transition: all 0.2s;
- }
-
- .btn-primary {
- background-color: #4CAF50;
- color: white;
- }
-
- .btn-primary:hover {
- background-color: #388E3C;
- }
-
- .btn-default {
- background-color: white;
- border: 1px solid #d1d5db;
- color: #374151;
- }
-
- .btn-default:hover {
- background-color: #f9fafb;
- }
-
- .btn-sm {
- padding: 4px 8px;
- font-size: 12px;
- }
-
- .search-box {
- display: flex;
- gap: 8px;
- }
-
- .input {
- padding: 8px 12px;
- border: 1px solid #d1d5db;
- border-radius: 4px;
- flex-grow: 1;
- }
-
- .select {
- padding: 8px 12px;
- border: 1px solid #d1d5db;
- border-radius: 4px;
- background-color: white;
- min-width: 120px;
- }
-
- .badge {
- display: inline-block;
- padding: 2px 8px;
- border-radius: 9999px;
- font-size: 12px;
- font-weight: 500;
- }
-
- .badge-success {
- background-color: #d1fae5;
- color: #065f46;
- }
-
- .badge-warning {
- background-color: #fef3c7;
- color: #92400e;
- }
-
- .badge-danger {
- background-color: #fee2e2;
- color: #b91c1c;
- }
-
- .page-header {
- display: flex;
- justify-content: space-between;
- align-items: center;
- margin-bottom: 20px;
- padding-bottom: 16px;
- border-bottom: 1px solid #e0e0e0;
- }
-
- .pagination {
- display: flex;
- align-items: center;
- justify-content: flex-end;
- gap: 4px;
- }
-
- .pagination-item {
- display: inline-flex;
- align-items: center;
- justify-content: center;
- width: 32px;
- height: 32px;
- border-radius: 4px;
- cursor: pointer;
- transition: all 0.2s;
- }
-
- .pagination-item:hover {
- background-color: #f3f4f6;
- }
-
- .pagination-item.active {
- background-color: #4CAF50;
- color: white;
- }
-
- .pagination-item.disabled {
- color: #9ca3af;
- cursor: not-allowed;
- }
-
- .modal-overlay {
- position: fixed;
- top: 0;
- left: 0;
- right: 0;
- bottom: 0;
- background-color: rgba(0, 0, 0, 0.5);
- display: flex;
- align-items: center;
- justify-content: center;
- z-index: 50;
- display: none;
- }
-
- .modal {
- background-color: white;
- border-radius: 8px;
- width: 100%;
- max-width: 600px;
- box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
- }
-
- .modal-header {
- padding: 16px 24px;
- border-bottom: 1px solid #e5e7eb;
- display: flex;
- align-items: center;
- justify-content: space-between;
- }
-
- .modal-title {
- font-size: 18px;
- font-weight: 500;
- }
-
- .modal-close {
- cursor: pointer;
- font-size: 20px;
- }
-
- .modal-body {
- padding: 24px;
- }
-
- .modal-footer {
- padding: 16px 24px;
- border-top: 1px solid #e5e7eb;
- display: flex;
- justify-content: flex-end;
- gap: 8px;
- }
-
- .form-group {
- margin-bottom: 16px;
- }
-
- .form-label {
- display: block;
- margin-bottom: 4px;
- font-weight: 500;
- }
-
- .form-input {
- width: 100%;
- padding: 8px 12px;
- border: 1px solid #d1d5db;
- border-radius: 4px;
- }
-
- .grid-2 {
- display: grid;
- grid-template-columns: 1fr 1fr;
- gap: 16px;
- }
-
- /* 搜索条件样式 */
- .filter-group {
- display: flex;
- flex-wrap: wrap;
- gap: 10px;
- margin-bottom: 15px;
- padding-bottom: 15px;
- border-bottom: 1px dashed #e5e7eb;
- }
-
- .filter-group:last-child {
- border-bottom: none;
- margin-bottom: 0;
- padding-bottom: 0;
- }
-
- .filter-item {
- display: flex;
- align-items: center;
- min-width: 180px;
- }
-
- .filter-label {
- color: #6b7280;
- font-size: 13px;
- min-width: 70px;
- }
-
- .date-filter {
- display: flex;
- align-items: center;
- }
-
- .date-filter input {
- width: 140px;
- }
-
- .filter-divider {
- color: #9ca3af;
- margin: 0 4px;
- }
- </style>
- </head>
- <body>
- <div class="page-container">
- <div class="page-header">
- <h1 class="text-2xl font-bold">设备管理列表</h1>
-
- <div class="flex gap-2">
- <button class="btn btn-primary" id="addDeviceBtn">
- <i class="iconfont icon-plus" style="margin-right: 4px;"></i>
- 新增设备
- </button>
- <button class="btn btn-default" id="importBtn">
- <i class="iconfont icon-upload" style="margin-right: 4px;"></i>
- 导入
- </button>
- <button class="btn btn-default" id="exportBtn">
- <i class="iconfont icon-download" style="margin-right: 4px;"></i>
- 导出
- </button>
- </div>
- </div>
-
- <div class="card p-6">
- <div class="filter-group">
- <div class="filter-item" style="min-width: 300px;">
- <span class="filter-label">设备编号:</span>
- <input type="text" class="input w-full" placeholder="请输入设备编号关键词">
- </div>
-
- <div class="filter-item" style="min-width: 300px;">
- <span class="filter-label">设备名称:</span>
- <input type="text" class="input w-full" placeholder="请输入设备名称关键词">
- </div>
-
- <div class="ml-auto">
- <button class="btn btn-primary">
- <i class="iconfont icon-search" style="margin-right: 4px;"></i>
- 搜索
- </button>
- <button class="btn btn-default ml-2">
- <i class="iconfont icon-reload" style="margin-right: 4px;"></i>
- 重置
- </button>
- </div>
- </div>
-
- <div class="filter-group">
- <div class="filter-item">
- <span class="filter-label">设备类型:</span>
- <select class="select">
- <option value="">全部</option>
- <option value="sensor">传感器</option>
- <option value="camera">摄像头</option>
- <option value="controller">控制器</option>
- <option value="weather">气象设备</option>
- </select>
- </div>
-
- <div class="filter-item">
- <span class="filter-label">所属农场:</span>
- <select class="select">
- <option value="">全部</option>
- <option value="east">东区智慧农场</option>
- <option value="west">西区智慧农场</option>
- <option value="south">南区智慧农场</option>
- <option value="center">中心监测农场</option>
- </select>
- </div>
-
- <div class="filter-item">
- <span class="filter-label">所属地块:</span>
- <select class="select">
- <option value="">全部</option>
- <option value="a-3">A区大棚3号</option>
- <option value="a-1">A区大棚1号</option>
- <option value="b-2">B区稻田2号</option>
- <option value="c-1">C区果园1号</option>
- <option value="m-1">监测区1号</option>
- </select>
- </div>
-
- <div class="filter-item">
- <span class="filter-label">设备状态:</span>
- <select class="select">
- <option value="">全部</option>
- <option value="1">在线</option>
- <option value="0">离线</option>
- <option value="2">故障</option>
- <option value="3">维护中</option>
- </select>
- </div>
-
- </div>
- </div>
-
- <div class="card">
- <div class="table-container">
- <div class="table-scroll-controls">
- <button class="table-scroll-btn table-scroll-left">
- <i class="iconfont icon-left"></i>
- </button>
- <button class="table-scroll-btn table-scroll-right">
- <i class="iconfont icon-right"></i>
- </button>
- </div>
- <table class="table-fixed-right">
- <thead>
- <tr>
- <th class="min-w-[120px]">设备编号</th>
- <th class="min-w-[120px]">设备名称</th>
- <th class="min-w-[100px]">设备类型</th>
- <th class="min-w-[120px]">所属地块</th>
- <th class="min-w-[120px]">所属农场</th>
- <th class="min-w-[100px]">设备型号</th>
- <th class="min-w-[100px]">厂家</th>
- <th class="min-w-[100px]">安装日期</th>
- <th class="min-w-[80px]">状态</th>
- <th class="min-w-[150px]">最后活动时间</th>
- <th class="min-w-[150px]">操作</th>
- </tr>
- </thead>
- <tbody>
- <tr>
- <td>DEV20230001</td>
- <td>温湿度传感器-A1</td>
- <td>传感器</td>
- <td>A区大棚3号</td>
- <td>东区智慧农场</td>
- <td>TS-100A</td>
- <td>智农科技</td>
- <td>2023-01-15</td>
- <td><span class="badge badge-success">在线</span></td>
- <td>2023-10-15 14:30</td>
- <td>
- <div class="flex gap-2">
- <button class="btn btn-sm btn-default view-btn" data-id="DEV20230001">
- <i class="iconfont icon-eye"></i>
- 查看
- </button>
- <button class="btn btn-sm btn-default edit-btn" data-id="DEV20230001">
- <i class="iconfont icon-edit"></i>
- 编辑
- </button>
- <button class="btn btn-sm btn-default delete-btn" data-id="DEV20230001" style="color: #F44336;">
- <i class="iconfont icon-delete"></i>
- 删除
- </button>
- </div>
- </td>
- </tr>
- <tr>
- <td>DEV20230002</td>
- <td>土壤湿度检测仪-B1</td>
- <td>传感器</td>
- <td>B区稻田2号</td>
- <td>西区智慧农场</td>
- <td>SM-200B</td>
- <td>农达科技</td>
- <td>2023-02-20</td>
- <td><span class="badge badge-warning">离线</span></td>
- <td>2023-10-10 09:15</td>
- <td>
- <div class="flex gap-2">
- <button class="btn btn-sm btn-default view-btn" data-id="DEV20230002">
- <i class="iconfont icon-eye"></i>
- 查看
- </button>
- <button class="btn btn-sm btn-default edit-btn" data-id="DEV20230002">
- <i class="iconfont icon-edit"></i>
- 编辑
- </button>
- <button class="btn btn-sm btn-default delete-btn" data-id="DEV20230002" style="color: #F44336;">
- <i class="iconfont icon-delete"></i>
- 删除
- </button>
- </div>
- </td>
- </tr>
- <tr>
- <td>DEV20230003</td>
- <td>气象站-C1</td>
- <td>气象设备</td>
- <td>监测区1号</td>
- <td>中心监测农场</td>
- <td>WS-500C</td>
- <td>科沃电子</td>
- <td>2023-03-10</td>
- <td><span class="badge badge-success">在线</span></td>
- <td>2023-10-16 10:25</td>
- <td>
- <div class="flex gap-2">
- <button class="btn btn-sm btn-default view-btn" data-id="DEV20230003">
- <i class="iconfont icon-eye"></i>
- 查看
- </button>
- <button class="btn btn-sm btn-default edit-btn" data-id="DEV20230003">
- <i class="iconfont icon-edit"></i>
- 编辑
- </button>
- <button class="btn btn-sm btn-default delete-btn" data-id="DEV20230003" style="color: #F44336;">
- <i class="iconfont icon-delete"></i>
- 删除
- </button>
- </div>
- </td>
- </tr>
- <tr>
- <td>DEV20230004</td>
- <td>智能灌溉控制器-D1</td>
- <td>控制器</td>
- <td>C区果园1号</td>
- <td>南区智慧农场</td>
- <td>IC-300D</td>
- <td>水利通</td>
- <td>2023-04-05</td>
- <td><span class="badge badge-danger">故障</span></td>
- <td>2023-10-12 18:40</td>
- <td>
- <div class="flex gap-2">
- <button class="btn btn-sm btn-default view-btn" data-id="DEV20230004">
- <i class="iconfont icon-eye"></i>
- 查看
- </button>
- <button class="btn btn-sm btn-default edit-btn" data-id="DEV20230004">
- <i class="iconfont icon-edit"></i>
- 编辑
- </button>
- <button class="btn btn-sm btn-default delete-btn" data-id="DEV20230004" style="color: #F44336;">
- <i class="iconfont icon-delete"></i>
- 删除
- </button>
- </div>
- </td>
- </tr>
- <tr>
- <td>DEV20230005</td>
- <td>作物监控摄像头-E1</td>
- <td>摄像头</td>
- <td>A区大棚1号</td>
- <td>东区智慧农场</td>
- <td>CC-400E</td>
- <td>视界科技</td>
- <td>2023-05-20</td>
- <td><span class="badge badge-success">在线</span></td>
- <td>2023-10-16 11:05</td>
- <td>
- <div class="flex gap-2">
- <button class="btn btn-sm btn-default view-btn" data-id="DEV20230005">
- <i class="iconfont icon-eye"></i>
- 查看
- </button>
- <button class="btn btn-sm btn-default edit-btn" data-id="DEV20230005">
- <i class="iconfont icon-edit"></i>
- 编辑
- </button>
- <button class="btn btn-sm btn-default delete-btn" data-id="DEV20230005" style="color: #F44336;">
- <i class="iconfont icon-delete"></i>
- 删除
- </button>
- </div>
- </td>
- </tr>
- </tbody>
- </table>
- </div>
-
- <div class="p-4 border-t border-gray-200 flex justify-between items-center">
- <div class="text-sm text-gray-500">显示 1 至 5,共 24 条记录</div>
- <div class="pagination">
- <div class="pagination-item disabled"><</div>
- <div class="pagination-item active">1</div>
- <div class="pagination-item">2</div>
- <div class="pagination-item">3</div>
- <div class="pagination-item">4</div>
- <div class="pagination-item">5</div>
- <div class="pagination-item">></div>
- </div>
- </div>
- </div>
-
- <!-- 设备表单弹窗 -->
- <div class="modal-overlay" id="deviceModal">
- <div class="modal">
- <div class="modal-header">
- <div class="modal-title">添加设备</div>
- <div class="modal-close" id="closeModal">×</div>
- </div>
- <div class="modal-body">
- <form id="deviceForm">
- <div class="grid-2">
- <div class="form-group">
- <label class="form-label">设备编号</label>
- <input type="text" class="form-input" id="deviceId" placeholder="输入设备编号">
- </div>
- <div class="form-group">
- <label class="form-label">设备名称</label>
- <input type="text" class="form-input" id="deviceName" placeholder="输入设备名称">
- </div>
- </div>
- <div class="grid-2">
- <div class="form-group">
- <label class="form-label">设备类型</label>
- <select class="form-input" id="deviceType">
- <option value="">请选择设备类型</option>
- <option value="sensor">传感器</option>
- <option value="camera">摄像头</option>
- <option value="controller">控制器</option>
- <option value="weather">气象设备</option>
- </select>
- </div>
- <div class="form-group">
- <label class="form-label">所属农场</label>
- <select class="form-input" id="deviceFarm">
- <option value="">请选择所属农场</option>
- <option value="east">东区智慧农场</option>
- <option value="west">西区智慧农场</option>
- <option value="south">南区智慧农场</option>
- <option value="center">中心监测农场</option>
- </select>
- </div>
- </div>
- <div class="grid-2">
- <div class="form-group">
- <label class="form-label">设备型号</label>
- <input type="text" class="form-input" id="deviceModel" placeholder="输入设备型号">
- </div>
- <div class="form-group">
- <label class="form-label">厂家</label>
- <input type="text" class="form-input" id="deviceManufacturer" placeholder="输入厂家名称">
- </div>
- </div>
- <div class="form-group">
- <label class="form-label">安装日期</label>
- <input type="date" class="form-input" id="installDate">
- </div>
- <div class="grid-2">
- <div class="form-group">
- <label class="form-label">GPS经度</label>
- <input type="number" step="0.000001" class="form-input" id="deviceLongitude" placeholder="输入经度(如:120.1619)">
- </div>
- <div class="form-group">
- <label class="form-label">GPS纬度</label>
- <input type="number" step="0.000001" class="form-input" id="deviceLatitude" placeholder="输入纬度(如:30.2922)">
- </div>
- </div>
- <div class="form-group">
- <label class="form-label">设备描述</label>
- <textarea class="form-input" id="deviceDesc" rows="3" placeholder="输入设备描述"></textarea>
- </div>
- </form>
- </div>
- <div class="modal-footer">
- <button class="btn btn-default" id="cancelBtn">取消</button>
- <button class="btn btn-primary" id="saveBtn">保存</button>
- </div>
- </div>
- </div>
-
- <!-- 删除确认弹窗 -->
- <div class="modal-overlay" id="deleteModal">
- <div class="modal" style="max-width: 400px;">
- <div class="modal-header">
- <div class="modal-title">删除确认</div>
- <div class="modal-close" id="closeDeleteModal">×</div>
- </div>
- <div class="modal-body">
- <p class="mb-2">确定要删除该设备吗?</p>
- <p class="text-gray-500 text-sm">设备编号:<span id="deleteDeviceId"></span></p>
- <p class="text-gray-500 text-sm">设备名称:<span id="deleteDeviceName"></span></p>
- </div>
- <div class="modal-footer">
- <button class="btn btn-default" id="cancelDeleteBtn">取消</button>
- <button class="btn btn-danger" id="confirmDeleteBtn" style="background-color: #F44336; color: white;">确认删除</button>
- </div>
- </div>
- </div>
- <!-- 设备详情弹窗 -->
- <div class="modal-overlay" id="deviceDetailModal" style="z-index: 60;">
- <div class="modal" style="max-width: 800px; max-height: 85vh; overflow: hidden; display: flex; flex-direction: column;">
- <div class="modal-header">
- <div class="modal-title">设备详情</div>
- <div class="modal-close" id="closeDetailModal">×</div>
- </div>
- <div class="flex border-b border-gray-200">
- <div class="cursor-pointer px-6 py-3 font-medium text-sm border-b-2 border-green-500 text-green-600 tab-btn active" data-tab="basic-info">基本信息</div>
- <div class="cursor-pointer px-6 py-3 font-medium text-sm text-gray-500 tab-btn" data-tab="real-time-data">实时数据</div>
- </div>
- <div class="modal-body flex-grow overflow-y-auto" style="max-height: calc(85vh - 120px);">
- <!-- 基本信息 Tab -->
- <div class="tab-content active" id="basic-info">
- <div class="grid grid-cols-2 gap-6">
- <div class="card p-6 bg-white rounded-lg shadow-sm">
- <h3 class="text-lg font-medium text-gray-800 mb-4">设备基础信息</h3>
- <div class="space-y-4">
- <div class="flex items-center">
- <span class="text-gray-500 w-24">设备编号:</span>
- <span id="detail-device-id" class="font-medium text-gray-800"></span>
- </div>
- <div class="flex items-center">
- <span class="text-gray-500 w-24">设备名称:</span>
- <span id="detail-device-name" class="font-medium text-gray-800"></span>
- </div>
- <div class="flex items-center">
- <span class="text-gray-500 w-24">设备类型:</span>
- <span id="detail-device-type" class="font-medium text-gray-800"></span>
- </div>
- <div class="flex items-center">
- <span class="text-gray-500 w-24">设备型号:</span>
- <span id="detail-device-model" class="font-medium text-gray-800"></span>
- </div>
- <div class="flex items-center">
- <span class="text-gray-500 w-24">制造厂商:</span>
- <span id="detail-manufacturer" class="font-medium text-gray-800"></span>
- </div>
- </div>
- </div>
-
- <div class="card p-6 bg-white rounded-lg shadow-sm">
- <h3 class="text-lg font-medium text-gray-800 mb-4">位置信息</h3>
- <div class="space-y-4">
- <div class="flex items-center">
- <span class="text-gray-500 w-24">所属农场:</span>
- <span id="detail-farm" class="font-medium text-gray-800"></span>
- </div>
- <div class="flex items-center">
- <span class="text-gray-500 w-24">所属地块:</span>
- <span id="detail-plot" class="font-medium text-gray-800"></span>
- </div>
- <div class="flex items-center">
- <span class="text-gray-500 w-24">安装日期:</span>
- <span id="detail-install-date" class="font-medium text-gray-800"></span>
- </div>
- <div class="flex items-center">
- <span class="text-gray-500 w-24">GPS坐标:</span>
- <span id="detail-gps" class="font-medium text-gray-800">30.2922° N, 120.1619° E</span>
- </div>
- </div>
- </div>
-
- <div class="card p-6 bg-white rounded-lg shadow-sm col-span-2">
- <h3 class="text-lg font-medium text-gray-800 mb-4">运行状态</h3>
- <div class="grid grid-cols-2 gap-8">
- <div class="space-y-4">
- <div class="flex items-center">
- <span class="text-gray-500 w-24">当前状态:</span>
- <span id="detail-status" class="font-medium"></span>
- </div>
- <div class="flex items-center">
- <span class="text-gray-500 w-24">最近活动:</span>
- <span id="detail-last-active" class="font-medium text-gray-800"></span>
- </div>
- </div>
- <div class="space-y-4">
- <div class="flex items-center">
- <span class="text-gray-500 w-24">电量状态:</span>
- <div class="flex-1">
- <div class="w-full bg-gray-200 rounded-full h-2.5">
- <div id="detail-battery" class="bg-green-500 h-2.5 rounded-full" style="width: 85%"></div>
- </div>
- </div>
- <span class="ml-2 text-sm text-gray-500" id="detail-battery-text">85%</span>
- </div>
- <div class="flex items-center">
- <span class="text-gray-500 w-24">信号强度:</span>
- <div class="flex items-end space-x-1">
- <div class="h-3 w-1.5 bg-green-500 rounded-t"></div>
- <div class="h-4 w-1.5 bg-green-500 rounded-t"></div>
- <div class="h-5 w-1.5 bg-green-500 rounded-t"></div>
- <div class="h-6 w-1.5 bg-green-500 rounded-t"></div>
- <div class="h-7 w-1.5 bg-gray-300 rounded-t"></div>
- </div>
- <span class="ml-2 text-sm text-gray-500">良好</span>
- </div>
- </div>
- </div>
- </div>
- </div>
- </div>
-
- <!-- 实时数据 Tab -->
- <div class="tab-content hidden" id="real-time-data">
- <!-- 摄像头设备视图 -->
- <div id="camera-view" class="device-type-view hidden">
- <div class="grid grid-cols-1 md:grid-cols-4 gap-6">
- <!-- 左侧视频区域 -->
- <div class="md:col-span-3">
- <div class="card p-6 bg-white rounded-lg shadow-sm">
- <div class="flex justify-between items-center mb-4">
- <h3 class="text-lg font-medium text-gray-800">实时视频</h3>
- <div class="flex space-x-2">
- <button class="bg-gray-500 text-white p-2 rounded-md">
- <svg xmlns="http://www.w3.org/2000/svg" class="h-5 w-5" fill="none" viewBox="0 0 24 24" stroke="currentColor">
- <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M15 10l4.553-2.276A1 1 0 0121 8.618v6.764a1 1 0 01-1.447.894L15 14M5 18h8a2 2 0 002-2V8a2 2 0 00-2-2H5a2 2 0 00-2 2v8a2 2 0 002 2z" />
- </svg>
- </button>
- <button class="bg-gray-500 text-white p-2 rounded-md">
- <svg xmlns="http://www.w3.org/2000/svg" class="h-5 w-5" fill="none" viewBox="0 0 24 24" stroke="currentColor">
- <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M21 21l-6-6m2-5a7 7 0 11-14 0 7 7 0 0114 0z" />
- </svg>
- </button>
- </div>
- </div>
- <div class="aspect-video bg-gray-100 rounded-md flex items-center justify-center border border-gray-200">
- <!-- SVG占位符 -->
- <svg xmlns="http://www.w3.org/2000/svg" width="100" height="100" viewBox="0 0 24 24" fill="none" stroke="#9ca3af" stroke-width="1" stroke-linecap="round" stroke-linejoin="round">
- <rect x="2" y="2" width="20" height="20" rx="2.18" ry="2.18"></rect>
- <line x1="7" y1="2" x2="7" y2="22"></line>
- <line x1="17" y1="2" x2="17" y2="22"></line>
- <line x1="2" y1="12" x2="22" y2="12"></line>
- <line x1="2" y1="7" x2="7" y2="7"></line>
- <line x1="2" y1="17" x2="7" y2="17"></line>
- <line x1="17" y1="17" x2="22" y2="17"></line>
- <line x1="17" y1="7" x2="22" y2="7"></line>
- </svg>
- </div>
- </div>
- </div>
-
- <!-- 右侧云台控制 -->
- <div class="md:col-span-1">
- <div class="card p-6 bg-white rounded-lg shadow-sm h-full">
- <h3 class="text-lg font-medium text-gray-800 mb-6">云台控制</h3>
-
- <!-- 方向控制 -->
- <div class="flex flex-col items-center mb-6">
- <!-- 上 -->
- <button class="bg-gray-200 hover:bg-gray-300 rounded-full p-3 mb-4 transition-colors">
- <svg xmlns="http://www.w3.org/2000/svg" class="h-6 w-6 text-gray-700" fill="none" viewBox="0 0 24 24" stroke="currentColor">
- <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M5 15l7-7 7 7" />
- </svg>
- </button>
-
- <!-- 左右 -->
- <div class="flex justify-between w-full mb-4">
- <button class="bg-gray-200 hover:bg-gray-300 rounded-full p-3 transition-colors">
- <svg xmlns="http://www.w3.org/2000/svg" class="h-6 w-6 text-gray-700" fill="none" viewBox="0 0 24 24" stroke="currentColor">
- <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M10 19l-7-7m0 0l7-7m-7 7h18" />
- </svg>
- </button>
- <button class="bg-gray-200 hover:bg-gray-300 rounded-full p-3 transition-colors">
- <svg xmlns="http://www.w3.org/2000/svg" class="h-6 w-6 text-gray-700" fill="none" viewBox="0 0 24 24" stroke="currentColor">
- <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M14 5l7 7m0 0l-7 7m7-7H3" />
- </svg>
- </button>
- </div>
-
- <!-- 下 -->
- <button class="bg-gray-200 hover:bg-gray-300 rounded-full p-3 transition-colors">
- <svg xmlns="http://www.w3.org/2000/svg" class="h-6 w-6 text-gray-700" fill="none" viewBox="0 0 24 24" stroke="currentColor">
- <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M19 9l-7 7-7-7" />
- </svg>
- </button>
- </div>
-
- <!-- 缩放控制 -->
- <div class="space-y-6">
- <div>
- <label class="block text-sm text-gray-600 mb-2">缩放</label>
- <div class="flex items-center">
- <span class="text-gray-500 mr-2">-</span>
- <input type="range" min="1" max="10" value="1" class="w-full accent-blue-500">
- <span class="text-gray-500 ml-2">+</span>
- </div>
- </div>
-
- <!-- 焦距控制 -->
- <div>
- <label class="block text-sm text-gray-600 mb-2">焦距</label>
- <div class="flex items-center">
- <span class="text-gray-500 mr-2">-</span>
- <input type="range" min="1" max="10" value="5" class="w-full accent-blue-500">
- <span class="text-gray-500 ml-2">+</span>
- </div>
- </div>
- </div>
- </div>
- </div>
- </div>
- </div>
-
- <!-- 传感器设备视图 -->
- <div id="sensor-view" class="device-type-view hidden">
- <div class="grid grid-cols-1 gap-6">
- <!-- 实时读数卡片 -->
- <div class="card p-6 bg-white rounded-lg shadow-sm">
- <div class="flex justify-between items-center mb-4">
- <h3 class="text-lg font-medium text-gray-800">实时读数</h3>
- <div class="text-xs text-gray-500">最后更新: <span id="sensor-last-update">2023-10-16 15:45</span></div>
- </div>
- <div class="grid grid-cols-2 md:grid-cols-4 gap-4">
- <div class="bg-gray-50 p-4 rounded-lg text-center">
- <div class="text-4xl font-bold text-green-600 mb-1" id="sensor-value-1">26.5</div>
- <div class="text-sm text-gray-500">温度 (°C)</div>
- </div>
- <div class="bg-gray-50 p-4 rounded-lg text-center">
- <div class="text-4xl font-bold text-blue-600 mb-1" id="sensor-value-2">65%</div>
- <div class="text-sm text-gray-500">湿度</div>
- </div>
- <div class="bg-gray-50 p-4 rounded-lg text-center">
- <div class="text-4xl font-bold text-amber-600 mb-1" id="sensor-value-3">782</div>
- <div class="text-sm text-gray-500">光照 (lux)</div>
- </div>
- <div class="bg-gray-50 p-4 rounded-lg text-center">
- <div class="text-4xl font-bold text-purple-600 mb-1" id="sensor-value-4">25%</div>
- <div class="text-sm text-gray-500">土壤湿度</div>
- </div>
- </div>
- </div>
-
- <!-- 数据统计图 -->
- <div class="card p-6 bg-white rounded-lg shadow-sm">
- <div class="flex flex-wrap justify-between items-center mb-4">
- <h3 class="text-lg font-medium text-gray-800 mb-2 sm:mb-0">数据统计图</h3>
-
- <div class="flex flex-wrap items-center gap-3">
- <!-- 指标选择 -->
- <div class="flex items-center">
- <span class="text-sm text-gray-500 mr-2">指标:</span>
- <select id="chart-indicator" class="text-sm border border-gray-300 rounded px-2 py-1">
- <option value="all">全部指标</option>
- <option value="temperature">温度</option>
- <option value="humidity">湿度</option>
- <option value="light">光照</option>
- <option value="soil">土壤湿度</option>
- </select>
- </div>
-
- <!-- 时间范围 -->
- <div class="flex space-x-1">
- <button class="time-range-btn bg-gray-200 hover:bg-gray-300 text-xs px-3 py-1.5 rounded-full" data-range="24h">24小时</button>
- <button class="time-range-btn bg-green-500 text-white text-xs px-3 py-1.5 rounded-full" data-range="7d">7天</button>
- <button class="time-range-btn bg-gray-200 hover:bg-gray-300 text-xs px-3 py-1.5 rounded-full" data-range="30d">30天</button>
- </div>
- </div>
- </div>
-
- <!-- 图表容器 -->
- <div class="chart-container h-80 bg-gray-50 rounded-lg">
- <canvas id="sensor-chart"></canvas>
- </div>
-
- <!-- 图表图例 -->
- <div class="flex flex-wrap gap-4 mt-4 justify-center">
- <div class="flex items-center">
- <span class="w-3 h-3 rounded-full bg-green-500 mr-1"></span>
- <span class="text-xs text-gray-600">温度</span>
- </div>
- <div class="flex items-center">
- <span class="w-3 h-3 rounded-full bg-blue-500 mr-1"></span>
- <span class="text-xs text-gray-600">湿度</span>
- </div>
- <div class="flex items-center">
- <span class="w-3 h-3 rounded-full bg-amber-500 mr-1"></span>
- <span class="text-xs text-gray-600">光照</span>
- </div>
- <div class="flex items-center">
- <span class="w-3 h-3 rounded-full bg-purple-500 mr-1"></span>
- <span class="text-xs text-gray-600">土壤湿度</span>
- </div>
- </div>
- <!-- 数据统计信息 -->
- <div class="grid grid-cols-2 md:grid-cols-4 gap-4 mt-6">
- <div class="bg-white p-4 rounded-lg shadow-sm">
- <div class="text-sm text-gray-500 mb-1">平均温度</div>
- <div class="text-2xl font-medium text-gray-800 mb-1">24.8 °C</div>
- <div class="text-xs text-green-600 flex items-center">
- <svg xmlns="http://www.w3.org/2000/svg" class="h-3 w-3 mr-1" viewBox="0 0 20 20" fill="currentColor">
- <path fill-rule="evenodd" d="M12 7a1 1 0 110-2h5a1 1 0 011 1v5a1 1 0 11-2 0V8.414l-4.293 4.293a1 1 0 01-1.414 0L8 10.414l-4.293 4.293a1 1 0 01-1.414-1.414l5-5a1 1 0 011.414 0L11 10.586 14.586 7H12z" clip-rule="evenodd" />
- </svg>
- 2.5%
- </div>
- </div>
- <div class="bg-white p-4 rounded-lg shadow-sm">
- <div class="text-sm text-gray-500 mb-1">平均湿度</div>
- <div class="text-2xl font-medium text-gray-800 mb-1">63.2%</div>
- <div class="text-xs text-red-600 flex items-center">
- <svg xmlns="http://www.w3.org/2000/svg" class="h-3 w-3 mr-1" viewBox="0 0 20 20" fill="currentColor">
- <path fill-rule="evenodd" d="M12 13a1 1 0 100 2h5a1 1 0 001-1v-5a1 1 0 10-2 0v2.586l-4.293-4.293a1 1 0 00-1.414 0L8 9.586 3.707 5.293a1 1 0 00-1.414 1.414l5 5a1 1 0 001.414 0L11 9.414 14.586 13H12z" clip-rule="evenodd" />
- </svg>
- 1.8%
- </div>
- </div>
- <div class="bg-white p-4 rounded-lg shadow-sm">
- <div class="text-sm text-gray-500 mb-1">平均光照</div>
- <div class="text-2xl font-medium text-gray-800 mb-1">756 lux</div>
- <div class="text-xs text-green-600 flex items-center">
- <svg xmlns="http://www.w3.org/2000/svg" class="h-3 w-3 mr-1" viewBox="0 0 20 20" fill="currentColor">
- <path fill-rule="evenodd" d="M12 7a1 1 0 110-2h5a1 1 0 011 1v5a1 1 0 11-2 0V8.414l-4.293 4.293a1 1 0 01-1.414 0L8 10.414l-4.293 4.293a1 1 0 01-1.414-1.414l5-5a1 1 0 011.414 0L11 10.586 14.586 7H12z" clip-rule="evenodd" />
- </svg>
- 5.2%
- </div>
- </div>
- <div class="bg-white p-4 rounded-lg shadow-sm">
- <div class="text-sm text-gray-500 mb-1">平均土壤湿度</div>
- <div class="text-2xl font-medium text-gray-800 mb-1">28.5%</div>
- <div class="text-xs text-green-600 flex items-center">
- <svg xmlns="http://www.w3.org/2000/svg" class="h-3 w-3 mr-1" viewBox="0 0 20 20" fill="currentColor">
- <path fill-rule="evenodd" d="M12 7a1 1 0 110-2h5a1 1 0 011 1v5a1 1 0 11-2 0V8.414l-4.293 4.293a1 1 0 01-1.414 0L8 10.414l-4.293 4.293a1 1 0 01-1.414-1.414l5-5a1 1 0 011.414 0L11 10.586 14.586 7H12z" clip-rule="evenodd" />
- </svg>
- 3.1%
- </div>
- </div>
- </div>
- </div>
- </div>
- </div>
-
- <!-- 气象站设备视图 -->
- <div id="weather-view" class="device-type-view hidden">
- <div class="grid grid-cols-1 gap-6">
- <!-- 实时气象数据卡片 -->
- <div class="card p-6 bg-white rounded-lg shadow-sm">
- <div class="flex justify-between items-center mb-4">
- <h3 class="text-lg font-medium text-gray-800">实时气象数据</h3>
- <div class="text-xs text-gray-500">最后更新: <span id="weather-last-update">2023-10-16 15:50</span></div>
- </div>
- <div class="grid grid-cols-2 md:grid-cols-3 lg:grid-cols-4 gap-4">
- <div class="bg-gray-50 p-4 rounded-lg flex items-center">
- <div class="text-red-500 mr-3">
- <svg xmlns="http://www.w3.org/2000/svg" class="h-6 w-6" fill="none" viewBox="0 0 24 24" stroke="currentColor">
- <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M5 10l7-7m0 0l7 7m-7-7v18" />
- </svg>
- </div>
- <div>
- <div class="text-sm text-gray-500">气温</div>
- <div class="text-xl font-medium text-gray-800">24.8 °C</div>
- </div>
- </div>
- <div class="bg-gray-50 p-4 rounded-lg flex items-center">
- <div class="text-blue-500 mr-3">
- <svg xmlns="http://www.w3.org/2000/svg" class="h-6 w-6" fill="none" viewBox="0 0 24 24" stroke="currentColor">
- <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M17.657 18.657A8 8 0 016.343 7.343S7 9 9 10c0-2 .5-5 2.986-7C14 5 16.09 5.777 17.656 7.343A7.975 7.975 0 0120 13a7.975 7.975 0 01-2.343 5.657z" />
- </svg>
- </div>
- <div>
- <div class="text-sm text-gray-500">湿度</div>
- <div class="text-xl font-medium text-gray-800">76%</div>
- </div>
- </div>
- <div class="bg-gray-50 p-4 rounded-lg flex items-center">
- <div class="text-blue-600 mr-3">
- <svg xmlns="http://www.w3.org/2000/svg" class="h-6 w-6" fill="none" viewBox="0 0 24 24" stroke="currentColor">
- <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M19 14l-7 7m0 0l-7-7m7 7V3" />
- </svg>
- </div>
- <div>
- <div class="text-sm text-gray-500">降雨量</div>
- <div class="text-xl font-medium text-gray-800">2.5 mm</div>
- </div>
- </div>
- <div class="bg-gray-50 p-4 rounded-lg flex items-center">
- <div class="text-amber-500 mr-3">
- <svg xmlns="http://www.w3.org/2000/svg" class="h-6 w-6" fill="none" viewBox="0 0 24 24" stroke="currentColor">
- <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 19l9 2-9-18-9 18 9-2zm0 0v-8" />
- </svg>
- </div>
- <div>
- <div class="text-sm text-gray-500">风向</div>
- <div class="text-xl font-medium text-gray-800">东北</div>
- </div>
- </div>
- <div class="bg-gray-50 p-4 rounded-lg flex items-center">
- <div class="text-purple-500 mr-3">
- <svg xmlns="http://www.w3.org/2000/svg" class="h-6 w-6" fill="none" viewBox="0 0 24 24" stroke="currentColor">
- <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M17.657 18.657A8 8 0 016.343 7.343S7 9 9 10c0-2 .5-5 2.986-7C14 5 16.09 5.777 17.656 7.343A7.975 7.975 0 0120 13a7.975 7.975 0 01-2.343 5.657z" />
- </svg>
- </div>
- <div>
- <div class="text-sm text-gray-500">风速</div>
- <div class="text-xl font-medium text-gray-800">3.2 m/s</div>
- </div>
- </div>
- <div class="bg-gray-50 p-4 rounded-lg flex items-center">
- <div class="text-indigo-500 mr-3">
- <svg xmlns="http://www.w3.org/2000/svg" class="h-6 w-6" fill="none" viewBox="0 0 24 24" stroke="currentColor">
- <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M3 15a4 4 0 004 4h9a5 5 0 10-.1-9.999 5.002 5.002 0 10-9.78 2.096A4.001 4.001 0 003 15z" />
- </svg>
- </div>
- <div>
- <div class="text-sm text-gray-500">气压</div>
- <div class="text-xl font-medium text-gray-800">1013 hPa</div>
- </div>
- </div>
- <div class="bg-gray-50 p-4 rounded-lg flex items-center">
- <div class="text-green-500 mr-3">
- <svg xmlns="http://www.w3.org/2000/svg" class="h-6 w-6" fill="none" viewBox="0 0 24 24" stroke="currentColor">
- <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 3v1m0 16v1m9-9h-1M4 12H3m15.364 6.364l-.707-.707M6.343 6.343l-.707-.707m12.728 0l-.707.707M6.343 17.657l-.707.707M16 12a4 4 0 11-8 0 4 4 0 018 0z" />
- </svg>
- </div>
- <div>
- <div class="text-sm text-gray-500">光照</div>
- <div class="text-xl font-medium text-gray-800">12500 lux</div>
- </div>
- </div>
- </div>
- </div>
-
- <!-- 数据统计图 -->
- <div class="card p-6 bg-white rounded-lg shadow-sm">
- <div class="flex flex-wrap justify-between items-center mb-4">
- <h3 class="text-lg font-medium text-gray-800 mb-2 sm:mb-0">气象数据统计图</h3>
-
- <div class="flex flex-wrap items-center gap-3">
- <!-- 指标选择 -->
- <div class="flex items-center">
- <span class="text-sm text-gray-500 mr-2">指标:</span>
- <select id="weather-chart-indicator" class="text-sm border border-gray-300 rounded px-2 py-1">
- <option value="all">全部指标</option>
- <option value="temperature">气温</option>
- <option value="humidity">湿度</option>
- <option value="rainfall">降雨量</option>
- <option value="windspeed">风速</option>
- <option value="pressure">气压</option>
- <option value="light">光照</option>
- </select>
- </div>
-
- <!-- 时间范围 -->
- <div class="flex space-x-1">
- <button class="weather-time-range-btn bg-gray-200 hover:bg-gray-300 text-xs px-3 py-1.5 rounded-full" data-range="24h">24小时</button>
- <button class="weather-time-range-btn bg-green-500 text-white text-xs px-3 py-1.5 rounded-full" data-range="7d">7天</button>
- <button class="weather-time-range-btn bg-gray-200 hover:bg-gray-300 text-xs px-3 py-1.5 rounded-full" data-range="30d">30天</button>
- </div>
- </div>
- </div>
-
- <!-- 图表容器 -->
- <div class="chart-container h-80 bg-gray-50 rounded-lg">
- <canvas id="weather-chart"></canvas>
- </div>
-
- <!-- 图表图例 -->
- <div class="flex flex-wrap gap-4 mt-4 justify-center">
- <div class="flex items-center">
- <span class="w-3 h-3 rounded-full bg-red-500 mr-1"></span>
- <span class="text-xs text-gray-600">气温</span>
- </div>
- <div class="flex items-center">
- <span class="w-3 h-3 rounded-full bg-blue-500 mr-1"></span>
- <span class="text-xs text-gray-600">湿度</span>
- </div>
- <div class="flex items-center">
- <span class="w-3 h-3 rounded-full bg-blue-600 mr-1"></span>
- <span class="text-xs text-gray-600">降雨量</span>
- </div>
- <div class="flex items-center">
- <span class="w-3 h-3 rounded-full bg-purple-500 mr-1"></span>
- <span class="text-xs text-gray-600">风速</span>
- </div>
- </div>
-
- <!-- 数据统计信息 -->
- <div class="grid grid-cols-2 md:grid-cols-4 gap-4 mt-6">
- <div class="bg-white p-4 rounded-lg shadow-sm">
- <div class="text-sm text-gray-500 mb-1">平均气温</div>
- <div class="text-2xl font-medium text-gray-800 mb-1">22.4 °C</div>
- <div class="text-xs text-green-600 flex items-center">
- <svg xmlns="http://www.w3.org/2000/svg" class="h-3 w-3 mr-1" viewBox="0 0 20 20" fill="currentColor">
- <path fill-rule="evenodd" d="M12 7a1 1 0 110-2h5a1 1 0 011 1v5a1 1 0 11-2 0V8.414l-4.293 4.293a1 1 0 01-1.414 0L8 10.414l-4.293 4.293a1 1 0 01-1.414-1.414l5-5a1 1 0 011.414 0L11 10.586 14.586 7H12z" clip-rule="evenodd" />
- </svg>
- 1.8%
- </div>
- </div>
- <div class="bg-white p-4 rounded-lg shadow-sm">
- <div class="text-sm text-gray-500 mb-1">平均湿度</div>
- <div class="text-2xl font-medium text-gray-800 mb-1">68.5%</div>
- <div class="text-xs text-red-600 flex items-center">
- <svg xmlns="http://www.w3.org/2000/svg" class="h-3 w-3 mr-1" viewBox="0 0 20 20" fill="currentColor">
- <path fill-rule="evenodd" d="M12 13a1 1 0 100 2h5a1 1 0 001-1v-5a1 1 0 10-2 0v2.586l-4.293-4.293a1 1 0 00-1.414 0L8 9.586 3.707 5.293a1 1 0 00-1.414 1.414l5 5a1 1 0 001.414 0L11 9.414 14.586 13H12z" clip-rule="evenodd" />
- </svg>
- 2.3%
- </div>
- </div>
- <div class="bg-white p-4 rounded-lg shadow-sm">
- <div class="text-sm text-gray-500 mb-1">累计降雨量</div>
- <div class="text-2xl font-medium text-gray-800 mb-1">18.5 mm</div>
- <div class="text-xs text-green-600 flex items-center">
- <svg xmlns="http://www.w3.org/2000/svg" class="h-3 w-3 mr-1" viewBox="0 0 20 20" fill="currentColor">
- <path fill-rule="evenodd" d="M12 7a1 1 0 110-2h5a1 1 0 011 1v5a1 1 0 11-2 0V8.414l-4.293 4.293a1 1 0 01-1.414 0L8 10.414l-4.293 4.293a1 1 0 01-1.414-1.414l5-5a1 1 0 011.414 0L11 10.586 14.586 7H12z" clip-rule="evenodd" />
- </svg>
- 12.4%
- </div>
- </div>
- <div class="bg-white p-4 rounded-lg shadow-sm">
- <div class="text-sm text-gray-500 mb-1">平均风速</div>
- <div class="text-2xl font-medium text-gray-800 mb-1">2.8 m/s</div>
- <div class="text-xs text-red-600 flex items-center">
- <svg xmlns="http://www.w3.org/2000/svg" class="h-3 w-3 mr-1" viewBox="0 0 20 20" fill="currentColor">
- <path fill-rule="evenodd" d="M12 13a1 1 0 100 2h5a1 1 0 001-1v-5a1 1 0 10-2 0v2.586l-4.293-4.293a1 1 0 00-1.414 0L8 9.586 3.707 5.293a1 1 0 00-1.414 1.414l5 5a1 1 0 001.414 0L11 9.414 14.586 13H12z" clip-rule="evenodd" />
- </svg>
- 0.7%
- </div>
- </div>
- </div>
- </div>
- </div>
- </div>
-
- <!-- 控制器设备视图 -->
- <div id="controller-view" class="device-type-view hidden">
- <div class="grid grid-cols-2 gap-4">
- <div class="card p-4">
- <h3 class="font-medium text-gray-700 mb-4">控制状态</h3>
- <div class="space-y-4">
- <div class="flex justify-between items-center pb-3 border-b">
- <span class="flex items-center">
- <span class="mr-2 h-3 w-3 rounded-full bg-green-500"></span>
- 水泵1#
- </span>
- <span class="badge badge-success">运行中</span>
- </div>
- <div class="flex justify-between items-center pb-3 border-b">
- <span class="flex items-center">
- <span class="mr-2 h-3 w-3 rounded-full bg-red-500"></span>
- 水泵2#
- </span>
- <span class="badge badge-danger">已停止</span>
- </div>
- <div class="flex justify-between items-center pb-3 border-b">
- <span class="flex items-center">
- <span class="mr-2 h-3 w-3 rounded-full bg-green-500"></span>
- 风机
- </span>
- <span class="badge badge-success">运行中</span>
- </div>
- <div class="flex justify-between items-center pb-3 border-b">
- <span class="flex items-center">
- <span class="mr-2 h-3 w-3 rounded-full bg-amber-500"></span>
- 灌溉阀门
- </span>
- <span class="badge badge-warning">部分开启</span>
- </div>
- <div class="flex justify-between items-center">
- <span class="flex items-center">
- <span class="mr-2 h-3 w-3 rounded-full bg-red-500"></span>
- 照明系统
- </span>
- <span class="badge badge-danger">已关闭</span>
- </div>
- </div>
- </div>
- <div class="card p-4">
- <h3 class="font-medium text-gray-700 mb-4">运行参数</h3>
- <div class="space-y-4">
- <div>
- <label class="block text-sm text-gray-600 mb-1">系统工作模式</label>
- <select class="form-input bg-gray-100" disabled>
- <option selected>自动模式</option>
- <option>手动模式</option>
- <option>定时模式</option>
- <option>智能模式</option>
- </select>
- </div>
- <div>
- <label class="block text-sm text-gray-600 mb-1">水泵1#流量</label>
- <div class="flex items-center">
- <div class="w-full bg-gray-200 rounded-full h-2.5">
- <div class="bg-green-500 h-2.5 rounded-full" style="width: 65%"></div>
- </div>
- <span class="ml-2 text-sm">65%</span>
- </div>
- </div>
- <div>
- <label class="block text-sm text-gray-600 mb-1">风机转速</label>
- <div class="flex items-center">
- <div class="w-full bg-gray-200 rounded-full h-2.5">
- <div class="bg-green-500 h-2.5 rounded-full" style="width: 80%"></div>
- </div>
- <span class="ml-2 text-sm">80%</span>
- </div>
- </div>
- <div>
- <label class="block text-sm text-gray-600 mb-1">阀门开度</label>
- <div class="flex items-center">
- <div class="w-full bg-gray-200 rounded-full h-2.5">
- <div class="bg-amber-500 h-2.5 rounded-full" style="width: 45%"></div>
- </div>
- <span class="ml-2 text-sm">45%</span>
- </div>
- </div>
- </div>
- </div>
- <div class="col-span-2 card p-4">
- <h3 class="font-medium text-gray-700 mb-4">运行记录</h3>
- <table class="min-w-full">
- <thead>
- <tr>
- <th class="py-2 px-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">时间</th>
- <th class="py-2 px-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">事件类型</th>
- <th class="py-2 px-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">操作人员</th>
- <th class="py-2 px-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">详情</th>
- </tr>
- </thead>
- <tbody class="bg-white divide-y divide-gray-200 text-sm">
- <tr>
- <td class="py-2 px-3">2023-10-16 14:30</td>
- <td class="py-2 px-3">自动启动</td>
- <td class="py-2 px-3">系统</td>
- <td class="py-2 px-3">根据传感器数据,水泵1#自动启动</td>
- </tr>
- <tr>
- <td class="py-2 px-3">2023-10-16 12:15</td>
- <td class="py-2 px-3">手动调整</td>
- <td class="py-2 px-3">张农艺师</td>
- <td class="py-2 px-3">调整风机转速至80%</td>
- </tr>
- <tr>
- <td class="py-2 px-3">2023-10-16 09:30</td>
- <td class="py-2 px-3">自动关闭</td>
- <td class="py-2 px-3">系统</td>
- <td class="py-2 px-3">灌溉完成,阀门自动关闭</td>
- </tr>
- <tr>
- <td class="py-2 px-3">2023-10-16 08:00</td>
- <td class="py-2 px-3">系统检查</td>
- <td class="py-2 px-3">系统</td>
- <td class="py-2 px-3">日常自检完成,所有系统正常</td>
- </tr>
- </tbody>
- </table>
- </div>
- </div>
- </div>
- </div>
- </div>
- </div>
- </div>
- </div>
-
- <script>
- // 添加设备按钮点击事件
- document.getElementById('addDeviceBtn').addEventListener('click', function() {
- document.getElementById('deviceModal').style.display = 'flex';
- });
-
- // 初始化表格滚动功能
- function initTableScroll() {
- const tableContainer = document.querySelector('.table-container');
- const scrollLeftBtn = document.querySelector('.table-scroll-left');
- const scrollRightBtn = document.querySelector('.table-scroll-right');
-
- // 检查表格是否需要水平滚动
- function checkTableOverflow() {
- if (tableContainer.scrollWidth > tableContainer.clientWidth) {
- tableContainer.classList.add('has-overflow');
- } else {
- tableContainer.classList.remove('has-overflow');
- }
- }
-
- // 左右滚动按钮点击事件
- scrollLeftBtn.addEventListener('click', function() {
- tableContainer.scrollLeft -= 150;
- });
-
- scrollRightBtn.addEventListener('click', function() {
- tableContainer.scrollLeft += 150;
- });
-
- // 初始检查和窗口大小变化时检查
- checkTableOverflow();
- window.addEventListener('resize', checkTableOverflow);
-
- // 滚动事件处理
- tableContainer.addEventListener('scroll', function() {
- // 根据滚动位置显示/隐藏滚动按钮
- if (tableContainer.scrollLeft <= 10) {
- scrollLeftBtn.style.opacity = '0.5';
- } else {
- scrollLeftBtn.style.opacity = '1';
- }
-
- if (tableContainer.scrollLeft >= tableContainer.scrollWidth - tableContainer.clientWidth - 10) {
- scrollRightBtn.style.opacity = '0.5';
- } else {
- scrollRightBtn.style.opacity = '1';
- }
- });
-
- // 初始触发滚动事件,设置初始按钮状态
- tableContainer.dispatchEvent(new Event('scroll'));
- }
-
- // 页面加载完成后初始化表格滚动
- window.addEventListener('load', initTableScroll);
-
- // 关闭模态框
- document.getElementById('closeModal').addEventListener('click', function() {
- document.getElementById('deviceModal').style.display = 'none';
- });
-
- // 取消按钮点击事件
- document.getElementById('cancelBtn').addEventListener('click', function() {
- document.getElementById('deviceModal').style.display = 'none';
- });
-
- // 保存按钮点击事件
- document.getElementById('saveBtn').addEventListener('click', function() {
- alert('设备信息已保存');
- document.getElementById('deviceModal').style.display = 'none';
- });
-
- // 编辑按钮点击事件
- const editBtns = document.querySelectorAll('.edit-btn');
- editBtns.forEach(function(btn) {
- btn.addEventListener('click', function() {
- const deviceId = this.getAttribute('data-id');
- document.getElementById('deviceModal').style.display = 'flex';
- document.querySelector('.modal-title').textContent = '编辑设备';
-
- // 根据表格行数据填充表单
- const row = this.closest('tr');
- const cells = row.querySelectorAll('td');
-
- // 填充表单字段
- document.getElementById('deviceId').value = cells[0].textContent;
- document.getElementById('deviceName').value = cells[1].textContent;
-
- // 设备类型
- const deviceTypeSelect = document.getElementById('deviceType');
- Array.from(deviceTypeSelect.options).forEach(option => {
- if (option.text === cells[2].textContent) {
- option.selected = true;
- }
- });
-
- // 所属农场
- const deviceFarmSelect = document.getElementById('deviceFarm');
- Array.from(deviceFarmSelect.options).forEach(option => {
- if (option.text === cells[4].textContent) {
- option.selected = true;
- }
- });
-
- // 设备型号、厂家、安装日期
- document.getElementById('deviceModel').value = cells[5].textContent;
- document.getElementById('deviceManufacturer').value = cells[6].textContent;
- document.getElementById('installDate').value = formatDateForInput(cells[7].textContent);
-
- // 填充GPS坐标(从详情中获取)
- const gpsText = document.getElementById('detail-gps').textContent;
- if (gpsText) {
- const [latitude, longitude] = gpsText.split(',').map(coord => {
- return parseFloat(coord.replace(/[°NS\s]/g, ''));
- });
- document.getElementById('deviceLatitude').value = latitude || '';
- document.getElementById('deviceLongitude').value = longitude || '';
- } else {
- document.getElementById('deviceLatitude').value = '';
- document.getElementById('deviceLongitude').value = '';
- }
- });
- });
-
- // 日期格式化工具函数(将 "YYYY-MM-DD" 格式化为 date input 所需格式)
- function formatDateForInput(dateString) {
- // 假设输入格式为 "YYYY-MM-DD"
- // HTML date input 也使用 "YYYY-MM-DD" 格式,所以可以直接返回
- return dateString;
- }
-
- // 查看按钮点击事件
- const viewBtns = document.querySelectorAll('.view-btn');
- viewBtns.forEach(function(btn) {
- btn.addEventListener('click', function() {
- const deviceId = this.getAttribute('data-id');
-
- // 获取设备所在行的数据
- const row = this.closest('tr');
- const cells = row.querySelectorAll('td');
-
- // 填充基本信息
- document.getElementById('detail-device-id').textContent = cells[0].textContent;
- document.getElementById('detail-device-name').textContent = cells[1].textContent;
- document.getElementById('detail-device-type').textContent = cells[2].textContent;
- document.getElementById('detail-device-model').textContent = cells[5].textContent;
- document.getElementById('detail-manufacturer').textContent = cells[6].textContent;
- document.getElementById('detail-farm').textContent = cells[4].textContent;
- document.getElementById('detail-plot').textContent = cells[3].textContent;
- document.getElementById('detail-install-date').textContent = cells[7].textContent;
-
- // 设置设备状态
- const statusText = cells[8].querySelector('span').textContent;
- document.getElementById('detail-status').textContent = statusText;
- if (statusText === '在线') {
- document.getElementById('detail-status').innerHTML = '<span class="badge badge-success">在线</span>';
- } else if (statusText === '离线') {
- document.getElementById('detail-status').innerHTML = '<span class="badge badge-warning">离线</span>';
- } else if (statusText === '故障') {
- document.getElementById('detail-status').innerHTML = '<span class="badge badge-danger">故障</span>';
- } else {
- document.getElementById('detail-status').innerHTML = '<span class="badge badge-secondary">维护中</span>';
- }
-
- // 设置最后活动时间
- document.getElementById('detail-last-active').textContent = cells[9].textContent;
-
- // 根据设备类型显示对应的实时数据视图
- const deviceType = cells[2].textContent;
- const deviceTypeViews = document.querySelectorAll('.device-type-view');
- deviceTypeViews.forEach(function(view) {
- view.classList.add('hidden');
- });
-
- // 根据设备类型显示对应的视图
- if (deviceType === '摄像头') {
- document.getElementById('camera-view').classList.remove('hidden');
- } else if (deviceType === '传感器') {
- document.getElementById('sensor-view').classList.remove('hidden');
-
- // 可以根据不同传感器类型设置不同的示例数据
- if (cells[1].textContent.includes('温湿度')) {
- document.getElementById('sensor-value-1').textContent = '26.5';
- document.getElementById('sensor-value-2').textContent = '65%';
- } else if (cells[1].textContent.includes('土壤')) {
- document.getElementById('sensor-value-4').textContent = '35%';
- }
- } else if (deviceType === '气象设备') {
- document.getElementById('weather-view').classList.remove('hidden');
- } else if (deviceType === '控制器') {
- document.getElementById('controller-view').classList.remove('hidden');
- }
-
- // 显示设备详情弹窗
- document.getElementById('deviceDetailModal').style.display = 'flex';
-
- // 默认显示基本信息标签页
- document.querySelector('.tab-btn[data-tab="basic-info"]').click();
- });
- });
- // 删除按钮点击事件
- const deleteBtns = document.querySelectorAll('.delete-btn');
- deleteBtns.forEach(function(btn) {
- btn.addEventListener('click', function() {
- const deviceId = this.getAttribute('data-id');
- const row = this.closest('tr');
- const cells = row.querySelectorAll('td');
-
- // 显示删除确认弹窗
- document.getElementById('deleteDeviceId').textContent = cells[0].textContent;
- document.getElementById('deleteDeviceName').textContent = cells[1].textContent;
- document.getElementById('deleteModal').style.display = 'flex';
-
- // 保存当前行引用,用于确认删除时使用
- document.getElementById('confirmDeleteBtn').setAttribute('data-row', row.rowIndex);
- });
- });
-
- // 关闭删除确认弹窗
- document.getElementById('closeDeleteModal').addEventListener('click', function() {
- document.getElementById('deleteModal').style.display = 'none';
- });
-
- // 取消删除
- document.getElementById('cancelDeleteBtn').addEventListener('click', function() {
- document.getElementById('deleteModal').style.display = 'none';
- });
-
- // 确认删除
- document.getElementById('confirmDeleteBtn').addEventListener('click', function() {
- const rowIndex = this.getAttribute('data-row');
- const table = document.querySelector('tbody');
- const rowToDelete = table.rows[rowIndex-1]; // -1 因为 rowIndex 是从 1 开始计数的
-
- if (rowToDelete) {
- rowToDelete.remove();
- }
-
- document.getElementById('deleteModal').style.display = 'none';
-
- // 显示删除成功提示
- alert('设备已成功删除');
- });
- // 设备详情相关功能
-
- // 关闭设备详情弹窗
- document.getElementById('closeDetailModal').addEventListener('click', function() {
- document.getElementById('deviceDetailModal').style.display = 'none';
- });
-
- // 切换设备详情标签页
- const tabBtns = document.querySelectorAll('.tab-btn');
- tabBtns.forEach(function(btn) {
- btn.addEventListener('click', function() {
- // 移除所有标签按钮的活动状态
- tabBtns.forEach(b => {
- b.classList.remove('active', 'border-b-2', 'border-green-500', 'text-green-600');
- b.classList.add('text-gray-500');
- });
-
- // 为当前按钮添加活动状态
- this.classList.add('active', 'border-b-2', 'border-green-500', 'text-green-600');
- this.classList.remove('text-gray-500');
-
- // 隐藏所有内容面板
- const tabContents = document.querySelectorAll('.tab-content');
- tabContents.forEach(function(content) {
- content.classList.add('hidden');
- });
-
- // 显示当前选中的内容面板
- const targetTab = this.getAttribute('data-tab');
- document.getElementById(targetTab).classList.remove('hidden');
- });
- });
- </script>
-
- <!-- Chart.js Library -->
- <script src="https://cdn.jsdelivr.net/npm/chart.js@3.9.1/dist/chart.min.js"></script>
-
- <!-- Chart Initialization -->
- <script>
- document.addEventListener('DOMContentLoaded', function() {
- // 初始化图表
- const initSensorChart = function() {
- const ctx = document.getElementById('sensor-chart');
-
- // 如果图表容器不存在,直接返回
- if (!ctx) return;
-
- // 模拟数据
- const timeLabels = [];
- const temperatureData = [];
- const humidityData = [];
- const lightData = [];
- const soilData = [];
-
- // 生成过去7天的日期标签和数据
- const now = new Date();
- for (let i = 6; i >= 0; i--) {
- const date = new Date(now);
- date.setDate(date.getDate() - i);
- timeLabels.push(`${date.getMonth() + 1}/${date.getDate()}`);
-
- // 生成模拟数据
- temperatureData.push(Math.round((20 + Math.random() * 10) * 10) / 10);
- humidityData.push(Math.round((50 + Math.random() * 30) * 10) / 10);
- lightData.push(Math.round(500 + Math.random() * 500));
- soilData.push(Math.round((20 + Math.random() * 15) * 10) / 10);
- }
-
- // 创建图表
- const sensorChart = new Chart(ctx, {
- type: 'line',
- data: {
- labels: timeLabels,
- datasets: [
- {
- label: '温度 (°C)',
- data: temperatureData,
- borderColor: '#4CAF50',
- backgroundColor: 'rgba(76, 175, 80, 0.1)',
- borderWidth: 2,
- tension: 0.3,
- fill: true
- },
- {
- label: '湿度 (%)',
- data: humidityData,
- borderColor: '#2196F3',
- backgroundColor: 'rgba(33, 150, 243, 0.1)',
- borderWidth: 2,
- tension: 0.3,
- fill: true
- },
- {
- label: '光照 (lux)',
- data: lightData,
- borderColor: '#FFC107',
- backgroundColor: 'rgba(255, 193, 7, 0.1)',
- borderWidth: 2,
- tension: 0.3,
- fill: true,
- hidden: true
- },
- {
- label: '土壤湿度 (%)',
- data: soilData,
- borderColor: '#9C27B0',
- backgroundColor: 'rgba(156, 39, 176, 0.1)',
- borderWidth: 2,
- tension: 0.3,
- fill: true,
- hidden: true
- }
- ]
- },
- options: {
- responsive: true,
- maintainAspectRatio: false,
- plugins: {
- legend: {
- display: false
- },
- tooltip: {
- mode: 'index',
- intersect: false
- }
- },
- scales: {
- x: {
- grid: {
- display: false
- }
- },
- y: {
- grid: {
- color: 'rgba(0, 0, 0, 0.05)'
- },
- beginAtZero: false
- }
- }
- }
- });
-
- // 指标选择事件处理
- document.getElementById('chart-indicator').addEventListener('change', function() {
- const selectedValue = this.value;
-
- // 重置所有数据集的可见性
- if (selectedValue === 'all') {
- sensorChart.data.datasets[0].hidden = false;
- sensorChart.data.datasets[1].hidden = false;
- sensorChart.data.datasets[2].hidden = true;
- sensorChart.data.datasets[3].hidden = true;
- } else {
- sensorChart.data.datasets[0].hidden = selectedValue !== 'temperature';
- sensorChart.data.datasets[1].hidden = selectedValue !== 'humidity';
- sensorChart.data.datasets[2].hidden = selectedValue !== 'light';
- sensorChart.data.datasets[3].hidden = selectedValue !== 'soil';
- }
-
- sensorChart.update();
- });
-
- // 时间范围按钮事件处理
- const timeRangeBtns = document.querySelectorAll('.time-range-btn');
- timeRangeBtns.forEach(function(btn) {
- btn.addEventListener('click', function() {
- // 更新按钮样式
- timeRangeBtns.forEach(b => {
- b.classList.remove('bg-green-500', 'text-white');
- b.classList.add('bg-gray-200');
- });
- this.classList.remove('bg-gray-200');
- this.classList.add('bg-green-500', 'text-white');
-
- // 根据选择的时间范围更新图表数据
- const range = this.getAttribute('data-range');
- let newLabels = [];
- let newTempData = [];
- let newHumidityData = [];
- let newLightData = [];
- let newSoilData = [];
-
- // 根据选择的时间范围生成新数据
- const now = new Date();
- let days = 7;
-
- if (range === '24h') {
- days = 1;
- // 生成24小时的数据
- for (let i = 0; i < 24; i += 2) {
- const hour = i.toString().padStart(2, '0') + ':00';
- newLabels.push(hour);
-
- newTempData.push(Math.round((20 + Math.random() * 10) * 10) / 10);
- newHumidityData.push(Math.round((50 + Math.random() * 30) * 10) / 10);
- newLightData.push(Math.round(500 + Math.random() * 500));
- newSoilData.push(Math.round((20 + Math.random() * 15) * 10) / 10);
- }
- } else if (range === '30d') {
- days = 30;
- // 生成30天的数据
- for (let i = 29; i >= 0; i -= 2) {
- const date = new Date(now);
- date.setDate(date.getDate() - i);
- newLabels.push(`${date.getMonth() + 1}/${date.getDate()}`);
-
- newTempData.push(Math.round((20 + Math.random() * 10) * 10) / 10);
- newHumidityData.push(Math.round((50 + Math.random() * 30) * 10) / 10);
- newLightData.push(Math.round(500 + Math.random() * 500));
- newSoilData.push(Math.round((20 + Math.random() * 15) * 10) / 10);
- }
- } else {
- // 7天的数据
- for (let i = 6; i >= 0; i--) {
- const date = new Date(now);
- date.setDate(date.getDate() - i);
- newLabels.push(`${date.getMonth() + 1}/${date.getDate()}`);
-
- newTempData.push(Math.round((20 + Math.random() * 10) * 10) / 10);
- newHumidityData.push(Math.round((50 + Math.random() * 30) * 10) / 10);
- newLightData.push(Math.round(500 + Math.random() * 500));
- newSoilData.push(Math.round((20 + Math.random() * 15) * 10) / 10);
- }
- }
-
- // 更新图表数据
- sensorChart.data.labels = newLabels;
- sensorChart.data.datasets[0].data = newTempData;
- sensorChart.data.datasets[1].data = newHumidityData;
- sensorChart.data.datasets[2].data = newLightData;
- sensorChart.data.datasets[3].data = newSoilData;
- sensorChart.update();
- });
- });
-
- return sensorChart;
- };
-
- // 当点击实时数据标签页时初始化图表
- document.querySelectorAll('.tab-btn').forEach(function(btn) {
- btn.addEventListener('click', function() {
- if (this.getAttribute('data-tab') === 'real-time-data') {
- setTimeout(function() {
- initSensorChart();
- }, 100);
- }
- });
- });
-
- // 当查看按钮点击时,为传感器类型设备初始化图表
- document.querySelectorAll('.view-btn').forEach(function(btn) {
- btn.addEventListener('click', function() {
- setTimeout(function() {
- if (!document.getElementById('sensor-view').classList.contains('hidden')) {
- initSensorChart();
- }
- if (!document.getElementById('weather-view').classList.contains('hidden')) {
- initWeatherChart();
- }
- }, 300);
- });
- });
-
- // 初始化气象图表
- const initWeatherChart = function() {
- const ctx = document.getElementById('weather-chart');
-
- // 如果图表容器不存在,直接返回
- if (!ctx) return;
-
- // 模拟数据
- const timeLabels = [];
- const temperatureData = [];
- const humidityData = [];
- const rainfallData = [];
- const windSpeedData = [];
-
- // 生成过去7天的日期标签和数据
- const now = new Date();
- for (let i = 6; i >= 0; i--) {
- const date = new Date(now);
- date.setDate(date.getDate() - i);
- timeLabels.push(`${date.getMonth() + 1}/${date.getDate()}`);
-
- // 生成模拟数据
- temperatureData.push(Math.round((18 + Math.random() * 10) * 10) / 10);
- humidityData.push(Math.round((60 + Math.random() * 30) * 10) / 10);
- rainfallData.push(Math.round(Math.random() * 10 * 10) / 10);
- windSpeedData.push(Math.round((1 + Math.random() * 4) * 10) / 10);
- }
-
- // 创建图表
- const weatherChart = new Chart(ctx, {
- type: 'line',
- data: {
- labels: timeLabels,
- datasets: [
- {
- label: '气温 (°C)',
- data: temperatureData,
- borderColor: '#EF4444',
- backgroundColor: 'rgba(239, 68, 68, 0.1)',
- borderWidth: 2,
- tension: 0.3,
- fill: true
- },
- {
- label: '湿度 (%)',
- data: humidityData,
- borderColor: '#3B82F6',
- backgroundColor: 'rgba(59, 130, 246, 0.1)',
- borderWidth: 2,
- tension: 0.3,
- fill: true
- },
- {
- label: '降雨量 (mm)',
- data: rainfallData,
- borderColor: '#2563EB',
- backgroundColor: 'rgba(37, 99, 235, 0.1)',
- borderWidth: 2,
- tension: 0.3,
- fill: true,
- hidden: true
- },
- {
- label: '风速 (m/s)',
- data: windSpeedData,
- borderColor: '#8B5CF6',
- backgroundColor: 'rgba(139, 92, 246, 0.1)',
- borderWidth: 2,
- tension: 0.3,
- fill: true,
- hidden: true
- }
- ]
- },
- options: {
- responsive: true,
- maintainAspectRatio: false,
- plugins: {
- legend: {
- display: false
- },
- tooltip: {
- mode: 'index',
- intersect: false
- }
- },
- scales: {
- x: {
- grid: {
- display: false
- }
- },
- y: {
- grid: {
- color: 'rgba(0, 0, 0, 0.05)'
- },
- beginAtZero: false
- }
- }
- }
- });
-
- // 指标选择事件处理
- document.getElementById('weather-chart-indicator').addEventListener('change', function() {
- const selectedValue = this.value;
-
- // 重置所有数据集的可见性
- if (selectedValue === 'all') {
- weatherChart.data.datasets[0].hidden = false;
- weatherChart.data.datasets[1].hidden = false;
- weatherChart.data.datasets[2].hidden = true;
- weatherChart.data.datasets[3].hidden = true;
- } else {
- weatherChart.data.datasets[0].hidden = selectedValue !== 'temperature';
- weatherChart.data.datasets[1].hidden = selectedValue !== 'humidity';
- weatherChart.data.datasets[2].hidden = selectedValue !== 'rainfall';
- weatherChart.data.datasets[3].hidden = selectedValue !== 'windspeed';
- }
-
- weatherChart.update();
- });
-
- // 时间范围按钮事件处理
- const weatherTimeRangeBtns = document.querySelectorAll('.weather-time-range-btn');
- weatherTimeRangeBtns.forEach(function(btn) {
- btn.addEventListener('click', function() {
- // 更新按钮样式
- weatherTimeRangeBtns.forEach(b => {
- b.classList.remove('bg-green-500', 'text-white');
- b.classList.add('bg-gray-200');
- });
- this.classList.remove('bg-gray-200');
- this.classList.add('bg-green-500', 'text-white');
-
- // 根据选择的时间范围更新图表数据
- const range = this.getAttribute('data-range');
- let newLabels = [];
- let newTempData = [];
- let newHumidityData = [];
- let newRainfallData = [];
- let newWindSpeedData = [];
-
- // 根据选择的时间范围生成新数据
- const now = new Date();
-
- if (range === '24h') {
- // 生成24小时的数据
- for (let i = 0; i < 24; i += 2) {
- const hour = i.toString().padStart(2, '0') + ':00';
- newLabels.push(hour);
-
- newTempData.push(Math.round((18 + Math.random() * 10) * 10) / 10);
- newHumidityData.push(Math.round((60 + Math.random() * 30) * 10) / 10);
- newRainfallData.push(Math.round(Math.random() * 5 * 10) / 10);
- newWindSpeedData.push(Math.round((1 + Math.random() * 4) * 10) / 10);
- }
- } else if (range === '30d') {
- // 生成30天的数据
- for (let i = 29; i >= 0; i -= 2) {
- const date = new Date(now);
- date.setDate(date.getDate() - i);
- newLabels.push(`${date.getMonth() + 1}/${date.getDate()}`);
-
- newTempData.push(Math.round((18 + Math.random() * 10) * 10) / 10);
- newHumidityData.push(Math.round((60 + Math.random() * 30) * 10) / 10);
- newRainfallData.push(Math.round(Math.random() * 15 * 10) / 10);
- newWindSpeedData.push(Math.round((1 + Math.random() * 4) * 10) / 10);
- }
- } else {
- // 7天的数据
- for (let i = 6; i >= 0; i--) {
- const date = new Date(now);
- date.setDate(date.getDate() - i);
- newLabels.push(`${date.getMonth() + 1}/${date.getDate()}`);
-
- newTempData.push(Math.round((18 + Math.random() * 10) * 10) / 10);
- newHumidityData.push(Math.round((60 + Math.random() * 30) * 10) / 10);
- newRainfallData.push(Math.round(Math.random() * 10 * 10) / 10);
- newWindSpeedData.push(Math.round((1 + Math.random() * 4) * 10) / 10);
- }
- }
-
- // 更新图表数据
- weatherChart.data.labels = newLabels;
- weatherChart.data.datasets[0].data = newTempData;
- weatherChart.data.datasets[1].data = newHumidityData;
- weatherChart.data.datasets[2].data = newRainfallData;
- weatherChart.data.datasets[3].data = newWindSpeedData;
- weatherChart.update();
- });
- });
-
- return weatherChart;
- };
- });
- </script>
- </body>
- </html>
|