Explorar el Código

新增样表下载

yukai hace 2 años
padre
commit
7f95ee7aff

BIN
public/example.xlsx


BIN
src/assets/example.xlsx


+ 20 - 2
src/views/iot/device/instance/component/excel.vue

@@ -19,12 +19,17 @@
           </el-upload>
           <div>{{ ruleForm.path }}</div>
         </el-form-item>
-
+        <el-form-item label="样表下载" v-if="open_type === 'upload'">
+          <el-button  @click="down" type="primary" text="primary">
+              <el-icon> <ele-Download /> </el-icon>
+              下载文件
+            </el-button>
+        </el-form-item>
       </el-form>
       <template #footer>
         <span class="dialog-footer">
           <el-button @click="onCancel" size="default">取 消</el-button>
-          <el-button type="primary" @click="onSubmit" size="default">{{ open_type === 'upload' ? '导入设备' : '导出设备'
+          <el-button type="primary" @click="onSubmit" size="default" v-if="open_type !== 'upload'">{{ open_type === 'upload' ? '导入设备' : '导出设备'
           }}</el-button>
         </span>
       </template>
@@ -149,10 +154,23 @@ export default defineComponent({
         }
       });
     };
+    const down=()=>{
+      const fileURL = '/example.xlsx';
+      // 创建下载链接
+      const link = document.createElement('a');
+      link.href = fileURL;
+      link.setAttribute('download', 'example.xlsx');
+
+      // 模拟点击下载链接进行下载
+      document.body.appendChild(link);
+      link.click();
+      document.body.removeChild(link);
+    }
     return {
       uploadUrl,
       headers,
       tagRef,
+      down,
       updateImg,
       openDialog,
       closeDialog,

+ 1 - 1
src/views/iot/device/instance/index.vue

@@ -106,7 +106,7 @@
             <el-tag type="info" size="small" v-if="scope.row.status == 0">未启用</el-tag>
           </template>
         </el-table-column>
-        <el-table-column prop="registryTime" label="激活时间" align="center" width="150"
+        <el-table-column prop="createdAt" label="创建时间" align="center" width="160"
           v-col="'registryTime'"></el-table-column>
         <!--        <el-table-column prop="lastOnlineTime" label="最后上线时间" align="center" width="150" v-col="'lastOnlineTime'"></el-table-column>-->
         <el-table-column prop="desc" label="说明" v-col="'desc'"></el-table-column>

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

@@ -11,7 +11,6 @@
         <div class="icon"></div>触发规则
       </div>
       <div class="product flex flex-warp">
-
         <el-form-item label="产品:" prop="productKey">
           <el-select v-model="item.productKey" filterable placeholder="请选择产品"
             @change="seletChange(index, item.productKey!)">
@@ -50,7 +49,6 @@
           </div>
         </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>
@@ -63,11 +61,6 @@
         <el-button type="primary" :icon="DocumentAdd" @click="addScene()">新增场景定义</el-button>
       </div>
     </div>
-
-
-
-
-
   </div>
 </template>
 
@@ -80,12 +73,8 @@ import product from '/@/api/device';
 import Condition from './condition.vue';
 const { proxy } = getCurrentInstance() as any;
 const scene_type = proxy.useDict('scene_type');
-
 const emit = defineEmits(['addScenesDetail','delScenesDetail','editScenesDetail']);
-
 const dialogVisible = ref();
-const sourceData = ref<testIValueType[]>([]);
-
 const deviceListData = ref<testIValueType[]>([]);
 const columnList = ref([]);
 let product_key = "";
@@ -94,7 +83,6 @@ interface IConditionItem {
   operator?: string;
   value?: string;
 }
-
 interface IValueType {
   triggerType?: string;
   productKey?: string;
@@ -103,30 +91,24 @@ interface IValueType {
   timer?: string;
   condition?: IConditionItem[][]; // 更新这里的类型定义
 }
-
-
 interface testIValueType {
   id: string;
   key: string;
   name?: string;
-
 }
-
-
-
 const props = defineProps({
-
   sceneList: {
     type: Array as PropType<IValueType[]>,
     default: () => [],
   },
-
   sceneType: {
     type: String,
     default: () => '',
   },
-
-
+  sourceData:{
+    type: Array as PropType<testIValueType[]>,
+    default: () => []
+  },
   sourceTypeData: {
     type: Array as PropType<testIValueType[]>,
     default: () => [{
@@ -154,21 +136,10 @@ const props = defineProps({
   }
 })
 
-
-
-
-const getProductList = () => {
-  product.product.getSubList().then((res: any) => {
-    sourceData.value = res.product;
-    intScenel();
-  });
-};
-
-
 const seletChange = (index: number, val: string) => {
   product_key = val;
   //根据产品key获取产品ID
-  let info = unref(sourceData)?.find((pro: { key: any; }) => pro.key === val);
+  let info = props.sourceData?.find((pro: { key: any; }) => pro.key === val);
 
   if (info) {
     // 重置 deviceKey 的值
@@ -188,19 +159,15 @@ const getDeviceList = (_id: any) => {
     deviceListData.value = res.device
   })
 }
-
 const getSelectcolumns=(index: number, val: string) => {
   EditPen(index);
-
   getcolumns(index,val);
-
     // 重置当前项的 condition 值
     props.sceneList[index].condition = [[{
     'parameter': '',
     'operator': '',
     'value': ''
   }]];
-
 }
 const getcolumns = (index: number, val: string) => {
   let where = {
@@ -215,9 +182,6 @@ const getcolumns = (index: number, val: string) => {
     }
   }
   getcolumnsList(where);
-  
-
-
 }
 const getcolumnsList = (where: any) => {
   api.manage.getColumns(where).then((res: any) => {
@@ -245,11 +209,9 @@ const addScene = () => {
 
 const EditPen=(index: number)=>{
   emit('editScenesDetail',index);
-
 }
 const delScene = (index: number) => {
   emit('delScenesDetail', index);
-
   props.sceneList.splice(index, 1);
 }
 const setNull = (row: any, key: string, val: string) => {
@@ -258,25 +220,21 @@ const setNull = (row: any, key: string, val: string) => {
 const handlelisten = (e: any) => {
   props.sceneList[e.type].timer = e.cron;
   EditPen(e.type);
-
 };
 const showCron = () => {
   dialogVisible.value = true;
-
 };
 const cronclose = () => {
   dialogVisible.value = false;
 }
-
 //初始化
 const intScenel=()=>{
+  console.log(props.sourceData);
   let array_data=props.sceneList;
-  console.log(array_data);
-
   array_data.map((val:any,index) => {
       if(val.productKey){
           product_key = val.productKey;
-          let info = unref(sourceData)?.find((pro: { key: any; }) => pro.key === val.productKey);
+          let info = props.sourceData?.find((pro: { key: any; }) => pro.key === val.productKey);
 
           if (info) {
             getDeviceList(info.id)
@@ -287,8 +245,7 @@ const intScenel=()=>{
       } 
   });
 }
-getProductList(); 
-
+intScenel();
 </script>
 <style scoped lang="scss">
 .type-item {
@@ -311,21 +268,14 @@ getProductList();
 
   .item {
     padding: 10px;
-    // background-color: #f2f3f5;
-
   }
-
   .biankang {
-
     border: 1px solid #e8e2e2;
-    ;
     border-radius: 10px;
     padding: 10px;
     margin-top: 10px;
   }
-
-
-  .title {
+    .title {
     height: 40px;
 
     .icon {
@@ -336,16 +286,13 @@ getProductList();
       background-color: #315efb;
     }
   }
-
   .product {
-
     .el-form-item {
       margin-left: 30px;
       margin-bottom: 10px;
       margin-top: 10px;
     }
   }
-
 }
 </style>
 

+ 12 - 6
src/views/iot/scene/manage/detail.vue

@@ -16,26 +16,26 @@
 	</el-card>
 	<el-card style="  margin-top: 15px;">
 		<div class="font20">场景定义</div>
-		<SceneItem v-if="showstatus" :sceneList="sceneList" :sceneType="detail.sceneType" @addScenesDetail="addScenesDetail"
+		<SceneItem v-if="showstatus && sourceData.length>0" :sceneList="sceneList" :sourceData="sourceData" :sceneType="detail.sceneType" @addScenesDetail="addScenesDetail"
 			@delScenesDetail="delScenesDetail" @editScenesDetail="editScenesDetail"></SceneItem>
 	</el-card>
 	<el-card style="  margin-top: 15px;">
 		<div class="font20">场景动作</div>
-		<ActionItem :actionList="actionList"></ActionItem>
+		<ActionItem :actionList="actionList"  :sourceData="sourceData"></ActionItem>
 	</el-card>
 
 	<EditForm ref="editFormRef" @getList="getDetail()"></EditForm>
 </template>
 <script lang="ts">
-import { toRefs, reactive, onMounted, ref, defineComponent } from 'vue';
-import { ElMessage } from 'element-plus';
-import type { TabsPaneContext } from 'element-plus'
+import { toRefs, reactive, ref, defineComponent } from 'vue';
 import { useRoute, useRouter } from 'vue-router';
 import { EditPen, DocumentAdd } from '@element-plus/icons-vue';
 import ActionItem from './component/actionItem.vue';
 import SceneItem from './component/sceneItem.vue';
 import EditForm from './edit.vue';
 import api from '/@/api/scene';
+import product from '/@/api/device';
+
 const editFormRef = ref();
 //原始
 const sceneList = {
@@ -45,7 +45,6 @@ const sceneList = {
 	'timer': '',
 	'triggerSwitch': false,
 	'condition': [[{
-
 		'parameter': '',
 		'operator': '',
 		'value': ''
@@ -63,6 +62,7 @@ export default defineComponent({
 		const state = reactive({
 			developer_status: 2,
 			showstatus: false,
+			sourceData: [],
 			detail: {
 				name: '',
 				status: 0,
@@ -100,6 +100,11 @@ export default defineComponent({
 			})
 			getOneDetail();
 		};
+		const getProductList = () => {
+			product.product.getSubList().then((res: any) => {
+				state.sourceData = res.product;
+			});
+		};
 
 		const getOneDetail = () => {
 			const id = route.params && route.params.id;
@@ -115,6 +120,7 @@ export default defineComponent({
 						...parsedBodyJson
 					};
 				});
+				getProductList();
 				state.sceneList = scenes;
 				state.showstatus = true;
 			})