From aa662f624a9f4b604ef76fc21bbae3701db9fd37 Mon Sep 17 00:00:00 2001
From: SuperCuteXiaoSi <1531733886@qq.com>
Date: Tue, 4 Jan 2022 17:19:38 +0800
Subject: [PATCH] =?UTF-8?q?feature:=20=E6=B7=BB=E5=8A=A0=E5=8A=A8=E6=80=81?=
=?UTF-8?q?=E4=B8=BB=E9=A2=98=E5=88=87=E6=8D=A2?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
build/vite/optimizeDeps.ts | 23 +++---
build/vite/plugin/theme.ts | 100 +++++++++++------------
src/assets/icons/moon.svg | 16 ++++
src/assets/icons/sun.svg | 42 ++++++++++
src/components/Application/AppLocale.vue | 1 +
src/components/Application/AppTheme.vue | 63 ++++++++++++++
src/components/Application/index.ts | 2 +
src/layouts/components/AppMain/index.vue | 14 ++--
src/layouts/components/Navbart/index.vue | 3 +-
src/styles/index.scss | 2 +-
src/styles/sidebar.scss | 2 +-
src/styles/variables-dark.scss | 47 ++++++-----
src/styles/variables-day.scss | 28 ++++---
src/views/useradmin/userlist/index.vue | 2 +-
types/index.d.ts | 3 +
15 files changed, 240 insertions(+), 108 deletions(-)
create mode 100644 src/assets/icons/moon.svg
create mode 100644 src/assets/icons/sun.svg
create mode 100644 src/components/Application/AppTheme.vue
diff --git a/build/vite/optimizeDeps.ts b/build/vite/optimizeDeps.ts
index 9d648c37..863e711b 100644
--- a/build/vite/optimizeDeps.ts
+++ b/build/vite/optimizeDeps.ts
@@ -1,16 +1,13 @@
-import { DepOptimizationOptions } from 'vite'
+import { DepOptimizationOptions } from 'vite';
export function createViteOptimizeDeps(): DepOptimizationOptions {
- const viteOptimizeDeps: DepOptimizationOptions = {
- // 默认情况下,不在 node_modules 中的,链接的包不会被预构建。使用此选项可强制预构建链接的包。
- include: [
- 'element-plus/es/locale/lang/zh-tw',
- 'element-plus/es/locale/lang/en',
- ],
- // 默认情况下,Vite 会抓取你的 index.html 来检测需要预构建的依赖项。如果指定了 build.rollupOptions.input,Vite 将转而去抓取这些入口点。
- entries: [],
- // 在预构建中强制排除的依赖项。
- exclude: ['@zougt/vite-plugin-theme-preprocessor/dist/browser-utils'],
- }
- return viteOptimizeDeps
+ const viteOptimizeDeps: DepOptimizationOptions = {
+ // 默认情况下,不在 node_modules 中的,链接的包不会被预构建。使用此选项可强制预构建链接的包。
+ include: ['element-plus/es/locale/lang/zh-tw', 'element-plus/es/locale/lang/en'],
+ // 默认情况下,Vite 会抓取你的 index.html 来检测需要预构建的依赖项。如果指定了 build.rollupOptions.input,Vite 将转而去抓取这些入口点。
+ entries: [],
+ // 在预构建中强制排除的依赖项。
+ exclude: ['@zougt/vite-plugin-theme-preprocessor/dist/browser-utils'],
+ };
+ return viteOptimizeDeps;
}
diff --git a/build/vite/plugin/theme.ts b/build/vite/plugin/theme.ts
index 09da592c..7716151a 100644
--- a/build/vite/plugin/theme.ts
+++ b/build/vite/plugin/theme.ts
@@ -3,60 +3,54 @@
* https://github.com/GitOfZGT/vite-plugin-theme-preprocessor
*/
-// import type { Plugin } from 'vite'
+import type { Plugin } from 'vite';
-// import path from 'path'
-// import themePreprocessorPlugin from '@zougt/vite-plugin-theme-preprocessor'
-
-// // 此配置暂时禁止使用(原因不支持ts)
-
-// export function configThemePlugin(): Plugin | Plugin[] {
-// const options = {
-// scss: {
-// multipleScopeVars: [
-// {
-// scopeName: 'variables-theme-day',
-// path: path.resolve('src/styles/variables-day.scss'),
-// },
-// {
-// scopeName: 'variables-theme-dark',
-// path: path.resolve('src/styles/variables-dark.scss'),
-// },
-// ],
-// // 默认取 multipleScopeVars[0].scopeName
-// defaultScopeName: '',
-// // 在生产模式是否抽取独立的主题css文件,extract为true以下属性有效
-// extract: false,
-// // 独立主题css文件的输出路径,默认取 viteConfig.build.assetsDir 相对于 (viteConfig.build.outDir)
-// outputDir: '',
-// // 会选取defaultScopeName对应的主题css文件在html添加link
-// themeLinkTagId: 'theme-link-tag',
-// // "head"||"head-prepend" || "body" ||"body-prepend"
-// themeLinkTagInjectTo: 'head',
-// // 是否对抽取的css文件内对应scopeName的权重类名移除
-// removeCssScopeName: false,
-// // 可以自定义css文件名称的函数
-// customThemeCssFileName: (scopeName: string) => scopeName,
-// },
-// // less: {
-// // multipleScopeVars: [
-// // {
-// // scopeName: "theme-default",
-// // path: path.resolve("src/theme/default-vars.less"),
-// // },
-// // {
-// // scopeName: "theme-mauve",
-// // path: path.resolve("src/theme/mauve-vars.less"),
-// // },
-// // ],
-// // },
-// }
-// const plugin: Plugin[] = [themePreprocessorPlugin(options)]
-
-// return plugin
-// }
+import path from 'path';
+import { themePreprocessorPlugin } from '@zougt/vite-plugin-theme-preprocessor';
+// 此配置暂时禁止使用(原因不支持ts)
export function configThemePlugin(): Plugin | Plugin[] {
- const plugin: Plugin[] = []
- return plugin
+ const options = {
+ scss: {
+ multipleScopeVars: [
+ {
+ scopeName: 'variables-theme-day',
+ path: path.resolve('src/styles/variables-day.scss'),
+ },
+ {
+ scopeName: 'variables-theme-dark',
+ path: path.resolve('src/styles/variables-dark.scss'),
+ },
+ ],
+ // 默认取 multipleScopeVars[0].scopeName
+ defaultScopeName: '',
+ // 在生产模式是否抽取独立的主题css文件,extract为true以下属性有效
+ extract: false,
+ // 独立主题css文件的输出路径,默认取 viteConfig.build.assetsDir 相对于 (viteConfig.build.outDir)
+ outputDir: '',
+ // 会选取defaultScopeName对应的主题css文件在html添加link
+ themeLinkTagId: 'theme-link-tag',
+ // "head"||"head-prepend" || "body" ||"body-prepend"
+ themeLinkTagInjectTo: 'head',
+ // 是否对抽取的css文件内对应scopeName的权重类名移除
+ removeCssScopeName: false,
+ // 可以自定义css文件名称的函数
+ customThemeCssFileName: (scopeName: string) => scopeName,
+ },
+ // less: {
+ // multipleScopeVars: [
+ // {
+ // scopeName: "theme-default",
+ // path: path.resolve("src/theme/default-vars.less"),
+ // },
+ // {
+ // scopeName: "theme-mauve",
+ // path: path.resolve("src/theme/mauve-vars.less"),
+ // },
+ // ],
+ // },
+ };
+ const plugin: Plugin[] = [themePreprocessorPlugin(options)];
+
+ return plugin;
}
diff --git a/src/assets/icons/moon.svg b/src/assets/icons/moon.svg
new file mode 100644
index 00000000..e6667f0d
--- /dev/null
+++ b/src/assets/icons/moon.svg
@@ -0,0 +1,16 @@
+
+
diff --git a/src/assets/icons/sun.svg b/src/assets/icons/sun.svg
new file mode 100644
index 00000000..a3997cbf
--- /dev/null
+++ b/src/assets/icons/sun.svg
@@ -0,0 +1,42 @@
+
+
diff --git a/src/components/Application/AppLocale.vue b/src/components/Application/AppLocale.vue
index a775b5d7..14bd485d 100644
--- a/src/components/Application/AppLocale.vue
+++ b/src/components/Application/AppLocale.vue
@@ -37,6 +37,7 @@
diff --git a/src/components/Application/AppTheme.vue b/src/components/Application/AppTheme.vue
new file mode 100644
index 00000000..bafe4a88
--- /dev/null
+++ b/src/components/Application/AppTheme.vue
@@ -0,0 +1,63 @@
+
+