Bläddra i källkod

【空调管理】优化了分页显示问题,顶部数据开关机显示联动问题。

soft5566 3 år sedan
förälder
incheckning
54f8a4ab63

+ 1 - 1
src/store/getters.js

@@ -4,7 +4,7 @@ const getters = {
 	token: state => state.user.token,
 	avatar: state => state.user.avatar,
 	name: state => state.user.name,
-	fullname: state => state.user.fullname,
+	user_name: state => state.user.user_name,
 	phone: state => state.user.phone
 }
 export default getters

+ 6 - 6
src/store/modules/user.js

@@ -18,7 +18,7 @@ const getDefaultState = () => {
 		name: '',
 		level: '',
 		avatar: '',
-		fullname: '',
+		user_name: '',
 		phone: ''
 	}
 }
@@ -38,8 +38,8 @@ const mutations = {
 	SET_PHONE: (state, phone) => {
 		state.phone = phone
 	},
-	SET_FULLNAME: (state, fullname) => {
-		state.fullname = fullname
+	SET_USER_NAME: (state, user_name) => {
+		state.user_name = user_name
 	},
 	SET_PWD: (state, pwd) => {
 		state.pwd = pwd
@@ -76,14 +76,14 @@ const actions = {
 					commit('SET_NAME', response.data[0].admin_name)
 					commit('SET_PWD', password)
 					commit('SET_PHONE', response.data[0].phone)
-					commit('SET_FULLNAME', response.data[0].fullname)
+					commit('SET_USER_NAME', response.data[0].user_name)
 				} else {
 					commit('SET_TOKEN', '')
 					commit('SET_LEVEL', '')
 					commit('SET_NAME', '')
 					commit('SET_PWD', '')
 					commit('SET_PHONE', '')
-					commit('SET_FULLNAME', '')
+					commit('SET_USER_NAME', '')
 				}
 				// commit('SET_TOKEN', data.token)
 				// setToken(data.token)
@@ -138,7 +138,7 @@ const actions = {
 			commit('SET_LEVEL', '')
 			commit('SET_TOKEN', '')
 			commit('SET_PHONE', '')
-			commit('SET_FULLNAME', '')
+			commit('SET_USER_NAME', '')
 			resolve()
 		})
 		// 修改:下面被注释了

+ 2 - 2
src/utils/request.js

@@ -12,7 +12,7 @@ import {
 const service = axios.create({
 	baseURL: process.env.VUE_APP_BASE_API, // url = base url + request url
 	// withCredentials: true, // 跨域请求时发送cookie
-	timeout: 10000 // 请求超时
+	timeout: 20000 // 请求超时
 })
 
 // 请求拦截器
@@ -30,7 +30,7 @@ service.interceptors.request.use(
 	},
 	error => {
 		// 处理请求错误
-		console.log(error) // 调试命令
+		// console.log(error) // 调试命令
 		return Promise.reject(error)
 	}
 )

+ 49 - 5
src/views/accountMgr/index.vue

@@ -24,11 +24,16 @@
 									<span>{{ scope.row.phone }}</span>
 								</template>
 							</el-table-column>
-							<el-table-column label="名" align="center">
+							<el-table-column label="用户名" align="center">
 								<template slot-scope="scope">
 									<span>{{ scope.row.admin_name }}</span>
 								</template>
 							</el-table-column>
+							<el-table-column label="姓名" align="center">
+								<template slot-scope="scope">
+									<span>{{ scope.row.user_name }}</span>
+								</template>
+							</el-table-column>
 							<el-table-column label="角色" align="center">
 								<template slot-scope="scope">
 									<span v-if="scope.row.level == 1">管理员</span>
@@ -69,11 +74,16 @@
 				</div>
 			</el-col>
 		</el-row>
+		<!-- 添加账号对话框 -->
 		<el-dialog title="添加账号" custom-class="add-account-class" :visible.sync="dialogAddAcountFormVisible"
 			:close-on-click-modal="false" :close-on-press-escape="false" @close="add_account_dialog_close">
 			<el-form :model="formAddAcount" ref="addAccountForm" :rules="addAccountFormRules">
 				<el-form-item label="用户名:" :label-width="formLabelWidth" :required="true" prop="username">
-					<el-input v-model="formAddAcount.username" autocomplete="off" placeholder="请输入用户名" maxlength="10">
+					<el-input v-model="formAddAcount.username" autocomplete="off" placeholder="请输入用户名" maxlength="16">
+					</el-input>
+				</el-form-item>
+				<el-form-item label="姓名:" :label-width="formLabelWidth" :required="true" prop="fullname">
+					<el-input v-model="formAddAcount.fullname" autocomplete="off" placeholder="请输入姓名" maxlength="6">
 					</el-input>
 				</el-form-item>
 				<el-form-item label="手机号:" :label-width="formLabelWidth" :required="true" prop="phone">
@@ -106,12 +116,17 @@
 				<el-button type="primary" @click="add_account_dialog">确 认</el-button>
 			</div>
 		</el-dialog>
+		<!-- 修改账号对话框 -->
 		<el-dialog title="修改账号" custom-class="modify-account-class" :visible.sync="dialogModifyAcountFormVisible"
 			:close-on-click-modal="false" :close-on-press-escape="false" @close="modify_account_dialog_close">
 			<el-form :model="formModifyAcount" ref="modifyAccountForm" :rules="modifyAccountFormRules">
 				<el-form-item label="用户名:" :label-width="formLabelWidth" :required="true" prop="username">
 					<el-input v-model="formModifyAcount.username" autocomplete="off" placeholder="请输入用户名" readonly
-						maxlength="10"></el-input>
+						maxlength="16"></el-input>
+				</el-form-item>
+				<el-form-item label="姓名:" :label-width="formLabelWidth" :required="true" prop="fullname">
+					<el-input v-model="formAddAcount.fullname" autocomplete="off" placeholder="请输入姓名" maxlength="6">
+					</el-input>
 				</el-form-item>
 				<el-form-item label="手机号:" :label-width="formLabelWidth" :required="true" prop="phone">
 					<el-input v-model="formModifyAcount.phone" autocomplete="off" placeholder="请输入手机号" maxlength="11">
@@ -143,6 +158,7 @@
 				<el-button type="primary" @click="modify_account_dialog">确 认</el-button>
 			</div>
 		</el-dialog>
+		<!-- 删除确认对话框 -->
 		<el-dialog custom-class="el-dialog-delete-account" :visible.sync="dialog_delete_account"
 			:close-on-click-modal="false" :close-on-press-escape="false" :show-close="false">
 			<div slot="" class="del-account-body">
@@ -184,6 +200,19 @@
 					}
 				}, 100);
 			}
+			var checkFullName = (rule, value, callback) => {
+				if (!value) {
+					return callback(new Error('请输入姓名'));
+				}
+				setTimeout(() => {
+					var reg = /^[\u4e00-\u9fa5]{2,6}$/
+					if (!reg.test(value)) {
+						callback(new Error('必须为2-6个汉字!'));
+					} else {
+						callback();
+					}
+				}, 100);
+			}
 			var checkPhone = (rule, value, callback) => {
 				if (!value) {
 					return callback(new Error('请输入手机号'));
@@ -271,6 +300,8 @@
 				formAddAcount: { // 添加账号对话框 数据
 					phone: '',
 					username: '',
+					fullname: '',
+					fullname: '',
 					password: '',
 					confirmPassword: '',
 					comment: '',
@@ -281,6 +312,9 @@
 					username: [{
 						validator: checkUserName
 					}],
+					fullname: [{
+						validator: checkFullName
+					}],
 					phone: [{
 						validator: checkPhone
 					}],
@@ -299,6 +333,7 @@
 					id: '',
 					phone: '',
 					username: '',
+					fullname: '',
 					password: '',
 					confirmPassword: '',
 					comment: '',
@@ -309,6 +344,9 @@
 					username: [{
 						validator: checkUserName
 					}],
+					fullname: [{
+						validator: checkFullName
+					}],
 					phone: [{
 						validator: checkPhone
 					}],
@@ -412,6 +450,7 @@
 				this.dialogModifyAcountFormVisible = true
 				this.formModifyAcount.id = row.id
 				this.formModifyAcount.username = row.admin_name
+				this.formModifyAcount.fullname = row.user_name
 				this.formModifyAcount.phone = row.phone
 				if (row.level == 1) {
 					this.formModifyAcount.checkedRole.push('管理员')
@@ -458,7 +497,7 @@
 				})
 			},
 			/**
-			 * 添加账号对话框确定按钮事件
+			 * 修改账号对话框确定按钮事件
 			 */
 			modify_account_dialog() {
 				this.$refs["modifyAccountForm"].validate(validate => {
@@ -488,6 +527,9 @@
 					}
 				})
 			},
+			/**
+			 * 删除账号对话框确定按钮事件
+			 */
 			delete_account_dialog() {
 				deleteAccount(this.deleteAccountData.id).then((res) => {
 					// console.log(res);
@@ -515,6 +557,7 @@
 				this.formAddAcount = {
 					phone: '',
 					username: '',
+					fullname: '',
 					password: '',
 					confirmPassword: '',
 					comment: '',
@@ -529,6 +572,7 @@
 				this.formModifyAcount = {
 					phone: '',
 					username: '',
+					fullname: '',
 					password: '',
 					confirmPassword: '',
 					comment: '',
@@ -771,7 +815,7 @@
 <style>
 	.add-account-class,
 	.modify-account-class {
-		height: 570px !important;
+		height: 620px !important;
 	}
 
 	.el-dialog-delete-account {

+ 1 - 1
src/views/login/index.vue

@@ -111,7 +111,7 @@
 						this.loading = true
 						this.$store.dispatch('user/login', this.loginForm)
 							.then((res) => {
-								console.log(res);
+								// console.log(res);
 								if (res.code == 200) {
 									this.$router.push({
 										path: this.redirect || '/'

+ 92 - 54
src/views/serveAC/index.vue

@@ -391,7 +391,7 @@
 							</el-col>
 						</el-row>
 						<div class="pagination-table">
-							<el-pagination @current-change="currentPageChange"
+							<el-pagination @current-change="currentPageChange" :hide-on-single-page="hideOnSinglePage"
 								:current-page.sync="pagination.currentPage" :page-size="pagination.pageSize"
 								layout="prev, pager, next, jumper" :total="pagination.total">
 							</el-pagination>
@@ -580,8 +580,7 @@
 		stopAirs,
 		selAirsStatus,
 		getDevices
-	} from '@/api/serveAC'
-	var deviceOptions = [];
+	} from '@/api/serveAC';
 	export default {
 		data() {
 			// var checkloudong = (rule, value, callback) => {
@@ -698,7 +697,8 @@
 				}
 			};
 			return {
-				cao: this.$store.state.user.name, // 操作员
+				hideOnSinglePage: true, // 只有一页时是否隐藏
+				cao: this.$store.state.user.user_name, // 操作员
 				contact: this.$store.state.user.phone,
 				room_number: 0, // 房间数量
 				device_number: 0, // 设备数量
@@ -766,7 +766,7 @@
 					deviceName: '',
 					deviceIp: '',
 					checkedDevice: [],
-					devices: deviceOptions,
+					devices: [],
 					duration_use: 0.00, // 使用时长
 					is_normal: '1', // 是否正常
 					is_on: '0' // 是否开启
@@ -857,11 +857,12 @@
 				}, {
 					loading: false,
 					text: ''
-				}]
+				}],
+				deviceOptions: []
 			}
 		},
 		created() {
-			// 获取消费记录,表格数据
+			// 获取表格数据
 			this.get_loudong_data()
 			// 默认选中第一个房间
 			let auto_click = setInterval(() => {
@@ -876,25 +877,32 @@
 			this.get_Devices();
 		},
 		mounted() {
-			document.getElementsByClassName("el-pagination__jump")[0].childNodes[0].nodeValue = "跳至";
+			var obj = document.getElementsByClassName("el-pagination__jump")[0];
+			if (typeof obj == 'undefined') {
+				return;
+			} else {
+				obj[0].childNodes[0].nodeValue = "跳至";
+			}
 		},
 		methods: {
 			/**
-			 * 获取费率列表数据
+			 * 获取所有的空调列表
 			 */
 			get_Devices() {
+				var _this = this;
 				// 开始发送请求,获取配置数据
 				getDevices().then((res) => {
 					// console.log(res.data);
 					if (res.code == 200) {
 						let resdata = res.data;
-						deviceOptions = []
+						_this.deviceOptions = [];
 						for (var i = 0; i < resdata.length; i++) {
-							deviceOptions.push(resdata[i].air_config);
+							_this.deviceOptions.push(resdata[i].air_config);
 						}
-						deviceOptions.sort((a, b) => a.localeCompare(b))
+						_this.deviceOptions.sort((a, b) => a - b);
+						this.form_add_device.devices = _this.deviceOptions;
 					} else {
-						deviceOptions = [];
+						_this.deviceOptions = [];
 						this.$message.warning('没有符合条件的数据!');
 					}
 				}).catch((err) => {
@@ -929,16 +937,13 @@
 
 						if (res.code == 200) {
 							this.$set(this.currentData.rooms[roomIndex].tableData[rowIndex], 'onOffStatus',
-								res
-								.is_on)
+								res.is_on)
 							if (res.is_normal == 1) {
 								this.$set(this.currentData.rooms[roomIndex].tableData[rowIndex],
-									'alarmStatus',
-									'正常')
+									'alarmStatus', '正常')
 							} else {
 								this.$set(this.currentData.rooms[roomIndex].tableData[rowIndex],
-									'alarmStatus',
-									'离线')
+									'alarmStatus', '离线')
 							}
 							// let _this = this;
 							// setTimeout(() => {
@@ -948,10 +953,14 @@
 							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();
 					})
 				} else if (open_close == 'close') {
 					this.$set(this.airsLoading[roomIndex], 'loading', true);
@@ -967,16 +976,13 @@
 
 						if (res.code == 200) {
 							this.$set(this.currentData.rooms[roomIndex].tableData[rowIndex], 'onOffStatus',
-								res
-								.is_on)
+								res.is_on)
 							if (res.is_normal == 1) {
 								this.$set(this.currentData.rooms[roomIndex].tableData[rowIndex],
-									'alarmStatus',
-									'正常')
+									'alarmStatus', '正常')
 							} else {
 								this.$set(this.currentData.rooms[roomIndex].tableData[rowIndex],
-									'alarmStatus',
-									'离线')
+									'alarmStatus', '离线')
 							}
 							// let _this = this;
 							// setTimeout(() => {
@@ -986,10 +992,14 @@
 							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();
 					})
 				}
 			},
@@ -1260,7 +1270,7 @@
 							for (var i = 0; i < data.length; i++) {
 								let room = {}
 								let param = this.btnActive
-								if (param == 'all') {
+								if (param == 'all') { // 全部
 									room = {
 										name: data[i].air_name, // 名称
 										ip: data[i].air_ip, // 空调ip或id
@@ -1271,8 +1281,8 @@
 										onOffStatus: data[i].is_on, // 是否开启
 										userName: data[i].cao, // 操作员
 										contact: '待接口返回,待优化' // 联系方式
-									}
-								} else if (param == 'powerOn' && data[i].is_on == '1') {
+									};
+								} else if (param == 'powerOn' && data[i].is_on == '1') { // 开机
 									room = {
 										name: data[i].air_name, // 名称
 										ip: data[i].air_ip, // 空调ip或id
@@ -1283,8 +1293,8 @@
 										onOffStatus: data[i].is_on, // 是否开启
 										userName: data[i].cao, // 操作员
 										contact: '待接口返回,待优化' // 联系方式
-									}
-								} else if (param == 'powerOff' && data[i].is_on == '0') {
+									};
+								} else if (param == 'powerOff' && data[i].is_on == '0') { // 关机
 									room = {
 										name: data[i].air_name, // 名称
 										ip: data[i].air_ip, // 空调ip或id
@@ -1295,8 +1305,8 @@
 										onOffStatus: data[i].is_on, // 是否开启
 										userName: data[i].cao, // 操作员
 										contact: '待接口返回,待优化' // 联系方式
-									}
-								} else if (param == 'abnormal' && data[i].is_normal == '0') {
+									};
+								} else if (param == 'abnormal' && data[i].is_normal == '0') { // 离线
 									room = {
 										name: data[i].air_name, // 名称
 										ip: data[i].air_ip, // 空调ip或id
@@ -1307,7 +1317,7 @@
 										onOffStatus: data[i].is_on, // 是否开启
 										userName: data[i].cao, // 操作员
 										contact: '待接口返回,待优化' // 联系方式
-									}
+									};
 								}
 								if (JSON.stringify(room) !== '{}') {
 									// 每个房间的设备循环添加
@@ -1366,6 +1376,9 @@
 			 * @param {Object} e
 			 */
 			loudong_toggle(id, label) {
+				this.pagination.pageSize = 4;
+				this.pagination.currentPage = 1;
+				this.pagination.total = 0;
 				let ids = id.split('|')
 				let labels = label.split('|')
 				// console.log(ids);
@@ -1381,13 +1394,14 @@
 			 * @param {Object} rooms
 			 */
 			louceng_click(e, id, label, rooms) {
+				// console.log(e, id, label, rooms);
 				this.listLoading = true;
 				let ids = id.split('|');
 				let labels = label.split('|');
 				// console.log(ids);
 				// console.log(labels);
 				// console.log(rooms);
-				// 清空数据
+				// 清空当前页面活动数据
 				this.currentData = {
 					school: '',
 					building: '',
@@ -1410,6 +1424,14 @@
 					title_any_where: '',
 					clickElement: e.target
 				};
+				// 分页每次单价楼层时,都要初始化
+				this.pagination = {
+					pageSize: 4,
+					currentPage: 1,
+					total: 0
+				};
+				this.offline_device_number = 0; // 离线数量初始化
+				this.shutdown_device_number = 0; // 关机数量初始化
 				// 点击的楼层id
 				this.louceng_click_id = ids[0];
 				// 填充数据
@@ -1422,16 +1444,23 @@
 				// 获取开机、关机、异常的房间,空的不显示
 				this.open_close_abnormal(this.currentData.school, this.currentData.building, this.currentData.floor,
 					rooms);
-				// 某层房间空调数	
-				this.getRoomsAndAirs(this.currentData.school, this.currentData.building, this.currentData.floor);
-				// 某层空调开启和异常统计
-				this.getOpeningAndAbnomal(this.currentData.school, this.currentData.building, this.currentData
-					.floor);
+				// 刷新顶部数据
+				this.flush_top_data();
+				// 延迟取消加载loading
 				setTimeout(() => {
 					this.listLoading = false;
 				}, 500);
 			},
 			/**
+			 * 刷新顶部数据
+			 */
+			flush_top_data() {
+				// 某层房间、空调数
+				this.getRoomsAndAirs(this.currentData.school, this.currentData.building, this.currentData.floor);
+				// 某层空调开启和异常统计
+				this.getOpeningAndAbnomal(this.currentData.school, this.currentData.building, this.currentData.floor);
+			},
+			/**
 			 * 获取开机、关机、异常房间数
 			 * @param {Object} school
 			 * @param {Object} build
@@ -1439,6 +1468,7 @@
 			 * @param {Object} rooms
 			 */
 			open_close_abnormal(school, build, floors, rooms) {
+				// console.log(school, build, floors, rooms);
 				let _this = this,
 					len = rooms.length;
 				for (var i = 0; i < len; i++) {
@@ -1590,24 +1620,26 @@
 				}).then((res) => {
 					// console.log(res);
 					if (typeof res.code == 'undefined' || res.code == '') {
-						this.$message.error('返回数据格式问题,code未获取到!')
-						return
+						this.$message.error('返回数据格式问题,code未获取到!');
+						return;
 					}
 
 					if (res.code == 200) {
 						// 填充数据
-						this.open_number = res.onNum
-						this.warning_number = res.stateNum
+						this.open_number = res.onNum;
+						this.warning_number = res.stateNum;
 					} else {
-						// this.$message.error(res.message)
+						this.open_number = 0;
+						this.warning_number = 0;
+						// this.$message.error(res.message);
 					}
 				}).catch((err) => {
 					// console.log(err);
-					this.$message.error(err.message)
+					this.$message.error(err.message);
 				})
 			},
 			/**
-			 * 某层房间空调数
+			 * 某层房间空调数
 			 * @param {Object} school
 			 * @param {Object} build
 			 * @param {Object} floors
@@ -1620,20 +1652,22 @@
 				}).then((res) => {
 					// console.log(res);
 					if (typeof res.code == 'undefined' || res.code == '') {
-						this.$message.error('返回数据格式问题,code未获取到!')
-						return
+						this.$message.error('返回数据格式问题,code未获取到!');
+						return;
 					}
 
 					if (res.code == 200) {
 						// 填充数据
-						this.room_number = res.domNum
-						this.device_number = res.airNum
+						this.room_number = res.domNum;
+						this.device_number = res.airNum;
 					} else {
-						this.$message.error(res.message)
+						this.room_number = 0;
+						this.device_number = 0;
+						// this.$message.error(res.message);
 					}
 				}).catch((err) => {
 					// console.log(err);
-					this.$message.error(err.message)
+					this.$message.error(err.message);
 				})
 			},
 			/**
@@ -1902,8 +1936,12 @@
 					this.$message.error(err.message)
 				})
 			},
-			// 主题部分按钮的单击事件
+			/**
+			 * 主题部分按钮的单击事件
+			 * @param {Object} param
+			 */
 			top_btn_click(param) {
+				// console.log(param);
 				this.btnActive = param;
 				if (param == 'all') {
 					this.currentData.clickElement.click();
@@ -2021,7 +2059,7 @@
 						deviceName: '',
 						deviceIp: '',
 						checkedDevice: [],
-						devices: deviceOptions,
+						devices: [],
 						duration_use: 0.00, // 使用时长
 						is_normal: '0', // 是否正常
 						is_on: '0', // 是否开启