Browse Source

fix: 产品新增命令bug

lvkun996 2 years ago
parent
commit
bceae32cfd

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

@@ -391,6 +391,8 @@ const okCmdParams = () => {
     // cmdParamsRef.id = useId()
     console.log(cmdParamsRef)
     const key = state.cmdParamsOpraState === 'request' ? 'requestData' : 'responseData'
+    console.log(state.dataCmdParams, key)
+
     const index = state.dataCmdParams[key].map(item => item.id).indexOf(cmdParamsRef.id)
     if (index >= 0) {
       state.dataCmdParams[key].splice(index, 1, { ...cmdParamsRef })
@@ -451,8 +453,8 @@ const openModel = (key: string, opraState: 'add' | 'update', record: any = {}) =
     console.log(record)
 
     resetFieldsCmd(record)
-    state.dataCmdParams.requestData = record.cmdParams
-    state.dataCmdParams.responseData = record.cmdResponses
+    state.dataCmdParams.requestData = record.cmdParams || []
+    state.dataCmdParams.responseData = record.cmdResponses || []
   }
 }
 

+ 6 - 10
src/pages/Iot/model/models.vue

@@ -1,10 +1,5 @@
 <template>
 <a-card>
-  <a-row justify="end" >
-    <a-col>
-      <a-button type="primary" @click="openModal" >新增</a-button>
-    </a-col>
-  </a-row>
   <a-table
     style="margin-top: 20px;"
     :columns="columns"
@@ -16,7 +11,9 @@
   <template #bodyCell="{column, record}">
         <template v-if="column.key === 'action'" >
           <a-space>
-            <a>详情</a>
+            <a @click="openModal(record)" >加入</a>
+            <a >详情</a>
+            <a >删除</a>
           </a-space>
         </template>
       </template>
@@ -35,7 +32,7 @@
       <a-input v-model:value="modelRef.templateLabel"  />
     </a-form-item>
 
-    <a-form-item label="产品" v-bind="validateInfos.modelId">
+    <a-form-item label="产品" v-bind="validateInfos.templateLabel">
       <a-select v-model:value="modelRef.modelId" >
         <a-select-option
           v-for="item in modelState.dataSource"
@@ -53,6 +50,7 @@
 </template>
 <script lang='ts' setup >
 import { ModelController } from '@/controller'
+import { LeftSquareOutlined } from '@ant-design/icons-vue'
 import { onMounted, reactive } from 'vue'
 import { Form } from 'ant-design-vue'
 
@@ -130,9 +128,7 @@ const changePage = ({ current }) => {
 
 const ok = () => {
   validate().then(async () => {
-    await ModelController.postModelTemplate(modelRef)
-    state.visible = false
-    getModelsPage()
+
   })
 }
 

+ 55 - 14
src/pages/Iot/task/manage.vue

@@ -94,16 +94,30 @@
         </a-select>
       </a-form-item>
       <a-form-item label="选择设备" >
-              <a-space>
-                <a-tag color="blue" v-if="modalRef.taskConfig.deviceLabel" >{{modalRef.taskConfig.deviceLabel}}</a-tag>
-                <a-button
-                  type="primary"
-                  @click="state.deviceModalVisible = true"
-                >
-                  {{modalRef.taskConfig.deviceId ? '重新选择' : '请选择设备'}}
-                </a-button>
-              </a-space>
-            </a-form-item>
+          <a-space>
+            <a-tag color="blue" v-if="modalRef.taskConfig.deviceLabel" >{{modalRef.taskConfig.deviceLabel}}</a-tag>
+            <a-button
+              type="primary"
+              @click="state.deviceModalVisible = true"
+            >
+              {{modalRef.taskConfig.deviceId ? '重新选择' : '请选择设备'}}
+            </a-button>
+          </a-space>
+      </a-form-item>
+      <a-form-item label="选择命令" >
+        <a-select
+          style="width: 170px;"
+          v-model:value="modalRef.taskConfig.cmdId"
+        >
+          <a-select-option
+            v-for="cmdItem in state.cmdList"
+            :key="cmdItem.id"
+            :value="cmdItem.id"
+          >
+          {{cmdItem.cmdLabel}}
+          </a-select-option>
+        </a-select>
+      </a-form-item>
     </a-form>
   </modal-pro>
 </a-card>
@@ -122,10 +136,9 @@
 </template>
 <script lang='ts' setup >
 import { TaskController } from '@/controller/iot/task'
-import { computed, onMounted, reactive, ref } from 'vue'
+import { computed, onMounted, reactive, ref, watch } from 'vue'
 import { Form } from 'ant-design-vue'
-import { string } from 'vue-types'
-import { ModelController } from '@/controller'
+import { ModelAttrController, ModelCmdController, ModelController } from '@/controller'
 import SelectDevice from '@/pages/iot/rule/components/selectDevice.vue'
 
 const columns = [
@@ -185,6 +198,8 @@ const state = reactive({
   opraState: 'add',
   visible: false,
   modelList: [],
+  cmdList: [],
+  attrList: [],
   deviceModalVisible: false
 })
 
@@ -198,12 +213,25 @@ const modalRef = reactive({
     deviceLabel: '',
     modelId: '',
     cmdLabel: '',
-    cmdParameters: {}
+    cmdParameters: {},
+    cmdId: ''
   }
 })
 
 const selectDeviceRef = ref('')
 
+// watch(
+//   () => modalRef.taskConfig.cmdId,
+//   () => {
+//     const cmdDetail = state.cmdList.find(item => item.id === initActionsData.cmdId)!
+//     console.log('cmdDetail:', cmdDetail)
+
+//     modalRef.taskConfig.cmdParameters = cmdDetail.cmdParams
+
+//     modalRef.taskConfig.cmdLabel = cmdDetail.cmdLabel
+//   }
+// )
+
 const { resetFields, validate, validateInfos } = useForm(modalRef, reactive({
   taskLabel: [{ required: true, message: '请填写任务名称' }],
   cornDescr: [{ required: true, message: '请填写corn表达式' }],
@@ -234,6 +262,17 @@ const changeStatus = (value) => {
   queryParamsState.status = value
 }
 
+const getCmdList = async () => {
+  const { data } = await ModelCmdController.list({ modelId: modalRef.taskConfig.modelId })
+  state.cmdList = data
+}
+
+// 获取属性
+const getAttrList = async () => {
+  const { data } = await ModelAttrController.list({ modelId: modalRef.taskConfig.modelId })
+  state.attrList = data
+}
+
 const getModelList = async () => {
   const { data } = await ModelController.list()
   state.modelList = data
@@ -255,6 +294,8 @@ const changePage = ({ current }) => {
 onMounted(() => {
   getTaskPage()
   getModelList()
+  getCmdList()
+  getAttrList()
 })
 
 </script>