Repository navigation
feat(rate): 支持清空评分,评分支持滑动为0 - #1302
Conversation
- 在 changeRate 函数中增加判断,当 index 为 -1 时设置 value 为 0 - 在 onTouchMove 函数中,当 clientX 小于第一个评分项的 left 时,调用 changeRate(-1, false)
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
✅ Deploy Preview for wot-design-uni ready!Built without sensitive environment variables
To edit notification comments on pull requests, go to your Netlify project configuration. |
Walkthrough在 wd-rate 组件中新增 allowZero 属性;调整触摸滑动与评分更新逻辑:为 changeRate 新增 index === -1 时强制置 0;onTouchMove 增加 readonly/disabled 早退;补充左侧越界时调用 changeRate(-1, false) 的边界处理。对外 API 增加了布尔属性 Changes
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`
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
Poem
Pre-merge checks and finishing touches✅ Passed checks (3 passed)
✨ Finishing touches
🧪 Generate unit tests
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. Comment |
There was a problem hiding this comment.
Actionable comments posted: 0
🧹 Nitpick comments (1)
src/uni_modules/wot-design-uni/components/wd-rate/wd-rate.vue (1)
131-138: 建议为清空评分功能补充单元测试虽然当前实现的清空评分功能逻辑正确,但考虑到这是新增的核心功能,建议补充相应的测试用例来确保:
changeRate(-1, false)能正确设置 value 为 0- 边界触摸事件能正确触发清空评分
- 在
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
📒 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
There was a problem hiding this comment.
Actionable comments posted: 0
🧹 Nitpick comments (1)
src/uni_modules/wot-design-uni/components/wd-rate/types.ts (1)
95-96: 澄清与 allowZero 的联动规则,避免歧义
allowHalf默认falseOK,但在本次新增“可为 0 分”能力后,半星与最小值的组合边界需要在属性说明或组件文档中明确(例如最小分应为:allowZero ? 0 : allowHalf ? 0.5 : 1)。否则用户可能误解 0.5 与 0 的优先级关系。
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 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 更新注释。
🤔 这个 PR 的性质是?(至少选择一个)
🔗 相关 Issue
#1293
💡 需求背景和解决方案
取消评分的情况
☑️ 请求合并前的自查清单
Summary by CodeRabbit
New Features
Bug Fixes