Skip to content

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

Open
NeverGiveUp1995 wants to merge 2 commits intoMoonofweisheng:masterfrom
NeverGiveUp1995:master
Open

fix(picker): 修复第一次modalValue值为空,打开面板后直接点击确认按钮,beforeConfirm回调中value参数为空的问题#1456
NeverGiveUp1995 wants to merge 2 commits intoMoonofweisheng:masterfrom
NeverGiveUp1995:master

Conversation

@NeverGiveUp1995
Copy link

@NeverGiveUp1995 NeverGiveUp1995 commented Jan 30, 2026

…为空串的问题

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

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

🔗 相关 Issue

💡 需求背景和解决方案

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

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

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

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

Summary by CodeRabbit

Bug修复

  • 改进选择器确认逻辑,确保在使用确认前钩子时,能正确获取并传递当前的选择值,修复了初始值未定义场景下的状态同步问题

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

NeverGiveUp1995 and others added 2 commits January 14, 2026 11:41
…onfirm

fix(picker): 修复第一次modalValue值为空,打开面板后直接点击确认按钮,beforeConfirm回调中value参数为空的问题
@vercel
Copy link

vercel bot commented Jan 30, 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 30, 2026

Deploy Preview for wot-design-uni ready!

Built without sensitive environment variables

Name Link
🔨 Latest commit 556ea7c
🔍 Latest deploy log https://app.netlify.com/projects/wot-design-uni/deploys/697c102920ff2f00084b111e
😎 Deploy Preview https://deploy-preview-1456--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 30, 2026

概览

修改了 wd-picker 组件的 onConfirm 方法,当存在 beforeConfirm 钩子时,改为通过调用 pickerViewWd.value!.getValues() 从选择器视图获取当前值,而不是使用 pickerValue.value,以确保传递给钩子的是最新的选择器状态。

变更内容

群组 / 文件 摘要
选择器确认逻辑
src/uni_modules/wot-design-uni/components/wd-picker/wd-picker.vue
onConfirm 方法中,调整了从选择器视图获取值的方式,改为直接调用 getValues() 方法获取实时值,而非依赖 pickerValue.value,以处理初始 modelValue 为 undefined 的场景。

关联的拉取请求

建议的审查者

  • Moonofweisheng

代码审查工作量评估

🎯 2 (Simple) | ⏱️ ~10 minutes

诗歌

🐰 小小改动显巧思,
确认时刻要新鲜,
getValues 来取最真,
状态准确无烦恼~

🚥 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组件在initialValue为空时直接确认会导致beforeConfirm回调参数为空的问题,与变更内容完全相符。
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.

✨ Finishing touches
🧪 Generate unit tests (beta)
  • 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.

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