|
|
@@ -1,44 +1,99 @@
|
|
|
<template>
|
|
|
+
|
|
|
<a-card>
|
|
|
- <table-pro
|
|
|
- modalTitle="模型"
|
|
|
- :request="ModelController.page"
|
|
|
- :del="ModelController.del"
|
|
|
- :params="{
|
|
|
- page: 1,
|
|
|
- pageSize: 10,
|
|
|
- modelLabel: 1
|
|
|
- }"
|
|
|
+ <a-row justify="space-between" >
|
|
|
+ <a-col>
|
|
|
+ <a-input-search
|
|
|
+ v-model:value="state.queryParams.modelLabel"
|
|
|
+ placeholder="请输入产品名称"
|
|
|
+ enter-button
|
|
|
+ @search="getModel"
|
|
|
+ />
|
|
|
+ </a-col>
|
|
|
+ <a-col>
|
|
|
+ <a-space>
|
|
|
+ <a-button type="primary" @click="openModel('add')" >
|
|
|
+ 新增
|
|
|
+ <template #icon>
|
|
|
+ <plus-outlined />
|
|
|
+ </template>
|
|
|
+ </a-button>
|
|
|
+ </a-space>
|
|
|
+ </a-col>
|
|
|
+ </a-row>
|
|
|
+ <a-table
|
|
|
+ style="margin-top: 10px;"
|
|
|
:columns="columns"
|
|
|
- :pro-able="['add']"
|
|
|
- />
|
|
|
+ :dataSource="state.dataSource"
|
|
|
+ :pagination="state.queryParams"
|
|
|
+ :loading="state.loading"
|
|
|
+ >
|
|
|
+ <template #bodyCell="{ column, record }">
|
|
|
+ <template v-if="column.key === 'action'">
|
|
|
+ <a-space>
|
|
|
+ <a href="#">查看</a>
|
|
|
+ <a-popconfirm
|
|
|
+ title="确实要删除吗?"
|
|
|
+ ok-text="确定"
|
|
|
+ cancel-text="取消"
|
|
|
+ @confirm="confirmDel(record.id)"
|
|
|
+ >
|
|
|
+ <a href="#">删除</a>
|
|
|
+ </a-popconfirm>
|
|
|
+ </a-space>
|
|
|
+ </template>
|
|
|
+ </template>
|
|
|
+ </a-table>
|
|
|
</a-card>
|
|
|
+
|
|
|
+ <a-modal
|
|
|
+ :title="modalTitle"
|
|
|
+ :visible="state.visible"
|
|
|
+ ok-text="确定"
|
|
|
+ cancel-text="取消"
|
|
|
+ @cancel="closeModel"
|
|
|
+ @ok="ok"
|
|
|
+ >
|
|
|
+ <a-form :label-col="{span: 4}" :wrapper-col="{span: 14}">
|
|
|
+ <a-form-item label="产品名称" v-bind="validateInfos.modelLabel">
|
|
|
+ <a-input v-model:value="modelRef.modelLabel" />
|
|
|
+ </a-form-item>
|
|
|
+ <a-form-item label="协议类型" v-bind="validateInfos.transportType">
|
|
|
+ <a-select v-model:value="modelRef.transportType" >
|
|
|
+ <a-select-option :value="item.port" v-for="item in state.transport" :key="item.port" >{{item.port}}</a-select-option>
|
|
|
+ </a-select>
|
|
|
+ </a-form-item>
|
|
|
+ <a-form-item label="数据格式" v-bind="validateInfos.payloadType">
|
|
|
+ <a-select v-model:value="modelRef.payloadType" >
|
|
|
+ <a-select-option :value="item" v-for="item in state.payloadType" :key="item" >{{item}}</a-select-option>
|
|
|
+ </a-select>
|
|
|
+ </a-form-item>
|
|
|
+ <a-form-item label="设备类型" >
|
|
|
+ <a-input v-model:value="modelRef.deviceType" />
|
|
|
+ </a-form-item>
|
|
|
+ <a-form-item label="厂商描述">
|
|
|
+ <a-textarea v-model:value="modelRef.modelDescription" />
|
|
|
+ </a-form-item>
|
|
|
+ </a-form>
|
|
|
+ </a-modal>
|
|
|
</template>
|
|
|
|
|
|
<script lang="ts" setup >
|
|
|
import { CommonController, ModelController } from '@/controller/index'
|
|
|
-import { AppTsx } from '@/components/index'
|
|
|
+import { onMounted, reactive } from 'vue'
|
|
|
+import { computed } from '@vue/reactivity'
|
|
|
+import { Form } from 'ant-design-vue'
|
|
|
+
|
|
|
const columns = [
|
|
|
{
|
|
|
title: '模型名称',
|
|
|
dataIndex: 'modelLabel',
|
|
|
- key: 'modelLabel',
|
|
|
- formItemProps: {
|
|
|
- rules: {
|
|
|
- required: true,
|
|
|
- message: '此项为必填项'
|
|
|
- },
|
|
|
- request: async () => {
|
|
|
- return await CommonController.getTransport()
|
|
|
- },
|
|
|
- type: '',
|
|
|
- key: ''
|
|
|
- }
|
|
|
+ key: 'modelLabel'
|
|
|
},
|
|
|
{
|
|
|
title: '传输协议',
|
|
|
- dataIndex: 'address',
|
|
|
- key: 'address'
|
|
|
+ dataIndex: 'transportType',
|
|
|
+ key: 'transportType'
|
|
|
},
|
|
|
{
|
|
|
title: '数据格式',
|
|
|
@@ -57,21 +112,89 @@ const columns = [
|
|
|
},
|
|
|
{
|
|
|
title: '操作',
|
|
|
- key: 'action',
|
|
|
- list: [
|
|
|
- {
|
|
|
- name: '复制',
|
|
|
- use: 'copy',
|
|
|
- bindKey: 'address'
|
|
|
- },
|
|
|
- {
|
|
|
- name: '删除',
|
|
|
- use: 'del',
|
|
|
- bindKey: 'id'
|
|
|
- }
|
|
|
- ]
|
|
|
+ key: 'action'
|
|
|
}
|
|
|
]
|
|
|
+
|
|
|
+const state = reactive<{
|
|
|
+ dataSource: IOT.API.MODEL.ModelDot[],
|
|
|
+ [key: string]: any
|
|
|
+}>({
|
|
|
+ loading: false,
|
|
|
+ opraState: 'add',
|
|
|
+ visible: false,
|
|
|
+ dataSource: [],
|
|
|
+ queryParams: {
|
|
|
+ page: 1,
|
|
|
+ pageSize: 10,
|
|
|
+ total: 0,
|
|
|
+ modelLabel: ''
|
|
|
+ },
|
|
|
+ payloadType: ['JSON', '二进制流']
|
|
|
+})
|
|
|
+
|
|
|
+const modalTitle = computed(() => state.opraState === 'add' ? '新增产品' : '编辑产品')
|
|
|
+
|
|
|
+const useForm = Form.useForm
|
|
|
+
|
|
|
+const modelRef = reactive({
|
|
|
+ modelLabel: '',
|
|
|
+ transportType: '',
|
|
|
+ payloadType: '',
|
|
|
+ deviceType: '',
|
|
|
+ modelDescription: ''
|
|
|
+})
|
|
|
+
|
|
|
+const rulesRef = reactive({
|
|
|
+ modelLabel: [{ required: true, message: '请填写标题' }],
|
|
|
+ transportType: [{ required: true, message: '请选择协议' }],
|
|
|
+ payloadType: [{ required: true, message: '请填写数据格式' }]
|
|
|
+})
|
|
|
+
|
|
|
+const { resetFields, validate, validateInfos } = useForm(modelRef, rulesRef)
|
|
|
+
|
|
|
+const ok = () => {
|
|
|
+ validate().then(async () => {
|
|
|
+ await opraModel()
|
|
|
+ state.visible = false
|
|
|
+ getModel()
|
|
|
+ })
|
|
|
+}
|
|
|
+
|
|
|
+const confirmDel = async (id: string) => {
|
|
|
+ await ModelController.del(id)
|
|
|
+ getModel()
|
|
|
+}
|
|
|
+
|
|
|
+const openModel = (opraState: 'add' | 'update') => {
|
|
|
+ state.opraState = opraState
|
|
|
+ state.visible = true
|
|
|
+}
|
|
|
+
|
|
|
+const opraModel = async () => {
|
|
|
+ console.log('opraModel')
|
|
|
+
|
|
|
+ if (state.opraState === 'add') {
|
|
|
+ await ModelController.post(modelRef)
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+const closeModel = () => {
|
|
|
+ state.visible = false
|
|
|
+}
|
|
|
+
|
|
|
+const getModel = async () => {
|
|
|
+ state.loading = true
|
|
|
+ const { data, sum } = await ModelController.page(state.queryParams)
|
|
|
+ state.loading = false
|
|
|
+ state.dataSource = data
|
|
|
+ state.queryParams.total = sum
|
|
|
+}
|
|
|
+
|
|
|
+onMounted(async () => {
|
|
|
+ getModel()
|
|
|
+ state.transport = await CommonController.getTransport()
|
|
|
+})
|
|
|
</script>
|
|
|
|
|
|
<style></style>
|