李程龙 3 rokov pred
rodič
commit
98d3033253

+ 174 - 0
components/ui-sticky/ui-sticky.vue

@@ -0,0 +1,174 @@
+<template>
+	<view class="">
+		<view class="u-sticky-wrap" :class="[elClass]" :style="{
+			height: fixed ? height + 'px' : 'auto',
+			backgroundColor: bgColor
+		}">
+			<view class="u-sticky" :style="{
+				position: fixed ? 'fixed' : 'static',
+				top: stickyTop + 'px',
+				left: left + 'px',
+				width: width == 'auto' ? 'auto' : width + 'px',
+				zIndex: uZIndex,
+				backgroundColor: bgColor
+			}">
+				<slot></slot>
+			</view>
+		</view>
+	</view>
+</template>
+
+<script>
+	/**
+	 * sticky 吸顶
+	 * @description 该组件与CSS中position: sticky属性实现的效果一致,当组件达到预设的到顶部距离时, 就会固定在指定位置,组件位置大于预设的顶部距离时,会重新按照正常的布局排列。
+	 * @tutorial https://www.uviewui.com/components/sticky.html
+	 * @property {String Number} offset-top 吸顶时与顶部的距离,单位rpx(默认0)
+	 * @property {String Number} index 自定义标识,用于区分是哪一个组件
+	 * @property {Boolean} enable 是否开启吸顶功能(默认true)
+	 * @property {String} bg-color 组件背景颜色(默认#ffffff)
+	 * @property {String Number} z-index 吸顶时的z-index值(默认970)
+	 * @property {String Number} h5-nav-height 导航栏高度,自定义导航栏时(无导航栏时需设置为0),需要传入此值,单位px(默认44)
+	 * @event {Function} fixed 组件吸顶时触发
+	 * @event {Function} unfixed 组件取消吸顶时触发
+	 * @example <u-sticky offset-top="200"><view>塞下秋来风景异,衡阳雁去无留意</view></u-sticky>
+	 */
+	export default {
+		name: "ui-sticky",
+		props: {
+			// 吸顶容器到顶部某个距离的时候,进行吸顶,在H5平台,NavigationBar为44px
+			offsetTop: {
+				type: [Number, String],
+				default: 0
+			},
+			//列表中的索引值
+			index: {
+				type: [Number, String],
+				default: ''
+			},
+			// 是否开启吸顶功能
+			enable: {
+				type: Boolean,
+				default: true
+			},
+			// h5顶部导航栏的高度
+			h5NavHeight: {
+				type: [Number, String],
+				default: 0
+			},
+			// 吸顶区域的背景颜色
+			bgColor: {
+				type: String,
+				default: '#ffffff'
+			},
+			// z-index值
+			zIndex: {
+				type: [Number, String],
+				default: ''
+			}
+		},
+		data() {
+			return {
+				fixed: false,
+				height: 'auto',
+				stickyTop: 0,
+				elClass:'ui-sticky1',
+				left: 0,
+				width: 'auto',
+			};
+		},
+		watch: {
+			offsetTop(val) {
+				this.initObserver();
+			},
+			enable(val) {
+				if (val == false) {
+					this.fixed = false;
+					this.disconnectObserver('contentObserver');
+				} else {
+					this.initObserver();
+				}
+			}
+		},
+		computed: {
+			uZIndex() {
+				return this.zIndex ? this.zIndex : 10;
+			}
+		},
+		mounted() {
+			this.initObserver();
+		},
+		methods: {
+			// 查询节点信息
+			// 目前此方法在支付宝小程序中无法获取组件跟接点的尺寸,为支付宝的bug(2020-07-21)
+			// 解决办法为在组件根部再套一个没有任何作用的view元素
+			$uGetRect(selector, all) {
+				return new Promise(resolve => {
+					uni.createSelectorQuery().
+					in(this)[all ? 'selectAll' : 'select'](selector)
+						.boundingClientRect(rect => {
+							if (all && Array.isArray(rect) && rect.length) {
+								resolve(rect)
+							}
+							if (!all && rect) {
+								resolve(rect)
+							}
+						})
+						.exec()
+				})
+			},
+			initObserver() {
+				if (!this.enable) return;
+				// #ifdef H5
+				this.stickyTop = this.offsetTop != 0 ? uni.upx2px(this.offsetTop) + this.h5NavHeight : this.h5NavHeight;
+				// #endif
+				// #ifndef H5
+				this.stickyTop = this.offsetTop != 0 ? uni.upx2px(this.offsetTop) : 0;
+				// #endif
+
+				this.disconnectObserver('contentObserver');
+				this.$uGetRect('.' + this.elClass).then((res) => {
+					this.height = res.height;
+					this.left = res.left;
+					this.width = res.width;
+					this.$nextTick(() => {
+						this.observeContent();
+					});
+				});
+			},
+			observeContent() {
+				this.disconnectObserver('contentObserver');
+				const contentObserver = this.createIntersectionObserver({
+					thresholds: [0.95, 0.98, 1]
+				});
+				contentObserver.relativeToViewport({
+					top: -this.stickyTop
+				});
+				contentObserver.observe('.' + this.elClass, res => {
+					if (!this.enable) return;
+					this.setFixed(res.boundingClientRect.top);
+				});
+				this.contentObserver = contentObserver;
+			},
+			setFixed(top) {
+				const fixed = top < this.stickyTop;
+				if (fixed) this.$emit('fixed', this.index);
+				else if(this.fixed) this.$emit('unfixed', this.index);
+				this.fixed = fixed;
+			},
+			disconnectObserver(observerName) {
+				const observer = this[observerName];
+				observer && observer.disconnect();
+			},
+		},
+		beforeDestroy() {
+			this.disconnectObserver('contentObserver');
+		}
+	};
+</script>
+
+<style scoped lang="scss">
+	.u-sticky {
+		z-index: 9999999999;
+	}
+</style>

+ 11 - 12
pages/aftersale/index.vue

@@ -6,11 +6,11 @@
 			<view class="form-title">
 				基本信息
 			</view>
-			<input class="form-input" v-model="aftersale.device_id" placeholder="设备ID" type="text" />
-			<input class="form-input" v-model="aftersale.device_name" placeholder="设备名称" type="text" />
-			<input class="form-input" v-model="aftersale.user" placeholder="请输入联系人名称" type="text" />
-			<input class="form-input" v-model="aftersale.phone" placeholder="请输入联系人电话" type="text" />
-			<input class="form-input" v-model="aftersale.addr" placeholder="请输入联系人地址" type="text" />
+			<input class="form-input" v-model="aftersale.device_id" maxlength="50" placeholder="设备ID" type="text" />
+			<input class="form-input" v-model="aftersale.device_name" maxlength="20" placeholder="设备名称" type="text" />
+			<input class="form-input" v-model="aftersale.user" maxlength="10" placeholder="请输入联系人名称" type="text" />
+			<input class="form-input" v-model="aftersale.phone" maxlength="11" placeholder="请输入联系人电话" type="text" />
+			<input class="form-input" v-model="aftersale.addr" maxlength="50" placeholder="请输入联系人地址" type="text" />
 			<view class="form-title" style="padding-top: 24rpx;">
 				故障信息
 			</view>
@@ -23,7 +23,6 @@
 			</view>
 			<!-- 上传文件 -->
 			<view class="ui-upload" id="descripImg">
-
 				<view class="ui-upload_file" v-for="(item,index) in imgList" :key="index">
 					<uni-icons class="close" type="clear" @click="removeFile('image',0)" size="30" color="#333">
 					</uni-icons>
