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
24 changes: 23 additions & 1 deletion ui/src/views/chat/login/index.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<script setup lang="ts">
import { computed, onBeforeMount, ref } from 'vue'
import { ArrowLeft } from '@element-plus/icons-vue'
import { getDingTalkClientAuthCode } from '@/views/login/dingtalk-client-login'
import { useRoute, useRouter, type RouteLocationRaw } from 'vue-router'
import { v7 as uuidv7 } from 'uuid'
Expand All @@ -18,7 +19,7 @@ const route = useRoute()
const router = useRouter()
const { auth } = useStore()
const isClientLoggingIn = ref(false)

console.log(auth)
const loginTitle = computed(() => {
if (auth.isPortal) return '门户登录'
return (auth.authProfile?.meta as ApplicationAuthProfileMeta | undefined)?.application_name || '登录'
Expand Down Expand Up @@ -132,15 +133,36 @@ onBeforeMount(async () => {
isClientLoggingIn.value = false
}
})

const enableAuth=computed(()=>{
return auth.authProfile?.enable_auth
})

const goBack = () => {
if (enableAuth.value) {
return
}
router.replace(getRedirectRoute())
}
</script>

<template>
<div class="chat-login flex-center flex-col">

<div class="mb-6 flex-align-center gap-4 max-w-full">
<ApplicationIcon :icon="auth.authProfile?.logo" :size="32" class="shrink-0" />
<h2 class="max-w-full truncate" :title="loginTitle">{{ loginTitle }}</h2>
</div>
<el-card class="chat-login__card w-100">
<!-- 返回上一页 -->
<span
v-if="!enableAuth"
class="mb-4 inline-flex items-center gap-1 cursor-pointer text-sm text-N900 hover:text-primary"
@click="goBack"
>
<MkIcon :icon="ArrowLeft" :size="14" />
返回
</span>
<LoginModePanel v-if="!isClientLoggingIn" :login-config="loginConfig" :login-service="loginService" />
</el-card>
</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.

Here is a review of the provided code changes, highlighting potential issues and optimization suggestions:

1. Critical Issue: Debug Code Left in Production

Problem: The line console.log(auth) has been added.
Impact: This pollutes the browser console in production and may expose sensitive data (depending on what auth contains) to end-users via developer tools.
Fix: Remove this line before committing/merging.

- console.log(auth)

2. Logic Error / Misleading Variable Name & Behavior

Problem: The logic for goBack seems counter-intuitive or potentially wrong depending on the business requirements.

  • Current Logic: If enableAuth is true, goBack does nothing. If enableAuth is false, it redirects home.
  • UI Logic: The "Return" button is shown only if !enableAuth.

Analysis:
If enableAuth means "Authentication is enabled/required for this profile," then showing a "Return" button only when auth is disabled might make sense (e.g., a guest/public landing page). However, if enableAuth is just a configuration flag, ensure that skipping navigation when enableAuth is true is the intended behavior. Usually, a "Back" button should always work unless explicitly prevented by a state lock, not an auth feature flag.

Suggestion: Verify the business requirement. If the user should always be able to go back when the button is visible, remove the check inside goBack:

// Option A: If the button visibility (!enableAuth) already handles the condition
const goBack = () => {
  router.replace(getRedirectRoute())
}

3. Redundant Optional Chaining / Type Safety

Problem: In the goBack function, you access auth.authProfile?.enable_auth.
Optimization: Since enableAuth is already a computed property handling this exact access, reuse it inside goBack instead of duplicating the logic. This ensures single source of truth and better maintainability.

const goBack = () => {
  // Use the existing computed ref
  if (enableAuth.value) {
    return
  }
  router.replace(getRedirectRoute())
}

4. Missing Import for MkIcon

Potential Issue: The template uses <MkIcon :icon="ArrowLeft" />, but MkIcon is not imported in the script setup block. While global registration might handle this in some Vue projects, it's best practice to verify if MkIcon needs explicit import or if it's globally registered. If it's not global, this will cause a runtime error.

5. Accessibility & Semantics

Suggestion: The "Return" button is implemented as a <span> with cursor-pointer. While functional, this is a "div/span hacking" pattern.

  • Better: Use a proper <button> element or an Element Plus link component (<el-link>).
  • Accessibility: Screen readers may not identify <span @click> as an interactive button.
<!-- Recommended Change -->
<button 
  v-if="!enableAuth"
  type="button"
  class="mb-4 inline-flex items-center gap-1 bg-transparent border-0 cursor-pointer text-sm text-N900 hover:text-primary"
  @click="goBack"
>
  <MkIcon :icon="ArrowLeft" :size="14" />
  返回
</button>

6. Styling Class Best Practices

Observation: You are using utility classes like text-N900, text-primary, gap-1, shrink-0.
Check: Ensure these custom color classes (text-N900) are properly defined in your tailwind/CSS config. Standard Tailwind does not include N900 by default. If this is a custom theme, it's fine; otherwise, this style might not apply.


Summary of Recommended Actions

  1. Remove console.log(auth).
  2. Refactor goBack to use the existing enableAuth.value instead of re-accessing auth.authProfile.
  3. Change <span> to <button> for semantic correctness and accessibility.
  4. Verify that MkIcon is globally registered or import it correctly.
  5. Confirm business logic: Does enableAuth=true really mean the user cannot go back, or was the logic meant to be opposite?

Expand Down
Loading