diff --git a/src/pages/calendar/Index.vue b/src/pages/calendar/Index.vue index 40eef71d..e404fac5 100644 --- a/src/pages/calendar/Index.vue +++ b/src/pages/calendar/Index.vue @@ -1,65 +1,82 @@ diff --git a/src/pages/colPicker/Index.vue b/src/pages/colPicker/Index.vue index 690c5aab..088bbe3a 100644 --- a/src/pages/colPicker/Index.vue +++ b/src/pages/colPicker/Index.vue @@ -123,20 +123,10 @@ const cellValue = reactive<{ [key: PropertyKey]: any }>({ const value1 = ref([]) const value2 = ref([]) -const value3 = ref(['130000', '130200', '130204']) const value4 = ref([]) -const value5 = ref([]) -const value6 = ref(['130000', '130200', '130204']) const value7 = ref([]) const value8 = ref([]) -const value9 = ref([]) -const value10 = ref([]) const value11 = ref([]) -const value12 = ref([]) -const value13 = ref([]) -const value14 = ref([]) -const value15 = ref([]) -const displayValue = ref('') const areaData1 = ref([ colPickerData.map((item) => { return { diff --git a/src/pages/datetimePicker/Index.vue b/src/pages/datetimePicker/Index.vue index 7c4e5cc6..2f19e3e0 100644 --- a/src/pages/datetimePicker/Index.vue +++ b/src/pages/datetimePicker/Index.vue @@ -1,67 +1,130 @@ diff --git a/src/pages/picker/Index.vue b/src/pages/picker/Index.vue index 296fcb23..f79e2480 100644 --- a/src/pages/picker/Index.vue +++ b/src/pages/picker/Index.vue @@ -1,49 +1,65 @@ - +const visible = reactive({ + visible1: false, + visible2: false, + visible3: false, + visible4: false, + visible5: false, + visible6: false +}) + +const cellValue = reactive<{ [key: PropertyKey]: any }>({ + value1: '', + value2: '选项4', + value3: '', + value4: '', + value5: '选项1', + value6: '' +}) + + diff --git a/src/uni_modules/wot-design-uni/components/wd-calendar/types.ts b/src/uni_modules/wot-design-uni/components/wd-calendar/types.ts index 21dc4e1c..fb26f6d3 100644 --- a/src/uni_modules/wot-design-uni/components/wd-calendar/types.ts +++ b/src/uni_modules/wot-design-uni/components/wd-calendar/types.ts @@ -1,10 +1,10 @@ /* * @Author: weisheng * @Date: 2024-03-15 20:40:34 - * @LastEditTime: 2024-11-13 13:18:15 + * @LastEditTime: 2024-12-03 13:29:49 * @LastEditors: weisheng * @Description: - * @FilePath: \wot-design-uni\src\uni_modules\wot-design-uni\components\wd-calendar\types.ts + * @FilePath: /wot-design-uni/src/uni_modules/wot-design-uni/components/wd-calendar/types.ts * 记得注释 */ import type { PropType } from 'vue' @@ -110,7 +110,11 @@ export const calendarProps = { /** * 是否在手指松开时立即触发picker-view的 change 事件。若不开启则会在滚动动画结束后触发 change 事件,1.2.25版本起提供,仅微信小程序和支付宝小程序支持。 */ - immediateChange: makeBooleanProp(false) + immediateChange: makeBooleanProp(false), + /** + * 是否显示 + */ + visible: makeBooleanProp(false) } export type CalendarDisplayFormat = (value: number | number[], type: CalendarType) => string diff --git a/src/uni_modules/wot-design-uni/components/wd-calendar/wd-calendar.vue b/src/uni_modules/wot-design-uni/components/wd-calendar/wd-calendar.vue index 90893dc8..ac012dc7 100644 --- a/src/uni_modules/wot-design-uni/components/wd-calendar/wd-calendar.vue +++ b/src/uni_modules/wot-design-uni/components/wd-calendar/wd-calendar.vue @@ -4,14 +4,17 @@ v-model="pickerShow" :duration="250" :close-on-click-modal="closeOnClickModal" - :safe-area-inset-bottom="safeAreaInsetBottom" + :hide-when-close="false" :z-index="zIndex" - @close="close" + :safe-area-inset-bottom="safeAreaInsetBottom" + @close="handlePickerClose" + @closed="handlePickerClosed" + @opened="handlePickerOpened" > {{ title || translate('title') }} - + @@ -32,10 +35,7 @@ - + { @@ -130,20 +131,21 @@ const formatRange = (value: number, rangeType: 'start' | 'end', type: CalendarTy } const props = defineProps(calendarProps) -const emit = defineEmits(['cancel', 'change', 'update:modelValue', 'confirm', 'open']) +const emit = defineEmits(['cancel', 'change', 'update:modelValue', 'confirm', 'open', 'update:visible', 'close']) const pickerShow = ref(false) const calendarValue = ref(null) const lastCalendarValue = ref(null) const panelHeight = ref(338) -const confirmBtnDisabled = ref(true) +const confirmBtnDisabled = computed(() => { + return getConfirmBtnStatus(calendarValue.value) +}) const currentTab = ref(0) const lastTab = ref(0) const currentType = ref('date') const lastCurrentType = ref() -const inited = ref(false) -const calendarView = ref() -const calendarTabs = ref() +const calendarViewRef = ref() // 日历组件实例 +const tabsRef = ref() // tabs组件实例 const rangeLabel = computed(() => { const [start, end] = deepClone(isArray(calendarValue.value) ? calendarValue.value : []) @@ -157,13 +159,24 @@ watch( (val, oldVal) => { if (isEqual(val, oldVal)) return calendarValue.value = deepClone(val) - confirmBtnDisabled.value = getConfirmBtnStatus(val) }, { immediate: true } ) +watch( + () => props.visible, + (newValue) => { + if (newValue) { + open() + } else { + close() + } + }, + { deep: true, immediate: true } +) + watch( () => props.type, (newValue) => { @@ -201,11 +214,11 @@ const range = computed(() => { }) function scrollIntoView() { - calendarView.value && calendarView.value && calendarView.value.$.exposed.scrollIntoView() + calendarViewRef.value && calendarViewRef.value && calendarViewRef.value!.scrollIntoView() } + // 对外暴露方法 function open() { - inited.value = true pickerShow.value = true lastCalendarValue.value = deepClone(calendarValue.value) lastTab.value = currentTab.value @@ -213,50 +226,65 @@ function open() { requestAnimationFrame(() => { scrollIntoView() }) - - setTimeout(() => { - if (props.showTypeSwitch) { - calendarTabs.value.scrollIntoView() - calendarTabs.value.updateLineStyle(false) - } - }, 250) - emit('open') } + +/** + * 弹出框打开后 + */ +function handlePickerOpened() { + if (props.showTypeSwitch && tabsRef.value) { + tabsRef.value.scrollIntoView() + tabsRef.value.updateLineStyle(false) + } +} + // 对外暴露方法 function close() { pickerShow.value = false - setTimeout(() => { - calendarValue.value = deepClone(lastCalendarValue.value) - currentTab.value = lastTab.value - currentType.value = lastCurrentType.value || 'date' - confirmBtnDisabled.value = getConfirmBtnStatus(lastCalendarValue.value) - }, 250) - emit('cancel') } + +/** + * 弹出框关闭时 + */ +function handlePickerClose() { + emit('update:visible', false) + emit('close') +} + +/** + * 弹出框关闭后 + */ +function handlePickerClosed() { + calendarValue.value = deepClone(lastCalendarValue.value) + currentTab.value = lastTab.value + currentType.value = lastCurrentType.value || 'date' + scrollIntoView() +} + function handleTypeChange({ index }: { index: number }) { - const tabs = ['date', 'week', 'month'] - const rangeTabs = ['daterange', 'weekrange', 'monthrange'] + const tabs: CalendarType[] = ['date', 'week', 'month'] + const rangeTabs: CalendarType[] = ['daterange', 'weekrange', 'monthrange'] const type = props.type.indexOf('range') > -1 ? rangeTabs[index] : tabs[index] currentTab.value = index - currentType.value = type as CalendarType + currentType.value = type } + function getConfirmBtnStatus(value: number | number[] | null) { - let confirmBtnDisabled = false + let disabled = false // 范围选择未选择满,或者多日期选择未选择日期,按钮置灰不可点击 if ( (props.type.indexOf('range') > -1 && (!isArray(value) || !value[0] || !value[1] || !value)) || (props.type === 'dates' && (!isArray(value) || value.length === 0 || !value)) || !value ) { - confirmBtnDisabled = true + disabled = true } - return confirmBtnDisabled + return disabled } + function handleChange({ value }: { value: number | number[] | null }) { calendarValue.value = deepClone(value) - confirmBtnDisabled.value = getConfirmBtnStatus(value) - emit('change', { value }) @@ -265,6 +293,7 @@ function handleChange({ value }: { value: number | number[] | null }) { handleConfirm() } } + function handleConfirm() { if (props.beforeConfirm) { props.beforeConfirm({ @@ -280,10 +309,13 @@ function handleConfirm() { function onConfirm() { pickerShow.value = false lastCurrentType.value = currentType.value + lastCalendarValue.value = deepClone(calendarValue.value) + lastTab.value = currentTab.value emit('update:modelValue', calendarValue.value) emit('confirm', { value: calendarValue.value }) + emit('update:visible', false) } function handleShortcutClick(index: number) { @@ -294,9 +326,7 @@ function handleShortcutClick(index: number) { index }) ) - confirmBtnDisabled.value = getConfirmBtnStatus(calendarValue.value) } - if (!props.showConfirm) { handleConfirm() } diff --git a/src/uni_modules/wot-design-uni/components/wd-col-picker/types.ts b/src/uni_modules/wot-design-uni/components/wd-col-picker/types.ts index 47810097..e4d81262 100644 --- a/src/uni_modules/wot-design-uni/components/wd-col-picker/types.ts +++ b/src/uni_modules/wot-design-uni/components/wd-col-picker/types.ts @@ -66,15 +66,7 @@ export const colPickerProps = { /** * 弹出面板是否设置底部安全距离(iphone X 类型的机型) */ - safeAreaInsetBottom: makeBooleanProp(true), - /** - * 底部条宽度,单位像素 - */ - lineWidth: numericProp, - /** - * 底部条高度,单位像素 - */ - lineHeight: numericProp + safeAreaInsetBottom: makeBooleanProp(true) } export type ColPickerProps = ExtractPropTypes @@ -87,7 +79,6 @@ export type ColPickerColumnChangeOption = { finish: (isOk?: boolean) => void } export type ColPickerColumnChange = (option: ColPickerColumnChangeOption) => void -export type ColPickerDisplayFormat = (selectedItems: ColPickerOption[]) => string export type ColPickerBeforeConfirm = (value: (string | number)[], selectedItems: ColPickerOption[], resolve: (isPass: boolean) => void) => void export type ColPickerExpose = { diff --git a/src/uni_modules/wot-design-uni/components/wd-col-picker/wd-col-picker.vue b/src/uni_modules/wot-design-uni/components/wd-col-picker/wd-col-picker.vue index 718f12d1..44acb5f1 100644 --- a/src/uni_modules/wot-design-uni/components/wd-col-picker/wd-col-picker.vue +++ b/src/uni_modules/wot-design-uni/components/wd-col-picker/wd-col-picker.vue @@ -5,14 +5,14 @@ :duration="250" :title="title || translate('title')" :close-on-click-modal="closeOnClickModal" - :hideWhenClose="false" + :hide-when-close="false" :z-index="zIndex" :safe-area-inset-bottom="safeAreaInsetBottom" @opened="handlePickerOpened" @close="handlePickerClose" @closed="handlePickerClosed" > - + @@ -62,7 +62,7 @@ import { colPickerProps, type ColPickerExpose, type ColPickerOption } from './ty import type { TabsInstance } from '../wd-tabs/types' const { translate } = useTranslate('col-picker') -const tabs = ref() +const tabsRef = ref() const props = defineProps(colPickerProps) const emit = defineEmits(['close', 'update:modelValue', 'update:visible', 'confirm']) @@ -70,7 +70,6 @@ const innerValue = ref(props.modelValue) // 当前选择值 const innerColumns = ref(props.columns) // 全部列数据 const currentColumn = ref([]) // 当前展示列数据 const animated = ref(false) // 是否开启切换动画 弹窗打开后开启 - const pickerShow = ref(false) const currentCol = ref(0) const loading = ref(false) @@ -134,8 +133,8 @@ function updateInnerValue() { * 弹出框打开后 */ function handlePickerOpened() { - if (isDef(tabs.value)) { - tabs.value?.updateLineStyle(false) + if (isDef(tabsRef.value)) { + tabsRef.value?.updateLineStyle(false) animated.value = true } } @@ -153,17 +152,15 @@ function handlePickerClose() { */ function handlePickerClosed() { animated.value = false - setTimeout(() => { - innerColumns.value = lastSelectList.value.slice(0) - innerValue.value = lastPickerColSelected.value.slice(0) - currentColumn.value = lastPickerColSelected.value.map((item, colIndex) => { - return getSelectedItem(item, colIndex, lastSelectList.value)[props.labelKey] - }) - currentCol.value = lastSelectList.value.length - 1 - if (isDef(tabs.value)) { - tabs.value.updateLineStyle(false) - } - }, 250) + innerColumns.value = lastSelectList.value.slice(0) + innerValue.value = lastPickerColSelected.value.slice(0) + currentColumn.value = lastPickerColSelected.value.map((item, colIndex) => { + return getSelectedItem(item, colIndex, lastSelectList.value)[props.labelKey] + }) + currentCol.value = lastSelectList.value.length - 1 + if (isDef(tabsRef.value)) { + tabsRef.value.updateLineStyle(false) + } } function getSelectedItem(value: string | number, colIndex: number, innerColumns: ColPickerOption[][]) { diff --git a/src/uni_modules/wot-design-uni/components/wd-datetime-picker/types.ts b/src/uni_modules/wot-design-uni/components/wd-datetime-picker/types.ts index eb93e4ed..a2c86e60 100644 --- a/src/uni_modules/wot-design-uni/components/wd-datetime-picker/types.ts +++ b/src/uni_modules/wot-design-uni/components/wd-datetime-picker/types.ts @@ -90,10 +90,6 @@ export const datetimePickerProps = { * 在区域选择模式下,自定义展示tab标签文案的格式化函数,返回一个字符串 */ displayFormatTabLabel: Function as PropType, - /** - * 默认日期,类型保持与 value 一致,打开面板时面板自动选到默认日期 - */ - defaultValue: [String, Number, Array] as PropType>, /** * 弹窗层级 */ @@ -105,7 +101,11 @@ export const datetimePickerProps = { /** * 是否在手指松开时立即触发picker-view的 change 事件。若不开启则会在滚动动画结束后触发 change 事件,1.2.25版本起提供,仅微信小程序和支付宝小程序支持。 */ - immediateChange: makeBooleanProp(false) + immediateChange: makeBooleanProp(false), + /** + * 是否显示 + */ + visible: makeBooleanProp(false) } export type DatetimePickerDisplayFormat = (items: Record[]) => string diff --git a/src/uni_modules/wot-design-uni/components/wd-datetime-picker/wd-datetime-picker.vue b/src/uni_modules/wot-design-uni/components/wd-datetime-picker/wd-datetime-picker.vue index 6dea4c5d..5ee248be 100644 --- a/src/uni_modules/wot-design-uni/components/wd-datetime-picker/wd-datetime-picker.vue +++ b/src/uni_modules/wot-design-uni/components/wd-datetime-picker/wd-datetime-picker.vue @@ -1,6 +1,5 @@