mirror of
https://gitee.com/vant-contrib/vant.git
synced 2025-04-06 03:57:59 +08:00
chore: improve filter (#8262)
This commit is contained in:
parent
9fd71923f9
commit
12be46fad8
@ -139,7 +139,7 @@ export default createComponent({
|
||||
if (province && province === city) {
|
||||
arr.splice(1, 1);
|
||||
}
|
||||
return arr.filter((text) => text).join('/');
|
||||
return arr.filter(Boolean).join('/');
|
||||
}
|
||||
return '';
|
||||
});
|
||||
@ -223,7 +223,7 @@ export default createComponent({
|
||||
};
|
||||
|
||||
const onAreaConfirm = (values: AreaColumnOption[]) => {
|
||||
values = values.filter((value) => !!value);
|
||||
values = values.filter(Boolean);
|
||||
|
||||
if (values.some((value) => !value.code)) {
|
||||
Toast(t('areaEmpty'));
|
||||
|
@ -221,9 +221,7 @@ export default createComponent({
|
||||
|
||||
const getValues = () => {
|
||||
if (pickerRef.value) {
|
||||
const values = pickerRef.value
|
||||
.getValues()
|
||||
.filter((value: AreaColumnOption) => !!value);
|
||||
const values = pickerRef.value.getValues().filter(Boolean);
|
||||
return parseValues(values);
|
||||
}
|
||||
return [];
|
||||
@ -244,7 +242,7 @@ export default createComponent({
|
||||
}
|
||||
|
||||
const names = values.map((item) => item.name);
|
||||
const validValues = values.filter((value) => !!value.code);
|
||||
const validValues = values.filter((value) => value.code);
|
||||
|
||||
area.code = validValues.length
|
||||
? validValues[validValues.length - 1].code
|
||||
|
@ -98,11 +98,11 @@ export default createComponent({
|
||||
selectedOption: option,
|
||||
};
|
||||
|
||||
const next = optionsCursor.filter(
|
||||
const next = optionsCursor.find(
|
||||
(item) => item[valueKey] === option[valueKey]
|
||||
);
|
||||
if (next.length) {
|
||||
optionsCursor = next[0][childrenKey];
|
||||
if (next) {
|
||||
optionsCursor = next[childrenKey];
|
||||
}
|
||||
|
||||
return tab;
|
||||
@ -157,7 +157,7 @@ export default createComponent({
|
||||
|
||||
const selectedOptions = state.tabs
|
||||
.map((tab) => tab.selectedOption)
|
||||
.filter((item) => !!item);
|
||||
.filter(Boolean);
|
||||
|
||||
const eventParams = {
|
||||
value: option[valueKey],
|
||||
|
@ -167,10 +167,9 @@ export default createComponent({
|
||||
|
||||
const originColumns = computed(() =>
|
||||
ranges.value.map(({ type, range: rangeArr }) => {
|
||||
let values = times(rangeArr[1] - rangeArr[0] + 1, (index) => {
|
||||
const value = padZero(rangeArr[0] + index);
|
||||
return value;
|
||||
});
|
||||
let values = times(rangeArr[1] - rangeArr[0] + 1, (index) =>
|
||||
padZero(rangeArr[0] + index)
|
||||
);
|
||||
|
||||
if (props.filter) {
|
||||
values = props.filter(type, values);
|
||||
@ -290,10 +289,7 @@ export default createComponent({
|
||||
emit('update:modelValue', oldValue ? value : null)
|
||||
);
|
||||
|
||||
watch(
|
||||
[() => props.filter, () => props.minDate, () => props.maxDate],
|
||||
updateInnerValue
|
||||
);
|
||||
watch(() => [props.filter, props.minDate, props.maxDate], updateInnerValue);
|
||||
|
||||
watch(
|
||||
() => props.modelValue,
|
||||
|
@ -137,12 +137,12 @@ export default createComponent({
|
||||
watch(columns, updateColumnValue);
|
||||
|
||||
watch(
|
||||
[
|
||||
() => props.filter,
|
||||
() => props.minHour,
|
||||
() => props.maxHour,
|
||||
() => props.minMinute,
|
||||
() => props.maxMinute,
|
||||
() => [
|
||||
props.filter,
|
||||
props.minHour,
|
||||
props.maxHour,
|
||||
props.minMinute,
|
||||
props.maxMinute,
|
||||
],
|
||||
updateInnerValue
|
||||
);
|
||||
|
@ -106,11 +106,11 @@ export default createComponent({
|
||||
return props.title;
|
||||
}
|
||||
|
||||
const match = props.options.filter(
|
||||
const match = props.options.find(
|
||||
(option) => option.value === props.modelValue
|
||||
);
|
||||
|
||||
return match.length ? match[0].text : '';
|
||||
return match ? match.text : '';
|
||||
};
|
||||
|
||||
const renderOption = (option: DropdownItemOption) => {
|
||||
|
@ -87,7 +87,7 @@ export default createComponent({
|
||||
new Promise<void>((resolve, reject) => {
|
||||
const fields = getFieldsByNames(names);
|
||||
Promise.all(fields.map((item) => item.validate())).then((errors) => {
|
||||
errors = errors.filter((item) => item);
|
||||
errors = errors.filter(Boolean);
|
||||
|
||||
if (errors.length) {
|
||||
reject(errors);
|
||||
@ -98,11 +98,11 @@ export default createComponent({
|
||||
});
|
||||
|
||||
const validateField = (name: string) => {
|
||||
const matched = children.filter((item) => item.name === name);
|
||||
const matched = children.find((item) => item.name === name);
|
||||
|
||||
if (matched.length) {
|
||||
if (matched) {
|
||||
return new Promise<void>((resolve, reject) => {
|
||||
matched[0].validate().then((error?: FieldValidateError) => {
|
||||
matched.validate().then((error?: FieldValidateError) => {
|
||||
if (error) {
|
||||
reject(error);
|
||||
} else {
|
||||
|
@ -206,16 +206,16 @@ export default createComponent({
|
||||
return;
|
||||
}
|
||||
|
||||
const match = children.filter((item) => String(item.index) === index);
|
||||
const match = children.find((item) => String(item.index) === index);
|
||||
|
||||
if (match[0]) {
|
||||
match[0].$el.scrollIntoView();
|
||||
if (match) {
|
||||
match.$el.scrollIntoView();
|
||||
|
||||
if (props.sticky && props.stickyOffsetTop) {
|
||||
setRootScrollTop(getRootScrollTop() - props.stickyOffsetTop);
|
||||
}
|
||||
|
||||
emit('select', match[0].index);
|
||||
emit('select', match.index);
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -256,11 +256,11 @@ export default createComponent({
|
||||
|
||||
// correct the index of active tab
|
||||
const setCurrentIndexByName = (name: number | string) => {
|
||||
const matched = children.filter(
|
||||
const matched = children.find(
|
||||
(tab, index) => getTabName(tab, index) === name
|
||||
);
|
||||
|
||||
const index = matched[0] ? children.indexOf(matched[0]) : 0;
|
||||
const index = matched ? children.indexOf(matched) : 0;
|
||||
setCurrentIndex(index);
|
||||
};
|
||||
|
||||
|
@ -240,7 +240,7 @@ export default createComponent({
|
||||
const imageFiles = props.modelValue.filter(isImageFile);
|
||||
const images = imageFiles
|
||||
.map((item) => item.content || item.url)
|
||||
.filter((item) => !!item) as string[];
|
||||
.filter(Boolean) as string[];
|
||||
|
||||
imagePreview = ImagePreview({
|
||||
images,
|
||||
|
Loading…
x
Reference in New Issue
Block a user