Selaa lähdekoodia

增加子设备功能

vera_min 2 vuotta sitten
vanhempi
sitoutus
22d5aa08ea

+ 2 - 0
src/api/device/index.ts

@@ -17,6 +17,7 @@ export default {
     deploy: (data: object) => post('/product/deploy', data),
     undeploy: (data: object) => post('/product/undeploy', data),
     event: (data: object) => get('/product/tsl/event/all', data),
+    getSubList: () => get('/product/sub_list'),
     // 获取插件通信方式类型
     getTypesAll: (data: object) => get('/system/plugins/getTypesAll', data),
   },
@@ -73,6 +74,7 @@ export default {
   },
   device: {
     getList: (params: object) => get('/product/device/bind_list', params),
+    getSubList: (params: object) => get('/product/device/sub_list', params),
     mutipleBind: (data: object) => post('/product/device/bind_sub', data),
     mutipleUnbind: (data: object) => post('/product/device/unbind_sub', data),
   }

+ 213 - 0
src/views/iot/device/instance/component/subDeviceMutipleBind.vue

@@ -0,0 +1,213 @@
+<template>
+	<div class="mutiple-bind-dialog-wrap">
+		<el-dialog title="批量绑定子设备" v-model="isShowDialog" width="90%">
+			<el-form :model="ruleForm" ref="formRef" :rules="rules" size="small" label-width="110px">
+				<el-form-item label="所属产品" prop="productId">
+					<el-select @change="handleChange" v-model="ruleForm.productId" placeholder="请选择所属产品" style="width: 300px;">
+						<el-option v-for="item in productData" :key="item.id" :label="item.name" :value="item.id" />
+					</el-select>
+					<el-button style="margin-left: 20px;" :disabled="!deviceKeyList.length" v-auth="'mutipleBind'" type="primary" @click="confirmBind()">批量绑定</el-button>
+
+				</el-form-item>
+			</el-form>
+			<el-table :data="tableData.data" style="width: 100%" @selection-change="handleSelectionChange" v-loading="tableData.loading">
+				<el-table-column type="selection" width="55" align="center" />
+				<el-table-column label="标识" prop="key" width="130" :show-overflow-tooltip="true" v-col="'key'" />
+				<el-table-column label="设备名称" prop="name" :show-overflow-tooltip="true" v-col="'name'" />
+				<el-table-column label="产品名称" prop="productName" :show-overflow-tooltip="true" v-col="'productName'" />
+
+				<el-table-column prop="status" label="状态" width="100" align="center" v-col="'status'">
+				<template #default="scope">
+					<el-tag type="info" size="small" v-if="scope.row.status==1">离线</el-tag>
+					<el-tag type="success" size="small" v-if="scope.row.status==2">在线</el-tag>
+					<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" v-col="'registryTime'"></el-table-column>
+				<el-table-column prop="desc" label="说明" v-col="'desc'"></el-table-column>
+
+			</el-table>
+			<pagination
+				v-show="tableData.total > 0"
+				:total="tableData.total"
+				v-model:page="tableData.param.pageNum"
+				v-model:limit="tableData.param.pageSize"
+				@pagination="getDeviceList"
+			/>
+
+		</el-dialog>
+	</div>
+</template>
+<script lang="ts">
+import { toRefs, reactive, onMounted, ref, defineComponent } from 'vue'
+import { ElMessageBox, ElMessage, FormInstance } from 'element-plus'
+
+import 'vue3-json-viewer/dist/index.css'
+
+import { useRoute } from 'vue-router'
+
+import api from '/@/api/device'
+
+interface TableDataState {
+    isShowDialog: boolean,
+	productData: object[],
+	deviceKeyList: string[];
+	gatewayKey: string;
+	tableData: {
+		data: []
+		total: number
+		loading: boolean
+		param: {
+			pageNum: number
+			pageSize: number
+			productId: number
+			status: string
+			dateRange: string[]
+		}
+	},
+	ruleForm: {
+		productId: string|number
+	},
+	rules: {}
+
+
+}
+export default defineComponent({
+	name: 'MutipleBindDialog',
+	// components: { EditDic, EditAttr, EditFun, EditEvent, EditTab, devantd, ListDic, functionCom },
+
+	setup(prop, { emit }) {
+		console.log(prop)
+		const route = useRoute()
+		// const editDicRef = ref()
+		const state = reactive<TableDataState>({
+			gatewayKey: '',
+			deviceKeyList: [],
+			isShowDialog: false,
+			productData: [],
+			tableData: {
+				data: [],
+				total: 0,
+				loading: false,
+				param: {
+					pageNum: 1,
+					pageSize: 10,
+					productId: 0,
+					status: '',
+					dateRange: [],
+				},
+			},
+			ruleForm: {
+				productId: ''
+			},
+			rules: {
+				productId: [{ required: true, message: '所属产品不能为空', trigger: 'blur' }],
+			}
+		})
+
+		onMounted(() => {
+			console.log('第一次加载')
+			// getProductList()
+		})
+
+		const getDeviceList = () => {
+			if(!state.ruleForm.productId) {
+				state.tableData.data = [];
+				state.tableData.total = 0;
+				return;
+			}
+
+			state.tableData.loading = true;
+			api.device.getSubList({
+				"productId": state.ruleForm.productId,
+				"pageSize": state.tableData.param.pageSize,
+				"pageNum": state.tableData.param.pageNum
+			}).then((res: any) => {
+				console.log(res)
+				state.tableData.data = res.device;
+				state.tableData.total = res.Total;
+			}).finally(() => (state.tableData.loading = false));
+
+		};
+
+		const getProductList = () => {
+			api.product.getSubList().then((res: any) => {
+				let productDataList = [{id: "", name: "全部"}].concat(res.product)
+				state.productData = productDataList;
+				state.ruleForm.productId = state.productData[0].id
+				getDeviceList()
+				state.isShowDialog = true;
+			});
+		};
+
+		const openDialog = (gatewayKey: any) => {
+			console.log('第二次加载')
+			state.gatewayKey = gatewayKey;
+			getProductList()
+			// state.isShowDialog = true;
+		};
+
+		    // 多选框选中数据
+		const handleSelectionChange = (selection: any[]) => {
+			console.log(selection)
+			console.log(typeof selection)
+			// selection.forEach((item:any) => {
+			//   console.log(item)
+			//   state.deviceKeyList.push(item.key)
+			// })
+			state.deviceKeyList = selection.map((item) => item.key);
+			console.log(state.deviceKeyList)
+			console.log(typeof state.deviceKeyList)
+		};
+
+		const confirmBind = () => {
+			let msg = '是否进行批量绑定?';
+			if (state.deviceKeyList.length === 0) {
+				ElMessage.error('请选择要批量绑定的数据。');
+				return;
+			}
+				// return
+			ElMessageBox.confirm(msg, '提示', {
+				confirmButtonText: '确认',
+				cancelButtonText: '取消',
+				type: 'warning',
+			})
+			.then(() => {
+				api.device.mutipleBind({
+					"gatewayKey":state.gatewayKey,
+					"subKeys": state.deviceKeyList
+				}).then(() => {
+					ElMessage.success('绑定成功');
+					emit('bindSuccess')
+					state.isShowDialog = false;
+				});
+			})
+			.catch(() => { });
+		};
+
+		const handleChange = (productId: number) => {
+			state.ruleForm.productId = productId;
+			getDeviceList()
+		}
+
+		return {
+			openDialog,
+			getProductList,
+			confirmBind,
+			getDeviceList,
+			handleSelectionChange,
+			handleChange,
+			...toRefs(state),
+		}
+	},
+})
+</script>
+
+<style lang="scss" scoped>
+.mutiple-bind-dialog-wrap {
+	background: pink;
+}
+
+</style>
+
+

