diff --git a/index.html b/index.html index e0254d1..f74d157 100644 --- a/index.html +++ b/index.html @@ -25,15 +25,21 @@ "Microsoft YaHei", "微软雅黑", Arial, sans-serif; } - .preload { + .preload__wrap { display: flex; flex-direction: column; height: 100%; letter-spacing: 1px; background-color: #2f3447; + position: fixed; + left: 0; + top: 0; + height: 100%; + width: 100%; + z-index: 9999; } - .preload .container { + .preload__container { display: flex; justify-content: center; align-items: center; @@ -43,7 +49,7 @@ flex-grow: 1; } - .preload .name { + .preload__name { font-size: 30px; color: #fff; letter-spacing: 5px; @@ -51,29 +57,29 @@ margin-bottom: 30px; } - .preload .title { + .preload__title { color: #fff; font-size: 14px; margin: 30px 0 20px 0; } - .preload .sub-title { + .preload__sub-title { color: #ababab; font-size: 12px; } - .preload .footer { + .preload__footer { text-align: center; padding: 10px 0 20px 0; } - .preload .footer a { + .preload__footer a { font-size: 12px; color: #ababab; text-decoration: none; } - .preload .loading { + .preload__loading { height: 30px; width: 30px; border-radius: 30px; @@ -94,8 +100,8 @@ } } - .preload .loading::after, - .preload .loading::before { + .preload__loading::after, + .preload__loading::before { content: ""; display: inline-block; position: absolute; @@ -106,11 +112,11 @@ background-color: currentColor; } - .preload .loading::after { + .preload__loading::after { left: -1px; } - .preload .loading::before { + .preload__loading::before { right: -1px; } @@ -139,15 +145,15 @@
-
-
-

COOL-ADMIN

-
-

正在加载资源...

-

初次加载资源可能需要较多时间 请耐心等待

+
+
+

COOL-ADMIN

+
+

正在加载资源...

+

初次加载资源可能需要较多时间 请耐心等待

- diff --git a/package.json b/package.json index 4f0e801..ae008bf 100644 --- a/package.json +++ b/package.json @@ -9,10 +9,10 @@ "lint:eslint": "eslint \"{src,mock}/**/*.{vue,ts,tsx}\" --fix" }, "dependencies": { - "@cool-vue/crud": "^5.0.5", + "@cool-vue/crud": "^5.0.6", "@element-plus/icons-vue": "^1.1.3", + "@vueuse/core": "^8.2.5", "axios": "^0.26.1", - "clipboard": "^2.0.10", "codemirror": "^5.62.0", "core-js": "^3.6.5", "echarts": "^5.0.2", @@ -26,6 +26,7 @@ "pinia": "^2.0.12", "quill": "^1.3.7", "store": "^2.0.12", + "unocss": "^0.31.0", "uuid": "^8.3.2", "vue": "^3.2.31", "vue-echarts": "^6.0.2", @@ -38,9 +39,11 @@ "@types/node": "^16.10.2", "@types/nprogress": "^0.2.0", "@types/quill": "^2.0.9", + "@types/store": "^2.0.2", "@types/uuid": "^8.3.4", "@typescript-eslint/eslint-plugin": "^4.20.0", "@typescript-eslint/parser": "^4.20.0", + "@unocss/preset-uno": "^0.31.0", "@vitejs/plugin-vue": "^2.2.4", "@vitejs/plugin-vue-jsx": "^1.3.8", "@vue/cli-plugin-babel": "^5.0.1", diff --git a/src/App.vue b/src/App.vue index 331a50a..d4a7cb7 100644 --- a/src/App.vue +++ b/src/App.vue @@ -1,14 +1,14 @@ - - diff --git a/src/modules/base/pages/layout/components/process.vue b/src/modules/base/pages/layout/components/process.vue index f198ab6..77477e6 100644 --- a/src/modules/base/pages/layout/components/process.vue +++ b/src/modules/base/pages/layout/components/process.vue @@ -204,7 +204,7 @@ watch( &:hover { color: #fff; - background-color: $color-primary; + background-color: var(--color-primary); } } @@ -221,7 +221,7 @@ watch( &.active { span { - color: $color-primary; + color: var(--color-primary); } i { @@ -230,7 +230,7 @@ watch( } &:before { - background-color: $color-primary; + background-color: var(--color-primary); } } } diff --git a/src/modules/base/pages/layout/components/slider.vue b/src/modules/base/pages/layout/components/slider.vue index 1bea424..cc6aca3 100644 --- a/src/modules/base/pages/layout/components/slider.vue +++ b/src/modules/base/pages/layout/components/slider.vue @@ -102,7 +102,9 @@ export default defineComponent({ return (
- {e.name} + + {e.name} +
); } @@ -153,7 +155,7 @@ export default defineComponent({ .app-slider { height: 100%; box-shadow: 0 4px 8px rgba(0, 0, 0, 0.3); - background-color: #2f3447; + background-color: var(--menu-bg-color); &__logo { display: flex; @@ -209,10 +211,11 @@ export default defineComponent({ &-item { &.is-active, &:hover { - background-color: $color-primary !important; + background-color: var(--color-primary) !important; .icon-svg, span { + // color: var(--menu-font-color); color: #fff; } } @@ -221,7 +224,7 @@ export default defineComponent({ .el-sub-menu__title, &-item, &__title { - color: #eee; + color: var(--menu-font-color); letter-spacing: 0.5px; height: 50px; line-height: 50px; diff --git a/src/modules/base/pages/layout/components/topbar.vue b/src/modules/base/pages/layout/components/topbar.vue index dfbfa95..165d029 100644 --- a/src/modules/base/pages/layout/components/topbar.vue +++ b/src/modules/base/pages/layout/components/topbar.vue @@ -16,7 +16,9 @@
-
    +
      + +
    diff --git a/src/modules/base/pages/layout/index.vue b/src/modules/base/pages/layout/index.vue index a3cf360..b366445 100644 --- a/src/modules/base/pages/layout/index.vue +++ b/src/modules/base/pages/layout/index.vue @@ -27,7 +27,7 @@ const { app } = useBaseStore(); diff --git a/src/modules/theme/config.ts b/src/modules/theme/config.ts new file mode 100644 index 0000000..83b12ad --- /dev/null +++ b/src/modules/theme/config.ts @@ -0,0 +1,11 @@ +export default { + name: "blue" + // color: "", + // rules: { + // "--view-bg-color": "#f7f7f7", + // "--menu-bg-color": "#2f3447", + // "--menu-font-color": "#ffffff", + // "--topbar-bg-color": "#ffffff", + // "--topbar-font-color": "#000000" + // } +}; diff --git a/src/modules/theme/index.ts b/src/modules/theme/index.ts new file mode 100644 index 0000000..bce4543 --- /dev/null +++ b/src/modules/theme/index.ts @@ -0,0 +1,13 @@ +import store from "store"; +import { App } from "vue"; +import { setTheme } from "./utils"; + +export default { + install(_: App, options: any) { + const theme = store.get("theme") || options; + + if (theme) { + setTheme(theme); + } + } +}; diff --git a/src/modules/theme/utils/index.ts b/src/modules/theme/utils/index.ts new file mode 100644 index 0000000..81fb77c --- /dev/null +++ b/src/modules/theme/utils/index.ts @@ -0,0 +1,116 @@ +import store from "store"; + +function mix(color1: string, color2: string, weight: number) { + weight = Math.max(Math.min(Number(weight), 1), 0); + const r1 = parseInt(color1.substring(1, 3), 16); + const g1 = parseInt(color1.substring(3, 5), 16); + const b1 = parseInt(color1.substring(5, 7), 16); + const r2 = parseInt(color2.substring(1, 3), 16); + const g2 = parseInt(color2.substring(3, 5), 16); + const b2 = parseInt(color2.substring(5, 7), 16); + let r = Math.round(r1 * (1 - weight) + r2 * weight).toString(16); + let g = Math.round(g1 * (1 - weight) + g2 * weight).toString(16); + let b = Math.round(b1 * (1 - weight) + b2 * weight).toString(16); + r = ("0" + (r || 0).toString(16)).slice(-2); + g = ("0" + (g || 0).toString(16)).slice(-2); + b = ("0" + (b || 0).toString(16)).slice(-2); + return "#" + r + g + b; +} + +export const themes = [ + { + label: "钴蓝", + name: "blue", + color: "#4165d7", + rules: { + "--menu-bg-color": "#2f3447", + "--menu-font-color": "#ffffff" + } + }, + { + label: "极黑", + name: "black", + color: "#2f3447" + }, + { + label: "果绿", + name: "green", + color: "#51C21A" + }, + { + label: "酱紫", + name: "purple", + color: "#d0378d", + rules: { + "--view-bg-color": "#f7f7f7", + "--menu-bg-color": "#ffffff", + "--menu-font-color": "#000000" + } + } +]; + +declare interface Options { + color?: string; + name?: string; + rules?: any; +} + +export function setTheme({ color, name, rules }: Options) { + // 主题配置 + const theme = store.get("theme") || {}; + + // 变量前缀 + const pre = "--el-color-primary"; + + // 白色混合色 + const mixWhite = "#ffffff"; + + // 黑色混合色 + const mixBlack = "#000000"; + + // 元素 + const el = document.documentElement; + + // 主题 + if (name) { + const item = themes.find((e) => e.name == name); + + if (item) { + theme.name = name; + color = item.color; + rules = item.rules; + + switch (name) { + case "blue": + break; + case "black": + break; + } + } + } + + // 设置主色 + if (color) { + el.style.setProperty(pre, color); + el.style.setProperty("--color-primary", color); + + // 设置辅色 + for (let i = 1; i < 10; i += 1) { + el.style.setProperty(`${pre}-light-${i}`, mix(color, mixWhite, i * 0.1)); + el.style.setProperty(`${pre}-dark-${i}`, mix(color, mixBlack, i * 0.1)); + } + + // 缓存 + theme.color = color; + } + + if (rules) { + for (const i in rules) { + el.style.setProperty(i, rules[i]); + } + } + + console.log(theme); + + store.set("theme", theme); +} diff --git a/src/modules/upload/components/index.vue b/src/modules/upload/components/index.vue index b9794d7..d3b0fd9 100644 --- a/src/modules/upload/components/index.vue +++ b/src/modules/upload/components/index.vue @@ -520,7 +520,7 @@ defineExpose({ &:hover { border-color: currentColor; - color: $color-primary; + color: var(--color-primary); .cl-upload__actions { display: inline-flex; diff --git a/src/modules/upload/components/space.vue b/src/modules/upload/components/space.vue index 3a91eba..a32857f 100644 --- a/src/modules/upload/components/space.vue +++ b/src/modules/upload/components/space.vue @@ -396,7 +396,7 @@ defineExpose({ cursor: pointer; &:hover { - border-color: $color-primary; + border-color: var(--color-primary); } i { diff --git a/src/modules/upload/components/space/category.vue b/src/modules/upload/components/space/category.vue index 19afb7e..61db783 100644 --- a/src/modules/upload/components/space/category.vue +++ b/src/modules/upload/components/space/category.vue @@ -248,7 +248,7 @@ onMounted(() => { cursor: pointer; &.is-active { - color: $color-primary; + color: var(--color-primary); } &:hover { diff --git a/src/modules/upload/components/space/file-item.vue b/src/modules/upload/components/space/file-item.vue index 29d3413..ee71bd6 100644 --- a/src/modules/upload/components/space/file-item.vue +++ b/src/modules/upload/components/space/file-item.vue @@ -55,12 +55,14 @@