-
Notifications
You must be signed in to change notification settings - Fork 8
Feat: 更新前端代码,移除读写localStorage缓存操作,全部数据均通过api获取最新数据 #99
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -643,18 +643,65 @@ const generateVersionsFromDeployState = (service: any) => { | |
| } | ||
| } | ||
|
|
||
| // 解析告警列表,提取服务告警状态 | ||
| const parseAlertsToServiceStatus = (alertsData: any) => { | ||
| // 优先级:Pending > InProcessing > Restored > AutoRestored | ||
| const priority: Record<string, number> = { | ||
| Pending: 4, | ||
| InProcessing: 3, | ||
| Restored: 2, | ||
| AutoRestored: 1 | ||
| } | ||
|
|
||
| // 服务名映射 | ||
| const prophetToServiceMap: Record<string, string> = { | ||
| s3apiv2: 's3' | ||
| } | ||
|
|
||
| const latestStateByService = new Map<string, { state: string; ts: number; prio: number }>() | ||
|
|
||
| for (const issue of alertsData) { | ||
| // 解析服务名:优先 labels.service,其次 prophet_service 的映射 | ||
| const serviceLabel = issue.labels.find((l: any) => l.key === 'service')?.value | ||
| const prophetService = issue.labels.find((l: any) => l.key === 'prophet_service')?.value | ||
| const mapped = prophetService ? prophetToServiceMap[prophetService] : undefined | ||
| const serviceName = serviceLabel || mapped | ||
| if (!serviceName) continue | ||
|
|
||
| const ts = new Date(issue.alertSince).getTime() | ||
| const prio = priority[issue.alertState] || 0 | ||
| const existing = latestStateByService.get(serviceName) | ||
| if (!existing || prio > existing.prio || (prio === existing.prio && ts > existing.ts)) { | ||
| latestStateByService.set(serviceName, { state: issue.alertState, ts, prio }) | ||
| } | ||
| } | ||
|
|
||
| // 更新到全局状态映射 | ||
| latestStateByService.forEach((val, service) => { | ||
| updateServiceAlertStatus(service, val.state) | ||
| }) | ||
| } | ||
|
Comment on lines
+647
to
+683
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 新添加的
建议进行如下修改,同时解决这两个问题。请注意,你需要在文件顶部导入 |
||
|
|
||
| // API调用函数 | ||
| const loadServicesData = async () => { | ||
| loading.value = true | ||
| error.value = null | ||
|
|
||
| try { | ||
| // 加载服务数据 - 调用真实后端API | ||
| const response = await apiService.getServices() | ||
| const servicesResponse = response.data | ||
| // 并行加载服务数据和告警数据 | ||
| const [servicesRes, openAlertsRes, closedAlertsRes] = await Promise.all([ | ||
| apiService.getServices(), | ||
| apiService.getAlerts(undefined, 100, 'Open'), | ||
| apiService.getAlerts(undefined, 100, 'Closed') | ||
| ]) | ||
|
|
||
| const servicesResponse = servicesRes.data | ||
| servicesData.value = servicesResponse | ||
|
|
||
| // 解析告警状态并更新到内存 | ||
| const allAlerts = [...openAlertsRes.data.items, ...closedAlertsRes.data.items] | ||
| parseAlertsToServiceStatus(allAlerts) | ||
|
|
||
| // 转换数据 | ||
| try { | ||
| const { nodes: transformedNodes, edges: transformedEdges } = transformServiceData(servicesResponse) | ||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这个PR移除了
localStorage的使用,非常好。但目前只是将相关函数 (saveDataToStorage,loadDataFromStorage,saveServiceAlertStatus,loadServiceAlertStatus等) 的函数体清空,而函数本身和对它们的调用仍然保留在代码中。为了使代码更整洁、更易于维护,建议将这些已无实际作用的函数以及所有对它们的调用完全移除。例如,
saveDataToStorage函数的调用在removeVersionFromAvailable和addVersionToAvailable等函数中仍然存在。如果未来可能需要恢复这些功能,通过 Git 历史记录来找回会是更好的选择。