Browse Source

代码同步(场景动作)

yukai 2 years ago
parent
commit
e14430487b

+ 10 - 3
src/views/iot/scene/manage/component/actionItem.vue

@@ -11,7 +11,7 @@
         <div class="icon"></div>串行动作
       </div>
       <div class="product flex flex-warp">
-        <ActionSerialItem :seriallist="item.seriallist"></ActionSerialItem>
+        <ActionSerialItem :seriallist="item.seriallist" :sourceData="sourceData"></ActionSerialItem>
 
       
       </div>
@@ -49,7 +49,11 @@ interface IConditionItem {
   operator?: string;
   value?: string;
 }
-
+interface testIValueType {
+  id: string;
+  key: string;
+  name?: string;
+}
 interface IValueType {
   seriallist?:IConditionItem[] ;
   parallellist?:IConditionItem[] ;
@@ -62,6 +66,10 @@ const props = defineProps({
     default: () => []
   },
 
+  sourceData: {
+    type: Array as PropType<testIValueType[]>,
+    default: () => []
+  },
 })
 
 
@@ -74,7 +82,6 @@ const addAction = () => {
       
     }],
   });
-  console.log(props.actionList);
 };
 const delAction = (index: number) => {
   props.actionList.splice(index, 1);

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

@@ -155,7 +155,6 @@ const addScene = () => {
 										}]
 							}]
   });
