Commit 3e57e0f6 by 周田

perf:优化请求次数,修复一些小问题

parent 32693b81
......@@ -3,7 +3,7 @@
<div class="container">
<div class="left">
<div class="mr-4">协议版本</div>
<el-select v-model="value">
<el-select v-model="currentVersion">
<!-- TODO: 选择协议版本 -->
<el-option
v-for="option in options"
......@@ -77,14 +77,18 @@
<script setup lang="ts">
import { ref,onMounted } from 'vue'
import { ElMessage, ElMessageBox } from "element-plus";
import { GetProtocolVersion,ProtocolInit } from "@/dao/protocol"
import { ProtocolInit } from "@/dao/protocol"
import ProtocolTable from "./ProtocolTable.vue";
import type { DeviceProtocolResponse, ProtocolCmdResponse } from './types';
import { useProtocolVersionStore } from '@/stores/allProtocolVersion';
const addCmd = ref<boolean>(false)
const value = ref('')
const options = ref<Array>([])
const protocol_names = ref<Array>([])
const currentVersion = ref('')
type OptionType = {
value: string
label: string
}
const options = ref<OptionType[]>([])
const formLabelWidth = '140px'
type propsType = {
......@@ -118,37 +122,46 @@ const open = () => {
})
}
async function getVersion(){
await GetProtocolVersion()
.then((res) => {
for (const item of res){
protocol_names.value.push(item.protocol_name)
if (item.protocol_name === props.name){
let version_paths = JSON.parse(item.version_paths)
for (const item2 of version_paths){
options.value.push({value: item2.version, label: item2.version})
}
}
}
})
.catch((err) => {
console.log(err);
})
}
function Init(){
ProtocolInit({protocol_name: props.name})
.then((res) => {
.then((_) => {
options.value.push({value: "init", label: "init"})
currentVersion.value = "init"
})
.catch((err) => {
console.log(err);
})
}
onMounted(async () => {
await getVersion()
if (protocol_names.value.indexOf(props.name) === -1){
const store = useProtocolVersionStore()
onMounted(() => {
// 判断是否需要初始化
let flag = true
for (let protocolVersion of store.protocolVersions){
if (protocolVersion.protocol_name === props.name) {
let version_paths = JSON.parse(protocolVersion.version_paths)
for (let version_path of version_paths){
options.value.push({value: version_path.version, label: version_path.version})
}
flag = false
break
}
}
if (!flag) {
for (let item of store.currentVersions){
if (item.protocol_name === props.name) {
currentVersion.value = item.version
}
}
}
// 如果需要初始化
if (flag){
Init()
}
})
......
import axios from "axios"
const baseURL = 'http://192.168.0.214:8000/op'
// const baseURL = 'http://192.168.0.214:8000/op'
export function GetProtocolVersion(){
return axios.get('/api/all_protocol_version/').then(
......@@ -11,9 +11,18 @@ export function GetProtocolVersion(){
}
export function ProtocolInit(protocol_name: any){
return axios.post('api/protocol_version_manage/init/', protocol_name).then(
return axios.post('/api/protocol_version_manage/init/', protocol_name).then(
function (response){
return response.data
}
)
}
\ No newline at end of file
}
export function GetCurrentVersion() {
return axios.get('/api/current_versions/').then(
function (response) {
return response.data
}
)
}
import { defineStore } from 'pinia'
import { ref } from 'vue'
type ProtocolVersion = {
protocol_name: string
version_paths: string
}
type CurrentVersion = {
protocol_name: string
version: string
}
export const useProtocolVersionStore = defineStore('protocolVersion', () => {
const protocolVersions = ref<ProtocolVersion[]>([])
const currentVersions = ref<CurrentVersion[]>([])
return {
protocolVersions,
currentVersions
}
})
\ No newline at end of file
......@@ -27,16 +27,30 @@
</template>
<script setup lang="ts">
import { ref } from 'vue';
import { ref, onMounted } from 'vue';
import KitCollapse from "@/components/protocol/KitCollapse";
import { GetProtocolVersion, GetCurrentVersion } from '@/dao/protocol';
import { useProtocolVersionStore } from '@/stores/allProtocolVersion';
const isShow = ref<boolean>(false)
const formLabelWidth = '140px'
const store = useProtocolVersionStore()
onMounted(() => {
GetProtocolVersion()
.then(res => {
store.protocolVersions.push(...res)
})
GetCurrentVersion()
.then(res => {
store.currentVersions = res
})
})
// TODO:添加协议
const addProtocol = () => {
isShow.value = false
console.log('addProtocol')
}
</script>
......
from django.urls import re_path
from rest_framework.routers import DefaultRouter
from . import views
router = DefaultRouter()
router.register(r'current_versions', views.CurrentDevVersionViewSet)
urlpatterns = [
re_path(r'^protocol_version_manage/init/$', views.init),
......@@ -13,3 +16,5 @@ urlpatterns = [
views.raw_file_download),
re_path(r'^all_protocol_version/$', views.AllProtocolVersionViewSet.as_view({'get': 'list'})),
]
urlpatterns += router.urls
......@@ -193,3 +193,8 @@ def raw_file_download(request, protocol_name, version):
response['Content-Type'] = 'multipart/form-data'
response['filename'] = file_name
return response
class CurrentDevVersionViewSet(GenericViewSet, ListModelMixin):
queryset = CurrentDevVersion.objects.all()
serializer_class = CurrentDevVersionSerializer
No preview for this file type
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