Browse Source

fix(equipList2): 修复设备列表页面数据展示和接口调用问题

1.  启用正式环境的API BASE_URL,注释测试环境地址
2.  新增工具方法处理空值避免渲染报错
3.  调整滑块组件取值范围为10-100
4.  新增弹窗遮罩不可关闭逻辑
5.  重构阀门控制接口调用逻辑
allen 1 tuần trước cách đây
mục cha
commit
c1da7420eb
2 tập tin đã thay đổi với 52 bổ sung20 xóa
  1. 50 18
      pages/equipList2/index.vue
  2. 2 2
      util/api.js

+ 50 - 18
pages/equipList2/index.vue

@@ -101,21 +101,21 @@
 								<view class="action-item">
 									<image :src="lightning" alt="" class="item-icon">
 									</image>
-            			<text>{{item.sensor_params.charging_vol || 0}}v</text>
+            			<text>{{getcharging_vol(item.sensor_params)}}v</text>
 								</view>
 								<view class="action-item">
-									<image :src="getSignal(item.sensor_params.rssl)" alt="" class="item-icon">
+									<image :src="getSignal(item.sensor_params)" alt="" class="item-icon">
 									</image>
-            			<text>{{item.sensor_params.rssl}}</text>
+            			<text>{{getrssl(item.sensor_params)}}</text>
 								</view>
 								<view class="action-item">
 									<image :src="battery" alt="" class="item-icon">
 									</image>
-            			<text>{{item.sensor_params.kwh}}%</text>
+            			<text>{{getopeningValue(item.sensor_params)}}%</text>
 								</view>
 							</view>
 							<view class="action-container" v-if="type_id == 49">
-								<view class="action-container-item" :class="n.switchValue?'action-container-container-item-active':''" v-for="(n,key) in item.valve_params" :key="key">
+								<view class="action-container-item" :class="n.switchValue?'action-container-container-item-active':''" v-for="(n,key) in getvalve_params(item)" :key="key">
 									<view class="action-open">
 										<view class="item-number" :class="n.switchValue?'item-number-active':''">{{n.name}}</view>
 										<u-switch 
@@ -167,14 +167,14 @@
           <view class="slider-min-value">10</view>
           <view
             class="custom-progress"
-            @touchstart.stop="onSliderTouchStart($event, 'openingValue', 10, 120)"
-            @touchmove.stop.prevent="onSliderTouchMove($event, 10, 120)"
+            @touchstart.stop="onSliderTouchStart($event, 'openingValue', 10, 100)"
+            @touchmove.stop.prevent="onSliderTouchMove($event, 10, 100)"
             @touchend.stop="onSliderTouchEnd"
-            @tap.stop="onSliderTap($event, 'openingValue', 10, 120)"
+            @tap.stop="onSliderTap($event, 'openingValue', 10, 100)"
           >
             <view class="progress-track">
-              <view class="progress-fill" :style="{ width: getProgressWidth(equipContrlForm.openingValue, 10, 120) + '%' }"></view>
-              <view class="progress-thumb" :style="{ left: getProgressWidth(equipContrlForm.openingValue, 10, 120) + '%' }"></view>
+              <view class="progress-fill" :style="{ width: getProgressWidth(equipContrlForm.openingValue, 10, 100) + '%' }"></view>
+              <view class="progress-thumb" :style="{ left: getProgressWidth(equipContrlForm.openingValue, 10, 100) + '%' }"></view>
             </view>
           </view>
           <view class="slider-max-value">100</view>
@@ -191,14 +191,14 @@
           <view class="slider-min-value">10</view>
           <view
             class="custom-progress"
-            @touchstart.stop="onSliderTouchStart($event, 'openingValue', 10, 120)"
-            @touchmove.stop.prevent="onSliderTouchMove($event, 10, 120)"
+            @touchstart.stop="onSliderTouchStart($event, 'openingValue', 10, 100)"
+            @touchmove.stop.prevent="onSliderTouchMove($event, 10, 100)"
             @touchend.stop="onSliderTouchEnd"
-            @tap.stop="onSliderTap($event, 'openingValue', 10, 120)"
+            @tap.stop="onSliderTap($event, 'openingValue', 10, 100)"
           >
             <view class="progress-track">
-              <view class="progress-fill" :style="{ width: getProgressWidth(equipContrlForm.openingValue, 10, 120) + '%' }"></view>
-              <view class="progress-thumb" :style="{ left: getProgressWidth(equipContrlForm.openingValue, 10, 120) + '%' }"></view>
+              <view class="progress-fill" :style="{ width: getProgressWidth(equipContrlForm.openingValue, 10, 100) + '%' }"></view>
+              <view class="progress-thumb" :style="{ left: getProgressWidth(equipContrlForm.openingValue, 10, 100) + '%' }"></view>
             </view>
           </view>
           <view class="slider-max-value">100</view>
@@ -211,7 +211,7 @@
 		<u-modal v-model="show3" :content="content" @confirm="confirmClose" @cancel="cancelClose"></u-modal>
 		<u-select v-model="show1" :list="hours" @confirm="changeHour"></u-select>
 		<u-select v-model="show2" :list="minutes" @confirm="changeMinute"></u-select>
-		<u-popup v-model="show4" mode="center" width="80%">
+		<u-popup v-model="show4" mode="center" width="80%" :mask-close-able="false">
 			<view class="progress-container">
 				<u-line-progress :percent="percentage" style="width: 90%;"></u-line-progress>
 			</view>
@@ -311,6 +311,21 @@ import openingDegree from '../assets/openingDegree.png';
 			};
 		},
 		methods: {
+			getvalve_params(item){
+				return item?.valve_params || [];
+			},
+			getcharging_vol(item){
+				return item?.charging_vol || 0;
+			},
+			getrssl(item){
+				return item?.rssl || 0;
+			},
+			getopeningValue(item){
+				return item?.kwh || 0;
+			},
+			getRadioValue(){
+				return this.value;
+			},
 			setPercentage(msg){
 				this.timer = setInterval(() => {
 					this.percentage += 1;
@@ -327,7 +342,8 @@ import openingDegree from '../assets/openingDegree.png';
 					}
 				}, 125);
 			},
-			getSignal(val){
+			getSignal(item){
+				const val = item?.rssl || 0;
 				if(val < 0){
 					return this.signal0;
 				}
@@ -396,6 +412,22 @@ import openingDegree from '../assets/openingDegree.png';
 					});
 				}
 			},
+			async setEditAction(data){
+				const res = await this.$myRequest({
+					url: '/api/api_gateway?method=irrigation_system.valvecontrol.alter_valvecontrol_valve_percentage',
+					method: 'POST',
+					data,
+				});
+				if(res.code == 0){
+					this.show4 = true;
+					this.setPercentage(res.message);
+				}else{
+					uni.showToast({
+						title: res?.message,
+						icon: 'none',
+					});
+				}
+			},
 			onSliderTouchStart(e, field, min, max) {
 				this.sliderField = field
 				this.sliderMin = min
@@ -437,7 +469,7 @@ import openingDegree from '../assets/openingDegree.png';
 				this.showPopup = false;
 			},
 			submit2(){
-				this.setAction({
+				this.setEditAction({
 					device_id: this.current_device_id,
 					valve_param_key: this.valve_param_key,
 					var_value: this.equipContrlForm.openingValue,

+ 2 - 2
util/api.js

@@ -1,9 +1,9 @@
 // let BASE_URL = 'http://114.55.0.7:8002';
 // const BASE_URL='http://8.136.98.49:8002'
 // let BASE_URL = 'http://218.28.198.186:10505'
-// let BASE_URL = 'https://wx.hnyfwlw.com'
+let BASE_URL = 'https://wx.hnyfwlw.com'
 // let BASE_URL = 'http://192.168.1.107:8000';
-let BASE_URL = 'http://218.28.198.186:10508';
+// let BASE_URL = 'http://218.28.198.186:10508';
 // let BASE_URL = 'https://uat.hnyfwlw.com'
 export const myRequest = (options) => {
   // BASE_URL=uni.getStorageSync('http')