@@ -66,7 +65,7 @@
 				// 上报信息
 				aftersale: {
 					device_id: '',
-					device_name:'',
+					device_name: '',
 					errordesc: "", //描述信息
 					errorimg: "", //图片链接,多张图片用 , 进行隔开
 					errorvideo: "", //视频链接
@@ -78,8 +77,8 @@
 			}
 		},
 		onLoad(options) {
-			this.aftersale.device_id=options.deviceId;
-			this.aftersale.device_name=options.name;
+			this.aftersale.device_id = options.deviceId;
+			this.aftersale.device_name = options.name;
 		},
 		methods: {
 			/**
@@ -94,10 +93,10 @@
 				this.$api.loading('上传中...');
 				let res = await uploadFile(file);
 				this.$api.hide();
-				if(!res){
+				if (!res) {
 					return;
 				}
-				this.$api.msg('上传成功','success');
+				this.$api.msg('上传成功', 'success');
 				// baseUrl 图片根据 img_url
 				if (type == 'image') {
 					return this.imgList.push(res)
@@ -136,7 +135,7 @@
 			},
 			// 提交保存
 			async submitAftersaleInfo(e) {
-				if(this.imgList.length==0 || !this.aftersale.errorvideo){
+				if (this.imgList.length == 0 || !this.aftersale.errorvideo) {
 					return this.$api.msg('请上传故障图片与视频');
 				}
 				this.$api.loading("上报中...");

+ 1 - 1
pages/aftersale/list.vue

@@ -22,6 +22,7 @@
 				<view class="flex-1 info">
 					<view class="font-16 title" :class="item.is_online==1?'on':'off'">设备名称:{{item.device_name?item.device_name:'测报灯'}}</view>
 					<view class="text">设备ID:{{item.imei}}</view>
+					<view class="text text-ellipsis">地址:{{item.address}}</view>
 					<view class="text">最新上报时间:{{ item.uptime | timeFrom}}</view>
 				</view>
 				<view class="aftersale-tips">故障上报</view>
@@ -31,7 +32,6 @@
 				<view class="flex-1 info">
 					<view class="font-16 title" :class="item.status==1?'on':'off'">设备名称:{{item.device_name}}</view>
 					<view class="text">设备ID:{{item.device_id}}</view>
-					<view class="text">SIM卡号:{{ item.sim}}</view>
 				</view>
 				<view class="aftersale-tips">故障上报</view>
 			</view>

+ 7 - 4
pages/pest/index.vue

@@ -1,8 +1,10 @@
 <template>
 	<!-- 病虫害百科 -->
 	<view>
-		<ui-search placeholder="请输入害虫名字" @confirm="searchPestList"></ui-search>
-		<ui-tabs :list="tabs" :active="params.code" @clickTab="clickPestTab"></ui-tabs>
+		<ui-sticky>
+			<ui-search placeholder="请输入害虫名字" @confirm="searchPestList"></ui-search>
+			<ui-tabs :list="tabs" :active="params.code" @clickTab="clickPestTab"></ui-tabs>
+		</ui-sticky>
 		<!-- 病虫害百科列表 -->
 		<view class="page-panel pest-panel">
 			<block v-for="(item,index) in pestList" :key="index">
@@ -13,6 +15,7 @@
 					</view>
 				</view>
 			</block>
+			<ui-empty v-if="pestList.length==0"></ui-empty>
 		</view>
 	</view>
 </template>
@@ -38,10 +41,10 @@
 
 				// tabs列表
 				tabs: [{
-					text: '虫害百科',
+					text: '虫害',
 					value: 2
 				}, {
-					text: '病害百科',
+					text: '病害',
 					value: 1
 				}]
 			};

+ 2 - 2
pages/worm/details.vue

@@ -6,7 +6,7 @@
 			<view class="flex-1">
 				<view class="font-16 title">虫情监测</view>
 				<view class="text">设备ID:{{deviceImei}}</view>
-				<view class="text">设备名称:测报灯</view>
+				<view class="text">设备名称:{{lampDetails.device_name}}</view>
 				<view class="text text-ellipsis">地址:{{lampDetails.address}}</view>
 				<view class="text">最新上报时间:{{uptime | timeFrom}}</view>
 			</view>
@@ -21,7 +21,7 @@
 			</navigator>
 			<navigator :url="`analyse?id=${deviceId}`" class="worm-nav-item" hover-class="none">
 				<image src="@/static/img/worm-nav-1.png" class="icon" mode="aspectFill"></image>
-				<view class=" text">虫分析</view>
+				<view class=" text">虫分析</view>
 			</navigator>
 			<navigator :url="`history?imeiId=${deviceImei}`" class="worm-nav-item" hover-class="none">
 				<image src="@/static/img/worm-nav-3.png" class="icon" mode="aspectFill"></image>

+ 1 - 1
pages/worm/history.vue

@@ -37,7 +37,7 @@
 				</uni-tr>
 			</uni-table>
 			<!-- 页码 -->
-			<uni-pagination :total="total" @change="getHistoryList" />
+			<uni-pagination :total="total" v-if="!loading" @change="getHistoryList" />
 			<!-- 页码end -->
 		</view>
 		<!-- 历史数据列表end -->

+ 1 - 0
pages/worm/index.vue

@@ -11,6 +11,7 @@
 					<view class="font-16  title" :class="item.is_online?'on':'off'">
 						{{item.device_name?item.device_name:'测报灯'}}</view>
 					<view class="text">设备ID:{{item.imei}}</view>
+					<view class="text text-ellipsis">地址:{{item.address}}</view>
 					<view class="text">最新上报时间:{{ item.uptime | timeFrom}}</view>
 				</view>
 				<ui-state :state="item.is_online"></ui-state>