Skip to content

feat: 添加fetchAnnotationData函数以获取注释数据#347

Merged
YufJi merged 3 commits into
testfrom
fix/fetchAnnotionData
Mar 20, 2026
Merged

feat: 添加fetchAnnotationData函数以获取注释数据#347
YufJi merged 3 commits into
testfrom
fix/fetchAnnotionData

Conversation

@YufJi
Copy link
Copy Markdown
Collaborator

@YufJi YufJi commented Mar 20, 2026

Summary by CodeRabbit

发布说明

  • 新功能
    • 应用启动时自动加载数据权限注解数据,优化权限管理流程。支持跨多个框架场景的权限数据初始化,包含错误处理和缓存机制。

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Mar 20, 2026

Warning

Rate limit exceeded

@YufJi has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 20 minutes and 48 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 724b9ba5-2726-4af2-96af-39dd66a744ef

📥 Commits

Reviewing files that changed from the base of the PR and between 29a409b and 5395ee7.

📒 Files selected for processing (1)
  • packages/vue2/src/data-permission.js

概览

此 PR 在多个应用入口文件中添加了数据权限注解数据的初始化逻辑。新增 data-permission 模块负责在应用启动时从指定 API 端点获取权限注解数据,并将其缓存至全局对象供应用使用。

变更

Cohort / File(s) 摘要
数据权限模块
packages/vue2/src/data-permission.js
新增模块导出 fetchAnnotationData 函数。该函数从配置中读取权限开关和系统路径前缀,在权限禁用或数据已缓存时提前返回。否则并行调用两个 API 端点(/api/system/annotation/entityAll/api/system/annotation/logicAll),处理响应数据并存储至 window.annotationAllData。异常情况下记录日志。
应用入口初始化
packages/vue2/src/main.js, packages/vue2/source/icestark/main.js, packages/vue2/source/qiankun/main.js, packages/vue2/source/wujie/main.js
各入口文件在模块初始化阶段导入并调用 fetchAnnotationData(),在 i18n 配置设置之前执行,用于提前加载权限注解数据。

序列图

sequenceDiagram
    participant App as 应用启动
    participant FetchFunc as fetchAnnotationData()
    participant Config as platform.config.json
    participant API as API 服务
    participant Window as window.annotationAllData

    App->>FetchFunc: 模块初始化调用
    FetchFunc->>Config: 读取 enableDataPermission<br/>和 sysPrefixPath
    
    alt 权限禁用或数据已存在
        FetchFunc->>FetchFunc: 提前返回
    else 需要获取数据
        FetchFunc->>API: 并行请求 entityAll 和 logicAll
        API-->>FetchFunc: 返回 JSON 响应
        FetchFunc->>FetchFunc: 解析并归一化数据<br/>(response.Data 处理)
        FetchFunc->>Window: 存储结果到<br/>window.annotationAllData
    end
    
    FetchFunc-->>App: 初始化完成
    Note over App,Window: 应用继续启动流程
Loading

预估代码审查工作量

🎯 3 (Moderate) | ⏱️ ~20 分钟

可能关联的 PR

  • lcap-template#175:实现相同的数据权限注解初始化逻辑,涉及 entityAll 和 logicAll 数据的获取和集成。

诗歌

🐰 启动时刻,小兔来奔跑,
权限注解数据先要找,
并行取数,快如闪电,
缓存全局,路径已标,
各个入口都准备好!✨

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed 标题准确反映了拉取请求的主要变更,即添加fetchAnnotationData函数以获取注释数据。

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

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/fetchAnnotionData
📝 Coding Plan
  • Generate coding plan for human review comments

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
Copy Markdown
Contributor

@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: 1

🧹 Nitpick comments (1)
packages/vue2/src/data-permission.js (1)

14-17: 缺少 HTTP 响应状态检查。

当服务器返回 4xx/5xx 错误时,response.json() 仍会尝试解析响应体,可能将错误信息错误地存入 window.annotationAllData

♻️ 建议添加响应状态检查
   const [entityAll, logicAll] = await Promise.all([
-    fetch(urlEntity).then((response) => response.json()),
-    fetch(urlLogic).then((response) => response.json()),
+    fetch(urlEntity).then((response) => {
+      if (!response.ok) throw new Error(`HTTP ${response.status}`);
+      return response.json();
+    }),
+    fetch(urlLogic).then((response) => {
+      if (!response.ok) throw new Error(`HTTP ${response.status}`);
+      return response.json();
+    }),
   ]);
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@packages/vue2/src/data-permission.js` around lines 14 - 17, The current
Promise.all that sets const [entityAll, logicAll] = await Promise.all([
fetch(urlEntity).then((response) => response.json()),
fetch(urlLogic).then((response) => response.json()), ]) lacks HTTP status
checks; update the fetch handlers for fetch(urlEntity) and fetch(urlLogic) to
verify response.ok (or check response.status) and throw or return a handled
error when not ok before calling response.json(), so that invalid 4xx/5xx
responses are not parsed into entityAll/logicAll (and thus not written into
window.annotationAllData); ensure the thrown error is caught where the
Promise.all is awaited or let the caller handle it.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@packages/vue2/src/data-permission.js`:
- Around line 10-11: The constructed URLs urlEntity and urlLogic use
sysPrefixPath which can be undefined; ensure sysPrefixPath defaults to an empty
string before building those URLs (e.g., set sysPrefixPath to
(platformConfig?.sysPrefixPath) ?? '' or equivalent) so urlEntity and urlLogic
become correct when platformConfig.sysPrefixPath is missing; update the code
around the sysPrefixPath variable assignment (used to build urlEntity and
urlLogic) to apply this default.

---

Nitpick comments:
In `@packages/vue2/src/data-permission.js`:
- Around line 14-17: The current Promise.all that sets const [entityAll,
logicAll] = await Promise.all([ fetch(urlEntity).then((response) =>
response.json()), fetch(urlLogic).then((response) => response.json()), ]) lacks
HTTP status checks; update the fetch handlers for fetch(urlEntity) and
fetch(urlLogic) to verify response.ok (or check response.status) and throw or
return a handled error when not ok before calling response.json(), so that
invalid 4xx/5xx responses are not parsed into entityAll/logicAll (and thus not
written into window.annotationAllData); ensure the thrown error is caught where
the Promise.all is awaited or let the caller handle it.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 19e5029e-b1b2-4dfe-bad7-2ced482300f6

📥 Commits

Reviewing files that changed from the base of the PR and between 5db0490 and 29a409b.

📒 Files selected for processing (5)
  • packages/vue2/source/icestark/main.js
  • packages/vue2/source/qiankun/main.js
  • packages/vue2/source/wujie/main.js
  • packages/vue2/src/data-permission.js
  • packages/vue2/src/main.js

Comment thread packages/vue2/src/data-permission.js
@YufJi YufJi merged commit 713293a into test Mar 20, 2026
2 checks passed
@YufJi YufJi deleted the fix/fetchAnnotionData branch March 20, 2026 08:24
YufJi added a commit that referenced this pull request Mar 20, 2026
Co-authored-by: 御风 <18012261618@126.com>
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