+ 11 - 30
src/views/iot/device/instance/detail.vue

@@ -282,7 +282,7 @@
             <div class="wu-title">
               <div class="title">子设备列表</div>
               <div>
-                <el-button v-auth="'mutipleBind'" type="primary" @click="mutipleBind()">批量绑定</el-button>
+                <el-button v-auth="'mutipleBind'" type="primary" @click="onOpenMutipleBind()">批量绑定</el-button>
                 <el-button :disabled="!deviceKeyList.length" type="primary" @click="mutipleUnbind()">批量解绑</el-button>
               </div>
             </div>
@@ -322,6 +322,8 @@
     <EditTab ref="editTabRef" @typeList="gettab" />
     <ListDic ref="listDicRef" />
     <SubDevice ref="subDeviceRef" />
+    <!-- 子设备-批量绑定弹窗 -->
+    <SubDeviceMutipleBind ref="mutipleBindRef" @bindSuccess="getDeviceTableData" />
 
     <el-dialog v-model="dialogVisible" title="返回Json数据" width="30%">
       <JsonViewer :value="jsonData" boxed sort theme="jv-dark" @click="onKeyclick" />
@@ -349,6 +351,7 @@ import EditTab from '../product/component/editTab.vue';
 import devantd from '/@/components/devantd/index.vue';
 import ListDic from './component/list.vue';
 import SubDevice from './component/subDevice.vue';
