新版布局组件开发规范
状态: 试行 (Pilot) 日期: 2026-04
1. 核心原则 (Core Principles)
为解决旧版样式耦合严重、难以维护的问题,我们引入了一套全新的布局组件体系。新开发页面必须遵循以下原则:
- 组件化优先: 拒绝手写 HTML 结构(如
<div class="mainbody">),必须使用封装好的 Vue 组件。 - 样式隔离: 新组件严禁引用
assets/scss/layout/下的旧样式文件。 - 零依赖: 仅允许引用
_tokens.scss和_variables.scss中的 CSS 变量。
2. 组件体系 (Component System)
2.1 <PageContainer> 页面容器
页面顶级容器,负责统一背景色、内边距 (Padding) 和面包屑导航。
- 替代:
.mainbody,LocationBar.vue - Props:
breadcrumbs:Array<{ title: string, to?: string }>- 面包屑配置
- Slots:
default: 页面主体内容
vue
<template>
<PageContainer :breadcrumbs="[{ title: '系统设置' }, { title: '应用管理' }]">
<!-- 内容区域 -->
</PageContainer>
</template>2.2 <Toolbar> 工具栏
用于列表页顶部的搜索和操作区域,采用 Flex 布局,自动处理间距。
- 替代:
ToolbarBox.vue,.lc-toolbar-container,.filters-row - Slots:
search: 左侧搜索表单 (建议配合SearchForm使用)actions: 右侧操作按钮组 (自动靠右)
vue
<Toolbar>
<template #search>
<SearchForm ... />
</template>
<template #actions>
<el-button type="primary">新增</el-button>
</template>
</Toolbar>2.3 <PageForm> 表单容器
用于编辑页或详情页的表单布局,提供标准化的卡片样式和底部按钮区。
- 替代:
FormBox.vue,.form-box - Props:
title:String- 卡片标题 (可选)pure:Boolean- 纯净模式 (无边框/阴影),在弹窗 (Dialog) 中使用时必须设为 true。
- Slots:
default: 表单内容footer: 底部按钮区 (会自动右对齐并添加顶部分割线)
vue
<!-- 独立页面模式 -->
<PageForm title="编辑用户">
<el-form>...</el-form>
<template #footer>
<el-button>保存</el-button>
</template>
</PageForm>
<!-- 弹窗模式 (注意 pure 属性) -->
<el-dialog>
<PageForm pure>
<el-form>...</el-form>
</PageForm>
</el-dialog>3. 样式禁区 (Forbidden Styles)
在新版页面 (src/pages/*) 的 <style> 块中,严禁使用以下旧版样式类名或文件:
❌ 禁止引用的文件
@use "@/assets/scss/layout/_content.scss"@use "@/assets/scss/layout/_toolbar.scss"@use "@/assets/scss/components/_business.scss"
❌ 禁止使用的类名
.mainbody/.main-body.content-box.list-box/.l-list/.r-list.toolbar-box/.lc-toolbar.location/.location-bar
✅ 推荐做法
- 使用
<style scoped lang="scss"> - 仅引用工具变量:
@use "@/assets/scss/utils/tokens" as *; - 使用 CSS 变量控制间距:
var(--app-margin),var(--app-padding)
4. 迁移指南 (Migration Guide)
| 旧组件/类名 | 新方案 | 备注 |
|---|---|---|
ToolbarBox | <Toolbar> | 移除 layout="search, buttons" 属性,改用插槽 |
FormBox | <PageForm> | 移除 resize 等复杂逻辑,回归原生 Flex |
LocationBar | <PageContainer> | 面包屑通过 prop 传入 |
.mainbody | <PageContainer> | 根节点替换 |
注意: 旧版页面 (如
article/category) 暂不需要重构,保持现状即可。本规范仅适用于新功能开发及逐步重构的页面。
