Skip to content

Conversation

xiaoyatong
Copy link
Collaborator

@xiaoyatong xiaoyatong commented Apr 11, 2025

🤔 这个变动的性质是?

  • 新特性提交
  • 日常 bug 修复
  • 站点、文档改进
  • 演示代码改进
  • 组件样式/交互改进
  • TypeScript 定义更新
  • 包体积优化
  • 性能优化
  • 功能增强
  • 国际化改进
  • 重构
  • 代码风格优化
  • 测试用例
  • 分支合并
  • 其他改动(是关于什么的改动?)

🔗 相关 Issue

💡 需求背景和解决方案

☑️ 请求合并前的自查清单

⚠️ 请自检并全部勾选全部选项⚠️

  • 文档已补充或无须补充
  • 代码演示已提供或无须提供
  • TypeScript 定义已补充或无须补充
  • fork仓库代码是否为最新避免文件冲突
  • Files changed 没有 package.json lock 等无关文件

Summary by CodeRabbit

  • 新功能

    • 新增电梯式地址选择模式,支持热门城市快捷访问和分级导航,提升地址录入体验。
    • 地址组件渲染逻辑模块化,支持电梯模式、级联模式和已有模式三种展示方式切换。
    • 新增地址选择演示示例,展示电梯式选择功能及热搜城市列表。
    • 支持动态加载和格式化地址数据,增强数据处理能力。
  • 样式

    • 新增电梯式地址组件样式,优化视觉结构和交互细节。
    • 调整样式导入路径,提升样式组织和维护性。
  • 文档

    • 更新地址组件文档,新增电梯式地址选择模式说明及演示示例。
    • 扩展多语言支持,新增热门城市及省份选择相关翻译内容。

Copy link

coderabbitai bot commented Apr 11, 2025

"""

Walkthrough

本次提交更新了地址组件相关代码。主要改动包括:

  • 在样式文件中调整了导入路径及移除不再启用的 .nut-address-elevator 样式块,新增了专门的电梯样式文件 elevator.scss
  • 在地址组件中新增了 hotList 属性,重构了渲染逻辑,将不同类型的渲染拆分为 renderElevatorrenderCascatorrenderExist 三个独立函数,支持新的 'elevator' 类型。
  • 新增了 ElevatorRender 组件,实现电梯式地址选择界面,包含层级导航和热门城市快速访问,支持弹窗和非弹窗两种展示方式。
  • 新增工具函数 generateIdtransformDatafindDataByName,用于字符串生成 ID、按 wordCode 分组转换地址数据及递归查找。
  • 在示例代码中新增电梯地址选择的演示组件(H5 和 Taro 版本),完善了状态管理、数据初始化及国际化翻译。
  • 修复了电梯栏激活状态判断时的安全访问问题,避免访问未定义元素导致的运行时错误。
  • 更新了地址组件的文档,增加了电梯模式的说明及示例。
  • 修改了配置文件中地址组件的版本及作者信息。

Changes

文件(s) 变更摘要
src/packages/address/address.scss
src/packages/address/elevator.scss
修改 address.scss@import 路径由 ../elevator/elevator.scss 改为 ./elevator.scss,移除 .nut-address-elevator 样式块;新增 elevator.scss,定义电梯地址选择相关样式。
src/packages/address/address.tsx
src/packages/address/address.taro.tsx
src/packages/address/elevatorRender.tsx
src/packages/address/elevatorRender.taro.tsx
address.tsxaddress.taro.tsx 中新增 hotList 属性,重构渲染逻辑为 renderElevatorrenderCascatorrenderExist 三个函数,新增 ElevatorRender 组件,实现电梯式地址选择。
src/packages/address/utils.ts 新增工具函数 generateId(字符串转数字 ID)、transformData(按 wordCode 分组转换地址数据)、findDataByName(递归查找数据项)。
src/packages/address/demos/h5/demo1.tsx
src/packages/address/demos/h5/demo11.tsx
src/packages/address/demos/taro/demo11.tsx
修改 demo1.tsx 状态初始化及事件参数,新增 demo11.tsx(H5 和 Taro 版本)演示电梯地址选择,包含热门城市和分级地址数据。
src/packages/address/demo.tsx
src/packages/address/demo.taro.tsx
新增 Demo11 演示组件并添加对应国际化翻译条目,展示电梯地址选择功能。
src/packages/elevator/elevator.tsx 修复电梯栏激活状态判断时的安全访问,使用可选链避免访问未定义元素导致的错误。
src/locales/*.ts 在多语言文件中新增地址组件相关的 hotCityselectProvince 翻译条目。
src/packages/address/doc*.md 更新地址组件文档,新增电梯模式说明和示例,扩展 type 属性支持 elevator,新增 hotList 属性说明。
src/types/spec/address/base.ts BaseAddress 接口中新增 hotList: RegionData[] 属性,调整 type 属性类型为 AddressModeType
src/config.json 更新地址组件版本号由 2.0.03.0.0,修改作者及版本字段。

Sequence Diagram(s)

sequenceDiagram
    participant U as 用户
    participant IA as InternalAddress
    participant RE as renderElevator
    participant RC as renderCascator
    participant RX as renderExist

    U->>IA: 触发地址选择
    IA->>IA: 检查 currentType
    alt 类型为 elevator
      IA->>RE: 调用 renderElevator
      RE-->>IA: 返回 ElevatorRender 组件
    else 类型为 cascader
      IA->>RC: 调用 renderCascator
      RC-->>IA: 返回 CascaderRender 组件
    else 其他类型
      IA->>RX: 调用 renderExist
      RX-->>IA: 返回 ExistRender 组件
    end
    IA-->>U: 渲染相应组件
Loading

Suggested reviewers

  • irisSong

Poem

我是一只快乐的小兔子,
跳跃在代码的花园里;
组件模块划分清晰,
电梯样式闪耀着神奇光芒🐇;
状态管理如风轻拂,
开发之路妙趣横生,
让我们共赏这智能的诗行!
"""

✨ Finishing Touches
  • 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@github-actions github-actions bot added action:review This PR needs more reviews (less than 2 approvals) 3.x Target branch 3.x labels Apr 11, 2025
@xiaoyatong xiaoyatong marked this pull request as draft April 11, 2025 05:43
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 11

🧹 Nitpick comments (9)
src/packages/address/address.scss (1)

5-8: 确认样式注释是否有意为之

这些 .nut-address-elevator 的样式已被注释掉。请确认这是否为有意为之,以及这些样式是否已在新的 elevator.scss 文件中重新定义。

如果这些样式现在已经在 ./elevator.scss 中定义,建议完全移除这些注释的代码块而不是保留注释。

-  // &-elevator {
-  //   display: flex;
-  //   margin-top: 20px;
-  // }
src/packages/address/elevator.scss (2)

47-50: 移除注释掉的样式代码

在开发环境中留下注释掉的样式代码会增加样式表的大小并降低可读性。

建议删除这些注释掉的样式规则:

-      // display: flex;
      display: inline-block;
-      // justify-content: center;
-      // align-items: center;

4-111: 整体结构良好,但建议分离嵌套深度

样式结构整体良好,但嵌套深度较高,可能会导致生成的 CSS 选择器过于特定,影响性能和可维护性。

考虑适当减少嵌套级别,特别是对于像 .nut-elevator-list.nut-elevator-bars 这样的选择器,可以提取到较高级别或使用变量来简化样式结构。

src/packages/address/elevatorRender.taro.tsx (1)

32-84: 组件名称与实际功能不符

组件命名为 CustomRender,但它只在 type === 'custom' 时渲染 Cascader 组件。这种命名可能会导致混淆,因为它暗示了一般性的自定义渲染能力,而不是特定于级联选择器的功能。

建议重命名组件以更好地反映其实际功能,例如 CascaderRenderCustomCascaderRender,或者扩展其功能以处理多种类型的渲染。

另外,从 "elevator" 文件名来看,此组件可能是与电梯功能相关,但其实现似乎主要与级联选择器相关。建议确保文件名和组件名能准确反映其功能。

src/packages/address/demos/h5/demo1.tsx (2)

6-17: 热门城市列表中存在重复项

热门城市列表中,"天津"重复出现了三次(第14、15和16行),这可能是无意的数据重复。

建议移除重复项,保留一个"天津"即可:

  const [hotList, setHotList] = useState([
    { id: '1', name: '北京' },
    { id: '2', name: '上海' },
    { id: '1601', name: '广州' },
    { id: '1607', name: '深圳' },
    { id: '1213', name: '杭州' },
    { id: '904', name: '南京' },
    { id: '988', name: '苏州' },
    { id: '3', name: '天津' },
-   { id: '3', name: '天津' },
-   { id: '3', name: '天津' },
  ])

59-59: 数据错误:文本与值不匹配

这行的text值"杜集区"与实际的value值"烈山区"不匹配,应该是复制错误。

修正文本值以匹配对应的value:

- { value: '烈山区', text: '杜集区', wordCode: 'L' },
+ { value: '烈山区', text: '烈山区', wordCode: 'L' },
src/packages/address/elevatorRender.tsx (3)

149-183: 存在多个调试日志语句

代码中包含多个console.log调试语句,应在生产代码中移除。

移除所有的console.log语句,或在开发环境中使用条件日志输出:

- console.log('levels', innerValue)
+ // 可以使用条件日志输出
+ if (process.env.NODE_ENV === 'development') {
+   console.log('levels', innerValue)
+ }

// 同样移除或条件化其他console.log语句

194-202: 未使用的代码注释

此代码块包含被注释掉的功能代码,如果不再需要应该移除以保持代码整洁。

如果这些功能已被完全弃用或实现在别处,建议完全移除这些注释以提高代码可读性。如果计划在未来实现,添加TODO注释说明原因。


306-346: 复杂的事件处理逻辑需要重构

onElevatorItemClick函数过于复杂且包含多个注释掉的代码段和调试日志,这降低了可读性和可维护性。

建议将函数逻辑拆分为更小的功能函数,移除未使用的注释代码,并整理日志输出:

const onElevatorItemClick = (elevatorItem: AreaInfo, levelIndex: number) => {
-  console.log('onitem click', elevatorItem, innerValue, levelIndex)
  if (elevatorItem?.disabled) return
  const distIndex = levelIndex + 1
  setLevelIndex(distIndex)

  if (elevatorItem.children?.length) {
    setElevatorOptions(elevatorItem.children)
  } else {
-    console.log('close popup')
  }

  const nextValue = innerValue.slice(0, levelIndex)
-  console.log('nextvalue', nextValue)
-  // const nextPathNodes = pathNodes.current.slice(0, levelIndex)
  if (elevatorItem.name) {
    setLoading(!!onLoad && { [levelIndex]: elevatorItem.name })
    nextValue[levelIndex] = elevatorItem.name
-    // nextPathNodes[levelIndex] = elevatorItem
-    // pathNodes.current = nextPathNodes
-    // props?.onPathChange?.(nextValue, pathNodes.current)
  }
-  // if (onLoad) {
-  //   // 叶子节点不操作
-  //   if (!elevatorItem.leaf) {
-  //     const asyncOptions = await onLoad(elevatorItem, levelIndex)
-  //     // 修改 options 触发渲染逻辑
-  //     if (asyncOptions) elevatorItem.children = asyncOptions
-  //   } else {
-  //     setVisible(false)
-  //     setValue(nextValue)
-  //   }
-  // }
  if (!elevatorItem.children && !onLoad) {
    setVisible(false)
    setValue(nextValue)
  }
-  console.log('330 ', nextValue)
  setInnerValue(nextValue)
  setLoading({})
}
🧰 Tools
🪛 GitHub Check: build

[failure] 308-308:
Property 'disabled' does not exist on type 'AreaInfo'.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 79a9900 and 91b1e70.

📒 Files selected for processing (7)
  • src/packages/address/address.scss (1 hunks)
  • src/packages/address/address.tsx (4 hunks)
  • src/packages/address/demos/h5/demo1.tsx (2 hunks)
  • src/packages/address/elevator.scss (1 hunks)
  • src/packages/address/elevatorRender.taro.tsx (1 hunks)
  • src/packages/address/elevatorRender.tsx (1 hunks)
  • src/packages/address/utils.ts (1 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (3)
src/packages/address/address.tsx (1)
src/packages/address/elevatorRender.tsx (1)
  • ElevatorRender (68-378)
src/packages/address/elevatorRender.taro.tsx (3)
src/packages/address/elevatorRender.tsx (1)
  • AddressProps (36-46)
src/types/spec/cascader/base.ts (3)
  • CascaderOption (10-20)
  • CascaderValue (28-28)
  • CascaderOptionKey (30-34)
src/utils/typings.ts (1)
  • ComponentDefaults (10-13)
src/packages/address/elevatorRender.tsx (5)
src/utils/typings.ts (1)
  • ComponentDefaults (10-13)
src/utils/merge-props.ts (1)
  • mergeProps (4-16)
src/utils/is-empty.ts (1)
  • isEmpty (1-6)
src/packages/cascader/utils.ts (2)
  • normalizeListOptions (24-61)
  • normalizeOptions (3-22)
src/packages/address/utils.ts (1)
  • transformData (6-40)
🪛 GitHub Check: build
src/packages/address/address.tsx

[failure] 67-67:
Property 'hotList' does not exist on type '{ visible: boolean; defaultVisible: boolean; value?: CascaderValue | undefined; defaultValue?: CascaderValue | undefined; type: string; options: CascaderOption[]; ... 284 more ...; onTransitionEndCapture?: TransitionEventHandler<...> | undefined; }'.

src/packages/address/elevatorRender.tsx

[failure] 308-308:
Property 'disabled' does not exist on type 'AreaInfo'.

🪛 Biome (1.9.4)
src/packages/address/address.tsx

[error] 150-192: This code is unreachable

... because this statement will return from the function beforehand

(lint/correctness/noUnreachable)

src/packages/address/elevatorRender.tsx

[error] 273-276: Missing key property for this element in iterable.

The order of the items may change, and having a key can help React identify which item was moved.
Check the React documentation.

(lint/correctness/useJsxKeyInIterable)

🪛 GitHub Actions: CI
src/packages/address/address.tsx

[error] 67-67: error TS2339: Property 'hotList' does not exist on type '{ visible: boolean; defaultVisible: boolean; value?: CascaderValue | undefined; defaultValue?: CascaderValue | undefined; type: string; options: CascaderOption[]; ... 284 more ...; onTransitionEndCapture?: TransitionEventHandler<...> | undefined; }'.

🪛 GitHub Check: lint
src/packages/address/elevatorRender.tsx

[warning] 243-243:
React Hook useEffect has missing dependencies: 'innerValue' and 'onLoad'. Either include them or remove the dependency array


[warning] 216-216:
React Hook useEffect has a missing dependency: 'levels.length'. Either include it or remove the dependency array

⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: test
🔇 Additional comments (8)
src/packages/address/address.scss (1)

1-1: 导入路径已更新

导入路径从 ../elevator/elevator.scss 更改为 ./elevator.scss,表明电梯组件的样式文件现在位于当前目录。这种变化使得样式文件组织更加内聚。

src/packages/address/elevator.scss (2)

1-2: 引入路径兼容性检查

确保这两个导入的 SCSS 文件(../elevator/elevator.scss../cascader/cascader.scss)在项目中存在,并且当前组件的样式不会与它们冲突。

这种多重导入可能会导致样式重叠或冲突。请确保每个导入的目的明确,并考虑是否可以整合或简化样式导入。


32-34:

❓ Verification inconclusive

检查 CSS :has 选择器的浏览器兼容性

:has() 选择器是较新的 CSS 功能,可能在某些浏览器(特别是旧版浏览器)中不受支持。


🌐 Web query:

CSS :has 选择器的浏览器兼容性

💡 Result:

CSS的:has选择器允许根据子元素或后续元素的存在来选择父元素,但目前浏览器支持仍有限。以下是主要浏览器的兼容情况:

支持的浏览器及版本

浏览器 最低支持版本 来源
Chrome 105+ [1][2][6]
Edge 105+ [2]
Safari 15.4+ [2][6][10]
Opera 91+ [2]
Firefox 尚未支持 [1][2][4]

关键细节

  • Chrome:自105版本开始默认支持,可通过chrome://flags的实验性功能提前启用(旧版本)[6]。
  • Safari:15.4及以上版本支持,是早期实现该功能的浏览器之一[2][6]。
  • Firefox:截至资料更新时间仍未支持,但已在开发路线图中[2][4][10]。

兼容性检测

可通过CSS的@supports规则检测浏览器是否支持:

@supports selector(:has(*)) {
  /* 支持时的样式 */
}

若浏览器不兼容,:has()所在的选择器块将失效,除非嵌套在:is():where()等容错选择器中[10]。

建议使用caniuse.com查看实时兼容性状态[1][5]。对于关键功能,目前仍需提供JavaScript后备方案[4][9]。

Citations:


注意:检查 CSS :has() 选择器的兼容性问题

当前在 src/packages/address/elevator.scss 文件(第 32-34 行)中使用的 :has() 选择器能够在 Chrome(105+)、Edge(105+)、Safari(15.4+)及 Opera(91+)中正常工作,但 Firefox 目前仍不支持。如果该样式对所有目标浏览器的布局至关重要,请考虑以下建议:

  • 利用 @supports 检查浏览器是否支持 :has(),并为不支持的浏览器提供相应的样式方案;
  • 或者为不支持 :has() 的情况使用 JavaScript 后备方案。

请根据项目需求确认是否需要调整兼容性策略。

src/packages/address/elevatorRender.taro.tsx (1)

62-81: 确保功能完整性

当前实现仅处理 type === 'custom' 的情况,但根据文件名 elevatorRender.taro.tsx,可能还应该处理 type === 'elevator' 的情况。

请检查是否需要处理 type === 'elevator' 或其他类型的情况,确保组件功能的完整性。如果这些其他类型的渲染逻辑在其他文件中处理,建议添加注释说明或考虑将相关逻辑整合到一个文件中,以提高代码的可维护性。

src/packages/address/demos/h5/demo1.tsx (1)

187-189: 组件属性更新

Address组件的属性已从原来的options={optionsDemo1}更新为hotList={hotList}, options={options},这与组件默认类型从'custom'改为'elevator'的变化相匹配。

src/packages/address/address.tsx (2)

25-25: 默认属性更新

将默认类型从'custom'更改为'elevator',并添加了新的hotList属性。这是对组件行为的重要变更。

这个改动可能会影响现有使用此组件但未显式指定type属性的代码。请确认这是预期的行为变更,并考虑在CHANGELOG或升级指南中说明此变更。

Also applies to: 31-31


244-246: 渲染逻辑重构

将渲染逻辑拆分为三个独立函数并通过条件渲染调用,这种重构提高了代码的可读性和可维护性。

src/packages/address/elevatorRender.tsx (1)

358-378: 功能实现完整

renderElevatorList函数和条件渲染逻辑实现完整,支持热门城市和电梯式地址选择功能。

Comment on lines 6 to 40
export const transformData = (data: any) => {
const groupByWordCode = (data: any) => {
return data?.reduce((acc: any, item: any) => {
const { wordCode } = item
if (!acc[wordCode]) {
acc[wordCode] = []
}
acc[wordCode].push({
name: item.value,
wordCode: item.wordCode,
id: generateId(item.value),
children: (item.children && groupByWordCode(item.children)) || null,
})

return acc
}, {})
}

const extractTitles = (obj: any) => {
return Object.keys(obj).map((key) => ({
title: key,
list: obj[key].map((item: any) => {
// console.log('item', item)
if (item.children) {
item.children = extractTitles(item.children)
}
return item
}),
}))
}

const middleData = groupByWordCode(data)
const resultData = extractTitles(middleData)
return resultData
}
Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

添加明确的类型定义并移除调试代码

transformData 函数缺少明确的输入和输出类型定义,并包含被注释掉的调试代码。

建议添加明确的类型定义并删除注释掉的调试代码:

-export const transformData = (data: any) => {
-  const groupByWordCode = (data: any) => {
-    return data?.reduce((acc: any, item: any) => {
+interface DataItem {
+  value: string;
+  wordCode: string;
+  children?: DataItem[];
+}
+
+interface GroupedItem {
+  name: string;
+  wordCode: string;
+  id: number | string;
+  children: GroupedDataType | null;
+}
+
+interface GroupedDataType {
+  [key: string]: GroupedItem[];
+}
+
+interface ResultItem {
+  title: string;
+  list: (GroupedItem & { children?: ResultItem[] })[];
+}
+
+export const transformData = (data: DataItem[]): ResultItem[] => {
+  const groupByWordCode = (data: DataItem[]): GroupedDataType => {
+    return data?.reduce((acc: GroupedDataType, item: DataItem) => {
-      return item
-    }))
-  }
+      return item
+    }))
+  }
-        // console.log('item', item)
+
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
export const transformData = (data: any) => {
const groupByWordCode = (data: any) => {
return data?.reduce((acc: any, item: any) => {
const { wordCode } = item
if (!acc[wordCode]) {
acc[wordCode] = []
}
acc[wordCode].push({
name: item.value,
wordCode: item.wordCode,
id: generateId(item.value),
children: (item.children && groupByWordCode(item.children)) || null,
})
return acc
}, {})
}
const extractTitles = (obj: any) => {
return Object.keys(obj).map((key) => ({
title: key,
list: obj[key].map((item: any) => {
// console.log('item', item)
if (item.children) {
item.children = extractTitles(item.children)
}
return item
}),
}))
}
const middleData = groupByWordCode(data)
const resultData = extractTitles(middleData)
return resultData
}
interface DataItem {
value: string;
wordCode: string;
children?: DataItem[];
}
interface GroupedItem {
name: string;
wordCode: string;
id: number | string;
children: GroupedDataType | null;
}
interface GroupedDataType {
[key: string]: GroupedItem[];
}
interface ResultItem {
title: string;
list: (GroupedItem & { children?: ResultItem[] })[];
}
export const transformData = (data: DataItem[]): ResultItem[] => {
const groupByWordCode = (data: DataItem[]): GroupedDataType => {
return data?.reduce((acc: GroupedDataType, item: DataItem) => {
const { wordCode } = item
if (!acc[wordCode]) {
acc[wordCode] = []
}
acc[wordCode].push({
name: item.value,
wordCode: item.wordCode,
id: generateId(item.value),
children: (item.children && groupByWordCode(item.children)) || null,
})
return acc
}, {})
}
const extractTitles = (obj: any) => {
return Object.keys(obj).map((key) => ({
title: key,
list: obj[key].map((item: any) => {
if (item.children) {
item.children = extractTitles(item.children)
}
return item
}),
}))
}
const middleData = groupByWordCode(data)
const resultData = extractTitles(middleData)
return resultData
}


useEffect(() => {
setTabActiveIndex(levels.length - 1)
}, [innerValue])
Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

useEffect缺少依赖项

useEffect钩子函数缺少levels.length依赖项,可能导致在levels数组长度变化时不会执行效果。

添加缺失的依赖项:

useEffect(() => {
  setTabActiveIndex(levels.length - 1)
- }, [innerValue])
+ }, [innerValue, levels.length])
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
}, [innerValue])
useEffect(() => {
setTabActiveIndex(levels.length - 1)
}, [innerValue, levels.length])
🧰 Tools
🪛 GitHub Check: lint

[warning] 216-216:
React Hook useEffect has a missing dependency: 'levels.length'. Either include it or remove the dependency array

Comment on lines 232 to 243
}
}, Promise.resolve(parent))

// 如果需要处理最终结果,可以在这里使用 last
setInnerOptions(parent.children)
} catch (error) {
console.error('Error loading data:', error)
}
}

if (lazy) load()
}, [lazy])
Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

useEffect依赖项不完整

useEffect钩子函数缺少innerValueonLoad依赖项,在这些值变化时可能不会重新执行效果。

添加缺失的依赖项:

useEffect(() => {
  // 函数实现...
- }, [lazy])
+ }, [lazy, innerValue, onLoad])
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
}
}, Promise.resolve(parent))
// 如果需要处理最终结果,可以在这里使用 last
setInnerOptions(parent.children)
} catch (error) {
console.error('Error loading data:', error)
}
}
if (lazy) load()
}, [lazy])
}
}, Promise.resolve(parent))
// 如果需要处理最终结果,可以在这里使用 last
setInnerOptions(parent.children)
} catch (error) {
console.error('Error loading data:', error)
}
}
if (lazy) load()
}, [lazy, innerValue, onLoad])
🧰 Tools
🪛 GitHub Check: lint

[warning] 243-243:
React Hook useEffect has missing dependencies: 'innerValue' and 'onLoad'. Either include them or remove the dependency array

@xiaoyatong xiaoyatong marked this pull request as ready for review April 17, 2025 06:14
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

♻️ Duplicate comments (2)
src/packages/address/elevatorRender.tsx (2)

31-35: AreaInfo 增补 disabled 字段

onElevatorItemClick 中已对 elevatorItem.disabled 进行访问(231‑233 行),但当前 AreaInfo 类型缺少该属性,导致 TypeScript 报错 (Property 'disabled' does not exist on type 'AreaInfo')。
请在类型定义中补充可选字段,确保类型一致。

 type AreaInfo = {
   name: string
   id: string | number
   children: any
+  disabled?: boolean
 }

197-200: ⚠️ Potential issue

useEffect 依赖缺失,可能导致选项切换后 Tab 未及时更新

该 effect 依赖 levels.length 才能在层级增减时同步 tabActiveIndex 和提示文案。缺失依赖会造成 UI 与数据不同步的潜在 Bug。

-  }, [innerValue])
+  }, [innerValue, levels.length])
🧰 Tools
🪛 GitHub Check: lint

[warning] 200-200:
React Hook useEffect has a missing dependency: 'levels.length'. Either include it or remove the dependency array

🧹 Nitpick comments (1)
src/packages/address/elevatorRender.tsx (1)

261-265: HotList 列表建议使用稳定且业务相关的 key

目前使用 index 作为 key,当列表顺序变化或增删元素时可能导致重复渲染。若接口数据包含 id,优先使用;否则可退化到名称。

-          {hotList.map((item, index) => (
-            <div className={`${classPrefix}-hotlist-item`} key={`hot-${index}`}>
+          {hotList.map((item) => (
+            <div
+              className={`${classPrefix}-hotlist-item`}
+              key={`hot-${item.id ?? item.name}`}
+            >
               {item.name}
             </div>
           ))}
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 91b1e70 and 3a4ee6d.

📒 Files selected for processing (1)
  • src/packages/address/elevatorRender.tsx (1 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (1)
src/packages/address/elevatorRender.tsx (7)
src/types/spec/cascader/base.ts (3)
  • CascaderOption (10-20)
  • CascaderValue (28-28)
  • CascaderOptionKey (30-34)
src/utils/typings.ts (1)
  • ComponentDefaults (10-13)
src/utils/merge-props.ts (1)
  • mergeProps (4-16)
src/hooks/use-props-value.ts (1)
  • usePropsValue (11-35)
src/utils/is-empty.ts (1)
  • isEmpty (1-6)
src/packages/cascader/utils.ts (2)
  • normalizeListOptions (24-61)
  • normalizeOptions (3-22)
src/packages/address/utils.ts (1)
  • transformData (6-40)
🪛 Biome (1.9.4)
src/packages/address/elevatorRender.tsx

[error] 229-231: Missing key property for this element in iterable.

The order of the items may change, and having a key can help React identify which item was moved.
Check the React documentation.

(lint/correctness/useJsxKeyInIterable)

🪛 GitHub Check: lint
src/packages/address/elevatorRender.tsx

[warning] 200-200:
React Hook useEffect has a missing dependency: 'levels.length'. Either include it or remove the dependency array

🪛 GitHub Check: build
src/packages/address/elevatorRender.tsx

[failure] 232-232:
Property 'disabled' does not exist on type 'AreaInfo'.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 6

♻️ Duplicate comments (2)
src/packages/address/address.tsx (1)

30-37: ⚠️ Potential issue

缺少 hotList 类型定义导致编译失败

CI 与静态分析均提示 Property 'hotList' does not exist on type 'WebAddressProps'
虽然这里给 defaultProps 及解构都加入了 hotList,但 @/types 中的 WebAddressProps 并未同步更新,编译无法通过。

请在类型声明中补充 hotList 字段(可复用在 Taro 端),例如:

 // @/types/index.d.ts
 export interface WebAddressProps /* ... */ {
   /* 其他字段 */
+  /**
+   * 热门地区列表
+   */
+  hotList?: Array<{ id: string | number; name: string }>
 }

⚠️ 之前的 review 已指出同样问题,本次仍未修复。

Also applies to: 67-68

src/packages/address/address.taro.tsx (1)

32-38: ⚠️ Potential issue

Taro 端同样遗漏 hotList 类型

TaroAddressProps 中也缺少 hotList,与 Web 端一致会触发 TS2339。请同步补齐定义,保持两端类型一致。

// @/types/index.d.ts
export interface TaroAddressProps /* ... */ {
  /* 其他字段 */
+ hotList?: Array<{ id: string | number; name: string }>
}

Also applies to: 68-69

🧹 Nitpick comments (9)
src/packages/address/demo.taro.tsx (1)

26-26: 繁体中文翻译需要修正

当前的翻译使用了简体中文字符"电梯地址",应该使用繁体中文"電梯地址"以保持一致性。

-      elevator: '电梯地址',
+      elevator: '電梯地址',
src/packages/address/demo.tsx (1)

23-23: 繁体中文翻译需要修正

当前的翻译使用了简体中文字符"电梯地址",应该使用繁体中文"電梯地址"以保持一致性。

-      elevator: '电梯地址',
+      elevator: '電梯地址',
src/packages/address/demos/h5/demo11.tsx (2)

6-17: 优化状态管理

setHotListsetOptions状态更新函数在初始化后未再使用,可考虑使用常量或useMemo代替useState,以提高性能和代码清晰度。

-  const [hotList, setHotList] = useState([
+  const hotList = useMemo(() => [
    { id: '1', name: '北京' },
    { id: '2', name: '上海' },
    { id: '1601', name: '广州' },
    { id: '1607', name: '深圳' },
    { id: '1213', name: '杭州' },
    { id: '904', name: '南京' },
    { id: '988', name: '苏州' },
    { id: '3', name: '天津' },
-  ])
+  ], [])

-  const [options, setOptions] = useState<any>([])
-  useEffect(() => {
-    setOptions([
+  const options = useMemo(() => [
    {
      value: '安徽',
      text: '安徽',
      wordCode: 'A',
      // ...省略其他数据...
    }
    // ...省略其他数据...
-   ])
-  }, [])
+  ], [])

Also applies to: 18-176


192-194: 增强错误处理

onChange回调中,应该添加检查确保value数组不为空,以防止潜在的join操作错误。

  onChange={(value) => {
-    setText(value.join(''))
+    setText(value?.length ? value.join('') : '请选择地址')
  }}
src/packages/address/demos/taro/demo11.tsx (3)

6-17: 优化状态管理

setHotListsetOptions状态更新函数在初始化后未再使用,可考虑使用常量或useMemo代替useState,以提高性能和代码清晰度。

-  const [hotList, setHotList] = useState([
+  const hotList = useMemo(() => [
    { id: '1', name: '北京' },
    { id: '2', name: '上海' },
    { id: '1601', name: '广州' },
    { id: '1607', name: '深圳' },
    { id: '1213', name: '杭州' },
    { id: '904', name: '南京' },
    { id: '988', name: '苏州' },
    { id: '3', name: '天津' },
-  ])
+  ], [])

-  const [options, setOptions] = useState<any>([])
-  useEffect(() => {
-    setOptions([
+  const options = useMemo(() => [
    {
      value: '安徽',
      text: '安徽',
      wordCode: 'A',
      // ...省略其他数据...
    }
    // ...省略其他数据...
-   ])
-  }, [])
+  ], [])

Also applies to: 18-176


182-182: 组件标题与功能不匹配

Cell组件的标题"选择自定义地址"与该组件演示的电梯地址功能不符,建议修改为"使用电梯地址"以保持一致性。

-      title="选择自定义地址"
+      title="使用电梯地址"

192-194: 增强错误处理

onChange回调中,应该添加检查确保value数组不为空,以防止潜在的join操作错误。

  onChange={(value) => {
-    setText(value.join(''))
+    setText(value?.length ? value.join('') : '请选择地址')
  }}
src/packages/address/elevatorRender.taro.tsx (2)

197-200: useEffect 依赖列表不完整

useEffect 中使用了 levels.length,却未作为依赖项列出,可能引发状态不同步:

-  }, [innerValue])
+  }, [innerValue, levels.length])

如果希望忽略,可在注释中说明原因以禁用 ESLint 规则。

🧰 Tools
🪛 GitHub Check: lint

[warning] 200-200:
React Hook useEffect has a missing dependency: 'levels.length'. Either include it or remove the dependency array


48-66: 不安全的双重类型断言

defaultProps 使用 as unknown as AddressProps 强制断言,易掩盖类型问题(本文件就存在未声明字段问题)。
建议显式声明部分类型或拆分为 Partial<AddressProps>

-const defaultProps = {
+const defaultProps: Partial<AddressProps> = {
   ...ComponentDefaults,
   /* ... */
-} as unknown as AddressProps
+}
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 3a4ee6d and 0fdc603.

📒 Files selected for processing (9)
  • src/packages/address/address.taro.tsx (4 hunks)
  • src/packages/address/address.tsx (5 hunks)
  • src/packages/address/demo.taro.tsx (4 hunks)
  • src/packages/address/demo.tsx (4 hunks)
  • src/packages/address/demos/h5/demo1.tsx (2 hunks)
  • src/packages/address/demos/h5/demo11.tsx (1 hunks)
  • src/packages/address/demos/taro/demo11.tsx (1 hunks)
  • src/packages/address/elevatorRender.taro.tsx (1 hunks)
  • src/packages/address/utils.ts (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (2)
  • src/packages/address/utils.ts
  • src/packages/address/demos/h5/demo1.tsx
🧰 Additional context used
🪛 GitHub Check: build
src/packages/address/address.tsx

[failure] 67-67:
Property 'hotList' does not exist on type '{ visible: boolean; defaultVisible: boolean; value?: CascaderValue | undefined; defaultValue?: CascaderValue | undefined; type: string; options: CascaderOption[]; ... 284 more ...; onTransitionEndCapture?: TransitionEventHandler<...> | undefined; }'.

src/packages/address/elevatorRender.taro.tsx

[failure] 232-232:
Property 'disabled' does not exist on type 'AreaInfo'.

src/packages/address/address.taro.tsx

[failure] 68-68:
Property 'hotList' does not exist on type '{ visible: boolean; defaultVisible: boolean; value?: CascaderValue | undefined; defaultValue?: CascaderValue | undefined; type: string; options: CascaderOption[]; ... 283 more ...; onTransitionEndCapture?: TransitionEventHandler<...> | undefined; }'.

🪛 Biome (1.9.4)
src/packages/address/elevatorRender.taro.tsx

[error] 229-231: Missing key property for this element in iterable.

The order of the items may change, and having a key can help React identify which item was moved.
Check the React documentation.

(lint/correctness/useJsxKeyInIterable)

🪛 GitHub Check: lint
src/packages/address/elevatorRender.taro.tsx

[warning] 200-200:
React Hook useEffect has a missing dependency: 'levels.length'. Either include it or remove the dependency array

🪛 GitHub Actions: CI
src/packages/address/address.taro.tsx

[error] 68-68: TypeScript error TS2339: Property 'hotList' does not exist on the specified type.

⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: test
🔇 Additional comments (2)
src/packages/address/demo.taro.tsx (1)

12-12: 新增电梯地址组件集成正确

正确引入了新的Demo11组件并在适当位置添加了相应的标题和组件渲染,符合功能扩展需求。

Also applies to: 49-50

src/packages/address/demo.tsx (1)

9-9: 新增电梯地址组件集成正确

正确引入了新的Demo11组件并在适当位置添加了相应的标题和组件渲染,符合功能扩展需求。

Also applies to: 45-46

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

♻️ Duplicate comments (9)
src/packages/address/utils.ts (2)

1-4: ID 生成算法过于简单,极易发生碰撞
此实现对所有字符做 Unicode 求和,abccab 会得到同一 ID,且当名称不足两个字符时风险更高。此前已在历史评论中指出,建议改用哈希或随机字符串。


6-32: 缺少类型定义 & 任意 any 影响可维护性
transformDatagroupByWordCode 全部以 any 处理,失去 TypeScript 静态检查价值。历史评论已给出完整接口示例,建议按示例补充精准类型。

src/packages/address/elevatorRender.tsx (3)

31-35: AreaInfo 缺少 disabled 字段,导致编译错误
onElevatorItemClick 第 240 行访问了 elevatorItem.disabled,但接口未声明该字段。请补充可选属性:

 type AreaInfo = {
   name: string
   id: string | number
   children: any
+  disabled?: boolean
 }

199-207: useEffect 依赖不完整
依赖数组仅包含 innerValuelevels.length 变化时不会重新执行,已在之前的 review 指出。

-useEffect(() => {
+useEffect(() => {
   setTabActiveIndex(levels.length - 1)
   setAddressTip(innerValue.length ? '请选择' : '选择省份/地区')
-}, [innerValue])
+}, [innerValue, levels.length])
🧰 Tools
🪛 GitHub Check: lint

[warning] 206-206:
React Hook useEffect has a missing dependency: 'levels.length'. Either include it or remove the dependency array


208-235: levels.map 外层 Fragment 缺少 key
React 需要稳定 key 以确保列表 Diff 正常。历史反馈未被采纳。

-        {levels.map((item, index) => (
-          <>
+        {levels.map((item, index) => (
+          <React.Fragment key={`level-${index}`}>-          </>
+          </React.Fragment>
         ))}
src/packages/address/elevatorRender.taro.tsx (4)

31-35: 同样缺少 disabled 字段
见 web 版本同评。


199-207: useEffect 依赖缺失
与 web 版本同问题,仍未修复。

🧰 Tools
🪛 GitHub Check: lint

[warning] 202-202:
React Hook useEffect has a missing dependency: 'levels.length'. Either include it or remove the dependency array


208-230: Fragment 缺少 key
Taro 端同样存在。参照 web 版本修复方案。


234-253: 访问未声明属性 disabled
Taro 端同上一问题。

🧰 Tools
🪛 GitHub Check: build

[failure] 235-235:
Property 'disabled' does not exist on type 'AreaInfo'.

🧹 Nitpick comments (4)
src/packages/address/utils.ts (1)

33-44: 保留调试代码降低可读性
// console.log('item', item) 等调试语句应在合并前移除,避免噪声进入生产代码。

src/packages/address/elevatorRender.tsx (2)

279-286: 使用索引作为 key 可能导致重排问题
hotList 渲染仍以 index 作为 key,顺序变化会触发不必要的重新渲染。若数据包含唯一标识,建议改为:

-          {hotList.map((item, index) => (
+          {hotList.map((item) => (
             <div
-              className={`${classPrefix}-hotlist-item`}
-              key={`hot-${index}`}
+              className={`${classPrefix}-hotlist-item`}
+              key={`hot-${item.id}`}
               onClick={() => onHotItemClick(item)}
             >

239-260: 残留调试代码 & 不必要的输出
console.log('close popup') 属开发期调试,应删除或替换为正式日志。

🧰 Tools
🪛 GitHub Check: build

[failure] 240-240:
Property 'disabled' does not exist on type 'AreaInfo'.

src/packages/address/elevatorRender.taro.tsx (1)

274-285: hotList 使用索引作为 key 的问题
同 web 版本,建议改为 item.id

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 0fdc603 and 8e91e2e.

📒 Files selected for processing (6)
  • src/packages/address/demos/h5/demo11.tsx (1 hunks)
  • src/packages/address/demos/taro/demo11.tsx (1 hunks)
  • src/packages/address/elevatorRender.taro.tsx (1 hunks)
  • src/packages/address/elevatorRender.tsx (1 hunks)
  • src/packages/address/utils.ts (1 hunks)
  • src/packages/elevator/elevator.tsx (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (2)
  • src/packages/address/demos/h5/demo11.tsx
  • src/packages/address/demos/taro/demo11.tsx
🧰 Additional context used
🪛 Biome (1.9.4)
src/packages/address/elevatorRender.tsx

[error] 237-239: Missing key property for this element in iterable.

The order of the items may change, and having a key can help React identify which item was moved.
Check the React documentation.

(lint/correctness/useJsxKeyInIterable)

src/packages/address/elevatorRender.taro.tsx

[error] 232-234: Missing key property for this element in iterable.

The order of the items may change, and having a key can help React identify which item was moved.
Check the React documentation.

(lint/correctness/useJsxKeyInIterable)

🪛 GitHub Check: build
src/packages/address/elevatorRender.tsx

[failure] 240-240:
Property 'disabled' does not exist on type 'AreaInfo'.

src/packages/address/elevatorRender.taro.tsx

[failure] 235-235:
Property 'disabled' does not exist on type 'AreaInfo'.

🪛 GitHub Check: lint
src/packages/address/elevatorRender.tsx

[warning] 206-206:
React Hook useEffect has a missing dependency: 'levels.length'. Either include it or remove the dependency array

src/packages/address/elevatorRender.taro.tsx

[warning] 202-202:
React Hook useEffect has a missing dependency: 'levels.length'. Either include it or remove the dependency array

⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: test
🔇 Additional comments (1)
src/packages/elevator/elevator.tsx (1)

277-277: 良好的错误防护措施

通过添加可选链操作符(?.)来安全访问 list[currentIndex]floorKey 属性,有效防止了当 currentIndex 超出数组范围或 list[currentIndex]undefined 时可能发生的运行时错误。这种防御性编程的做法提高了组件的健壮性,特别是在用户快速滚动或进行其他交互操作时。

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 5

♻️ Duplicate comments (6)
src/packages/address/elevatorRender.tsx (2)

22-26: AreaInfo 类型定义需要添加 disabled 属性

AreaInfo 类型定义中缺少 disabled 属性,但在 handleElevatorItemClick 函数中有被注释的代码尝试访问此属性(第183行)。为了未来取消注释该逻辑时不会出现类型错误,应该提前定义该属性。

type AreaInfo = {
  name: string
  id: string | number
  children: any
+ disabled?: boolean
}

216-237: ⚠️ Potential issue

React 迭代器中的 Fragment 缺少 key 属性

在 levels.map 循环中使用了无 key 的 Fragment (<>...</>),这会导致 React 在重新渲染时无法正确识别元素,可能影响性能和渲染正确性。

{levels.map((item, index) => (
-  <>
+  <React.Fragment key={`level-${index}`}>
    {item.name && (
      <div
        className={`${classPrefix}-selected-item ${item.current ? 'active' : ''}`}
        key={`-${index}`}
        onClick={() => {
          props.onTabsChange?.(Number(index))
          setTabActiveIndex(Number(index))
          setLevelIndex(index)
          setElevatorOptions(item.children)
        }}
      >
        {item.name}
      </div>
    )}
    {levels[index + 1]?.name && (
      <div className={`${classPrefix}-selected-border`}>-</div>
    )}
-  </>
+  </React.Fragment>
))}
src/packages/address/elevatorRender.taro.tsx (4)

23-27: AreaInfo 类型定义需要添加 disabled 属性

AreaInfo 类型定义中缺少 disabled 属性,但在 handleElevatorItemClick 函数中有被注释的代码尝试访问此属性(第184行)。为了未来取消注释该逻辑时不会出现类型错误,应该提前定义该属性。

type AreaInfo = {
  name: string
  id: string | number
  children: any
+ disabled?: boolean
}

40-58: defaultProps 缺少 hotList 默认值

在 AddressProps 接口中定义了 hotList 属性,但在 defaultProps 中未提供默认值,这可能导致组件在未传入 hotList 时出现 undefined 访问错误。

const defaultProps = {
  ...ComponentDefaults,
  visible: false,
  type: 'elevator',
  options: [],
+ hotList: [],
  optionKey: { textKey: 'text', valueKey: 'value', childrenKey: 'children' },
  format: {},
  height: '200px',
  activeColor: '',
  activeIcon: 'checklist',
  popup: true,
  closeable: false,
  closeIconPosition: 'top-right',
  closeIcon: 'close',
  lazy: false,
  onClose: () => {},
  onChange: () => {},
  onPathChange: () => {},
} as unknown as AddressProps

217-237: ⚠️ Potential issue

React 迭代器中的 Fragment 缺少 key 属性

在 levels.map 循环中使用了无 key 的 Fragment (<>...</>),这会导致 React 在重新渲染时无法正确识别元素,可能影响性能和渲染正确性。

{levels.map((item, index) => (
-  <>
+  <React.Fragment key={`level-${index}`}>
    {item.name && (
      <View
        className={`${classPrefix}-selected-item ${item.current ? 'active' : ''}`}
        key={`-${index}`}
        onClick={() => {
          props.onTabsChange?.(Number(index))
          setTabActiveIndex(Number(index))
          setLevelIndex(index)
          setElevatorOptions(item.children)
        }}
      >
        {item.name}
      </View>
    )}
    {levels[index + 1]?.name && (
      <View className={`${classPrefix}-selected-border`}>-</View>
    )}
-  </>
+  </React.Fragment>
))}

58-58: 🛠️ Refactor suggestion

不安全的类型断言

使用 as unknown as AddressProps 进行类型断言是不安全的做法,可能掩盖潜在的类型错误。建议使用明确的类型定义。

-const defaultProps = {
+const defaultProps: Partial<AddressProps> = {
  ...ComponentDefaults,
  visible: false,
  type: 'elevator',
  options: [],
+ hotList: [],
  optionKey: { textKey: 'text', valueKey: 'value', childrenKey: 'children' },
  format: {},
  height: '200px',
  activeColor: '',
  activeIcon: 'checklist',
  popup: true,
  closeable: false,
  closeIconPosition: 'top-right',
  closeIcon: 'close',
  lazy: false,
  onClose: () => {},
  onChange: () => {},
  onPathChange: () => {},
-} as unknown as AddressProps
+}
🧹 Nitpick comments (2)
src/packages/address/elevatorRender.tsx (1)

183-183: 注释掉的代码应该移除或实现

有一行被注释掉的代码 // if (elevatorItem?.disabled) return,但相关的 disabled 属性未在 AreaInfo 类型中定义。应该移除此注释或完整实现此功能。

如果这是计划实现的功能,请完成 AreaInfo 类型定义并取消注释;如果不计划实现,请移除此注释行。

src/packages/address/elevatorRender.taro.tsx (1)

184-184: 注释掉的代码应该移除或实现

有一行被注释掉的代码 // if (elevatorItem?.disabled) return,但相关的 disabled 属性未在 AreaInfo 类型中定义。应该移除此注释或完整实现此功能。

如果这是计划实现的功能,请完成 AreaInfo 类型定义并取消注释;如果不计划实现,请移除此注释行。

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 8e91e2e and 91a0008.

📒 Files selected for processing (12)
  • src/locales/base.ts (1 hunks)
  • src/locales/en-US.ts (1 hunks)
  • src/locales/id-ID.ts (1 hunks)
  • src/locales/tr-TR.ts (1 hunks)
  • src/locales/zh-CN.ts (1 hunks)
  • src/locales/zh-TW.ts (1 hunks)
  • src/locales/zh-UG.ts (1 hunks)
  • src/packages/address/demos/h5/demo11.tsx (1 hunks)
  • src/packages/address/doc.md (1 hunks)
  • src/packages/address/elevator.scss (1 hunks)
  • src/packages/address/elevatorRender.taro.tsx (1 hunks)
  • src/packages/address/elevatorRender.tsx (1 hunks)
✅ Files skipped from review due to trivial changes (7)
  • src/locales/zh-CN.ts
  • src/locales/id-ID.ts
  • src/locales/tr-TR.ts
  • src/locales/zh-TW.ts
  • src/locales/zh-UG.ts
  • src/packages/address/elevator.scss
  • src/packages/address/doc.md
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/packages/address/demos/h5/demo11.tsx
🧰 Additional context used
🪛 Biome (1.9.4)
src/packages/address/elevatorRender.taro.tsx

[error] 221-243: Missing key property for this element in iterable.

The order of the items may change, and having a key can help React identify which item was moved.
Check the React documentation.

(lint/correctness/useJsxKeyInIterable)

src/packages/address/elevatorRender.tsx

[error] 220-242: Missing key property for this element in iterable.

The order of the items may change, and having a key can help React identify which item was moved.
Check the React documentation.

(lint/correctness/useJsxKeyInIterable)

🪛 GitHub Check: lint
src/packages/address/elevatorRender.taro.tsx

[warning] 178-178:
React Hook useEffect has missing dependencies: 'levels.length', 'select', and 'selectProvice'. Either include them or remove the dependency array

src/packages/address/elevatorRender.tsx

[warning] 177-177:
React Hook useEffect has missing dependencies: 'levels.length', 'select', and 'selectProvice'. Either include them or remove the dependency array

⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: test

Comment on lines 174 to 177
useEffect(() => {
setTabActiveIndex(levels.length - 1)
setAddressTip(innerValue.length ? select : selectProvice)
}, [innerValue])
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue

useEffect 依赖项不完整

useEffect 钩子函数缺少 levels.lengthselectselectProvice 依赖项。当这些值发生变化时,effect 可能不会重新执行,导致状态更新不及时。

useEffect(() => {
  setTabActiveIndex(levels.length - 1)
  setAddressTip(innerValue.length ? select : selectProvice)
- }, [innerValue])
+ }, [innerValue, levels.length, select, selectProvice])
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
useEffect(() => {
setTabActiveIndex(levels.length - 1)
setAddressTip(innerValue.length ? select : selectProvice)
}, [innerValue])
useEffect(() => {
setTabActiveIndex(levels.length - 1)
setAddressTip(innerValue.length ? select : selectProvice)
}, [innerValue, levels.length, select, selectProvice])
🧰 Tools
🪛 GitHub Check: lint

[warning] 177-177:
React Hook useEffect has missing dependencies: 'levels.length', 'select', and 'selectProvice'. Either include them or remove the dependency array

Comment on lines 175 to 178
useEffect(() => {
setTabActiveIndex(levels.length - 1)
setAddressTip(innerValue.length ? select : selectProvice)
}, [innerValue])
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue

useEffect 依赖项不完整

useEffect 钩子函数缺少 levels.lengthselectselectProvice 依赖项。当这些值发生变化时,effect 可能不会重新执行,导致状态更新不及时。

useEffect(() => {
  setTabActiveIndex(levels.length - 1)
  setAddressTip(innerValue.length ? select : selectProvice)
- }, [innerValue])
+ }, [innerValue, levels.length, select, selectProvice])
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
useEffect(() => {
setTabActiveIndex(levels.length - 1)
setAddressTip(innerValue.length ? select : selectProvice)
}, [innerValue])
useEffect(() => {
setTabActiveIndex(levels.length - 1)
setAddressTip(innerValue.length ? select : selectProvice)
}, [innerValue, levels.length, select, selectProvice])
🧰 Tools
🪛 GitHub Check: lint

[warning] 178-178:
React Hook useEffect has missing dependencies: 'levels.length', 'select', and 'selectProvice'. Either include them or remove the dependency array

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 3

🔭 Outside diff range comments (1)
src/packages/address/doc.zh-TW.md (1)

72-91: 🛠️ Refactor suggestion

缺少hotList属性的文档说明

在文档中缺少对新增的hotList属性的说明,应当添加此属性的功能描述以保持文档的完整性。

建议在属性表中添加:

| 屬性 | 說明 | 類型 | 默認值 |
| --- | --- | --- | --- |
| visible | 是否打開地址選擇 | `boolean` | `-` |
| defaultVisible | 初始地址選擇打開/關閉狀態 | `boolean` | - |
| type | 地址選擇類型 exist/custom/elevator | `string` | `custom` |
+| hotList | 是否展示熱門城市,目前只在電梯模式下有效 | `Array` | - |
| existList | 已存在地址列錶,每個地址對象中,必傳值provinceName、cityName、countyName、townName、addressDetail、selectedAddress(字段解釋見下) | `Array` | `[]` |
🧰 Tools
🪛 LanguageTool

[locale-violation] ~88-~88: 'open' é un xenismo. É preferíbel dicir "aberto"
Context: ...| 方法名 | 說明 | 參數 | | --- | --- | --- | | open | 打開地址選擇 | - | | close | 關閉地址選擇 | -...

(GL_BARBARISM_REPLACE)

♻️ Duplicate comments (7)
src/packages/address/elevatorRender.tsx (3)

35-53: ⚠️ Potential issue

defaultProps缺少hotList默认值

在AddressProps接口中定义了hotList属性,但在defaultProps中未提供默认值,这可能导致组件在未传入hotList时出现undefined访问错误。

const defaultProps = {
  ...ComponentDefaults,
  visible: false,
  type: 'elevator',
  options: [],
+ hotList: [],
  optionKey: { textKey: 'text', valueKey: 'value', childrenKey: 'children' },
  format: {},
  height: '200px',
  activeColor: '',
  activeIcon: 'checklist',
  popup: true,
  closeable: false,
  closeIconPosition: 'top-right',
  closeIcon: 'close',
  lazy: false,
  onClose: () => {},
  onChange: () => {},
  onPathChange: () => {},
} as unknown as AddressProps

169-172: ⚠️ Potential issue

useEffect依赖项不完整

useEffect钩子函数缺少levels.lengthselectselectProvice依赖项。当这些值发生变化时,effect可能不会重新执行,导致状态更新不及时。

useEffect(() => {
  setTabActiveIndex(levels.length - 1)
  setAddressTip(innerValue.length ? select : selectProvice)
- }, [innerValue])
+ }, [innerValue, levels.length, select, selectProvice])
🧰 Tools
🪛 GitHub Check: lint

[warning] 172-172:
React Hook useEffect has missing dependencies: 'levels.length', 'select', and 'selectProvice'. Either include them or remove the dependency array


206-233: ⚠️ Potential issue

renderTabs函数中的Fragment缺少key属性

在renderTabs函数中,map迭代器内使用的Fragment元素缺少key属性,这可能导致React警告并影响性能。

{levels.map((item, index) => (
-  <>
+  <React.Fragment key={`level-fragment-${index}`}>
    {item.name && (
      <div
        className={`${classPrefix}-selected-item ${item.current ? 'active' : ''}`}
        key={`-${index}`}
        onClick={() => {
          props.onTabsChange?.(Number(index))
          setTabActiveIndex(Number(index))
          setLevelIndex(index)
          setElevatorOptions(item.children)
        }}
      >
        {item.name}
      </div>
    )}
    {levels[index + 1]?.name && (
      <div className={`${classPrefix}-selected-border`}>-</div>
    )}
-  </>
+  </React.Fragment>
))}
src/packages/address/elevatorRender.taro.tsx (4)

171-174: ⚠️ Potential issue

useEffect 依赖数组不完整

此 useEffect 钩子使用了 levels.lengthselectselectProvice 变量,但这些变量没有添加到依赖数组中。这可能导致当这些值变化时,effect 不会重新执行。

建议完善依赖数组:

useEffect(() => {
  setTabActiveIndex(levels.length - 1)
  setAddressTip(innerValue.length ? select : selectProvice)
- }, [innerValue])
+ }, [innerValue, levels.length, select, selectProvice])
🧰 Tools
🪛 GitHub Check: lint

[warning] 174-174:
React Hook useEffect has missing dependencies: 'levels.length', 'select', and 'selectProvice'. Either include them or remove the dependency array


212-232: ⚠️ Potential issue

缺少片段键值

在 React 的循环渲染中,每个元素(包括 Fragment)都应该有一个唯一的 key 属性。当前代码中使用了空的 Fragment(<>...</>)但没有为其提供 key,这可能导致渲染和更新时的问题。

建议添加 key 属性:

{levels.map((item, index) => (
-  <>
+  <React.Fragment key={`tab-${index}`}>
    {item.name && (
      <View
        className={`${classPrefix}-selected-item ${item.current ? 'active' : ''}`}
        key={`-${index}`}
        onClick={() => {
          props.onTabsChange?.(Number(index))
          setTabActiveIndex(Number(index))
          setLevelIndex(index)
          setElevatorOptions(item.children)
        }}
      >
        {item.name}
      </View>
    )}
    {levels[index + 1]?.name && (
      <View className={`${classPrefix}-selected-border`}>-</View>
    )}
-  </>
+  </React.Fragment>
))}
🧰 Tools
🪛 GitHub Check: build

[failure] 216-216:
Property 'current' does not exist on type '{ name: null; children: { title: string; list: any; }[]; }'.

🪛 GitHub Actions: CI

[error] 216-216: TypeScript error TS2339: Property 'current' does not exist on type '{ name: null; children: { title: string; list: any; }[]; }'.


36-45: ⚠️ Potential issue

defaultProps 缺少 hotList 属性

AddressProps 接口中定义了 hotList 属性,但在 defaultProps 中没有提供默认值。这可能导致组件使用时出现 TypeScript 错误或运行时异常。

建议添加缺失的 hotList 默认值:

const defaultProps = {
  ...ComponentDefaults,
  visible: false,
  type: 'elevator',
  options: [],
+ hotList: [],
  optionKey: { textKey: 'text', valueKey: 'value', childrenKey: 'children' },
  format: {},
  height: '200px',

54-54: 🛠️ Refactor suggestion

避免使用不安全的类型断言

使用 as unknown as AddressProps 的类型断言会绕过 TypeScript 的类型检查,可能隐藏潜在的类型错误。

建议改用明确的类型定义:

-} as unknown as AddressProps
+} as Partial<AddressProps>

或者更好的方式:

-const defaultProps = {
+const defaultProps: Partial<AddressProps> = {
  // ...属性定义
-} as unknown as AddressProps
+}
🧹 Nitpick comments (7)
src/packages/address/elevatorRender.tsx (3)

121-149: levels计算逻辑正确但需优化

levels的计算逻辑正确,但flatMap和filter的组合使用可能不够高效。考虑直接使用find方法简化查找过程。

const levels: any[] = useMemo(() => {
  const next = []
  let end = false
  let currentOptions = options
  for (const [index, val] of innerValue.entries()) {
-    const opt = currentOptions
-      ?.flatMap((o: any) => o.list.find((item: any) => item.name === val))
-      .filter((item) => item !== undefined)[0]
+    const opt = currentOptions?.find((o: any) => 
+      o.list.some((item: any) => item.name === val)
+    )?.list.find((item: any) => item.name === val)

    next.push({
      name: val,
      children: currentOptions,
      levelIndex: index,
      current: index === tabActiveIndex,
    })
    if (opt?.children) {
      currentOptions = opt.children
    } else {
      end = true
    }
  }
  if (!end) {
    next.push({
      name: null,
      children: currentOptions,
    })
  }
  return next
}, [innerValue, options, tabActiveIndex])

174-191: handleElevatorItemClick函数逻辑正确

handleElevatorItemClick函数的逻辑正确,但有一行被注释掉的代码检查disabled属性,而RegionData类型定义中并未包含该属性。

建议移除注释掉的代码,或在RegionData接口中添加disabled属性:

// 移除注释代码
- // if (elevatorItem?.disabled) return

// 或在RegionData接口中添加disabled属性(在相应文件中)
+ export interface RegionData {
+   name?: string
+   disabled?: boolean
+   [key: string]: any
+ }

235-253: renderHotCity函数应检查hotList是否存在

renderHotCity函数在遍历hotList前应该检查它是否存在,以避免潜在的错误。

const renderHotCity = () => {
  if (levels.length && tabActiveIndex !== 0) return
+  if (!hotList?.length) return
  return (
    <>
      <div className={`${classPrefix}-title`}>{hotCity}</div>
      <div className={`${classPrefix}-hotlist`}>
        {hotList.map((item, index) => (
          <div
            className={`${classPrefix}-hotlist-item`}
            key={`hot-${index}`}
            onClick={() => handleHotItemClick(item)}
          >
            {item.name}
          </div>
        ))}
      </div>
    </>
  )
}
src/packages/address/elevatorRender.taro.tsx (4)

267-267: 考虑使用 props.height 而非硬编码高度

Elevator 组件的 height 属性被硬编码为 "300px",但组件接收了一个 height prop,应该优先使用该 prop 的值。

建议使用 props 中的 height 值:

<Elevator
  className={`${classPrefix}-elevator`}
  list={elevatorOptions}
  onItemClick={(key: string, item: any) =>
    handleElevatorItemClick(item, levelIndex)
  }
- height="300px"
+ height={props.height}
/>

176-193: 建议改进 handleElevatorItemClick 函数类型安全性

handleElevatorItemClick 函数的类型定义不完全,参数 elevatorItem 使用了 RegionData 类型,但实际上可能包含额外的属性如 disabled(如第180行注释所示)。

建议明确函数参数类型,并处理 disabled 状态:

const handleElevatorItemClick = (
- elevatorItem: RegionData,
+ elevatorItem: RegionData & { disabled?: boolean },
  levelIndex: number
) => {
- // if (elevatorItem?.disabled) return
+ if (elevatorItem?.disabled) return
  
  // 其余代码保持不变
}

195-207: 优化 handleHotItemClick 函数类型定义

handleHotItemClick 函数使用了 any 类型的参数,这降低了类型安全性。

建议使用明确的类型定义:

- const handleHotItemClick = (hotItem: any) => {
+ const handleHotItemClick = (hotItem: RegionData) => {
  // 通过修改 innerValue 构造 level 数据
  const distData = findDataByName(options, hotItem.name)
  // 热门城市主要是一级城市和二级城市,可以扩展。TODO
  if (distData) {
    const innerValue = [distData.pName, distData.name].filter(
      (item) => item !== ''
    )
    setInnerValue(innerValue)
    setElevatorOptions(distData.children)
    setLevelIndex(innerValue.length)
  }
}

107-115: 减少条件分支,简化 options 初始化逻辑

当前代码使用了多个条件判断来初始化 options,可以通过调整逻辑顺序来简化代码。

建议按优先级排序逻辑,并提前返回结果:

const options = useMemo(() => {
  if (!isEmpty(format)) {
    return transformData(normalizeListOptions(innerOptions, format))
  }
  if (!isEmpty(optionKey)) {
    return transformData(normalizeOptions(innerOptions, optionKey) || [])
  }
  return transformData(innerOptions)
}, [innerOptions, optionKey, format])
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 91a0008 and 8cc6934.

📒 Files selected for processing (9)
  • src/packages/address/address.taro.tsx (5 hunks)
  • src/packages/address/address.tsx (6 hunks)
  • src/packages/address/doc.en-US.md (2 hunks)
  • src/packages/address/doc.md (3 hunks)
  • src/packages/address/doc.taro.md (2 hunks)
  • src/packages/address/doc.zh-TW.md (2 hunks)
  • src/packages/address/elevatorRender.taro.tsx (1 hunks)
  • src/packages/address/elevatorRender.tsx (1 hunks)
  • src/types/spec/address/base.ts (1 hunks)
✅ Files skipped from review due to trivial changes (1)
  • src/packages/address/doc.en-US.md
🚧 Files skipped from review as they are similar to previous changes (3)
  • src/packages/address/doc.md
  • src/packages/address/address.tsx
  • src/packages/address/address.taro.tsx
🧰 Additional context used
🪛 Biome (1.9.4)
src/packages/address/elevatorRender.taro.tsx

[error] 216-238: Missing key property for this element in iterable.

The order of the items may change, and having a key can help React identify which item was moved.
Check the React documentation.

(lint/correctness/useJsxKeyInIterable)

src/packages/address/elevatorRender.tsx

[error] 214-236: Missing key property for this element in iterable.

The order of the items may change, and having a key can help React identify which item was moved.
Check the React documentation.

(lint/correctness/useJsxKeyInIterable)

🪛 GitHub Check: build
src/packages/address/elevatorRender.taro.tsx

[failure] 216-216:
Property 'current' does not exist on type '{ name: null; children: { title: string; list: any; }[]; }'.

🪛 GitHub Check: lint
src/packages/address/elevatorRender.taro.tsx

[warning] 174-174:
React Hook useEffect has missing dependencies: 'levels.length', 'select', and 'selectProvice'. Either include them or remove the dependency array

src/packages/address/elevatorRender.tsx

[warning] 172-172:
React Hook useEffect has missing dependencies: 'levels.length', 'select', and 'selectProvice'. Either include them or remove the dependency array

🪛 GitHub Actions: CI
src/packages/address/elevatorRender.taro.tsx

[error] 216-216: TypeScript error TS2339: Property 'current' does not exist on type '{ name: null; children: { title: string; list: any; }[]; }'.

⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: test
🔇 Additional comments (13)
src/types/spec/address/base.ts (1)

72-72: 新增的hotList属性符合预期

新增的hotList: RegionData[]属性正确地扩展了地址组件的功能,用于支持电梯模式下的热门地区列表展示。这种类型定义与其他属性保持一致,易于理解和使用。

src/packages/address/doc.zh-TW.md (2)

13-19: 新增电梯地址示例文档正确

成功添加了电梯地址的示例文档,并正确引用了对应的示例代码文件。


71-71: 地址选择类型文档更新正确

文档中已正确更新了type属性,包含了新增的elevator选项。

src/packages/address/doc.taro.md (2)

13-19: 新增电梯地址示例文档正确

成功添加了电梯地址的示例文档,并正确引用了对应的示例代码文件。


79-86: 地址选择类型和热门列表属性文档更新正确

文档中已正确更新了type属性,包含了新增的elevator选项,同时也添加了hotList属性的说明,内容清晰明了。

src/packages/address/elevatorRender.tsx (8)

1-33: 组件导入和接口定义正确

组件导入和AddressProps接口定义正确,包含了所有必要的属性和类型。


55-105: 组件结构和状态管理设计良好

ElevatorRender组件的结构清晰,使用了适当的useState和usePropsValue钩子管理状态。props解构和默认值处理也很规范。


106-119: 数据初始化和转换逻辑正确

使用useMemo进行选项数据的格式化和转换,避免了不必要的重复计算,并且正确处理了不同的格式选项。


151-168: visible状态管理正确

visible状态的管理使用了usePropsValue钩子,确保了组件在受控和非受控模式下都能正常工作。


193-205: handleHotItemClick函数逻辑正确

handleHotItemClick函数的实现正确,能够根据热门项查找数据并更新状态。


255-279: renderArea和renderContent函数实现正确

renderArea和renderContent函数的实现简洁明了,逻辑正确。


281-301: 条件渲染逻辑正确

根据popup属性条件渲染内容的逻辑正确,选择在Popup组件内渲染或直接渲染内容。


303-303: 组件displayName设置正确

为组件设置了正确的displayName,便于调试和开发工具识别。

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 3

♻️ Duplicate comments (6)
src/packages/address/elevatorRender.taro.tsx (3)

175-181: 被注释的禁用逻辑应恢复,避免禁用项可选
如果业务数据含 disabled 字段,当前注释掉的判断会导致禁用节点仍可点击。

-    // if (elevatorItem?.disabled) return
+    if (elevatorItem?.disabled) return

同时确保 RegionData 类型包含 disabled?: boolean,以消除 TS 报错。


36-54: ⚠️ Potential issue

缺少 hotList 默认值且存在不安全的两次类型断言
defaultProps 中仍未给 hotList 提供默认空数组,同时通过 as unknown as AddressProps 强行断言会掩盖类型错误。
如果父组件未传入 hotListrenderHotCityhotList.map 会在运行时抛出异常。

 const defaultProps = {
   ...ComponentDefaults,
   visible: false,
   type: 'elevator',
   options: [],
+  hotList: [], // ✅ 添加默认值,避免空引用
   optionKey: { textKey: 'text', valueKey: 'value', childrenKey: 'children' },
   format: {},
   height: '200px',
@@
   onChange: () => {},
   onPathChange: () => {},
-} as unknown as AddressProps
+} as Partial<AddressProps>        // ✅ 仅声明为部分类型即可

这样既消除了运行时风险,也避免了不必要的双重断言。


170-174: 🛠️ Refactor suggestion

useEffect 依赖缺失,状态可能不同步
当前 effect 只监听 innerValue,但内部使用了 levels.lengthselectselectProvice。当它们变化时不会重新执行,可能导致标签索引或标题错误。

-useEffect(() => {
+useEffect(() => {
   setTabActiveIndex(levels.length - 1)
   setAddressTip(innerValue.length ? select : selectProvice)
-}, [innerValue])
+}, [innerValue, levels.length, select, selectProvice])

请补全依赖或改为 useLayoutEffect / 计算属性以保证一致性。

🧰 Tools
🪛 GitHub Check: lint

[warning] 173-173:
React Hook useEffect has missing dependencies: 'levels.length', 'select', and 'selectProvice'. Either include them or remove the dependency array

src/packages/address/elevatorRender.tsx (3)

35-53: defaultProps 缺少 hotList 默认值

在 AddressProps 接口中定义了 hotList 属性,但在 defaultProps 中未提供默认值,这可能导致组件在未传入 hotList 时出现 undefined 访问错误。

const defaultProps = {
  ...ComponentDefaults,
  visible: false,
  type: 'elevator',
  options: [],
+ hotList: [],
  optionKey: { textKey: 'text', valueKey: 'value', childrenKey: 'children' },
  format: {},
  height: '200px',
  activeColor: '',
  activeIcon: 'checklist',
  popup: true,
  closeable: false,
  closeIconPosition: 'top-right',
  closeIcon: 'close',
  lazy: false,
  onClose: () => {},
  onChange: () => {},
  onPathChange: () => {},
} as unknown as AddressProps

169-172: useEffect 依赖项不完整

useEffect 钩子函数缺少 levels.lengthselectselectProvice 依赖项。当这些值发生变化时,effect 可能不会重新执行,导致状态更新不及时。

useEffect(() => {
  setTabActiveIndex(levels.length - 1)
  setAddressTip(innerValue.length ? select : selectProvice)
- }, [innerValue])
+ }, [innerValue, levels.length, select, selectProvice])
🧰 Tools
🪛 GitHub Check: lint

[warning] 172-172:
React Hook useEffect has missing dependencies: 'levels.length', 'select', and 'selectProvice'. Either include them or remove the dependency array


240-248: 🛠️ Refactor suggestion

热门列表项需使用更有意义的 key

在渲染热门城市列表时,应使用项目的唯一标识符作为 key,而不是数组索引,以确保在列表更新时 React 能正确处理组件重新渲染。

{hotList.map((item, index) => (
  <div
    className={`${classPrefix}-hotlist-item`}
-   key={`hot-${index}`}
+   key={`hot-${item.id || index}`}
    onClick={() => handleHotItemClick(item)}
  >
    {item.name}
  </div>
))}
🧹 Nitpick comments (4)
src/packages/address/elevatorRender.taro.tsx (1)

143-150: levels 数组字段不一致,易引发类型问题
此处为占位节点添加了 levels: -1 字段,而前面节点使用 levelIndexcurrent。字段混用会让 levels 的元素类型不统一,增加维护难度。

       next.push({
         name: null,
         children: currentOptions,
-        levels: -1,
-        current: false,
+        levelIndex: innerValue.length,
+        current: false,
       })

建议统一使用同一接口(如 LevelItem),或显式声明类型,减少类型歧义。

src/packages/address/elevatorRender.tsx (3)

106-115: 优化 useMemo 依赖项

useMemo 钩子函数中计算 options 的逻辑可以通过重构减少重复计算。目前每次 innerOptionsoptionKeyformat 变化时都会执行全部逻辑,可以优化如下:

const options = useMemo(() => {
+ let normalizedOptions = innerOptions;
  if (!isEmpty(format)) {
-   return transformData(normalizeListOptions(innerOptions, format))
+   normalizedOptions = normalizeListOptions(normalizedOptions, format);
  }
- if (!isEmpty(optionKey)) {
+ else if (!isEmpty(optionKey)) {
-   return transformData(normalizeOptions(innerOptions, optionKey) || [])
+   normalizedOptions = normalizeOptions(normalizedOptions, optionKey) || [];
  }
- return transformData(innerOptions)
+ return transformData(normalizedOptions);
}, [innerOptions, optionKey, format])

62-80: 考虑使用解构提取更多必要的属性

当前解构未提取 height 属性,但在组件中需要使用该属性。建议扩展解构列表以包含所有使用的属性。

const {
  hotList,
  title,
  left,
  optionKey,
  format,
  onClose,
  onChange,
  onPathChange,
  popup,
  popupProps = {},
  visible: outerVisible,
  options: outerOptions,
  value: outerValue,
  defaultValue: outerDefaultValue,
  closeable,
  closeIconPosition,
  closeIcon,
+ height,
} = mergeProps(defaultProps, props)

234-252: 考虑抽取热门城市列表为独立组件

热门城市列表的渲染逻辑可以抽取为独立组件,以提高代码可维护性和复用性。这样可以减少 ElevatorRender 组件的复杂度。

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 8cc6934 and c049920.

📒 Files selected for processing (2)
  • src/packages/address/elevatorRender.taro.tsx (1 hunks)
  • src/packages/address/elevatorRender.tsx (1 hunks)
🧰 Additional context used
🪛 GitHub Check: lint
src/packages/address/elevatorRender.taro.tsx

[warning] 173-173:
React Hook useEffect has missing dependencies: 'levels.length', 'select', and 'selectProvice'. Either include them or remove the dependency array

src/packages/address/elevatorRender.tsx

[warning] 172-172:
React Hook useEffect has missing dependencies: 'levels.length', 'select', and 'selectProvice'. Either include them or remove the dependency array

⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: test
🔇 Additional comments (1)
src/packages/address/elevatorRender.tsx (1)

195-204: ⚠️ Potential issue

findDataByName 函数可能返回 undefined

findDataByName 函数可能返回 undefined,但当前代码没有处理这种情况,可能导致运行时错误。

const handleHotItemClick = (hotItem: any) => {
  // 通过修改 innerValue 构造 level 数据
  const distData = findDataByName(options, hotItem.name)
  // 热门城市主要是一级城市和二级城市,可以扩展。TODO
- if (distData) {
+ if (distData && distData.name) {
    const innerValue = [distData.pName, distData.name].filter(
      (item) => item !== ''
    )
    setInnerValue(innerValue)
    setElevatorOptions(distData.children)
    setLevelIndex(innerValue.length)
  }
}

Likely an incorrect or invalid review comment.

elevatorItem: RegionData,
levelIndex: number
) => {
// if (elevatorItem?.disabled) return
Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

被注释掉的禁用状态检查

这行注释掉的代码表明应该有对禁用状态的检查,但目前未实现。如果 elevatorItem 可能包含 disabled 状态,应该恢复这个检查。

- // if (elevatorItem?.disabled) return
+ if (elevatorItem?.disabled) return
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
// if (elevatorItem?.disabled) return
- // if (elevatorItem?.disabled) return
+ if (elevatorItem?.disabled) return

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (2)
packages/nutui-taro-demo/src/pages/index/index.tsx (1)

85-85: 条件逻辑简化,移除了平台特定检查

您已经移除了之前使用的 (harmony() ? com.dd : true) 平台特定检查逻辑,现在组件的展示仅基于 com.showcom.taro 和搜索匹配条件。

这个改动虽然简化了代码,但请确认:

  1. 移除这个平台特定检查是有意为之的
  2. 这不会导致在特定平台上错误地显示不兼容的组件

另外,由于不再使用 harmony() 函数,您可以考虑移除第19行的未使用导入。

src/config.json (1)

467-467: 更新作者信息
author 字段已改为 hanyuxinting,建议在相关文档(如 CHANGELOG.md、README 或其他示例页面)中同步更新,以保持作者信息一致。

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between c049920 and 60527bb.

📒 Files selected for processing (6)
  • packages/nutui-taro-demo/src/pages/index/index.tsx (1 hunks)
  • src/config.json (1 hunks)
  • src/packages/address/address.scss (1 hunks)
  • src/packages/address/address.taro.tsx (6 hunks)
  • src/packages/address/address.tsx (6 hunks)
  • src/packages/address/elevator.scss (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (4)
  • src/packages/address/address.scss
  • src/packages/address/elevator.scss
  • src/packages/address/address.taro.tsx
  • src/packages/address/address.tsx
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: test
🔇 Additional comments (1)
src/config.json (1)

466-466: 确认 v15 字段值更新合理
Address 组件的 v15 字段已由旧值调整为 1,请验证该值是否符合项目中 V15 兼容策略(例如与路由或组件升级逻辑一致)。

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 4

♻️ Duplicate comments (8)
src/packages/address/elevatorRender.tsx (5)

170-174: useEffect 依赖项仍不完整

此前已在过往评论中指出,这里缺少 levels.lengthselectselectProvice 等依赖;本次提交依旧未修复,可能导致状态不同步。请按下方示例补充依赖。

-}, [innerValue])
+}, [innerValue, levels.length, select, selectProvice])
🧰 Tools
🪛 GitHub Check: lint

[warning] 173-173:
React Hook useEffect has missing dependencies: 'levels.length', 'select', and 'selectProvice'. Either include them or remove the dependency array


260-267: height 属性硬编码导致无法按需定制

Elevator 的高度被写死为 300px,与 props 中的 height 不一致,限制了组件可配置性。

-<Elevator
+<Elevator
   className={`${classPrefix}-elevator`}
   list={elevatorOptions}
   onItemClick={(key: string, item: any) =>
     handleElevatorItemClick(item, levelIndex)
   }
-  height="300px"
+  height={props.height}
 />

175-181: 禁用状态检查依旧被注释

仍保留注释的 if (elevatorItem?.disabled) return,会使禁用配置失效。

-  // if (elevatorItem?.disabled) return
+  if (elevatorItem?.disabled) return

241-248: 迭代元素缺少稳定 key,可能导致渲染性能问题

建议使用业务唯一字段(如 idname)作为 key,而非索引。

-  {hotList.map((item, index) => (
-    <div
-      className={`${classPrefix}-hotlist-item`}
-      key={`hot-${index}`}
+  {hotList.map((item) => (
+    <div
+      className={`${classPrefix}-hotlist-item`}
+      key={`hot-${item.id ?? item.name}`}
       onClick={() => handleHotItemClick(item)}
     >
       {item.name}
     </div>
  ))}

35-53: ⚠️ Potential issue

defaultProps 缺少 hotList,运行时可能抛出异常

renderHotCity 中直接访问 hotList.length,而 defaultProps 未为 hotList 提供默认空数组。若调用方未传 hotList,组件将因读取 undefined.length 而报错。

 const defaultProps = {
   ...ComponentDefaults,
   visible: false,
   type: 'elevator',
   options: [],
+  hotList: [],
   optionKey: { textKey: 'text', valueKey: 'value', childrenKey: 'children' },
   format: {},
src/packages/address/elevatorRender.taro.tsx (3)

171-174: ⚠️ Potential issue

useEffect 依赖项不完整

该 useEffect 钩子在其函数体中使用了 levels.lengthselectselectProvice,但这些变量没有包含在依赖数组中。当这些值发生变化时,effect 可能不会重新执行,导致状态更新不及时。

useEffect(() => {
  setTabActiveIndex(levels.length - 1)
  setAddressTip(innerValue.length ? select : selectProvice)
- }, [innerValue])
+ }, [innerValue, levels.length, select, selectProvice])
🧰 Tools
🪛 GitHub Check: lint

[warning] 174-174:
React Hook useEffect has missing dependencies: 'levels.length', 'select', and 'selectProvice'. Either include them or remove the dependency array


54-54: 🛠️ Refactor suggestion

避免使用不安全的类型断言

使用 as unknown as AddressProps 类型断言是不安全的做法,可能会掩盖类型错误。

建议使用明确的类型定义:

-} as unknown as AddressProps
+} as Partial<AddressProps>

36-47: ⚠️ Potential issue

请添加 hotList 的默认值

defaultProps 中缺少 hotList 的默认值,但在 AddressProps 接口中却将其定义为必需属性。如果使用此组件时未提供 hotList,可能会导致运行时错误。

建议添加默认空数组:

const defaultProps = {
  ...ComponentDefaults,
  visible: false,
  type: 'elevator',
  options: [],
+ hotList: [],
  optionKey: { textKey: 'text', valueKey: 'value', childrenKey: 'children' },
  format: {},
  height: '200px',
🧹 Nitpick comments (1)
src/packages/address/elevatorRender.taro.tsx (1)

198-198: 将 TODO 注释更明确

当前的 TODO 注释较为模糊。建议明确说明需要扩展什么功能以及如何实现。

- // 热门城市主要是一级城市和二级城市,可以扩展。TODO
+ // TODO: 扩展热门城市支持,添加对三级及以上城市的支持,需要修改 findDataByName 方法
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 60527bb and 624be13.

📒 Files selected for processing (3)
  • src/packages/address/elevator.scss (1 hunks)
  • src/packages/address/elevatorRender.taro.tsx (1 hunks)
  • src/packages/address/elevatorRender.tsx (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/packages/address/elevator.scss
🧰 Additional context used
🪛 GitHub Check: lint
src/packages/address/elevatorRender.tsx

[warning] 173-173:
React Hook useEffect has missing dependencies: 'levels.length', 'select', and 'selectProvice'. Either include them or remove the dependency array

src/packages/address/elevatorRender.taro.tsx

[warning] 174-174:
React Hook useEffect has missing dependencies: 'levels.length', 'select', and 'selectProvice'. Either include them or remove the dependency array

⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: test
🔇 Additional comments (1)
src/packages/address/elevatorRender.taro.tsx (1)

180-180: 解决注释掉的代码

这行被注释掉的代码是检查 elevatorItem 是否禁用的重要逻辑。如果这是必要的检查,应该取消注释并确保类型定义中包含 disabled 属性。

- // if (elevatorItem?.disabled) return
+ if (elevatorItem?.disabled) return

请确保 RegionData 类型定义中包含 disabled 属性。

Comment on lines +148 to +150
levels: -1,
current: false,
})
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue

保持一致的属性命名

levels 数组中,最后一个被推入的对象具有 levels 属性,而其他对象则使用 levelIndex。这种不一致可能导致类型错误。

建议修改为:

next.push({
  name: null,
  children: currentOptions,
- levels: -1,
+ levelIndex: innerValue.length,
- current: false,
+ current: innerValue.length === tabActiveIndex,
})
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
levels: -1,
current: false,
})
next.push({
name: null,
children: currentOptions,
levelIndex: innerValue.length,
current: innerValue.length === tabActiveIndex,
})

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

♻️ Duplicate comments (9)
src/packages/address/elevatorRender.tsx (3)

193-204: 局部变量与状态同名,易产生混淆

handleHotItemClick 中重新声明了 innerValue,遮蔽同名的 state 变量,降低代码可读性。

-  const innerValue = [distData.pName, distData.name].filter(
-    (item) => item !== ''
-  )
-  setInnerValue(innerValue)
-  setElevatorOptions(distData.children)
-  setLevelIndex(innerValue.length)
+  const nextValue = [distData.pName, distData.name].filter(Boolean)
+  setInnerValue(nextValue)
+  setElevatorOptions(distData.children)
+  setLevelIndex(nextValue.length)

35-53: ⚠️ Potential issue

defaultProps 缺少 hotList 默认值

AddressProps 接口中定义了 hotList 属性,但在 defaultProps 中未提供默认值,这可能导致组件在未传入 hotList 时出现访问错误。

const defaultProps = {
  ...ComponentDefaults,
  visible: false,
  type: 'elevator',
  options: [],
+ hotList: [],
  optionKey: { textKey: 'text', valueKey: 'value', childrenKey: 'children' },
  format: {},
  height: '200px',
  activeColor: '',
  activeIcon: 'checklist',
  popup: true,
  closeable: false,
  closeIconPosition: 'top-right',
  closeIcon: 'close',
  lazy: false,
  onClose: () => {},
  onChange: () => {},
  onPathChange: () => {},
} as unknown as AddressProps

170-173: ⚠️ Potential issue

useEffect 依赖项不完整

useEffect 钩子函数缺少 levels.lengthselectselectProvice 依赖项。当这些值发生变化时,effect 可能不会重新执行,导致状态更新不及时。

useEffect(() => {
  setTabActiveIndex(levels.length - 1)
  setAddressTip(innerValue.length ? select : selectProvice)
- }, [innerValue])
+ }, [innerValue, levels.length, select, selectProvice])
🧰 Tools
🪛 GitHub Check: lint

[warning] 173-173:
React Hook useEffect has missing dependencies: 'levels.length', 'select', and 'selectProvice'. Either include them or remove the dependency array

src/packages/address/elevatorRender.taro.tsx (6)

208-208: ⚠️ Potential issue

增加空数组检查,防止运行时错误

levels 为空数组时,访问 levels[0].name 将导致运行时错误。

建议添加一个额外的检查:

- if (!levels[0].name) return null
+ if (!levels.length || !levels[0].name) return null

171-174: ⚠️ Potential issue

useEffect 依赖项不完整

useEffect 钩子函数缺少 levels.lengthselectselectProvice 依赖项。当这些值发生变化时,effect 可能不会重新执行,导致状态更新不及时。

建议添加缺失的依赖项:

useEffect(() => {
  setTabActiveIndex(levels.length - 1)
  setAddressTip(innerValue.length ? select : selectProvice)
- }, [innerValue])
+ }, [innerValue, levels.length, select, selectProvice])
🧰 Tools
🪛 GitHub Check: lint

[warning] 174-174:
React Hook useEffect has missing dependencies: 'levels.length', 'select', and 'selectProvice'. Either include them or remove the dependency array


257-271: 🛠️ Refactor suggestion

高度参数不一致

Elevator 组件中使用了硬编码的高度值 "93%",而不是使用传入的 props.height 参数。另外,还有一个被注释掉的高度设置 // height="67%" 和一个 style 内联高度设置 height: '100%',这些不一致可能导致样式问题。

建议统一使用 props.height

<Elevator
  className={`${classPrefix}-elevator`}
  list={elevatorOptions}
  onItemClick={(key: string, item: any) =>
    handleElevatorItemClick(item, levelIndex)
  }
- // height="67%"
- style={{ height: '100%' }}
- height="93%"
+ height={props.height}
/>

145-150: ⚠️ Potential issue

保持一致的属性命名

levels 数组中,最后一个被推入的对象具有 levelscurrent 属性,而其他对象则使用 levelIndexcurrent。这种不一致可能导致类型错误和运行时问题。

建议修改为:

if (!end) {
  next.push({
    name: null,
    children: currentOptions,
-   levels: -1,
+   levelIndex: innerValue.length,
-   current: false,
+   current: innerValue.length === tabActiveIndex,
  })
}

36-54: ⚠️ Potential issue

缺少 hotList 默认值,与接口定义不一致

AddressProps 接口中定义了 hotList 属性,但默认属性中没有提供该属性的默认值。这可能导致在未传入 hotList 时访问 undefined,从而引发运行时错误。

建议添加 hotList 默认值:

const defaultProps = {
  ...ComponentDefaults,
  visible: false,
  type: 'elevator',
  options: [],
+ hotList: [], // 添加 hotList 默认值
  optionKey: { textKey: 'text', valueKey: 'value', childrenKey: 'children' },
  format: {},
  height: '200px',
  // ...其他属性
} as unknown as AddressProps

54-54: 🛠️ Refactor suggestion

类型断言使用不当

使用 as unknown as AddressProps 的类型断言是不安全的做法,可能会掩盖类型错误。

建议改用明确的类型定义:

-const defaultProps = {
+const defaultProps: Partial<AddressProps> = {
  ...ComponentDefaults,
  visible: false,
  type: 'elevator',
  options: [],
  // 添加 hotList: [],
  optionKey: { textKey: 'text', valueKey: 'value', childrenKey: 'children' },
  format: {},
  height: '200px',
  // ...其他属性
-} as unknown as AddressProps
+}
🧹 Nitpick comments (4)
src/packages/address/elevatorRender.tsx (4)

242-250: 热门城市列表项需要更稳定的 key

当前使用索引作为 key,对于动态列表不够稳定。若 hotList 中的项目有唯一标识符,应优先使用它作为 key。

{hotList.map((item, index) => (
  <div
    className={`${classPrefix}-hotlist-item`}
-   key={`hot-${index}`}
+   key={item.id ? `hot-${item.id}` : `hot-${index}`}
    onClick={() => handleHotItemClick(item)}
  >
    {item.name}
  </div>
))}

258-267: Elevator 组件高度属性重复设置

Elevator 组件同时设置了 style 内联样式和 height 属性,这是冗余的。建议统一使用一种方式,并确保高度值与父组件设置的 height 属性一致。

<Elevator
  className={`${classPrefix}-elevator`}
  list={elevatorOptions}
  onItemClick={(key: string, item: any) =>
    handleElevatorItemClick(item, levelIndex)
  }
- style={{ height: '100%' }}
- height="93%"
+ height={props.height}
/>

107-116: 考虑添加错误处理机制

当前转换数据的逻辑没有任何错误处理机制。如果输入数据格式不符合预期,可能会导致运行时错误。建议添加适当的错误处理,例如对 transformData 函数的结果进行校验。

const options = useMemo(() => {
+ try {
    if (!isEmpty(format)) {
      return transformData(normalizeListOptions(innerOptions, format))
    }
    if (!isEmpty(optionKey)) {
      return transformData(normalizeOptions(innerOptions, optionKey) || [])
    }
    return transformData(innerOptions)
+ } catch (error) {
+   console.error('地址数据转换失败:', error)
+   return []
+ }
}, [innerOptions, optionKey, format])

286-305: 需要在 props 中添加对 popup 样式的控制

当前 popup 模式下的 Popup 组件高度硬编码为 "89%",没有通过 props 暴露控制接口。如果需要支持不同的高度设置,应该添加相应的属性。

<Popup
  {...popupProps}
  visible={visible}
  position="bottom"
- style={{ height: '89%' }}
+ style={{ height: props.popupHeight || '89%' }}
  round
  closeIcon={closeIcon}
  closeable={closeable}
  closeIconPosition={closeIconPosition}
  title={title}
  left={left}
  onOverlayClick={() => setVisible(false)}
  onCloseIconClick={() => setVisible(false)}
>
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 624be13 and 8294428.

📒 Files selected for processing (4)
  • src/packages/address/demos/h5/demo11.tsx (1 hunks)
  • src/packages/address/demos/taro/demo11.tsx (1 hunks)
  • src/packages/address/elevatorRender.taro.tsx (1 hunks)
  • src/packages/address/elevatorRender.tsx (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (2)
  • src/packages/address/demos/h5/demo11.tsx
  • src/packages/address/demos/taro/demo11.tsx
🧰 Additional context used
🪛 GitHub Check: lint
src/packages/address/elevatorRender.taro.tsx

[warning] 174-174:
React Hook useEffect has missing dependencies: 'levels.length', 'select', and 'selectProvice'. Either include them or remove the dependency array

src/packages/address/elevatorRender.tsx

[warning] 173-173:
React Hook useEffect has missing dependencies: 'levels.length', 'select', and 'selectProvice'. Either include them or remove the dependency array

⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: test
🔇 Additional comments (2)
src/packages/address/elevatorRender.tsx (2)

175-191: 未实现禁用状态检查

以前的代码中可能存在对地址项的禁用状态检查,但在当前实现中没有任何处理。如果 RegionData 类型包含 disabled 属性,应添加相应的检查逻辑。

const handleElevatorItemClick = (
  elevatorItem: RegionData,
  levelIndex: number
) => {
+ if (elevatorItem?.disabled) return
  const nextValue = innerValue.slice(0, levelIndex)
  if (elevatorItem.name) {
    nextValue[levelIndex] = elevatorItem.name
  }
  // 剩余代码...
}

23-33: AddressProps 接口可能缺少类型定义

从代码使用情况看,RegionData 类型应该包含 namepNamechildren 等属性,请确保 RegionData 类型定义中包含这些字段,否则可能导致类型错误。

请检查 RegionData 类型定义是否包含以下属性:

  • name: 地区名称
  • pName: 父级地区名称
  • children: 子级地区列表
  • disabled: 是否禁用(如果支持禁用功能)
  • id: 唯一标识符(如支持)

Copy link

codecov bot commented Apr 27, 2025

Codecov Report

Attention: Patch coverage is 96.41026% with 14 lines in your changes missing coverage. Please review.

Project coverage is 86.70%. Comparing base (bc1f644) to head (60e8f70).
Report is 3 commits behind head on feat_v3.x.

Files with missing lines Patch % Lines
src/packages/address/elevatorRender.tsx 94.91% 12 Missing ⚠️
src/packages/address/address.tsx 97.61% 2 Missing ⚠️
Additional details and impacted files
@@              Coverage Diff              @@
##           feat_v3.x    #3171      +/-   ##
=============================================
+ Coverage      86.54%   86.70%   +0.15%     
=============================================
  Files            289      291       +2     
  Lines          18739    19062     +323     
  Branches        2822     2890      +68     
=============================================
+ Hits           16217    16527     +310     
- Misses          2517     2530      +13     
  Partials           5        5              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

♻️ Duplicate comments (1)
src/packages/address/address.tsx (1)

68-68: 💡 Verification agent

🧩 Analysis chain

确保类型定义已更新

确认hotList属性已被正确添加到组件的props中,请确保相应的类型定义(WebAddressProps接口)也已更新,避免TypeScript编译错误。


🏁 Script executed:

#!/bin/bash
# 检查WebAddressProps接口中是否包含hotList属性
rg -A 20 "export\s+interface\s+WebAddressProps" src/types

Length of output: 162


需要在类型定义中添加 hotList 属性

WebAddressProps 接口当前定义为空,并未包含 hotList,会导致组件使用时报 TypeScript 错误。请在以下位置补充该属性并指定合适类型:

  • 文件src/types/spec/address/h5.ts
  • 位置export interface WebAddressProps extends BaseAddress, WebCascaderProps { … }

示例修改(请根据实际数据结构调整类型):

export interface WebAddressProps extends BaseAddress, WebCascaderProps {
+  /** 热门地址列表 */
+  hotList: HotListItem[]; 
}
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 8294428 and 7f9e385.

📒 Files selected for processing (2)
  • src/packages/address/address.taro.tsx (6 hunks)
  • src/packages/address/address.tsx (6 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/packages/address/address.taro.tsx
🧰 Additional context used
🪛 GitHub Check: codecov/patch
src/packages/address/address.tsx

[warning] 126-144: src/packages/address/address.tsx#L126-L144
Added lines #L126 - L144 were not covered by tests


[warning] 146-146: src/packages/address/address.tsx#L146
Added line #L146 was not covered by tests


[warning] 163-164: src/packages/address/address.tsx#L163-L164
Added lines #L163 - L164 were not covered by tests

⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: test
🔇 Additional comments (6)
src/packages/address/address.tsx (6)

10-10: 增加了电梯式地址选择器导入

引入了新的ElevatorRender组件,支持电梯式地址选择模式,这是一个良好的功能扩展。


21-21: 引入mergeProps工具函数改进了属性合并

使用mergeProps替代手动合并默认属性是一个良好的实践,可以提高代码可维护性。


32-32: 为地址组件添加热门城市列表支持

在默认属性中添加了hotList属性,为电梯模式提供热门城市列表支持。


74-74: 使用mergeProps替代手动合并默认属性

使用专用的mergeProps工具函数替代手动合并默认属性,可以减少代码量并提高可维护性。


99-110: 改进了返回箭头图标的条件渲染逻辑

通过提前返回优化了条件渲染逻辑,使代码更加清晰简洁。


199-204: 优化了地址选择器的渲染逻辑

将渲染逻辑拆分为不同的函数,并根据currentType条件渲染相应的组件,使代码结构更加清晰。

注意:onSwitchModule函数只在'exist'和'custom'模式之间切换,没有处理'elevator'模式。如果需要在三种模式之间切换,请考虑更新onSwitchModule函数。

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

♻️ Duplicate comments (4)
src/packages/address/elevatorRender.taro.tsx (4)

171-174: ⚠️ Potential issue

useEffect 依赖项不完整

useEffect 钩子函数缺少 levels.lengthselectselectProvice 依赖项。当这些值发生变化时,effect 可能不会重新执行,导致状态更新不及时。

useEffect(() => {
  setTabActiveIndex(levels.length - 1)
  setAddressTip(innerValue.length ? select : selectProvice)
- }, [innerValue])
+ }, [innerValue, levels.length, select, selectProvice])
🧰 Tools
🪛 GitHub Check: lint

[warning] 174-174:
React Hook useEffect has missing dependencies: 'levels.length', 'select', and 'selectProvice'. Either include them or remove the dependency array


208-208: ⚠️ Potential issue

增加空数组检查,防止运行时错误

levels 为空数组时,访问 levels[0].name 将导致运行时错误。

建议添加一个额外的检查:

- if (!levels[0].name) return null
+ if (!levels.length || !levels[0].name) return null

36-54: ⚠️ Potential issue

默认属性中缺少 hotList

默认属性对象中没有包含 hotList 属性,而该属性在 AddressProps 接口中是必需的。这可能导致组件在未传入该属性时出现运行时错误。

建议添加默认值:

const defaultProps = {
  ...ComponentDefaults,
  visible: false,
  type: 'elevator',
  options: [],
+ hotList: [],
  optionKey: { textKey: 'text', valueKey: 'value', childrenKey: 'children' },
  format: {},
  height: '200px',
  activeColor: '',
  activeIcon: 'checklist',
  popup: true,
  closeable: false,
  closeIconPosition: 'top-right',
  closeIcon: 'close',
  lazy: false,
  onClose: () => {},
  onChange: () => {},
  onPathChange: () => {},
} as unknown as AddressProps

148-150: ⚠️ Potential issue

属性命名不一致

levels 数组中,最后一个对象使用了 levels 属性,而其他对象都使用 levelIndex。这种不一致会导致类型错误。

建议修改为:

next.push({
  name: null,
  children: currentOptions,
- levels: -1,
+ levelIndex: innerValue.length,
- current: false,
+ current: innerValue.length === tabActiveIndex,
})
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 3edd64c and 3b8669f.

📒 Files selected for processing (3)
  • scripts/build-taro.mjs (0 hunks)
  • src/packages/address/elevatorRender.taro.tsx (1 hunks)
  • src/packages/cascader/cascader.taro.tsx (1 hunks)
💤 Files with no reviewable changes (1)
  • scripts/build-taro.mjs
✅ Files skipped from review due to trivial changes (1)
  • src/packages/cascader/cascader.taro.tsx
🧰 Additional context used
🪛 GitHub Check: lint
src/packages/address/elevatorRender.taro.tsx

[warning] 174-174:
React Hook useEffect has missing dependencies: 'levels.length', 'select', and 'selectProvice'. Either include them or remove the dependency array

⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: test

Comment on lines +266 to +269
// height="67%"
style={{ height: '100%' }}
height="93%"
/>
Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

高度设置不一致

组件中存在三种不同的高度设置方式,会导致样式冲突:

  1. 被注释掉的 height="67%"
  2. 内联样式 style={{ height: '100%' }}
  3. props 属性 height="93%"

建议统一使用一种方式设置高度,并使用从父组件传入的 props.height 值:

<Elevator
  className={`${classPrefix}-elevator`}
  list={elevatorOptions}
  onItemClick={(key: string, item: any) =>
    handleElevatorItemClick(item, levelIndex)
  }
- // height="67%"
- style={{ height: '100%' }}
- height="93%"
+ height={props.height}
/>
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
// height="67%"
style={{ height: '100%' }}
height="93%"
/>
<Elevator
className={`${classPrefix}-elevator`}
list={elevatorOptions}
onItemClick={(key: string, item: any) =>
handleElevatorItemClick(item, levelIndex)
}
height={props.height}
/>

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

♻️ Duplicate comments (9)
src/packages/address/elevatorRender.taro.tsx (5)

54-54: 避免使用不安全的类型断言

使用 as unknown as AddressProps 进行类型断言是不安全的做法,可能会掩盖类型错误。

建议改用显式的类型定义:

-const defaultProps = {
+const defaultProps: Partial<AddressProps> = {
  ...ComponentDefaults,
  visible: false,
  type: 'elevator',
  options: [],
  hotList: [], // 添加缺失的 hotList 默认值
  optionKey: { textKey: 'text', valueKey: 'value', childrenKey: 'children' },
  format: {},
  height: '200px',
  activeColor: '',
  activeIcon: 'checklist',
  popup: true,
  closeable: false,
  closeIconPosition: 'top-right',
  closeIcon: 'close',
  lazy: false,
  onClose: () => {},
  onChange: () => {},
  onPathChange: () => {},
-} as unknown as AddressProps
+}

171-174: useEffect 依赖项不完整

useEffect 钩子函数缺少 levels.lengthselectselectProvice 依赖项。当这些值发生变化时,effect 可能不会重新执行,导致状态更新不及时。

useEffect(() => {
  setTabActiveIndex(levels.length - 1)
  setAddressTip(innerValue.length ? select : selectProvice)
- }, [innerValue])
+ }, [innerValue, levels.length, select, selectProvice])
🧰 Tools
🪛 GitHub Check: lint

[warning] 174-174:
React Hook useEffect has missing dependencies: 'levels.length', 'select', and 'selectProvince'. Either include them or remove the dependency array


145-150: 保持一致的属性命名

levels 数组中,最后一个被推入的对象具有 levels 属性,而其他对象则使用 levelIndex。这种不一致可能导致类型错误。

建议修改为:

next.push({
  name: null,
  children: currentOptions,
- levels: -1,
+ levelIndex: innerValue.length,
- current: false,
+ current: innerValue.length === tabActiveIndex,
})

208-208: 增加空数组检查,防止运行时错误

levels 为空数组时,访问 levels[0].name 将导致运行时错误。

建议添加一个额外的检查:

- if (!levels[0].name) return null
+ if (!levels.length || !levels[0].name) return null

266-269: 高度设置不一致

组件中存在三种不同的高度设置方式,会导致样式冲突:

  1. 被注释掉的 height="67%"
  2. 内联样式 style={{ height: '100%' }}
  3. props 属性 height="93%"

建议统一使用一种方式设置高度,并使用从父组件传入的 props.height 值:

<Elevator
  className={`${classPrefix}-elevator`}
  list={elevatorOptions}
  onItemClick={(key: string, item: any) =>
    handleElevatorItemClick(item, levelIndex)
  }
- // height="67%"
- style={{ height: '100%' }}
- height="93%"
+ height={props.height}
/>
src/packages/address/elevatorRender.tsx (4)

170-174: useEffect 依赖列表仍缺失(重复提醒)

此前已指出需要把 levels.lengthselectselectProvince 纳入依赖。否则切换语言或层级数变化时不会重新计算,UI 与数据易失同步。

-}, [innerValue])
+}, [innerValue, levels.length, select, selectProvince])
🧰 Tools
🪛 GitHub Check: lint

[warning] 173-173:
React Hook useEffect has missing dependencies: 'levels.length', 'select', and 'selectProvince'. Either include them or remove the dependency array


175-191: 🛠️ Refactor suggestion

缺少对禁用项的保护,易导致不可选数据被选中

