Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 9 additions & 6 deletions ui/src/views/system/identity/workspaces/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,15 @@ function handleWorkspaceDelete(workspace: WorkspaceItem) {
.then(() =>
MsgConfirm(`确认删除${workspace.name}?`, '删除后,该空间下的成员都会被移除,请谨慎操作。').then(() => {
workspaceLoading.value = true
return WorkspaceApi.deleteWorkspace(workspace.id as string).then(() => {
MsgSuccess('删除成功')
if (currentWorkspace.value?.id === workspace.id) {
return loadWorkspaceOptions()
}
})
return WorkspaceApi.deleteWorkspace(workspace.id as string)
.then(() => {
MsgSuccess('删除成功')
// 删除未选中的空间也要刷新列表,并保留当前选中项。
return loadWorkspaceOptions(currentWorkspace.value?.id)
})
.finally(() => {
workspaceLoading.value = false
})
}),
)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Code Review

Improvements in the new version (good):

  1. finally ensures workspaceLoading resets even on error — fixes a potential "stuck spinner" bug in the old code.
  2. Always refreshing the list after deletion, and passing the current workspace ID to preserve selection, is more robust than only refreshing when the deleted item was selected.

Remaining issues / suggestions:

  1. Unhandled errors: If deleteWorkspace or loadWorkspaceOptions rejects, the error propagates with no user feedback. Add .catch:
    return WorkspaceApi.deleteWorkspace(workspace.id)
      .then(...)
      .catch((e) => MsgError(e?.message || '删除失败'))
      .finally(...)
  2. MsgConfirm rejection noise: Clicking "cancel" typically rejects the promise, producing an unhandled rejection. Wrap it:
    MsgConfirm(...).then(...).catch(() => { /* 用户取消 */ })
  3. workspace.id as string cast: Avoidable type assertion (as string) hides possible undefined. Validate first:
    if (!workspace.id) return
  4. Selection loss edge case: If the API supports it, better UX is to have the backend return which workspace was auto-switched to after deletion, instead of guessing client-side. Also confirm loadWorkspaceOptions(id) actually handles "the passed ID was just deleted" (it should fall back to the first item).
  5. Minor: Success message before refresh is fine, but consider moving MsgSuccess after loadWorkspaceOptions succeeds so toast reflects the full operation.

Expand Down
Loading