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
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,15 @@ import AccountMenu from '../account-menu/index.vue'

import { useMessageListStore } from '../../components/message-list/index'
import { useShareLinkStoreOptional } from '../../components/message-list/share/index'
import { useViewType, VIEW_TYPE } from '../../view/index'
import { useViewType, VIEW_TYPE ,type ViewType} from '../../view/index'

defineOptions({ name: 'ConversationList' })

const viewType = useViewType()
const { auth } = useStore()
const authProfile = computed(() => (viewType === VIEW_TYPE.CHAT ? auth.authProfile : null))

const SHOW_PROFILE: readonly ViewType[] = [VIEW_TYPE.CHAT, VIEW_TYPE.PORTAL]
const msgs = useMessageListStore()
// 会话菜单分享不针对某一轮,进入后不预先勾选
const shareLink = useShareLinkStoreOptional()
Expand Down Expand Up @@ -138,7 +140,7 @@ function handleClearConversations() {
</div>
</el-scrollbar>
<!-- 账户入口固定在侧栏底部,不随历史列表滚动。 -->
<div class="mt-3 shrink-0">
<div class="mt-3 shrink-0" v-if="SHOW_PROFILE.includes(viewType)">
<AccountMenu />
</div>
</div>

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.

The diff is valid and the intent is clear. No blocking issue from the shown code, but here are review points:

  1. Import formatting

    import { useViewType, VIEW_TYPE ,type ViewType} from '../../view/index'

    Should be formatted as:

    import { useViewType, VIEW_TYPE, type ViewType } from '../../view/index'

    Or use a separate import type { ViewType } ... if your lint rules prefer that.

  2. Verify useViewType() return type
    The existing computed:

    const authProfile = computed(() => (viewType === VIEW_TYPE.CHAT ? auth.authProfile : null))

    compares viewType directly. If useViewType() returns a Ref/ComputedRef, this is likely a bug and should use viewType.value.
    In the template, refs are auto-unwrapped, so:

    v-if="SHOW_PROFILE.includes(viewType)"

    probably works. But for consistency and testability, prefer:

    const showAccountMenu = computed(() =>
      SHOW_PROFILE.includes(viewType.value)
    )

    and:

    v-if="showAccountMenu"

    Adjust .value only if viewType is actually a ref.

  3. Rename SHOW_PROFILE
    It is not a boolean; it is a list of view types controlling the account menu. A clearer name:

    const ACCOUNT_MENU_VIEW_TYPES: readonly ViewType[] = [
      VIEW_TYPE.CHAT,
      VIEW_TYPE.PORTAL,
    ]

    Then:

    v-if="ACCOUNT_MENU_VIEW_TYPES.includes(viewType)"
  4. v-if destroys/remounts AccountMenu
    If AccountMenu has internal state or async initialization, switching view types will destroy and recreate it. Use v-show instead if state preservation is needed, or keep v-if if remounting is acceptable.

  5. Confirm product behavior
    Hiding the account entry in all other view types may remove access to logout/settings. Make sure this is intentional.

  6. Type/export checks
    Ensure ViewType is exported from ../../view/index, and that VIEW_TYPE.PORTAL is actually part of the ViewType union/enum. Otherwise TypeScript will fail.

  7. Minor optimization
    Array.prototype.includes is fine for two values. If the list grows, use a Set<ViewType> and .has(...). The array is also recreated per component instance in <script setup>; negligible here, but it can be moved to module scope if desired.

Suggested small cleanup:

import { useViewType, VIEW_TYPE, type ViewType } from '../../view/index'

const ACCOUNT_MENU_VIEW_TYPES: readonly ViewType[] = [
  VIEW_TYPE.CHAT,
  VIEW_TYPE.PORTAL,
]
<div
  v-if="ACCOUNT_MENU_VIEW_TYPES.includes(viewType)"
  class="mt-3 shrink-0"
>
  <AccountMenu />
</div>

Expand Down
Loading