Skip to content

Conversation

@TAYUN
Copy link
Contributor

@TAYUN TAYUN commented Sep 25, 2025

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

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

🔗 相关 Issue

wd-fab组件可拖动记忆。 #1310
Fab 悬浮按钮添加 offset 属性 #811
Fab组件支持自定义初始位置 #660

💡 需求背景和解决方案

需求背景:

  • FAB组件需要支持自定义位置和偏移量,以满足不同场景下的定位需求
  • 修复关闭拖拽功能后,菜单弹出方向未正确更新的bug

解决方案:

  • 新增 custom 定位类型,支持通过 offsetXoffsetY 属性自定义FAB组件的初始位置
  • 修复 watch 监听器,确保 draggable 属性变化时正确更新 fabDirection

API变更:

  • 新增 offsetX: 自定义X轴偏移量(number类型)
  • 新增 offsetY: 自定义Y轴偏移量(number类型)

代码变更:

  • /d:/code-open/wot-design-uni/src/uni_modules/wot-design-uni/components/wd-fab/wd-fab.vue#L169-176: 添加自定义位置初始化逻辑
  • /d:/code-open/wot-design-uni/src/uni_modules/wot-design-uni/components/wd-fab/wd-fab.vue#L93-98: 修复菜单弹出方向更新逻辑

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

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

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

Summary by CodeRabbit

  • 新功能

    • FAB 支持“自定义位置”,可通过 offsetX/offsetY 精确定位,并按屏幕尺寸自动限制偏移范围。
    • 新增本地化文案(en-US/zh-CN):“自定义位置”“偏移量”。
  • 文档/示例

    • FAB 示例页新增自定义位置演示与 X/Y 偏移滑块,支持重渲染即时查看效果。
  • Bug 修复

    • 修复切换可拖拽状态时方向不同步的问题,现与当前方向设置保持一致。

TAYUN and others added 4 commits September 25, 2025 17:30
为悬浮按钮组件添加自定义位置类型(custom)和偏移量属性(offsetX/offsetY),支持通过props设置初始位置和展开方向的偏移量
在Fab组件中新增自定义位置选项,允许用户通过滑块调整X/Y轴偏移量。添加相关中英文翻译字段,并实现重新渲染功能以确保偏移量更改生效。
清理fab组件中未使用的custom-class属性和对应的样式定义,减少冗余代码
将Y偏移量滑块的最大值从固定值100改为动态变量maxOffsetY,提高组件灵活性
@netlify
Copy link

netlify bot commented Sep 25, 2025

Deploy Preview for wot-design-uni ready!

Built without sensitive environment variables

Name Link
🔨 Latest commit b0d9537
🔍 Latest deploy log https://app.netlify.com/projects/wot-design-uni/deploys/68d557403d02bf0008cdb518
😎 Deploy Preview https://deploy-preview-1315--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 Sep 25, 2025

Walkthrough

为 FAB 新增“custom”自定义位置与 X/Y 偏移能力;示例页加入偏移调节与强制重渲染逻辑;组件类型新增 offsetX/offsetY 属性并扩展 FabPosition;组件实现支持自定义位置初始化与边界夹取;中英文文案新增对应键值。

Changes

Cohort / File(s) Summary of changes
本地化文案
src/locale/en-US.json, src/locale/zh-CN.json
新增两条 FAB 相关文案键:fab-zi-ding-yi-wei-zhifab-pian-yi-liang(中英对应“自定义位置/Custom Position”“偏移量/Offset”)。
示例页:FAB 子页
src/subPages/fab/Index.vue
增加 position='custom' 演示;提供 offsetX/offsetY 滑块调节;通过 key 触发 FAB 强制重挂载以应用偏移;获取系统信息以计算最大偏移。
FAB 类型与属性
src/uni_modules/wot-design-uni/components/wd-fab/types.ts
FabPosition 扩展新增 'custom'fabProps 新增数值属性 offsetXoffsetY(默认 0),用于自定义位置与展开时偏移。
FAB 组件实现
src/uni_modules/wot-design-uni/components/wd-fab/wd-fab.vue
initPosition 新增 'custom' 分支,使用 offsetX/offsetY 并做边界夹取;新增对 props.draggable 的侦听以同步方向值。

Sequence Diagram(s)

sequenceDiagram
  autonumber
  actor User as 用户
  participant Demo as FAB示例页(Index.vue)
  participant Fab as 组件:wd-fab

  User->>Demo: 选择 position = "custom"\n调整 offsetX/offsetY
  Demo->>Fab: 渲染 <wd-fab position="custom"\n:offset-x="offsetX" :offset-y="offsetY">
  activate Fab
  Note over Fab: initPosition 读取 offsetX/offsetY\n并进行边界夹取
  Fab-->>Demo: 完成首次渲染
  deactivate Fab

  User->>Demo: 点击“重新渲染”
  Demo->>Demo: 变更 key 触发重挂载
  Demo->>Fab: 以新 key 重建组件\n传入当前 offsetX/offsetY
  activate Fab
  Fab-->>Demo: 以自定义位置完成渲染
  deactivate Fab
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

Suggested reviewers

  • Moonofweisheng
  • MonkeyCode-AI

Poem

小兔挥爪点按钮,
自定方位随心奔。
X 左一寸 Y 上分,
轻改 key,重如新。
风吹偏移不走神,
咔嗒一响落准身。 🐇✨

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 该标题准确概括了对 wd-fab 组件新增自定义位置与偏移量支持的功能,并同时说明了拖拽关闭后菜单方向未更新的修复,内容清晰且与更改内容高度匹配,便于阅读记录和溯源。
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

Tip

👮 Agentic pre-merge checks are now available in preview!

Pro plan users can now enable pre-merge checks in their settings to enforce checklists before merging PRs.

  • Built-in checks – Quickly apply ready-made checks to enforce title conventions, require pull request descriptions that follow templates, validate linked issues for compliance, and more.
  • Custom agentic checks – Define your own rules using CodeRabbit’s advanced agentic capabilities to enforce organization-specific policies and workflows. For example, you can instruct CodeRabbit’s agent to verify that API documentation is updated whenever API schema files are modified in a PR. Note: Upto 5 custom checks are currently allowed during the preview period. Pricing for this feature will be announced in a few weeks.

Please see the documentation for more information.

Example:

reviews:
  pre_merge_checks:
    custom_checks:
      - name: "Undocumented Breaking Changes"
        mode: "warning"
        instructions: |
          Pass/fail criteria: All breaking changes to public APIs, CLI flags, environment variables, configuration keys, database schemas, or HTTP/GraphQL endpoints must be documented in the "Breaking Change" section of the PR description and in CHANGELOG.md. Exclude purely internal or private changes (e.g., code not exported from package entry points or explicitly marked as internal).

Please share your feedback with us on this Discord post.


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.

@vercel
Copy link

vercel bot commented Sep 25, 2025

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 25, 2025 2:54pm

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

93-98: 仅在拖拽关闭时重置弹出方向,避免开启拖拽时被覆盖

当前 watch 在 draggable 任意变更(true/false)时都会重置 fabDirection,可能在“开启拖拽”时无意覆盖 props.direction 或拖拽后逻辑。建议仅在“拖拽被关闭(变为 false)”时同步一次方向。

可按下述方式调整:

-watch(
-  () => props.draggable,
-  () => {
-    fabDirection.value = props.direction
-  }
-)
+watch(
+  () => props.draggable,
+  (newVal, _oldVal) => {
+    if (newVal === false) {
+      fabDirection.value = props.direction
+    }
+  }
+)

169-176: 自定义位置仅初始化生效,未响应 offsetX/offsetY 动态变更

组件在 position='custom' 时仅在初始化/切换 position 时读取 offsetX/offsetY;运行期修改 offset 不会生效(示例页只能通过强制重渲染规避)。建议在 position='custom' 时侦听 offsetX/offsetY 变更并重算位置,消除对强制重渲染的依赖。

可在现有 watch 段后追加监听(插入到 watch 区域,非本片段):

// 当自定义偏移变化时,重新计算位置
watch(
  [() => props.offsetX, () => props.offsetY],
  () => {
    if (props.position === 'custom') {
      initPosition()
    }
  }
)

如需在 gap 变化或窗口尺寸变化时也自适应,可再补充:

watch(
  () => props.gap,
  async () => {
    await getBounding()
    initPosition()
  },
  { deep: true }
)

请确认此行为是否与期望一致(例如:当用户已拖拽过,是否仍应被外部 offset 覆盖)。如需避免覆盖拖拽结果,可在 init 前增加保护条件。

src/subPages/fab/Index.vue (4)

27-39: 示例滑块的最大偏移建议与组件实际边界一致

maxOffsetX/maxOffsetY 直接取窗口宽高,未扣除 gap 与 FAB 尺寸,用户拖到极值后会被组件再次夹取,体验不直观。建议示例页估算更贴近的上限,或在文案提示“实际会受边界夹取”。

可近似处理(示例用,不需精确):默认 gap=16px、默认 FAB≈56px

const approxGap = 16
const approxFab = 56
const maxOffsetX = Math.max(0, sysInfo.windowWidth - approxGap - approxFab - approxGap)
const maxOffsetY = Math.max(0, sysInfo.windowHeight - approxGap - approxFab - approxGap)

72-81: 去除强制重渲染依赖(待组件支持 offset 响应式)

当前通过 :key 与“重新渲染”按钮强制重挂载 FAB 才能应用 offset。若上游组件按建议监听 offsetX/offsetY,则可移除 :key、按钮与 reRenderFab 简化示例。

先移除 :key:

-        :key="fabKey"

随后可删除“重新渲染”按钮与 reRenderFab 相关代码(见下方对应片段)。


123-129: 偏移上限与设备信息初始化 OK;建议监听方向/尺寸变更时重算上限

横竖屏切换或窗口发生变化时,maxOffsetX/Y 不会更新。作为示例可选:监听 onResize 或页面 show 时刷新。


133-135: “重新渲染”仅为示例兜底逻辑,可在组件完善后移除

上游实现 offset 响应式后,可删除该函数与按钮,降低示例复杂度。

对应移除:

-<wd-button @click="reRenderFab">重新渲染</wd-button>
-const fabKey = ref<number>(0)
...
-function reRenderFab() {
-  fabKey.value++
-}
src/uni_modules/wot-design-uni/components/wd-fab/types.ts (1)

63-71: offsetX/offsetY 注释与实现不符,请统一语义

注释称“在展开时作为展开方向偏移量”,但当前实现仅用于 position='custom' 的初始定位,未影响展开菜单位置。请二选一:修正文档或补齐实现。

若选择修正文档(最小改动):

-  /**
-   * 悬浮按钮的x偏移量,在position为custom时作为初始x位置,在展开时作为展开方向的x偏移量
-   */
+  /**
+   * 悬浮按钮的 x 偏移量,仅在 position 为 'custom' 时用于初始位置
+   */
   offsetX: makeNumberProp(0),
-  /**
-   * 悬浮按钮的y轴偏移量,在position为custom时作为初始y位置,在展开时作为展开方向的y偏移量
-   */
+  /**
+   * 悬浮按钮的 y 偏移量,仅在 position 为 'custom' 时用于初始位置
+   */
   offsetY: makeNumberProp(0)

若选择补齐实现:建议在 wd-fab.vue 中为 actions 容器增加偏移样式(按 fabDirection 分别作用于 top/left/transform),以匹配注释语义。

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 1a9c3e8 and b0d9537.

📒 Files selected for processing (5)
  • src/locale/en-US.json (1 hunks)
  • src/locale/zh-CN.json (1 hunks)
  • src/subPages/fab/Index.vue (3 hunks)
  • src/uni_modules/wot-design-uni/components/wd-fab/types.ts (2 hunks)
  • src/uni_modules/wot-design-uni/components/wd-fab/wd-fab.vue (2 hunks)
⏰ 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-fab)
🔇 Additional comments (5)
src/locale/zh-CN.json (1)

427-429: 文案键新增符合预期

新增自定义位置与偏移量文案键与功能对齐,命名清晰,无冲突。

src/locale/en-US.json (1)

427-429: i18n 键新增正确

英文文案与中文键一一对应,满足示例页展示需要。

src/subPages/fab/Index.vue (2)

24-25: 新增 custom 位置选项合理

示例增加 “自定义” 位置入口,契合新特性。


113-116: 类型扩展为含 custom 的联合值 ✅

与组件新增能力一致。

src/uni_modules/wot-design-uni/components/wd-fab/types.ts (1)

6-15: FabPosition 扩展包含 'custom' ✅

类型层面与实现、示例一致,向后兼容良好。

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