优化更新
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
# 样式与主题
|
||||
|
||||
:::tip 说明
|
||||
前端样式方案采用 Tailwind CSS + SCSS + ElementPlus 主题覆盖,支持深色模式切换。全局 SCSS 变量通过 Vite 的 `additionalData` 注入。
|
||||
前端样式方案采用 Tailwind CSS + SCSS + AntDesign Vue 主题覆盖,支持深色模式切换。全局 SCSS 变量通过 Vite 的 `additionalData` 注入。
|
||||
:::
|
||||
|
||||
## 样式架构
|
||||
@@ -11,7 +11,7 @@ src/styles/
|
||||
├── var.scss # SCSS 全局变量(通过 Vite additionalData 注入)
|
||||
├── index.scss # 入口文件,引入所有样式
|
||||
├── tailwindbase.css # Tailwind CSS 基础样式
|
||||
└── element-override.css # ElementPlus 主题覆盖(可选)
|
||||
└── ant-override.css # AntDesign Vue 主题覆盖(可选)
|
||||
```
|
||||
|
||||
## SCSS 全局变量
|
||||
@@ -56,36 +56,33 @@ import './styles/tailwindbase.css';
|
||||
<div class="w-full md:w-1/2 lg:w-1/3">响应式宽度</div>
|
||||
```
|
||||
|
||||
## ElementPlus 主题
|
||||
## AntDesign Vue 主题
|
||||
|
||||
ElementPlus 通过 CSS 变量支持主题定制:
|
||||
AntDesign Vue 通过 CSS 变量和 ConfigProvider 支持主题定制:
|
||||
|
||||
```typescript
|
||||
// main.ts
|
||||
import 'element-plus/dist/index.css';
|
||||
import 'element-plus/theme-chalk/display.css';
|
||||
import 'element-plus/theme-chalk/dark/css-vars.css'; // 深色模式 CSS 变量
|
||||
import 'ant-design-vue/dist/reset.css';
|
||||
```
|
||||
|
||||
### ElementPlus 全局引入
|
||||
### AntDesign Vue 全局引入
|
||||
|
||||
```typescript
|
||||
// src/plugins/setupElement.ts
|
||||
import ElementPlus from 'element-plus';
|
||||
import zhCn from 'element-plus/es/locale/lang/zh-cn';
|
||||
// src/plugins/setupAntd.ts
|
||||
import Antd from 'ant-design-vue';
|
||||
|
||||
export function setupElement(app) {
|
||||
app.use(ElementPlus, { locale: zhCn, size: 'default' });
|
||||
export function setupAntd(app) {
|
||||
app.use(Antd);
|
||||
}
|
||||
```
|
||||
|
||||
## 深色模式
|
||||
|
||||
通过 ElementPlus 的 `dark/css-vars.css` 和 Tailwind 的 `dark` 模式实现深色主题:
|
||||
通过 AntDesign Vue 的 ConfigProvider 和 Tailwind 的 `dark` 模式实现深色主题:
|
||||
|
||||
```vue
|
||||
<template>
|
||||
<el-switch v-model="isDark" @change="toggleDark" />
|
||||
<a-switch v-model:checked="isDark" @change="toggleDark" />
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
@@ -100,9 +97,9 @@ const toggleDark = (val) => {
|
||||
|
||||
```css
|
||||
.dark {
|
||||
--el-bg-color: #1d1e1f;
|
||||
--el-text-color-primary: #e5eaf3;
|
||||
--el-border-color: #4c4d4f;
|
||||
--ant-color-bg-base: #1d1e1f;
|
||||
--ant-color-text: #e5eaf3;
|
||||
--ant-color-border: #4c4d4f;
|
||||
}
|
||||
```
|
||||
|
||||
@@ -130,12 +127,12 @@ export function useDesignSetting() {
|
||||
```vue
|
||||
<template>
|
||||
<PageWrapper>
|
||||
<el-card :bordered="false" class="pt-3 mb-3 proCard">
|
||||
<a-card :bordered="false" class="pt-3 mb-3 proCard">
|
||||
<!-- 搜索区域 -->
|
||||
</el-card>
|
||||
<el-card :bordered="false" class="proCard">
|
||||
</a-card>
|
||||
<a-card :bordered="false" class="proCard">
|
||||
<!-- 表格区域 -->
|
||||
</el-card>
|
||||
</a-card>
|
||||
</PageWrapper>
|
||||
</template>
|
||||
```
|
||||
@@ -150,4 +147,4 @@ export function useDesignSetting() {
|
||||
|
||||
## 总结
|
||||
|
||||
样式方案采用 Tailwind CSS 提供原子化样式 + SCSS 全局变量(Vite `additionalData` 注入)+ ElementPlus 主题覆盖,支持深色模式切换。`designSetting` store 管理主题配置,`PageWrapper` 组件提供统一页面容器。
|
||||
样式方案采用 Tailwind CSS 提供原子化样式 + SCSS 全局变量(Vite `additionalData` 注入)+ AntDesign Vue 主题覆盖,支持深色模式切换。`designSetting` store 管理主题配置,`PageWrapper` 组件提供统一页面容器。
|
||||
|
||||
Reference in New Issue
Block a user