Browse Source

控制空调

程志平 3 years ago
parent
commit
2637c1d910
4 changed files with 216 additions and 29 deletions
  1. 38 0
      src/api/serveAC.js
  2. 1 1
      src/utils/request.js
  3. 175 26
      src/views/serveAC/index.vue
  4. 2 2
      src/views/systemSet/index.vue

+ 38 - 0
src/api/serveAC.js

@@ -168,3 +168,41 @@ export function delRooms(forData) {
 		data
 		data
 	})
 	})
 }
 }
+
+// 开空调
+export function startAirs(forData) {
+	let data = new FormData()
+	data.append('admin_name', forData.admin_name)
+	data.append('password', forData.password)
+	data.append('air_ip', forData.air_ip)
+
+	return request({
+		url: '/airManage/consumemana_start.action',
+		method: 'post',
+		data
+	})
+}
+
+// 关空调
+export function stopAirs(forData) {
+	let data = new FormData()
+	data.append('air_ip', forData.air_ip)
+
+	return request({
+		url: '/airManage/consumemana_end.action',
+		method: 'post',
+		data
+	})
+}
+
+// 查询空调开启状态
+export function selAirsStatus(forData) {
+	let data = new FormData()
+	data.append('air_ip', forData.air_ip)
+
+	return request({
+		url: '/airManage/consumeStatus.action',
+		method: 'post',
+		data
+	})
+}

+ 1 - 1
src/utils/request.js

@@ -12,7 +12,7 @@ import {
 const service = axios.create({
 const service = axios.create({
 	baseURL: process.env.VUE_APP_BASE_API, // url = base url + request url
 	baseURL: process.env.VUE_APP_BASE_API, // url = base url + request url
 	// withCredentials: true, // 跨域请求时发送cookie
 	// withCredentials: true, // 跨域请求时发送cookie
-	timeout: 5000 // 请求超时
+	timeout: 10000 // 请求超时
 })
 })
 
 
 // 请求拦截器
 // 请求拦截器

+ 175 - 26
src/views/serveAC/index.vue

@@ -83,7 +83,11 @@
 									</div>
 									</div>
 									<div class="panel-body">
 									<div class="panel-body">
 										<el-table :data="currentData.rooms[0].tableData" height="170"
 										<el-table :data="currentData.rooms[0].tableData" height="170"
-											:cell-style="setCellStyle" :header-cell-style="setHeaderSellStyle">
+											v-loading="airsLoading[0].loading"
+											:element-loading-text="airsLoading[0].text"
+											element-loading-spinner="el-icon-loading"
+											element-loading-background="rgba(0, 0, 0, 0.8)" :cell-style="setCellStyle"
+											:header-cell-style="setHeaderSellStyle">
 											<el-table-column label="名称" align="center">
 											<el-table-column label="名称" align="center">
 												<template slot-scope="scope">
 												<template slot-scope="scope">
 													<span>{{ scope.row.name }}</span>
 													<span>{{ scope.row.name }}</span>
@@ -115,11 +119,11 @@
 											<el-table-column label="开关状态" align="center">
 											<el-table-column label="开关状态" align="center">
 												<template slot-scope="scope">
 												<template slot-scope="scope">
 													<span v-if="scope.row.onOffStatus == 0"
 													<span v-if="scope.row.onOffStatus == 0"
-														@click="open_close_airs(0, scope.$index)">
+														@click="open_close_airs(0, scope.$index, scope.row, 'open')">
 														<svg-icon icon-class="power" class="power-icon" />
 														<svg-icon icon-class="power" class="power-icon" />
 													</span>
 													</span>
 													<span v-else class="txt-cell-blue"
 													<span v-else class="txt-cell-blue"
-														@click="open_close_airs(0, scope.$index)">
+														@click="open_close_airs(0, scope.$index, scope.row, 'close')">
 														<svg-icon icon-class="power" class="power-icon" />
 														<svg-icon icon-class="power" class="power-icon" />
 													</span>
 													</span>
 												</template>
 												</template>
@@ -159,7 +163,11 @@
 									</div>
 									</div>
 									<div class="panel-body">
 									<div class="panel-body">
 										<el-table :data="currentData.rooms[1].tableData" height="170"
 										<el-table :data="currentData.rooms[1].tableData" height="170"
-											:cell-style="setCellStyle" :header-cell-style="setHeaderSellStyle">
+											v-loading="airsLoading[1].loading"
+											:element-loading-text="airsLoading[1].text"
+											element-loading-spinner="el-icon-loading"
+											element-loading-background="rgba(0, 0, 0, 0.8)" :cell-style="setCellStyle"
+											:header-cell-style="setHeaderSellStyle">
 											<el-table-column label="名称" align="center">
 											<el-table-column label="名称" align="center">
 												<template slot-scope="scope">
 												<template slot-scope="scope">
 													<span>{{ scope.row.name }}</span>
 													<span>{{ scope.row.name }}</span>
@@ -191,11 +199,11 @@
 											<el-table-column label="开关状态" align="center">
 											<el-table-column label="开关状态" align="center">
 												<template slot-scope="scope">
 												<template slot-scope="scope">
 													<span v-if="scope.row.onOffStatus == 0"
 													<span v-if="scope.row.onOffStatus == 0"
-														@click="open_close_airs(1, scope.$index)">
+														@click="open_close_airs(1, scope.$index, scope.row, 'open')">
 														<svg-icon icon-class="power" class="power-icon" />
 														<svg-icon icon-class="power" class="power-icon" />
 													</span>
 													</span>
 													<span v-else class="txt-cell-blue"
 													<span v-else class="txt-cell-blue"
-														@click="open_close_airs(1, scope.$index)">
+														@click="open_close_airs(1, scope.$index, scope.row, 'close')">
 														<svg-icon icon-class="power" class="power-icon" />
 														<svg-icon icon-class="power" class="power-icon" />
 													</span>
 													</span>
 												</template>
 												</template>
@@ -237,7 +245,11 @@
 									</div>
 									</div>
 									<div class="panel-body">
 									<div class="panel-body">
 										<el-table :data="currentData.rooms[2].tableData" height="170"
 										<el-table :data="currentData.rooms[2].tableData" height="170"
-											:cell-style="setCellStyle" :header-cell-style="setHeaderSellStyle">
+											v-loading="airsLoading[2].loading"
+											:element-loading-text="airsLoading[2].text"
+											element-loading-spinner="el-icon-loading"
+											element-loading-background="rgba(0, 0, 0, 0.8)" :cell-style="setCellStyle"
+											:header-cell-style="setHeaderSellStyle">
 											<el-table-column label="名称" align="center">
 											<el-table-column label="名称" align="center">
 												<template slot-scope="scope">
 												<template slot-scope="scope">
 													<span>{{ scope.row.name }}</span>
 													<span>{{ scope.row.name }}</span>
@@ -269,11 +281,11 @@
 											<el-table-column label="开关状态" align="center">
 											<el-table-column label="开关状态" align="center">
 												<template slot-scope="scope">
 												<template slot-scope="scope">
 													<span v-if="scope.row.onOffStatus == 0"
 													<span v-if="scope.row.onOffStatus == 0"
-														@click="open_close_airs(2, scope.$index)">
+														@click="open_close_airs(2, scope.$index, scope.row, 'open')">
 														<svg-icon icon-class="power" class="power-icon" />
 														<svg-icon icon-class="power" class="power-icon" />
 													</span>
 													</span>
 													<span v-else class="txt-cell-blue"
 													<span v-else class="txt-cell-blue"
-														@click="open_close_airs(2, scope.$index)">
+														@click="open_close_airs(2, scope.$index, scope.row, 'close')">
 														<svg-icon icon-class="power" class="power-icon" />
 														<svg-icon icon-class="power" class="power-icon" />
 													</span>
 													</span>
 												</template>
 												</template>
@@ -313,7 +325,11 @@
 									</div>
 									</div>
 									<div class="panel-body">
 									<div class="panel-body">
 										<el-table :data="currentData.rooms[3].tableData" height="170"
 										<el-table :data="currentData.rooms[3].tableData" height="170"
-											:cell-style="setCellStyle" :header-cell-style="setHeaderSellStyle">
+											v-loading="airsLoading[3].loading"
+											:element-loading-text="airsLoading[3].text"
+											element-loading-spinner="el-icon-loading"
+											element-loading-background="rgba(0, 0, 0, 0.8)" :cell-style="setCellStyle"
+											:header-cell-style="setHeaderSellStyle">
 											<el-table-column label="名称" align="center">
 											<el-table-column label="名称" align="center">
 												<template slot-scope="scope">
 												<template slot-scope="scope">
 													<span>{{ scope.row.name }}</span>
 													<span>{{ scope.row.name }}</span>
@@ -345,11 +361,11 @@
 											<el-table-column label="开关状态" align="center">
 											<el-table-column label="开关状态" align="center">
 												<template slot-scope="scope">
 												<template slot-scope="scope">
 													<span v-if="scope.row.onOffStatus == 0"
 													<span v-if="scope.row.onOffStatus == 0"
-														@click="open_close_airs(3, scope.$index)">
+														@click="open_close_airs(3, scope.$index, scope.row, 'open')">
 														<svg-icon icon-class="power" class="power-icon" />
 														<svg-icon icon-class="power" class="power-icon" />
 													</span>
 													</span>
 													<span v-else class="txt-cell-blue"
 													<span v-else class="txt-cell-blue"
-														@click="open_close_airs(3, scope.$index)">
+														@click="open_close_airs(3, scope.$index, scope.row, 'close')">
 														<svg-icon icon-class="power" class="power-icon" />
 														<svg-icon icon-class="power" class="power-icon" />
 													</span>
 													</span>
 												</template>
 												</template>
@@ -555,7 +571,10 @@
 		getRoomsAndAirs,
 		getRoomsAndAirs,
 		getOpeningAndAbnomal,
 		getOpeningAndAbnomal,
 		updateRooms,
 		updateRooms,
-		delRooms
+		delRooms,
+		startAirs,
+		stopAirs,
+		selAirsStatus
 	} from '@/api/serveAC'
 	} from '@/api/serveAC'
 	const deviceOptions = ['1匹', '1.5匹', '2匹', '3匹', '天花机器(3匹)'];
 	const deviceOptions = ['1匹', '1.5匹', '2匹', '3匹', '天花机器(3匹)'];
 	export default {
 	export default {
@@ -813,7 +832,20 @@
 					room: ''
 					room: ''
 				},
 				},
 				navLoading: false, // 加载
 				navLoading: false, // 加载
