Skip to content

Conversation

@discreted66
Copy link
Collaborator

@discreted66 discreted66 commented Oct 23, 2025

PR

PR Checklist

fix:修复文件上传大小限制失效,以及vue2时间面板示例

Please check if your PR fulfills the following requirements:

  • The commit message follows our Commit Message Guidelines
  • Tests for the changes have been added (for bug fixes / features)
  • Docs have been added / updated (for bug fixes / features)

PR Type

What kind of change does this PR introduce?

  • Bugfix
  • Feature
  • Code style update (formatting, local variables)
  • Refactoring (no functional changes, no api changes)
  • Build related changes
  • CI related changes
  • Documentation content changes
  • Other... Please describe:

What is the current behavior?

Issue Number: N/A

What is the new behavior?

Does this PR introduce a breaking change?

  • Yes
  • No

Other information

Summary by CodeRabbit

  • Refactor

    • Updated example components to use consistent Vue component structure patterns for improved maintainability.
  • Bug Fixes

    • Corrected file upload size validation logic to properly process numeric file size parameters, ensuring accurate and consistent file size limit enforcement across different configuration scenarios.

@github-actions github-actions bot added the bug Something isn't working label Oct 23, 2025
@coderabbitai
Copy link

coderabbitai bot commented Oct 23, 2025

Walkthrough

Eight Vue demo components refactored from Composition API <script setup> syntax to traditional Options API with explicit export default objects containing component declarations, data properties, and methods. File upload module enhanced with numeric type conversions to ensure type safety in file size calculations.

Changes

Cohort / File(s) Summary
Date Panel Demo Refactoring
examples/sites/demos/pc/app/date-panel/basic-usage.vue, custom-weeks.vue, disabled-date.vue, event.vue, format.vue, readonly.vue, shortcuts.vue, unlink-panels.vue
Converted from Composition API with <script setup> to Options API pattern. Replaced top-level ref declarations with data() return objects. Moved standalone functions into methods blocks. Added explicit components option registering TinyDatePanel, TinyDateRange, TinyMonthRange, TinyYearRange. Preserved template bindings and reactive behavior without functional changes.
File Upload Type Safety
packages/renderless/src/file-upload/index.ts
Enhanced ProperFileSize logic with explicit Number() conversions for all arithmetic operations on file size values. Added conditional logic for EDM mode handling and array-based file size calculations. Improved type consistency in numeric computations for single file max size and overall max size calculations.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

The changes follow consistent, repetitive refactoring patterns across multiple files (Vue Options API conversion) with straightforward type safety enhancements. Low logic density and homogeneous transformation patterns reduce cognitive load.

Poem

🐰 From setup to options, we hopped along,
Converting refs to data, righting the song,
Numbers now typed in the upload file,
Type safety grows with each composable mile!
Scripts that once danced now elegantly stand—
Options API reigns across this demo land! ✨

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 The PR title "fix(file-upload): fix file upload size limit and the vue2 date-panel example" is clearly and specifically related to the main changes in the changeset. The title accurately references the two primary areas of modification: the file upload size limit fix in the renderless/src/file-upload/index.ts file (with explicit numeric type conversions for file size calculations) and the Vue 2 date-panel example corrections across multiple demo files (converting them from Vue 3 script setup to Options API patterns). The title is concise, uses a meaningful scope prefix (fix), and provides enough information for someone scanning the commit history to understand the primary purpose of the changes without being vague or overly generic.
Docstring Coverage ✅ Passed No functions found in the changes. Docstring coverage check skipped.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 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.

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: 2

🧹 Nitpick comments (2)
packages/renderless/src/file-upload/index.ts (1)

402-402: Redundant Math.min with single argument.

Calling Math.min(state.singleMaxSize) with a single argument simply returns that argument. This is functionally correct but unnecessarily verbose.

Simplify by removing the redundant function call:

-      maxSize = state.isEdm ? Math.min(state.singleMaxSize) : Number(props.fileSize) / 1024
+      maxSize = state.isEdm ? state.singleMaxSize : Number(props.fileSize) / 1024
examples/sites/demos/pc/app/date-panel/custom-weeks.vue (1)

33-33: Remove unused eachWeekFirstDay property.

The eachWeekFirstDay property is assigned in the formatWeeks method (line 38) but never referenced in the template. Unlike the similar component in date-picker/custom-weeks.vue which displays this value, the date-panel variant does not use it. Remove the property declaration and assignment to keep the component clean.

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between c8cfea3 and 9244d4e.

📒 Files selected for processing (9)
  • examples/sites/demos/pc/app/date-panel/basic-usage.vue (1 hunks)
  • examples/sites/demos/pc/app/date-panel/custom-weeks.vue (1 hunks)
  • examples/sites/demos/pc/app/date-panel/disabled-date.vue (1 hunks)
  • examples/sites/demos/pc/app/date-panel/event.vue (1 hunks)
  • examples/sites/demos/pc/app/date-panel/format.vue (1 hunks)
  • examples/sites/demos/pc/app/date-panel/readonly.vue (1 hunks)
  • examples/sites/demos/pc/app/date-panel/shortcuts.vue (1 hunks)
  • examples/sites/demos/pc/app/date-panel/unlink-panels.vue (1 hunks)
  • packages/renderless/src/file-upload/index.ts (1 hunks)
🔇 Additional comments (9)
packages/renderless/src/file-upload/index.ts (1)

399-400: Good type safety improvements with Number() conversions.

The explicit Number() conversions ensure that arithmetic operations work correctly regardless of the input type. This properly addresses the file size limit enforcement issue mentioned in the PR.

examples/sites/demos/pc/app/date-panel/custom-weeks.vue (1)

36-41: LGTM: Method conversion is correct.

The formatWeeks function has been properly converted from a standalone function to a component method, with correct use of this for accessing component properties.

examples/sites/demos/pc/app/date-panel/unlink-panels.vue (1)

21-37: LGTM: Clean Options API conversion.

The refactoring correctly moves reactive state to data() and explicitly registers components. All data properties are properly used in the template.

examples/sites/demos/pc/app/date-panel/basic-usage.vue (1)

18-38: LGTM: Options API conversion is structurally correct.

The refactoring properly moves all reactive state to data() and registers components explicitly.

However, note that line 6 of the template uses v-model="value" for a month-type panel, while the month data property exists but isn't bound to that panel. This appears to be a pre-existing issue not addressed in this PR.

examples/sites/demos/pc/app/date-panel/readonly.vue (1)

18-38: LGTM: Clean Options API conversion.

The refactoring correctly moves reactive state to data() and explicitly registers all components. All data properties are properly used in the template.

examples/sites/demos/pc/app/date-panel/disabled-date.vue (1)

38-48: LGTM: Methods correctly converted.

The disabled date methods have been properly moved from standalone functions to component methods. The logic is preserved from the original implementation.

examples/sites/demos/pc/app/date-panel/event.vue (1)

38-57: LGTM: Event handlers correctly converted.

All event handler methods have been properly moved to the component's methods section. The modal message logic is preserved correctly.

examples/sites/demos/pc/app/date-panel/format.vue (1)

12-28: LGTM: Clean Options API conversion.

The refactoring correctly moves reactive state to data() and explicitly registers components. The date format in the data matches the format specified in the template.

examples/sites/demos/pc/app/date-panel/shortcuts.vue (1)

21-203: LGTM: Large shortcuts conversion handled correctly.

The extensive shortcuts arrays have been properly moved from standalone constants into the component's data() return object. The overall structure and date manipulation logic is preserved.

Comment on lines +174 to +181
text: '本年',
onClick(picker) {
const date = new Date()
const tmp = new Date(date.getFullYear(), 0, 2)
const start = new Date(date.getFullYear(), 0, 2)
const end = new Date(tmp.getTime() - 1)
picker.$emit('pick', [start, end])
}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🔴 Critical

🧩 Analysis chain

Verify date range logic for "本年" (this year) shortcut.

The logic appears to create a backwards date range:

  • start is set to January 2 of the current year (line 177)
  • end is calculated as 1ms before January 2, which is effectively January 1 (line 179)

This results in start > end, which is likely incorrect for a year range shortcut. Typically, "本年" should span from January 1 to December 31 of the current year, or from January 1 to today.

Consider this fix:

 {
   text: '本年',
   onClick(picker) {
     const date = new Date()
-    const tmp = new Date(date.getFullYear(), 0, 2)
-    const start = new Date(date.getFullYear(), 0, 2)
-    const end = new Date(tmp.getTime() - 1)
+    const start = new Date(date.getFullYear(), 0, 1)
+    const end = new Date(date.getFullYear(), 11, 31)
     picker.$emit('pick', [start, end])
   }
 }

I'll verify the date range logic issue by examining the actual file and checking similar patterns in the codebase.


---

🏁 Script executed:

```shell
#!/bin/bash
# 1. Display the relevant section of the file
echo "=== Checking lines 174-181 in shortcuts.vue ==="
sed -n '170,185p' examples/sites/demos/pc/app/date-panel/shortcuts.vue

# 2. Look for other year/date shortcuts to understand the pattern
echo -e "\n=== Looking for similar date patterns in the file ==="
grep -n "getFullYear\|0, 1\|11, 31\|12, 31" examples/sites/demos/pc/app/date-panel/shortcuts.vue | head -20

# 3. Check if there's a "上年" or similar pattern we can compare against
echo -e "\n=== Searching for all shortcuts with similar structure ==="
sed -n '1,200p' examples/sites/demos/pc/app/date-panel/shortcuts.vue | grep -A 5 "text:"

Length of output: 5237


Fix backwards date range in "本年" (this year) shortcut.

The issue is confirmed. The code creates an invalid date range where start (January 2) is after end (January 1):

  • Line 177: tmp is set to January 2
  • Line 178: start is set to January 2 (same as tmp)
  • Line 179: end is 1ms before January 2, which is effectively January 1

This backwards range is inconsistent with the "本月" (this month) pattern in the same file (lines 147-148), which correctly creates a valid range by calculating the next period and subtracting 1ms.

For "本年", this should span the full calendar year (January 1 to December 31):

 {
   text: '本年',
   onClick(picker) {
     const date = new Date()
-    const tmp = new Date(date.getFullYear(), 0, 2)
-    const start = new Date(date.getFullYear(), 0, 2)
-    const end = new Date(tmp.getTime() - 1)
+    const start = new Date(date.getFullYear(), 0, 1)
+    const end = new Date(date.getFullYear(), 11, 31)
     picker.$emit('pick', [start, end])
   }
 }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
text: '本年',
onClick(picker) {
const date = new Date()
const tmp = new Date(date.getFullYear(), 0, 2)
const start = new Date(date.getFullYear(), 0, 2)
const end = new Date(tmp.getTime() - 1)
picker.$emit('pick', [start, end])
}
text: '本年',
onClick(picker) {
const date = new Date()
const start = new Date(date.getFullYear(), 0, 1)
const end = new Date(date.getFullYear(), 11, 31)
picker.$emit('pick', [start, end])
}
🤖 Prompt for AI Agents
In examples/sites/demos/pc/app/date-panel/shortcuts.vue around lines 174 to 181,
the "本年" shortcut builds a backwards range by setting both tmp and start to
January 2 and end to 1ms before that; change it so start is the first
millisecond of Jan 1 of the current year and end is the last millisecond of Dec
31 of the current year (e.g. set start = new Date(year, 0, 1) and end = new
Date(year + 1, 0, 1).getTime() - 1) so the picker receives [start, end] as a
proper full-calendar-year range.

let maxSize = 0

state.singleMaxSize = props.edm.singleFileMaxSize || state.singleMaxSize || 200
if (Array.isArray(props.fileSize) && props.fileSize[1]) {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

Edge case: fileSize[1] check fails when value is 0.

The condition props.fileSize[1] evaluates to false when the value is 0, which might be a valid max file size. This could cause the logic to incorrectly fall through to the else branch.

Consider using an explicit check for undefined or null:

-    if (Array.isArray(props.fileSize) && props.fileSize[1]) {
+    if (Array.isArray(props.fileSize) && props.fileSize[1] !== undefined) {
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
if (Array.isArray(props.fileSize) && props.fileSize[1]) {
if (Array.isArray(props.fileSize) && props.fileSize[1] !== undefined) {
🤖 Prompt for AI Agents
In packages/renderless/src/file-upload/index.ts around line 397, the condition
`Array.isArray(props.fileSize) && props.fileSize[1]` incorrectly treats a valid
max size of 0 as falsy; change the check to explicitly test for undefined/null
(e.g., `Array.isArray(props.fileSize) && props.fileSize[1] != null` or `!==
undefined`) so that 0 is accepted as a valid value and the correct branch
executes.

@zzcr zzcr merged commit bb72f19 into opentiny:dev Oct 27, 2025
11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants