Repository navigation
fix: format bug - #7954
fix: format bug#7954
Conversation
| /> | ||
| </template> | ||
| </ModelCard> | ||
| </template> |
There was a problem hiding this comment.
I reviewed the diff. Here are my findings:
Issues
1. Unused / orphaned default constant (potential functional bug)
const DEFAULT_MODEL_PROVIDER: ModelProviderItem = { icon: '', name: '全部模型', provider: 'all' }This still contains a hardcoded localized string '全部模型'. Since the rest is being i18n-ified, this leftover Chinese label will likely show up somewhere (e.g., as the default provider's displayed name). Consider replacing name with a message key or resolving it via t('model.providers.all') at use time.
2. Nested ternary in currentProviderName — readability
currentProvider.value.provider === 'all'
? t('model.providers.all')
: currentProvider.value.provider === 'shared'
? t('model.providers.shared')
: currentProvider.value.name,Nested ternaries hurt readability and are often flagged by linters (no-nested-ternary). Prefer an early-return function or a lookup map:
const PROVIDER_NAME_KEYS: Record<string, string> = {
all: 'model.providers.all',
shared: 'model.providers.shared',
}
const currentProviderName = computed(() => {
const key = PROVIDER_NAME_KEYS[currentProvider.value.provider]
return key ? t(key) : currentProvider.value.name
})3. searchFields is a computed but doesn't depend on t reactively
t from useI18n returns a reactive-ish function; however, if the user changes locale at runtime, computed tracking of t(...) calls may not re-trigger unless locale is read reactively inside the computed. To be safe when locale switches should update labels, explicitly depend on the locale:
const { t, locale } = useI18n({ useScope: 'global' })
const searchFields = computed(() => {
locale.value // track locale changes
return [ ... ]
})Same applies to currentProviderName.
4. Removed MODEL_TYPE_LABELS import — verify no other usages
The diff replaces MODEL_TYPE_LABELS from @/constants with MODEL_TYPE_MESSAGE_KEYS from ./model-type-labels. Make sure:
MODEL_TYPE_LABELSisn't used elsewhere in this file (looks clean).- If
MODEL_TYPE_LABELSis now unused project-wide, remove it to avoid dead exports. - The new module
./model-type-labelsexists and maps values consistently with the old keys (same value strings like'RERANKER', etc.).
5. Hardcoded provider type literals
'all' and 'shared' are magic strings repeated in multiple places (DEFAULT_MODEL_PROVIDER, isShared, currentProviderName). Extract to constants/enum to avoid typos:
const PROVIDER_ALL = 'all'
const PROVIDER_SHARED = 'shared'6. Consistency: Name vs provider
In the fallback branch you use currentProvider.value.name, but for 'shared' you ignore name and use a translation. Ensure ModelProviderItem for shared/all providers always has a stable provider id so this logic is reliable — otherwise .name could be empty for custom entries.
Minor / Nitpicks
- Unicode annotation line (
@@ -1,5 +1,6 @@) appears malformed/incomplete in the pasted diff — verify the patch applies cleanly (looks like a truncated header). - Consistent label sourcing:
t('resource.authorization.title')vs earlier资源授权— confirm these message keys match the intended legacy text. - The
MkActionfor edit was reformatted to multiline while others follow varying styles; consider letting Prettier normalize. - No
importordering rule violation detected, but placing the new import aftervue(grouped with external libs) would be cleaner than jumping between@/apilines.
Summary
The main correctness concern is the leftover hardcoded '全部模型' in DEFAULT_MODEL_PROVIDER, and the reactivity of computed labels on locale change. The rest are style/maintainability improvements.
| :placeholder="t('auth.fields.confirmPassword.placeholder')" | ||
| show-password | ||
| type="password" | ||
| /> |
There was a problem hiding this comment.
Here are the irregularities, potential issues, and optimization suggestions:
Issues / Irregularities
-
Inconsistent i18n key namespaces (high priority)
The diff mixes three different translation-key conventions:auth.fields.email.*/auth.fields.password.*/auth.fields.confirmPassword.*/auth.fields.verificationCode.*auth.forgotPassword.validation.*→ partially migratedauth.forgotPassword.password.*(inpassword.lengthMessageandpassword.placeholder)
This suggests an incomplete refactor. Some keys reference
auth.fields.*, others still useauth.forgotPassword.*. Verify all these keys actually exist in the locale files; otherwise you'll get missing-translation warnings/fallbacks. -
Possible broken key:
auth.forgotPassword.password.lengthMessage
Earlier it wasauth.forgotPassword.validation.passwordLength. If the new pathauth.forgotPassword.password.lengthMessagedoesn't exist in your locale JSON, validation will display the raw key string. Double-check. -
Removal of the
localewatcher (functional regression risk)
The watch was responsible for re-validating visible fields when the language changes so error messages update to the new locale. Removing it means: after switching language, previously shown validation errors will remain in the old language until the user re-triggers blur/validate. If cross-locale reactive validation is desired, either keep the watcher or ensure errors are cleared/re-validated elsewhere. If intentionally dropped, confirm UX requirement. -
Unused import removed correctly, but verify
localeis not used elsewhere
You removedlocalefrom destructuring andwatchfrom imports — good, provided neither is referenced elsewhere in the file. (tonly is fine.) -
Whitespace-only password still treated as valid
Forpassword, there's nowhitespace: true, while email and verificationCode have it. A password of only spaces passesrequired(non-empty) — usually acceptable for passwords, but note the inconsistency. If spaces should be rejected, add a check. -
min/maxon a password with whitespace
{ min: 6, max: 30 }counts spaces. Confirm this matches backend constraints.
Optimization Suggestions
-
Stable validator reference
validateConfirmPasswordis defined outsidecomputed, which is good. But sinceforgotPasswordRulesis acomputeddepending ont(), any locale change recreates rule objects — fine, but if you removed thelocalewatcher the rules won't visibly re-run until re-validation fires. -
Centralize message lookups
Given the namespace churn, consider a helper likeconst msg = (key: string) => t(\auth.fields.${key}`)to keep keys consistent and avoid drift betweenauth.fields.andauth.forgotPassword.`. -
Avoid inline
new Error(t(...))duplication
Multiple rule definitions repeat the pattern. Extracting arequiredRule(key)factory would reduce boilerplate and make future namespace migrations trivial. -
callback(new Error(...))vs returning a Promise
Element Plus supports async validators; usingasync/throwcan simplify readability and reduce callback-style nesting, though current style is correct. -
Placeholder key inconsistency (visual bug risk)
emailnow usesauth.fields.email.placeholder, but theresendCode/sendCodebuttons still useauth.forgotPassword.actions.*. Not a bug per se, just confirm the migration scope was intentional and that action labels weren't meant to move too. -
Missing
whitespaceonconfirmPassword
confirmPassworduses only a custom validator withoutwhitespace; a value of" "differing from password triggers the mismatch message rather than a "required" message. Minor UX inconsistency.
Summary
The main concern is the partially completed i18n key refactor (possible missing keys / inconsistent namespaces) and the removal of the locale watcher, which may cause stale-language validation messages after a language switch. Verify locale files contain every key referenced and confirm the UX decision around the watcher.
| permission: () => perm.application.system.chatLogRead(), | ||
| next: 'system-resource-application-access', | ||
| }, | ||
| }, |
There was a problem hiding this comment.
Code Review: Route Configuration Diff
1. Potential Bug: permission Type Changed from Value to Function
Issue (most important):
- permission: perm.application.system.overviewRead,
+ permission: () => perm.application.system.overviewRead(),This changes the meta field from a value to a factory function. Any consumer that previously did something like:
if (route.meta.permission) { ... } // now always truthy!
const allowed = route.meta.permission; // no longer a booleanwill break silently. If the entire codebase was migrated consistently to call permission() as a function, fine — but if any other route definitions still use the value form (permission: perm.x.y), you now have inconsistent types and likely a runtime bug depending on how the permission filter works.
Recommendation: Verify the menu/permission filtering code handles both shapes, or migrate all routes uniformly in the same PR.
2. Incorrect next Value (pre-existing, but visible here)
{
path: 'access',
meta: {
...
next: 'system-resource-application-access', // ← points to itself
}
}The access route's next points back to system-resource-application-access (itself). This will cause an infinite loop or be a no-op depending on how next is consumed. It likely should point to the next sibling (system-resource-application-chat-user).
Same for chat-user and operation-log: both have next: 'system-resource-application-access', which jumps backward rather than continuing sequentially. Confirm this is intentional (e.g., "next" means "fallback after this one's subtree"), otherwise fix the ordering.
3. Repeated Closure Allocation
Each arrow function () => perm.application.system.x() creates a new closure on every module evaluation. Not a real perf concern at route-definition scale, but if perm is a mutable/observable object, note these functions are captured at definition time and won't re-evaluate if permissions update later — unless your framework re-invokes them per navigation (which appears to be the intent).
Suggestion: If you want consistency and cacheability, consider a helper:
const can = (p: () => boolean) => () => p();
// or simply memoize:
const can = memoize((fn) => fn);Not necessary — just naming clarity.
4. activeMenu: '/system/resource/applications' — Hard-coded Path
Hardcoding the path string is fragile. If the parent resource list route path ever changes, this breaks silently (no compile-time check).
Suggestion: Reference the route by name instead, or extract to a constant:
export const SYSTEM_RESOURCE_APP_LIST_PATH = '/system/resource/applications';
...
activeMenu: SYSTEM_RESOURCE_APP_LIST_PATH,Also verify this path exactly matches the actual list route's path — a mismatch will leave no menu item highlighted.
5. Unrelated Change Bundled In
The activeMenu addition in system-resource-application-detail is logically unrelated to the permission refactor. Consider splitting into separate commits/PRs for cleaner history and easier revert.
6. Formatting / Consistency
- The
metablocks are now multi-line but indentation of individual keys is inconsistent across siblings (some align, some don't). Run Prettier/eslint on the file after editing. operation-logroute uses componentchat-log/index.vuewhile namedoperation-log— verify this isn't a copy-paste mistake (title says 对话日志 which matches chat-log, so probably intentional, but worth confirming).
7. Missing as const / Typing (minor)
If RouteRecordRaw typing permits meta to be any, the changed permission shape won't be caught by TypeScript. Add an explicit meta type:
interface AppDetailMeta {
title: string;
hidden?: boolean;
permission?: () => boolean;
next?: string;
...
}so future divergences from value→function are caught at compile time.
Summary of Action Items (by priority)
- Confirm
permissionconsumers support function form everywhere (or normalize). - Fix
nextchain — especiallyaccess → accessself-reference. - Replace hardcoded
activeMenupath with a shared constant. - Add explicit
metatyping to prevent silent regressions. - Split the unrelated
activeMenuchange into its own commit. - Run formatter/linter.
fix: format bug