-  console.log(props.parallellist);
 };
 const delScene = (index: number) => {
   props.parallellist.splice(index, 1);

+ 24 - 66
src/views/iot/scene/manage/component/actionSerialItem.vue

@@ -9,60 +9,38 @@
         </el-icon>
       </div>
       <div class="product flex flex-warp">
-
-        <el-form-item label="动作类型:" prop="product_key">
-          <el-select v-model="item.product_key" filterable placeholder="请选择动作类型">
+        <el-form-item label="动作类型:" prop="actionType">
+          <el-select v-model="item.actionType" filterable placeholder="请选择动作类型">
             <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>
             </el-option>
           </el-select>
         </el-form-item>
-        <el-form-item label="用户类型:" prop="device_key">
-          <el-select v-model="item.device_key" filterable placeholder="请选择设备">
-            <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>
-            </el-option>
-          </el-select>
-        </el-form-item>
-        <el-form-item label="触发类型:" prop="type">
-          <el-select v-model="item.type" filterable placeholder="请选择触发类型">
-            <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>
-            </el-option>
-          </el-select>
-        </el-form-item>
-
-        <el-form-item label="属性:" prop="type">
-          <el-select v-model="item.type" filterable placeholder="请选择触发类型">
-            <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>
-            </el-option>
-          </el-select>
-        </el-form-item>
+        <DeviceOut :sourceData="sourceData" v-if="item.actionType=='deviceOutput'"></DeviceOut>
+        <SendNotice  v-if="item.actionType=='sendNotice'"></SendNotice>
+        <CallWebService  v-if="item.actionType=='callWebService'"></CallWebService>
       </div>
-
-
     </div>
     <div>
       <div class=" flex-center">
-        <el-button :icon="DocumentAdd" @click="addScene()" style="border: 1px solid #409eff;color: #409eff;">新增串行动作</el-button>
+        <el-button :icon="DocumentAdd" @click="addScene()"
+          style="border: 1px solid #409eff;color: #409eff;">新增串行动作</el-button>
       </div>
     </div>
-
-
-
-
-
   </div>
 </template>
 
 <script lang="ts" setup>
-import { PropType, ref  } from 'vue'
+import { PropType, ref } from 'vue'
 import { DocumentAdd, CircleClose } from '@element-plus/icons-vue';
+import DeviceOut from './actionType/deviceOut.vue';
+import SendNotice from './actionType/sendNotice.vue';
+import CallWebService from './actionType/callWebService.vue';
+
+let product_key = "";
+
+const deviceListData = ref<testIValueType[]>([]);
 
 interface IConditionItem {
   param?: string;
@@ -71,7 +49,10 @@ interface IConditionItem {
 }
 
 interface IValueType {
-  seriallist?: IConditionItem[] ;
+  actionType:'';
+  productKey:'';
+  deviceKey:'';
+  seriallist?: IConditionItem[];
 }
 
 
@@ -90,22 +71,7 @@ const props = defineProps({
   },
   sourceData: {
     type: Array as PropType<testIValueType[]>,
-    default: () => [{
-      'key': 'test',
-      'name': '测试',
-    }, {
-      'key': 'test',
-      'name': '测试',
-    }, {
-      'key': 'test',
-      'name': '测试',
-    }, {
-      'key': 'test',
-      'name': '测试',
-    }, {
-      'key': 'test',
-      'name': '测试',
-    }]
+    default: () => []
   },
   sourceActionTypeData: {
     type: Array as PropType<testIValueType[]>,
@@ -135,24 +101,14 @@ const props = defineProps({
 const addScene = () => {
   props.seriallist.push({
     'product_key': '',
-    'device_key': '',
-    'type': '',
-    'condition':[{
-								'list': [{
-											'param': '',
-											'operator': '',
-											'value': ''
-										}]
-							}]
+
   });
-  console.log(props.seriallist);
 };
 const delScene = (index: number) => {
   props.seriallist.splice(index, 1);
 }
 </script>
 <style scoped lang="scss">
-
 .type-item {
   width: 100%;
 
@@ -176,7 +132,8 @@ const delScene = (index: number) => {
 
   .biankang {
 
-    border: 1px dashed #959596;;
+    border: 1px dashed #959596;
+    ;
     border-radius: 10px;
   }
 
@@ -195,6 +152,7 @@ const delScene = (index: number) => {
 
   .product {
     margin-bottom: 20px;
+
     .el-form-item {
       margin-left: 30px;
       margin-bottom: 10px;

+ 57 - 0
src/views/iot/scene/manage/component/actionType/callWebService.vue

@@ -0,0 +1,57 @@
+<template>
+  <el-form-item label="请求方式" prop="productKey" class="form-item" style="margin-left: 50px;">
+    <el-select v-model="fromData.callWebService.method" filterable placeholder="请选择请求方式" @change="seletChange">
+      <el-option label="POST" value="POST" />
+      <el-option label="GET" value="GET" />
+    </el-select>
+  </el-form-item>
+
+  <el-form-item label="服务地址:" prop="deviceKey" class="form-item">
+    <el-input v-model="fromData.callWebService.url" placeholder="请输入服务地址:" @input="saveData" />
+  </el-form-item>
+
+  <el-form-item label="编码:" prop="executeAction" class="form-item">
+    <el-select v-model="fromData.callWebService.encoding" filterable placeholder="请选择触发类型">
+      <el-option label="UTF-8" value="UTF-8" />
+      <el-option label="GBK" value="GBK" />
+    </el-select>
+  </el-form-item>
+  <el-form-item label="设置请求头:" prop="executeAction" class="form-item">
+      <el-input v-model="fromData.callWebService.headers" type="textarea" />
+  </el-form-item>
+  <el-form-item label="参数编写:" prop="executeAction" class="form-item">
+      <el-input v-model="fromData.callWebService.parameter" type="textarea" />
+  </el-form-item>
+</template>
+
+<script lang="ts" setup>
+import { PropType, ref } from 'vue'
+
+
+
+const fromData = ref({
+  actionType: "callWebService",
+  callWebService: {
+    url: "",
+    method: "",
+    template: "",
+    headers: "",
+    encoding:"",
+    parameter: "",
+  }
+})
+
+
+const saveData = () => {
+  console.log(fromData);
+}
+saveData();
+
+
+</script>
+<style scoped lang="scss">
+.form-item {
+  flex: 0 0 25%;
+
+}
+</style>

+ 190 - 0
src/views/iot/scene/manage/component/actionType/deviceOut.vue

@@ -0,0 +1,190 @@
+<template>
+          <el-form-item label="产品:" prop="productKey" class="form-item" style="margin-left: 50px;">
+            <el-select v-model="fromData.productKey" filterable placeholder="请选择产品"
+              @change="seletChange">
+              <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>
+              </el-option>
+            </el-select>
+          </el-form-item>
+
+          <el-form-item label="设备:" prop="deviceKey" class="form-item">
+            <el-select v-model="fromData.deviceKey" filterable placeholder="请选择设备">
+              <el-option v-for="it in deviceListData" :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="触发类型:" prop="executeAction" class="form-item">
+            <el-select v-model="fromData.executeAction" filterable placeholder="请选择触发类型" @change="getAction">
+              <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>
+              </el-option>
+            </el-select>
+          </el-form-item>
+
+          <el-form-item label="功能调用" prop="type" class="form-item" v-if="fromData.executeAction=='functionCall'">
+            <el-select v-model="fromData.functionCall.functionName" filterable placeholder="请选择触发类型">
+              <el-option v-for="it in functionCallList" :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="参数" prop="type" class="form-item" v-if="fromData.executeAction=='functionCall'">
+                <el-input v-model="fromData.functionCall.parameter" placeholder="请输入参数" @input="saveData" />
+          </el-form-item>
+
+
+          
+          <el-form-item label="读取属性" prop="type" class="form-item" v-if="fromData.executeAction=='getProperties'">
+            <el-select v-model="fromData.getProperties" filterable multiple  placeholder="请选择读取属性" @change="saveData">
+              <el-option v-for="it in propertyCallList" :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="设置属性" prop="type" class="form-item" v-if="fromData.executeAction=='setProperties'">
+            <el-select v-model="fromData.setProperties_temp" filterable multiple  placeholder="请选择设置属性" @change="setProperties">
+              <el-option v-for="it in propertyCallList" :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>
+          <div class="form-item" v-if="fromData.executeAction=='setProperties'">
+            <el-table :data="setPropertiesItem">
+                <el-table-column>
+                  <template #default="{row}">
+                    <span>{{row.name}}</span>
+                  </template>
+                </el-table-column>
+                <el-table-column >
+                  <template #default="{row}">
+                    <el-input v-model="row.value" @input="saveSetData"></el-input>
+                  </template>
+                </el-table-column>
+              </el-table>
+          </div>
+
+</template>
+
+<script lang="ts" setup>
+import { PropType, ref  } from 'vue'
+import product from '/@/api/device';
+import datahub from '/@/api/datahub';
+interface testIValueType {
+  id?: string;
+  key?: string;
+  name?: string;
+}
+const props = defineProps({
+  sourceData: {
+    type: Array as PropType<testIValueType[]>,
+    default: () => []
+  },
+  sourceActionTypeData: {
+    type: Array as PropType<testIValueType[]>,
+    default: () => [{
+      'key': 'functionCall',
+      'name': '功能调用',
+    }, {
+      'key': 'getProperties',
+      'name': '获取属性',
+    }, {
+      'key': 'setProperties',
+      'name': '设置属性',
+    }]
+  },
+})
+const deviceListData = ref<testIValueType[]>([]);
+const functionCallList=ref<testIValueType[]>([]);
+const propertyCallList=ref<testIValueType[]>([]);
+const productKey=ref();
+const setPropertiesItem=ref([]);
+const fromData=ref({
+  actionType: "deviceOut", 
+  productKey: "",
+  deviceKey: "",
+  executeAction:"",
+  functionCall: {
+    functionName: "",
+    parameter: ""
+  },
+  getProperties:{},
+  setProperties:[],
+  setProperties_temp:[],
+})
+
+//获取类型数据
+const getAction=(val:string)=>{
+    switch(val){
+      case 'functionCall':
+        product.tabDeviceFucntion.getList({ key: productKey.value }).then((res: any) => {
+          functionCallList.value = res
+        })
+      break;
+      case 'getProperties':
+        datahub.node.getpropertyList({ key: productKey.value }).then((re: any) => {
+          propertyCallList.value=re;
+        });
+  
+      break;
+      case 'setProperties':
+        datahub.node.getpropertyList({ key: productKey.value }).then((re: any) => {
+          propertyCallList.value=re;
+        });
+      break;
+    }
+}
+
+const saveSetData=()=>{
+  fromData.value.setProperties = setPropertiesItem.value; 
+  console.log(fromData);
+
+}
+const setProperties=(val:any)=>{
+  setPropertiesItem.value = val.map((item:string) => {
+        return {
+          name: item,
+          value: ''
+        };
+      });
+
+       fromData.value.setProperties = setPropertiesItem.value;
+       console.log(fromData);
+}
+const saveData=()=>{
+  console.log(fromData.value);
+}
+
+const getDeviceList = (_id: any) => {
+  product.device.allList({ productId: _id }).then((res: any) => {
+    deviceListData.value = res.device
+  })
+}
+const seletChange = (val:string) => {
+  productKey.value=val;
+  //根据产品key获取产品ID
+  let info = props.sourceData?.find((pro: testIValueType) => pro.key === val);
+  if (info) {
+    // 重置 deviceKey 的值
+    fromData.value.deviceKey = '';
+    getDeviceList(info.id)
+  }
+}
+</script>
+<style scoped lang="scss">
+.form-item{
+  flex: 0 0 25%;
+
+}
+</style>

+ 100 - 0
src/views/iot/scene/manage/component/actionType/sendNotice.vue

@@ -0,0 +1,100 @@
+<template>
+  <el-form-item label="通知方式" prop="productKey" class="form-item" style="margin-left: 50px;">
+    <el-select v-model="fromData.notice.types" filterable placeholder="请选择通知方式" @change="seletChange">
+      <el-option v-for="item in notice_send_gateway" :key="item.value" :label="item.label" :value="item.value" />
+    </el-select>
+  </el-form-item>
+
+  <el-form-item label="通知配置:" prop="deviceKey" class="form-item">
+    <el-select v-model="fromData.notice.name" filterable placeholder="请选择通知配置" @change="getTemplist">
+      <el-option v-for="item in sendGatewayData" :key="item.id" :label="item.title" :value="item.id" />
+    </el-select>
+  </el-form-item>
+
+  <el-form-item label="通知模板:" prop="executeAction" class="form-item">
+    <el-select v-model="fromData.notice.template" filterable placeholder="请选择触发类型">
+      <el-option v-for="item in noticeConfigData" :key="item.id" :label="item.title" :value="item.id" />
+    </el-select>
+  </el-form-item>
+
+
+  <div class="form-item" v-for="(ph, phindex) in fromData.notice.object_temp" :key="phindex">
+    <el-input v-model="ph.info" placeholder="请输入接收人信息" style="width: 320px" @input="saveData" />
+    <el-icon style="width: 32px; height: 32px; font-size: 24px" v-if="phindex == 0" @click="AddPhone(index)">
+      <CirclePlus />
+    </el-icon>
+    <el-icon style="width: 32px; height: 32px; font-size: 24px" v-if="phindex > 0" @click="DelPhone( phindex)">
+      <Remove />
+    </el-icon>
+  </div>
+</template>
+
+<script lang="ts" setup>
+import { PropType, ref, getCurrentInstance } from 'vue'
+import notice from '/@/api/notice';
+import { CirclePlus, Remove } from '@element-plus/icons-vue';
+
+const { proxy } = getCurrentInstance() as any;
+const { notice_send_gateway } = proxy.useDict('notice_send_gateway');
+const sendGatewayData = ref([]);
+const noticeConfigData = ref([]);
+interface testIValueType {
+  id?: string;
+  key?: string;
+  name?: string;
+}
+const props = defineProps({
+  sourceData: {
+    type: Array as PropType<testIValueType[]>,
+    default: () => []
+  },
+})
+const fromData = ref({
+  actionType: "notice",
+  notice: {
+    types: "",
+    name: "",
+    template: "",
+    object: {},
+    object_temp: [{
+      info:'',
+    }]
+  }
+})
+const AddPhone = () => {
+  fromData.value.notice.object_temp.push({
+    info:'',
+  });
+};
+
+const DelPhone = (index: number) => {
+  fromData.value.notice.object_temp.splice(index, 1);
+};
+const seletChange = (val: string) => {
+  notice.config.getList({ sendGateway: val }).then((res: any) => {
+    sendGatewayData.value = res.Data;
+  });
+}
+
+const getTemplist = (val: number) => {
+  notice.template.configIddetail(val).then((res: any) => {
+    noticeConfigData.value = [res];
+  });
+}
+
+const saveData = () => {
+  const result = fromData.value.notice.object_temp.map(item => item.info);
+  fromData.value.notice.object = result;
+
+  console.log(fromData);
+}
+saveData();
+
+
+</script>
+<style scoped lang="scss">
+.form-item {
+  flex: 0 0 25%;
+
+}
+</style>

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

@@ -229,7 +229,6 @@ const cronclose = () => {
 }
 //初始化
 const intScenel=()=>{
-  console.log(props.sourceData);
   let array_data=props.sceneList;
   array_data.map((val:any,index) => {
       if(val.productKey){

+ 1 - 1
src/views/iot/scene/manage/detail.vue

@@ -111,7 +111,7 @@ export default defineComponent({
 			api.manage.getOneDetail({ "sceneId": id, 'group': 'definition' }).then((res: any) => {
 				if (!res) {
 					addScenesDetail('definition');
-					getOneDetail();
+					// getOneDetail();
 				}
 				originalSceneList.value = res;
 				const scenes = res.map((scene: any) => {