Skip to content

fix(picker): 修复第一次modalValue值为空,打开面板后直接点击确认按钮,beforeConfirm回调中value参数…#1443

Open
NeverGiveUp1995 wants to merge 2 commits intoMoonofweisheng:masterfrom
NeverGiveUp1995:fix/add-wd-picker-before-confirm
Open

fix(picker): 修复第一次modalValue值为空,打开面板后直接点击确认按钮,beforeConfirm回调中value参数…#1443
NeverGiveUp1995 wants to merge 2 commits intoMoonofweisheng:masterfrom
NeverGiveUp1995:fix/add-wd-picker-before-confirm

Conversation

@NeverGiveUp1995
Copy link

@NeverGiveUp1995 NeverGiveUp1995 commented Jan 14, 2026

…为空串的问题

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

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

🔗 相关 Issue

💡 需求背景和解决方案

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

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

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

bug复现示例代码

<script setup lang="ts">
import { ref } from 'vue'

const animalList = ref([
  { label: '', value: 'dog' },
  { label: '', value: 'cat' },
  { label: '', value: 'bird' },
])
const selectedAnimal = ref()

const beforeConfirm = (value, resolve) => {
  // 这里取不到值
  console.log('beforeConfirm', value)
  resolve(true)
}

const confirm = ({ value, selectedItem }) => {
  // 这里能取到值
  console.log('confirm', value, selectedItem)
}
</script>

<template>
  <view class="root-container">
    <wd-picker
        :before-confirm="beforeConfirm"
        v-model="selectedAnimal"
        :columns="animalList"
        @confirm="confirm"
    />
  </view>
</template>

<style scoped>
.root-container {
  padding: 5rem 2.5rem;
  text-align: center;
}
</style>

bug示例效果

534490691-d6d8e270-e7b0-46de-9c8a-4cf54bef80c2.mp4

Summary by CodeRabbit

发布说明

  • Bug 修复
    • 修复了选择器确认时的值传递问题,确保用户未修改选项直接确认时仍能正确提交当前值。

✏️ Tip: You can customize this high-level summary in your review settings.

@vercel
Copy link

vercel bot commented Jan 14, 2026

@NeverGiveUp1995 is attempting to deploy a commit to the weisheng's projects Team on Vercel.

A member of the Team first needs to authorize it.

@netlify
Copy link

netlify bot commented Jan 14, 2026

Deploy Preview for wot-design-uni ready!

Built without sensitive environment variables

Name Link
🔨 Latest commit bcb1755
🔍 Latest deploy log https://app.netlify.com/projects/wot-design-uni/deploys/697c0eb7cdef1e000807b683
😎 Deploy Preview https://deploy-preview-1443--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
Copy link

coderabbitai bot commented Jan 14, 2026

概述

在wd-picker组件的onConfirm函数中,当beforeConfirm存在时,现在从pickerViewWd直接获取当前选择器值,而非使用缓存的pickerValue,确保初始modelValue为undefined时仍能提供有效值。

变更详情

文件组 / 文件 变更摘要
选择器确认逻辑
src/uni_modules/wot-design-uni/components/wd-picker/wd-picker.vue
修改onConfirm中beforeConfirm的值源:从pickerValue.value改为pickerViewWd.value!.getValues(),确保获取实时的选择器值

代码审查工作量

🎯 2 (简单) | ⏱️ ~8 分钟

建议审查者

  • Moonofweisheng

兔子之诗

🐰✨ 选择器的值现在更真实,
不再依赖缓存的记忆,
直接从视图中取用当下,
确保confirm时无虚无实,
小小改动,大大智慧!🌟

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed 标题与PR目标高度相关,准确描述了修复的问题:picker组件在初始modelValue为空时,直接点击确认按钮导致beforeConfirm回调的value参数为空的bug。
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.



📜 Recent review details

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 3b6833c and 240493c.

📒 Files selected for processing (1)
  • src/uni_modules/wot-design-uni/components/wd-picker/wd-picker.vue
🧰 Additional context used
🧠 Learnings (2)
📓 Common learnings
Learnt from: Moonofweisheng
Repo: Moonofweisheng/wot-design-uni PR: 761
File: src/uni_modules/wot-design-uni/components/wd-message-box/wd-message-box.vue:166-182
Timestamp: 2024-12-05T15:55:35.371Z
Learning: 在文件 `wd-message-box.vue` 的 `toggleModal` 方法中,当 `isPass` 为 `false` 时,应阻止执行 `confirm`,但不触发 `cancel` 操作。
📚 Learning: 2024-12-05T15:55:35.371Z
Learnt from: Moonofweisheng
Repo: Moonofweisheng/wot-design-uni PR: 761
File: src/uni_modules/wot-design-uni/components/wd-message-box/wd-message-box.vue:166-182
Timestamp: 2024-12-05T15:55:35.371Z
Learning: 在文件 `wd-message-box.vue` 的 `toggleModal` 方法中,当 `isPass` 为 `false` 时,应阻止执行 `confirm`,但不触发 `cancel` 操作。

Applied to files:

  • src/uni_modules/wot-design-uni/components/wd-picker/wd-picker.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). (4)
  • GitHub Check: Test Components (wd-picker)
  • GitHub Check: Redirect rules - wot-design-uni
  • GitHub Check: Header rules - wot-design-uni
  • GitHub Check: Pages changed - wot-design-uni
🔇 Additional comments (1)
src/uni_modules/wot-design-uni/components/wd-picker/wd-picker.vue (1)

326-340: 修复正确,确保 beforeConfirmhandleConfirm 行为一致。

此修改通过直接从 pickerViewWd 获取当前值来解决问题。当 modelValue 初始为空时,pickerValue.value 也会是空值,但 pickerViewWd.value!.getValues() 能够返回 picker view 中实际选中的值(默认为首项)。

这与 handleConfirm(第 348 行)的实现保持一致,两者现在都使用相同的方式获取确认值。

✏️ Tip: You can disable this entire section by setting review_details to false in your review settings.


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.

@NeverGiveUp1995 NeverGiveUp1995 marked this pull request as draft January 14, 2026 03:55
@NeverGiveUp1995 NeverGiveUp1995 marked this pull request as ready for review January 14, 2026 03:55
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.

1 participant