Commit c55e0acb by 周田

refactor:切换接口

parent 908b6b54
......@@ -20,6 +20,11 @@ class TableAllDevCmdDefineView_1(ModelViewSet):
queryset = TableAllDevCmdDefine.objects.all()
serializer_class = TableAllDevCmdDefineSerializer
def list(self, request):
serializer = self.get_serializer(self.get_queryset(), many=True)
data = tree_data(serializer.data, 'cmd_name')
return Response(data)
def perform_create(self, serializer):
"""
新增指令字段,给 TableAllDevCmdDefine 表创建记录时,同时给 AllDevCmdDefineAndVersion 表创建
......@@ -88,6 +93,11 @@ class TableDevCmdNamePollView_1(ModelViewSet):
queryset = TableDevCmdNamePoll.objects.all()
serializer_class = TableDevCmdNamePollSerializer
def list(self, request):
serializer = self.get_serializer(self.get_queryset(), many=True)
data = tree_data(serializer.data, 'protocol_name')
return Response(data)
def perform_create(self, serializer):
"""
新增指令,给 TableDevCmdNamePollView 表创建记录时,同时给 AllProtocolDefineAndVersion 表创建
......
......@@ -27,8 +27,34 @@
</template>
<script setup lang="ts">
import { ref } from 'vue'
import { onBeforeMount, ref } from 'vue'
const activeIndex = ref('1')
import { DeviceProtocol, ProtocolCmd } from "@/dao/device";
import { GetProtocolVersion, GetCurrentVersion } from '@/dao/protocol';
import { useProtocolInfoStore } from './stores/protocolInfo';
import { useProtocolVersionStore } from '@/stores/allProtocolVersion';
const store = useProtocolVersionStore()
const protocolStore = useProtocolInfoStore()
onBeforeMount(async () => {
await GetProtocolVersion()
.then(res => {
store.protocolVersions.push(...res)
})
await GetCurrentVersion()
.then(res => {
store.currentVersions = res
})
await DeviceProtocol()
.then((res) => {
protocolStore.deviceProtocol = res
})
await ProtocolCmd()
.then((res) => {
protocolStore.protocolCmd = res
})
})
</script>
<style>
......
......@@ -17,7 +17,7 @@
</template>
<script setup lang="ts">
import { ref, watch } from 'vue'
import { onMounted, ref, watch } from 'vue'
import CollapseTable from "./CollapseTable.vue";
import type { DeviceProtocolResponse, ProtocolCmdResponse } from './types';
......@@ -27,6 +27,11 @@ type propsType = {
}
const props = defineProps<propsType>()
onMounted(() => {
let { fields } = props.deviceProtocol
protocol_names.value = fields
})
const protocol_names = ref<string[]>([]);
watch(() => props.deviceProtocol, (val) => {
let { fields } = val
......
......@@ -3,7 +3,7 @@ import axios from "axios"
// const baseURL = 'http://192.168.0.214:8000/op'
export function DeviceProtocol() {
return axios.get('/api/dev_cmd_name_poll/').then(
return axios.get('/api/dev_cmd_name_poll_1/').then(
function (response) {
return response.data
}
......@@ -11,7 +11,7 @@ export function DeviceProtocol() {
}
export function ProtocolCmd() {
return axios.get('/api/all_dev_cmd_define/').then(
return axios.get('/api/all_dev_cmd_define_1/').then(
function (response) {
return response.data
}
......@@ -19,7 +19,7 @@ export function ProtocolCmd() {
}
export function EditProtocolCmd(id: number, params: any) {
return axios.put('/api/all_dev_cmd_define/' + id + '/', params).then(
return axios.put('/api/all_dev_cmd_define_1/' + id + '/', params).then(
function (response) {
return response.data
}
......@@ -27,7 +27,7 @@ export function EditProtocolCmd(id: number, params: any) {
}
export function DeleteProtocolCmd(id: number) {
return axios.delete('/api/all_dev_cmd_define/' + id + '/').then(
return axios.delete('/api/all_dev_cmd_define_1/' + id + '/').then(
function (response) {
return response.data
}
......
import { defineStore } from 'pinia'
import { ref } from 'vue';
import type { DeviceProtocolResponse, ProtocolCmdResponse } from '@/components/protocol/types';
export const useProtocolInfoStore = defineStore('protocolInfo', () => {
const deviceProtocol = ref<DeviceProtocolResponse>()
const protocolCmd = ref<ProtocolCmdResponse>()
return {
deviceProtocol,
protocolCmd
}
});
......@@ -32,33 +32,18 @@
<script setup lang="ts">
import { ref, onBeforeMount } from 'vue';
import KitCollapse from '@/components/protocol/KitCollapse.vue';
import { GetProtocolVersion, GetCurrentVersion } from '@/dao/protocol';
import { useProtocolVersionStore } from '@/stores/allProtocolVersion';
import { DeviceProtocol, ProtocolCmd } from "@/dao/device";
import { useProtocolInfoStore } from '@/stores/protocolInfo';
import type { DeviceProtocolResponse, ProtocolCmdResponse } from '@/components/protocol/types';
const isShow = ref<boolean>(false)
const formLabelWidth = '140px'
const store = useProtocolVersionStore()
const protocolStore = useProtocolInfoStore()
const deviceProtocol = ref<DeviceProtocolResponse>()
const protocolCmd = ref<ProtocolCmdResponse>()
onBeforeMount(() => {
GetProtocolVersion()
.then(res => {
store.protocolVersions.push(...res)
})
GetCurrentVersion()
.then(res => {
store.currentVersions = res
})
DeviceProtocol()
.then((res) => {
deviceProtocol.value = res
})
ProtocolCmd()
.then((res) => {
protocolCmd.value = res
})
deviceProtocol.value = protocolStore.deviceProtocol
protocolCmd.value = protocolStore.protocolCmd
})
const protocolName = ref<string>('')
......@@ -67,8 +52,6 @@ const addProtocol = () => {
deviceProtocol.value!.fields.push(protocolName.value)
deviceProtocol.value![protocolName.value] = []
}
const deviceProtocol = ref<DeviceProtocolResponse>()
const protocolCmd = ref<ProtocolCmdResponse>()
</script>
<style scoped>
......
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