-				listLoading: false
+				listLoading: false,
+				airsLoading: [{
+					loading: false,
+					text: ''
+				}, {
+					loading: false,
+					text: ''
+				}, {
+					loading: false,
+					text: ''
+				}, {
+					loading: false,
+					text: ''
+				}]
 			}
 			}
 		},
 		},
 		created() {
 		created() {
@@ -837,9 +869,116 @@
 			 * @param {Object} roomIndex
 			 * @param {Object} roomIndex
 			 * @param {Object} rowIndex
 			 * @param {Object} rowIndex
 			 */
 			 */
-			open_close_airs(roomIndex, rowIndex) {
-				console.log(this.currentData);
+			open_close_airs(roomIndex, rowIndex, row, open_close) {
+				// console.log(this.currentData.rooms[roomIndex].tableData[rowIndex]);
+				// console.log(row);
+				let air_ip = this.currentData.rooms[roomIndex].tableData[rowIndex].ip;
+				if (open_close == 'open') {
+					this.$set(this.airsLoading[roomIndex], 'loading', true);
+					this.$set(this.airsLoading[roomIndex], 'text', row.name + ' ' + row.device + ' 正在【开机】中...');
+					let user = this.$store.state.user;
+					startAirs({
+						admin_name: user.name,
+						password: user.pwd,
+						air_ip: air_ip
+					}).then((res) => {
+						// console.log(res);
+						if (typeof res.code == 'undefined' || res.code == '') {
+							this.$message.error('返回数据格式问题,code未获取到!')
+							return
+						}
+
+						if (res.code == 200) {
+							this.$set(this.currentData.rooms[roomIndex].tableData[rowIndex], 'onOffStatus',
+								res
+								.is_on)
+							if (res.is_normal == 1) {
+								this.$set(this.currentData.rooms[roomIndex].tableData[rowIndex],
+									'alarmStatus',
+									'正常')
+							} else {
+								this.$set(this.currentData.rooms[roomIndex].tableData[rowIndex],
+									'alarmStatus',
+									'异常')
+							}
+							// let _this = this;
+							// setTimeout(() => {
+							// 	_this.getAirsStatus(roomIndex, rowIndex, air_ip)
+							// }, 4000)
+						} else {
+							this.$message.error(res.message)
+						}
+						this.$set(this.airsLoading[roomIndex], 'loading', false);
+					}).catch((err) => {
+						// console.log(err);
+						this.$message.error(err.message)
+					})
+				} else if (open_close == 'close') {
+					this.$set(this.airsLoading[roomIndex], 'loading', true);
+					this.$set(this.airsLoading[roomIndex], 'text', row.name + ' ' + row.device + ' 正在【关机】中...');
+					stopAirs({
+						air_ip: air_ip
+					}).then((res) => {
+						// console.log(res);
+						if (typeof res.code == 'undefined' || res.code == '') {
+							this.$message.error('返回数据格式问题,code未获取到!')
+							return
+						}
+
+						if (res.code == 200) {
+							this.$set(this.currentData.rooms[roomIndex].tableData[rowIndex], 'onOffStatus',
+								res
+								.is_on)
+							if (res.is_normal == 1) {
+								this.$set(this.currentData.rooms[roomIndex].tableData[rowIndex],
+									'alarmStatus',
+									'正常')
+							} else {
+								this.$set(this.currentData.rooms[roomIndex].tableData[rowIndex],
+									'alarmStatus',
+									'异常')
+							}
+							// let _this = this;
+							// setTimeout(() => {
+							// 	_this.getAirsStatus(roomIndex, rowIndex, air_ip)
+							// }, 4000)
+						} else {
+							this.$message.error(res.message)
+						}
+						this.$set(this.airsLoading[roomIndex], 'loading', false);
+					}).catch((err) => {
+						// console.log(err);
+						this.$message.error(err.message)
+					})
+				}
+			},
+			/**
+			 * 获取空调状态
+			 * @param {Object} roomIndex
+			 * @param {Object} rowIndex
+			 * @param {Object} air_ip
+			 */
+			getAirsStatus(roomIndex, rowIndex, air_ip) {
 				console.log(roomIndex, rowIndex);
 				console.log(roomIndex, rowIndex);
+				selAirsStatus({
+					air_ip: air_ip
+				}).then((res) => {
+					console.log(res);
+					if (typeof res.code == 'undefined' || res.code == '') {
+						this.$message.error('返回数据格式问题,code未获取到!')
+						return
+					}
+
+					if (res.code == 200) {
+						this.currentData.rooms[roomIndex].tableData[rowIndex].onOffStatus == res.is_on
+						this.currentData.rooms[roomIndex].tableData[rowIndex].alarmStatus == res.is_normal
+					} else {
+						this.$message.error(res.message)
+					}
+				}).catch((err) => {
+					// console.log(err);
+					this.$message.error(err.message)
+				})
 			},
 			},
 			/**
 			/**
 			 * 编辑修改房间
 			 * 编辑修改房间
@@ -872,12 +1011,14 @@
 										.children !== 'undefined' && tmp1[j].children.length > 0) {
 										.children !== 'undefined' && tmp1[j].children.length > 0) {
 										let tmp2 = tmp1[j].children;
 										let tmp2 = tmp1[j].children;
 										for (var k = 0; k < tmp2.length; k++) {
 										for (var k = 0; k < tmp2.length; k++) {
-											if (tmp2[k].label == this.form_modify_room.floor && typeof tmp2[k]
+											if (tmp2[k].label == this.form_modify_room.floor &&
+												typeof tmp2[k]
 												.rooms !== 'undefined' && tmp2[k].rooms.length > 0) {
 												.rooms !== 'undefined' && tmp2[k].rooms.length > 0) {
 												let tmp3 = tmp2[k].rooms;
 												let tmp3 = tmp2[k].rooms;
 												for (var p = 0; p < tmp3.length; p++) {
 												for (var p = 0; p < tmp3.length; p++) {
 													if (tmp3[p] == room) {
 													if (tmp3[p] == room) {
-														this.navData[i].children[j].children[k].rooms[p] = this
+														this.navData[i].children[j].children[k].rooms[p] =
+															this
 															.form_modify_room.building + '-' + this
 															.form_modify_room.building + '-' + this
 															.form_modify_room.room;
 															.form_modify_room.room;
 													}
 													}
@@ -927,17 +1068,20 @@
 								.children.length > 0) {
 								.children.length > 0) {
 								let tmp1 = tmp[i].children
 								let tmp1 = tmp[i].children
 								for (var j = 0; j < tmp1.length; j++) {
 								for (var j = 0; j < tmp1.length; j++) {
-									if (tmp1[j].label == data[1] && typeof tmp1[j].children !== 'undefined' &&
+									if (tmp1[j].label == data[1] && typeof tmp1[j].children !==
+										'undefined' &&
 										tmp1[j]
 										tmp1[j]
 										.children.length > 0) {
 										.children.length > 0) {
 										let tmp2 = tmp1[j].children
 										let tmp2 = tmp1[j].children
 										for (var k = 0; k < tmp2.length; k++) {
 										for (var k = 0; k < tmp2.length; k++) {
-											if (tmp2[k].label == data[2] && typeof tmp2[k].rooms !== 'undefined' &&
+											if (tmp2[k].label == data[2] && typeof tmp2[k].rooms !==
+												'undefined' &&
 												tmp2[k].rooms.length > 0) {
 												tmp2[k].rooms.length > 0) {
 												let tmp3 = tmp2[k].rooms
 												let tmp3 = tmp2[k].rooms
 												for (var p = 0; p < tmp3.length; p++) {
 												for (var p = 0; p < tmp3.length; p++) {
 													if (tmp3[p] == room) {
 													if (tmp3[p] == room) {
-														this.navData[i].children[j].children[k].rooms.splice(p, 1)
+														this.navData[i].children[j].children[k].rooms
+															.splice(p, 1)
 													}
 													}
 												}
 												}
 												this.navData[i].children[j].children[k].rooms.sort()
 												this.navData[i].children[j].children[k].rooms.sort()
@@ -1207,7 +1351,8 @@
 				this.currentData.floor = labels[0]
 				this.currentData.floor = labels[0]
 				this.currentData.allRooms = rooms
 				this.currentData.allRooms = rooms
 				// 给右侧窗口标题赋值
 				// 给右侧窗口标题赋值
-				this.currentData.title_any_where = this.currentData.school + '-' + this.currentData.building + '-' + this
+				this.currentData.title_any_where = this.currentData.school + '-' + this.currentData.building +
+					'-' + this
 					.currentData.floor
 					.currentData.floor
 				// 赋值分页数据
 				// 赋值分页数据
 				this.pagination.total = rooms.length
 				this.pagination.total = rooms.length
@@ -1217,12 +1362,14 @@
 					this.pagination.currentPage = size
 					this.pagination.currentPage = size
 				}
 				}
 				// 进行分页处理
 				// 进行分页处理
-				this.roomDataPagination(this.pagination.currentPage, this.pagination.pageSize, this.currentData.allRooms,
+				this.roomDataPagination(this.pagination.currentPage, this.pagination.pageSize, this.currentData
+					.allRooms,
 					this.currentData.school, this.currentData.building, this.currentData.floor);
 					this.currentData.school, this.currentData.building, this.currentData.floor);
 				// 某层房间空调数	
 				// 某层房间空调数	
 				this.getRoomsAndAirs(this.currentData.school, this.currentData.building, this.currentData.floor)
 				this.getRoomsAndAirs(this.currentData.school, this.currentData.building, this.currentData.floor)
 				// 某层空调开启和异常统计
 				// 某层空调开启和异常统计
-				this.getOpeningAndAbnomal(this.currentData.school, this.currentData.building, this.currentData.floor)
+				this.getOpeningAndAbnomal(this.currentData.school, this.currentData.building, this.currentData
+					.floor)
 				this.listLoading = false
 				this.listLoading = false
 			},
 			},
 			/**
 			/**
@@ -1314,7 +1461,8 @@
 			 * 添加房间
 			 * 添加房间
 			 */
 			 */
 			add_room() {
 			add_room() {
-				if (this.currentData.school == '' || this.currentData.building == '' || this.currentData.floor == '') {
+				if (this.currentData.school == '' || this.currentData.building == '' || this.currentData.floor ==
+					'') {
 					this.$message.warning('请选择楼层后,再添加房间!')
 					this.$message.warning('请选择楼层后,再添加房间!')
 					return
 					return
 				}
 				}
@@ -1699,7 +1847,8 @@
 					tableData: []
 					tableData: []
 				}];
 				}];
 				this.pagination.currentPage = val;
 				this.pagination.currentPage = val;
-				this.roomDataPagination(this.pagination.currentPage, this.pagination.pageSize, this.currentData.allRooms,
+				this.roomDataPagination(this.pagination.currentPage, this.pagination.pageSize, this.currentData
+					.allRooms,
 					this.currentData.school, this.currentData.building, this.currentData.floor);
 					this.currentData.school, this.currentData.building, this.currentData.floor);
 				this.listLoading = false;
 				this.listLoading = false;
 			},
 			},

+ 2 - 2
src/views/systemSet/index.vue

@@ -128,8 +128,8 @@
 					var reg = /^[1-9]\d*|0$/
 					var reg = /^[1-9]\d*|0$/
 					if (!reg.test(value)) {
 					if (!reg.test(value)) {
 						callback(new Error('请输入整数或0'));
 						callback(new Error('请输入整数或0'));
-					} else if (value < 8 || value > 59) {
-						callback(new Error('范围在8-59'));
+					} else if (value < 4 || value > 10) {
+						callback(new Error('范围在4-10'));
 					} else {
 					} else {
 						callback();
 						callback();
 					}
 					}