perf: layout

This commit is contained in:
xiaoxian521 2021-10-04 11:00:36 +08:00 committed by 啝裳
parent 6b16a04229
commit 37a967942b
4 changed files with 68 additions and 36 deletions

View File

@ -1,13 +1,3 @@
<script lang="ts">
export default {
computed: {
dynamicTagList() {
return this.$storage.routesInStorage;
}
}
};
</script>
<script setup lang="ts"> <script setup lang="ts">
import { import {
ref, ref,
@ -15,9 +5,11 @@ import {
onBeforeMount, onBeforeMount,
unref, unref,
nextTick, nextTick,
getCurrentInstance computed,
getCurrentInstance,
ComputedRef
} from "vue"; } from "vue";
import { RouteConfigs } from "../../types"; import { RouteConfigs, relativeStorageType, tagsViewsType } from "../../types";
import { emitter } from "/@/utils/mitt"; import { emitter } from "/@/utils/mitt";
import { templateRef } from "@vueuse/core"; import { templateRef } from "@vueuse/core";
import { storageLocal } from "/@/utils/storage"; import { storageLocal } from "/@/utils/storage";
@ -33,7 +25,9 @@ import closeRight from "/@/assets/svg/close_right.svg";
let refreshButton = "refresh-button"; let refreshButton = "refresh-button";
const instance = getCurrentInstance(); const instance = getCurrentInstance();
let st: any;
// storage
let relativeStorage: relativeStorageType;
const route = useRoute(); const route = useRoute();
const router = useRouter(); const router = useRouter();
const showTags = ref(storageLocal.getItem("tagsVal") || false); const showTags = ref(storageLocal.getItem("tagsVal") || false);
@ -51,50 +45,53 @@ let routerArrays: Array<RouteConfigs> = [
} }
} }
]; ];
const tagsViews = ref<ForDataType<undefined>>([ const tagsViews = ref<Array<tagsViewsType>>([
{ {
icon: refresh, icon: refresh,
text: "重新加载", text: "message.hsreload",
divided: false, divided: false,
disabled: false, disabled: false,
show: true show: true
}, },
{ {
icon: close, icon: close,
text: "关闭当前标签页", text: "message.hscloseCurrentTab",
divided: false, divided: false,
disabled: routerArrays.length > 1 ? false : true, disabled: routerArrays.length > 1 ? false : true,
show: true show: true
}, },
{ {
icon: closeLeft, icon: closeLeft,
text: "关闭左侧标签页", text: "message.hscloseLeftTabs",
divided: true, divided: true,
disabled: routerArrays.length > 1 ? false : true, disabled: routerArrays.length > 1 ? false : true,
show: true show: true
}, },
{ {
icon: closeRight, icon: closeRight,
text: "关闭右侧标签页", text: "message.hscloseRightTabs",
divided: false, divided: false,
disabled: routerArrays.length > 1 ? false : true, disabled: routerArrays.length > 1 ? false : true,
show: true show: true
}, },
{ {
icon: closeOther, icon: closeOther,
text: "关闭其他标签页", text: "message.hscloseOtherTabs",
divided: true, divided: true,
disabled: routerArrays.length > 2 ? false : true, disabled: routerArrays.length > 2 ? false : true,
show: true show: true
}, },
{ {
icon: closeAll, icon: closeAll,
text: "关闭全部标签页", text: "message.hscloseAllTabs",
divided: false, divided: false,
disabled: routerArrays.length > 1 ? false : true, disabled: routerArrays.length > 1 ? false : true,
show: true show: true
} }
]); ]);
const dynamicTagList: ComputedRef<Array<RouteConfigs>> = computed(() => {
return relativeStorage.routesInStorage;
});
// //
const showModel = ref(storageLocal.getItem("showModel") || "smart"); const showModel = ref(storageLocal.getItem("showModel") || "smart");
@ -110,7 +107,7 @@ let buttonTop = ref(0);
let currentSelect = ref({}); let currentSelect = ref({});
function dynamicRouteTag(value: string, parentPath: string): void { function dynamicRouteTag(value: string, parentPath: string): void {
const hasValue = st.routesInStorage.some((item: any) => { const hasValue = relativeStorage.routesInStorage.some((item: any) => {
return item.path === value; return item.path === value;
}); });
@ -124,7 +121,7 @@ function dynamicRouteTag(value: string, parentPath: string): void {
parentPath: `/${parentPath.split("/")[1]}`, parentPath: `/${parentPath.split("/")[1]}`,
meta: arrItem.meta meta: arrItem.meta
}); });
st.routesInStorage = routerArrays; relativeStorage.routesInStorage = routerArrays;
} else { } else {
if (arrItem.children && arrItem.children.length > 0) { if (arrItem.children && arrItem.children.length > 0) {
concatPath(arrItem.children, value, parentPath); concatPath(arrItem.children, value, parentPath);
@ -155,7 +152,7 @@ function deleteDynamicTag(obj: any, current: any, tag?: string) {
const spliceRoute = (start?: number, end?: number, other?: boolean): void => { const spliceRoute = (start?: number, end?: number, other?: boolean): void => {
if (other) { if (other) {
st.routesInStorage = [ relativeStorage.routesInStorage = [
{ {
path: "/welcome", path: "/welcome",
parentPath: "/", parentPath: "/",
@ -168,10 +165,10 @@ function deleteDynamicTag(obj: any, current: any, tag?: string) {
}, },
obj obj
]; ];
routerArrays = st.routesInStorage; routerArrays = relativeStorage.routesInStorage;
} else { } else {
routerArrays.splice(start, end); routerArrays.splice(start, end);
st.routesInStorage = routerArrays; relativeStorage.routesInStorage = routerArrays;
} }
router.push(obj.path); router.push(obj.path);
}; };
@ -255,7 +252,7 @@ function onClickDrop(key, item, selectRoute?: RouteConfigs) {
case 5: case 5:
// //
routerArrays.splice(1, routerArrays.length); routerArrays.splice(1, routerArrays.length);
st.routesInStorage = routerArrays; relativeStorage.routesInStorage = routerArrays;
router.push("/welcome"); router.push("/welcome");
break; break;
} }
@ -287,8 +284,8 @@ function disabledMenus(value: Boolean) {
// //
function showMenuModel(currentPath: string, refresh = false) { function showMenuModel(currentPath: string, refresh = false) {
let allRoute = unref(st.routesInStorage); let allRoute = unref(relativeStorage.routesInStorage);
let routeLength = unref(st.routesInStorage).length; let routeLength = unref(relativeStorage.routesInStorage).length;
// currentIndex1 // currentIndex1
let currentIndex = allRoute.findIndex(v => v.path === currentPath); let currentIndex = allRoute.findIndex(v => v.path === currentPath);
// currentIndexrouteLength-1 // currentIndexrouteLength-1
@ -319,7 +316,7 @@ function showMenuModel(currentPath: string, refresh = false) {
tagsViews.value[v].disabled = false; tagsViews.value[v].disabled = false;
}); });
tagsViews.value[3].disabled = true; tagsViews.value[3].disabled = true;
} else if (currentIndex === 0) { } else if (currentIndex === 0 || currentPath === "/redirect/welcome") {
// //
disabledMenus(true); disabledMenus(true);
} else { } else {
@ -337,8 +334,11 @@ function openMenu(tag, e) {
// //
tagsViews.value[0].show = false; tagsViews.value[0].show = false;
showMenuModel(tag.path); showMenuModel(tag.path);
} else if (
// eslint-disable-next-line no-dupe-else-if // eslint-disable-next-line no-dupe-else-if
} else if (st.routesInStorage.length === 2 && route.path !== tag.path) { relativeStorage.routesInStorage.length === 2 &&
route.path !== tag.path
) {
showMenus(true); showMenus(true);
// //
tagsViews.value[4].show = false; tagsViews.value[4].show = false;
@ -410,8 +410,8 @@ watch(
onBeforeMount(() => { onBeforeMount(() => {
if (!instance) return; if (!instance) return;
st = instance.appContext.app.config.globalProperties.$storage; relativeStorage = instance.appContext.app.config.globalProperties.$storage;
routerArrays = st.routesInStorage ?? routerArrays; routerArrays = relativeStorage.routesInStorage ?? routerArrays;
// //
showMenuModel(route.fullPath); showMenuModel(route.fullPath);
@ -486,7 +486,7 @@ onBeforeMount(() => {
> >
<li v-if="item.show" @click="selectTag(key, item)"> <li v-if="item.show" @click="selectTag(key, item)">
<component :is="item.icon" :key="key" /> <component :is="item.icon" :key="key" />
{{ item.text }} {{ $t(item.text) }}
</li> </li>
</div> </div>
</ul> </ul>
@ -513,7 +513,7 @@ onBeforeMount(() => {
@click="onClickDrop(key, item)" @click="onClickDrop(key, item)"
> >
<component :is="item.icon" :key="key" /> <component :is="item.icon" :key="key" />
{{ item.text }} {{ $t(item.text) }}
</el-dropdown-item> </el-dropdown-item>
</el-dropdown-menu> </el-dropdown-menu>
</template> </template>

View File

@ -9,6 +9,24 @@ export type RouteConfigs = {
}; };
}; };
export type relativeStorageType = {
routesInStorage: Array<RouteConfigs>;
};
export type tagsViewsType = {
icon: string;
text: string;
divided: {
valueOf: () => boolean;
};
disabled: {
valueOf: () => boolean;
};
show: {
valueOf: () => boolean;
};
};
export const routerArrays: Array<RouteConfigs> = [ export const routerArrays: Array<RouteConfigs> = [
{ {
path: "/welcome", path: "/welcome",

View File

@ -100,7 +100,13 @@ export const buttonConfig = {
hsexpendAll: "全部展开", hsexpendAll: "全部展开",
hscollapseAll: "全部折叠", hscollapseAll: "全部折叠",
hssystemSet: "系统设置", hssystemSet: "系统设置",
hsdelete: "删除" hsdelete: "删除",
hsreload: "重新加载",
hscloseCurrentTab: "关闭当前标签页",
hscloseLeftTabs: "关闭左侧标签页",
hscloseRightTabs: "关闭右侧标签页",
hscloseOtherTabs: "关闭其他标签页",
hscloseAllTabs: "关闭全部标签页"
} }
}, },
en: { en: {
@ -118,7 +124,13 @@ export const buttonConfig = {
hsexpendAll: "Expand All", hsexpendAll: "Expand All",
hscollapseAll: "Collapse All", hscollapseAll: "Collapse All",
hssystemSet: "System Set", hssystemSet: "System Set",
hsdelete: "Delete" hsdelete: "Delete",
hsreload: "Reload",
hscloseCurrentTab: "Close CurrentTab",
hscloseLeftTabs: "Close LeftTabs",
hscloseRightTabs: "Close RightTabs",
hscloseOtherTabs: "Close OtherTabs",
hscloseAllTabs: "Close AllTabs"
} }
} }
}; };

2
types/index.d.ts vendored
View File

@ -29,3 +29,5 @@ declare type ElRef<T extends HTMLElement = HTMLDivElement> = Nullable<T>;
declare type ForDataType<T> = { declare type ForDataType<T> = {
[P in T]?: ForDataType<T[P]>; [P in T]?: ForDataType<T[P]>;
}; };
declare type AnyFunction<T> = (...args: any[]) => T;