Skip to content

Commit

Permalink
feat: 新增 clamp 函数 (#1901)
Browse files Browse the repository at this point in the history
* 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 函数
  • Loading branch information
yangxiaolu1993 authored Dec 4, 2022
1 parent 68f7370 commit ad3647f
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 6 deletions.
4 changes: 1 addition & 3 deletions src/packages/__VUE/imagepreview/imagePreviewItem.vue
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
import { toRefs, reactive, watch, computed, CSSProperties, PropType } from 'vue';
import { createComponent } from '@/packages/utils/create';
import { useTouch } from '@/packages/utils/useTouch';
import { preventDefault } from '@/packages/utils/util';
import { preventDefault, clamp } from '@/packages/utils/util';
import { ImageInterface } from './types';
import { baseProps } from './types';
const { create } = createComponent('imagepreviewitem');
Expand Down Expand Up @@ -262,8 +262,6 @@ export default create({
touch.reset();
};
const clamp = (num: number, min: number, max: number): number => Math.min(Math.max(num, min), max);
const closeSwiper = () => {
emit('close');
};
Expand Down
4 changes: 2 additions & 2 deletions src/packages/__VUE/picker/Column.vue
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
import { reactive, ref, watch, computed, toRefs, onMounted, PropType } from 'vue';
import { createComponent } from '@/packages/utils/create';
import { PickerOption, TouchParams } from './types';
import { preventDefault } from '@/packages/utils/util';
import { preventDefault, clamp } from '@/packages/utils/util';
import { useTouch } from '@/packages/utils/useTouch';
const { create } = createComponent('picker-column');
Expand Down Expand Up @@ -223,7 +223,7 @@ export default create({
const maxDeg = (props.column.length + 1) * state.rotation;
const minDeg = 0;
deg = Math.min(Math.max(currentDeg, minDeg), maxDeg);
deg = clamp(currentDeg, minDeg, maxDeg);
if (minDeg < deg && deg < maxDeg) {
setTransform(updateMove, null, undefined, deg + 'deg');
Expand Down
3 changes: 2 additions & 1 deletion src/packages/__VUE/picker/ColumnTaro.vue
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import { reactive, ref, watch, computed, toRefs, onMounted, PropType } from 'vue
import { createComponent } from '@/packages/utils/create';
import { PickerOption, TouchParams } from './types';
import { useTaroRect } from '@/packages/utils/useTaroRect';
import { clamp } from '@/packages/utils/util';
import { useTouch } from '@/packages/utils/useTouch';
const { create } = createComponent('picker-column');
import Taro from '@tarojs/taro';
Expand Down Expand Up @@ -241,7 +242,7 @@ export default create({
const maxDeg = (props.column.length + 1) * state.rotation;
const minDeg = 0;
deg = Math.min(Math.max(currentDeg, minDeg), maxDeg);
deg = clamp(currentDeg, minDeg, maxDeg);
if (minDeg < deg && deg < maxDeg) {
setTransform(updateMove, null, undefined, deg + 'deg');
Expand Down
2 changes: 2 additions & 0 deletions src/packages/utils/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,3 +138,5 @@ export const padZero = (num: number | string, length = 2): string => {
}
return num.toString();
};

export const clamp = (num: number, min: number, max: number): number => Math.min(Math.max(num, min), max);

0 comments on commit ad3647f

Please sign in to comment.