+import SubDeviceMutipleBind from './component/subDeviceMutipleBind.vue';
 
 
 import { useRoute } from 'vue-router';
@@ -400,7 +403,7 @@ interface TableDataState {
 }
 export default defineComponent({
   name: 'deviceEditPro',
-  components: { SubDevice, EditDic, EditAttr, EditFun, EditEvent, EditTab, devantd, ListDic, functionCom },
+  components: { SubDeviceMutipleBind, SubDevice, EditDic, EditAttr, EditFun, EditEvent, EditTab, devantd, ListDic, functionCom },
 
 	setup(prop, context) {
 		const route = useRoute();
@@ -411,6 +414,7 @@ export default defineComponent({
 		const editEventRef = ref();
 		const editTabRef = ref();
     const subDeviceRef = ref();
+    const mutipleBindRef = ref();
 		const state = reactive<TableDataState>({
       deviceKeyList: [],
 			areaData:[],
@@ -485,33 +489,6 @@ export default defineComponent({
 
 		});
 
-    const mutipleBind = () => {
-      let msg = '是否进行批量绑定?';
-      if (state.deviceKeyList.length === 0) {
-        ElMessage.error('请选择要批量绑定的数据。');
-        return;
-      }
-      console.log(state.deviceKeyList)
-      console.log(state.deviceKeyList.length)
-        // return
-      ElMessageBox.confirm(msg, '提示', {
-        confirmButtonText: '确认',
-        cancelButtonText: '取消',
-        type: 'warning',
-      })
-        .then(() => {
-          api.device.mutipleBind({
-            "gatewayKey":state.deviceTableData.param.gatewayKey,
-            "subKeys": state.deviceKeyList
-          }).then(() => {
-            ElMessage.success('绑定成功');
-            // typeList();
-            getDeviceTableData();
-          });
-        })
-        .catch(() => { });
-    }
-
     const mutipleUnbind = () => {
       let msg = '是否进行批量解绑?';
       if (state.deviceKeyList.length === 0) {
@@ -575,6 +552,9 @@ export default defineComponent({
       state.dialogVisible = true;
     };
 
+    const onOpenMutipleBind = () => {
+      mutipleBindRef.value.openDialog(state.deviceTableData.param.gatewayKey);
+    };
     
 
     //编辑属性
@@ -825,6 +805,7 @@ export default defineComponent({
       editEventRef,
       editTabRef,
       subDeviceRef,
+      mutipleBindRef,
       onOpenListDetail,
       getrunData,
       getlog,
@@ -851,7 +832,7 @@ export default defineComponent({
       onOpenEditDic,
       onOpenDetail,
       handleClick,
-      mutipleBind,
+      onOpenMutipleBind,
       mutipleUnbind,
       ...toRefs(state),
     };