Skip to content

fix: format bug - #7953

Closed
shaohuzhang1 wants to merge 1 commit into
v3from
pr@v3@fix_format
Closed

shaohuzhang1 wants to merge 1 commit into
v3from
pr@v3@fix_format

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.

Review

Potential issues

  1. DEFAULT_MODEL_PROVIDER still hard-codes a Chinese string (name: '全部模型'). Since the PR is i18n-izing provider names via currentProviderName, this default should ideally be updated too — otherwise any consumer that renders provider.name directly (e.g., ModelProvider aside, or other code paths) will still show Chinese text.

  2. currentProviderName depends on t() inside a computed. This works, but if the user changes locale at runtime, the computed will re-evaluate only if the underlying reactive dependency changes. useI18n().t from vue-i18n is generally reactive to locale changes when accessed as t(...) inside computed in Composition API mode — but verify this holds for your setup (with legacy: false). If using tc/$t patterns elsewhere, ensure consistency.

  3. Repeated ternaries in currentProviderName are getting unwieldy. Consider mapping:

    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
    })
  4. searchFields name collision risk: field labels are now translated, but there is no guarantee consumers don't match on labels for filtering/logic. Worth confirming MkComplexSearch uses value (not label) internally for identity — the diff already keeps value, so this looks safe.

  5. Unused import check: MODEL_TYPE_LABELS was removed and MODEL_TYPE_MESSAGE_KEYS added. Confirm:

    • The new file ./model-type-labels actually exports MODEL_TYPE_MESSAGE_KEYS.
    • MODEL_TYPE_LABELS isn't used anywhere else in this file (looks clean, but verify across the repo).
    • Any other consumers of MODEL_TYPE_LABELS from @/constants haven't broken (only the constant itself removed here).
  6. Inconsistent i18n key prefixes in search fields: you use common.fields.creator.label here, while model-specific fields use model.fields.*. Just make sure common.fields.creator is indeed a real shared key; otherwise use model.fields.creator.label.

  7. t('resource.authorization.title') and t('resource.relations.title') mix naming conventions (title vs others using .label / actions namespaces). Ensure these keys exist and align with whatever convention the resource module uses.

  8. MkViewLayout :title="t('model.title')" is static — fine, but if the layout renders a title in locales where changing language dynamically should reflect, consider making it computed. Minor.

Optimization suggestions

  • Extract the provider-name ternary into a small helper or map (see [FEATURE]增加首次进入系统强制修改用户密码功能。 #3).
  • Consider a shared composable/utility for "translate or fallback to name" pattern if used elsewhere.
  • Since currentProviderName returns either a translated label or a user-facing provider name, document that it may not be fully localizable for custom providers — that's expected.
  • If MODEL_TYPE_MESSAGE_KEYS is static, hoist the derived options:
    const MODEL_TYPE_OPTIONS = Object.entries(MODEL_TYPE_MESSAGE_KEYS)
      .map(([value, key]) => ({ value, key }))
    Then only map to { label: t(key), value } inside the computed so the t calls remain locale-reactive.

Overall

Changes look correct and consistent with the goal of i18n-izing the component. Main action items: update DEFAULT_MODEL_PROVIDER.name, verify the new translation keys and MODEL_TYPE_MESSAGE_KEYS export exist, and simplify the provider-name ternaries.

: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 my observations on this diff:

Potential Issues

  1. Inconsistent i18n key namespaces (likely a bug).
    The refactor intends to standardize keys under auth.fields.*, but two keys were changed to a different, inconsistent namespace:

    • t('auth.forgotPassword.password.lengthMessage') — note password is not nested under fields. Compare with other password rules that use auth.fields.password.requiredMessage.
    • t('auth.forgotPassword.password.placeholder') in the template — same inconsistency; should likely be auth.fields.password.placeholder.

    Unless these keys intentionally exist elsewhere, they will render as raw key strings. Verify against the locale files.

  2. undefined vs null for validateState. You removed code that relied on field.validateState === 'error', so this is now moot, but if you re-add locale-reactive validation later, prefer checking field.validateMessage or using a state enum to avoid magic strings.

  3. Removal of locale watch — behavior regression.
    Previously, switching language while errors were visible re-validated those fields so messages updated immediately. After this change, stale error messages persist in the old language until the user blurs/edits the field. If that UX was intentional (e.g., "keep input, only refresh shown errors"), silently dropping it may be unwanted. Consider documenting the removal or keep it behind a feature flag.

  4. Rule whitelist / tolerance. email rule uses whitespace: true + type: 'email' but no max length; extremely long emails still hit the backend. Consider adding a length bound similar to password.

Optimization Suggestions

  1. Avoid recreating FormRules on every render. forgotPasswordRules is a computed, good — but since the messages come from t() (reactive only to locale), ensure t is reactive in your setup. This is fine, but consider Object.freeze-style memoization if rule objects grow.

  2. Consolidate duplicated t(...) calls inside validators. validateConfirmPassword calls t(...) each invocation; cache the two messages via computed once and reuse, reducing per-keystroke cost on blur.

  3. Interval cleanup check. You didn't show full startCountdown, but confirm countdownTimer is cleared in onBeforeUnmount and when the component unmounts mid-countdown; setInterval leaking into a destroyed route causes warnings and wasted ticks.

  4. isSendCodeDisabled computed reading .trim() on every keystroke is negligible but consider debouncing send-button disable state only if email input grows large — usually unnecessary.

  5. Type safety. validateConfirmPassword's callback is typed manually; consider using Element Plus's exported FormItemRule validator type instead of ad-hoc (error?: Error) => void to stay compatible with future versions.

  6. Key naming convention. Maintain a single source of truth (e.g., auth.fields.*) and add a CI check (script scanning t('...') strings against locale JSON) to avoid the kind of divergence seen in point build(deps): bump the pip group across 1 directory with 2 updates #1.

Summary

The main actionable concern is the i18n key inconsistency (auth.forgotPassword.password.* vs auth.fields.password.*) which is very likely a copy-paste mistake. Second is the intentional-but-undocumented removal of locale-reactive revalidation. Everything else is minor.

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.

Here are my findings on the diff:

Potential Issues / Irregularities

  1. next pointing to a sibling instead of the next tab (likely bug)

    • In system-resource-application-access, next: 'system-resource-application-access' points to itself. This will cause an infinite/self-loop when navigating forward, or point nowhere meaningful.
    • In chat-user and operation-log, next: 'system-resource-application-access' points backward to access. Given orders 30 → 40 → 50, next for chat-user should probably be system-resource-application-operation-log, and operation-log's next should be undefined (last tab) or removed.
    • Fix suggestion: Set access.next → chat-user, chat-user.next → operation-log, and remove/omit next on the last item.
  2. permission changed from a value to a thunk — verify the contract

    • Changing perm.application.system.overviewRead (a value) to () => perm.application.system.overviewRead() (a function). This is only correct if the field was originally a lazy getter and the route consumer invokes permission functions. If the consumer expects a boolean/value, passing a function will make it always truthy (permission effectively bypassed). Confirm the type of meta.permission in RouteMeta and how it's evaluated (e.g., typeof perm === 'function' ? perm() : perm).
  3. Whitespace/bracket alignment in chat-user

    • The original had mismatched indentation (next: ... not aligned). The new version fixes this — good. No functional issue, just confirm no accidental merging occurred.

Optimization / Consistency Suggestions

  1. Consistency in meta.activeMenu

    • activeMenu: '/system/resource/applications' was added only to the root detail route. Ensure the child routes inherit expected menu highlighting; children typically don't need their own activeMenu if they share the parent layout. Verify the highlighting works for deep links (e.g., directly opening /access).
  2. Repeated formatting

    • All meta objects were reflowed multi-line. If a formatter (Prettier/eslint) is configured with printWidth, some of these could remain single-line (e.g., the access meta line). Consider running formatter to avoid unnecessary churn in future diffs.
  3. Magic strings for route names

    • next, redirect, and name values are hardcoded strings repeated across files. Consider extracting route-name constants to prevent typos (the self-referencing next is exactly the kind of bug constants + type-checking would catch).
  4. Type safety

    • Since next, activeMenu, permission, and detailMenuVisible are custom RouteMeta fields, ensure they're declared in the RouteMeta module augmentation (e.g., vue-router's RouteMeta interface) so TS catches invalid names/values.

Summary

The main bug is the incorrect next links (self-reference on access, backward references on later tabs). Also verify the permission thunk change is supported by the route evaluator — otherwise permissions become permissive. The rest are style/consistency improvements.

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