docs/archives/122-naive-ui-migration/functional-design.md
文档版本: v1.0
创建日期: 2025-01-01
最后更新: 2025-01-01
设计负责人: 开发团队
基于Naive UI构建现代化的组件系统,保持现有功能完整性的同时,大幅提升界面美观度和代码可维护性。
| 现有组件 | 目标组件 | 文件位置 | 迁移复杂度 |
|---|---|---|---|
el-button | n-button | BasicTestMode.vue, TestPanel.vue | 简单 |
el-input | n-input | ModelManager.vue, InputPanel.vue | 简单 |
el-select | n-select | ModelManager.vue | 中等 |
el-dialog | n-modal | UpdaterModal.vue | 中等 |
el-form | n-form | ModelManager.vue | 复杂 |
| 现有类名 | 目标组件 | 使用频率 | 迁移策略 |
|---|---|---|---|
theme-button-* | n-button + 自定义主题 | 高 | 统一API,保持变体 |
theme-input | n-input + 主题变量 | 高 | CSS变量映射 |
theme-card | n-card + 自定义样式 | 高 | 保持现有布局 |
theme-modal | n-modal + 主题配置 | 中 | API适配 |
| 现有类名 | 目标方案 | 优化建议 |
|---|---|---|
theme-manager-* | 简化为通用组件 | 减少特定场景类 |
theme-dropdown-* | n-dropdown + 主题 | 统一下拉组件 |
theme-history-* | n-card + n-list | 组合式设计 |
// 主题配置接口
interface ThemeConfig {
common: CommonTheme;
light: LightTheme;
dark: DarkTheme;
blue: BlueTheme;
green: GreenTheme;
purple: PurpleTheme;
}
// 设计token结构
interface DesignTokens {
colors: {
primary: string;
secondary: string;
background: string;
surface: string;
text: string;
border: string;
};
spacing: {
xs: string;
sm: string;
md: string;
lg: string;
xl: string;
};
typography: {
fontSize: Record<string, string>;
fontWeight: Record<string, number>;
};
}
Light Theme (默认)
Dark Theme
Blue Theme
Green Theme
Purple Theme
/* 使用CSS变量实现主题 */
:root {
--n-primary-color: #0ea5e9;
--n-primary-color-hover: #0284c7;
--n-primary-color-pressed: #0369a1;
}
:root[data-theme="dark"] {
--n-primary-color: #64748b;
--n-primary-color-hover: #475569;
--n-primary-color-pressed: #334155;
}
// 现有按钮类 → Naive UI实现
interface ButtonVariants {
'theme-button-primary': 'primary' | 'default';
'theme-button-secondary': 'default' | 'tertiary';
'theme-button-toggle-active': 'primary';
'theme-button-toggle-inactive': 'default';
'theme-icon-button': 'default' + icon;
}
<!-- 统一按钮组件 -->
<template>
<n-button
:type="buttonType"
:size="size"
:ghost="ghost"
:loading="loading"
@click="handleClick"
>
<template #icon v-if="icon">
<component :is="icon" />
</template>
<slot />
</n-button>
</template>
<!-- 主题化输入组件 -->
<template>
<n-input
v-model:value="modelValue"
:type="type"
:placeholder="placeholder"
:disabled="disabled"
:size="size"
class="theme-input-wrapper"
/>
</template>
<style scoped>
.theme-input-wrapper {
--n-color: var(--theme-input-bg);
--n-border: var(--theme-input-border);
--n-text-color: var(--theme-input-text);
}
</style>
<!-- 现代化卡片组件 -->
<template>
<n-card
:title="title"
:size="size"
:hoverable="hoverable"
class="theme-card-wrapper"
>
<template #header-extra v-if="$slots.actions">
<slot name="actions" />
</template>
<slot />
<template #footer v-if="$slots.footer">
<slot name="footer" />
</template>
</n-card>
</template>
const breakpoints = {
xs: '0px',
sm: '576px',
md: '768px',
lg: '992px',
xl: '1200px',
xxl: '1600px'
};
// Naive UI国际化配置
import { zhCN, enUS, jaJP } from 'naive-ui';
const naiveUILocales = {
'zh-CN': zhCN,
'en-US': enUS,
'ja-JP': jaJP,
};
// 与现有vue-i18n集成
const setupNaiveUILocale = (locale: string) => {
return naiveUILocales[locale] || enUS;
};
// vite.config.ts 配置
export default defineConfig({
plugins: [
vue(),
// Naive UI 自动导入
NaiveUiResolver(),
],
});
// 组件测试示例
describe('ThemeButton', () => {
it('should render different variants correctly', () => {
// 测试各种按钮变体
});
it('should handle theme switching', () => {
// 测试主题切换功能
});
it('should maintain accessibility', () => {
// 测试可访问性
});
});
interface PerformanceMetrics {
// 包体积变化
bundleSize: {
before: number;
after: number;
change: number;
};
// 页面加载性能
pageLoad: {
firstPaint: number;
firstContentfulPaint: number;
largestContentfulPaint: number;
};
// 主题切换性能
themeSwitch: {
duration: number;
fps: number;
};
}
// 兼容层设计
const LegacyButtonAdapter = {
'theme-button-primary': (props: any) => ({
type: 'primary',
...props
}),
'theme-button-secondary': (props: any) => ({
type: 'default',
...props
}),
// 其他映射...
};
文档状态: 设计完成
版本历史: