Skip to content

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

Merged
merged 1 commit into from
Jul 8, 2025

Conversation

dataeaseShu
Copy link
Contributor

What this PR does / why we need it?

Summary of your change

Please indicate you've done the following:

  • Made sure tests are passing and test coverage is added if needed.
  • Made sure commit message follow the rule of Conventional Commits specification.
  • Considered the docs impact and opened a new docs issue or PR with docs changes if needed.

@@ -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"
/>
Copy link
Contributor

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') 来记录状态更改。

以下是主要的优化和改进建议:

  1. 命名一致

    • 确保函数名和变量名在上下文中是清晰易懂的。
    • handleCurrentPlaceholderChange 更改为更为通用的名字,比如 updatePropertyInputValues 或者直接使用 onInputChange,以提高可读性和维护性。
  2. 简化逻辑

    • 在处理 props.element.propValue 时,可以考虑使用更高效的方法来更新元素值。例如,如果只有一个元素需要修改,可以直接使用数组索引来更新,而不是遍历整个数组。
  3. 数据流管理

    • 如果有更多类似的数据输入控制字段,考虑将它们集中在一个组件或单独的一个函数中处理,从而减少重复代码并提高复用性。
  4. 性能考虑

    • 对于大规模数据集,确保更新操作不会影响应用程序的性能。可以考虑批量更新或异步操作来分摊资源加载时间。

以下是一个可能的优化后的版本示例:

<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({
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

代码中存在以下问题和优化建议:

  1. tagWidthtagTextWidth 的计算公式没有考虑 getCustomWidth() 可能小于 65 情况,导致可能会返回负数。
    建议将 getCustomWidth() 处理为空或较小值来避免这种情况。

  2. 在处理宽度时可以添加一些条件判断以确保数值不会过界。
    例如,在 Math.min(...) 中添加取最大值(如 (getCustomWidth() - 65) / 2 + minVal),确保结果不会低于某个最小阈值。

  3. 可以使用变量来简化代码逻辑。
    例如:

    const maxWidth = Math.min(getCustomWidth(), someMaxValue);

    父组件可以根据需要设置 someMaxValue 来控制最大宽度。

  4. 如果可能的话,考虑使用响应式数组或其他数据结构来管理标签数量和大小,从而减少不必要的重复计算。

总之,为了提高代码的健壮性和可维护性,可以进一步调整和优化这些计算公式。

Copy link
Contributor

@xuwei-fit2cloud xuwei-fit2cloud left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@xuwei-fit2cloud xuwei-fit2cloud merged commit 87e61b1 into dev-v3 Jul 8, 2025
3 of 4 checks passed
@xuwei-fit2cloud xuwei-fit2cloud deleted the pr@dev-v3_st branch July 8, 2025 06:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants