feat: testscan页面

This commit is contained in:
caoqianming 2025-03-25 16:04:52 +08:00
parent 8bf3ad06d6
commit 0c9c38890e
2 changed files with 35 additions and 1 deletions

View File

@ -1,5 +1,5 @@
from django.urls import path, include from django.urls import path, include
from apps.develop.views import BackupDatabase, BackupMedia, ReloadClientGit, ReloadServerGit, ReloadServerOnly, TestViewSet, CorrectViewSet from apps.develop.views import BackupDatabase, BackupMedia, ReloadClientGit, ReloadServerGit, ReloadServerOnly, TestViewSet, CorrectViewSet, testScanHtml
from rest_framework.routers import DefaultRouter from rest_framework.routers import DefaultRouter
API_BASE_URL = 'api/develop/' API_BASE_URL = 'api/develop/'
@ -15,4 +15,5 @@ urlpatterns = [
path(API_BASE_URL + 'backup_database/', BackupDatabase.as_view()), path(API_BASE_URL + 'backup_database/', BackupDatabase.as_view()),
path(API_BASE_URL + 'backup_media/', BackupMedia.as_view()), path(API_BASE_URL + 'backup_media/', BackupMedia.as_view()),
path(API_BASE_URL, include(router.urls)), path(API_BASE_URL, include(router.urls)),
path(HTML_BASE_URL + "testscan/", testScanHtml)
] ]

View File

@ -35,6 +35,7 @@ from apps.utils.snowflake import idWorker
from django.core.cache import cache from django.core.cache import cache
import json import json
from apps.utils.decorators import auto_log, idempotent from apps.utils.decorators import auto_log, idempotent
from django.http import HttpResponse
# Create your views here. # Create your views here.
@ -643,3 +644,35 @@ class TestViewSet(CustomGenericViewSet):
from apps.wpm.tasks import cal_exp_duration_sec from apps.wpm.tasks import cal_exp_duration_sec
cal_exp_duration_sec('3397169058570170368') cal_exp_duration_sec('3397169058570170368')
return Response() return Response()
html_str = """
<!DOCTYPE html>
<html lang="zh">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>WebView 扫码</title>
</head>
<body>
<button onclick="openScanner()">扫码</button>
<p>扫描结果: <span id="result"></span></p>
<script>
function openScanner() {
if (window.Android) {
window.Android.openScanner();
} else {
alert("当前环境不支持扫码");
}
}
function onScanResult(data) {
document.getElementById("result").innerText = data;
}
</script>
</body>
</html>
"""
def testScanHtml(request):
return HttpResponse(html_str)