若数据源为某些区域设置了 disabled,当前逻辑仍可点击生效。建议在早期返回,保持一致性:

 const handleElevatorItemClick = (
   elevatorItem: RegionData,
   levelIndex: number
 ) => {
+  if (elevatorItem?.disabled) return        // 🚫 禁止点击禁用项
   const nextValue = innerValue.slice(0, levelIndex)
   if (elevatorItem.name) {
     nextValue[levelIndex] = elevatorItem.name
   }

35-53: ⚠️ Potential issue

defaultProps 缺少 hotList,调用 .length 会触发运行时异常

renderHotCity 中直接访问 hotList.length,而 defaultProps 未给出默认值;当父组件未显式传入 hotList 时会抛出 “Cannot read properties of undefined” 异常。请为其提供安全默认值。

 const defaultProps = {
   ...ComponentDefaults,
   visible: false,
   type: 'elevator',
   options: [],
+  hotList: [],              // ✅ 避免空指针
   optionKey: { textKey: 'text', valueKey: 'value', childrenKey: 'children' },
   format: {},
   height: '200px',

193-204: ⚠️ Potential issue

局部变量遮蔽 state,降低可读性且易出错

handleHotItemClick 内部重新声明 innerValue,会掩盖同名 state。建议更名并一次性复用,代码更清晰:

-    if (distData) {
-      const innerValue = [distData.pName, distData.name].filter(
-        (item) => item !== ''
-      )
-      setInnerValue(innerValue)
-      setElevatorOptions(distData.children)
-      setLevelIndex(innerValue.length)
-    }
+    if (distData) {
+      const nextValue = [distData.pName, distData.name].filter(Boolean)
+      setInnerValue(nextValue)
+      setElevatorOptions(distData.children)
+      setLevelIndex(nextValue.length)
+    }
🧹 Nitpick comments (5)
src/packages/address/elevatorRender.taro.tsx (4)

194-206: 增强 handleHotItemClick 的类型安全性

handleHotItemClick 函数接受类型为 any 的参数,这降低了类型安全性。建议使用更具体的类型 RegionData,与组件接口中的 hotList 类型保持一致。

-const handleHotItemClick = (hotItem: any) => {
+const handleHotItemClick = (hotItem: RegionData) => {
  // 通过修改 innerValue 构造 level 数据
  const distData = findDataByName(options, hotItem.name)
  // 热门城市主要是一级城市和二级城市,可以扩展。TODO
  if (distData) {
    const innerValue = [distData.pName, distData.name].filter(
      (item) => item !== ''
    )
    setInnerValue(innerValue)
    setElevatorOptions(distData.children)
    setLevelIndex(innerValue.length)
  }
}

277-280: 考虑使用变量存储硬编码高度值

View 组件使用了硬编码的高度值('80%'、'93%')。为提高可维护性,建议将这些值提取为常量或组件属性。

+// 在组件顶部定义常量
+const CONTENT_HEIGHT_WITH_VALUE = '80%'
+const CONTENT_HEIGHT_WITHOUT_VALUE = '93%'

// 在 renderContent 中使用
<View
  style={{
-    height: innerValue.length ? '80%' : '93%',
+    height: innerValue.length ? CONTENT_HEIGHT_WITH_VALUE : CONTENT_HEIGHT_WITHOUT_VALUE,
    overflowY: levels.length && tabActiveIndex !== 0 ? 'hidden' : 'auto',
  }}
>

263-265: 提高 onItemClick 回调的类型安全性

在 Elevator 组件的 onItemClick 回调中,参数 item 的类型被声明为 any,这降低了类型安全性。建议使用明确的 RegionData 类型以确保类型安全。

onItemClick={(key: string, item: any) =>
-  handleElevatorItemClick(item, levelIndex)
+  handleElevatorItemClick(item as RegionData, levelIndex)
}

237-254: 添加 hotList 空值检查

在渲染热门城市列表时,没有检查 hotList 是否为空或未定义,这可能导致在极端情况下出现运行时错误。

const renderHotCity = () => {
  if (levels.length && tabActiveIndex !== 0) return null
+  if (!hotList?.length) return null
  return (
    <>
      <View className={`${classPrefix}-title`}>{hotCity}</View>
      <View
        className={`${classPrefix}-hotlist ${hotList.length > MAX_LENGTH ? 'hotlist-more' : ''}`}
      >
        {hotList.map((item, index) => (
          <View
            className={`${classPrefix}-hotlist-item`}
            key={`hot-${index}`}
            onClick={() => handleHotItemClick(item)}
          >
            {item.name}
          </View>
        ))}
      </View>
    </>
  )
}
src/packages/address/elevatorRender.tsx (1)

258-267: 高度硬编码阻碍外部自定义

Elevator 组件把 height 固定为 "93%",与 props 中的 height 不一致,外部无法通过属性覆盖。推荐优先使用传入值并提供回退:

-        style={{ height: '100%' }}
-        height="93%"
+        style={{ height: '100%' }}
+        height={props.height || '93%'}
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 3b8669f and 529b0d4.

📒 Files selected for processing (9)
  • src/locales/base.ts (1 hunks)
  • src/locales/en-US.ts (1 hunks)
  • src/locales/id-ID.ts (1 hunks)
  • src/locales/tr-TR.ts (1 hunks)
  • src/locales/zh-CN.ts (1 hunks)
  • src/locales/zh-TW.ts (1 hunks)
  • src/locales/zh-UG.ts (1 hunks)
  • src/packages/address/elevatorRender.taro.tsx (1 hunks)
  • src/packages/address/elevatorRender.tsx (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (7)
  • src/locales/id-ID.ts
  • src/locales/tr-TR.ts
  • src/locales/base.ts
  • src/locales/zh-CN.ts
  • src/locales/zh-TW.ts
  • src/locales/en-US.ts
  • src/locales/zh-UG.ts
🧰 Additional context used
🪛 GitHub Check: lint
src/packages/address/elevatorRender.taro.tsx

[warning] 174-174:
React Hook useEffect has missing dependencies: 'levels.length', 'select', and 'selectProvince'. Either include them or remove the dependency array

src/packages/address/elevatorRender.tsx

[warning] 173-173:
React Hook useEffect has missing dependencies: 'levels.length', 'select', and 'selectProvince'. Either include them or remove the dependency array

⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: test
🔇 Additional comments (1)
src/packages/address/elevatorRender.tsx (1)

240-247: 对可能为空的 hotList 缺乏防御性

即使添加默认值,也建议在渲染处使用可选链,提升健壮性,并为列表元素采用更稳定的 key(如 item.id)。

-          {hotList.map((item, index) => (
+          {(hotList ?? []).map((item, index) => (
-              key={`hot-${index}`}
+              key={item.id ?? `hot-${index}`}

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 5

🔭 Outside diff range comments (3)
src/packages/address/existRender.taro.tsx (2)

7-18: 🛠️ Refactor suggestion

使用统一的联合类型提升类型安全

ExistRenderPropstype 依旧是 string,而在全局类型中已定义 AddressModeType = 'exist' | 'cascader' | 'elevator'
type 改为该联合类型,可以在编译期捕获非法值,并与其它组件保持一致。

-export interface ExistRenderProps {
-  type: string
+export interface ExistRenderProps {
+  type: AddressModeType

113-117: ⚠️ Potential issue

判断逻辑有歧义,可能出现按钮文案为空

表达式 (custom || (custom && locale.address.chooseAnotherAddress)) 实际等价于 custom
customtrue(布尔值)时,将把 true 直接渲染到按钮文本里。
常见的做法是:当 custom 为字符串时直接使用,否则回退到国际化文案。

-      {(custom || (custom && locale.address.chooseAnotherAddress)) && (
+      {(typeof custom === 'string' ? custom : locale.address.chooseAnotherAddress) && (
         <View className={`${classPrefix}-footer`} onClick={onClick}>
-          <View className={`${classPrefix}-footer-btn`}>{custom}</View>
+          <View className={`${classPrefix}-footer-btn`}>
+            {typeof custom === 'string'
+              ? custom
+              : locale.address.chooseAnotherAddress}
+          </View>
         </View>
       )}
src/types/spec/address/base.ts (1)

50-63: 🛠️ Refactor suggestion

缺少可选标记导致外部引用容易报错

hotListBaseAddress 中被定义为必填 (hotList: RegionData[])。
虽然当前 defaultProps 提供了 [],但在很多场景(如只引入类型而未使用默认值的 hooks / 业务组件)会提示属性缺失。
与现有的 existListoptions 等保持一致,建议改为可选属性:

-  hotList: RegionData[]
+  hotList?: RegionData[]

同样地,onSwitch?: (data: { type: string }) => void 应复用 AddressModeType

-  onSwitch?: (data: { type: string }) => void
+  onSwitch?: (data: { type: AddressModeType }) => void
♻️ Duplicate comments (1)
src/packages/address/address.tsx (1)

161-164: ⚠️ Potential issue

缺少可选链调用可能导致运行时错误

renderCascatoronChange 中直接调用 onChange(val, params),当用户未传入该回调时会抛异常。
此前已有类似问题在电梯模式中修复,这里应保持一致:

-        onChange={(val: CascaderValue, params?: any) => {
-          onChange(val, params)
-        }}
+        onChange={(val: CascaderValue, params?: any) => {
+          onChange?.(val, params)
+        }}
🧰 Tools
🪛 GitHub Check: codecov/patch

[warning] 163-164: src/packages/address/address.tsx#L163-L164
Added lines #L163 - L164 were not covered by tests

🧹 Nitpick comments (4)
src/packages/address/existRender.taro.tsx (1)

54-57: 使用可选链并避免硬编码字符串

  1. 与其它文件保持风格一致,推荐改为 onSwitch?.(...)
  2. 将硬编码字符串 'cascader' / 'exist' 提炼为常量或使用 AddressModeType,降低拼写出错可能。
-  onSwitch && onSwitch({ type: type === 'exist' ? 'cascader' : 'exist' })
+  onSwitch?.({ type: type === 'exist' ? 'cascader' : 'exist' })
🧰 Tools
🪛 Biome (1.9.4)

[error] 56-56: Change to an optional chain.

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)

src/packages/address/address.tsx (2)

99-110: 函数命名与用途不符 & 拼写问题

  1. renderLeftOnCascaderSwitch 内部用于“存在/级联”切换,不局限于 Cascader;命名可简化为 renderBackIcon
  2. 下方的渲染函数命名为 renderCascator,与组件 CascaderRender 拼写不一致。虽然不影响运行,但易读性较差,建议统一为 renderCascader
-const renderLeftOnCascaderSwitch = () => {
+const renderBackIcon = () => {
...
-const renderCascator = () => {
+const renderCascader = () => {
...
-      left={renderLeftOnCascaderSwitch()}
+      left={renderBackIcon()}

200-204: 渲染分支缺少 else 会多次创建组件

当前按三元表达式分别判断三次,会导致所有分支每次 render 都执行一次条件。可改为 switch 或单一 if...else if,减少不必要的判断与组件生成。

-      {currentType === 'elevator' ? renderElevator() : null}
-      {currentType === 'cascader' ? renderCascator() : null}
-      {currentType === 'exist' ? renderExist() : null}
+      {currentType === 'elevator'
+        ? renderElevator()
+        : currentType === 'cascader'
+        ? renderCascader()
+        : renderExist()}
src/packages/address/address.taro.tsx (1)

163-165: 防御性编码:给 onChange 增加可选链

CascaderRenderonChange 回调中直接调用 onChange(val, params),当调用方未传递该 prop 时会抛出运行时异常;而同文件的 ElevatorRender 已使用可选链。

-          onChange(val, params)
+          onChange?.(val, params)

保持一致性并避免潜在空指针。

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 529b0d4 and 2b92cfd.

⛔ Files ignored due to path filters (1)
  • src/packages/address/__test__/__snapshots__/address.spec.tsx.snap is excluded by !**/*.snap
📒 Files selected for processing (16)
  • src/packages/address/__test__/address.spec.tsx (2 hunks)
  • src/packages/address/address.taro.tsx (5 hunks)
  • src/packages/address/address.tsx (5 hunks)
  • src/packages/address/cascaderRender.taro.tsx (2 hunks)
  • src/packages/address/cascaderRender.tsx (2 hunks)
  • src/packages/address/demo.taro.tsx (2 hunks)
  • src/packages/address/demo.tsx (2 hunks)
  • src/packages/address/demos/h5/demo5.tsx (1 hunks)
  • src/packages/address/doc.en-US.md (2 hunks)
  • src/packages/address/doc.md (3 hunks)
  • src/packages/address/doc.taro.md (2 hunks)
  • src/packages/address/doc.zh-TW.md (2 hunks)
  • src/packages/address/existRender.taro.tsx (2 hunks)
  • src/packages/address/existRender.tsx (2 hunks)
  • src/sites/sites-react/doc/docs/react/migrate-from-v2.md (1 hunks)
  • src/types/spec/address/base.ts (2 hunks)
✅ Files skipped from review due to trivial changes (1)
  • src/sites/sites-react/doc/docs/react/migrate-from-v2.md
🚧 Files skipped from review as they are similar to previous changes (7)
  • src/packages/address/demo.taro.tsx
  • src/packages/address/demo.tsx
  • src/packages/address/doc.zh-TW.md
  • src/packages/address/doc.md
  • src/packages/address/doc.taro.md
  • src/packages/address/doc.en-US.md
  • src/packages/address/test/address.spec.tsx
🧰 Additional context used
🧬 Code Graph Analysis (3)
src/packages/address/cascaderRender.taro.tsx (1)
src/packages/address/cascaderRender.tsx (2)
  • AddressProps (11-20)
  • CascaderRender (32-84)
src/packages/address/cascaderRender.tsx (1)
src/packages/address/cascaderRender.taro.tsx (2)
  • AddressProps (11-20)
  • CascaderRender (32-84)
src/types/spec/address/base.ts (1)
src/types/spec/cascader/base.ts (1)
  • CascaderValue (28-28)
🪛 Biome (1.9.4)
src/packages/address/existRender.tsx

[error] 55-55: Change to an optional chain.

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)

src/packages/address/existRender.taro.tsx

[error] 56-56: Change to an optional chain.

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)

src/packages/address/address.tsx

[error] 123-123: Change to an optional chain.

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)

src/packages/address/address.taro.tsx

[error] 124-124: Change to an optional chain.

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)

🪛 GitHub Check: codecov/patch
src/packages/address/address.tsx

[warning] 163-164: src/packages/address/address.tsx#L163-L164
Added lines #L163 - L164 were not covered by tests

🪛 GitHub Check: build
src/packages/address/address.taro.tsx

[failure] 12-12:
Cannot find module './CascaderRender.taro' or its corresponding type declarations.

🪛 GitHub Actions: CI
src/packages/address/address.taro.tsx

[error] 12-12: TypeScript error TS2307: Cannot find module './CascaderRender.taro' or its corresponding type declarations.

⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: test
🔇 Additional comments (4)
src/packages/address/demos/h5/demo5.tsx (1)

96-96: 条件判断已更新为新的类型值

onSwitch 函数中的条件判断已经从检查 val.type === 'custom' 更新为 val.type === 'cascader',这与地址组件的重构相符,其中默认类型从 'custom' 改为 'cascader'。这保证了当用户切换地址选择模式时,日志记录能够正确反映实际操作。

src/packages/address/cascaderRender.taro.tsx (1)

25-25: 组件重命名和类型更新

此更改包含三个相关联的修改:

  1. 默认类型从 'custom' 更改为 'cascader'
  2. 组件从 CustomRender 重命名为 CascaderRender
  3. 条件渲染的判断从检查 type === 'custom' 更新为 type === 'cascader'

这些更改正确地统一了组件的命名和其功能,使其在整个地址组件系统中保持一致性,与其他文件中的相关更改相匹配。

Also applies to: 32-32, 62-62

src/packages/address/cascaderRender.tsx (1)

25-25: 组件重命名和类型更新

此更改包含三个相关联的修改:

  1. 默认类型从 'custom' 更改为 'cascader'
  2. 组件从 CustomRender 重命名为 CascaderRender
  3. 条件渲染的判断从检查 type === 'custom' 更新为 type === 'cascader'

这些更改正确地统一了组件的命名和其功能,使其与组件的实际用途更加一致。这是地址组件重构的一部分,支持新的三模式渲染系统('exist'、'cascader' 和 'elevator')。

Also applies to: 32-32, 62-62

src/types/spec/address/base.ts (1)

43-44: AddressModeType 定义良好 👍

新增的联合类型为后续重构打下了良好基础,可读性和类型安全性显著提升。

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

♻️ Duplicate comments (2)
src/packages/address/address.taro.tsx (2)

77-77: 🛠️ Refactor suggestion

添加明确的 AddressModeType 联合类型

当前 currentType 使用 string 类型,建议使用明确的联合类型以增强类型安全性。

-const [currentType, setCurrentType] = useState<string>(type)
+const [currentType, setCurrentType] = useState<'elevator' | 'cascader' | 'exist'>(type as 'elevator' | 'cascader' | 'exist')

118-125: ⚠️ Potential issue

修复模块切换时回调参数状态不一致问题

当前实现在调用 setCurrentType 后立即使用旧的 currentType 值调用回调,由于 React 状态更新的异步性,这会导致回调接收到错误的类型值。

-const onSwitchModule = () => {
-  if (currentType === 'exist') {
-    setCurrentType('cascader')
-  } else {
-    setCurrentType('exist')
-  }
-  onSwitch && onSwitch({ type: currentType })
-}
+const onSwitchModule = () => {
+  const nextType = currentType === 'exist' ? 'cascader' : 'exist'
+  setCurrentType(nextType)
+  onSwitch?.({ type: nextType })
+}
🧰 Tools
🪛 Biome (1.9.4)

[error] 124-124: Change to an optional chain.

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 2b92cfd and 39068af.

📒 Files selected for processing (1)
  • src/packages/address/address.taro.tsx (5 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (1)
src/packages/address/address.taro.tsx (7)
src/utils/typings.ts (1)
  • ComponentDefaults (10-13)
src/utils/merge-props.ts (1)
  • mergeProps (4-16)
src/packages/calendarcard/icon.taro.tsx (1)
  • ArrowLeft (44-44)
src/packages/address/elevatorRender.taro.tsx (1)
  • ElevatorRender (56-308)
src/packages/address/cascaderRender.taro.tsx (1)
  • CascaderRender (32-84)
src/packages/popup/popup.taro.tsx (1)
  • Popup (41-259)
src/packages/address/existRender.taro.tsx (1)
  • ExistRender (25-120)
🪛 Biome (1.9.4)
src/packages/address/address.taro.tsx

[error] 124-124: Change to an optional chain.

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)

⏰ Context from checks skipped due to timeout of 90000ms (2)
  • GitHub Check: build
  • GitHub Check: test
🔇 Additional comments (7)
src/packages/address/address.taro.tsx (7)

11-12: 添加电梯式地址选择组件与级联选择组件 ✅

引入了新的 ElevatorRender 组件和重命名后的 CascaderRender 组件,支持电梯式和级联式两种地址选择模式。这是 v15 版本的核心功能增强。


27-27: 更新默认 type 为 'cascader' 并添加 hotList 属性 ✅

将默认类型从 'custom' 更改为 'cascader',并添加了 hotList 属性用于支持热门城市列表功能,这与电梯模式相匹配。

Also applies to: 33-33


75-75: 使用 mergeProps 替代属性展开 ✅

使用 mergeProps 工具函数替代简单的属性展开操作,可以避免 undefined 值覆盖默认值,提高组件属性合并的可靠性。


100-111: 重命名并简化返回图标处理函数 ✅

将函数名从 renderLeftOnCustomSwitch 更改为 renderLeftOnCascaderSwitch,更好地反映其实际用途,并简化了条件判断逻辑。


126-147: 新增电梯模式渲染函数 ✅

添加 renderElevator 函数专门渲染电梯式地址选择界面,正确传递了 hotList 等相关属性,并使用了可选链确保 onChange 安全调用。


169-199: 抽取已有地址模式渲染函数 ✅

将已有地址渲染逻辑抽取为 renderExist 函数,保持了原有的功能和结构,使代码更模块化且易于维护。


202-204: 更新条件渲染逻辑支持三种模式 ✅

将渲染逻辑更新为支持三种模式:电梯式、级联式和已有地址,使用清晰的条件渲染方式,便于理解和维护。

但需要注意修复 renderCascator 的拼写错误。

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (5)
src/packages/address/existRender.tsx (1)

53-56: 建议使用可选链调用 onSwitch
当前写法在功能上没有问题,但更符合现代 TypeScript/ES 规范的写法是使用可选链,代码也更简洁:

-    onSwitch && onSwitch({ type: type === 'exist' ? 'cascader' : 'exist' })
+    onSwitch?.({ type: type === 'exist' ? 'cascader' : 'exist' })
🧰 Tools
🪛 Biome (1.9.4)

[error] 55-55: Change to an optional chain.

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)

src/packages/address/address.tsx (2)

118-121: onSwitch 回调建议改为可选链

-    setCurrentType(nextType)
-    onSwitch && onSwitch({ type: nextType })
+    setCurrentType(nextType)
+    onSwitch?.({ type: nextType })

可避免 onSwitch 未传入时出现 ESLint/Biome 告警。

🧰 Tools
🪛 Biome (1.9.4)

[error] 120-120: Change to an optional chain.

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)


145-164: 函数命名 & 回调安全性

  1. 函数名 renderCascator 拼写不规范,建议改为 renderCascader,与组件 CascaderRender 一致。
  2. onChange 同样建议使用可选链:
-  const renderCascator = () => {
+  const renderCascader = () => {
     ...
-          onChange && onChange(val, params)
+          onChange?.(val, params)
     ...
   }

同时别忘了将下方调用处一并改为 renderCascader()

🧰 Tools
🪛 Biome (1.9.4)

[error] 160-160: Change to an optional chain.

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)

🪛 GitHub Check: codecov/patch

[warning] 160-161: src/packages/address/address.tsx#L160-L161
Added lines #L160 - L161 were not covered by tests

src/packages/address/address.taro.tsx (2)

118-122: onSwitch 建议使用可选链

-    setCurrentType(nextType)
-    onSwitch && onSwitch({ type: nextType })
+    setCurrentType(nextType)
+    onSwitch?.({ type: nextType })
🧰 Tools
🪛 Biome (1.9.4)

[error] 121-121: Change to an optional chain.

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)


145-165: 拼写一致性 & 回调安全性

-  const renderCascator = () => {
+  const renderCascader = () => {
     ...
-          onChange && onChange(val, params)
+          onChange?.(val, params)
   }

并同步修改下方 renderCascator() 的调用。

🧰 Tools
🪛 Biome (1.9.4)

[error] 161-161: Change to an optional chain.

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 39068af and bab94df.

📒 Files selected for processing (3)
  • src/packages/address/address.taro.tsx (5 hunks)
  • src/packages/address/address.tsx (5 hunks)
  • src/packages/address/existRender.tsx (2 hunks)
🧰 Additional context used
🪛 Biome (1.9.4)
src/packages/address/address.taro.tsx

[error] 121-121: Change to an optional chain.

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)


[error] 161-161: Change to an optional chain.

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)

src/packages/address/address.tsx

[error] 120-120: Change to an optional chain.

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)


[error] 160-160: Change to an optional chain.

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)

src/packages/address/existRender.tsx

[error] 55-55: Change to an optional chain.

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)

🪛 GitHub Check: codecov/patch
src/packages/address/address.tsx

[warning] 160-161: src/packages/address/address.tsx#L160-L161
Added lines #L160 - L161 were not covered by tests

⏰ Context from checks skipped due to timeout of 90000ms (2)
  • GitHub Check: build
  • GitHub Check: test
🔇 Additional comments (5)
src/packages/address/existRender.tsx (1)

17-17: 默认类型拼写已纠正,👍
defaultProps.type 已由 'exsit' 更正为 'exist',避免了类型比对出错的问题。

src/packages/address/address.tsx (2)

9-11: 模块化拆分导入值得肯定
引入 CascaderRenderElevatorRender,使组件职责更加清晰,易于维护。


24-33: 请确认类型定义已同步添加 hotList
defaultProps 新增 hotList。若 WebAddressProps 未同步更新,将导致类型报错。
建议再次检查 @/types 下的对应接口。

src/packages/address/address.taro.tsx (2)

11-13: 导入路径大小写问题已修复,👍
统一使用小写文件名,解决 *nix 系统下的编译失败。


24-34: 确认 hotList 已在 Taro 类型声明中补充
同 Web 端,需要确保 TaroAddressProps 已包含 hotList 字段。

handleElevatorItemClick(item, levelIndex)
}
style={{ height: '100%' }}
height="93%"
Copy link
Collaborator

Choose a reason for hiding this comment

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

怎么有两个height

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

需要动态设置高度,一个是外层一个内层。
等 合并 V15 Elevator 后,看看是不是可以优化~

@irisSong
Copy link
Collaborator

截屏2025-04-29 14 34 33 选中北京 切换回来 热门城市未选中 电梯项也未选中

@xiaoyatong xiaoyatong requested a review from Miles-hxy May 5, 2025 03:33
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

♻️ Duplicate comments (8)
src/packages/address/elevatorRender.taro.tsx (3)

174-175: ⚠️ Potential issue

useEffect 依赖项不完整

useEffect 钩子缺少 levels.lengthselectselectProvince 依赖项。当这些值发生变化时,effect 可能不会重新执行,导致状态不同步。

useEffect(() => {
  setTabActiveIndex(levels.length - 1)
  setAddressTip(innerValue.length ? select : selectProvince)
- }, [innerValue])
+ }, [innerValue, levels.length, select, selectProvince])
🧰 Tools
🪛 GitHub Check: lint

[warning] 175-175:
React Hook useEffect has missing dependencies: 'levels.length', 'select', and 'selectProvince'. Either include them or remove the dependency array


148-151: 🛠️ Refactor suggestion

确保对象属性命名一致

next.push 添加的对象使用了 levels: -1 而不是 levelIndex,与前面的对象属性命名不一致,可能导致类型错误。

next.push({
  name: null,
  children: currentOptions,
- levels: -1,
+ levelIndex: innerValue.length,
  current: false,
})

267-270: 🛠️ Refactor suggestion

移除冲突的高度设置

Elevator 组件具有多种冲突的高度设置方式:内联样式、属性和一个被注释掉的值。这会导致样式冲突和难以预测的渲染结果。

<Elevator
  className={`${classPrefix}-elevator`}
  list={elevatorOptions}
  onItemClick={(key: string, item: any) =>
    handleElevatorItemClick(item, levelIndex)
  }
- // height="67%"
- style={{ height: '100%' }}
  height="93%"
/>
src/packages/address/elevatorRender.tsx (2)

148-150: 🛠️ Refactor suggestion

确保对象属性命名一致

next.push 添加的对象使用了 levels: -1 而不是 levelIndex,与前面的对象属性命名不一致,可能导致类型错误。

next.push({
  name: null,
  children: currentOptions,
- levels: -1,
+ levelIndex: innerValue.length,
  current: false,
})

174-174: ⚠️ Potential issue

useEffect 依赖项不完整

useEffect 钩子缺少 levels.lengthselectselectProvince 依赖项。当这些值发生变化时,effect 可能不会重新执行,导致状态不同步。

useEffect(() => {
  setTabActiveIndex(levels.length - 1)
  setAddressTip(innerValue.length ? select : selectProvince)
- }, [innerValue])
+ }, [innerValue, levels.length, select, selectProvince])
🧰 Tools
🪛 GitHub Check: lint

[warning] 174-174:
React Hook useEffect has missing dependencies: 'levels.length', 'select', and 'selectProvince'. Either include them or remove the dependency array

src/packages/address/address.taro.tsx (3)

145-145: 函数命名拼写错误

renderCascator 应该是 renderCascader,与导入的组件名 CascaderRender 保持一致。此类拼写错误可能导致代码阅读困难和命名混淆。

-const renderCascator = () => {
+const renderCascader = () => {

199-201: 渲染条件逻辑可优化

当前使用了三个单独的条件渲染语句。建议使用更具可维护性的方式,如对象映射或变量存储渲染结果。

-  {currentType === 'elevator' ? renderElevator() : null}
-  {currentType === 'cascader' ? renderCascator() : null}
-  {currentType === 'exist' ? renderExist() : null}
+  {
+    {
+      'elevator': renderElevator(),
+      'cascader': renderCascader(), // 注意这里已修正拼写
+      'exist': renderExist()
+    }[currentType] || null
+  }

161-161: ⚠️ Potential issue

添加可选链运算符防止错误

在调用 onChange 时需要使用可选链,与 renderElevator 中的用法保持一致,以防止 onChange 未定义时出现运行时错误。

onChange={(val: CascaderValue, params?: any) => {
-  onChange && onChange(val, params)
+  onChange?.(val, params)
}}
🧰 Tools
🪛 Biome (1.9.4)

[error] 161-161: Change to an optional chain.

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)

🧹 Nitpick comments (4)
src/packages/address/address.tsx (2)

145-145: 函数命名拼写错误

renderCascator 应该是 renderCascader,与导入的组件名 CascaderRender 保持一致。此类拼写错误可能导致代码阅读困难和命名混淆。

-const renderCascator = () => {
+const renderCascader = () => {

199-201: 渲染条件逻辑可优化

当前使用了三个单独的条件渲染语句。建议使用更具可维护性的方式,如对象映射或变量存储渲染结果。

-  {currentType === 'elevator' ? renderElevator() : null}
-  {currentType === 'cascader' ? renderCascator() : null}
-  {currentType === 'exist' ? renderExist() : null}
+  {
+    {
+      'elevator': renderElevator(),
+      'cascader': renderCascader(), // 注意这里已修正拼写
+      'exist': renderExist()
+    }[currentType] || null
+  }
src/packages/address/address.taro.tsx (2)

121-121: 使用可选链调用回调函数

使用可选链运算符调用 onSwitch 回调函数,以符合现代 JavaScript 最佳实践,提高代码可读性。

-onSwitch && onSwitch({ type: nextType })
+onSwitch?.({ type: nextType })
🧰 Tools
🪛 Biome (1.9.4)

[error] 121-121: Change to an optional chain.

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)


77-77: 定义明确的联合类型

按照原有代码评论建议,建议将 currentType 状态的类型从 string 改为明确的联合类型,以提高类型安全性。

-const [currentType, setCurrentType] = useState<string>(type)
+const [currentType, setCurrentType] = useState<'exist' | 'cascader' | 'elevator'>(type as 'exist' | 'cascader' | 'elevator')
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between bab94df and 60e8f70.

📒 Files selected for processing (11)
  • src/packages/address/address.taro.tsx (5 hunks)
  • src/packages/address/address.tsx (5 hunks)
  • src/packages/address/demos/h5/demo1.tsx (2 hunks)
  • src/packages/address/demos/h5/demo11.tsx (1 hunks)
  • src/packages/address/demos/taro/demo11.tsx (1 hunks)
  • src/packages/address/elevatorRender.taro.tsx (1 hunks)
  • src/packages/address/elevatorRender.tsx (1 hunks)
  • src/packages/address/utils.ts (1 hunks)
  • src/sites/sites-react/doc/docs/react/migrate-from-v2.md (1 hunks)
  • src/sites/sites-react/doc/docs/taro/migrate-from-v2.md (1 hunks)
  • src/types/spec/cascader/base.ts (1 hunks)
✅ Files skipped from review due to trivial changes (2)
  • src/types/spec/cascader/base.ts
  • src/sites/sites-react/doc/docs/taro/migrate-from-v2.md
🚧 Files skipped from review as they are similar to previous changes (5)
  • src/sites/sites-react/doc/docs/react/migrate-from-v2.md
  • src/packages/address/demos/taro/demo11.tsx
  • src/packages/address/utils.ts
  • src/packages/address/demos/h5/demo1.tsx
  • src/packages/address/demos/h5/demo11.tsx
🧰 Additional context used
🪛 GitHub Check: lint
src/packages/address/elevatorRender.taro.tsx

[warning] 175-175:
React Hook useEffect has missing dependencies: 'levels.length', 'select', and 'selectProvince'. Either include them or remove the dependency array

src/packages/address/elevatorRender.tsx

[warning] 174-174:
React Hook useEffect has missing dependencies: 'levels.length', 'select', and 'selectProvince'. Either include them or remove the dependency array

🪛 Biome (1.9.4)
src/packages/address/address.tsx

[error] 120-120: Change to an optional chain.

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)


[error] 160-160: Change to an optional chain.

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)

src/packages/address/address.taro.tsx

[error] 121-121: Change to an optional chain.

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)


[error] 161-161: Change to an optional chain.

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)

🪛 GitHub Check: codecov/patch
src/packages/address/address.tsx

[warning] 160-161: src/packages/address/address.tsx#L160-L161
Added lines #L160 - L161 were not covered by tests

src/packages/address/elevatorRender.tsx

[warning] 111-112: src/packages/address/elevatorRender.tsx#L111-L112
Added lines #L111 - L112 were not covered by tests


[warning] 116-116: src/packages/address/elevatorRender.tsx#L116
Added line #L116 was not covered by tests


[warning] 186-187: src/packages/address/elevatorRender.tsx#L186-L187
Added lines #L186 - L187 were not covered by tests


[warning] 217-221: src/packages/address/elevatorRender.tsx#L217-L221
Added lines #L217 - L221 were not covered by tests


[warning] 227-227: src/packages/address/elevatorRender.tsx#L227
Added line #L227 was not covered by tests


[warning] 305-305: src/packages/address/elevatorRender.tsx#L305
Added line #L305 was not covered by tests

⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: test

Comment on lines +160 to +161
onChange && onChange(val, params)
}}
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue

添加可选链运算符防止错误

在调用 onChange 时需要使用可选链,与 renderElevator 中的用法保持一致,以防止 onChange 未定义时出现运行时错误。

onChange={(val: CascaderValue, params?: any) => {
-  onChange && onChange(val, params)
+  onChange?.(val, params)
}}
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
onChange && onChange(val, params)
}}
onChange={(val: CascaderValue, params?: any) => {
onChange?.(val, params)
}}
🧰 Tools
🪛 Biome (1.9.4)

[error] 160-160: Change to an optional chain.

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)

🪛 GitHub Check: codecov/patch

[warning] 160-161: src/packages/address/address.tsx#L160-L161
Added lines #L160 - L161 were not covered by tests

@xiaoyatong
Copy link
Collaborator Author

截屏2025-04-29 14 34 33 选中北京 切换回来 热门城市未选中 电梯项也未选中

需要Elevator 支持受控

@xiaoyatong xiaoyatong requested a review from irisSong May 5, 2025 05:43
@irisSong irisSong merged commit 56f239d into jdf2e:feat_v3.x May 5, 2025
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

3.x Target branch 3.x action:review This PR needs more reviews (less than 2 approvals) size/XXL

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants