mirror of
https://github.com/pure-admin/pure-admin-thin.git
synced 2026-01-06 21:50:43 +08:00
release: update 5.1.0
This commit is contained in:
@@ -1,9 +1,14 @@
|
||||
import { ref } from "vue";
|
||||
import { getConfig } from "@/config";
|
||||
import { useLayout } from "./useLayout";
|
||||
import { themeColorsType } from "../types";
|
||||
import { useGlobal } from "@pureadmin/utils";
|
||||
import { removeToken } from "@/utils/auth";
|
||||
import { routerArrays } from "@/layout/types";
|
||||
import { router, resetRouter } from "@/router";
|
||||
import type { themeColorsType } from "../types";
|
||||
import { useAppStoreHook } from "@/store/modules/app";
|
||||
import { useGlobal, storageLocal } from "@pureadmin/utils";
|
||||
import { useEpThemeStoreHook } from "@/store/modules/epTheme";
|
||||
import { useMultiTagsStoreHook } from "@/store/modules/multiTags";
|
||||
import {
|
||||
darken,
|
||||
lighten,
|
||||
@@ -13,42 +18,55 @@ import {
|
||||
export function useDataThemeChange() {
|
||||
const { layoutTheme, layout } = useLayout();
|
||||
const themeColors = ref<Array<themeColorsType>>([
|
||||
/* 道奇蓝(默认) */
|
||||
{ color: "#1b2a47", themeColor: "default" },
|
||||
/* 亮白色 */
|
||||
{ color: "#ffffff", themeColor: "light" },
|
||||
/* 道奇蓝 */
|
||||
{ color: "#1b2a47", themeColor: "default" },
|
||||
/* 深紫罗兰色 */
|
||||
{ color: "#722ed1", themeColor: "saucePurple" },
|
||||
/* 深粉色 */
|
||||
{ color: "#eb2f96", themeColor: "pink" },
|
||||
/* 猩红色 */
|
||||
{ color: "#f5222d", themeColor: "dusk" },
|
||||
/* 橙红色 */
|
||||
{ color: "#fa541c", themeColor: "volcano" },
|
||||
/* 金色 */
|
||||
{ color: "#fadb14", themeColor: "yellow" },
|
||||
/* 绿宝石 */
|
||||
{ color: "#13c2c2", themeColor: "mingQing" },
|
||||
/* 酸橙绿 */
|
||||
{ color: "#52c41a", themeColor: "auroraGreen" },
|
||||
/* 深粉色 */
|
||||
{ color: "#eb2f96", themeColor: "pink" },
|
||||
/* 深紫罗兰色 */
|
||||
{ color: "#722ed1", themeColor: "saucePurple" }
|
||||
{ color: "#52c41a", themeColor: "auroraGreen" }
|
||||
]);
|
||||
|
||||
const { $storage } = useGlobal<GlobalPropertiesApi>();
|
||||
const dataTheme = ref<boolean>($storage?.layout?.darkMode);
|
||||
const overallStyle = ref<string>($storage?.layout?.overallStyle);
|
||||
const body = document.documentElement as HTMLElement;
|
||||
|
||||
function toggleClass(flag: boolean, clsName: string, target?: HTMLElement) {
|
||||
const targetEl = target || document.body;
|
||||
let { className } = targetEl;
|
||||
className = className.replace(clsName, "").trim();
|
||||
targetEl.className = flag ? `${className} ${clsName}` : className;
|
||||
}
|
||||
|
||||
/** 设置导航主题色 */
|
||||
function setLayoutThemeColor(theme = getConfig().Theme ?? "default") {
|
||||
function setLayoutThemeColor(
|
||||
theme = getConfig().Theme ?? "light",
|
||||
isClick = true
|
||||
) {
|
||||
layoutTheme.value.theme = theme;
|
||||
toggleTheme({
|
||||
scopeName: `layout-theme-${theme}`
|
||||
});
|
||||
// 如果非isClick,保留之前的themeColor
|
||||
const storageThemeColor = $storage.layout.themeColor;
|
||||
$storage.layout = {
|
||||
layout: layout.value,
|
||||
theme,
|
||||
darkMode: dataTheme.value,
|
||||
sidebarStatus: $storage.layout?.sidebarStatus,
|
||||
epThemeColor: $storage.layout?.epThemeColor
|
||||
epThemeColor: $storage.layout?.epThemeColor,
|
||||
themeColor: isClick ? theme : storageThemeColor,
|
||||
overallStyle: overallStyle.value
|
||||
};
|
||||
|
||||
if (theme === "default" || theme === "light") {
|
||||
@@ -78,27 +96,48 @@ export function useDataThemeChange() {
|
||||
}
|
||||
};
|
||||
|
||||
/** 日间、夜间主题切换 */
|
||||
function dataThemeChange() {
|
||||
/* 如果当前是light夜间主题,默认切换到default主题 */
|
||||
/** 浅色、深色整体风格切换 */
|
||||
function dataThemeChange(overall?: string) {
|
||||
overallStyle.value = overall;
|
||||
if (useEpThemeStoreHook().epTheme === "light" && dataTheme.value) {
|
||||
setLayoutThemeColor("default");
|
||||
setLayoutThemeColor("default", false);
|
||||
} else {
|
||||
setLayoutThemeColor(useEpThemeStoreHook().epTheme);
|
||||
setLayoutThemeColor(useEpThemeStoreHook().epTheme, false);
|
||||
}
|
||||
|
||||
if (dataTheme.value) {
|
||||
document.documentElement.classList.add("dark");
|
||||
} else {
|
||||
if ($storage.layout.themeColor === "light") {
|
||||
setLayoutThemeColor("light", false);
|
||||
}
|
||||
document.documentElement.classList.remove("dark");
|
||||
}
|
||||
}
|
||||
|
||||
/** 清空缓存并返回登录页 */
|
||||
function onReset() {
|
||||
removeToken();
|
||||
storageLocal().clear();
|
||||
const { Grey, Weak, MultiTagsCache, EpThemeColor, Layout } = getConfig();
|
||||
useAppStoreHook().setLayout(Layout);
|
||||
setEpThemeColor(EpThemeColor);
|
||||
useMultiTagsStoreHook().multiTagsCacheChange(MultiTagsCache);
|
||||
toggleClass(Grey, "html-grey", document.querySelector("html"));
|
||||
toggleClass(Weak, "html-weakness", document.querySelector("html"));
|
||||
router.push("/login");
|
||||
useMultiTagsStoreHook().handleTags("equal", [...routerArrays]);
|
||||
resetRouter();
|
||||
}
|
||||
|
||||
return {
|
||||
body,
|
||||
dataTheme,
|
||||
overallStyle,
|
||||
layoutTheme,
|
||||
themeColors,
|
||||
onReset,
|
||||
toggleClass,
|
||||
dataThemeChange,
|
||||
setEpThemeColor,
|
||||
setLayoutThemeColor
|
||||
|
||||
@@ -18,10 +18,12 @@ export function useLayout() {
|
||||
if (!$storage.layout) {
|
||||
$storage.layout = {
|
||||
layout: $config?.Layout ?? "vertical",
|
||||
theme: $config?.Theme ?? "default",
|
||||
theme: $config?.Theme ?? "light",
|
||||
darkMode: $config?.DarkMode ?? false,
|
||||
sidebarStatus: $config?.SidebarStatus ?? true,
|
||||
epThemeColor: $config?.EpThemeColor ?? "#409EFF"
|
||||
epThemeColor: $config?.EpThemeColor ?? "#409EFF",
|
||||
themeColor: $config?.Theme ?? "light",
|
||||
overallStyle: $config?.OverallStyle ?? "light"
|
||||
};
|
||||
}
|
||||
/** 灰色模式、色弱模式、隐藏标签页 */
|
||||
@@ -30,6 +32,7 @@ export function useLayout() {
|
||||
grey: $config?.Grey ?? false,
|
||||
weak: $config?.Weak ?? false,
|
||||
hideTabs: $config?.HideTabs ?? false,
|
||||
hideFooter: $config.HideFooter ?? true,
|
||||
showLogo: $config?.ShowLogo ?? true,
|
||||
showModel: $config?.ShowModel ?? "smart",
|
||||
multiTagsCache: $config?.MultiTagsCache ?? false
|
||||
@@ -37,7 +40,7 @@ export function useLayout() {
|
||||
}
|
||||
};
|
||||
|
||||
/** 清空缓存后从serverConfig.json读取默认配置并赋值到storage中 */
|
||||
/** 清空缓存后从platform-config.json读取默认配置并赋值到storage中 */
|
||||
const layout = computed(() => {
|
||||
return $storage?.layout.layout;
|
||||
});
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
import { storeToRefs } from "pinia";
|
||||
import { getConfig } from "@/config";
|
||||
import { emitter } from "@/utils/mitt";
|
||||
import { routeMetaType } from "../types";
|
||||
import userAvatar from "@/assets/user.jpg";
|
||||
import { getTopMenu } from "@/router/utils";
|
||||
import { useGlobal } from "@pureadmin/utils";
|
||||
import type { routeMetaType } from "../types";
|
||||
import { useRouter, useRoute } from "vue-router";
|
||||
import { router, remainingPaths } from "@/router";
|
||||
import { computed, type CSSProperties } from "vue";
|
||||
@@ -107,6 +107,11 @@ export function useNav() {
|
||||
return remainingPaths.includes(path);
|
||||
}
|
||||
|
||||
/** 获取`logo` */
|
||||
function getLogo() {
|
||||
return new URL("/logo.svg", import.meta.url).href;
|
||||
}
|
||||
|
||||
return {
|
||||
route,
|
||||
title,
|
||||
@@ -123,6 +128,7 @@ export function useNav() {
|
||||
menuSelect,
|
||||
handleResize,
|
||||
resolvePath,
|
||||
getLogo,
|
||||
isCollapse,
|
||||
pureApp,
|
||||
username,
|
||||
|
||||
@@ -1,15 +1,13 @@
|
||||
import {
|
||||
ref,
|
||||
unref,
|
||||
watch,
|
||||
computed,
|
||||
reactive,
|
||||
onMounted,
|
||||
CSSProperties,
|
||||
type CSSProperties,
|
||||
getCurrentInstance
|
||||
} from "vue";
|
||||
import { tagsViewsType } from "../types";
|
||||
import { useEventListener } from "@vueuse/core";
|
||||
import type { tagsViewsType } from "../types";
|
||||
import { useRoute, useRouter } from "vue-router";
|
||||
import { responsiveStorageNameSpace } from "@/config";
|
||||
import { useSettingStoreHook } from "@/store/modules/settings";
|
||||
@@ -43,6 +41,7 @@ export function useTags() {
|
||||
const activeIndex = ref(-1);
|
||||
// 当前右键选中的路由信息
|
||||
const currentSelect = ref({});
|
||||
const isScrolling = ref(false);
|
||||
|
||||
/** 显示模式,默认灵动模式 */
|
||||
const showModel = ref(
|
||||
@@ -153,7 +152,8 @@ export function useTags() {
|
||||
|
||||
const getTabStyle = computed((): CSSProperties => {
|
||||
return {
|
||||
transform: `translateX(${translateX.value}px)`
|
||||
transform: `translateX(${translateX.value}px)`,
|
||||
transition: isScrolling.value ? "none" : "transform 0.5s ease-in-out"
|
||||
};
|
||||
});
|
||||
|
||||
@@ -174,7 +174,7 @@ export function useTags() {
|
||||
toggleClass(true, "schedule-in", instance.refs["schedule" + index][0]);
|
||||
toggleClass(false, "schedule-out", instance.refs["schedule" + index][0]);
|
||||
} else {
|
||||
if (hasClass(instance.refs["dynamic" + index][0], "card-active")) return;
|
||||
if (hasClass(instance.refs["dynamic" + index][0], "is-active")) return;
|
||||
toggleClass(true, "card-in", instance.refs["dynamic" + index][0]);
|
||||
toggleClass(false, "card-out", instance.refs["dynamic" + index][0]);
|
||||
}
|
||||
@@ -189,7 +189,7 @@ export function useTags() {
|
||||
toggleClass(false, "schedule-in", instance.refs["schedule" + index][0]);
|
||||
toggleClass(true, "schedule-out", instance.refs["schedule" + index][0]);
|
||||
} else {
|
||||
if (hasClass(instance.refs["dynamic" + index][0], "card-active")) return;
|
||||
if (hasClass(instance.refs["dynamic" + index][0], "is-active")) return;
|
||||
toggleClass(false, "card-in", instance.refs["dynamic" + index][0]);
|
||||
toggleClass(true, "card-out", instance.refs["dynamic" + index][0]);
|
||||
}
|
||||
@@ -214,14 +214,8 @@ export function useTags() {
|
||||
}
|
||||
});
|
||||
|
||||
watch(
|
||||
() => visible.value,
|
||||
() => {
|
||||
useEventListener(document, "click", closeMenu);
|
||||
}
|
||||
);
|
||||
|
||||
return {
|
||||
Close,
|
||||
route,
|
||||
router,
|
||||
visible,
|
||||
@@ -236,6 +230,7 @@ export function useTags() {
|
||||
pureSetting,
|
||||
activeIndex,
|
||||
getTabStyle,
|
||||
isScrolling,
|
||||
iconIsActive,
|
||||
linkIsActive,
|
||||
currentSelect,
|
||||
|
||||
Reference in New Issue
Block a user