Repository navigation
fix: portal auth setting #7762
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
fix: portal auth setting #7762
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,9 +4,10 @@ import { pick } from 'lodash' | |
| import CurrentUserApi from '@/api/admin/auth/current-user' | ||
| import AuthSettingApi from '@/api/admin/system/settings/auth-setting' | ||
| import UserGroupsApi from '@/api/admin/system/user-groups' | ||
| import type { ListItem, LoginAuthSettingPayload, SystemUserGroup } from '@/api/types' | ||
| import type { ListItem, LoginAuthSettingPayload, LoginMethod, SystemUserGroup } from '@/api/types' | ||
| import type { FormInstance, FormRules } from 'element-plus' | ||
| import { LOGIN_METHOD, ROLE_TYPE } from '@/api/enums' | ||
| import { LOGIN_METHOD_LABELS } from '@/constants' | ||
| import { MsgSuccess } from '@/utils/message' | ||
| import { useStore } from '@/stores' | ||
| import perm from '@/permission' | ||
|
|
@@ -171,7 +172,7 @@ onActivated(() => { | |
| <el-form-item label="登录方式" prop="login_methods"> | ||
| <el-checkbox-group v-model="form.login_methods" @change="handleLoginMethodsChange" class="flex-wrap"> | ||
| <el-checkbox v-for="loginMethodOption in loginMethodOptions" :key="loginMethodOption.value" :value="loginMethodOption.value" class="w-40"> | ||
| {{ loginMethodOption.label }} | ||
| {{ LOGIN_METHOD_LABELS[loginMethodOption.value as LoginMethod] || loginMethodOption.label }} | ||
| </el-checkbox> | ||
| </el-checkbox-group> | ||
| </el-form-item> | ||
|
|
@@ -182,7 +183,7 @@ onActivated(() => { | |
| v-for="loginMethodOption in defaultLoginMethodOptions" | ||
| :key="loginMethodOption.value" | ||
| :value="loginMethodOption.value" | ||
| :label="loginMethodOption.label" | ||
| :label="LOGIN_METHOD_LABELS[loginMethodOption.value as LoginMethod] || loginMethodOption.label" | ||
| /> | ||
| </el-select> | ||
| </el-form-item> | ||
|
Contributor
Author
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. Code ReviewPotential Issues
Optimization Suggestions
Minor
|
||
|
|
||
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.
Here's my review of the diff:
Issues & Concerns
Redundant fallback logic —
LOGIN_METHOD_LABELS[...] || loginMethodOption.labelsuggests uncertainty about whetherloginMethodOption.valueis a validLoginMethod. If it isn't, using it as an index is unsafe; if it is, the||fallback pollutes intent. Pick one source of truth.Unsafe type casting (
as LoginMethod) — repeated inline casts in the template obscure the real type ofloginMethodOption.value. Better to typeloginMethodOptions/defaultLoginMethodOptionscorrectly at their source (e.g.,Array<{ value: LoginMethod; label: string }>), then drop the casts.Inconsistent data sources — if
LOGIN_METHOD_LABELSis now the canonical label map, why keeplabelon the option objects at all? Maintaining labels in two places invites drift. Either:labelfrom the options and rely solely onLOGIN_METHOD_LABELS, orLOGIN_METHOD_LABELS(single iteration overObject.entries).Missing-key behavior —
LOGIN_METHOD_LABELS[k] || labelsilently falls back when a key is missing. That may hide real bugs (e.g., a newLOGIN_METHODadded without a label). Consider??(nullish) instead of||— but note that if a label can legitimately be'', even??won't help; in that case use explicitinchecks or TypeScript exhaustiveness.Computed for label lookup (optimization) — if the checkbox/select lists are stable, precompute a mapped list once with
computed()rather than doing the dictionary lookup per-item per-render:Then iterate those in the template with no casts.
Logic duplication — the same "resolve label" logic appears twice. Extract into a helper:
Ensure
LoginMethodandLOGIN_METHOD_LABELSstay in sync — defineLOGIN_METHOD_LABELSasRecord<LoginMethod, string>so TypeScript enforces exhaustiveness. This removes the need for the cast entirely.Import location consistency —
LOGIN_METHODcomes from@/api/enumsbutLOGIN_METHOD_LABELScomes from@/constants. Consider co-locating them (both in enums, or both in constants) to avoid future divergence.Minor: blank line / diff noise — the diff looks clean otherwise; no unrelated changes detected.
Suggested Rewrite (sketch)
This removes casts, removes duplication, enforces label coverage at compile time, and avoids per-render dictionary lookups.