فهرست منبع

开关设备优化,携带头部信息,

soft5566 3 سال پیش
والد
کامیت
24e111aac4
4فایلهای تغییر یافته به همراه114 افزوده شده و 77 حذف شده
  1. 3 1
      src/store/modules/user.js
  2. 9 0
      src/utils/auth.js
  3. 3 1
      src/utils/request.js
  4. 99 75
      src/views/serveAC/index.vue

+ 3 - 1
src/store/modules/user.js

@@ -6,7 +6,8 @@ import {
 import {
 import {
 	getToken,
 	getToken,
 	setToken,
 	setToken,
-	removeToken
+	removeToken,
+	setName
 } from '@/utils/auth'
 } from '@/utils/auth'
 import {
 import {
 	resetRouter
 	resetRouter
@@ -71,6 +72,7 @@ const actions = {
 					const token = 'admin_token'
 					const token = 'admin_token'
 					commit('SET_TOKEN', token)
 					commit('SET_TOKEN', token)
 					setToken(token)
 					setToken(token)
+					setName(response.data[0].admin_name)
 					// 添加:
 					// 添加:
 					commit('SET_LEVEL', response.data[0].level)
 					commit('SET_LEVEL', response.data[0].level)
 					commit('SET_NAME', response.data[0].admin_name)
 					commit('SET_NAME', response.data[0].admin_name)

+ 9 - 0
src/utils/auth.js

@@ -1,6 +1,7 @@
 import Cookies from 'js-cookie'
 import Cookies from 'js-cookie'
 
 
 const TokenKey = 'admin_token'
 const TokenKey = 'admin_token'
+const AdminName = 'admin_name'
 
 
 export function getToken() {
 export function getToken() {
   return Cookies.get(TokenKey)
   return Cookies.get(TokenKey)
@@ -12,4 +13,12 @@ export function setToken(token) {
 
 
 export function removeToken() {
 export function removeToken() {
   return Cookies.remove(TokenKey)
   return Cookies.remove(TokenKey)
+}
+
+export function setName(name) {
+  return Cookies.set(AdminName, name)
+}
+
+export function getName() {
+	return Cookies.get(AdminName)
 }
 }

+ 3 - 1
src/utils/request.js

@@ -5,7 +5,8 @@ import {
 } from 'element-ui'
 } from 'element-ui'
 import store from '@/store'
 import store from '@/store'
 import {
 import {
-	getToken
+	getToken,
+	getName
 } from '@/utils/auth'
 } from '@/utils/auth'
 
 
 // 创建axios实例
 // 创建axios实例
@@ -25,6 +26,7 @@ service.interceptors.request.use(
 			// ['X-Token'] 是否为自定义标题键
 			// ['X-Token'] 是否为自定义标题键
 			// 请根据实际情况进行修改
 			// 请根据实际情况进行修改
 			config.headers['X-Token'] = getToken()
 			config.headers['X-Token'] = getToken()
+			config.headers['admin_name'] = getName()
 		}
 		}
 		return config
 		return config
 	},
 	},

+ 99 - 75
src/views/serveAC/index.vue

@@ -893,86 +893,110 @@
 				// console.log(row);
 				// console.log(row);
 				let air_ip = this.currentData.rooms[roomIndex].tableData[rowIndex].ip;
 				let air_ip = this.currentData.rooms[roomIndex].tableData[rowIndex].ip;
 				if (open_close == 'open') {
 				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', '正常')
+					this.$confirm('是否开启设备:' + row.name + ' ' + row.device, '提示', {
+						confirmButtonText: '是的',
+						cancelButtonText: '不用了',
+						type: 'warning'
+					}).then(() => {
+						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 {
 							} else {
-								this.$set(this.currentData.rooms[roomIndex].tableData[rowIndex],
-									'alarmStatus', '离线')
+								this.$message.error(res.message)
 							}
 							}
-							// let _this = this;
-							// setTimeout(() => {
-							// 	_this.getAirsStatus(roomIndex, rowIndex, air_ip)
-							// }, 4000)
-						} else {
-							this.$message.error(res.message)
-						}
-						this.$set(this.airsLoading[roomIndex], 'loading', false);
-						// 刷新顶部数据
-						this.flush_top_data();
-					}).catch((err) => {
-						// console.log(err);
-						// this.$message.error(err.message)
-						this.$set(this.airsLoading[roomIndex], 'loading', false);
-						// 刷新顶部数据
-						this.flush_top_data();
-					})
+							this.$set(this.airsLoading[roomIndex], 'loading', false);
+							// 刷新顶部数据
+							this.flush_top_data();
+						}).catch((err) => {
+							// console.log(err);
+							// this.$message.error(err.message)
+							this.$set(this.airsLoading[roomIndex], 'loading', false);
+							// 刷新顶部数据
+							this.flush_top_data();
+						});
+					}).catch(() => {
+						this.$message({
+							type: 'warning',
+							message: '已取消'
+						});
+					});					
 				} else if (open_close == 'close') {
 				} 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', '正常')
+					this.$confirm('是否关闭设备:' + row.name + ' ' + row.device, '提示', {
+						confirmButtonText: '是的',
+						cancelButtonText: '不用了',
+						type: 'warning'
+					}).then(() => {
+						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 {
 							} else {
-								this.$set(this.currentData.rooms[roomIndex].tableData[rowIndex],
-									'alarmStatus', '离线')
+								this.$message.error(res.message)
 							}
 							}
-							// let _this = this;
-							// setTimeout(() => {
-							// 	_this.getAirsStatus(roomIndex, rowIndex, air_ip)
-							// }, 4000)
-						} else {
-							this.$message.error(res.message)
-						}
-						this.$set(this.airsLoading[roomIndex], 'loading', false);
-						// 刷新顶部数据
-						this.flush_top_data();
-					}).catch((err) => {
-						// console.log(err);
-						// this.$message.error(err.message)
-						this.$set(this.airsLoading[roomIndex], 'loading', false);
-						// 刷新顶部数据
-						this.flush_top_data();
-					})
+							this.$set(this.airsLoading[roomIndex], 'loading', false);
+							// 刷新顶部数据
+							this.flush_top_data();
+						}).catch((err) => {
+							// console.log(err);
+							// this.$message.error(err.message)
+							this.$set(this.airsLoading[roomIndex], 'loading', false);
+							// 刷新顶部数据
+							this.flush_top_data();
+						});
+					}).catch(() => {
+						this.$message({
+							type: 'warning',
+							message: '已取消'
+						});
+					});
+				} else {
+					this.$message('未知开关');
 				}
 				}
 			},
 			},
 			/**
 			/**