From 584ef677c895482785c54be32f9e41012abed0e0 Mon Sep 17 00:00:00 2001 From: xiaji Date: Tue, 19 May 2026 14:57:53 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E7=A7=BB=E9=99=A4Swagger/Redoc;=20?= =?UTF-8?q?=E9=A6=96=E9=A1=B5=E6=8C=89=E5=8C=BA=E5=9F=9F=E5=88=86=E5=9D=97?= =?UTF-8?q?=E6=98=BE=E7=A4=BA=E8=AE=BE=E5=A4=87=E6=B8=85=E5=8D=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- config/settings.py | 12 - config/urls.py | 20 -- .../templates/device_management/index.html | 334 +++++++----------- device_management/views.py | 38 +- requirements.txt | 21 +- 5 files changed, 172 insertions(+), 253 deletions(-) diff --git a/config/settings.py b/config/settings.py index 52582b1..401eb8d 100644 --- a/config/settings.py +++ b/config/settings.py @@ -30,7 +30,6 @@ INSTALLED_APPS = [ 'rest_framework', 'rest_framework_simplejwt', 'django_filters', - 'drf_yasg', 'device_management', ] @@ -119,17 +118,6 @@ REST_FRAMEWORK = { 'PAGE_SIZE': 20, } -SWAGGER_SETTINGS = { - 'SECURITY_DEFINITIONS': { - 'Bearer': { - 'type': 'apiKey', - 'name': 'Authorization', - 'in': 'header' - } - }, - 'USE_SESSION_AUTH': True, -} - from datetime import timedelta SIMPLE_JWT = { diff --git a/config/urls.py b/config/urls.py index 0c9e1bc..e18d5f1 100644 --- a/config/urls.py +++ b/config/urls.py @@ -6,10 +6,6 @@ from django.urls import path, include from django.conf import settings from django.conf.urls.static import static -from rest_framework import permissions -from drf_yasg.views import get_schema_view -from drf_yasg import openapi - from rest_framework_simplejwt.views import ( TokenObtainPairView, TokenRefreshView, @@ -17,19 +13,6 @@ from rest_framework_simplejwt.views import ( from device_management.views import home_page -schema_view = get_schema_view( - openapi.Info( - title="视频主设备管理系统 API", - default_version='v1', - description="视频编码器、解码器、矩阵、NVR等设备管理系统API文档", - terms_of_service="https://www.example.com/terms/", - contact=openapi.Contact(email="contact@example.com"), - license=openapi.License(name="BSD License"), - ), - public=True, - permission_classes=(permissions.AllowAny,), -) - urlpatterns = [ path('', home_page, name='home'), path('admin/', admin.site.urls), @@ -37,7 +20,4 @@ urlpatterns = [ path('api/token/', TokenObtainPairView.as_view(), name='token_obtain_pair'), path('api/token/refresh/', TokenRefreshView.as_view(), name='token_refresh'), path('api-auth/', include('rest_framework.urls')), - path('swagger/', schema_view.without_ui(cache_timeout=0), name='schema-json'), - path('swagger/', schema_view.with_ui('swagger', cache_timeout=0), name='schema-swagger-ui'), - path('redoc/', schema_view.with_ui('redoc', cache_timeout=0), name='schema-redoc'), ] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT) diff --git a/device_management/templates/device_management/index.html b/device_management/templates/device_management/index.html index 4e1ec9a..6904a01 100644 --- a/device_management/templates/device_management/index.html +++ b/device_management/templates/device_management/index.html @@ -6,243 +6,163 @@ 视频主设备管理系统 -
-
+
-
- +
+

视频主设备管理系统

-

Device Management System · RESTful API Service

+

Device Management System

-
- - 服务运行中 +
+ 后台管理 + API +
+ + 运行中 +
- -
- -
-
-
-
- - - -
- 核心 -
-

设备管理

-

全生命周期设备资产库

+
+ +
+
+

{{ total_count }}

+

设备总数

- -
-
-
- - - -
- 网络 -
-

IP/序列号管理

-

唯一性校验防止冲突

+
+

{{ status_counts.normal }}

+

正常运行

- -
-
-
- - - - -
- 运维 -
-

维修/巡检追踪

-

历史可追溯保修预警

+
+

{{ status_counts.warning }}

+

告警

- -
-
-
- - - -
- 数据 -
-

Excel导入导出

-

批量数据高效管理

+
+

{{ status_counts.offline }}

+

离线

+
+
+

{{ status_counts.repair }}

+

维修中

+
+
+

{{ warranty_expiring }}

+

保修即将到期

- - - - -
- -
-

- - 技术栈 -

-
-
- 后端框架 - Django 4.2 + DRF 3.15 -
-
- 身份认证 - JWT Token + Session -
-
- 图片处理 - Pillow (自动缩略图) -
-
- Excel处理 - openpyxl + pandas -
-
- 日志系统 - loguru + + {% if devices_by_location %} + {% for location, devices in devices_by_location.items %} +
+
+
+ +

{{ location }}

+ {{ devices|length }} 台
-
- - -
-

- - API 端点 -

-
-
- GET - /api/devices/ - 设备列表 -
-
- POST - /api/devices/ - 创建设备 -
-
- GET - /api/devices/{id}/ - 设备详情 -
-
- GET - /api/devices/export_excel/ - 导出Excel -
-
- POST - /api/devices/import_excel/ - 导入Excel -
-
- POST - /api/token/ - JWT认证 -
+
+ + + + + + + + + + + + + + + {% for device in devices %} + + + + + + + + + + + {% endfor %} + +
设备名称型号楼栋/机柜主IP主序列号状态负责人服役天数
+
{{ device.device_name }}
+
{{ device.brand|default:"" }}
+
{{ device.model|default:"-" }} + {{ device.building|default:"-" }} + {% if device.cabinet %} / {{ device.cabinet }}{% endif %} + {% if device.floor %} {{ device.floor }}{% endif %} + + {% with primary_ip=device.ips.all|first %} + {% if primary_ip and primary_ip.is_primary %} + {{ primary_ip.ip_address }} + {% else %} + {% for ip in device.ips.all %} + {% if ip.is_primary %} + {{ ip.ip_address }} + {% endif %} + {% empty %} + - + {% endfor %} + {% endif %} + {% endwith %} + + {% for serial in device.serials.all %} + {% if serial.is_primary %} + {{ serial.serial_number }} + {% endif %} + {% empty %} + - + {% endfor %} + + + {{ device.get_status_display }} + + {{ device.responsible_person|default:"-" }}{{ device.service_duration_days }} 天
-
+ {% endfor %} + {% else %} +
+ + + +

暂无设备数据

+ 前往后台添加设备 → +
+ {% endif %}
- -