Skip to content

Commit

Permalink
fix:修复picker滚动问题
Browse files Browse the repository at this point in the history
  • Loading branch information
chaorenluo committed Oct 31, 2024
1 parent e958f37 commit a89448c
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 10 deletions.
15 changes: 7 additions & 8 deletions web/src/management/pages/edit/components/Picker/pickerList.vue
Original file line number Diff line number Diff line change
@@ -1,20 +1,19 @@
<template>
<div class="list" ref="list">
<ul :style="state.ulStyle">
<li v-for="(item, index) in props.column" :key="'item' + index" @click="setTop(index)">{{ item.text }}</li>
<li v-for="(item, index) in props.column" :key="'item' + index" >{{ item.text }}</li>
</ul>
</div>
</template>

<script setup>
import { reactive, computed, onMounted, ref, watch, onBeforeUnmount } from 'vue'
import { getClient, START_EVENT, MOVE_EVENT, END_EVENT } from './utils'
import { isMobile as isInMobile } from '@/render/utils/index'
import { getClient, START_EVENT, MOVE_EVENT, END_EVENT,isPC } from './utils'
const DEFAULT_DURATION = 200
const LIMIT_TIME = 300
const LIMIT_DISTANCE = 15
const IS_Mobile = isInMobile()
const IS_PC = isPC()
const props = defineProps({
Expand Down Expand Up @@ -85,7 +84,7 @@ const handleStart = (e) => {
state.ulStyle.transitionDuration = `0ms`
state.ulStyle.transitionProperty = `none`
if (!IS_Mobile) {
if (IS_PC) {
document.addEventListener(MOVE_EVENT, handleMove, false)
document.addEventListener(END_EVENT, handleEnd, false)
}
Expand Down Expand Up @@ -114,7 +113,7 @@ const handleMove = (e) => {
}
const handleEnd = () => {
if (!IS_Mobile) {
if (IS_PC) {
document.removeEventListener(MOVE_EVENT, handleMove, false)
document.removeEventListener(END_EVENT, handleEnd, false)
}
Expand Down Expand Up @@ -195,7 +194,7 @@ const mousewheel = (e) => {
onMounted(() => {
init();
list.value.addEventListener(START_EVENT, handleStart, false)
if (!IS_Mobile) {
if (IS_PC) {
list.value.addEventListener('wheel', mousewheel, false)
} else {
list.value.addEventListener(MOVE_EVENT, handleMove, false)
Expand All @@ -205,7 +204,7 @@ onMounted(() => {
onBeforeUnmount(() => {
list.value.removeEventListener(START_EVENT, handleStart, false)
if (!IS_Mobile) {
if (IS_PC) {
list.value.removeEventListener('wheel', mousewheel, false)
list.value.removeEventListener(MOVE_EVENT, handleMove, false)
list.value.removeEventListener(END_EVENT, handleEnd, false)
Expand Down
13 changes: 13 additions & 0 deletions web/src/management/pages/edit/components/Picker/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,16 @@ export const getClient = (e:any) => {
y: clientY
}
}

export const isPC = () => {
const userAgentInfo = navigator.userAgent
const Agents = ['Android', 'iPhone', 'SymbianOS', 'Windows Phone', 'iPad', 'iPod']
let flag = true
for (let v = 0; v < Agents.length; v++) {
if (userAgentInfo.indexOf(Agents[v]) > 0) {
flag = false
break
}
}
return flag
}
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
</div>
</template>
<script setup>
import { ref, nextTick, onMounted, computed } from 'vue'
import { ref, nextTick, onMounted, computed,onBeforeUnmount } from 'vue'
import Picker from '@/management/pages/edit/components/Picker/index.vue'
import { isMobile as isInMobile } from '@/render/utils/index'
const props = defineProps({
Expand All @@ -73,7 +73,7 @@ const valList = ref([]);
const pickPop = ref(false)
const listPop = ref([])
const pickIndex = ref(-1)
const isMobile = isInMobile()
const isMobile = ref(isInMobile())
const placeholderList = computed(() => {
return props.multilevelData.placeholder
Expand Down Expand Up @@ -119,12 +119,21 @@ const showPickPop = (list, index) => {
pickIndex.value = index
}
const updateEquipment = () => {
isMobile.value = isInMobile()
}
onMounted(() => {
window.addEventListener('resize', updateEquipment)
placeholderList.value.map(() => {
valList.value.push(null)
})
})
onBeforeUnmount(() => {
window.removeEventListener('resize', updateEquipment)
})
</script>
<style lang="scss" scoped>
Expand Down

0 comments on commit a89448c

Please sign in to comment.