-
Notifications
You must be signed in to change notification settings - Fork 3.7k
fix(查询组件): 升级后文本下拉多选UI发生变化 #16443 #16468
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
@@ -512,7 +522,7 @@ const onTitleChange = () => { | |||
:effect="themes" | |||
:min="100" | |||
controls-position="right" | |||
@change="handleCurrentPlaceholderChange" | |||
@change="onPlaceholderChange" | |||
:disabled="!chart.customStyle.component.placeholderShow || !currentPlaceholder" | |||
v-model.lazy="currentSearch.queryConditionWidth" | |||
/> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
代码中添加了 onPlaceholderChange
函数用于响应 placeholder 和 queryConditionWidth 的变化,并且调用了 snapshotStore.recordSnapshotCacheToMobile('propValue')
来记录状态更改。
以下是主要的优化和改进建议:
-
命名一致:
- 确保函数名和变量名在上下文中是清晰易懂的。
- 将
handleCurrentPlaceholderChange
更改为更为通用的名字,比如updatePropertyInputValues
或者直接使用onInputChange
,以提高可读性和维护性。
-
简化逻辑:
- 在处理
props.element.propValue
时,可以考虑使用更高效的方法来更新元素值。例如,如果只有一个元素需要修改,可以直接使用数组索引来更新,而不是遍历整个数组。
- 在处理
-
数据流管理:
- 如果有更多类似的数据输入控制字段,考虑将它们集中在一个组件或单独的一个函数中处理,从而减少重复代码并提高复用性。
-
性能考虑:
- 对于大规模数据集,确保更新操作不会影响应用程序的性能。可以考虑批量更新或异步操作来分摊资源加载时间。
以下是一个可能的优化后的版本示例:
<script>
const onTitleChange = () => {
element.value.name = chart.value.customStyle.component.title;
chart.value.title = chart.value.customStyle.component.title;
}
const updatePlaceholderInputs = () => {
props.element.propValue.forEach((ele, index) => {
if (ele.id === currentPlaceholder.value) {
ele.placeholder = currentSearch.value.placeholder;
ele.queryConditionWidth = currentSearch.value.queryConditionWidth;
props.element.propValue[index] = ele; // 直接替换原始对象
}
});
snapshotStore.recordSnapshotCacheToMobile('propValue');
}
</script>
<template>
...
<el-input
:effect="themes"
@change="updatePlaceholderInputs"
...
/>
通过这些优化和改进建议,可以使代码更简洁、更容易维护,并提高用户体验。
}) | ||
|
||
const tagTextWidth = computed(() => { | ||
return Math.min((getCustomWidth() - 60) / 2 - 25, 40) + 'px' | ||
return (getCustomWidth() - 65) / 2 - 20 + 'px' | ||
}) | ||
|
||
defineExpose({ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
代码中存在以下问题和优化建议:
-
tagWidth
和tagTextWidth
的计算公式没有考虑getCustomWidth()
可能小于 65 情况,导致可能会返回负数。
建议将getCustomWidth()
处理为空或较小值来避免这种情况。 -
在处理宽度时可以添加一些条件判断以确保数值不会过界。
例如,在Math.min(...)
中添加取最大值(如(getCustomWidth() - 65) / 2 + minVal
),确保结果不会低于某个最小阈值。 -
可以使用变量来简化代码逻辑。
例如:const maxWidth = Math.min(getCustomWidth(), someMaxValue);
父组件可以根据需要设置
someMaxValue
来控制最大宽度。 -
如果可能的话,考虑使用响应式数组或其他数据结构来管理标签数量和大小,从而减少不必要的重复计算。
总之,为了提高代码的健壮性和可维护性,可以进一步调整和优化这些计算公式。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
What this PR does / why we need it?
Summary of your change
Please indicate you've done the following: