Skip to content

fix: picker组件重影问题修复 #1428

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Jun 27, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
67 changes: 42 additions & 25 deletions src/packages/__VUE/picker/Column.vue
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
<template>
<view class="nut-picker__list" @touchstart="onTouchStart" @touchmove="onTouchMove" @touchend="onTouchEnd">
<view class="nut-picker-roller" ref="roller" :style="touchRollerStyle">
<view
class="nut-picker-roller-item"
:class="{ 'nut-picker-roller-item-hidden': isHidden(index + 1) }"
v-for="(item, index) in column"
:style="setRollerStyle(index + 1)"
:key="item.value ? item.value : index"
>
{{ item.text }}
</view>
<template v-for="(item, index) in column" :key="item.value ? item.value : index">
<view
class="nut-picker-roller-item"
:class="{ 'nut-picker-roller-item-hidden': isHidden(index + 1) }"
:style="setRollerStyle(index + 1)"
v-if="item && item.text"
>
{{ item.text }}
</view>
</template>
</view>
<view class="nut-picker-roller-mask"></view>

<view class="nut-picker-content">
<!-- <view class="nut-picker-content">
<view class="nut-picker-list-panel" ref="list" :style="touchListStyle">
<view
:class="['nut-picker-item', 'nut-picker-item-ref', item.className]"
Expand All @@ -22,7 +24,7 @@
</view>
<view class="nut-picker-placeholder" v-if="column && column.length === 1"></view>
</view>
</view>
</view> -->
</view>
</template>
<script lang="ts">
Expand Down Expand Up @@ -118,6 +120,7 @@ export default create({
let move = state.touchParams.lastY - state.touchParams.startY;

let moveTime = state.touchParams.lastTime - state.touchParams.startTime;
console.log('touchEnd', move, moveTime);
if (moveTime <= 300) {
move = move * 2;
moveTime = moveTime + 1000;
Expand Down Expand Up @@ -151,6 +154,7 @@ export default create({
};

const setMove = (move: number, type?: string, time?: number) => {
console.log('setMove');
let updateMove = move + state.transformY;
if (type === 'end') {
// 限定滚动距离
Expand All @@ -164,6 +168,7 @@ export default create({
// 设置滚动距离为lineSpacing的倍数值
let endMove = Math.round(updateMove / state.lineSpacing) * state.lineSpacing;
let deg = `${(Math.abs(Math.round(endMove / state.lineSpacing)) + 1) * state.rotation}deg`;

setTransform(endMove, type, time, deg);

let t = time ? time / 2 : 0;
Expand All @@ -174,14 +179,25 @@ export default create({
state.currIndex = Math.abs(Math.round(endMove / state.lineSpacing)) + 1;
} else {
let deg = '0deg';
let degNum = 0;
if (updateMove < 0) {
deg = `${(Math.abs(updateMove / state.lineSpacing) + 1) * state.rotation}deg`;
degNum = (Math.abs(updateMove / state.lineSpacing) + 1) * state.rotation;
} else {
deg = `${(-updateMove / state.lineSpacing + 1) * state.rotation}deg`;
degNum = (-updateMove / state.lineSpacing + 1) * state.rotation;
}

setTransform(updateMove, null, undefined, deg);
state.currIndex = Math.abs(Math.round(updateMove / state.lineSpacing)) + 1;
// picker 滚动的最大角度
const maxDeg = (props.column.length + 1) * state.rotation;
const minDeg = 0;
if (degNum > maxDeg) {
deg = `${maxDeg}deg`;
} else if (degNum < minDeg) {
deg = `${minDeg}deg`;
} else {
deg = `${degNum}deg`;
setTransform(updateMove, null, undefined, deg);
state.currIndex = Math.abs(Math.round(updateMove / state.lineSpacing)) + 1;
}
}
};

Expand All @@ -202,6 +218,7 @@ export default create({
watch(
() => props.column,
(val) => {
console.log('props.column变化', props.column);
state.transformY = 0;
modifyStatus(false);
},
Expand All @@ -210,16 +227,16 @@ export default create({
}
);

watch(
() => props.value,
(val) => {
console.log('列更新', val);
modifyStatus(true);
},
{
deep: true
}
);
// watch(
// () => props.value,
// (val) => {
// console.log('props.value变化')
// modifyStatus(true);
// },
// {
// deep: true
// }
// );

onMounted(() => {
modifyStatus(true);
Expand Down
30 changes: 21 additions & 9 deletions src/packages/__VUE/picker/ColumnTaro.vue
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
{{ item.text }}
</view>
</view>

<view class="nut-picker-content">
<view class="nut-picker-roller-mask"></view>
<!-- <view class="nut-picker-content">
<view class="nut-picker-list-panel" ref="list" :id="'list' + refRandomId" :style="touchListStyle">
<view
:class="['nut-picker-item', 'nut-picker-item-ref', item.className]"
Expand All @@ -22,7 +22,7 @@
</view>
<view class="nut-picker-placeholder" v-if="column && column.length === 1"></view>
</view>
</view>
</view> -->
</view>
</template>
<script lang="ts">
Expand Down Expand Up @@ -177,13 +177,25 @@ export default create({
state.currIndex = Math.abs(Math.round(endMove / state.lineSpacing)) + 1;
} else {
let deg = '0deg';
let degNum = 0;
if (updateMove < 0) {
deg = `${(Math.abs(updateMove / state.lineSpacing) + 1) * state.rotation}deg`;
degNum = (Math.abs(updateMove / state.lineSpacing) + 1) * state.rotation;
} else {
degNum = (-updateMove / state.lineSpacing + 1) * state.rotation;
}

// picker 滚动的最大角度
const maxDeg = (props.column.length + 1) * state.rotation;
const minDeg = 0;
if (degNum > maxDeg) {
deg = `${maxDeg}deg`;
} else if (degNum < minDeg) {
deg = `${minDeg}deg`;
} else {
deg = `${(-updateMove / state.lineSpacing + 1) * state.rotation}deg`;
deg = `${degNum}deg`;
setTransform(updateMove, null, undefined, deg);
state.currIndex = Math.abs(Math.round(updateMove / state.lineSpacing)) + 1;
}
setTransform(updateMove, null, undefined, deg);
state.currIndex = Math.abs(Math.round(updateMove / state.lineSpacing)) + 1;
}
};

Expand All @@ -202,8 +214,8 @@ export default create({
};

const getReference = async () => {
const refe = await useTaroRect(list, Taro);
state.lineSpacing = refe.height / props.column.length;
// const refe = await useTaroRect(list, Taro);
// state.lineSpacing = refe.height / props.column.length;
modifyStatus(true);
};

Expand Down
2 changes: 2 additions & 0 deletions src/packages/__VUE/picker/doc.en.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ export const Internation = {
ouHai: '瓯海区',
fuJian: '福建',
fuZhou: '福州',
xiaMen: '厦门',
guLou: '鼓楼区',
taiJiang: '台江区',
siMing: '思明区',
Expand Down Expand Up @@ -74,6 +75,7 @@ export const Internation = {
ouHai: 'OuHai',
fuJian: 'FuJian',
fuZhou: 'FuZhou',
xiaMen: 'XiaMen',
guLou: 'GuLou',
taiJiang: 'TaiJiang',
siMing: 'SiMing',
Expand Down
13 changes: 13 additions & 0 deletions src/packages/__VUE/picker/index.scss
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,19 @@
}
}

&-roller-mask {
position: absolute;
width: 100%;
display: block;
height: 100%;
background-image: linear-gradient(180deg, rgba(255, 255, 255, 0.9), rgba(255, 255, 255, 0.4)),
linear-gradient(0deg, rgba(255, 255, 255, 0.9), rgba(255, 255, 255, 0.4));
background-repeat: no-repeat;
background-position: top, bottom;
background-size: 100% 108px;
z-index: 1;
}

&-content {
display: block;
position: absolute;
Expand Down
7 changes: 3 additions & 4 deletions src/packages/__VUE/picker/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

<slot name="top"></slot>

<view class="nut-picker__column">
<view class="nut-picker__column" ref="wrapHeight">
<view class="nut-picker__hairline"></view>
<view class="nut-picker__columnitem" v-for="(column, columnIndex) in columnsList" :key="columnIndex">
<nut-picker-column
Expand Down Expand Up @@ -94,6 +94,8 @@ export default create({
// 选中项
let defaultValues = ref<(number | string)[]>(props.modelValue);

const wrapHeight = ref();

const classes = computed(() => {
const prefixCls = componentName;
return {
Expand Down Expand Up @@ -201,7 +203,6 @@ export default create({
};

onMounted(() => {
console.log(11, props.modelValue);
if (props.visible) state.show = props.visible;
});

Expand All @@ -212,7 +213,6 @@ export default create({
watch(
() => props.modelValue,
(newValues) => {
console.log('change', newValues, defaultValues.value);
const isSameValue = JSON.stringify(newValues) === JSON.stringify(defaultValues.value);
if (!isSameValue) {
defaultValues.value = newValues;
Expand All @@ -235,7 +235,6 @@ export default create({
watch(
() => props.visible,
(val) => {
console.log('props更新', props.columns);
state.show = val;
}
);
Expand Down
2 changes: 1 addition & 1 deletion src/packages/styles/variables-jdb.scss
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ $picker-bar-title-font-size: 16px !default;
$picker-bar-title-color: $title-color !default;
$picker-bar-title-font-weight: normal !default;
$picker-item-height: 36px !default;
$picker-item-text-color: #808080 !default;
$picker-item-text-color: $title-color !default;
$picker-item-active-text-color: inherit !default;
$picker-item-text-font-size: 16px !default;
$picker-item-active-line-border: 1px solid #d8d8d8 !default;
Expand Down
2 changes: 1 addition & 1 deletion src/packages/styles/variables-jdt.scss
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ $picker-bar-title-font-size: 18px !default;
$picker-bar-title-color: #323233 !default;
$picker-bar-title-font-weight: 600 !default;
$picker-item-height: 36px !default;
$picker-item-text-color: #808080 !default;
$picker-item-text-color: $title-color !default;
$picker-item-active-text-color: $primary-color !default;
$picker-item-text-font-size: 16px !default;
$picker-item-active-line-border: 1px solid rgba(0, 0, 0, 0.06) !default;
Expand Down
2 changes: 1 addition & 1 deletion src/packages/styles/variables.scss
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ $picker-bar-title-font-size: 16px !default;
$picker-bar-title-color: $title-color !default;
$picker-bar-title-font-weight: normal !default;
$picker-item-height: 36px !default;
$picker-item-text-color: #808080 !default;
$picker-item-text-color: $title-color !default;
$picker-item-active-text-color: inherit !default;
$picker-item-text-font-size: 16px !default;
$picker-item-active-line-border: 1px solid #d8d8d8 !default;
Expand Down