6.2 KiB
6.2 KiB
AGENTS.md - views/setting
Scope
This file applies to src/views/setting/**.
This directory implements the account settings page at route /settings. The route is cached in src/router/index.ts with meta: { cache: true }, so stateful changes should handle re-entry and refresh deliberately.
Project Rules
- Do not start local services by default. Assume the project service is already running unless the user explicitly asks you to start one, or you first ask for permission because runtime verification requires it.
- Keep the current Vue 3 style: Composition API,
<script setup lang="ts">, typed props/emits, and scoped Less in SFCs. - Prefer
rgfor code search. - Keep edits focused on this feature. Do not refactor unrelated settings, router, API, or language files unless the setting page change requires it.
Page Architecture
index.vueis the route-level composition surface. Keep it thin: page shell, banner, section composition, and lifecycle wiring only.useSettingsForm.tsowns settings state, API calls, save/discard behavior, email verification state, validation, and language synchronization.types.tsowns setting-page domain types and option constants.components/SettingsSection.vueprovides the two-column section layout.components/ProfileSection.vuerenders profile fields, role selection, and avatar upload.components/SecuritySection.vuerenders email/password editing controls and emits security actions upward.components/RegionSection.vuerenders language and region selectors.components/SettingsActions.vuerenders edit/save/verify/discard actions.components/EmailVerificationDialog.vueowns the verification-code modal UI, countdown, local code input, and submit/resend events.components/Radio.vueis a local button-based single/multiple select control. For role selection, it is used withmultipleandmax="2".
Data Flow
- Preserve the
sourceData/draftDatasplit inuseSettingsForm.ts.sourceDatais the last loaded/saved server state.draftDatais the editable copy used whileisEditingis true.displayDataswitches between them based onisEditing.
- Child components should receive data through props or
v-model:*bindings and report changes with typed emits. - Do not let child components mutate parent objects directly.
- Keep security-only draft fields in
securityDraft(newEmail,newPassword,currentPassword) rather than mixing them intodraftData. handleDiscard()must reset profile draft, security draft, verification state, and section editing flags.
API Contracts
The setting page currently depends on src/api/user.ts:
fetchUserProfile()->/buyer/profile/getProfileupdateUserProfile(data)->/buyer/profile/setProfileupdateUserAvatar({ avatarUrl })->/buyer/profile/setAvataruploadFile(file)->/buyer/profile/uploadfetchVerifyCode()->/buyer/profile/sendEmailChangeCodeverifyEmailCode(verifyCode)->/buyer/profile/verifyEmailChangeCode
When saving settings:
- Trim text fields before building the payload.
- Send
rolesasstring[]. - Send
verifyCodeonly when email or password is being changed. - Hash
oldPasswordandnewPasswordwithmd5only when changing password. - Keep email/password verification behavior centralized in
useSettingsForm.ts; child components should only emit intent.
Language And Region
- Frontend setting values are
englishandchinese. - i18n locale values are
ENGLISHandCHINESE_SIMPLIFIED. - Backend language values are
enandzh-CN. - Keep all language mapping in
useSettingsForm.tsunless it becomes shared with another feature. - After saving a changed language, update
locale.valueandlocalStorage.language. - Regions come from
src/utils/area.ts; display labels are translated througharea.<key>insrc/lang/en.tsandsrc/lang/zh-cn.ts. - When adding a language, role, message, or region label, update both language files.
Validation And UX
- Email changes require a valid email format and a successful verification before save.
- Password changes use
validateLength,validateSpecial, andvalidateCasefromsrc/views/login/tools. - New password must not equal the current password.
- Password changes also require verification using the current account email.
SettingsActions.vueintentionally shows the Verify Email action before Save whenneedsEmailVerificationis true.EmailVerificationDialog.vueowns its 60-second resend countdown and clears timers on close/unmount.- Avoid adding visible instructional copy unless the product requirement asks for it; most labels and tips already come from i18n.
Styling
- Existing layout uses fixed
remsizing, Kaisei font classes, white/gray/black styling, and Element Plus controls restyled with:deep. - Keep SFC styles scoped.
- Reuse local Less mixins such as
.field-text(),.field-frame(), and.control-wrapper()within components when extending matching controls. - Preserve the two-column settings layout: left label/description and right content area.
- Be careful with responsive changes: this page currently has large fixed widths and desktop-oriented spacing.
Known Maintenance Notes
RegionSection.vueimportsRegionValuefrom../types, buttypes.tscurrently does not exportRegionValue. If touching region typing, define/export a proper region type instead of usingany.ProfileSection.vuecurrently includesconsole.log(file)anddebuggerin avatar upload. Remove these when working on avatar upload.ProfileSection.vuereadsavatarUrlthrough(displayData as any)even thoughSettingsDatadoes not include it. If avatar display is changed, type the field explicitly.- Some verification button markup in
SecuritySection.vueis commented out. Prefer either restoring it intentionally or deleting stale comments when working in that area.
Verification
- For type-only or state-flow changes, run
npm run type-checkwhen feasible. - For production-impacting changes, run
npm run build-typeCheckwhen feasible. - Do not start
npm run devunless the user explicitly asks or has approved runtime verification. - If you cannot run checks, explain why in the final response.