Skip to content

fix(TimePicker): 修改滚动条bug和完善时间限制 #11

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 1 commit into from
Dec 15, 2021
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
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,14 @@ export default function useTimeScroll():any{

// 点击轨道 thumb滚动到相应位置
const clickTrackFun = (e:MouseEvent)=>{
const offset = Math.abs(scrollTrackDom.value.getBoundingClientRect().top - e.clientY)
const offsetNum = scrollTrackDom.value.getBoundingClientRect().top - e.clientY
const offset = Math.abs(offsetNum > 0 ? 0 : offsetNum)
const thumbCenter = scrollThumbDom.value.offsetHeight / 2;
const thumbPosition = (offset - thumbCenter) * 100 / scrollContentDom.value.offsetHeight;
scrollContentDom.value.scrollTop = (thumbPosition * scrollContentDom.value.scrollHeight / 100);
scrollContentDom.value.style.top = scrollContentDom.value.scrollTop + 'px'
}

// 鼠标拖到
const mouseDownThum = ()=>{
isDown.value = true
Expand All @@ -41,18 +42,14 @@ export default function useTimeScroll():any{
}

const thumbMouseMove = (e:any)=>{

const path = (e.composedPath && e.composedPath()) || e.path

if(path.includes(scrollBoxDom.value) || isDown.value){
scrollTrackDom.value.style.opacity = 1
}else{
scrollTrackDom.value.style.opacity = 0
}

if( !isDown.value ) return
clickTrackFun(e)

}

const getScrollWidth=()=>{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,18 @@ export default function useTimePicker(

const vModelValueArr = value.split(':')
const minTimeValueArr = minTime.split(':')
const maxTimeValueArr = maxTime.split(':')

vModeValue.value == ''
? vModeValue.value = '00:00:00'
: ''
if( vModeValue.value > minTime ){

if( value > minTime && value < maxTime){
firsthandActiveTime.value = value
setInputValue(vModelValueArr[0],vModelValueArr[1],vModelValueArr[2])
}else if( value > maxTime ){
firsthandActiveTime.value = maxTime
setInputValue(maxTimeValueArr[0],maxTimeValueArr[1],maxTimeValueArr[2])
}else{
firsthandActiveTime.value = minTime
setInputValue(minTimeValueArr[0],minTimeValueArr[1],minTimeValueArr[2])
Expand Down