mirror of
https://gitee.com/wot-design-uni/wot-design-uni.git
synced 2025-12-06 17:18:40 +08:00
fix: 🐛 修复Picker选择器多列选择模式绑定值为空数组时将列第一项作为显示值的问题
This commit is contained in:
parent
103298e4c1
commit
c3b96ce912
@ -1,6 +1,6 @@
|
|||||||
<frame/>
|
<frame/>
|
||||||
|
|
||||||
# Picker 选择器视图
|
# Picker 选择器
|
||||||
|
|
||||||
Picker 组件为 popup 和 pickerView 的组合。
|
Picker 组件为 popup 和 pickerView 的组合。
|
||||||
|
|
||||||
|
|||||||
@ -98,7 +98,7 @@ const columns2 = ref(['选项1', '选项2', '选项3', '选项4', '选项5', '
|
|||||||
const columns3 = ref(['选项1', '选项2', '选项3', '选项4', '选项5', '选项6', '选项7'])
|
const columns3 = ref(['选项1', '选项2', '选项3', '选项4', '选项5', '选项6', '选项7'])
|
||||||
const value3 = ref('选项4')
|
const value3 = ref('选项4')
|
||||||
|
|
||||||
const value4 = ref(['中南大学', '软件工程'])
|
const value4 = ref([])
|
||||||
const columns4 = ref([
|
const columns4 = ref([
|
||||||
['中山大学', '中南大学', '华南理工大学'],
|
['中山大学', '中南大学', '华南理工大学'],
|
||||||
['计算机科学与技术', '软件工程', '通信工程', '法学', '经济学']
|
['计算机科学与技术', '软件工程', '通信工程', '法学', '经济学']
|
||||||
|
|||||||
@ -89,7 +89,7 @@ export default {
|
|||||||
import { getCurrentInstance, onBeforeMount, ref, watch, computed, onMounted, nextTick } from 'vue'
|
import { getCurrentInstance, onBeforeMount, ref, watch, computed, onMounted, nextTick } from 'vue'
|
||||||
import { deepClone, defaultDisplayFormat, getType, isArray, isDef, isFunction } from '../common/util'
|
import { deepClone, defaultDisplayFormat, getType, isArray, isDef, isFunction } from '../common/util'
|
||||||
import { useCell } from '../composables/useCell'
|
import { useCell } from '../composables/useCell'
|
||||||
import { type ColumnItem, formatArray } from '../wd-picker-view/types'
|
import { type ColumnItem, formatArray, type PickerViewInstance } from '../wd-picker-view/types'
|
||||||
import { FORM_KEY, type FormItemRule } from '../wd-form/types'
|
import { FORM_KEY, type FormItemRule } from '../wd-form/types'
|
||||||
import { useParent } from '../composables/useParent'
|
import { useParent } from '../composables/useParent'
|
||||||
import { useTranslate } from '../composables/useTranslate'
|
import { useTranslate } from '../composables/useTranslate'
|
||||||
@ -99,7 +99,7 @@ const { translate } = useTranslate('picker')
|
|||||||
const props = defineProps(pickerProps)
|
const props = defineProps(pickerProps)
|
||||||
const emit = defineEmits(['confirm', 'open', 'cancel', 'update:modelValue'])
|
const emit = defineEmits(['confirm', 'open', 'cancel', 'update:modelValue'])
|
||||||
|
|
||||||
const pickerViewWd = ref<any>(null)
|
const pickerViewWd = ref<PickerViewInstance | null>(null)
|
||||||
const cell = useCell()
|
const cell = useCell()
|
||||||
|
|
||||||
const innerLoading = ref<boolean>(false) // 内部控制是否loading
|
const innerLoading = ref<boolean>(false) // 内部控制是否loading
|
||||||
@ -124,12 +124,8 @@ watch(
|
|||||||
if (fn && !isFunction(fn)) {
|
if (fn && !isFunction(fn)) {
|
||||||
console.error('The type of displayFormat must be Function')
|
console.error('The type of displayFormat must be Function')
|
||||||
}
|
}
|
||||||
if (pickerViewWd.value && pickerViewWd.value.selectedIndex && pickerViewWd.value.selectedIndex.length !== 0) {
|
if (pickerViewWd.value && pickerViewWd.value.getSelectedIndex().length !== 0) {
|
||||||
if (isDef(props.modelValue) && props.modelValue !== '') {
|
handleShowValueUpdate(props.modelValue)
|
||||||
setShowValue(pickerViewWd.value.getSelects())
|
|
||||||
} else {
|
|
||||||
showValue.value = ''
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@ -143,17 +139,7 @@ watch(
|
|||||||
(newValue) => {
|
(newValue) => {
|
||||||
pickerValue.value = newValue
|
pickerValue.value = newValue
|
||||||
// 获取初始选中项,并展示初始选中文案
|
// 获取初始选中项,并展示初始选中文案
|
||||||
if (isDef(newValue) && newValue !== '') {
|
handleShowValueUpdate(newValue)
|
||||||
if (pickerViewWd.value && pickerViewWd.value.getSelects) {
|
|
||||||
nextTick(() => {
|
|
||||||
setShowValue(pickerViewWd.value!.getSelects())
|
|
||||||
})
|
|
||||||
} else {
|
|
||||||
setShowValue(getSelects(newValue)!)
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
showValue.value = ''
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
deep: true,
|
deep: true,
|
||||||
@ -167,17 +153,7 @@ watch(
|
|||||||
displayColumns.value = newValue
|
displayColumns.value = newValue
|
||||||
resetColumns.value = newValue
|
resetColumns.value = newValue
|
||||||
// 获取初始选中项,并展示初始选中文案
|
// 获取初始选中项,并展示初始选中文案
|
||||||
if (isDef(props.modelValue) && props.modelValue !== '') {
|
handleShowValueUpdate(props.modelValue)
|
||||||
if (pickerViewWd.value && pickerViewWd.value.getSelects) {
|
|
||||||
nextTick(() => {
|
|
||||||
setShowValue(pickerViewWd.value!.getSelects())
|
|
||||||
})
|
|
||||||
} else {
|
|
||||||
setShowValue(getSelects(props.modelValue)!)
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
showValue.value = ''
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
deep: true,
|
deep: true,
|
||||||
@ -226,10 +202,7 @@ const isRequired = computed(() => {
|
|||||||
const { proxy } = getCurrentInstance() as any
|
const { proxy } = getCurrentInstance() as any
|
||||||
|
|
||||||
onMounted(() => {
|
onMounted(() => {
|
||||||
isDef(props.modelValue) && props.modelValue !== '' && setShowValue(getSelects(props.modelValue)!)
|
handleShowValueUpdate(props.modelValue)
|
||||||
if (isDef(props.modelValue) && props.modelValue !== '' && pickerViewWd.value && pickerViewWd.value.getSelects) {
|
|
||||||
setShowValue(pickerViewWd.value!.getSelects())
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
|
|
||||||
onBeforeMount(() => {
|
onBeforeMount(() => {
|
||||||
@ -237,6 +210,25 @@ onBeforeMount(() => {
|
|||||||
resetColumns.value = deepClone(props.columns)
|
resetColumns.value = deepClone(props.columns)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 值变更时更新显示内容
|
||||||
|
* @param value
|
||||||
|
*/
|
||||||
|
function handleShowValueUpdate(value: string | number | Array<string | number>) {
|
||||||
|
// 获取初始选中项,并展示初始选中文案
|
||||||
|
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展示值。
|
* @description 根据传入的value,picker组件获取当前cell展示值。
|
||||||
* @param {String|Number|Array<String|Number|Array<any>>}value
|
* @param {String|Number|Array<String|Number|Array<any>>}value
|
||||||
@ -344,6 +336,7 @@ function handleConfirm() {
|
|||||||
popupShow.value = false
|
popupShow.value = false
|
||||||
resetColumns.value = deepClone(columns)
|
resetColumns.value = deepClone(columns)
|
||||||
emit('update:modelValue', values)
|
emit('update:modelValue', values)
|
||||||
|
|
||||||
setShowValue(selects)
|
setShowValue(selects)
|
||||||
emit('confirm', {
|
emit('confirm', {
|
||||||
value: values,
|
value: values,
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user