Skip to content

feat(rate): 支持清空评分,评分支持滑动为0 - #1302

Merged
Moonofweisheng merged 2 commits into
Moonofweisheng:masterfrom
TAYUN:feat/rate-zero-support
Sep 18, 2025
Merged

Moonofweisheng merged 2 commits into
Moonofweisheng:masterfrom
TAYUN:feat/rate-zero-support

Conversation

@TAYUN

@TAYUN TAYUN commented Sep 15, 2025 •

Copy link
Copy Markdown
Collaborator
  • 在 changeRate 函数中增加判断,当 index 为 -1 时设置 value 为 0
  • 在 onTouchMove 函数中,当 clientX 小于第一个评分项的 left 时,调用 changeRate(-1, false)

🤔 这个 PR 的性质是?(至少选择一个)

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

🔗 相关 Issue

#1293

💡 需求背景和解决方案

取消评分的情况

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

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

  • 文档已补充或无须补充
  • 代码演示已提供或无须提供
  • TypeScript 定义已补充或无须补充

Summary by CodeRabbit

  • New Features

    • 新增允许评分为 0 的配置项,支持按需开启 0 分评分行为。
  • Bug Fixes

    • 修复在左滑超出首个星时未重置为 0 分的问题,现会正确归零。
    • 修复触摸滑动在只读或禁用状态下仍响应的问题,交互现已被忽略。
    • 优化边界与半星计算,避免出现负值或异常评分,提升交互稳定性。

- 在 changeRate 函数中增加判断,当 index 为 -1 时设置 value 为 0
- 在 onTouchMove 函数中,当 clientX 小于第一个评分项的 left 时,调用 changeRate(-1, false)
@vercel

vercel Bot commented Sep 15, 2025 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Preview Comments Updated (UTC)
wot-design-uni Ready Ready Preview Comment Sep 15, 2025 2:52pm

@netlify

netlify Bot commented Sep 15, 2025 •

Copy link
Copy Markdown

✅ Deploy Preview for wot-design-uni ready!

Built without sensitive environment variables

Name Link
🔨 Latest commit e480adb
🔍 Latest deploy log https://app.netlify.com/projects/wot-design-uni/deploys/68c827e4afeba50008281d2a
😎 Deploy Preview https://deploy-preview-1302--wot-design-uni.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@coderabbitai

coderabbitai Bot commented Sep 15, 2025 •

Copy link
Copy Markdown

Walkthrough

在 wd-rate 组件中新增 allowZero 属性;调整触摸滑动与评分更新逻辑:为 changeRate 新增 index === -1 时强制置 0;onTouchMove 增加 readonly/disabled 早退;补充左侧越界时调用 changeRate(-1, false) 的边界处理。对外 API 增加了布尔属性 allowZero。

Changes

Cohort / File(s) Change summary
wd-rate 触摸与边界处理
src/uni_modules/wot-design-uni/components/wd-rate/wd-rate.vue
changeRate:当 index === -1 时强制值为 0;onTouchMove:新增 readonly/disabled 早退;获取 rateItems 后新增左侧越界判断并调用 changeRate(-1, false) 后返回;其余 targetIndex/isHalf 计算与更新逻辑保持不变。
wd-rate 类型/Props
src/uni_modules/wot-design-uni/components/wd-rate/types.ts
新增布尔 prop allowZero(makeBooleanProp(false)),默认 false,JSDoc: "是否允许评分为0"。无其它对外签名变更。

Sequence Diagram(s)

sequenceDiagram
  autonumber
  participant U as 用户
  participant R as wd-rate 组件
  participant CR as changeRate()

  rect rgba(230,240,255,0.4)
    U->>R: touchmove
    alt 只读/禁用
      R-->>U: 直接返回(不处理)
    else 可交互
      R->>R: 获取 rateItems
      alt 触点在第一个星左侧
        R->>CR: changeRate(-1, false)
        CR-->>R: 值设为 0
        R-->>U: 更新渲染为 0
      else 正常区域
        R->>R: 计算 targetIndex / isHalf
        R->>CR: changeRate(targetIndex, isHalf)
        CR-->>R: 更新值并渲染
      end
    end
  end

  note over CR: 新增规则:index === -1 时强制置 0;新增 prop `allowZero`
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

Poem

小兔抚星排成行,
指尖滑过月光凉。
左越归零新规则,
可允零分新属性亮。
只读不动静静望,评分更稳心不慌。 🐇✨

Pre-merge checks and finishing touches

✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title Check ✅ Passed 标题 “feat(rate): 支持清空评分,评分支持滑动为0” 直观且精确地概括了本次变更的核心目的:让评分可被清空(index = -1 设置为 0)并支持通过滑动把评分置为 0(onTouchMove 的边界处理)。措辞简洁、具体,未包含文件列表或不必要的噪音,能让审阅者快速把握 PR 的主要改动点。基于提供的摘要与 PR 目标,标题与变更内容高度相关且足够清晰,因此评定为通过。
Docstring Coverage ✅ Passed No functions found in the changes. Docstring coverage check skipped.
✨ Finishing touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

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 (1)
src/uni_modules/wot-design-uni/components/wd-rate/wd-rate.vue (1)

131-138: 建议为清空评分功能补充单元测试

虽然当前实现的清空评分功能逻辑正确,但考虑到这是新增的核心功能,建议补充相应的测试用例来确保:

  1. changeRate(-1, false) 能正确设置 value 为 0
  2. 边界触摸事件能正确触发清空评分
  3. 在 readonly 和 disabled 状态下清空功能被正确禁用

根据 PR 描述中的自检清单显示测试用例尚未勾选,建议补充相关测试:

// 建议的测试用例示例
describe('wd-rate clearable functionality', () => {
  it('should set value to 0 when changeRate is called with index -1', () => {
    const wrapper = mount(WdRate, { props: { modelValue: 3, num: 5 } })
    wrapper.vm.changeRate(-1, false)
    expect(wrapper.emitted('update:modelValue')[0]).toEqual([0])
  })
  
  it('should not clear rating when readonly or disabled', () => {
    const wrapper = mount(WdRate, { props: { modelValue: 3, readonly: true } })
    wrapper.vm.changeRate(-1, false)
    expect(wrapper.emitted('update:modelValue')).toBeUndefined()
  })
})
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 41dd417 and f12a95f.

📒 Files selected for processing (1)
  • src/uni_modules/wot-design-uni/components/wd-rate/wd-rate.vue (1 hunks)
🔇 Additional comments (4)
src/uni_modules/wot-design-uni/components/wd-rate/wd-rate.vue (4)

133-133: LGTM! 支持清空评分功能

新增对 index === -1 的判断逻辑,当触摸滑动到第一个评分项左侧时能正确设置评分为 0,实现清空评分的功能需求。


141-141: 良好的性能优化

在函数开头增加 readonly 和 disabled 状态的早期返回判断,避免不必要的 DOM 查询和计算操作,提升性能。


144-147: 完善的边界处理逻辑

新增对触摸位置在第一个评分项左侧的边界检测,当用户滑动到评分区域左侧时调用 changeRate(-1, false) 实现清空评分,逻辑清晰且符合用户交互预期。


140-161: 验证触摸事件兼容性(需手动确认)

在 src/uni_modules/wot-design-uni/components/ 运行搜索(排除 wd-rate)未返回其它使用 TouchEvent 或 event.touches[0].clientX 的匹配,无法仅靠代码搜索自动确认兼容性。
在目标平台(微信小程序、支付宝小程序、H5)验证 wd-rate 中 onTouchMove 使用 event.touches[0].clientX 的行为;或改为更稳健的实现:先校验 event.touches && event.touches.length>0;或使用 changedTouches;或在无法获取坐标时避免变更评分。
位置: src/uni_modules/wot-design-uni/components/wd-rate/wd-rate.vue:140-161

- 在 rate 组件的属性中添加 allowZero,用于控制是否允许评分为0
- 修改 onTouchMove 事件处理逻辑,当 allowZero 为 true 时允许评分为0

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

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 (1)
src/uni_modules/wot-design-uni/components/wd-rate/types.ts (1)

95-96: 澄清与 allowZero 的联动规则,避免歧义

allowHalf 默认 false OK,但在本次新增“可为 0 分”能力后,半星与最小值的组合边界需要在属性说明或组件文档中明确(例如最小分应为:allowZero ? 0 : allowHalf ? 0.5 : 1)。否则用户可能误解 0.5 与 0 的优先级关系。

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between f12a95f and e480adb.

📒 Files selected for processing (2)
  • src/uni_modules/wot-design-uni/components/wd-rate/types.ts (1 hunks)
  • src/uni_modules/wot-design-uni/components/wd-rate/wd-rate.vue (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/uni_modules/wot-design-uni/components/wd-rate/wd-rate.vue
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: Test Components (wd-rate)
🔇 Additional comments (1)
src/uni_modules/wot-design-uni/components/wd-rate/types.ts (1)

97-102: 确保 allowZero 仅在开启时影响评分行为

在 wd-rate.vue 的触摸左越界处已看到 props.allowZero 检查(src/uni_modules/wot-design-uni/components/wd-rate/wd-rate.vue 行 ~145–147),但尚未完全验证 index === -1 的其它调用点及是否存在把 0 误当“空”的判空写法。要求:

  • 左侧越界置 0 与 index === -1 的分支必须仅在 props.allowZero === true 时生效;若未受控,在对应分支加判断(示例):
    if (props.allowZero && index === -1) { changeRate(-1, false); return }
  • 避免使用 if (!value)、value || 1 等把合法的 0 视为“未赋值”;改为明确判断(value == null / value === undefined / Number.isFinite 等)。
  • 建议在 allowZero 注释中补充联动规则:最小值为 allowZero ? 0 : (allowHalf ? 0.5 : 1),可按原 diff 更新注释。

@Moonofweisheng
Moonofweisheng merged commit 5b43e6f into Moonofweisheng:master Sep 18, 2025
10 of 11 checks passed
Moonofweisheng added a commit that referenced this pull request Sep 18, 2025

This branch was successfully deployed

1 active deployment
Preview — e480adb6 Deployed Sep 15, 2025 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants