lvkun 3 жил өмнө
parent
commit
179218777d

+ 51 - 0
src/api/iot/model.ts

@@ -108,3 +108,54 @@ export const delModelAttribute = (id: string) => {
     method: 'DELETE'
   })
 }
+
+/**
+ * 此函数发送 GET 请求以检索模型命令页面。
+ * @param {any} params - `params` 参数是一个包含可选查询参数的对象,这些参数将与 GET 请求一起发送到 `/modelCmd/page`
+ * 端点。这些参数可能包括页码、页面大小、排序标准或过滤器等内容,以应用于端点返回的数据。
+ * @returns `getModelCmd` 函数返回一个解析为 `string` 的 `Promise`。 `request` 函数使用提供的 `params` 向 `/modelCmd/page`
+ * 端点发出 GET 请求。
+ */
+export const getModelCmd = (params: any) => {
+  return request<IOT.API.CMD.CMD[]>({
+    url: '/modelCmd/page',
+    method: 'GET',
+    params
+  })
+}
+
+/**
+ * 此函数使用提供的数据向“/modelCmd”端点发送 POST 请求。
+ * @param {any} data - `data` 参数是一个对象,其中包含要在请求正文中发送的数据。它可以包括诸如“名称”、“描述”、“类型”、“参数”等属性。具体属性及其值将取决于被调用的
+ * API 端点的要求。
+ * @returns `addModelCmd` 函数返回一个解析为字符串的 Promise。 Promise 由 `request` 函数返回,该函数使用提供的 `data` 向 `/modelCmd`
+ * 端点发出 POST 请求。
+ */
+export const addModelCmd = (data: any) => {
+  return request<string>({
+    url: '/modelCmd',
+    method: 'POST',
+    data
+  })
+}
+
+/**
+ * 此函数发送 PUT 请求以使用提供的数据更新模型命令。
+ * @param {any} data - `data` 参数是一个对象,其中包含要在请求正文中发送的数据。它可以是需要为模型命令更新的任何数据。
+ * @returns `updateModelCmd` 函数返回一个解析为字符串的 Promise。 Promise 由“request”函数返回,该函数使用提供的数据向“/modelCmd”端点发送
+ * PUT 请求。
+ */
+export const updateModelCmd = (data: any) => {
+  return request<string>({
+    url: '/modelCmd',
+    method: 'PUT',
+    data
+  })
+}
+
+export const delModelCmd = (id: string) => {
+  return request<string>({
+    url: `/modelCmd/${id}`,
+    method: 'DELETE'
+  })
+}

+ 24 - 0
src/controller/iot/modelCmd.ts

@@ -0,0 +1,24 @@
+
+import { addModelCmd, getModelCmd, updateModelCmd, delModelCmd } from '@/api/iot/model'
+import { message } from 'ant-design-vue'
+
+export class ModelAttrCmd {
+  static async page (params: any) {
+    return await getModelCmd(params)
+  }
+
+  static async post (data: IOT.API.MODELATTR.ModelAttr & {modelId: string}) {
+    await addModelCmd(data)
+    message.success('新增成功')
+  }
+
+  static async update (data: IOT.API.MODELATTR.ModelAttr & {modelId: string, id: string}) {
+    await updateModelCmd(data)
+    message.success('修改成功')
+  }
+
+  static async del (id: string) {
+    await delModelCmd(id)
+    message.success('删除成功')
+  }
+}

+ 54 - 2
src/pages/Iot/model/components/modelDefine.vue

@@ -6,6 +6,7 @@
       </a-space>
     </a-col>
   </a-row>
+  <!-- 模型属性 -->
   <a-table
     style="margin-top: 10px;"
     :columns="columns"
@@ -30,6 +31,30 @@
     </template>
   </a-table>
 
+  <!-- 模型命令 -->
+  <a-table
+    style="margin-top: 10px;"
+    :columns="columnsCmd"
+    :dataSource="state.dataSourceCmd"
+    :loading="state.loadingCmd"
+    :pagination="state.queryParamsCmd"
+  >
+    <template #bodyCell="{column, record}">
+      <template v-if="column.key === 'action'">
+      </template>
+            <a-space>
+                <a href="#">修改</a>
+                <a-popconfirm
+                  title="确实要删除吗?"
+                  ok-text="确定"
+                  cancel-text="取消"
+                  @confirm="confirmDel('attr', record.id)"
+                >
+                  <a href="#">删除</a>
+            </a-popconfirm>
+     </a-space>
+    </template>
+  </a-table>
   <a-modal
     :title="modalTitle"
     :visible="state.attrVisible"
@@ -68,7 +93,7 @@ import { onMounted, reactive } from 'vue'
 import { Form } from 'ant-design-vue'
 import { useRoute } from 'vue-router'
 
-const columns: ColumnProps = [
+const columns = [
   {
     title: '属性',
     key: 'attributeKey'
@@ -99,6 +124,24 @@ const columns: ColumnProps = [
   }
 ]
 
+const columnsCmd = [
+  {
+    title: '命令名称',
+    key: 'cmdLabel'
+  },
+  {
+    title: '下发参数',
+    key: 'cmdParams'
+  },
+  {
+    title: '下发参数',
+    key: 'cmdParams'
+  },
+  {
+    title: '操作',
+    key: 'action'
+  }
+]
 const route = useRoute()
 
 const modelId = route.query.id! as string
@@ -109,6 +152,7 @@ const dataTypes = ['string(字符串)', 'long(整数)', 'boolean(布尔值)', 'd
 
 const state = reactive<{
   dataSource: IOT.API.MODELATTR.ModelAttr[],
+  dataSourceCmd: IOT.API.CMD.CMD[]
   [key: string]: any
 }>({
   dataSource: [],
@@ -120,8 +164,16 @@ const state = reactive<{
     modelId: '',
     total: 0
   },
+  queryParamsCmd: {
+    page: 1,
+    pageSize: 10,
+    modelId: '',
+    total: 0
+  },
   attrVisible: false,
-  commandVisible: false
+  cmdVisible: false,
+  loadingCmd: false,
+  dataSourceCmd: []
 })
 
 const attrRef = reactive({

+ 31 - 0
src/type/iot.d.ts

@@ -38,5 +38,36 @@ declare namespace IOT {
         expr: string
       }
     }
+
+    namespace CMD {
+      interface CMD {
+        'cmdLabel': string,
+        'cmdParams': [
+          {
+            'paramLabel': string,
+            'dataType': string,
+            'required': boolean,
+            'dataUnit': string,
+            'minValue': any,
+            'maxValue': any,
+            'scope': string,
+            'description': string
+          }
+        ],
+        'cmdResponses': [
+          {
+            'paramLabel': string,
+            'dataType': string,
+            'required': boolean,
+            'dataUnit': string,
+            'minValue': any,
+            'maxValue': any,
+            'scope': string,
+            'description': string
+          }
+        ],
+        'modelId': string
+      }
+    }
   }
 }