mirror of
https://github.com/pure-admin/vue-pure-admin.git
synced 2025-06-07 08:57:19 +08:00
perf: layout style
This commit is contained in:
parent
73705eb0e4
commit
0eb0b7395e
@ -29,10 +29,21 @@ const transitions = computed(() => {
|
|||||||
const hideTabs = computed(() => {
|
const hideTabs = computed(() => {
|
||||||
return instance?.sets.hideTabs;
|
return instance?.sets.hideTabs;
|
||||||
});
|
});
|
||||||
|
|
||||||
const layout = computed(() => {
|
const layout = computed(() => {
|
||||||
return instance?.layout.layout === "vertical";
|
return instance?.layout.layout === "vertical";
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const getSectionStyle = computed(() => {
|
||||||
|
return [
|
||||||
|
hideTabs.value && layout ? "padding-top: 48px;" : "",
|
||||||
|
!hideTabs.value && layout ? "padding-top: 85px;" : "",
|
||||||
|
hideTabs.value && !layout.value ? "padding-top: 48px" : "",
|
||||||
|
!hideTabs.value && !layout.value ? "padding-top: 85px;" : "",
|
||||||
|
props.fixedHeader ? "" : "padding-top: 0;"
|
||||||
|
];
|
||||||
|
});
|
||||||
|
|
||||||
const transitionMain = defineComponent({
|
const transitionMain = defineComponent({
|
||||||
render() {
|
render() {
|
||||||
return h(
|
return h(
|
||||||
@ -71,12 +82,7 @@ const transitionMain = defineComponent({
|
|||||||
<template>
|
<template>
|
||||||
<section
|
<section
|
||||||
:class="[props.fixedHeader ? 'app-main' : 'app-main-nofixed-header']"
|
:class="[props.fixedHeader ? 'app-main' : 'app-main-nofixed-header']"
|
||||||
:style="[
|
:style="getSectionStyle"
|
||||||
hideTabs && layout ? 'padding-top: 48px;' : '',
|
|
||||||
!hideTabs && layout ? 'padding-top: 85px;' : '',
|
|
||||||
hideTabs && !layout ? 'padding-top: 48px' : '',
|
|
||||||
!hideTabs && !layout ? 'padding-top: 85px;' : ''
|
|
||||||
]"
|
|
||||||
>
|
>
|
||||||
<router-view>
|
<router-view>
|
||||||
<template #default="{ Component, route }">
|
<template #default="{ Component, route }">
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
|
import { computed } from "vue";
|
||||||
import { useI18n } from "vue-i18n";
|
import { useI18n } from "vue-i18n";
|
||||||
import { emitter } from "/@/utils/mitt";
|
import { emitter } from "/@/utils/mitt";
|
||||||
import Notice from "./notice/index.vue";
|
import Notice from "./notice/index.vue";
|
||||||
@ -22,6 +23,15 @@ const route = useRoute();
|
|||||||
let usename = storageSession.getItem("info")?.username;
|
let usename = storageSession.getItem("info")?.username;
|
||||||
const { locale } = useI18n();
|
const { locale } = useI18n();
|
||||||
|
|
||||||
|
const getDropdownItemStyle = computed(() => {
|
||||||
|
return t => {
|
||||||
|
return {
|
||||||
|
background: locale.value === t ? "#1b2a47" : "",
|
||||||
|
color: locale.value === t ? "#f4f4f5" : "#000"
|
||||||
|
};
|
||||||
|
};
|
||||||
|
});
|
||||||
|
|
||||||
watch(
|
watch(
|
||||||
() => locale.value,
|
() => locale.value,
|
||||||
() => {
|
() => {
|
||||||
@ -82,20 +92,14 @@ function translationEn() {
|
|||||||
<template #dropdown>
|
<template #dropdown>
|
||||||
<el-dropdown-menu class="translation">
|
<el-dropdown-menu class="translation">
|
||||||
<el-dropdown-item
|
<el-dropdown-item
|
||||||
:style="{
|
:style="getDropdownItemStyle('zh')"
|
||||||
background: locale === 'zh' ? '#1b2a47' : '',
|
|
||||||
color: locale === 'zh' ? '#f4f4f5' : '#000'
|
|
||||||
}"
|
|
||||||
@click="translationCh"
|
@click="translationCh"
|
||||||
><el-icon class="check-zh" v-show="locale === 'zh'"
|
><el-icon class="check-zh" v-show="locale === 'zh'"
|
||||||
><check /></el-icon
|
><check /></el-icon
|
||||||
>简体中文</el-dropdown-item
|
>简体中文</el-dropdown-item
|
||||||
>
|
>
|
||||||
<el-dropdown-item
|
<el-dropdown-item
|
||||||
:style="{
|
:style="getDropdownItemStyle('en')"
|
||||||
background: locale === 'en' ? '#1b2a47' : '',
|
|
||||||
color: locale === 'en' ? '#f4f4f5' : '#000'
|
|
||||||
}"
|
|
||||||
@click="translationEn"
|
@click="translationEn"
|
||||||
><el-icon class="check-en" v-show="locale === 'en'"
|
><el-icon class="check-en" v-show="locale === 'en'"
|
||||||
><check /></el-icon
|
><check /></el-icon
|
||||||
|
@ -11,9 +11,9 @@ import {
|
|||||||
} from "vue";
|
} from "vue";
|
||||||
import rgbHex from "rgb-hex";
|
import rgbHex from "rgb-hex";
|
||||||
import { find } from "lodash-es";
|
import { find } from "lodash-es";
|
||||||
import panel from "../panel/index.vue";
|
|
||||||
import { getConfig } from "/@/config";
|
import { getConfig } from "/@/config";
|
||||||
import { useRouter } from "vue-router";
|
import { useRouter } from "vue-router";
|
||||||
|
import panel from "../panel/index.vue";
|
||||||
import { emitter } from "/@/utils/mitt";
|
import { emitter } from "/@/utils/mitt";
|
||||||
import { templateRef } from "@vueuse/core";
|
import { templateRef } from "@vueuse/core";
|
||||||
import dayIcon from "/@/assets/svg/day.svg";
|
import dayIcon from "/@/assets/svg/day.svg";
|
||||||
@ -92,6 +92,12 @@ const settings = reactive({
|
|||||||
multiTagsCache: instance.sets.multiTagsCache
|
multiTagsCache: instance.sets.multiTagsCache
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const getThemeColorStyle = computed(() => {
|
||||||
|
return rgb => {
|
||||||
|
return { background: `rgb(${rgb})` };
|
||||||
|
};
|
||||||
|
});
|
||||||
|
|
||||||
function toggleClass(flag: boolean, clsName: string, target?: HTMLElement) {
|
function toggleClass(flag: boolean, clsName: string, target?: HTMLElement) {
|
||||||
const targetEl = target || document.body;
|
const targetEl = target || document.body;
|
||||||
let { className } = targetEl;
|
let { className } = targetEl;
|
||||||
@ -338,7 +344,7 @@ nextTick(() => {
|
|||||||
<li
|
<li
|
||||||
v-for="(item, index) in themeColors"
|
v-for="(item, index) in themeColors"
|
||||||
:key="index"
|
:key="index"
|
||||||
:style="{ background: `rgb(${item.rgb})` }"
|
:style="getThemeColorStyle(item.rgb)"
|
||||||
@click="setLayoutThemeColor(item.themeColor)"
|
@click="setLayoutThemeColor(item.themeColor)"
|
||||||
>
|
>
|
||||||
<el-icon
|
<el-icon
|
||||||
|
@ -35,6 +35,15 @@ const routers = useRouter().options.routes;
|
|||||||
let usename = storageSession.getItem("info")?.username;
|
let usename = storageSession.getItem("info")?.username;
|
||||||
const { locale, t } = useI18n();
|
const { locale, t } = useI18n();
|
||||||
|
|
||||||
|
const getDropdownItemStyle = computed(() => {
|
||||||
|
return t => {
|
||||||
|
return {
|
||||||
|
background: locale.value === t ? "#1b2a47" : "",
|
||||||
|
color: locale.value === t ? "#f4f4f5" : "#000"
|
||||||
|
};
|
||||||
|
};
|
||||||
|
});
|
||||||
|
|
||||||
watch(
|
watch(
|
||||||
() => locale.value,
|
() => locale.value,
|
||||||
() => {
|
() => {
|
||||||
@ -149,20 +158,14 @@ onMounted(() => {
|
|||||||
<template #dropdown>
|
<template #dropdown>
|
||||||
<el-dropdown-menu class="translation">
|
<el-dropdown-menu class="translation">
|
||||||
<el-dropdown-item
|
<el-dropdown-item
|
||||||
:style="{
|
:style="getDropdownItemStyle('zh')"
|
||||||
background: locale === 'zh' ? '#1b2a47' : '',
|
|
||||||
color: locale === 'zh' ? '#f4f4f5' : '#000'
|
|
||||||
}"
|
|
||||||
@click="translationCh"
|
@click="translationCh"
|
||||||
><el-icon class="check-zh" v-show="locale === 'zh'"
|
><el-icon class="check-zh" v-show="locale === 'zh'"
|
||||||
><check /></el-icon
|
><check /></el-icon
|
||||||
>简体中文</el-dropdown-item
|
>简体中文</el-dropdown-item
|
||||||
>
|
>
|
||||||
<el-dropdown-item
|
<el-dropdown-item
|
||||||
:style="{
|
:style="getDropdownItemStyle('en')"
|
||||||
background: locale === 'en' ? '#1b2a47' : '',
|
|
||||||
color: locale === 'en' ? '#f4f4f5' : '#000'
|
|
||||||
}"
|
|
||||||
@click="translationEn"
|
@click="translationEn"
|
||||||
><el-icon class="check-en" v-show="locale === 'en'"
|
><el-icon class="check-en" v-show="locale === 'en'"
|
||||||
><check /></el-icon
|
><check /></el-icon
|
||||||
|
@ -1,11 +1,19 @@
|
|||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
|
import {
|
||||||
|
ref,
|
||||||
|
PropType,
|
||||||
|
nextTick,
|
||||||
|
computed,
|
||||||
|
CSSProperties,
|
||||||
|
getCurrentInstance
|
||||||
|
} from "vue";
|
||||||
import path from "path";
|
import path from "path";
|
||||||
import { PropType, ref, nextTick, getCurrentInstance } from "vue";
|
|
||||||
import { childrenType } from "../../types";
|
import { childrenType } from "../../types";
|
||||||
import { useAppStoreHook } from "/@/store/modules/app";
|
|
||||||
import Icon from "/@/components/ReIcon/src/Icon.vue";
|
|
||||||
import { transformI18n } from "/@/plugins/i18n";
|
import { transformI18n } from "/@/plugins/i18n";
|
||||||
import { findIconReg } from "/@/components/ReIcon";
|
import { findIconReg } from "/@/components/ReIcon";
|
||||||
|
import Icon from "/@/components/ReIcon/src/Icon.vue";
|
||||||
|
import { useAppStoreHook } from "/@/store/modules/app";
|
||||||
|
|
||||||
const instance = getCurrentInstance().appContext.app.config.globalProperties;
|
const instance = getCurrentInstance().appContext.app.config.globalProperties;
|
||||||
const menuMode = instance.$storage.layout?.layout === "vertical";
|
const menuMode = instance.$storage.layout?.layout === "vertical";
|
||||||
const pureApp = useAppStoreHook();
|
const pureApp = useAppStoreHook();
|
||||||
@ -24,6 +32,48 @@ const props = defineProps({
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const getNoDropdownStyle = computed((): CSSProperties => {
|
||||||
|
return {
|
||||||
|
display: "flex",
|
||||||
|
alignItems: "center"
|
||||||
|
};
|
||||||
|
});
|
||||||
|
|
||||||
|
const getDivStyle = computed((): CSSProperties => {
|
||||||
|
return {
|
||||||
|
width: pureApp.sidebar.opened ? "" : "100%",
|
||||||
|
display: "flex",
|
||||||
|
alignItems: "center",
|
||||||
|
justifyContent: "space-between",
|
||||||
|
overflow: "hidden"
|
||||||
|
};
|
||||||
|
});
|
||||||
|
|
||||||
|
const getMenuTextStyle = computed((): CSSProperties => {
|
||||||
|
return {
|
||||||
|
width: pureApp.sidebar.opened ? "125px" : "",
|
||||||
|
overflow: "hidden",
|
||||||
|
textOverflow: "ellipsis",
|
||||||
|
outline: "none"
|
||||||
|
};
|
||||||
|
});
|
||||||
|
|
||||||
|
const getSubTextStyle = computed((): CSSProperties => {
|
||||||
|
return {
|
||||||
|
width: pureApp.sidebar.opened ? "125px" : "",
|
||||||
|
display: "inline-block",
|
||||||
|
overflow: "hidden",
|
||||||
|
textOverflow: "ellipsis"
|
||||||
|
};
|
||||||
|
});
|
||||||
|
|
||||||
|
const getSpanStyle = computed((): CSSProperties => {
|
||||||
|
return {
|
||||||
|
overflow: "hidden",
|
||||||
|
textOverflow: "ellipsis"
|
||||||
|
};
|
||||||
|
});
|
||||||
|
|
||||||
const onlyOneChild: childrenType = ref(null);
|
const onlyOneChild: childrenType = ref(null);
|
||||||
// 存放菜单是否存在showTooltip属性标识
|
// 存放菜单是否存在showTooltip属性标识
|
||||||
const hoverMenuMap = new WeakMap();
|
const hoverMenuMap = new WeakMap();
|
||||||
@ -88,7 +138,7 @@ function resolvePath(routePath) {
|
|||||||
<el-menu-item
|
<el-menu-item
|
||||||
:index="resolvePath(onlyOneChild.path)"
|
:index="resolvePath(onlyOneChild.path)"
|
||||||
:class="{ 'submenu-title-noDropdown': !isNest }"
|
:class="{ 'submenu-title-noDropdown': !isNest }"
|
||||||
style="display: flex; align-items: center"
|
:style="getNoDropdownStyle"
|
||||||
>
|
>
|
||||||
<el-icon v-show="props.item.meta.icon">
|
<el-icon v-show="props.item.meta.icon">
|
||||||
<component
|
<component
|
||||||
@ -101,15 +151,7 @@ function resolvePath(routePath) {
|
|||||||
></component>
|
></component>
|
||||||
</el-icon>
|
</el-icon>
|
||||||
<template #title>
|
<template #title>
|
||||||
<div
|
<div :style="getDivStyle">
|
||||||
:style="{
|
|
||||||
width: pureApp.sidebar.opened ? '' : '100%',
|
|
||||||
display: 'flex',
|
|
||||||
alignItems: 'center',
|
|
||||||
justifyContent: 'space-between',
|
|
||||||
overflow: 'hidden'
|
|
||||||
}"
|
|
||||||
>
|
|
||||||
<span v-if="!menuMode">{{
|
<span v-if="!menuMode">{{
|
||||||
transformI18n(onlyOneChild.meta.title, onlyOneChild.meta.i18n)
|
transformI18n(onlyOneChild.meta.title, onlyOneChild.meta.i18n)
|
||||||
}}</span>
|
}}</span>
|
||||||
@ -126,12 +168,7 @@ function resolvePath(routePath) {
|
|||||||
</template>
|
</template>
|
||||||
<span
|
<span
|
||||||
ref="menuTextRef"
|
ref="menuTextRef"
|
||||||
:style="{
|
:style="getMenuTextStyle"
|
||||||
width: pureApp.sidebar.opened ? '125px' : '',
|
|
||||||
overflow: 'hidden',
|
|
||||||
textOverflow: 'ellipsis',
|
|
||||||
outline: 'none'
|
|
||||||
}"
|
|
||||||
@mouseover="hoverMenu(onlyOneChild)"
|
@mouseover="hoverMenu(onlyOneChild)"
|
||||||
>
|
>
|
||||||
{{
|
{{
|
||||||
@ -175,15 +212,10 @@ function resolvePath(routePath) {
|
|||||||
</template>
|
</template>
|
||||||
<div
|
<div
|
||||||
ref="menuTextRef"
|
ref="menuTextRef"
|
||||||
:style="{
|
:style="getSubTextStyle"
|
||||||
width: pureApp.sidebar.opened ? '125px' : '',
|
|
||||||
display: 'inline-block',
|
|
||||||
overflow: 'hidden',
|
|
||||||
textOverflow: 'ellipsis'
|
|
||||||
}"
|
|
||||||
@mouseover="hoverMenu(props.item)"
|
@mouseover="hoverMenu(props.item)"
|
||||||
>
|
>
|
||||||
<span style="overflow: hidden; text-overflow: ellipsis">
|
<span :style="getSpanStyle">
|
||||||
{{ transformI18n(props.item.meta.title, props.item.meta.i18n) }}
|
{{ transformI18n(props.item.meta.title, props.item.meta.i18n) }}
|
||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
|
@ -2,12 +2,13 @@
|
|||||||
import {
|
import {
|
||||||
ref,
|
ref,
|
||||||
watch,
|
watch,
|
||||||
onBeforeMount,
|
|
||||||
unref,
|
unref,
|
||||||
nextTick,
|
nextTick,
|
||||||
computed,
|
computed,
|
||||||
getCurrentInstance,
|
ComputedRef,
|
||||||
ComputedRef
|
CSSProperties,
|
||||||
|
onBeforeMount,
|
||||||
|
getCurrentInstance
|
||||||
} from "vue";
|
} from "vue";
|
||||||
|
|
||||||
import close from "/@/assets/svg/close.svg";
|
import close from "/@/assets/svg/close.svg";
|
||||||
@ -610,17 +611,23 @@ onBeforeMount(() => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const getTabStyle = computed((): CSSProperties => {
|
||||||
|
return {
|
||||||
|
transform: `translateX(${translateX.value}px)`
|
||||||
|
};
|
||||||
|
});
|
||||||
|
|
||||||
|
const getContextMenuStyle = computed((): CSSProperties => {
|
||||||
|
return { left: buttonLeft.value + "px", top: buttonTop.value + "px" };
|
||||||
|
});
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
<div ref="containerDom" class="tags-view" v-if="!showTags">
|
<div ref="containerDom" class="tags-view" v-if="!showTags">
|
||||||
<i class="ri-arrow-left-s-line" @click="handleScroll(200)"></i>
|
<i class="ri-arrow-left-s-line" @click="handleScroll(200)"></i>
|
||||||
<div ref="scrollbarDom" class="scroll-container">
|
<div ref="scrollbarDom" class="scroll-container">
|
||||||
<div
|
<div class="tab" ref="tabDom" :style="getTabStyle">
|
||||||
class="tab"
|
|
||||||
ref="tabDom"
|
|
||||||
:style="{ transform: `translateX(${translateX}px)` }"
|
|
||||||
>
|
|
||||||
<div
|
<div
|
||||||
:ref="'dynamic' + index"
|
:ref="'dynamic' + index"
|
||||||
v-for="(item, index) in multiTags"
|
v-for="(item, index) in multiTags"
|
||||||
@ -664,7 +671,7 @@ onBeforeMount(() => {
|
|||||||
<ul
|
<ul
|
||||||
v-show="visible"
|
v-show="visible"
|
||||||
:key="Math.random()"
|
:key="Math.random()"
|
||||||
:style="{ left: buttonLeft + 'px', top: buttonTop + 'px' }"
|
:style="getContextMenuStyle"
|
||||||
class="contextmenu"
|
class="contextmenu"
|
||||||
>
|
>
|
||||||
<div
|
<div
|
||||||
|
Loading…
x
Reference in New Issue
Block a user