Files
umed/web/.cursor/rules/project-conventions.mdc
T
2026-07-09 14:35:32 +08:00

78 lines
3.4 KiB
Plaintext
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
---
description: UMedGlobal 官网(Nuxt 3 + Vue 3 双语 SSR)核心架构与编码约定
alwaysApply: true
---
# UMedGlobal 官网编码规范
来华医疗服务对外官网,**Nuxt 3 + Vue 3 + TypeScript**,SSR 默认开启,中英双语。所有页面文案来自 `data/`,组件只负责渲染。
## 技术栈与约定
- Nuxt 3 自动导入:`ref` / `computed` / `useRoute` / `useState` / `useHead` 等**无需手动 import**。
- `components/`、`composables/`、`utils/` 下的内容自动注册,**直接使用,不要写 import**(仅 `import type` 与 `data/` 内容包需显式导入)。
- 路径别名统一用 `~/`(如 `~/data/...`、`~/utils/...`、`~/types/locale`)。
- 全部用 `<script setup lang="ts">`,禁止 Options API。
## 内容与代码分离(最重要)
页面/组件**不得硬编码可见文案**。所有文案放在 `data/*-content.ts`,并导出 `LocaleBundle`(中英双语)。
```ts
// data/xxx-content.ts
import type { LocaleBundle } from '~/types/locale'
export const xxxContent = { /* en 文案 */ } as const
const xxxContentZh = { /* zh 文案,结构与 en 完全一致 */ } as const
export const xxxContentBundle: LocaleBundle<typeof xxxContent> = {
en: xxxContent,
zh: xxxContentZh
}
```
页面中用 `useLocalized` 取当前语言内容,模板只渲染:
```ts
const xxx = useLocalized(xxxContentBundle) // 返回 computed
// 模板:{{ xxx.hero.title }}、v-for 遍历 xxx.items
```
- UI 级零散文案(导航、按钮、占位符)放 `locales/ui/{en,zh}.ts`,用 `useSiteLocale()` 的 `t('nav.home')` / `tr<T>('key')` 读取。
- zh 结构必须与 en 完全对齐(缺失时 `pickLocale` 回退 en,`t` 回退 en 再回退 key)。
## SEO(每个页面必做)
每个 `pages/*.vue` 必须调用 `usePageSeo({...})` 配置标题/描述,参数支持函数式响应(推荐 getter):
```ts
usePageSeo({
title: () => page.value.seo.title,
description: () => page.value.seo.description,
ogImage: '/images/hero.jpg' // 站内图用绝对路径,会自动补全为完整 URL
})
```
- 不要手写 `useHead` 拼 meta/OG/canonical/JSON-LD,统一走 `usePageSeo`。
- 结构化数据用 `~/utils/seo` 的 `JsonLdNode`,通过 `jsonLd` 传入。
- 新增可索引页面记得同步 `data/sitemap-routes.ts`。
## 样式约定
- 组件样式一律 `<style scoped>`,类名用 BEM(`.hero__title`、`.btn--ghost`)。
- 颜色/圆角/阴影/间距用 `assets/css/main.css` 的 CSS 变量:`var(--blue)` `var(--teal)` `var(--ink)` `var(--muted)` `var(--radius)` `var(--shadow)`,**不要新造硬编码主色**。
- 响应式断点统一 `@media (max-width: 900px)`,移动端多为单列。
- 图片用 `/images/...`、图标用 `/icons/...`(`public/` 下),`<img>` 配 `:alt` 并尽量带 `width`/`height` 或 `loading="lazy"`。
## 组件与服务端
- 展示型组件用 `defineProps<{...}>()` 定义类型,可选项给默认值(如 `label ?? 'Official website →'`)。
- 弹窗用 `v-model`(`defineModel` / `update:modelValue`)。
- 服务端逻辑放 `server/routes/*.ts`,用 `defineEventHandler`,输出前对动态内容做转义(参考 `sitemap.xml.ts` 的 `escapeXml`)。
## 命名
- 内容文件:`xxx-content.ts`,导出 `xxxContentBundle`;zh 文案集中放 `data/locale/zh/xxx.zh.ts`。
- composable:`useXxx.ts`;工具:`kebab-case.ts`(纯函数,无副作用)。
- 类型用 `type`(项目无 interface 习惯),常量用 `UPPER_SNAKE_CASE`。