Commit 6d6c3ac1 by qianmo

Merge branch 'main' into fh

# Conflicts:
#	chat/consumers.py
#	frontend/handleHTML.js
#	frontend/package.json
#	frontend/src/App.vue
#	frontend/yarn.lock
#	mqtt/mqtt.py
parents 6f9d794f 16410aef
__pycache__
*.pyc
.idea
assets
......@@ -73,8 +73,8 @@ class ChatConsumer(AsyncWebsocketConsumer):
# Receive message from room group
async def chat_message(self, event):
message = event["message"]
# Send message to WebSocket
print(message)
await self.send(text_data=json.dumps({"message": message}))
# await self.send(bytes_data=message)
......
......@@ -21,7 +21,7 @@ class TableSoftLimitAngleSerializer(ModelSerializer):
"""
当传过来的值为 none 时,则在数据库里存一个空值
@param value: 通过基本校验之后的值
:param value: 通过基本校验之后的值
"""
if value == "none":
return ""
......@@ -38,7 +38,7 @@ class TableXproAllDevinfoSerializer(ModelSerializer):
"""
当传过来的值为 none 时,则在数据库里存一个空值
@param value: 通过基本校验之后的值
:param value: 通过基本校验之后的值
"""
if value == "none":
return ""
......@@ -49,7 +49,7 @@ class TableXproAllDevinfoSerializer(ModelSerializer):
校验字段,在进行基础校验之后,如果字段名称为下面的字段,
且当传过来的值为 none 时,存一个空值
@param attrs: 通过基本校验之后的值
:param attrs: 通过基本校验之后的值
"""
for field_name, value in attrs.items():
if field_name in (['cmd_excel_path', 'udp_ip_src', 'udp_ip_dst',
......
......@@ -17,6 +17,22 @@ class TableAllDevCmdDefineView(ModelViewSet):
data = tree_data(serializer.data, 'cmd_name')
return Response(data)
def perform_destroy(self, instance):
"""
删除某个字段,需要将字段的 index 更新
"""
# 获取改字段的 cmd_name
cmd_name = instance.cmd_name
super().perform_destroy(instance)
fields = self.get_queryset().filter(cmd_name=cmd_name).all()
# 更新字段的 index
for i in range(len(fields)):
print(fields[i])
fields[i].fieldindex = i + 1
fields[i].save()
class TableDevCmdNamePollView(ModelViewSet):
queryset = TableDevCmdNamePoll.objects.all()
......
from django.contrib import admin
# Register your models here.
from django.apps import AppConfig
class DownloadDbConfig(AppConfig):
default_auto_field = 'django.db.models.BigAutoField'
name = 'download_db'
from django.urls import path
from . import views
urlpatterns = [
path('downloadFile/', views.index),
]
from django.conf import settings
from django.http import FileResponse, HttpResponse
from rest_framework import status
import os
def index(request):
file_path = os.path.join(settings.BASE_DIR, 'xdc.sqlite')
print(f"file path => {file_path}")
if os.path.exists(file_path):
response = FileResponse(open(file_path, 'rb'))
response['Content-Disposition'] = 'inline; filename=' + os.path.basename(file_path)
response['Content-Type'] = 'application/x-sqlite3'
return response
return HttpResponse(status=status.HTTP_404_NOT_FOUND)
<script setup lang="ts">
import { ref, watch, onMounted } from 'vue';
import { ref, onMounted, watch } from 'vue';
import { ElScrollbar, ElInput, ElButton } from 'element-plus';
import { load } from 'protobufjs';
const innerRef = ref<HTMLDivElement>();
const scrollbarRef = ref<InstanceType<typeof ElScrollbar>>();
......@@ -30,24 +29,6 @@ const send = () => {
input.value = '';
}
const test = () => {
load([
"../proto/TDSCmd.proto",
"../proto/OAM_datastruct.proto",
"../proto/Device_datastruct.proto",
], (error: any, root: any) => {
if (error) {
throw error
}
console.log(root)
let cmd = root.lookupType('TDSCmd');
console.log(cmd);
});
}
watch(flag, () => {
setTimeout(() => {
scrollbarRef.value!.setScrollTop(innerRef.value!.offsetHeight);
......@@ -62,8 +43,8 @@ onMounted(() => {
);
chatSocket.onmessage = (e) => {
// console.log(e);
// console.log(e.data)
console.log(e);
console.log(e.data)
// // 接收到的是字节流数据(ArrayBuffer)
// const byteArray = new Uint8Array(e.data);
// // 将字节流转换为字符串或其他格式进行处理
......@@ -90,9 +71,8 @@ onMounted(() => {
</el-scrollbar>
<el-input v-model="input" placeholder="Please input" @keyup.enter="send"></el-input>
<el-button mt-10 @click="send">Send</el-button>
<el-button @click="send">Send</el-button>
<br/>
<el-button mt-10 @click="test">test</el-button>
</template>
<style scoped>
......
<script setup lang="ts">
import { ElButton } from 'element-plus';
import axiox from 'axios';
const downloadFile = () => {
let url = '/api/downloadFile/'
axiox({
url,
method: 'GET',
responseType: 'blob'
}).then(res => {
// 下载文件
console.log(res)
const blob = new Blob([res.data], { type: 'application/x-sqlite3' });
const link = document.createElement('a');
link.href = window.URL.createObjectURL(blob);
link.download = 'xdc.sqlite';
link.click();
})
console.log('downloadFile');
}
</script>
<template>
<ElButton type="primary" @click="downloadFile">导出文件</ElButton>
</template>
\ No newline at end of file
......@@ -31,10 +31,8 @@ def on_message(mqtt_client, userdata, msg):
# print(f'Received message on topic: {msg.topic} with payload: {msg.payload}')
# data = parse_proto(msg.payload)
data = msg.payload.decode('utf-8')
if data[0] == '0':
send_websocket_message(data)
else:
send_websocket_message(data, "chat_123")
client = mqtt.Client()
client.on_connect = on_connect
......
......@@ -49,20 +49,11 @@ class CurrentDevVersion(models.Model):
db_table = 'CurrentDevVersion'
class AllProtocolChangeLog(models.Model):
id = models.AutoField(primary_key=True) # Field name made lowercase.
protocol_name = models.TextField() # Field name made lowercase.
log = models.TextField()
class Meta:
db_table = 'AllProtocolChangeLog'
class Test(models.Model):
class AllProtocolVersion(models.Model):
id = models.AutoField(primary_key=True)
json = models.TextField()
protocol_name = models.TextField()
vesrions_path = models.TextField()
class Meta:
db_table = 'Test'
db_table = 'AllProtocolVersion'
import mimetypes
mimetypes.add_type("text/css", ".css", True)
mimetypes.add_type("text/javascript", ".js", True)
......@@ -132,7 +132,8 @@ USE_TZ = True
STATIC_URL = '/assets/'
STATIC_ROOT = os.path.join(BASE_DIR, 'assets')
STATICFILES_DIRS = [
os.path.join(BASE_DIR, 'frontend', 'dist', 'assets')
os.path.join(BASE_DIR, 'frontend', 'dist', 'assets'),
os.path.join(BASE_DIR, 'frontend', 'dist'),
]
......
......@@ -17,6 +17,9 @@ from django.contrib import admin
from django.urls import path, include, re_path
from .views import index, test
from django.conf import settings
from django.views.static import serve
from drf_yasg.views import get_schema_view
from drf_yasg import openapi
......@@ -36,6 +39,10 @@ urlpatterns = [
path("mqtt/", include("mqtt.urls")),
path("chat/", include("chat.urls")),
path("op/", include("device_data_op.urls")),
path("api/", include("download_db.urls")),
re_path(r'^assets/(?P<path>.*)/$', serve, {'document_root': settings.STATIC_ROOT}),
re_path(r'^swagger/$', schema_view.with_ui('swagger', cache_timeout=0), name='schema-swagger-ui'),
]
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment