Skip to content

fix: format bug - #7954

Merged
wangdan-fit2cloud merged 1 commit into
v3from
pr@v3@fix_format1
Nov 16, 2026
Merged

wangdan-fit2cloud merged 1 commit into
v3from
pr@v3@fix_format1

Conversation

@shaohuzhang1

Copy link
Copy Markdown
Contributor

fix: format bug

/>
</template>
</ModelCard>
</template>

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.

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_LABELS isn't used elsewhere in this file (looks clean).
  • If MODEL_TYPE_LABELS is now unused project-wide, remove it to avoid dead exports.
  • The new module ./model-type-labels exists 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 MkAction for edit was reformatted to multiline while others follow varying styles; consider letting Prettier normalize.
  • No import ordering rule violation detected, but placing the new import after vue (grouped with external libs) would be cleaner than jumping between @/api lines.

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.

@wangdan-fit2cloud
wangdan-fit2cloud merged commit 76221d8 into v3 Nov 16, 2026
3 of 4 checks passed
@wangdan-fit2cloud
wangdan-fit2cloud deleted the pr@v3@fix_format1 branch November 16, 2026 12:33
:placeholder="t('auth.fields.confirmPassword.placeholder')"
show-password
type="password"
/>

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 are the irregularities, potential issues, and optimization suggestions:

Issues / Irregularities

  1. 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 migrated
    • auth.forgotPassword.password.* (in password.lengthMessage and password.placeholder)

    This suggests an incomplete refactor. Some keys reference auth.fields.*, others still use auth.forgotPassword.*. Verify all these keys actually exist in the locale files; otherwise you'll get missing-translation warnings/fallbacks.

  2. Possible broken key: auth.forgotPassword.password.lengthMessage
    Earlier it was auth.forgotPassword.validation.passwordLength. If the new path auth.forgotPassword.password.lengthMessage doesn't exist in your locale JSON, validation will display the raw key string. Double-check.

  3. Removal of the locale watcher (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.

  4. Unused import removed correctly, but verify locale is not used elsewhere
    You removed locale from destructuring and watch from imports — good, provided neither is referenced elsewhere in the file. (t only is fine.)

  5. Whitespace-only password still treated as valid
    For password, there's no whitespace: true, while email and verificationCode have it. A password of only spaces passes required (non-empty) — usually acceptable for passwords, but note the inconsistency. If spaces should be rejected, add a check.

  6. min/max on a password with whitespace
    { min: 6, max: 30 } counts spaces. Confirm this matches backend constraints.

Optimization Suggestions

  1. Stable validator reference
    validateConfirmPassword is defined outside computed, which is good. But since forgotPasswordRules is a computed depending on t(), any locale change recreates rule objects — fine, but if you removed the locale watcher the rules won't visibly re-run until re-validation fires.

  2. Centralize message lookups
    Given the namespace churn, consider a helper like const msg = (key: string) => t(\auth.fields.${key}`)to keep keys consistent and avoid drift betweenauth.fields.andauth.forgotPassword.`.

  3. Avoid inline new Error(t(...)) duplication
    Multiple rule definitions repeat the pattern. Extracting a requiredRule(key) factory would reduce boilerplate and make future namespace migrations trivial.

  4. callback(new Error(...)) vs returning a Promise
    Element Plus supports async validators; using async/throw can simplify readability and reduce callback-style nesting, though current style is correct.

  5. Placeholder key inconsistency (visual bug risk)
    email now uses auth.fields.email.placeholder, but the resendCode/sendCode buttons still use auth.forgotPassword.actions.*. Not a bug per se, just confirm the migration scope was intentional and that action labels weren't meant to move too.

  6. Missing whitespace on confirmPassword
    confirmPassword uses only a custom validator without whitespace; 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',
},
},

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.

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 boolean

will 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 meta blocks 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-log route uses component chat-log/index.vue while named operation-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)

  1. Confirm permission consumers support function form everywhere (or normalize).
  2. Fix next chain — especially access → access self-reference.
  3. Replace hardcoded activeMenu path with a shared constant.
  4. Add explicit meta typing to prevent silent regressions.
  5. Split the unrelated activeMenu change into its own commit.
  6. Run formatter/linter.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants