Kaynağa Gözat

修复场景回显

yukai 2 yıl önce
ebeveyn
işleme
fb47685b25

+ 26 - 15
src/views/iot/scene/manage/component/actionItem.vue

@@ -20,7 +20,7 @@
         <div class="icon"></div>并行动作
       </div>
       <div class="product flex flex-warp">
-            <ActionParallelItem :parallel="item.parallel"></ActionParallelItem>
+            <ActionParallelItem :index="index"  :parallel="item.parallel" :sourceData="sourceData" @saveData="saveData" @delData="delData"></ActionParallelItem>
       
       </div>
     </div>
@@ -78,16 +78,26 @@ const getOneDetail = () => {
 				}
 
        	originalSceneList.value = res;
-
-         const action = res.map(scene=> {
-              const parsedBodyJson = JSON.parse(scene.bodyjson);
-              return {
-                  serial: parsedBodyJson[0].serial,
-                  parallel: parsedBodyJson[0].parallel
-              };
-          });
-        
-        actionList.value=action;
+        console.log(res);
+        const combinedArray = res.map(scene => {
+          const parsedBodyJson = JSON.parse(scene.bodyjson);
+          if (Array.isArray(parsedBodyJson)) {
+            const serial = parsedBodyJson.map(item => item.serial).flat();
+            const parallel = parsedBodyJson.map(item => item.parallel).flat();
+            return {
+              serial,
+              parallel
+            };
+          } else {
+            return {
+              serial: [parsedBodyJson.serial].flat(),
+              parallel: [parsedBodyJson.parallel].flat()
+            };
+          }
+        });
+      console.log(combinedArray,3333);
+
+        actionList.value=combinedArray;
 			})
 		};
 getOneDetail();    
