Skip to content

Commit 9d200c0

Browse files
committed
1. 优化懒加载的方法
2. 优化步进器的代码逻辑 3. 修改评分组件对支付宝小程序的支持 4. 添加搜索组件的maxlength参数 5. 优化$u.getRect()方法,使其支持支付宝小程序
1 parent 95fd1c8 commit 9d200c0

File tree

9 files changed

+1148
-1085
lines changed

9 files changed

+1148
-1085
lines changed

uview-ui/components/u-avatar-cropper/u-avatar-cropper.vue

Lines changed: 240 additions & 229 deletions
Large diffs are not rendered by default.

uview-ui/components/u-button/u-button.vue

Lines changed: 465 additions & 443 deletions
Large diffs are not rendered by default.

uview-ui/components/u-cell-item/u-cell-item.vue

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,17 +76,17 @@ export default {
7676
},
7777
// 左侧标题
7878
title: {
79-
type: String,
79+
type: [String, Number],
8080
default: ''
8181
},
8282
// 右侧内容
8383
value: {
84-
type: String,
84+
type: [String, Number],
8585
default: ''
8686
},
8787
// 标题下方的描述信息
8888
label: {
89-
type: String,
89+
type: [String, Number],
9090
default: ''
9191
},
9292
// 是否显示内边框

uview-ui/components/u-lazy-load/u-lazy-load.vue

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,6 @@
1616
</template>
1717

1818
<script>
19-
// observer最终赋值的是个对象,不能放到data中,vue会报错(浏览器),也不能在用到的地方let定义,某些安卓也报错……
20-
let observer = {};
2119
/**
2220
* lazyLoad 懒加载
2321
* @description 懒加载使用的场景为:页面有很多图片时,APP会同时加载所有的图片,导致页面卡顿,各个位置的图片出现前后不一致等.
@@ -116,9 +114,13 @@
116114
},
117115
// 计算图片的高度,可能为auto,带%,或者直接数值
118116
imgHeight() {
119-
return this.height == 'auto' ? 'auto' : this.height.indexOf('%') != -1 ? this.height : this.height + 'rpx';
117+
return this.height == 'auto' ? 'auto' : String(this.height).indexOf('%') != -1 ? this.height : this.height + 'rpx';
120118
}
121119
},
120+
created() {
121+
// 由于一些特殊原因,不能将此变量放到data中定义
122+
this.observer = {};
123+
},
122124
watch: {
123125
isShow(nVal) {
124126
// 如果是不开启过渡效果,直接返回
@@ -166,7 +168,11 @@
166168
// 图片加载失败
167169
loadError() {
168170
this.isError = true;
169-
}
171+
},
172+
disconnectObserver(observerName) {
173+
const observer = this[observerName];
174+
observer && observer.disconnect();
175+
},
170176
},
171177
beforeDestroy() {
172178
// 销毁页面时,可能还没触发某张很底部的懒加载图片,所以把这个事件给去掉
@@ -180,25 +186,23 @@
180186
});
181187
})
182188
// mounted的时候,不一定挂载了这个元素,延时30ms,否则会报错或者不报错,但是也没有效果
183-
let that = this;
184-
//let observer = null;
185189
setTimeout(() => {
186190
// 这里是组件内获取布局状态,不能用uni.createIntersectionObserver,而必须用this.createIntersectionObserver
187-
// 因为这样可以把选择器的选取范围定义在自定义组件内
188-
// 否则某些安卓机型报错,也不能加this(如createIntersectionObserver(this)),否则某些机型也报错
189-
observer = uni.createIntersectionObserver(this);
191+
this.disconnectObserver('contentObserver');
192+
const contentObserver = uni.createIntersectionObserver(this);
190193
// 要理解这里怎么计算的,请看这个:
191194
// https://blog.csdn.net/qq_25324335/article/details/83687695
192-
observer.relativeToViewport({
193-
bottom: that.getThreshold,
194-
}).observe('.u-lazy-item-' + that.elIndex, (res) => {
195+
contentObserver.relativeToViewport({
196+
bottom: this.getThreshold,
197+
}).observe('.u-lazy-item-' + this.elIndex, (res) => {
195198
if (res.intersectionRatio > 0) {
196199
// 懒加载状态改变
197-
that.isShow = true;
200+
this.isShow = true;
198201
// 如果图片已经加载,去掉监听,减少性能的消耗
199-
observer.disconnect();
202+
this.disconnectObserver('contentObserver');
200203
}
201204
})
205+
this.contentObserver = contentObserver;
202206
}, 30)
203207
}
204208
}

uview-ui/components/u-number-box/u-number-box.vue

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,8 +114,8 @@
114114
// 为了让用户能够删除所有输入值,重新输入内容,删除所有值后,内容为空字符串
115115
if (v1 == '') return;
116116
let value = 0;
117-
// 首先判断是否正整数,并且在min和max之间,如果不是,使用原来值
118-
let tmp = /(^\d+$)/.test(v1) && value[0] != 0;
117+
// 首先判断是否正整数,并且第一位数字不为0,并且在min和max之间,如果不是,使用原来值
118+
let tmp = /(^\d+$)/.test(v1) && String(v1)[0] != 0;
119119
if (tmp && v1 >= this.min && v1 <= this.max) value = v1;
120120
else value = v2;
121121
this.handleChange(value, 'change');

0 commit comments

Comments
 (0)