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
7 changes: 4 additions & 3 deletions ui/src/layout/avatar-dropdown/index.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<script setup lang="ts">
import { computed, ref, useTemplateRef, watch } from 'vue'
import { useRouter } from 'vue-router'
import { useRoute, useRouter } from 'vue-router'
import { useI18n } from 'vue-i18n'
import type { Locale } from '@/locales/config'
import { LOGIN_METHOD } from '@/api/enums'
Expand All @@ -19,6 +19,7 @@ defineOptions({ name: 'AvatarDropdown' })
const { t } = useI18n({ useScope: 'global' })

const isChangingLanguage = ref(false)
const route = useRoute()
const router = useRouter()
const { auth, user, theme } = useStore()
const currentLocale = computed(() => resolveSupportedLocale(user.language))
Expand All @@ -44,9 +45,9 @@ function handleOpenChangePassword() {
changePasswordDialogRef.value?.open()
}

// 用户资料和弹窗就绪后提示修改默认密码;刷新页面后仍会重新检查。
// 用户资料和弹窗就绪、工作空间与系统管理切换时检查默认密码;刷新后仍会重新检查。
watch(
[() => user.userInfo?.is_edit_password, changePasswordDialogRef],
[() => user.userInfo?.is_edit_password, changePasswordDialogRef, () => route.meta.scope],
([isDefaultPassword]) => {
if (isDefaultPassword === true) handleOpenChangePassword()
},

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.

No syntax-level issues in the diff, but there are a few logic/UX and timing concerns.

Potential issues

  1. The dialog may be reopened or reset on every scope change

    • Adding () => route.meta.scope to the watch sources means the callback runs whenever route.meta.scope changes.
    • If is_edit_password === true, handleOpenChangePassword() is called even if the dialog is already open or the user has dismissed it.
    • If open() resets form state, this can overwrite user input. Make open() idempotent, or guard it with an isOpen check or a “already prompted” flag.
  2. Template ref timing / stale dialog instance risk

    • The watcher uses changePasswordDialogRef as a readiness trigger, but the callback does not explicitly check changePasswordDialogRef.value.
    • With the default flush: 'pre', route.meta.scope can change before the DOM/template ref is updated. This can cause a no-op call or, worse, an open() call on a stale instance during route transition.
    • Prefer flush: 'post' and explicitly check the ref.
  3. Scope trigger is broader than the comment suggests

    • The comment says “workspace / system management switch”, but route.meta.scope will trigger for any change in that value, including undefined or future scope values.
    • If only workspace/system scopes should trigger, use a computed predicate or watch specific route metadata.
  4. Possible double trigger during route transitions

    • Both route.meta.scope and changePasswordDialogRef can change during the same navigation. If open() is not idempotent, this can result in two open attempts.
  5. Type safety for route.meta.scope

    • If RouteMeta is not augmented with scope, TypeScript may complain or infer unknown.
    • Add a RouteMeta module augmentation or cast/narrow the value explicitly.

Suggested adjustment

watch(
  [
    () => user.userInfo?.is_edit_password,
    changePasswordDialogRef,
    () => route.meta.scope,
  ],
  ([isDefaultPassword]) => {
    if (isDefaultPassword === true && changePasswordDialogRef.value) {
      handleOpenChangePassword()
    }
  },
  { flush: 'post' },
)

And make handleOpenChangePassword() / the dialog’s open() safe to call repeatedly, e.g.:

function handleOpenChangePassword() {
  const dialog = changePasswordDialogRef.value
  if (!dialog || dialog.isOpen) return
  dialog.open()
}

Minor optimization

If the intended behavior is only “prompt once after login or once per session”, track a flag such as hasPromptedDefaultPassword instead of relying on scope changes. Otherwise, switching between workspace/system management while the default password remains unchanged will keep reopening the dialog.

Expand Down
Loading