| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968 |
- <!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="devicePlot">
- <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>
- <div class="grid-2">
- <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 class="form-group">
- <label class="form-label">设备型号</label>
- <input type="text" class="form-input" id="deviceModel" placeholder="输入设备型号">
- </div>
- </div>
- <div class="grid-2">
- <div class="form-group">
- <label class="form-label">厂家</label>
- <input type="text" class="form-input" id="deviceManufacturer" placeholder="输入厂家名称">
- </div>
- <div class="form-group">
- <label class="form-label">安装日期</label>
- <input type="date" class="form-input" id="installDate">
- </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>
-
- <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 devicePlotSelect = document.getElementById('devicePlot');
- Array.from(devicePlotSelect.options).forEach(option => {
- if (option.text === cells[3].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);
- });
- });
-
- // 日期格式化工具函数(将 "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');
- alert('查看设备详情:' + deviceId);
- // 这里可以跳转到设备详情页面
- });
- });
- // 删除按钮点击事件
- 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('设备已成功删除');
- });
- </script>
- </body>
- </html>
|