Browse Source

优化设备

yuhao 1 year ago
parent
commit
db7a2bccca
1 changed files with 79 additions and 93 deletions
  1. 79 93
      pages/edit/edit.vue

+ 79 - 93
pages/edit/edit.vue

@@ -9,53 +9,54 @@
9
 			<view class="facilityType">
9
 			<view class="facilityType">
10
 				<p>设备类型</p>
10
 				<p>设备类型</p>
11
 				<view class="buttonOP" v-if="typeList">
11
 				<view class="buttonOP" v-if="typeList">
12
-						<view class="item" @click="selectOne('type_sn',index,item)" :class="{selectType:index==selectTypeIndex}" v-for="(item,index) in typeList" :key="index">
13
-							<img :src="item.cover_url" alt="">
14
-							<span>{{item.name}}</span>
15
-						</view>
12
+					<view class="item" @click="selectOne('type_sn',index,item)"
13
+						:class="{selectType:index==selectTypeIndex}" v-for="(item,index) in typeList" :key="index">
14
+						<img :src="item.cover_url" alt="">
15
+						<span>{{item.name}}</span>
16
+					</view>
16
 				</view>
17
 				</view>
17
 			</view>
18
 			</view>
18
 			<view class="facilityType">
19
 			<view class="facilityType">
19
 				<p>探头</p>
20
 				<p>探头</p>
20
 				<view class="buttonOP" v-if="typeList!=''">
21
 				<view class="buttonOP" v-if="typeList!=''">
21
-						<view class="item" @click="selectOne('detectors',index,item)" :class="{selectType:index==selectDetectorsIndexA}" v-for="(item,index) in typeList[selectTypeIndex].detectors"
22
-						:key="index">
23
-							<img :src="item.cover_url" alt="">
24
-							<span>{{item.detector_name}}</span>
25
-						</view>
22
+					<view class="item" @click="selectOne('detectors',index,item)"
23
+						:class="{selectType:index==selectDetectorsIndexA}"
24
+						v-for="(item,index) in typeList[selectTypeIndex].detectors" :key="index">
25
+						<img :src="item.cover_url" alt="">
26
+						<span>{{item.detector_name}}</span>
27
+					</view>
26
 				</view>
28
 				</view>
27
 			</view>
29
 			</view>
28
 			<!-- mode中的模式 -->
30
 			<!-- mode中的模式 -->
29
 			<view class="pattern">
31
 			<view class="pattern">
30
-			<view class="facilityType"
31
-				v-if="typeList!=''&&typeList[selectTypeIndex].detectors[selectDetectorsIndex].config.mode&&typeList[selectTypeIndex].detectors[selectDetectorsIndex].config.mode.list">
32
-				<p>模式</p>
33
-				<view class="buttonOP">
34
-					<button @click="selectOne('mode',index,item)" :class="{selectType:index==selectModeIndexA}"
35
-						v-for="(item,index) in typeList[selectTypeIndex].detectors[selectDetectorsIndex].config.mode.list">{{item.name}}</button>
32
+				<view class="facilityType"
33
+					v-if="typeList!=''&&typeList[selectTypeIndex].detectors[selectDetectorsIndex].config.mode&&typeList[selectTypeIndex].detectors[selectDetectorsIndex].config.mode.list">
34
+					<p>模式</p>
35
+					<view class="buttonOP">
36
+						<button @click="selectOne('mode',index,item)" :class="{selectType:index==selectModeIndexA}"
37
+							v-for="(item,index) in typeList[selectTypeIndex].detectors[selectDetectorsIndex].config.mode.list">{{item.name}}</button>
38
+					</view>
36
 				</view>
39
 				</view>
37
-			</view>
38
-			<!-- power中的模式 -->
39
-			<view class="facilityType"
40
-				v-else-if="typeList!=''&&typeList[selectTypeIndex].detectors[selectDetectorsIndex].config.power.list">
41
-				<p>模式</p>
42
-				<view class="buttonOP">
43
-					<button @click="selectOne('mode',index,item)" :class="{selectType:index==selectModeIndexA}"
44
-						v-for="(item,index) in typeList[selectTypeIndex].detectors[selectDetectorsIndex].config.power.list">{{item.name}}</button>
45
-					<button style="margin-left: 100px; background-color: #374b5f;" @click="pqCLick">点击排气</button>
40
+				<!-- power中的模式 -->
41
+				<view class="facilityType"
42
+					v-else-if="typeList!=''&&typeList[selectTypeIndex].detectors[selectDetectorsIndex].config.power.list">
43
+					<p>模式</p>
44
+					<view class="buttonOP">
45
+						<button @click="selectOne('mode',index,item)" :class="{selectType:index==selectModeIndexA}"
46
+							v-for="(item,index) in typeList[selectTypeIndex].detectors[selectDetectorsIndex].config.power.list">{{item.name}}</button>
47
+						<button style="margin-left: 100px; background-color: #374b5f;" @click="pqCLick">点击排气</button>
48
+					</view>
46
 				</view>
49
 				</view>
47
-			</view>
48
-			<view class="facilityType" v-else>
49
-				<p>强度</p>
50
-				<view class="buttonOPO">
51
-					<button @click="reduce">减少</button>
52
-					<view class="strength">
53
-						{{modeClass}}
54
-					</view><button @click="add">增加</button>
50
+				<view class="facilityType" v-else>
51
+					<p>强度</p>
52
+					<view class="buttonOPO">
53
+						<button @click="reduce">减少</button>
54
+						<view class="strength">
55
+							{{modeClass}}
56
+						</view><button @click="add">增加</button>
57
+					</view>
55
 				</view>
58
 				</view>
56
 			</view>
59
 			</view>
57
-			{{CODE}}
58
-			</view>
59
 		</view>
60
 		</view>
60
 		<view class="bottomBox">
61
 		<view class="bottomBox">
61
 			<view class="back">
62
 			<view class="back">
@@ -87,7 +88,6 @@
87
 				selectModeIndex: 0, //模式index
88
 				selectModeIndex: 0, //模式index
88
 				selectModeIndexA: 99, //模式index
89
 				selectModeIndexA: 99, //模式index
89
 				TYPE_SN: 'ZK', //设备名称
90
 				TYPE_SN: 'ZK', //设备名称
90
-				CODE: 'AABB12343838373244363235444138020301010101', //设备码
91
 				PQCODE: "AABB12343838373244363235444138010101010101", //开始排气
91
 				PQCODE: "AABB12343838373244363235444138010101010101", //开始排气
92
 				PQCLOSECODE: "AABB12343838373244363235444138010201010101", //关闭排气
92
 				PQCLOSECODE: "AABB12343838373244363235444138010201010101", //关闭排气
93
 				modeClass: 0, //强度等级
93
 				modeClass: 0, //强度等级
@@ -98,10 +98,9 @@
98
 				PAUSE: '00', //暂停
98
 				PAUSE: '00', //暂停
99
 				equipmentNum: '', //设备编号
99
 				equipmentNum: '', //设备编号
100
 				modeNum: '01', //模式编号
100
 				modeNum: '01', //模式编号
101
-				CODE: '',
102
 				startTime: "", //开始时间
101
 				startTime: "", //开始时间
103
 				time: '00:00:00', //初始展示时间
102
 				time: '00:00:00', //初始展示时间
104
-				timer: '', 
103
+				timer: '',
105
 				istimer: false, //是否暂停
104
 				istimer: false, //是否暂停
106
 				hour: 0, //计时(时)
105
 				hour: 0, //计时(时)
107
 				minutes: 0, //计时(分)
106
 				minutes: 0, //计时(分)
@@ -109,15 +108,15 @@
109
 			};
108
 			};
110
 		},
109
 		},
111
 		onLoad(options) {
110
 		onLoad(options) {
112
-			console.log(options, 333333);
111
+			// console.log(options, 333333);
113
 			this.deviceId = options.deviceId
112
 			this.deviceId = options.deviceId
114
 			this.serviceId = options.serviceId
113
 			this.serviceId = options.serviceId
115
 			this.characteristicId = options.characteristicId
114
 			this.characteristicId = options.characteristicId
116
 			let typeList = uni.getStorageSync('typeList')
115
 			let typeList = uni.getStorageSync('typeList')
117
-			if(!typeList){
116
+			if (!typeList) {
118
 				// 获取设备列表
117
 				// 获取设备列表
119
 				this.getTypeList()
118
 				this.getTypeList()
120
-			}else{
119
+			} else {
121
 				this.typeList = typeList
120
 				this.typeList = typeList
122
 			}
121
 			}
123
 		},
122
 		},
@@ -126,19 +125,6 @@
126
 			blueError(code) {
125
 			blueError(code) {
127
 				switch (code) {
126
 				switch (code) {
128
 					case 10000:
127
 					case 10000:
129
-						// uni.openBluetoothAdapter({
130
-						// 	success(res) {
131
-						// 		uni.showToast({
132
-						// 			title: '初始化成功,请重新启动',
133
-						// 			duration: 2500,
134
-						// 			icon: 'none'
135
-						// 		})
136
-						// 	},
137
-						// 	fail(err) {
138
-						// 		uni.hideLoading()
139
-						// 		console.log('初始化蓝牙失败')
140
-						// 	}
141
-						// })
142
 						this.errorToast('未初始化蓝牙适配器,请返回重新连接')
128
 						this.errorToast('未初始化蓝牙适配器,请返回重新连接')
143
 						break
129
 						break
144
 					case 10001:
130
 					case 10001:
@@ -199,17 +185,15 @@
199
 				const {
185
 				const {
200
 					data: res
186
 					data: res
201
 				} = await uni.$http.post('v2/api-device/device/type_list')
187
 				} = await uni.$http.post('v2/api-device/device/type_list')
202
-				console.log(JSON.parse(JSON.stringify(res.data.list)), '获取的数据返回');
188
+				// console.log(JSON.parse(JSON.stringify(res.data.list)), '获取的数据返回');
203
 				// 筛选出无创水光
189
 				// 筛选出无创水光
204
 				for (let key in res.data.list) {
190
 				for (let key in res.data.list) {
205
-					if (res.data.list[key].id != 1&&res.data.list[key].id != 15) {
206
-						this.typeList.push(res.data.list[key])   
191
+					if (res.data.list[key].id != 1 && res.data.list[key].id != 15) {
192
+						this.typeList.push(res.data.list[key])
207
 					}
193
 					}
208
 				}
194
 				}
209
-				// this.typeList = res.data.list
195
+				// 将数据保存到本地
210
 				uni.setStorageSync('typeList', this.typeList)
196
 				uni.setStorageSync('typeList', this.typeList)
211
-				// console.log(JSON.parse(JSON.stringify(this.typeList[0].detectors[1])), 333333);
212
-				// console.log(JSON.parse(JSON.stringify(this.typeList)), 333333);
213
 			},
197
 			},
214
 			// ------------------选择设备配置
198
 			// ------------------选择设备配置
215
 			selectOne(type, index, item) {
199
 			selectOne(type, index, item) {
@@ -222,7 +206,7 @@
222
 						this.selectModeIndexA = 99
206
 						this.selectModeIndexA = 99
223
 						this.equipmentNum = '' //重置探头
207
 						this.equipmentNum = '' //重置探头
224
 						this.modeNum = '' //重置模式或强度
208
 						this.modeNum = '' //重置模式或强度
225
-						console.log(item)
209
+						// console.log(item)
226
 						//赋值哪个厂家的设备
210
 						//赋值哪个厂家的设备
227
 						if (item.type_sn.includes('ZK')) {
211
 						if (item.type_sn.includes('ZK')) {
228
 							this.TYPE_SN = 'ZK'
212
 							this.TYPE_SN = 'ZK'
@@ -236,24 +220,19 @@
236
 						this.selectModeIndexA = 99
220
 						this.selectModeIndexA = 99
237
 						this.equipmentNum = Number(item.detector_sn).toString(16) < 10 ? '0' + Number(item.detector_sn)
221
 						this.equipmentNum = Number(item.detector_sn).toString(16) < 10 ? '0' + Number(item.detector_sn)
238
 							.toString(16) : Number(item.detector_sn).toString(16) //设备探头编号(16进制)
222
 							.toString(16) : Number(item.detector_sn).toString(16) //设备探头编号(16进制)
239
-						console.log(this.equipmentNum)
240
-						console.log(JSON.parse(JSON.stringify(this.typeList[this.selectTypeIndex].detectors[this
241
-							.selectDetectorsIndex])))
242
-						this.minClass = this.typeList[this.selectTypeIndex].detectors[this.selectDetectorsIndex].config
243
-							.power.min //最小值
244
-						this.maxClass = this.typeList[this.selectTypeIndex].detectors[this.selectDetectorsIndex].config
245
-							.power.max //最大值
246
-						this.incrementClass = this.typeList[this.selectTypeIndex].detectors[this.selectDetectorsIndex]
247
-							.config.power.increment //增幅
248
-						this.modeClass = this.typeList[this.selectTypeIndex].detectors[this.selectDetectorsIndex].config
249
-							.power.default //默认值
223
+						// console.log(this.equipmentNum)
224
+						// console.log(item)
225
+						this.minClass = item.config.power.min //最小值
226
+						this.maxClass = item.config.power.max //最大值
227
+						this.incrementClass = item.config.power.increment //增幅
228
+						this.modeClass = item.config.power.default //默认值
250
 						break
229
 						break
251
 					case 'mode':
230
 					case 'mode':
252
 						this.selectModeIndex = index
231
 						this.selectModeIndex = index
253
 						this.selectModeIndexA = index
232
 						this.selectModeIndexA = index
254
 						this.modeNum = Number(item.value).toString(16) < 10 ? '0' + Number(item.value).toString(16) :
233
 						this.modeNum = Number(item.value).toString(16) < 10 ? '0' + Number(item.value).toString(16) :
255
 							Number(item.value).toString(16)
234
 							Number(item.value).toString(16)
256
-						console.log(this.modeNum)
235
+						// console.log(this.modeNum)
257
 						break
236
 						break
258
 				}
237
 				}
259
 			},
238
 			},
@@ -301,13 +280,14 @@
301
 			// ----------------------操作设备开启暂停结束
280
 			// ----------------------操作设备开启暂停结束
302
 			operate(type) {
281
 			operate(type) {
303
 				// 强度编号
282
 				// 强度编号
304
-				let	modeNum = Number(this.modeClass).toString(16) < 10 ? '0' + Number(this.modeClass).toString(16) :
305
-						Number(this.modeClass).toString(16)
283
+				let modeNum = Number(this.modeClass).toString(16) < 10 ? '0' + Number(this.modeClass).toString(16) :
284
+					Number(this.modeClass).toString(16)
306
 				// 设备模式编号
285
 				// 设备模式编号
307
-				if (this.typeList[this.selectTypeIndex].detectors[this.selectDetectorsIndex].config.mode?.list||this.typeList[this.selectTypeIndex].detectors[this.selectDetectorsIndex].config.power?.list) {
286
+				if (this.typeList[this.selectTypeIndex].detectors[this.selectDetectorsIndex].config.mode?.list || this
287
+					.typeList[this.selectTypeIndex].detectors[this.selectDetectorsIndex].config.power?.list) {
308
 					modeNum = this.modeNum
288
 					modeNum = this.modeNum
309
 				}
289
 				}
310
-				console.log(modeNum);
290
+				// console.log(modeNum);
311
 				// 蓝牙指令操作码
291
 				// 蓝牙指令操作码
312
 				let code =
292
 				let code =
313
 					`AABB12343838373244363235444138${this.equipmentNum}03${type=='open'?this.START:this.PAUSE}${modeNum}0101`
293
 					`AABB12343838373244363235444138${this.equipmentNum}03${type=='open'?this.START:this.PAUSE}${modeNum}0101`
@@ -322,13 +302,14 @@
322
 					})
302
 					})
323
 					return
303
 					return
324
 				}
304
 				}
325
-				if (this.typeList[this.selectTypeIndex].detectors[this.selectDetectorsIndex].config.mode?.list||this.typeList[this.selectTypeIndex].detectors[this.selectDetectorsIndex].config.power?.list) {
326
-					if(this.selectModeIndexA==99){						
327
-					uni.showToast({
328
-						title: '请选择模式',
329
-						icon: "none"
330
-					})
331
-					return
305
+				if (this.typeList[this.selectTypeIndex].detectors[this.selectDetectorsIndex].config.mode?.list || this
306
+					.typeList[this.selectTypeIndex].detectors[this.selectDetectorsIndex].config.power?.list) {
307
+					if (this.selectModeIndexA == 99) {
308
+						uni.showToast({
309
+							title: '请选择模式',
310
+							icon: "none"
311
+						})
312
+						return
332
 					}
313
 					}
333
 				}
314
 				}
334
 				// 操作 开始 暂停 结束
315
 				// 操作 开始 暂停 结束
@@ -364,7 +345,6 @@
364
 			// -------------------发送数据
345
 			// -------------------发送数据
365
 			send(newMsg, title = '执行成功') {
346
 			send(newMsg, title = '执行成功') {
366
 				console.log(newMsg);
347
 				console.log(newMsg);
367
-				this.CODE = newMsg
368
 				wx.showLoading({
348
 				wx.showLoading({
369
 					title: '正在启动',
349
 					title: '正在启动',
370
 					mask: true
350
 					mask: true
@@ -380,7 +360,7 @@
380
 						index++
360
 						index++
381
 					}
361
 					}
382
 				}
362
 				}
383
-				console.log(that.deviceId, that.serviceId, that.characteristicId);
363
+				// console.log(that.deviceId, that.serviceId, that.characteristicId);
384
 				// return
364
 				// return
385
 				uni.writeBLECharacteristicValue({
365
 				uni.writeBLECharacteristicValue({
386
 					deviceId: that.deviceId, // 设备ID
366
 					deviceId: that.deviceId, // 设备ID
@@ -425,7 +405,7 @@
425
 						} else {
405
 						} else {
426
 							that.finishTime()
406
 							that.finishTime()
427
 						}
407
 						}
428
-						console.log(res,'发送数据成功')
408
+						console.log(res, '发送数据成功')
429
 					},
409
 					},
430
 					fail(err) {
410
 					fail(err) {
431
 						uni.hideLoading()
411
 						uni.hideLoading()
@@ -468,18 +448,22 @@
468
 		margin-left: 100px;
448
 		margin-left: 100px;
469
 		margin-top: 40px;
449
 		margin-top: 40px;
470
 		width: 85%;
450
 		width: 85%;
471
-		.pattern{
451
+
452
+		.pattern {
472
 			display: flex;
453
 			display: flex;
473
 			overflow-x: scroll;
454
 			overflow-x: scroll;
474
-			.facilityType{
455
+
456
+			.facilityType {
475
 				margin-right: 80px;
457
 				margin-right: 80px;
476
 			}
458
 			}
477
 		}
459
 		}
460
+
478
 		.buttonOP {
461
 		.buttonOP {
479
 			display: flex;
462
 			display: flex;
480
-			.item{
463
+
464
+			.item {
481
 				padding-right: 20px;
465
 				padding-right: 20px;
482
-				padding-left:6px;
466
+				padding-left: 6px;
483
 				height: 100px;
467
 				height: 100px;
484
 				background-color: #b8b8b8;
468
 				background-color: #b8b8b8;
485
 				margin-right: 20px;
469
 				margin-right: 20px;
@@ -488,13 +472,15 @@
488
 				display: flex;
472
 				display: flex;
489
 				justify-content: center;
473
 				justify-content: center;
490
 				align-items: center;
474
 				align-items: center;
491
-				img{
475
+
476
+				img {
492
 					width: 90px;
477
 					width: 90px;
493
 					height: 90px;
478
 					height: 90px;
494
 					border-radius: 24px;
479
 					border-radius: 24px;
495
 					margin-right: 20px;
480
 					margin-right: 20px;
496
 				}
481
 				}
497
 			}
482
 			}
483
+
498
 			button {
484
 			button {
499
 				flex-shrink: 0;
485
 				flex-shrink: 0;
500
 				margin: 0;
486
 				margin: 0;
@@ -506,7 +492,7 @@
506
 			.selectType {
492
 			.selectType {
507
 				background-color: #1e98d7;
493
 				background-color: #1e98d7;
508
 			}
494
 			}
509
-			
495
+
510
 		}
496
 		}
511
 
497
 
512
 		.buttonOPO {
498
 		.buttonOPO {
@@ -575,4 +561,4 @@
575
 			}
561
 			}
576
 		}
562
 		}
577
 	}
563
 	}
578
-</style>
564
+</style>