Browse Source

fix: 场景联动详情: 1. 时间输入卡顿,不能选择其他功能
2. 触发条件关闭,保存时候去掉条件
3. 多个出发条件并且的时候,删除掉其中一个,还是有多个保存了
4. 多个调试件时候不能删除第一个,只能删除其他的

yanglzh 1 year ago
parent
commit
0f1faab331

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

@@ -4,7 +4,7 @@
 
       <div v-if="index > 0"><el-divider>或满足以下条件</el-divider></div>
       <div class="type-item">
-        <div class="conicon" style="width: 100%; text-align: right; position: relative; right: -15px; top: -5px; color: red" v-if="index > 0">
+        <div class="conicon" style="width: 100%; text-align: right; position: relative; right: -15px; top: -5px; color: red" v-if="condition.length > 1">
           <el-icon @click="delScene(index)">
             <CircleClose />
           </el-icon>
@@ -13,7 +13,6 @@
         <div class="flex-warp item_list">
 
           <div v-for="(vo, i) in item" :key="i">
-
             <div class="items">
               <el-button style="background: #fff; color: #000;border: 1px solid #d9cde3;margin-left: 10px;margin-right: 10px;" v-if="(i as number) > 0">并且</el-button>
 
@@ -49,16 +48,14 @@
 
               <el-popover placement="bottom" trigger="click">
                 <template #reference>
-                  <el-button style="background: #bc7dee1a; color: #692ca7;border: 1px solid #bc7dee80;">{{ vo.value ||
-                    '参数值' }}</el-button>
+                  <el-button style="background: #bc7dee1a; color: #692ca7;border: 1px solid #bc7dee80;">{{ vo.value || '参数值' }}</el-button>
                 </template>
                 <div class="popover-content">
-                  <el-input v-model="vo.value" placeholder="请输入参数值" @input="saveData" />
-
+                  <el-input v-model="vo.value" placeholder="请输入参数值" @blur="saveData" />
                 </div>
               </el-popover>
 
-              <el-icon size="16" v-if="(i as number) > 0" @click="DelSceneItem(i as number, index)" style="position: relative;top: -13px;">
+              <el-icon size="16" v-if="item.length > 1" @click="DelSceneItem(i as number, index)" style="position: relative;top: -13px;">
                 <CircleClose />
               </el-icon>
 
@@ -79,7 +76,7 @@
 
     </div>
 
-    <div class="mt15"><el-button @click="addScene()">增加条件</el-button></div>
+    <div class="mt15"><el-button @click="addScene()">增加条件</el-button></div>
 
   </div>
 </template>
@@ -149,9 +146,11 @@ const addScene = () => {
     'operator': '',
     'value': ''
   }]);
