Skip to content

Commit

Permalink
feature: 添加标签页
Browse files Browse the repository at this point in the history
  • Loading branch information
jsxiaosi committed Jun 27, 2022
1 parent b621fc1 commit a199bfd
Show file tree
Hide file tree
Showing 23 changed files with 275 additions and 59 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
"intro.js": "^5.1.0",
"lodash-es": "^4.17.21",
"marked": "^4.0.17",
"mitt": "^3.0.0",
"mockjs": "^1.1.0",
"path": "^0.12.7",
"pinia": "^2.0.14",
Expand Down
4 changes: 2 additions & 2 deletions src/components/Application/AppLocale.vue
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@
<script setup lang="ts">
import { useI18n, localesList } from '@/hooks/web/useI18n';
import SvgIcon from '@/components/SvgIcon/index.vue';
import { useAppStore } from '@/store/modules/app';
import { useAppStoreHook } from '@/store/modules/app';
import { getAppCollapseMenu } from '@/hooks/userAppWindow';
const i18n = useI18n();
const appStore = useAppStore();
const appStore = useAppStoreHook();
const { appConfigMode } = getAppCollapseMenu();
// const availableLocales = i18n.availableLocales;
const tolochos = (key: string) => {
Expand Down
14 changes: 6 additions & 8 deletions src/components/SvgIcon/index.vue
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
<template>
<div :class="className" style="line-height: 1px">
<el-icon v-if="isELIcon">
<component :is="name" />
</el-icon>
<svg v-else class="svg" :aria-hidden="true">
<use :xlink:href="symbolId" :fill="color" />
</svg>
</div>
<el-icon v-if="isELIcon" :class="className">
<component :is="name" />
</el-icon>
<svg v-else :class="className" class="svg" :aria-hidden="true">
<use :xlink:href="symbolId" :fill="color" />
</svg>
</template>

<script setup lang="ts">
Expand Down
4 changes: 2 additions & 2 deletions src/hooks/userAppWindow.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
// import { useStore } from '@/store'
import { computed } from 'vue';
import { useAppStore } from '@/store/modules/app';
import { useAppStoreHook } from '@/store/modules/app';
import { appConfig } from '@/store/types';

export const getAppCollapseMenu = () => {
// const store = useStore()
const appStore = useAppStore();
const appStore = useAppStoreHook();
const appConfigMode = computed<appConfig>(() => appStore.getAppConfigMode);
return { appConfigMode };
};
1 change: 0 additions & 1 deletion src/hooks/web/useECharts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ export function useECharts(elRef: Ref<HTMLDivElement>) {

// 改变图表大小
function resize() {
console.log('每次都执行?');
chartInstance?.resize();
}

Expand Down
4 changes: 2 additions & 2 deletions src/layouts/pageLayouts/components/AppMain/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@
.app-main {
position: relative;
width: 100%;
height: calc(100vh - #{$navBarHeight+$TabsPageHeight});
// min-height: calc(100vh - #{$navBarHeight+$TabsPageHeight});
height: calc(100vh - #{$navBarHeight+$tabsPageHeight});
// min-height: calc(100vh - #{$navBarHeight+$tabsPageHeight});
overflow: auto;
padding: 20px;
background-color: #{$app-main-bg-color};
Expand Down
184 changes: 184 additions & 0 deletions src/layouts/pageLayouts/components/AppTabs/index.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,184 @@
<template>
<div class="main-container-tabs">
<el-tabs
v-model="editableTabsValue"
type="card"
class="demo-tabs"
:closable="multiTabs.length > 1"
@tab-remove="removeTab"
@tab-change="changeTab"
>
<el-tab-pane
v-for="item in multiTabs"
:key="item.path"
:label="t(item.meta.title as string)"
:name="item.path"
>
</el-tab-pane>
</el-tabs>
<ul>
<li class="cursor" @click="onFresh">
<svg-icon class="rotate" name="iEL-refresh"></svg-icon>
</li>
</ul>
</div>
</template>

<script setup lang="ts">
import { useI18n } from '@/hooks/web/useI18n';
import { usePermissionStoreHook } from '@/store/modules/permission';
import type { MultiTabsType } from '@/store/types';
import { ref, onMounted, computed, watch, unref } from 'vue';
import { useRoute, useRouter } from 'vue-router';
import SvgIcon from '@/components/SvgIcon/index.vue';
import { removeClass, toggleClass } from '@/utils/operate';
import { sidebarRouteList } from '@/router/modules';
import { findRouteByPath } from '@/router/utils';
const { t } = useI18n();
const route = useRoute();
const router = useRouter();
const multiTabs = computed<MultiTabsType[]>(() => usePermissionStoreHook().multiTabs);
const editableTabsValue = ref(route.path);
watch(
() => route.path,
() => {
editableTabsValue.value = route.path;
addRouteTabs();
},
);
onMounted(() => {
addRouteTabs();
});
const addRouteTabs = () => {
const { path, name, query, meta } = route;
const routeIndex = findRouteByPath(path, sidebarRouteList);
if (!routeIndex) return;
const currentRoute = { path, query, meta, name };
usePermissionStoreHook().handleMultiTabs('add', currentRoute);
};
const removeTab = (e: string) => {
const valueIndex = multiTabs.value.findIndex((i) => i.path === e);
const tabsLength = multiTabs.value.length;
let value,
toRoute = {};
if (valueIndex === tabsLength - 1) {
value = multiTabs.value[valueIndex - 1];
toRoute = {
path: value.path,
query: value.query,
};
} else {
value = multiTabs.value[tabsLength - 1];
toRoute = {
path: value.path,
query: value.query,
};
}
router.push(toRoute);
usePermissionStoreHook().cacheOperate({
mode: 'delete',
name: multiTabs.value[valueIndex].name || '',
});
usePermissionStoreHook().handleMultiTabs('delete', e);
};
// 重新加载
function onFresh() {
const refreshButton = 'refresh-button';
toggleClass(true, refreshButton, document.querySelector('.rotate'));
const { fullPath, query } = unref(route);
router.replace({
path: '/redirect' + fullPath,
query: query,
});
setTimeout(() => {
removeClass(document.querySelector('.rotate'), refreshButton);
}, 600);
}
const changeTab = (e: string) => {
router.push(e);
};
</script>

<style lang="scss" scoped>
.main-container-tabs {
display: flex;
ul {
li {
width: $tabsPageHeight;
height: 100%;
text-align: center;
line-height: $tabsPageHeight;
font-size: 16px;
border: 1px solid var(--text-color-placeholder);
}
}
// .el-tabs :deep(.el-tabs__header) {
// margin: 0;
// }
.el-tabs {
width: 0;
height: $tabsPageHeight;
flex: 1;
margin: 0 10px;
:deep(.el-tabs__header) {
height: 100%;
margin: 0;
border: none;
// display: flex;
// align-items: center;
.el-tabs__nav-wrap,
.el-tabs__nav-scroll {
height: 100%;
}
.el-tabs__nav-scroll {
display: flex;
align-items: center;
.el-tabs__nav {
border: none;
border-radius: 0;
.el-tabs__item {
height: 100%;
line-height: $tabsPageHeight - 10;
border-radius: 4px;
border: 1px solid var(--text-color-placeholder);
margin-right: 4px;
}
}
}
.el-tabs__nav-next,
.el-tabs__nav-prev {
height: $tabsPageHeight;
line-height: $tabsPageHeight;
}
// .el-tabs__nav-*{
// }
}
}
/* 刷新按钮动画效果 */
.refresh-button {
animation: rotate 600ms linear infinite;
}
@keyframes rotate {
from {
transform: rotate(0deg);
}
to {
transform: rotate(-360deg);
}
}
}
</style>
6 changes: 3 additions & 3 deletions src/layouts/pageLayouts/components/Breadcrumb/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
import { getAppCollapseMenu } from '@/hooks/userAppWindow';
import { useRoute, useRouter } from 'vue-router';
import { useI18n } from '@/hooks/web/useI18n';
import { useAppStore } from '@/store/modules/app';
import { useAppStoreHook } from '@/store/modules/app';
import { AppRouteRecordRaw } from '#/route';
import { getParentPaths, findRouteByPath } from '@/router/utils';
Expand All @@ -51,7 +51,7 @@
// 解析路由匹配的数组
const getBreadcrumb = () => {
const matched: AppRouteRecordRaw[] = [];
const parentRoutes = getParentPaths(router.currentRoute.value.name || '', routes);
const parentRoutes = getParentPaths(router.currentRoute.value.path || '', routes);
// 获取每个父级路径对应的路由信息
parentRoutes.forEach((path) => {
if (path !== '/') {
Expand Down Expand Up @@ -91,7 +91,7 @@
// 当前是否折叠导航栏
const { appConfigMode } = getAppCollapseMenu();
const isAppConfigMode = ref(appConfigMode.value);
const appStore = useAppStore();
const appStore = useAppStoreHook();
// 折叠菜单事件
const handerShowElmenu = () => {
isAppConfigMode.value.collapseMenu = !isAppConfigMode.value.collapseMenu;
Expand Down
4 changes: 2 additions & 2 deletions src/layouts/pageLayouts/components/Seting/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
<script setup lang="ts">
import { getAppCollapseMenu } from '@/hooks/userAppWindow';
import { watch, ref } from 'vue';
import { useAppStore } from '@/store/modules/app';
import { useAppStoreHook } from '@/store/modules/app';
import { SidebarMode } from '@/store/types';
const props = defineProps({
Expand Down Expand Up @@ -65,7 +65,7 @@
},
];
const appStore = useAppStore();
const appStore = useAppStoreHook();
// 折叠菜单事件
const handerShowElmenu = (vale: SidebarMode) => {
isAppConfigMode.value.sidebarMode = vale;
Expand Down
18 changes: 7 additions & 11 deletions src/layouts/pageLayouts/components/Sidebar/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<el-menu
:default-active="activeMenyu"
:unique-opened="true"
:collapse="appConfigMode.sidebarMode !== 'vertical' ? false : appConfigMode.collapseMenu"
:collapse="appConfigMode.sidebarMode === 'horizontal' ? false : appConfigMode.collapseMenu"
:mode="mode"
>
<sidebar-item
Expand All @@ -19,7 +19,7 @@

<script setup lang="ts">
import { computed, PropType, ref, watch } from 'vue';
import { RouteRecordName, useRoute } from 'vue-router';
import { useRoute } from 'vue-router';
import SidebarItem from './SidebarItem.vue';
import { getAppCollapseMenu } from '@/hooks/userAppWindow';
import { usePermissionStoreHook } from '@/store/modules/permission';
Expand All @@ -43,27 +43,23 @@
: usePermissionStoreHook().wholeMenus;
});
function getSubMenuData(name: RouteRecordName) {
console.log('不执行了是吗?');
function getSubMenuData(path: string) {
// path的上级路由组成的数组
const parentPathArr = getParentPaths(name, usePermissionStoreHook().wholeMenus);
const parentPathArr = getParentPaths(path, usePermissionStoreHook().wholeMenus);
// 当前路由的父级路由信息
const parenetRoute = findRouteByPath(
parentPathArr[0] || name,
usePermissionStoreHook().wholeMenus,
);
const parenetRoute = findRouteByPath(parentPathArr[0], usePermissionStoreHook().wholeMenus);
if (parenetRoute) {
if (parenetRoute.children) subMenuData.value = parenetRoute.children;
else subMenuData.value = [parenetRoute];
}
}
getSubMenuData(route.name as RouteRecordName);
getSubMenuData(route.path);
watch(
() => [route.path, appConfigMode.value.sidebarMode],
() => {
if (appConfigMode.value.sidebarMode === 'blend') {
getSubMenuData(route.name as RouteRecordName);
getSubMenuData(route.path);
}
},
);
Expand Down
3 changes: 2 additions & 1 deletion src/layouts/pageLayouts/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<!-- 顶部导航栏 -->
<NavBart />
<!-- 选项卡 -->
<div class="main-container-tabs"> </div>
<AppTabs />
<!-- 内容区 -->
<AppMain />
</div>
Expand All @@ -16,6 +16,7 @@

<script setup lang="ts">
import AppMain from './components/AppMain/index.vue';
import AppTabs from './components/AppTabs/index.vue';
import NavBart from './components/Navbart/index.vue';
import VerticalSidebar from './components/VerticalSidebar/index.vue';
</script>
Expand Down
8 changes: 5 additions & 3 deletions src/router/index.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
import { createRouter, createWebHistory, RouteRecordRaw } from 'vue-router';
import { App } from 'vue';
import routeModuleList from './modules';
import whiteRouteModulesList from './modules';
import { handleAliveRoute, initAsyncRoute } from './utils';
import { usePermissionStoreHook } from '@/store/modules/permission';

const routeList = whiteRouteModulesList;

export const router = createRouter({
history: createWebHistory(''),
routes: routeModuleList as unknown as RouteRecordRaw[],
routes: routeList as unknown as RouteRecordRaw[],
});

export const configMainRouter = async (app: App<Element>) => {
Expand All @@ -20,7 +22,7 @@ router.beforeEach((to, from, next) => {
const newMatched = to.matched;
handleAliveRoute(newMatched, 'add');
// 页面整体刷新
if (from.name === undefined || from.name === 'redirect') {
if (from.name === undefined || from.name === 'Redirect') {
handleAliveRoute(newMatched);
}
}
Expand Down
Loading

0 comments on commit a199bfd

Please sign in to comment.