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 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
-
-
- 当前选中日期:{{ formatValue }}
-
- 选择日期
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+ handleConfirm({ ...result, index: 1 })" />
+ handleConfirm({ ...result, index: 2 })" />
+ handleConfirm({ ...result, index: 3, connectors: ' 至 ' })"
+ />
+ handleConfirm({ ...result, index: 4, type: 'datetime' })"
+ />
+ handleConfirm({ ...result, type: 'datetime', index: 5, connectors: ' 至 ' })"
+ />
+ handleConfirm({ ...result, index: 6 })" />
-
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 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+ handleConfirm({ ...result, index: 1 })" />
+ handleConfirm({ ...result, index: 2, type: 'date' })"
+ />
+
+ handleConfirm({ ...result, index: 3, type: 'year-month' })"
+ />
+
+ handleConfirm({ ...result, index: 4, type: 'year' })"
+ />
+
+ handleConfirm({ ...result, index: 5, type: 'time' })"
+ />
+
+ handleConfirm({ ...result, index: 6 })"
+ />
+
+ handleConfirm({ ...result, index: 7 })"
+ />
+
+ handleConfirm({ ...result, index: 8 })"
+ />
+
+ handleConfirm({ ...result, index: 9 })"
+ />
+
+ handleConfirm({ ...result, index: 10 })"
+ :display-format-tab-label="displayFormatTabLabel"
+ />
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 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
-
-
-
-
-
-
-
-
-
-
-
-
- 选中值:
- {{ value8 }}
-
-
- 插槽唤起
-
-
-
+ handleConfirm({ ...result, index: 1 })"
+ />
+ handleConfirm({ ...result, index: 2 })"
+ />
+ handleConfirm({ ...result, index: 3 })"
+ />
+ handleConfirm({ ...result, index: 4 })"
+ />
+
+ handleConfirm({ ...result, index: 5 })"
+ />
+
+ handleConfirm({ ...result, index: 6 })"
+ />
-
+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"
>
-
+
{
@@ -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 @@
-
-
-
-
+
{{ cancelButtonText || translate('cancel') }}
-
{{ title }}
-
{{ confirmButtonText || translate('confirm') }}
-
{{ translate('start') }}
@@ -36,7 +31,6 @@
{{ showTabLabel[1] }}
-
props.visible,
+ (newValue) => {
+ if (newValue) {
+ open()
+ } else {
+ close()
+ }
+ },
+ { deep: true, immediate: true }
+)
+
watch(
() => props.displayFormat,
(fn) => {
@@ -227,22 +233,6 @@ watch(
}
)
-watch(
- () => props.defaultValue,
- (val) => {
- if (isArray(val) || region.value) {
- innerValue.value = deepClone(getDefaultInnerValue(true))
- endInnerValue.value = deepClone(getDefaultInnerValue(true, true))
- } else {
- innerValue.value = deepClone(getDefaultInnerValue())
- }
- },
- {
- deep: true,
- immediate: true
- }
-)
-
/**
* @description 自定义列项筛选规则,对每列单项进行禁用校验,最终返回传入PickerView的columns数组
* @param {Component} picker datetimePickerView对象
@@ -317,34 +307,20 @@ function getSelects(picker: 'before' | 'after') {
function noop() {}
function getDefaultInnerValue(isRegion?: boolean, isEnd?: boolean): string | number {
- const { modelValue: value, defaultValue, maxDate, minDate, type } = props
+ const { modelValue: value, maxDate, minDate, type } = props
if (isRegion) {
const index = isEnd ? 1 : 0
const targetValue = isArray(value) ? (value[index] as string) : ''
- const targetDefault = isArray(defaultValue) ? (defaultValue[index] as string) : ''
const maxValue = type === 'time' ? dayjs(maxDate).format('HH:mm') : maxDate
const minValue = type === 'time' ? dayjs(minDate).format('HH:mm') : minDate
- return targetValue || targetDefault || (isEnd ? maxValue : minValue)
+ return targetValue || (isEnd ? maxValue : minValue)
} else {
- return isDef(value || defaultValue) ? (value as string) || (defaultValue as string) : ''
+ return isDef(value) ? (value as string) : ''
}
}
-// 对外暴露接口,打开弹框
+// 打开弹框
function open() {
- showPopup()
-}
-
-// 对外暴露接口,关闭弹框
-function close() {
- onCancel()
-}
-
-/**
- * @description 展示popup,小程序有个bug,在picker-view弹出时设置value,会触发change事件,而且会将picker-view的value多次触发change重置为第一项
- */
-function showPopup() {
- emit('open')
if (region.value) {
popupShow.value = true
showStart.value = true
@@ -357,6 +333,34 @@ function showPopup() {
setShowValue(true, false, true)
}
+// 关闭弹框
+function close() {
+ popupShow.value = false
+}
+
+/**
+ * 弹出框关闭后
+ */
+function handlePickerClosed() {
+ let timer = setTimeout(() => {
+ clearTimeout(timer)
+ if (region.value) {
+ innerValue.value = deepClone(getDefaultInnerValue(true))
+ endInnerValue.value = deepClone(getDefaultInnerValue(true, true))
+ } else {
+ innerValue.value = deepClone(getDefaultInnerValue())
+ }
+ }, 300)
+}
+
+/**
+ * 弹出框关闭时
+ */
+function handlePickerClose() {
+ emit('update:visible', false)
+ emit('close')
+}
+
/**
* @description 区域选择时tab标签切换时触发
*/
@@ -401,23 +405,6 @@ function onChangeEnd({ value }: { value: number | string }) {
datetimePickerView1.value && datetimePickerView1.value.setColumns(datetimePickerView1.value.updateColumns())
}
-/**
- * @description 点击取消按钮触发。关闭popup,触发cancel事件。
- */
-function onCancel() {
- popupShow.value = false
- setTimeout(() => {
- if (region.value) {
- innerValue.value = deepClone(getDefaultInnerValue(true))
- endInnerValue.value = deepClone(getDefaultInnerValue(true, true))
- } else {
- innerValue.value = deepClone(getDefaultInnerValue())
- }
- }, 200)
-
- emit('cancel')
-}
-
/** picker触发confirm事件,同步触发confirm事件 */
function onConfirm() {
if (props.loading || isLoading.value) return
diff --git a/src/uni_modules/wot-design-uni/components/wd-picker/types.ts b/src/uni_modules/wot-design-uni/components/wd-picker/types.ts
index 2ac36b16..ecd17f3f 100644
--- a/src/uni_modules/wot-design-uni/components/wd-picker/types.ts
+++ b/src/uni_modules/wot-design-uni/components/wd-picker/types.ts
@@ -1,7 +1,6 @@
import type { ComponentPublicInstance, ExtractPropTypes, PropType } from 'vue'
-import { baseProps, makeArrayProp, makeBooleanProp, makeNumberProp, makeStringProp } from '../common/props'
+import { baseProps, makeBooleanProp, makeNumberProp, makeStringProp } from '../common/props'
import type { ColumnItem, PickerViewColumnChange } from '../wd-picker-view/types'
-import type { FormItemRule } from '../wd-form/types'
export const pickerProps = {
...baseProps,
@@ -72,10 +71,6 @@ export const pickerProps = {
* 接收 pickerView 实例、选中项、当前修改列的下标、resolve 作为入参,根据选中项和列下标进行判断,通过 pickerView 实例暴露出来的 setColumnData 方法修改其他列的数据源。
*/
columnChange: Function as PropType,
- /**
- * 自定义展示文案的格式化函数,返回一个字符串
- */
- displayFormat: Function as PropType,
/**
* 自定义层级
*/
@@ -83,13 +78,15 @@ export const pickerProps = {
/**
* 是否在手指松开时立即触发 change 事件。若不开启则会在滚动动画结束后触发 change 事件,1.2.25版本起提供,仅微信小程序和支付宝小程序支持。
*/
- immediateChange: makeBooleanProp(false)
+ immediateChange: makeBooleanProp(false),
+ /**
+ * 是否显示
+ */
+ visible: makeBooleanProp(false)
}
export type PickerProps = ExtractPropTypes
-export type PickerDisplayFormat = (item: ColumnItem | ColumnItem[], vl: { valueKey: string; labelKey: string }) => string
-
export type PickerBeforeConfirm = (
value: string | number | boolean | string[] | number[] | boolean[],
resolve: (isPass: boolean) => void,
diff --git a/src/uni_modules/wot-design-uni/components/wd-picker/wd-picker.vue b/src/uni_modules/wot-design-uni/components/wd-picker/wd-picker.vue
index 8d872078..d770170f 100644
--- a/src/uni_modules/wot-design-uni/components/wd-picker/wd-picker.vue
+++ b/src/uni_modules/wot-design-uni/components/wd-picker/wd-picker.vue
@@ -7,12 +7,13 @@
:close-on-click-modal="closeOnClickModal"
:z-index="zIndex"
:safe-area-inset-bottom="safeAreaInsetBottom"
- @close="onCancel"
+ @leave="handlePickerClose"
+ @after-leave="handlePickerClosed"
custom-class="wd-picker__popup"
>
-
+
{{ cancelButtonText || translate('cancel') }}
{{ title }}
@@ -21,7 +22,7 @@
import wdPopup from '../wd-popup/wd-popup.vue'
import wdPickerView from '../wd-picker-view/wd-picker-view.vue'
-import { getCurrentInstance, onBeforeMount, ref, watch, computed, onMounted, nextTick } from 'vue'
-import { deepClone, getType, isArray, isDef, isFunction } from '../common/util'
-import { type ColumnItem, formatArray, type PickerViewInstance } from '../wd-picker-view/types'
+import { getCurrentInstance, onBeforeMount, ref, watch, computed } from 'vue'
+import { deepClone, isDef, isFunction } from '../common/util'
+import { type ColumnItem, type PickerViewInstance } from '../wd-picker-view/types'
import { useTranslate } from '../composables/useTranslate'
import { pickerProps, type PickerExpose } from './types'
const { translate } = useTranslate('picker')
const props = defineProps(pickerProps)
-const emit = defineEmits(['confirm', 'open', 'cancel', 'clear', 'update:modelValue'])
+const emit = defineEmits(['confirm', 'open', 'cancel', 'update:modelValue', 'update:visible', 'close'])
-const pickerViewWd = ref(null)
+const pickerViewRef = ref(null)
const innerLoading = ref(false) // 内部控制是否loading
@@ -82,28 +83,10 @@ const isLoading = computed(() => {
return props.loading || innerLoading.value
})
-watch(
- () => props.displayFormat,
- (fn) => {
- if (fn && !isFunction(fn)) {
- console.error('The type of displayFormat must be Function')
- }
- if (pickerViewWd.value && pickerViewWd.value.getSelectedIndex().length !== 0) {
- handleShowValueUpdate(props.modelValue)
- }
- },
- {
- immediate: true,
- deep: true
- }
-)
-
watch(
() => props.modelValue,
(newValue) => {
pickerValue.value = newValue
- // 获取初始选中项,并展示初始选中文案
- handleShowValueUpdate(newValue)
},
{
deep: true,
@@ -111,13 +94,23 @@ watch(
}
)
+watch(
+ () => props.visible,
+ (newValue) => {
+ if (newValue) {
+ open()
+ } else {
+ close()
+ }
+ },
+ { deep: true, immediate: true }
+)
+
watch(
() => props.columns,
(newValue) => {
displayColumns.value = deepClone(newValue)
resetColumns.value = deepClone(newValue)
- // 获取初始选中项,并展示初始选中文案
- handleShowValueUpdate(props.modelValue)
},
{
deep: true,
@@ -140,106 +133,41 @@ watch(
const { proxy } = getCurrentInstance() as any
-onMounted(() => {
- handleShowValueUpdate(props.modelValue)
-})
-
onBeforeMount(() => {
displayColumns.value = deepClone(props.columns)
resetColumns.value = deepClone(props.columns)
})
-/**
- * 值变更时更新显示内容
- * @param value
- */
-function handleShowValueUpdate(value: string | number | Array) {
- // 获取初始选中项,并展示初始选中文案
- if ((isArray(value) && value.length > 0) || (isDef(value) && !isArray(value) && value !== '')) {
- if (pickerViewWd.value) {
- nextTick(() => {
- // setShowValue(pickerViewWd.value!.getSelects())
- })
- } else {
- // setShowValue(getSelects(value)!)
- }
- } else {
- // showValue.value = ''
- }
-}
-
-/**
- * @description 根据传入的value,picker组件获取当前cell展示值。
- * @param {String|Number|Array>}value
- */
-function getSelects(value: string | number | Array>) {
- const formatColumns = formatArray(props.columns, props.valueKey, props.labelKey)
- if (props.columns.length === 0) return
-
- // 使其默认选中首项
- if (value === '' || !isDef(value) || (isArray(value) && value.length === 0)) {
- return
- }
- const valueType = getType(value)
- const type = ['string', 'number', 'boolean', 'array']
- if (type.indexOf(valueType) === -1) return []
- /**
- * 1.单key转为Array
- * 2.根据formatColumns的长度截取Array,保证下面的遍历不溢出
- * 3.根据每列的key值找到选项中value为此key的下标并记录
- */
- value = isArray(value) ? value : [value]
- value = value.slice(0, formatColumns.length)
-
- if (value.length === 0) {
- value = formatColumns.map(() => 0)
- }
- let selected: number[] = []
- value.forEach((target, col) => {
- let row = formatColumns[col].findIndex((row) => {
- return row[props.valueKey].toString() === target.toString()
- })
- row = row === -1 ? 0 : row
- selected.push(row)
- })
-
- const selects = selected.map((row, col) => formatColumns[col][row])
- // 单列选择器,则返回单项
- if (selects.length === 1) {
- return selects[0]
- }
- return selects
-}
-
-// 对外暴露方法,打开弹框
+// 打开弹框
function open() {
- showPopup()
-}
-// 对外暴露方法,关闭弹框
-function close() {
- onCancel()
-}
-/**
- * 展示popup
- */
-function showPopup() {
emit('open')
popupShow.value = true
pickerValue.value = props.modelValue
displayColumns.value = resetColumns.value
}
+// 关闭弹框
+function close() {
+ popupShow.value = false
+}
/**
- * 点击取消按钮触发。关闭popup,触发cancel事件。
+ * 弹出框关闭后
*/
-function onCancel() {
- popupShow.value = false
- emit('cancel')
- let timmer = setTimeout(() => {
- clearTimeout(timmer)
- isDef(pickerViewWd.value) && pickerViewWd.value.resetColumns(resetColumns.value)
+function handlePickerClosed() {
+ let timer = setTimeout(() => {
+ clearTimeout(timer)
+ isDef(pickerViewRef.value) && pickerViewRef.value.resetColumns(resetColumns.value)
}, 300)
}
+
+/**
+ * 弹出框关闭时
+ */
+function handlePickerClose() {
+ emit('update:visible', false)
+ emit('close')
+}
+
/**
* 点击确定按钮触发。展示选中值,触发cancel事件。
*/
@@ -271,15 +199,13 @@ function handleConfirm() {
return
}
- const selects = pickerViewWd.value!.getSelects()
- const values = pickerViewWd.value!.getValues()
+ const selects = pickerViewRef.value!.getSelects()
+ const values = pickerViewRef.value!.getValues()
// 获取当前的数据源,并设置给 resetColumns,用于取消时可以回退数据源
- const columns = pickerViewWd.value!.getColumnsData()
+ const columns = pickerViewRef.value!.getColumnsData()
popupShow.value = false
resetColumns.value = deepClone(columns)
emit('update:modelValue', values)
-
- // setShowValue(selects)
emit('confirm', {
value: values,
selectedItems: selects