chore: update

This commit is contained in:
xiaoxian521 2022-08-15 15:53:27 +08:00
parent acaeb0cb42
commit f27787d560
11 changed files with 107 additions and 97 deletions

View File

@ -1,23 +1,18 @@
<script setup lang="ts"> <script setup lang="ts">
import { import { useGlobal } from "@pureadmin/utils";
h,
ref,
computed,
Transition,
defineComponent,
getCurrentInstance
} from "vue";
import backTop from "/@/assets/svg/back_top.svg?component"; import backTop from "/@/assets/svg/back_top.svg?component";
import { h, computed, Transition, defineComponent } from "vue";
import { usePermissionStoreHook } from "/@/store/modules/permission"; import { usePermissionStoreHook } from "/@/store/modules/permission";
const props = defineProps({ const props = defineProps({
fixedHeader: Boolean fixedHeader: Boolean
}); });
const keepAlive: Boolean = ref(
getCurrentInstance().appContext.config.globalProperties.$config?.KeepAlive const { $storage, $config } = useGlobal<GlobalPropertiesApi>();
);
const instance = const keepAlive = computed(() => {
getCurrentInstance().appContext.app.config.globalProperties.$storage; return $config?.KeepAlive;
});
const transitions = computed(() => { const transitions = computed(() => {
return route => { return route => {
@ -26,11 +21,11 @@ const transitions = computed(() => {
}); });
const hideTabs = computed(() => { const hideTabs = computed(() => {
return instance?.configure.hideTabs; return $storage?.configure.hideTabs;
}); });
const layout = computed(() => { const layout = computed(() => {
return instance?.layout.layout === "vertical"; return $storage?.layout.layout === "vertical";
}); });
const getSectionStyle = computed(() => { const getSectionStyle = computed(() => {

View File

@ -20,6 +20,7 @@ import { useDataThemeChange } from "/@/layout/hooks/useDataThemeChange";
import { import {
useDark, useDark,
debounce, debounce,
useGlobal,
storageLocal, storageLocal,
storageSession storageSession
} from "@pureadmin/utils"; } from "@pureadmin/utils";
@ -31,6 +32,7 @@ import darkIcon from "/@/assets/svg/dark.svg?component";
const router = useRouter(); const router = useRouter();
const { isDark } = useDark(); const { isDark } = useDark();
const { isSelect } = useCssModule(); const { isSelect } = useCssModule();
const { $storage } = useGlobal<GlobalPropertiesApi>();
const mixRef = templateRef<HTMLElement | null>("mixRef", null); const mixRef = templateRef<HTMLElement | null>("mixRef", null);
const verticalRef = templateRef<HTMLElement | null>("verticalRef", null); const verticalRef = templateRef<HTMLElement | null>("verticalRef", null);
@ -38,7 +40,6 @@ const horizontalRef = templateRef<HTMLElement | null>("horizontalRef", null);
const { const {
body, body,
instance,
dataTheme, dataTheme,
layoutTheme, layoutTheme,
themeColors, themeColors,
@ -58,17 +59,17 @@ if (unref(layoutTheme)) {
} }
/** 默认灵动模式 */ /** 默认灵动模式 */
const markValue = ref(instance.configure?.showModel ?? "smart"); const markValue = ref($storage.configure?.showModel ?? "smart");
const logoVal = ref(instance.configure?.showLogo ?? true); const logoVal = ref($storage.configure?.showLogo ?? true);
const settings = reactive({ const settings = reactive({
greyVal: instance.configure.grey, greyVal: $storage.configure.grey,
weakVal: instance.configure.weak, weakVal: $storage.configure.weak,
tabsVal: instance.configure.hideTabs, tabsVal: $storage.configure.hideTabs,
showLogo: instance.configure.showLogo, showLogo: $storage.configure.showLogo,
showModel: instance.configure.showModel, showModel: $storage.configure.showModel,
multiTagsCache: instance.configure.multiTagsCache multiTagsCache: $storage.configure.multiTagsCache
}); });
const getThemeColorStyle = computed(() => { const getThemeColorStyle = computed(() => {
@ -85,9 +86,9 @@ const showThemeColors = computed(() => {
}); });
function storageConfigureChange<T>(key: string, val: T): void { function storageConfigureChange<T>(key: string, val: T): void {
const storageConfigure = instance.configure; const storageConfigure = $storage.configure;
storageConfigure[key] = val; storageConfigure[key] = val;
instance.configure = storageConfigure; $storage.configure = storageConfigure;
} }
function toggleClass(flag: boolean, clsName: string, target?: HTMLElement) { function toggleClass(flag: boolean, clsName: string, target?: HTMLElement) {
@ -116,7 +117,7 @@ const weekChange = (value): void => {
const tagsChange = () => { const tagsChange = () => {
let showVal = settings.tabsVal; let showVal = settings.tabsVal;
storageConfigureChange("hideTabs", showVal); storageConfigureChange("hideTabs", showVal);
emitter.emit("tagViewsChange", showVal); emitter.emit("tagViewsChange", showVal as unknown as string);
}; };
const multiTagsCacheChange = () => { const multiTagsCacheChange = () => {
@ -158,7 +159,7 @@ function setFalse(Doms): any {
}); });
} }
watch(instance, ({ layout }) => { watch($storage, ({ layout }) => {
/* 设置wangeditorV5主题色 */ /* 设置wangeditorV5主题色 */
body.style.setProperty("--w-e-toolbar-active-color", layout["epThemeColor"]); body.style.setProperty("--w-e-toolbar-active-color", layout["epThemeColor"]);
switch (layout["layout"]) { switch (layout["layout"]) {
@ -203,12 +204,11 @@ const getThemeColor = computed(() => {
function setLayoutModel(layout: string) { function setLayoutModel(layout: string) {
layoutTheme.value.layout = layout; layoutTheme.value.layout = layout;
window.document.body.setAttribute("layout", layout); window.document.body.setAttribute("layout", layout);
instance.layout = { $storage.layout = {
layout, layout,
theme: layoutTheme.value.theme, theme: layoutTheme.value.theme,
darkMode: instance.layout.darkMode, darkMode: $storage.layout.darkMode,
sidebarStatus: instance.layout.sidebarStatus, sidebarStatus: $storage.layout.sidebarStatus
epThemeColor: instance.layout.epThemeColor
}; };
useAppStoreHook().setLayout(layout); useAppStoreHook().setLayout(layout);
} }

View File

@ -6,10 +6,10 @@ import avatars from "/@/assets/avatars.jpg";
import { useNav } from "/@/layout/hooks/useNav"; import { useNav } from "/@/layout/hooks/useNav";
import screenfull from "../screenfull/index.vue"; import screenfull from "../screenfull/index.vue";
import { deviceDetection } from "@pureadmin/utils"; import { deviceDetection } from "@pureadmin/utils";
import { ref, watch, nextTick, onMounted } from "vue";
import { useTranslationLang } from "../../hooks/useTranslationLang"; import { useTranslationLang } from "../../hooks/useTranslationLang";
import { usePermissionStoreHook } from "/@/store/modules/permission"; import { usePermissionStoreHook } from "/@/store/modules/permission";
import globalization from "/@/assets/svg/globalization.svg?component"; import globalization from "/@/assets/svg/globalization.svg?component";
import { ref, watch, nextTick, onMounted, onBeforeUnmount } from "vue";
const menuRef = ref(); const menuRef = ref();
@ -29,10 +29,18 @@ const {
getDropdownItemClass getDropdownItemClass
} = useNav(); } = useNav();
onMounted(() => { function onResizeMenu() {
nextTick(() => { nextTick(() => {
handleResize(menuRef.value); handleResize(menuRef.value);
}); });
}
onMounted(() => {
window.addEventListener("resize", onResizeMenu);
});
onBeforeUnmount(() => {
window.removeEventListener("resize", onResizeMenu);
}); });
watch( watch(

View File

@ -6,12 +6,12 @@ import { useNav } from "/@/layout/hooks/useNav";
import { transformI18n } from "/@/plugins/i18n"; import { transformI18n } from "/@/plugins/i18n";
import screenfull from "../screenfull/index.vue"; import screenfull from "../screenfull/index.vue";
import { deviceDetection } from "@pureadmin/utils"; import { deviceDetection } from "@pureadmin/utils";
import { ref, toRaw, watch, nextTick, onMounted } from "vue";
import { useRenderIcon } from "/@/components/ReIcon/src/hooks"; import { useRenderIcon } from "/@/components/ReIcon/src/hooks";
import { getParentPaths, findRouteByPath } from "/@/router/utils"; import { getParentPaths, findRouteByPath } from "/@/router/utils";
import { useTranslationLang } from "../../hooks/useTranslationLang"; import { useTranslationLang } from "../../hooks/useTranslationLang";
import { usePermissionStoreHook } from "/@/store/modules/permission"; import { usePermissionStoreHook } from "/@/store/modules/permission";
import globalization from "/@/assets/svg/globalization.svg?component"; import globalization from "/@/assets/svg/globalization.svg?component";
import { ref, toRaw, watch, nextTick, onMounted, onBeforeUnmount } from "vue";
const menuRef = ref(); const menuRef = ref();
let defaultActive = ref(null); let defaultActive = ref(null);
@ -42,11 +42,19 @@ function getDefaultActive(routePath) {
)?.children[0]?.path; )?.children[0]?.path;
} }
onMounted(() => { function onResizeMenu() {
getDefaultActive(route.path);
nextTick(() => { nextTick(() => {
handleResize(menuRef.value); handleResize(menuRef.value);
}); });
}
onMounted(() => {
getDefaultActive(route.path);
window.addEventListener("resize", onResizeMenu);
});
onBeforeUnmount(() => {
window.removeEventListener("resize", onResizeMenu);
}); });
watch( watch(

View File

@ -45,7 +45,7 @@ getSubMenuData(route.path);
onBeforeMount(() => { onBeforeMount(() => {
emitter.on("logoChange", key => { emitter.on("logoChange", key => {
showLogo.value = key as unknown as boolean; showLogo.value = key;
}); });
}); });

View File

@ -1,9 +1,10 @@
import { ref } from "vue";
import { getConfig } from "/@/config"; import { getConfig } from "/@/config";
import { find } from "lodash-unified"; import { find } from "lodash-unified";
import { useLayout } from "./useLayout"; import { useLayout } from "./useLayout";
import { themeColorsType } from "../types"; import { themeColorsType } from "../types";
import { TinyColor } from "@ctrl/tinycolor"; import { TinyColor } from "@ctrl/tinycolor";
import { ref, getCurrentInstance } from "vue"; import { useGlobal } from "@pureadmin/utils";
import { useEpThemeStoreHook } from "/@/store/modules/epTheme"; import { useEpThemeStoreHook } from "/@/store/modules/epTheme";
import { import {
darken, darken,
@ -34,9 +35,9 @@ export function useDataThemeChange() {
{ color: "#722ed1", themeColor: "saucePurple" } { color: "#722ed1", themeColor: "saucePurple" }
]); ]);
const { $storage } = useGlobal<GlobalPropertiesApi>();
const body = document.documentElement as HTMLElement; const body = document.documentElement as HTMLElement;
const instance =
getCurrentInstance().appContext.app.config.globalProperties.$storage;
/** 设置导航主题色 */ /** 设置导航主题色 */
function setLayoutThemeColor(theme = "default") { function setLayoutThemeColor(theme = "default") {
@ -44,8 +45,8 @@ export function useDataThemeChange() {
toggleTheme({ toggleTheme({
scopeName: `layout-theme-${theme}` scopeName: `layout-theme-${theme}`
}); });
instance.layout.theme = theme; $storage.layout.theme = theme;
instance.layout.darkMode = dataTheme.value; $storage.layout.darkMode = dataTheme.value;
if (theme === "default" || theme === "light") { if (theme === "default" || theme === "light") {
setEpThemeColor(getConfig().EpThemeColor); setEpThemeColor(getConfig().EpThemeColor);
@ -81,7 +82,7 @@ export function useDataThemeChange() {
); );
} }
}; };
const dataTheme = ref<boolean>(instance?.layout?.darkMode); const dataTheme = ref<boolean>($storage?.layout?.darkMode);
/** 日间、夜间主题切换 */ /** 日间、夜间主题切换 */
function dataThemeChange() { function dataThemeChange() {
@ -93,17 +94,16 @@ export function useDataThemeChange() {
} }
if (dataTheme.value) { if (dataTheme.value) {
instance.layout.darkMode = true; $storage.layout.darkMode = true;
document.documentElement.classList.add("dark"); document.documentElement.classList.add("dark");
} else { } else {
instance.layout.darkMode = false; $storage.layout.darkMode = false;
document.documentElement.classList.remove("dark"); document.documentElement.classList.remove("dark");
} }
} }
return { return {
body, body,
instance,
dataTheme, dataTheme,
layoutTheme, layoutTheme,
themeColors, themeColors,

View File

@ -1,60 +1,59 @@
import { computed } from "vue";
import { useI18n } from "vue-i18n"; import { useI18n } from "vue-i18n";
import { routerArrays } from "../types"; import { routerArrays } from "../types";
import { computed, getCurrentInstance } from "vue"; import { useGlobal } from "@pureadmin/utils";
import { useMultiTagsStore } from "/@/store/modules/multiTags"; import { useMultiTagsStore } from "/@/store/modules/multiTags";
export function useLayout() { export function useLayout() {
const instance = getCurrentInstance().appContext.app.config.globalProperties; const { $storage, $config } = useGlobal<GlobalPropertiesApi>();
const initStorage = () => { const initStorage = () => {
// 路由 /** 路由 */
if ( if (
useMultiTagsStore().multiTagsCache && useMultiTagsStore().multiTagsCache &&
(!instance.$storage.tags || instance.$storage.tags.length === 0) (!$storage.tags || $storage.tags.length === 0)
) { ) {
// eslint-disable-next-line vue/no-side-effects-in-computed-properties $storage.tags = routerArrays;
instance.$storage.tags = routerArrays;
} }
// 国际化 /** 国际化 */
if (!instance.$storage.locale) { if (!$storage.locale) {
// eslint-disable-next-line $storage.locale = { locale: $config?.Locale ?? "zh" };
instance.$storage.locale = { locale: instance.$config?.Locale ?? "zh" }; useI18n().locale.value = $config?.Locale ?? "zh";
useI18n().locale.value = instance.$config?.Locale ?? "zh";
} }
// 导航 /** 导航 */
if (!instance.$storage.layout) { if (!$storage.layout) {
// eslint-disable-next-line vue/no-side-effects-in-computed-properties $storage.layout = {
instance.$storage.layout = { layout: $config?.Layout ?? "vertical",
layout: instance.$config?.Layout ?? "vertical", theme: $config?.Theme ?? "default",
theme: instance.$config?.Theme ?? "default", darkMode: $config?.DarkMode ?? false,
darkMode: instance.$config?.DarkMode ?? false, sidebarStatus: $config?.SidebarStatus ?? true,
sidebarStatus: instance.$config?.SidebarStatus ?? true, epThemeColor: $config?.EpThemeColor ?? "#409EFF"
epThemeColor: instance.$config?.EpThemeColor ?? "#409EFF"
}; };
} }
// 灰色模式、色弱模式、隐藏标签页 /** 灰色模式、色弱模式、隐藏标签页 */
if (!instance.$storage.configure) { if (!$storage.configure) {
// eslint-disable-next-line $storage.configure = {
instance.$storage.configure = { grey: $config?.Grey ?? false,
grey: instance.$config?.Grey ?? false, weak: $config?.Weak ?? false,
weak: instance.$config?.Weak ?? false, hideTabs: $config?.HideTabs ?? false,
hideTabs: instance.$config?.HideTabs ?? false, showLogo: $config?.ShowLogo ?? true,
showLogo: instance.$config?.ShowLogo ?? true, showModel: $config?.ShowModel ?? "smart",
showModel: instance.$config?.ShowModel ?? "smart", multiTagsCache: $config?.MultiTagsCache ?? false
multiTagsCache: instance.$config?.MultiTagsCache ?? false
}; };
} }
}; };
// 清空缓存后从serverConfig.json读取默认配置并赋值到storage中
/** 清空缓存后从serverConfig.json读取默认配置并赋值到storage中 */
const layout = computed(() => { const layout = computed(() => {
return instance.$storage?.layout.layout; return $storage?.layout.layout;
}); });
const layoutTheme = computed(() => { const layoutTheme = computed(() => {
return instance.$storage.layout; return $storage.layout;
}); });
return { return {
layout, layout,
instance,
layoutTheme, layoutTheme,
initStorage initStorage
}; };

View File

@ -150,6 +150,7 @@ export function useNav() {
layout, layout,
logout, logout,
routers, routers,
$storage,
backHome, backHome,
onPanel, onPanel,
changeTitle, changeTitle,

View File

@ -1,23 +1,22 @@
import { useNav } from "./useNav"; import { useNav } from "./useNav";
import { useI18n } from "vue-i18n"; import { useI18n } from "vue-i18n";
import { useRoute } from "vue-router"; import { useRoute } from "vue-router";
import { watch, getCurrentInstance, type Ref } from "vue"; import { watch, type Ref } from "vue";
export function useTranslationLang(ref?: Ref) { export function useTranslationLang(ref?: Ref) {
const { changeTitle, changeWangeditorLanguage, handleResize } = useNav(); const { $storage, changeTitle, changeWangeditorLanguage, handleResize } =
useNav();
const { locale, t } = useI18n(); const { locale, t } = useI18n();
const route = useRoute(); const route = useRoute();
const instance =
getCurrentInstance().appContext.config.globalProperties.$storage;
function translationCh() { function translationCh() {
instance.locale = { locale: "zh" }; $storage.locale = { locale: "zh" };
locale.value = "zh"; locale.value = "zh";
ref && handleResize(ref.value); ref && handleResize(ref.value);
} }
function translationEn() { function translationEn() {
instance.locale = { locale: "en" }; $storage.locale = { locale: "en" };
locale.value = "en"; locale.value = "en";
ref && handleResize(ref.value); ref && handleResize(ref.value);
} }

View File

@ -3,8 +3,8 @@ import { setType } from "./types";
import { emitter } from "/@/utils/mitt"; import { emitter } from "/@/utils/mitt";
import { useLayout } from "./hooks/useLayout"; import { useLayout } from "./hooks/useLayout";
import { useAppStoreHook } from "/@/store/modules/app"; import { useAppStoreHook } from "/@/store/modules/app";
import { deviceDetection, useDark } from "@pureadmin/utils";
import { useSettingStoreHook } from "/@/store/modules/settings"; import { useSettingStoreHook } from "/@/store/modules/settings";
import { deviceDetection, useDark, useGlobal } from "@pureadmin/utils";
import { h, reactive, computed, onMounted, defineComponent } from "vue"; import { h, reactive, computed, onMounted, defineComponent } from "vue";
import backTop from "/@/assets/svg/back_top.svg?component"; import backTop from "/@/assets/svg/back_top.svg?component";
@ -19,10 +19,10 @@ import Vertical from "./components/sidebar/vertical.vue";
import Horizontal from "./components/sidebar/horizontal.vue"; import Horizontal from "./components/sidebar/horizontal.vue";
const { isDark } = useDark(); const { isDark } = useDark();
const { layout } = useLayout();
const isMobile = deviceDetection(); const isMobile = deviceDetection();
const pureSetting = useSettingStoreHook(); const pureSetting = useSettingStoreHook();
const { $storage } = useGlobal<GlobalPropertiesApi>();
const { instance, layout } = useLayout();
const set: setType = reactive({ const set: setType = reactive({
sidebar: computed(() => { sidebar: computed(() => {
@ -47,18 +47,18 @@ const set: setType = reactive({
}), }),
hideTabs: computed(() => { hideTabs: computed(() => {
return instance.$storage?.configure.hideTabs; return $storage?.configure.hideTabs;
}) })
}); });
function setTheme(layoutModel: string) { function setTheme(layoutModel: string) {
window.document.body.setAttribute("layout", layoutModel); window.document.body.setAttribute("layout", layoutModel);
instance.$storage.layout = { $storage.layout = {
layout: `${layoutModel}`, layout: `${layoutModel}`,
theme: instance.$storage.layout?.theme, theme: $storage.layout?.theme,
darkMode: instance.$storage.layout?.darkMode, darkMode: $storage.layout?.darkMode,
sidebarStatus: instance.$storage.layout?.sidebarStatus, sidebarStatus: $storage.layout?.sidebarStatus,
epThemeColor: instance.$storage.layout?.epThemeColor epThemeColor: $storage.layout?.epThemeColor
}; };
} }

View File

@ -11,7 +11,7 @@ type Events = {
openPanel: string; openPanel: string;
tagViewsChange: string; tagViewsChange: string;
tagViewsShowModel: string; tagViewsShowModel: string;
logoChange: string; logoChange: boolean;
changLayoutRoute: { changLayoutRoute: {
indexPath: string; indexPath: string;
parentPath: string; parentPath: string;