mirror of
https://gitee.com/vant-contrib/vant.git
synced 2025-04-06 03:57:59 +08:00
chore(Picker): improve variable names
This commit is contained in:
parent
5d75aabaae
commit
b3feaf01c9
@ -34,7 +34,7 @@ function isOptionDisabled(option) {
|
|||||||
|
|
||||||
export default createComponent({
|
export default createComponent({
|
||||||
props: {
|
props: {
|
||||||
valueKey: String,
|
textKey: String,
|
||||||
readonly: Boolean,
|
readonly: Boolean,
|
||||||
allowHtml: Boolean,
|
allowHtml: Boolean,
|
||||||
className: String,
|
className: String,
|
||||||
@ -126,8 +126,8 @@ export default createComponent({
|
|||||||
};
|
};
|
||||||
|
|
||||||
const getOptionText = (option) => {
|
const getOptionText = (option) => {
|
||||||
if (isObject(option) && props.valueKey in option) {
|
if (isObject(option) && props.textKey in option) {
|
||||||
return option[props.valueKey];
|
return option[props.textKey];
|
||||||
}
|
}
|
||||||
return option;
|
return option;
|
||||||
};
|
};
|
||||||
|
@ -18,11 +18,11 @@ const [createComponent, bem, t] = createNamespace('picker');
|
|||||||
export default createComponent({
|
export default createComponent({
|
||||||
props: {
|
props: {
|
||||||
...pickerProps,
|
...pickerProps,
|
||||||
|
columnsFieldNames: Object,
|
||||||
columns: {
|
columns: {
|
||||||
type: Array,
|
type: Array,
|
||||||
default: () => [],
|
default: () => [],
|
||||||
},
|
},
|
||||||
columnsFieldNames: Object,
|
|
||||||
defaultIndex: {
|
defaultIndex: {
|
||||||
type: [Number, String],
|
type: [Number, String],
|
||||||
default: 0,
|
default: 0,
|
||||||
@ -41,7 +41,8 @@ export default createComponent({
|
|||||||
|
|
||||||
setup(props, { emit, slots }) {
|
setup(props, { emit, slots }) {
|
||||||
const formattedColumns = ref([]);
|
const formattedColumns = ref([]);
|
||||||
const { text, values: valuesKey, children: childKey } = {
|
|
||||||
|
const { text: textKey, values: valuesKey, children: childrenKey } = {
|
||||||
text: props.valueKey, // 向下兼容
|
text: props.valueKey, // 向下兼容
|
||||||
values: 'values',
|
values: 'values',
|
||||||
children: 'children',
|
children: 'children',
|
||||||
@ -58,7 +59,7 @@ export default createComponent({
|
|||||||
const { columns } = props;
|
const { columns } = props;
|
||||||
const firstColumn = columns[0] || {};
|
const firstColumn = columns[0] || {};
|
||||||
|
|
||||||
if (firstColumn[childKey]) {
|
if (firstColumn[childrenKey]) {
|
||||||
return 'cascade';
|
return 'cascade';
|
||||||
}
|
}
|
||||||
if (firstColumn[valuesKey]) {
|
if (firstColumn[valuesKey]) {
|
||||||
@ -70,10 +71,10 @@ export default createComponent({
|
|||||||
const formatCascade = () => {
|
const formatCascade = () => {
|
||||||
const formatted = [];
|
const formatted = [];
|
||||||
|
|
||||||
let cursor = { [childKey]: props.columns };
|
let cursor = { [childrenKey]: props.columns };
|
||||||
|
|
||||||
while (cursor && cursor[childKey]) {
|
while (cursor && cursor[childrenKey]) {
|
||||||
const children = cursor[childKey];
|
const children = cursor[childrenKey];
|
||||||
let defaultIndex = cursor.defaultIndex ?? +props.defaultIndex;
|
let defaultIndex = cursor.defaultIndex ?? +props.defaultIndex;
|
||||||
|
|
||||||
while (children[defaultIndex] && children[defaultIndex].disabled) {
|
while (children[defaultIndex] && children[defaultIndex].disabled) {
|
||||||
@ -86,7 +87,7 @@ export default createComponent({
|
|||||||
}
|
}
|
||||||
|
|
||||||
formatted.push({
|
formatted.push({
|
||||||
[valuesKey]: cursor[childKey],
|
[valuesKey]: cursor[childrenKey],
|
||||||
className: cursor.className,
|
className: cursor.className,
|
||||||
defaultIndex,
|
defaultIndex,
|
||||||
});
|
});
|
||||||
@ -121,17 +122,17 @@ export default createComponent({
|
|||||||
};
|
};
|
||||||
|
|
||||||
const onCascadeChange = (columnIndex) => {
|
const onCascadeChange = (columnIndex) => {
|
||||||
let cursor = { [childKey]: props.columns };
|
let cursor = { [childrenKey]: props.columns };
|
||||||
const indexes = getIndexes();
|
const indexes = getIndexes();
|
||||||
|
|
||||||
for (let i = 0; i <= columnIndex; i++) {
|
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++;
|
columnIndex++;
|
||||||
setColumnValues(columnIndex, cursor[childKey]);
|
setColumnValues(columnIndex, cursor[childrenKey]);
|
||||||
cursor = cursor[childKey][cursor.defaultIndex || 0];
|
cursor = cursor[childrenKey][cursor.defaultIndex || 0];
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -264,8 +265,8 @@ export default createComponent({
|
|||||||
formattedColumns.value.map((item, columnIndex) => (
|
formattedColumns.value.map((item, columnIndex) => (
|
||||||
<PickerColumn
|
<PickerColumn
|
||||||
v-slots={{ option: slots.option }}
|
v-slots={{ option: slots.option }}
|
||||||
|
textKey={textKey}
|
||||||
readonly={props.readonly}
|
readonly={props.readonly}
|
||||||
valueKey={text}
|
|
||||||
allowHtml={props.allowHtml}
|
allowHtml={props.allowHtml}
|
||||||
className={item.className}
|
className={item.className}
|
||||||
itemHeight={itemHeight.value}
|
itemHeight={itemHeight.value}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user