@@ -114,7 +124,7 @@ const delData = (index: number) => {
 //修改一条场景
 const saveData = (data: any) => {
       let ids = originalSceneList.value[data.index].id;
-			api.manage.editDetail({ id: ids, bodyjson:actionList.value }).then((res: any) => {
+			api.manage.editDetail({ id: ids, bodyjson:actionList.value[data.index] }).then((res: any) => {
 				  getOneDetail();
 			});
 
@@ -131,6 +141,7 @@ const addAction = () => {
 };
 const delAction = (index: number) => {
   actionList.value.splice(index, 1);
+  delData(index);
 }
 
 </script>
@@ -161,9 +172,9 @@ const delAction = (index: number) => {
   }
 
   .biankang {
-
-    border: 1px dashed #959596;;
-    border-radius: 10px;
+    margin-top: 10px;
+    border: 1px solid #cfcfcf;;
+    border-radius: 2px;
   }
 
 

+ 4 - 3
src/views/iot/scene/manage/component/actionType/delayExecution.vue

@@ -36,9 +36,10 @@ const saveData = () => {
 }
 
 onMounted(() => {
-    if (props.data && props.data.delayTime) {
-      fromData.value.delayTime = { ...props.data.delayTime }
-    }
+    // if (props.data && props.data.delayTime) {
+    //   fromData.value.delayTime = { ...props.data.delayTime }
+    // }
+    fromData.value= props.data
 });
 
 </script>

+ 26 - 10
src/views/iot/scene/manage/component/actionType/deviceOut.vue

@@ -18,7 +18,7 @@
   </el-form-item>
 
   <el-form-item label="触发类型:" prop="executeAction" class="form-item">
-    <el-select v-model="fromData.executeAction" filterable placeholder="请选择触发类型" @change="getAction">
+    <el-select v-model="fromData.executeAction" filterable placeholder="请选择触发类型" @change="selectAction">
       <el-option v-for="it in sourceActionTypeData" :key="it.key" :label="it.name" :value="it.key">
         <span style="float: left">{{ it.name }}</span>
         <span style="float: right; font-size: 13px">{{ it.key }}</span>
@@ -76,7 +76,7 @@
 </template>
 
 <script lang="ts" setup>
-import { PropType, ref } from 'vue'
+import { PropType, ref,onMounted } from 'vue'
 import product from '/@/api/device';
 import datahub from '/@/api/datahub';
 const emit = defineEmits(['SetSaveData']);
@@ -132,6 +132,10 @@ const fromData = ref({
   setProperties_temp: [],
 })
 
+const selectAction=(val:string)=>{
+  saveData();
+  getAction(val);
+}
 //获取类型数据
 const getAction = (val: string) => {
   switch (val) {
@@ -152,7 +156,6 @@ const getAction = (val: string) => {
       });
       break;
   }
-  // saveData();
 }
 
 const saveSetData = () => {
@@ -197,21 +200,34 @@ const seletChange = (val: string) => {
   saveData();
 }
 
-
-const initData = () => {
-  let infoc = props.data;
-  if (infoc.productKey) {
+onMounted(() => {
+    let infoc = props.data;
+    if (infoc.productKey) {
     productKey.value = infoc.productKey;
     let info = props.sourceData?.find((pro: testIValueType) => pro.key === infoc.productKey);
     if (info) {
        getDeviceList(info.id)
     }
   }
-  getAction(infoc.executeAction);
-  fromData.value = infoc
+
+    getAction(infoc.executeAction);
+    if (props.data && props.data.setProperties) {
+      setPropertiesItem.value =props.data.setProperties
+    }
+
+    fromData.value = infoc
+
+    if (props.data && props.data.functionCall) {
+      fromData.value.functionCall = props.data.functionCall;
+    } else {
+      fromData.value.functionCall = {
+        functionName: "",
+        parameter: ""
+      };
 }
+    
+});
 
-initData();
 
 
 </script>

+ 4 - 4
src/views/iot/scene/manage/component/condition.vue

@@ -93,7 +93,7 @@
 </template>
 
 <script lang="ts" setup>
-import { PropType, ref } from 'vue'
+import { PropType, ref,onMounted } from 'vue'
 import { CirclePlus, CircleClose, Right } from '@element-plus/icons-vue';
 const emit = defineEmits(['EditPen']);
 interface IConditionItem {
@@ -160,7 +160,7 @@ const addScene = () => {
 const delScene = (index: number) => {
   props.condition.splice(index, 1);
 }
-const initItem = () => {
+onMounted(() => {
   props.condition.forEach((item) => {
     item.forEach((vo:any) => {
       let operator = vo.operator;
@@ -174,8 +174,8 @@ const initItem = () => {
       }
     });
   });
-};
-initItem();
+});
+
 
 </script>
 <style scoped lang="scss">

+ 1 - 1
src/views/iot/scene/manage/component/sceneItem.vue

@@ -53,7 +53,7 @@
         <div class="icon"></div> 触发条件 <div class="ml10"> <el-switch v-model="item.triggerSwitch"   @change="EditPen(index)"/>
         </div>
       </div>
-      <Condition :condition="item.condition" :operate_index="index" :columnList="columnList" v-if="item.triggerSwitch && columnList.length>0" @EditPen="EditPen">
+      <Condition :condition="item.condition" :operate_index="index" :columnList="columnList" v-if="item.triggerSwitch" @EditPen="EditPen">
       </Condition>
     </div>
     <div>

+ 4 - 3
src/views/iot/scene/manage/detail.vue

@@ -27,7 +27,7 @@
 	<EditForm ref="editFormRef" @getList="getDetail()"></EditForm>
 </template>
 <script lang="ts">
-import { toRefs, reactive, ref, defineComponent } from 'vue';
+import { toRefs, reactive, ref, defineComponent,onMounted } from 'vue';
 import { useRoute, useRouter } from 'vue-router';
 import { EditPen, DocumentAdd } from '@element-plus/icons-vue';
 import ActionItem from './component/actionItem.vue';
@@ -159,9 +159,10 @@ export default defineComponent({
 			editFormRef.value.open(row);
 		};
 
-		getDetail();
-
 
+		onMounted(() => {
+			getDetail();
+		});
 		return {
 			addOrEdit,
 			delScenesDetail,