Skip to content

Commit ad3647f

Browse files
feat: 新增 clamp 函数 (#1901)
* fix: 修复 ImagePreview 在Taro编译成H5后报错的问题 * fix: 地址关闭时, Close 事件触发两次问题解决 * feat: 组件DatePicker 添加双向绑定 * docs: 组件Picker文档修改 * feat: 组件Picker与DatePicker新增属性safe-area-inset-bottom * feat: imagepreview * fix: 组件imagepreview点击视频遮罩关闭(#1729) * fix: 解决 Picker 在微信小程序中无法使用问题 (#1774) * fix: 修改 Picker 组件 v-model 失效问题 * fix: 组件NoticeBar修改height之后,垂直轮播会卡顿 * fix: 删除Datepicker Demo演示多余内容 * fix: 组件Picker在JD小程序上适配 * fix: 组件Address京东小程序适配 * feat: 京东小程序适配 * fix: 删除空格 * feat: 删除console * fix: 京东小程序imagepreview适配 * fix: 修复 imagepreview 动态设置 initNo 显示不正确问题 * fix: 组件 InfiniteLoading 某些情况下会错误触发下拉刷新#1819 * fix: 删除pullrefresh * feat: 组件 imagepreview瘦身 * feat: 组件Picker 瘦身 * fix: address线上问题修改 * fix: 完善imagepreview * feat: 公共函数提取 * feat: 函数式改用 createComponent * fix: 文件回撤 * feat: 单元测试修改 * fix: 组件popover样式问题修改 * feat: 新增 clamp 函数
1 parent 68f7370 commit ad3647f

File tree

4 files changed

+7
-6
lines changed

4 files changed

+7
-6
lines changed

src/packages/__VUE/imagepreview/imagePreviewItem.vue

+1-3
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
import { toRefs, reactive, watch, computed, CSSProperties, PropType } from 'vue';
1818
import { createComponent } from '@/packages/utils/create';
1919
import { useTouch } from '@/packages/utils/useTouch';
20-
import { preventDefault } from '@/packages/utils/util';
20+
import { preventDefault, clamp } from '@/packages/utils/util';
2121
import { ImageInterface } from './types';
2222
import { baseProps } from './types';
2323
const { create } = createComponent('imagepreviewitem');
@@ -262,8 +262,6 @@ export default create({
262262
touch.reset();
263263
};
264264
265-
const clamp = (num: number, min: number, max: number): number => Math.min(Math.max(num, min), max);
266-
267265
const closeSwiper = () => {
268266
emit('close');
269267
};

src/packages/__VUE/picker/Column.vue

+2-2
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
import { reactive, ref, watch, computed, toRefs, onMounted, PropType } from 'vue';
3030
import { createComponent } from '@/packages/utils/create';
3131
import { PickerOption, TouchParams } from './types';
32-
import { preventDefault } from '@/packages/utils/util';
32+
import { preventDefault, clamp } from '@/packages/utils/util';
3333
import { useTouch } from '@/packages/utils/useTouch';
3434
const { create } = createComponent('picker-column');
3535
@@ -223,7 +223,7 @@ export default create({
223223
const maxDeg = (props.column.length + 1) * state.rotation;
224224
const minDeg = 0;
225225
226-
deg = Math.min(Math.max(currentDeg, minDeg), maxDeg);
226+
deg = clamp(currentDeg, minDeg, maxDeg);
227227
228228
if (minDeg < deg && deg < maxDeg) {
229229
setTransform(updateMove, null, undefined, deg + 'deg');

src/packages/__VUE/picker/ColumnTaro.vue

+2-1
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ import { reactive, ref, watch, computed, toRefs, onMounted, PropType } from 'vue
3131
import { createComponent } from '@/packages/utils/create';
3232
import { PickerOption, TouchParams } from './types';
3333
import { useTaroRect } from '@/packages/utils/useTaroRect';
34+
import { clamp } from '@/packages/utils/util';
3435
import { useTouch } from '@/packages/utils/useTouch';
3536
const { create } = createComponent('picker-column');
3637
import Taro from '@tarojs/taro';
@@ -241,7 +242,7 @@ export default create({
241242
const maxDeg = (props.column.length + 1) * state.rotation;
242243
const minDeg = 0;
243244
244-
deg = Math.min(Math.max(currentDeg, minDeg), maxDeg);
245+
deg = clamp(currentDeg, minDeg, maxDeg);
245246
246247
if (minDeg < deg && deg < maxDeg) {
247248
setTransform(updateMove, null, undefined, deg + 'deg');

src/packages/utils/util.ts

+2
Original file line numberDiff line numberDiff line change
@@ -138,3 +138,5 @@ export const padZero = (num: number | string, length = 2): string => {
138138
}
139139
return num.toString();
140140
};
141+
142+
export const clamp = (num: number, min: number, max: number): number => Math.min(Math.max(num, min), max);

0 commit comments

Comments
 (0)