From b3feaf01c9c8b7394b76018c8426e110d2c9d434 Mon Sep 17 00:00:00 2001 From: chenjiahan Date: Tue, 29 Dec 2020 20:11:33 +0800 Subject: [PATCH] chore(Picker): improve variable names --- src/picker/PickerColumn.js | 6 +++--- src/picker/index.js | 27 ++++++++++++++------------- 2 files changed, 17 insertions(+), 16 deletions(-) diff --git a/src/picker/PickerColumn.js b/src/picker/PickerColumn.js index 6deb3da7d..322dcc349 100644 --- a/src/picker/PickerColumn.js +++ b/src/picker/PickerColumn.js @@ -34,7 +34,7 @@ function isOptionDisabled(option) { export default createComponent({ props: { - valueKey: String, + textKey: String, readonly: Boolean, allowHtml: Boolean, className: String, @@ -126,8 +126,8 @@ export default createComponent({ }; const getOptionText = (option) => { - if (isObject(option) && props.valueKey in option) { - return option[props.valueKey]; + if (isObject(option) && props.textKey in option) { + return option[props.textKey]; } return option; }; diff --git a/src/picker/index.js b/src/picker/index.js index 248821e1f..65e935fc1 100644 --- a/src/picker/index.js +++ b/src/picker/index.js @@ -18,11 +18,11 @@ const [createComponent, bem, t] = createNamespace('picker'); export default createComponent({ props: { ...pickerProps, + columnsFieldNames: Object, columns: { type: Array, default: () => [], }, - columnsFieldNames: Object, defaultIndex: { type: [Number, String], default: 0, @@ -41,7 +41,8 @@ export default createComponent({ setup(props, { emit, slots }) { const formattedColumns = ref([]); - const { text, values: valuesKey, children: childKey } = { + + const { text: textKey, values: valuesKey, children: childrenKey } = { text: props.valueKey, // 向下兼容 values: 'values', children: 'children', @@ -58,7 +59,7 @@ export default createComponent({ const { columns } = props; const firstColumn = columns[0] || {}; - if (firstColumn[childKey]) { + if (firstColumn[childrenKey]) { return 'cascade'; } if (firstColumn[valuesKey]) { @@ -70,10 +71,10 @@ export default createComponent({ const formatCascade = () => { const formatted = []; - let cursor = { [childKey]: props.columns }; + let cursor = { [childrenKey]: props.columns }; - while (cursor && cursor[childKey]) { - const children = cursor[childKey]; + while (cursor && cursor[childrenKey]) { + const children = cursor[childrenKey]; let defaultIndex = cursor.defaultIndex ?? +props.defaultIndex; while (children[defaultIndex] && children[defaultIndex].disabled) { @@ -86,7 +87,7 @@ export default createComponent({ } formatted.push({ - [valuesKey]: cursor[childKey], + [valuesKey]: cursor[childrenKey], className: cursor.className, defaultIndex, }); @@ -121,17 +122,17 @@ export default createComponent({ }; const onCascadeChange = (columnIndex) => { - let cursor = { [childKey]: props.columns }; + let cursor = { [childrenKey]: props.columns }; const indexes = getIndexes(); for (let i = 0; i <= columnIndex; i++) { - cursor = cursor[childKey][indexes[i]]; + cursor = cursor[childrenKey][indexes[i]]; } - while (cursor && cursor[childKey]) { + while (cursor && cursor[childrenKey]) { columnIndex++; - setColumnValues(columnIndex, cursor[childKey]); - cursor = cursor[childKey][cursor.defaultIndex || 0]; + setColumnValues(columnIndex, cursor[childrenKey]); + cursor = cursor[childrenKey][cursor.defaultIndex || 0]; } }; @@ -264,8 +265,8 @@ export default createComponent({ formattedColumns.value.map((item, columnIndex) => (