Skip to content

Commit 6a2fd6b

Browse files
authored
fix(picker): enhance the compatibility of the date picker on mobile and PC, add isPCMode parameter to control the display logic (#3336)
1 parent 7f4d89c commit 6a2fd6b

File tree

2 files changed

+22
-15
lines changed

2 files changed

+22
-15
lines changed

packages/renderless/src/picker/index.ts

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -64,9 +64,9 @@ export const watchMobileVisible =
6464
}
6565

6666
export const watchPickerVisible =
67-
({ api, vm, dispatch, emit, props, state, nextTick }) =>
67+
({ api, vm, dispatch, emit, props, state, nextTick, isPCMode }) =>
6868
(value) => {
69-
if (props.readonly || state.pickerDisabled || state.isMobileScreen) return
69+
if (props.readonly || state.pickerDisabled || (state.isMobileScreen && !isPCMode)) return
7070

7171
if (value) {
7272
api.showPicker()
@@ -940,20 +940,27 @@ export const handleClose =
940940
}
941941

942942
export const handleFocus =
943-
({ emit, vm, state, api, props }) =>
943+
({ emit, vm, state, api, props, isPCMode }) =>
944944
() => {
945945
const type = state.type
946946
if (props.readonly || state.pickerDisabled) {
947947
return
948948
}
949949

950+
// 判断当前日期选择器类型是否在触发类型列表中
950951
if (DATEPICKER.TriggerTypes.includes(type)) {
951-
if (state.isMobileScreen && state.isDateMobileComponent) {
952+
// 如果不是移动端屏幕或者强制使用PC端模式
953+
if (!state.isMobileScreen || isPCMode) {
954+
// 显示PC端的日期选择弹窗
955+
state.pickerVisible = true
956+
} else if (state.isDateMobileComponent) {
957+
// 如果是移动端日期相关组件(日期、日期时间、日期范围等)
958+
// 调用移动端日期选择器的显示方法
952959
api.dateMobileToggle(true)
953-
} else if (state.isMobileScreen && state.isTimeMobileComponent) {
960+
} else if (state.isTimeMobileComponent) {
961+
// 如果是移动端时间相关组件(时间、时间范围等)
962+
// 调用移动端时间选择器的显示方法
954963
api.timeMobileToggle(true)
955-
} else {
956-
state.pickerVisible = true
957964
}
958965
}
959966

@@ -1057,15 +1064,15 @@ export const handlePick =
10571064
if (!state.picker) return
10581065

10591066
if (chooseOne) {
1060-
const minDate = date && date[0] || ''
1067+
const minDate = (date && date[0]) || ''
10611068

10621069
state.userInput = [api.formatToString(minDate), null]
10631070
} else {
10641071
state.userInput = null
10651072
state.pickerVisible = state.picker.state.visible = visible
1066-
1073+
10671074
api.emitInput(date, visible)
1068-
1075+
10691076
state.date = date
10701077
state.picker.resetView && state.picker.resetView()
10711078
}

packages/renderless/src/picker/vue.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ const initState = ({ api, reactive, vm, computed, props, utils, parent, breakpoi
176176
return state
177177
}
178178

179-
const initApi = ({ api, props, hooks, state, vnode, others, utils, parent }) => {
179+
const initApi = ({ api, props, hooks, state, vnode, others, utils, parent, isPCMode }) => {
180180
const { t, emit, dispatch, nextTick, vm } = vnode
181181
const { TimePanel, TimeRangePanel } = others
182182
const { destroyPopper, popperElm, updatePopper } = initPopper({ props, hooks, vnode })
@@ -190,7 +190,7 @@ const initApi = ({ api, props, hooks, state, vnode, others, utils, parent }) =>
190190
hidePicker: hidePicker({ destroyPopper, state }),
191191
handleSelectChange: ({ tz, date }) => !state.ranged && emit('select-change', { tz, date }),
192192
getPanel: getPanel(others),
193-
handleFocus: handleFocus({ emit, vm, state, api, props }),
193+
handleFocus: handleFocus({ emit, vm, state, api, props, isPCMode }),
194194
getTimezone: getTimezone({ props, utils }),
195195
emitChange: emitChange({ api, dispatch, emit, props, state }),
196196
parsedValue: parsedValue({ api, props, state, t }),
@@ -213,7 +213,7 @@ const initApi = ({ api, props, hooks, state, vnode, others, utils, parent }) =>
213213
handleClose: handleClose({ api, props, state }),
214214
displayValue: displayValue({ api, props, state }),
215215
handlePick: handlePick({ api, state }),
216-
watchPickerVisible: watchPickerVisible({ api, vm, dispatch, emit, props, state, nextTick }),
216+
watchPickerVisible: watchPickerVisible({ api, vm, dispatch, emit, props, state, nextTick, isPCMode }),
217217
watchMobileVisible: watchMobileVisible({ api, props, state, nextTick }),
218218
formatToString: formatToString({ api, state }),
219219
watchIsRange: watchIsRange({ api, state, TimePanel, TimeRangePanel }),
@@ -306,14 +306,14 @@ export const renderless = (
306306
): IPickerApi => {
307307
const api = {} as IPickerApi
308308
const { reactive, computed, watch, onBeforeUnmount, inject, markRaw, onMounted } = hooks
309-
const { vm, service, parent, useBreakpoint } = vnode
309+
const { vm, service, parent, useBreakpoint, isPCMode } = vnode
310310
const { utils = {} } = service || {}
311311
const breakpoint = useBreakpoint()
312312
const state = initState({ api, reactive, vm, computed, props, utils, parent, inject, breakpoint })
313313

314314
parent.tinyForm = parent.tinyForm || inject('form', null)
315315

316-
initApi({ api, props, hooks, state, vnode, others, utils, parent })
316+
initApi({ api, props, hooks, state, vnode, others, utils, parent, isPCMode })
317317
initWatch({ api, state, props, watch, markRaw })
318318

319319
api.initGlobalTimezone()

0 commit comments

Comments
 (0)