device-management.html 38 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968
  1. <!DOCTYPE html>
  2. <html lang="zh-CN">
  3. <head>
  4. <meta charset="UTF-8">
  5. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  6. <title>设备管理列表 - 爱智农</title>
  7. <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/tailwindcss@2.2.19/dist/tailwind.min.css">
  8. <link rel="stylesheet" href="https://at.alicdn.com/t/font_3114978_qe0b39no76.css">
  9. <link rel="stylesheet" href="../assets/css/global.css">
  10. <style>
  11. :root {
  12. --primary: #4CAF50;
  13. --primary-dark: #388E3C;
  14. --primary-light: #A5D6A7;
  15. --primary-bg: #F1F8E9;
  16. --success: #4CAF50;
  17. --warning: #FFC107;
  18. --danger: #F44336;
  19. --info: #2196F3;
  20. --disabled: #9E9E9E;
  21. --border: #E0E0E0;
  22. --text-primary: #212121;
  23. --text-secondary: #757575;
  24. --radius: 8px;
  25. }
  26. body {
  27. font-family: "PingFang SC", "Microsoft YaHei", sans-serif;
  28. background-color: #f5f7f9;
  29. color: var(--text-primary);
  30. margin: 0;
  31. padding: 0;
  32. min-height: 100vh;
  33. padding-top: 70px; /* 确保内容不被系统导航栏遮挡 */
  34. }
  35. .page-container {
  36. padding: 20px;
  37. position: relative;
  38. min-height: 100vh;
  39. width: 100%;
  40. max-width: 1400px;
  41. margin: 0 auto;
  42. box-sizing: border-box;
  43. }
  44. .card {
  45. background-color: white;
  46. border-radius: 8px;
  47. box-shadow: 0 2px 8px rgba(0,0,0,0.05);
  48. margin-bottom: 20px;
  49. }
  50. .table-container {
  51. position: relative;
  52. position: relative;
  53. overflow-x: auto;
  54. position: relative;
  55. }
  56. table {
  57. width: 100%;
  58. border-collapse: separate;
  59. border-spacing: 0;
  60. }
  61. th {
  62. white-space: nowrap;
  63. position: relative;
  64. overflow: visible;
  65. max-width: none;
  66. text-overflow: clip;
  67. white-space: nowrap;
  68. position: relative;
  69. background-color: #f9fafb;
  70. padding: 12px 16px;
  71. text-align: left;
  72. font-weight: 500;
  73. color: #6b7280;
  74. border-bottom: 1px solid #e5e7eb;
  75. white-space: nowrap;
  76. position: relative;
  77. }
  78. td {
  79. white-space: nowrap;
  80. max-width: 200px;
  81. overflow: hidden;
  82. text-overflow: ellipsis;
  83. white-space: nowrap;
  84. max-width: 200px;
  85. overflow: hidden;
  86. text-overflow: ellipsis;
  87. padding: 12px 16px;
  88. border-bottom: 1px solid #e5e7eb;
  89. white-space: nowrap;
  90. max-width: 200px;
  91. overflow: hidden;
  92. text-overflow: ellipsis;
  93. }
  94. /* 固定最后一列(操作列)样式 */
  95. .table-fixed-right {
  96. position: relative;
  97. }
  98. .table-fixed-right th:last-child,
  99. .table-fixed-right td:last-child {
  100. position: sticky;
  101. right: 0;
  102. z-index: 2;
  103. background-color: white;
  104. box-shadow: -5px 0 5px -5px rgba(0, 0, 0, 0.1);
  105. }
  106. .table-fixed-right th:last-child {
  107. background-color: #f9fafb;
  108. }
  109. /* 表格滚动控件 */
  110. .table-scroll-controls {
  111. display: none;
  112. position: absolute;
  113. top: 50%;
  114. transform: translateY(-50%);
  115. width: 100%;
  116. pointer-events: none;
  117. z-index: 3;
  118. }
  119. .table-scroll-btn {
  120. position: absolute;
  121. width: 32px;
  122. height: 32px;
  123. border-radius: 50%;
  124. background-color: rgba(255, 255, 255, 0.9);
  125. color: #4CAF50;
  126. border: 1px solid #e0e0e0;
  127. display: flex;
  128. align-items: center;
  129. justify-content: center;
  130. cursor: pointer;
  131. pointer-events: auto;
  132. box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
  133. z-index: 4;
  134. }
  135. .table-scroll-left {
  136. left: 10px;
  137. }
  138. .table-scroll-right {
  139. right: 10px;
  140. }
  141. .has-overflow .table-scroll-controls {
  142. display: block;
  143. }
  144. tr:hover {
  145. background-color: #f9fafb;
  146. }
  147. tr:hover td:last-child {
  148. background-color: #f9fafb;
  149. }
  150. .btn {
  151. display: inline-flex;
  152. align-items: center;
  153. justify-content: center;
  154. padding: 8px 16px;
  155. border-radius: 4px;
  156. font-weight: 500;
  157. cursor: pointer;
  158. transition: all 0.2s;
  159. }
  160. .btn-primary {
  161. background-color: #4CAF50;
  162. color: white;
  163. }
  164. .btn-primary:hover {
  165. background-color: #388E3C;
  166. }
  167. .btn-default {
  168. background-color: white;
  169. border: 1px solid #d1d5db;
  170. color: #374151;
  171. }
  172. .btn-default:hover {
  173. background-color: #f9fafb;
  174. }
  175. .btn-sm {
  176. padding: 4px 8px;
  177. font-size: 12px;
  178. }
  179. .search-box {
  180. display: flex;
  181. gap: 8px;
  182. }
  183. .input {
  184. padding: 8px 12px;
  185. border: 1px solid #d1d5db;
  186. border-radius: 4px;
  187. flex-grow: 1;
  188. }
  189. .select {
  190. padding: 8px 12px;
  191. border: 1px solid #d1d5db;
  192. border-radius: 4px;
  193. background-color: white;
  194. min-width: 120px;
  195. }
  196. .badge {
  197. display: inline-block;
  198. padding: 2px 8px;
  199. border-radius: 9999px;
  200. font-size: 12px;
  201. font-weight: 500;
  202. }
  203. .badge-success {
  204. background-color: #d1fae5;
  205. color: #065f46;
  206. }
  207. .badge-warning {
  208. background-color: #fef3c7;
  209. color: #92400e;
  210. }
  211. .badge-danger {
  212. background-color: #fee2e2;
  213. color: #b91c1c;
  214. }
  215. .page-header {
  216. display: flex;
  217. justify-content: space-between;
  218. align-items: center;
  219. margin-bottom: 20px;
  220. padding-bottom: 16px;
  221. border-bottom: 1px solid #e0e0e0;
  222. }
  223. .pagination {
  224. display: flex;
  225. align-items: center;
  226. justify-content: flex-end;
  227. gap: 4px;
  228. }
  229. .pagination-item {
  230. display: inline-flex;
  231. align-items: center;
  232. justify-content: center;
  233. width: 32px;
  234. height: 32px;
  235. border-radius: 4px;
  236. cursor: pointer;
  237. transition: all 0.2s;
  238. }
  239. .pagination-item:hover {
  240. background-color: #f3f4f6;
  241. }
  242. .pagination-item.active {
  243. background-color: #4CAF50;
  244. color: white;
  245. }
  246. .pagination-item.disabled {
  247. color: #9ca3af;
  248. cursor: not-allowed;
  249. }
  250. .modal-overlay {
  251. position: fixed;
  252. top: 0;
  253. left: 0;
  254. right: 0;
  255. bottom: 0;
  256. background-color: rgba(0, 0, 0, 0.5);
  257. display: flex;
  258. align-items: center;
  259. justify-content: center;
  260. z-index: 50;
  261. display: none;
  262. }
  263. .modal {
  264. background-color: white;
  265. border-radius: 8px;
  266. width: 100%;
  267. max-width: 600px;
  268. box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
  269. }
  270. .modal-header {
  271. padding: 16px 24px;
  272. border-bottom: 1px solid #e5e7eb;
  273. display: flex;
  274. align-items: center;
  275. justify-content: space-between;
  276. }
  277. .modal-title {
  278. font-size: 18px;
  279. font-weight: 500;
  280. }
  281. .modal-close {
  282. cursor: pointer;
  283. font-size: 20px;
  284. }
  285. .modal-body {
  286. padding: 24px;
  287. }
  288. .modal-footer {
  289. padding: 16px 24px;
  290. border-top: 1px solid #e5e7eb;
  291. display: flex;
  292. justify-content: flex-end;
  293. gap: 8px;
  294. }
  295. .form-group {
  296. margin-bottom: 16px;
  297. }
  298. .form-label {
  299. display: block;
  300. margin-bottom: 4px;
  301. font-weight: 500;
  302. }
  303. .form-input {
  304. width: 100%;
  305. padding: 8px 12px;
  306. border: 1px solid #d1d5db;
  307. border-radius: 4px;
  308. }
  309. .grid-2 {
  310. display: grid;
  311. grid-template-columns: 1fr 1fr;
  312. gap: 16px;
  313. }
  314. /* 搜索条件样式 */
  315. .filter-group {
  316. display: flex;
  317. flex-wrap: wrap;
  318. gap: 10px;
  319. margin-bottom: 15px;
  320. padding-bottom: 15px;
  321. border-bottom: 1px dashed #e5e7eb;
  322. }
  323. .filter-group:last-child {
  324. border-bottom: none;
  325. margin-bottom: 0;
  326. padding-bottom: 0;
  327. }
  328. .filter-item {
  329. display: flex;
  330. align-items: center;
  331. min-width: 180px;
  332. }
  333. .filter-label {
  334. color: #6b7280;
  335. font-size: 13px;
  336. min-width: 70px;
  337. }
  338. .date-filter {
  339. display: flex;
  340. align-items: center;
  341. }
  342. .date-filter input {
  343. width: 140px;
  344. }
  345. .filter-divider {
  346. color: #9ca3af;
  347. margin: 0 4px;
  348. }
  349. </style>
  350. </head>
  351. <body>
  352. <div class="page-container">
  353. <div class="page-header">
  354. <h1 class="text-2xl font-bold">设备管理列表</h1>
  355. <div class="flex gap-2">
  356. <button class="btn btn-primary" id="addDeviceBtn">
  357. <i class="iconfont icon-plus" style="margin-right: 4px;"></i>
  358. 新增设备
  359. </button>
  360. <button class="btn btn-default" id="importBtn">
  361. <i class="iconfont icon-upload" style="margin-right: 4px;"></i>
  362. 导入
  363. </button>
  364. <button class="btn btn-default" id="exportBtn">
  365. <i class="iconfont icon-download" style="margin-right: 4px;"></i>
  366. 导出
  367. </button>
  368. </div>
  369. </div>
  370. <div class="card p-6">
  371. <div class="filter-group">
  372. <div class="filter-item" style="min-width: 300px;">
  373. <span class="filter-label">设备编号:</span>
  374. <input type="text" class="input w-full" placeholder="请输入设备编号关键词">
  375. </div>
  376. <div class="filter-item" style="min-width: 300px;">
  377. <span class="filter-label">设备名称:</span>
  378. <input type="text" class="input w-full" placeholder="请输入设备名称关键词">
  379. </div>
  380. <div class="ml-auto">
  381. <button class="btn btn-primary">
  382. <i class="iconfont icon-search" style="margin-right: 4px;"></i>
  383. 搜索
  384. </button>
  385. <button class="btn btn-default ml-2">
  386. <i class="iconfont icon-reload" style="margin-right: 4px;"></i>
  387. 重置
  388. </button>
  389. </div>
  390. </div>
  391. <div class="filter-group">
  392. <div class="filter-item">
  393. <span class="filter-label">设备类型:</span>
  394. <select class="select">
  395. <option value="">全部</option>
  396. <option value="sensor">传感器</option>
  397. <option value="camera">摄像头</option>
  398. <option value="controller">控制器</option>
  399. <option value="weather">气象设备</option>
  400. </select>
  401. </div>
  402. <div class="filter-item">
  403. <span class="filter-label">所属农场:</span>
  404. <select class="select">
  405. <option value="">全部</option>
  406. <option value="east">东区智慧农场</option>
  407. <option value="west">西区智慧农场</option>
  408. <option value="south">南区智慧农场</option>
  409. <option value="center">中心监测农场</option>
  410. </select>
  411. </div>
  412. <div class="filter-item">
  413. <span class="filter-label">所属地块:</span>
  414. <select class="select">
  415. <option value="">全部</option>
  416. <option value="a-3">A区大棚3号</option>
  417. <option value="a-1">A区大棚1号</option>
  418. <option value="b-2">B区稻田2号</option>
  419. <option value="c-1">C区果园1号</option>
  420. <option value="m-1">监测区1号</option>
  421. </select>
  422. </div>
  423. <div class="filter-item">
  424. <span class="filter-label">设备状态:</span>
  425. <select class="select">
  426. <option value="">全部</option>
  427. <option value="1">在线</option>
  428. <option value="0">离线</option>
  429. <option value="2">故障</option>
  430. <option value="3">维护中</option>
  431. </select>
  432. </div>
  433. </div>
  434. </div>
  435. <div class="card">
  436. <div class="table-container">
  437. <div class="table-scroll-controls">
  438. <button class="table-scroll-btn table-scroll-left">
  439. <i class="iconfont icon-left"></i>
  440. </button>
  441. <button class="table-scroll-btn table-scroll-right">
  442. <i class="iconfont icon-right"></i>
  443. </button>
  444. </div>
  445. <table class="table-fixed-right">
  446. <thead>
  447. <tr>
  448. <th class="min-w-[120px]">设备编号</th>
  449. <th class="min-w-[120px]">设备名称</th>
  450. <th class="min-w-[100px]">设备类型</th>
  451. <th class="min-w-[120px]">所属地块</th>
  452. <th class="min-w-[120px]">所属农场</th>
  453. <th class="min-w-[100px]">设备型号</th>
  454. <th class="min-w-[100px]">厂家</th>
  455. <th class="min-w-[100px]">安装日期</th>
  456. <th class="min-w-[80px]">状态</th>
  457. <th class="min-w-[150px]">最后活动时间</th>
  458. <th class="min-w-[150px]">操作</th>
  459. </tr>
  460. </thead>
  461. <tbody>
  462. <tr>
  463. <td>DEV20230001</td>
  464. <td>温湿度传感器-A1</td>
  465. <td>传感器</td>
  466. <td>A区大棚3号</td>
  467. <td>东区智慧农场</td>
  468. <td>TS-100A</td>
  469. <td>智农科技</td>
  470. <td>2023-01-15</td>
  471. <td><span class="badge badge-success">在线</span></td>
  472. <td>2023-10-15 14:30</td>
  473. <td>
  474. <div class="flex gap-2">
  475. <button class="btn btn-sm btn-default view-btn" data-id="DEV20230001">
  476. <i class="iconfont icon-eye"></i>
  477. 查看
  478. </button>
  479. <button class="btn btn-sm btn-default edit-btn" data-id="DEV20230001">
  480. <i class="iconfont icon-edit"></i>
  481. 编辑
  482. </button>
  483. <button class="btn btn-sm btn-default delete-btn" data-id="DEV20230001" style="color: #F44336;">
  484. <i class="iconfont icon-delete"></i>
  485. 删除
  486. </button>
  487. </div>
  488. </td>
  489. </tr>
  490. <tr>
  491. <td>DEV20230002</td>
  492. <td>土壤湿度检测仪-B1</td>
  493. <td>传感器</td>
  494. <td>B区稻田2号</td>
  495. <td>西区智慧农场</td>
  496. <td>SM-200B</td>
  497. <td>农达科技</td>
  498. <td>2023-02-20</td>
  499. <td><span class="badge badge-warning">离线</span></td>
  500. <td>2023-10-10 09:15</td>
  501. <td>
  502. <div class="flex gap-2">
  503. <button class="btn btn-sm btn-default view-btn" data-id="DEV20230002">
  504. <i class="iconfont icon-eye"></i>
  505. 查看
  506. </button>
  507. <button class="btn btn-sm btn-default edit-btn" data-id="DEV20230002">
  508. <i class="iconfont icon-edit"></i>
  509. 编辑
  510. </button>
  511. <button class="btn btn-sm btn-default delete-btn" data-id="DEV20230002" style="color: #F44336;">
  512. <i class="iconfont icon-delete"></i>
  513. 删除
  514. </button>
  515. </div>
  516. </td>
  517. </tr>
  518. <tr>
  519. <td>DEV20230003</td>
  520. <td>气象站-C1</td>
  521. <td>气象设备</td>
  522. <td>监测区1号</td>
  523. <td>中心监测农场</td>
  524. <td>WS-500C</td>
  525. <td>科沃电子</td>
  526. <td>2023-03-10</td>
  527. <td><span class="badge badge-success">在线</span></td>
  528. <td>2023-10-16 10:25</td>
  529. <td>
  530. <div class="flex gap-2">
  531. <button class="btn btn-sm btn-default view-btn" data-id="DEV20230003">
  532. <i class="iconfont icon-eye"></i>
  533. 查看
  534. </button>
  535. <button class="btn btn-sm btn-default edit-btn" data-id="DEV20230003">
  536. <i class="iconfont icon-edit"></i>
  537. 编辑
  538. </button>
  539. <button class="btn btn-sm btn-default delete-btn" data-id="DEV20230003" style="color: #F44336;">
  540. <i class="iconfont icon-delete"></i>
  541. 删除
  542. </button>
  543. </div>
  544. </td>
  545. </tr>
  546. <tr>
  547. <td>DEV20230004</td>
  548. <td>智能灌溉控制器-D1</td>
  549. <td>控制器</td>
  550. <td>C区果园1号</td>
  551. <td>南区智慧农场</td>
  552. <td>IC-300D</td>
  553. <td>水利通</td>
  554. <td>2023-04-05</td>
  555. <td><span class="badge badge-danger">故障</span></td>
  556. <td>2023-10-12 18:40</td>
  557. <td>
  558. <div class="flex gap-2">
  559. <button class="btn btn-sm btn-default view-btn" data-id="DEV20230004">
  560. <i class="iconfont icon-eye"></i>
  561. 查看
  562. </button>
  563. <button class="btn btn-sm btn-default edit-btn" data-id="DEV20230004">
  564. <i class="iconfont icon-edit"></i>
  565. 编辑
  566. </button>
  567. <button class="btn btn-sm btn-default delete-btn" data-id="DEV20230004" style="color: #F44336;">
  568. <i class="iconfont icon-delete"></i>
  569. 删除
  570. </button>
  571. </div>
  572. </td>
  573. </tr>
  574. <tr>
  575. <td>DEV20230005</td>
  576. <td>作物监控摄像头-E1</td>
  577. <td>摄像头</td>
  578. <td>A区大棚1号</td>
  579. <td>东区智慧农场</td>
  580. <td>CC-400E</td>
  581. <td>视界科技</td>
  582. <td>2023-05-20</td>
  583. <td><span class="badge badge-success">在线</span></td>
  584. <td>2023-10-16 11:05</td>
  585. <td>
  586. <div class="flex gap-2">
  587. <button class="btn btn-sm btn-default view-btn" data-id="DEV20230005">
  588. <i class="iconfont icon-eye"></i>
  589. 查看
  590. </button>
  591. <button class="btn btn-sm btn-default edit-btn" data-id="DEV20230005">
  592. <i class="iconfont icon-edit"></i>
  593. 编辑
  594. </button>
  595. <button class="btn btn-sm btn-default delete-btn" data-id="DEV20230005" style="color: #F44336;">
  596. <i class="iconfont icon-delete"></i>
  597. 删除
  598. </button>
  599. </div>
  600. </td>
  601. </tr>
  602. </tbody>
  603. </table>
  604. </div>
  605. <div class="p-4 border-t border-gray-200 flex justify-between items-center">
  606. <div class="text-sm text-gray-500">显示 1 至 5,共 24 条记录</div>
  607. <div class="pagination">
  608. <div class="pagination-item disabled">&lt;</div>
  609. <div class="pagination-item active">1</div>
  610. <div class="pagination-item">2</div>
  611. <div class="pagination-item">3</div>
  612. <div class="pagination-item">4</div>
  613. <div class="pagination-item">5</div>
  614. <div class="pagination-item">&gt;</div>
  615. </div>
  616. </div>
  617. </div>
  618. <!-- 设备表单弹窗 -->
  619. <div class="modal-overlay" id="deviceModal">
  620. <div class="modal">
  621. <div class="modal-header">
  622. <div class="modal-title">添加设备</div>
  623. <div class="modal-close" id="closeModal">&times;</div>
  624. </div>
  625. <div class="modal-body">
  626. <form id="deviceForm">
  627. <div class="grid-2">
  628. <div class="form-group">
  629. <label class="form-label">设备编号</label>
  630. <input type="text" class="form-input" id="deviceId" placeholder="输入设备编号">
  631. </div>
  632. <div class="form-group">
  633. <label class="form-label">设备名称</label>
  634. <input type="text" class="form-input" id="deviceName" placeholder="输入设备名称">
  635. </div>
  636. </div>
  637. <div class="grid-2">
  638. <div class="form-group">
  639. <label class="form-label">设备类型</label>
  640. <select class="form-input" id="deviceType">
  641. <option value="">请选择设备类型</option>
  642. <option value="sensor">传感器</option>
  643. <option value="camera">摄像头</option>
  644. <option value="controller">控制器</option>
  645. <option value="weather">气象设备</option>
  646. </select>
  647. </div>
  648. <div class="form-group">
  649. <label class="form-label">所属地块</label>
  650. <select class="form-input" id="devicePlot">
  651. <option value="">请选择所属地块</option>
  652. <option value="a-3">A区大棚3号</option>
  653. <option value="a-1">A区大棚1号</option>
  654. <option value="b-2">B区稻田2号</option>
  655. <option value="c-1">C区果园1号</option>
  656. <option value="m-1">监测区1号</option>
  657. </select>
  658. </div>
  659. </div>
  660. <div class="grid-2">
  661. <div class="form-group">
  662. <label class="form-label">所属农场</label>
  663. <select class="form-input" id="deviceFarm">
  664. <option value="">请选择所属农场</option>
  665. <option value="east">东区智慧农场</option>
  666. <option value="west">西区智慧农场</option>
  667. <option value="south">南区智慧农场</option>
  668. <option value="center">中心监测农场</option>
  669. </select>
  670. </div>
  671. <div class="form-group">
  672. <label class="form-label">设备型号</label>
  673. <input type="text" class="form-input" id="deviceModel" placeholder="输入设备型号">
  674. </div>
  675. </div>
  676. <div class="grid-2">
  677. <div class="form-group">
  678. <label class="form-label">厂家</label>
  679. <input type="text" class="form-input" id="deviceManufacturer" placeholder="输入厂家名称">
  680. </div>
  681. <div class="form-group">
  682. <label class="form-label">安装日期</label>
  683. <input type="date" class="form-input" id="installDate">
  684. </div>
  685. </div>
  686. <div class="form-group">
  687. <label class="form-label">设备描述</label>
  688. <textarea class="form-input" id="deviceDesc" rows="3" placeholder="输入设备描述"></textarea>
  689. </div>
  690. </form>
  691. </div>
  692. <div class="modal-footer">
  693. <button class="btn btn-default" id="cancelBtn">取消</button>
  694. <button class="btn btn-primary" id="saveBtn">保存</button>
  695. </div>
  696. </div>
  697. </div>
  698. <!-- 删除确认弹窗 -->
  699. <div class="modal-overlay" id="deleteModal">
  700. <div class="modal" style="max-width: 400px;">
  701. <div class="modal-header">
  702. <div class="modal-title">删除确认</div>
  703. <div class="modal-close" id="closeDeleteModal">&times;</div>
  704. </div>
  705. <div class="modal-body">
  706. <p class="mb-2">确定要删除该设备吗?</p>
  707. <p class="text-gray-500 text-sm">设备编号:<span id="deleteDeviceId"></span></p>
  708. <p class="text-gray-500 text-sm">设备名称:<span id="deleteDeviceName"></span></p>
  709. </div>
  710. <div class="modal-footer">
  711. <button class="btn btn-default" id="cancelDeleteBtn">取消</button>
  712. <button class="btn btn-danger" id="confirmDeleteBtn" style="background-color: #F44336; color: white;">确认删除</button>
  713. </div>
  714. </div>
  715. </div>
  716. </div>
  717. <script>
  718. // 添加设备按钮点击事件
  719. document.getElementById('addDeviceBtn').addEventListener('click', function() {
  720. document.getElementById('deviceModal').style.display = 'flex';
  721. });
  722. // 初始化表格滚动功能
  723. function initTableScroll() {
  724. const tableContainer = document.querySelector('.table-container');
  725. const scrollLeftBtn = document.querySelector('.table-scroll-left');
  726. const scrollRightBtn = document.querySelector('.table-scroll-right');
  727. // 检查表格是否需要水平滚动
  728. function checkTableOverflow() {
  729. if (tableContainer.scrollWidth > tableContainer.clientWidth) {
  730. tableContainer.classList.add('has-overflow');
  731. } else {
  732. tableContainer.classList.remove('has-overflow');
  733. }
  734. }
  735. // 左右滚动按钮点击事件
  736. scrollLeftBtn.addEventListener('click', function() {
  737. tableContainer.scrollLeft -= 150;
  738. });
  739. scrollRightBtn.addEventListener('click', function() {
  740. tableContainer.scrollLeft += 150;
  741. });
  742. // 初始检查和窗口大小变化时检查
  743. checkTableOverflow();
  744. window.addEventListener('resize', checkTableOverflow);
  745. // 滚动事件处理
  746. tableContainer.addEventListener('scroll', function() {
  747. // 根据滚动位置显示/隐藏滚动按钮
  748. if (tableContainer.scrollLeft <= 10) {
  749. scrollLeftBtn.style.opacity = '0.5';
  750. } else {
  751. scrollLeftBtn.style.opacity = '1';
  752. }
  753. if (tableContainer.scrollLeft >= tableContainer.scrollWidth - tableContainer.clientWidth - 10) {
  754. scrollRightBtn.style.opacity = '0.5';
  755. } else {
  756. scrollRightBtn.style.opacity = '1';
  757. }
  758. });
  759. // 初始触发滚动事件,设置初始按钮状态
  760. tableContainer.dispatchEvent(new Event('scroll'));
  761. }
  762. // 页面加载完成后初始化表格滚动
  763. window.addEventListener('load', initTableScroll);
  764. // 关闭模态框
  765. document.getElementById('closeModal').addEventListener('click', function() {
  766. document.getElementById('deviceModal').style.display = 'none';
  767. });
  768. // 取消按钮点击事件
  769. document.getElementById('cancelBtn').addEventListener('click', function() {
  770. document.getElementById('deviceModal').style.display = 'none';
  771. });
  772. // 保存按钮点击事件
  773. document.getElementById('saveBtn').addEventListener('click', function() {
  774. alert('设备信息已保存');
  775. document.getElementById('deviceModal').style.display = 'none';
  776. });
  777. // 编辑按钮点击事件
  778. const editBtns = document.querySelectorAll('.edit-btn');
  779. editBtns.forEach(function(btn) {
  780. btn.addEventListener('click', function() {
  781. const deviceId = this.getAttribute('data-id');
  782. document.getElementById('deviceModal').style.display = 'flex';
  783. document.querySelector('.modal-title').textContent = '编辑设备';
  784. // 根据表格行数据填充表单
  785. const row = this.closest('tr');
  786. const cells = row.querySelectorAll('td');
  787. // 填充表单字段
  788. document.getElementById('deviceId').value = cells[0].textContent;
  789. document.getElementById('deviceName').value = cells[1].textContent;
  790. // 设备类型
  791. const deviceTypeSelect = document.getElementById('deviceType');
  792. Array.from(deviceTypeSelect.options).forEach(option => {
  793. if (option.text === cells[2].textContent) {
  794. option.selected = true;
  795. }
  796. });
  797. // 所属地块
  798. const devicePlotSelect = document.getElementById('devicePlot');
  799. Array.from(devicePlotSelect.options).forEach(option => {
  800. if (option.text === cells[3].textContent) {
  801. option.selected = true;
  802. }
  803. });
  804. // 所属农场
  805. const deviceFarmSelect = document.getElementById('deviceFarm');
  806. Array.from(deviceFarmSelect.options).forEach(option => {
  807. if (option.text === cells[4].textContent) {
  808. option.selected = true;
  809. }
  810. });
  811. // 设备型号、厂家、安装日期
  812. document.getElementById('deviceModel').value = cells[5].textContent;
  813. document.getElementById('deviceManufacturer').value = cells[6].textContent;
  814. document.getElementById('installDate').value = formatDateForInput(cells[7].textContent);
  815. });
  816. });
  817. // 日期格式化工具函数(将 "YYYY-MM-DD" 格式化为 date input 所需格式)
  818. function formatDateForInput(dateString) {
  819. // 假设输入格式为 "YYYY-MM-DD"
  820. // HTML date input 也使用 "YYYY-MM-DD" 格式,所以可以直接返回
  821. return dateString;
  822. }
  823. // 查看按钮点击事件
  824. const viewBtns = document.querySelectorAll('.view-btn');
  825. viewBtns.forEach(function(btn) {
  826. btn.addEventListener('click', function() {
  827. const deviceId = this.getAttribute('data-id');
  828. alert('查看设备详情:' + deviceId);
  829. // 这里可以跳转到设备详情页面
  830. });
  831. });
  832. // 删除按钮点击事件
  833. const deleteBtns = document.querySelectorAll('.delete-btn');
  834. deleteBtns.forEach(function(btn) {
  835. btn.addEventListener('click', function() {
  836. const deviceId = this.getAttribute('data-id');
  837. const row = this.closest('tr');
  838. const cells = row.querySelectorAll('td');
  839. // 显示删除确认弹窗
  840. document.getElementById('deleteDeviceId').textContent = cells[0].textContent;
  841. document.getElementById('deleteDeviceName').textContent = cells[1].textContent;
  842. document.getElementById('deleteModal').style.display = 'flex';
  843. // 保存当前行引用,用于确认删除时使用
  844. document.getElementById('confirmDeleteBtn').setAttribute('data-row', row.rowIndex);
  845. });
  846. });
  847. // 关闭删除确认弹窗
  848. document.getElementById('closeDeleteModal').addEventListener('click', function() {
  849. document.getElementById('deleteModal').style.display = 'none';
  850. });
  851. // 取消删除
  852. document.getElementById('cancelDeleteBtn').addEventListener('click', function() {
  853. document.getElementById('deleteModal').style.display = 'none';
  854. });
  855. // 确认删除
  856. document.getElementById('confirmDeleteBtn').addEventListener('click', function() {
  857. const rowIndex = this.getAttribute('data-row');
  858. const table = document.querySelector('tbody');
  859. const rowToDelete = table.rows[rowIndex-1]; // -1 因为 rowIndex 是从 1 开始计数的
  860. if (rowToDelete) {
  861. rowToDelete.remove();
  862. }
  863. document.getElementById('deleteModal').style.display = 'none';
  864. // 显示删除成功提示
  865. alert('设备已成功删除');
  866. });
  867. </script>
  868. </body>
  869. </html>