+  saveData();
 };
 const delScene = (index: number) => {
   props.condition.splice(index, 1);
+  saveData();
 }
 onMounted(() => {
   props.condition.forEach((item) => {

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

@@ -1,8 +1,7 @@
 <template>
   <div class="type-item">
     <div v-for="(item, index) in sceneList" :key="index" class="item " :class="index > 0 ? 'biankang' : ''">
-      <div class="conicon" style="width: 100%; text-align: right; position: relative; right: -8px; top: -8px; color: red"
-        v-if="index > 0">
+      <div class="conicon" style="width: 100%; text-align: right; position: relative; right: -8px; top: -8px; color: red" v-if="index > 0">
         <el-icon @click="delScene(index)">
           <CircleClose />
         </el-icon>
@@ -12,8 +11,7 @@
       </div>
       <div class="product flex flex-warp">
         <el-form-item label="产品:" prop="productKey">
-          <el-select v-model="item.productKey" filterable clearable placeholder="请选择产品"
-            @change="seletChange(index, item.productKey!)">
+          <el-select v-model="item.productKey" filterable clearable placeholder="请选择产品" @change="seletChange(index, item.productKey!)">
             <el-option v-for="it in sourceData" :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>
@@ -29,16 +27,14 @@
           </el-select>
         </el-form-item>
         <el-form-item label="触发类型:" prop="triggerType">
-          <el-select v-model="item.triggerType" clearable filterable placeholder="请选择触发类型"
-            @change="getSelectcolumns(index, item.triggerType!)">
+          <el-select v-model="item.triggerType" clearable filterable placeholder="请选择触发类型" @change="getSelectcolumns(index, item.triggerType!)">
             <el-option v-for="it in sourceTypeData" :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>
             </el-option>
           </el-select>
         </el-form-item>
-        <el-form-item label="定时请求"
-          v-if="item.triggerType && ['readAttribute', 'functionCall'].includes(item.triggerType)">
+        <el-form-item label="定时请求" v-if="item.triggerType && ['readAttribute', 'functionCall'].includes(item.triggerType)">
           <div style="display:flex">
             <el-input v-model="item.timer" placeholder="请输入cron表达式" />
             <el-dialog v-model="dialogVisible" title="选择Cron规则" width="60%">
@@ -50,10 +46,10 @@
         </el-form-item>
       </div>
       <div class="title flex">
-        <div class="icon"></div> 触发条件 <div class="ml10"> <el-switch v-model="item.triggerSwitch"   @change="EditPen(index)"/>
+        <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 && columnList.length > 0" @EditPen="EditPen">
       </Condition>
     </div>
     <div>
@@ -75,7 +71,7 @@ import datahub from '/@/api/datahub';
 import Condition from './condition.vue';
 const { proxy } = getCurrentInstance() as any;
 const scene_type = proxy.useDict('scene_type');
-const emit = defineEmits(['addScenesDetail','delScenesDetail','editScenesDetail']);
+const emit = defineEmits(['addScenesDetail', 'delScenesDetail', 'editScenesDetail']);
 const dialogVisible = ref();
 const deviceListData = ref<testIValueType[]>([]);
 const functionCallList = ref<testIValueType[]>([]);
@@ -109,7 +105,7 @@ const props = defineProps({
     type: String,
     default: () => '',
   },
-  sourceData:{
+  sourceData: {
     type: Array as PropType<testIValueType[]>,
     default: () => []
   },
@@ -121,15 +117,15 @@ const props = defineProps({
     }, {
       'key': 'offLine',
       'name': '设备离线',
-    }, 
-    
+    },
+
     {
       'key': 'readAttribute',
       'name': '读取属性',
     }, {
       'key': 'modifyAttribute',
       'name': '修改属性',
-    }, 
+    },
     {
       'key': 'reportAttribute',
       'name': '属性上报',
@@ -137,11 +133,11 @@ const props = defineProps({
       'key': 'reportEvent',
       'name': '事件上报',
     },
-     {
+    {
       'key': 'functionCall',
       'name': '功能调用',
     }
-  ]
+    ]
   }
 })
 
@@ -168,11 +164,11 @@ const getDeviceList = (_id: any) => {
     deviceListData.value = res.device
   })
 }
-const getSelectcolumns=(index: number, val: string) => {
+const getSelectcolumns = (index: number, val: string) => {
   EditPen(index);
-  getcolumns(index,val);
-    // 重置当前项的 condition 值
-    props.sceneList[index].condition = [[{
+  getcolumns(index, val);
+  // 重置当前项的 condition 值
+  props.sceneList[index].condition = [[{
     'parameter': '',
     'operator': '',
     'value': ''
@@ -217,7 +213,7 @@ const getcolumns = (index: number, val: string) => {
 }
 const getcolumnsList = (where: any) => {
   api.manage.getColumns(where).then((res: any) => {
-    if(res){
+    if (res) {
       columnList.value = res;
     }
   })
@@ -239,8 +235,8 @@ const addScene = () => {
   emit('addScenesDetail', 'definition');
 };
 
-const EditPen=(index: number)=>{
-  emit('editScenesDetail',index);
+const EditPen = (index: number) => {
+  emit('editScenesDetail', index);
 }
 const delScene = (index: number) => {
   emit('delScenesDetail', index);
@@ -260,20 +256,20 @@ const cronclose = () => {
   dialogVisible.value = false;
 }
 //初始化
-const intScenel=()=>{
-  let array_data=props.sceneList;
-  array_data.map((val:any,index) => {
-      if(val.productKey){
-          product_key = val.productKey;
-          let info = props.sourceData?.find((pro: { key: any; }) => pro.key === val.productKey);
+const intScenel = () => {
+  let array_data = props.sceneList;
+  array_data.map((val: any, index) => {
+    if (val.productKey) {
+      product_key = val.productKey;
+      let info = props.sourceData?.find((pro: { key: any; }) => pro.key === val.productKey);
 
-          if (info) {
-            getDeviceList(info.id)
-          }
+      if (info) {
+        getDeviceList(info.id)
       }
-      if(val.triggerType){
-        getcolumns(index,val.triggerType)
-      } 
+    }
+    if (val.triggerType) {
+      getcolumns(index, val.triggerType)
+    }
   });
 }
 intScenel();
@@ -300,13 +296,15 @@ intScenel();
   .item {
     padding: 10px;
   }
+
   .biankang {
     border: 1px solid #e8e2e2;
     border-radius: 10px;
     padding: 10px;
     margin-top: 10px;
   }
-    .title {
+
+  .title {
     height: 40px;
 
     .icon {
@@ -317,6 +315,7 @@ intScenel();
       background-color: #315efb;
     }
   }
+
   .product {
     .el-form-item {
       margin-left: 30px;

+ 7 - 2
src/views/iot/scene/manage/detail.vue

@@ -214,16 +214,21 @@ export default defineComponent({
 		const editScenesDetail = (index: number) => {
 			let saveData = state.sceneList[index];
 			let ids = originalSceneList.value[index].id;
+
+			// 如果触发条件关闭,则清空触发条件的数据
+			if (!saveData.triggerSwitch) {
+				saveData.condition = []
+			}
+
 			api.manage.editDetail({ id: ids, bodyjson: saveData }).then((res: any) => {
 				getOneDetail();
 			});
-
 		}
+
 		const addOrEdit = async (row?: any) => {
 			editFormRef.value.open(row);
 		};
 
-
 		onMounted(() => {
 			getDetail();
 		});