Skip to content

feat: ✨ ImgCropper 图片剪裁支持设置裁剪框宽高比#973

Merged
Moonofweisheng merged 1 commit into
masterfrom
feature/ImgCropper/aspectRatio
Mar 25, 2025
Merged

feat: ✨ ImgCropper 图片剪裁支持设置裁剪框宽高比#973
Moonofweisheng merged 1 commit into
masterfrom
feature/ImgCropper/aspectRatio

Conversation

@Moonofweisheng

@Moonofweisheng Moonofweisheng commented Mar 25, 2025

Copy link
Copy Markdown
Owner

Closes: #920

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

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

🔗 相关 Issue

#920

💡 需求背景和解决方案

添加aspect-ratio属性支持设置裁剪框宽高比

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

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

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

Summary by CodeRabbit

  • 新功能

    • 新增图片裁剪比例设置,支持用户以如 1:1、3:2、16:9 等预设或自定义比例精准裁剪图片。
    • 引入裁剪后自动上传功能,简化流程并提供上传进度反馈。
  • 文档

    • 更新了使用示例和说明,帮助用户快速上手新功能。

@vercel

vercel Bot commented Mar 25, 2025

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
wot-design-uni ✅ Ready (Inspect) Visit Preview 💬 Add feedback Mar 25, 2025 3:17pm

@coderabbitai

coderabbitai Bot commented Mar 25, 2025

Copy link
Copy Markdown

Walkthrough

此次更新为 wd-img-cropper 组件添加了 aspect-ratio 属性,允许用户指定裁剪框的宽高比(格式为 "宽:高",默认 "1:1")。文档中更新了属性说明及示例,展示了如何使用自定义裁剪比例(例如 "3:2")以及裁剪后自动上传的功能。页面组件新增了对应的响应式变量和处理函数(如 uploadCustomhandleCustomConfirmhandleConfirmUpload),并调整了样式布局。同时,组件类型定义及内部裁剪逻辑也做了相应改进,以依据传入的宽高比计算裁剪区域和图片缩放。

Changes

文件路径 变更说明
docs/component/…/img-cropper.md 新增 aspect-ratio 属性说明、基本用法示例及自动上传的说明。
src/pages/imgCropper/Index.vue 增加自定义裁剪比例和裁剪后上传功能,新增响应式状态与方法(如 uploadCustomhandleCustomConfirmhandleConfirmUpload),同时调整页面布局样式。
src/uni_modules/…/wd-img-cropper/(types.ts, wd-img-cropper.vue) 在类型定义中新增 aspectRatio 属性(默认值 '1:1'),并更新裁剪区域尺寸、图像缩放和旋转计算逻辑,以支持自定义宽高比。

Sequence Diagram(s)

sequenceDiagram
    participant U as 用户
    participant C as ImgCropper组件
    participant H as 裁剪处理函数
    participant Upl as useUpload
    participant S as 服务器

    U->>C: 选择自定义裁剪比例
    C->>U: 显示裁剪区域
    U->>C: 执行裁剪并确认
    C->>H: 触发 handleConfirmUpload/handleCustomConfirm
    H->>Upl: 调用 useUpload 上传图片
    Upl->>S: 发送图片数据
    S-->>Upl: 返回上传结果
    Upl-->>H: 返回处理反馈
    H->>C: 更新界面状态
Loading

Assessment against linked issues

Objective Addressed Explanation
支持自定义裁剪宽高比(例如 3:2) (#920)

Possibly related PRs

Poem

我是一只快乐的小兔 🐰
跳跃间带来新功能的鼓舞,
裁剪比例随心所欲,
代码中洒下智慧的种子,
上传成功,喜悦满怀,
欢迎体验这份精致改变!
轻轻跃动,梦想启程!

✨ Finishing Touches
  • 📝 Generate Docstrings

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
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai plan to trigger planning for file edits and PR creation.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@netlify

netlify Bot commented Mar 25, 2025

Copy link
Copy Markdown

Deploy Preview for wot-design-uni ready!

Name Link
🔨 Latest commit 5264591
🔍 Latest deploy log https://app.netlify.com/sites/wot-design-uni/deploys/67e2c8eecc815e0008bd9562
😎 Deploy Preview https://deploy-preview-973--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 site configuration.

@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 (2)
docs/component/img-cropper.md (1)

98-111: 重复的"基本用法"标题

文档中出现了两个相同的"基本用法"标题(第5行和第99行),这可能会导致目录混乱。建议将第二个标题修改为更具体的描述,例如"设置自定义裁剪比例"。

-## 基本用法
+## 设置自定义裁剪比例
🧰 Tools
🪛 markdownlint-cli2 (0.17.2)

99-99: Multiple headings with the same content
null

(MD024, no-duplicate-heading)

src/pages/imgCropper/Index.vue (1)

147-180: 硬编码的 API URL 应考虑配置化

上传函数中硬编码了 API URL (https://mockapi.eolink.com/zhTuw2P8c29bc981a741931bdd86eb04dc1e8fd64865cb5/upload)。建议将此 URL 提取为配置变量或环境变量,以便更容易地在不同环境中切换。

-      action: 'https://mockapi.eolink.com/zhTuw2P8c29bc981a741931bdd86eb04dc1e8fd64865cb5/upload', // 替换为实际的上传地址
+      action: import.meta.env.VITE_UPLOAD_API_URL || 'https://mockapi.eolink.com/zhTuw2P8c29bc981a741931bdd86eb04dc1e8fd64865cb5/upload', // 替换为实际的上传地址

在项目根目录的环境配置文件中添加:

VITE_UPLOAD_API_URL=https://your-production-upload-url
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between b852376 and 5264591.

📒 Files selected for processing (4)
  • docs/component/img-cropper.md (2 hunks)
  • src/pages/imgCropper/Index.vue (4 hunks)
  • src/uni_modules/wot-design-uni/components/wd-img-cropper/types.ts (2 hunks)
  • src/uni_modules/wot-design-uni/components/wd-img-cropper/wd-img-cropper.vue (4 hunks)
🧰 Additional context used
🪛 markdownlint-cli2 (0.17.2)
docs/component/img-cropper.md

99-99: Multiple headings with the same content
null

(MD024, no-duplicate-heading)

⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: Cloudflare Pages
🔇 Additional comments (10)
src/uni_modules/wot-design-uni/components/wd-img-cropper/types.ts (1)

60-64: 属性定义清晰,文档完整

新增的 aspectRatio 属性定义良好,包含了清晰的类型说明和默认值。注释也很完整,明确指出了裁剪框宽高比的格式要求为 width:height。

docs/component/img-cropper.md (2)

73-73: 属性表格添加完整

aspect-ratio 属性已正确添加到属性表格中,清晰地说明了其类型、默认值及格式要求。

不过请注意 $LOWEST_VERSION$ 应该替换为实际的最低支持版本号。


113-180: 上传示例代码实现完整

裁剪后上传的示例代码实现完整,包括了错误处理和进度跟踪,对用户理解如何集成上传功能很有帮助。代码结构清晰,注释充分。

src/uni_modules/wot-design-uni/components/wd-img-cropper/wd-img-cropper.vue (3)

166-174: 裁剪框尺寸计算逻辑优化

裁剪框尺寸计算逻辑已优化,使用宽高比正确计算裁剪区域的宽高。代码清晰地从 aspectRatio 属性中解析比例并应用到尺寸计算中。


278-295: 旋转后的缩放比例计算逻辑优化

旋转后的缩放比例计算逻辑已优化,考虑了不同宽高比下的旋转情况。通过交换宽高并重新计算缩放比例,确保图片在任何角度下都能正确填充裁剪框。


332-369: 图片尺寸计算逻辑优化

图片尺寸计算逻辑已优化,考虑了图片与裁剪框的比例关系,确保至少有一边等于裁剪框尺寸。代码中添加了详细的注释说明不同情况下的处理逻辑。

src/pages/imgCropper/Index.vue (4)

33-58: 自定义裁剪比例示例实现完整

自定义裁剪比例的示例实现完整,展示了不同比例(1:1, 3:2, 16:9)的裁剪效果。UI 结构良好,使用了栅格布局展示不同比例的裁剪效果。


60-78: 裁剪后上传示例实现良好

裁剪后上传的示例实现良好,UI 结构清晰,与文档中的示例代码一致。


198-202: 高度计算函数实现合理

getHeight 函数实现合理,根据不同的宽高比计算出适当的高度值,保持 UI 显示的一致性。


242-274: 样式结构清晰,适应不同比例

新增的样式结构清晰,针对不同的裁剪比例提供了适当的样式调整。使用 flex 布局和 gap 属性使界面排版整洁。

@Moonofweisheng Moonofweisheng merged commit 5a3f85d into master Mar 25, 2025
@Moonofweisheng Moonofweisheng deleted the feature/ImgCropper/aspectRatio branch March 25, 2025 15:41
@Wong-Harry

Copy link
Copy Markdown

请问什么时候发布到npm上

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.

[新功能需求] ImgCropper设置图片裁剪比例

2 participants