Skip to content

Commit

Permalink
Merge branch 'template' into release
Browse files Browse the repository at this point in the history
  • Loading branch information
yuntian001 committed Jun 21, 2023
2 parents c86a86e + 41d5624 commit 9b716ac
Show file tree
Hide file tree
Showing 14 changed files with 55 additions and 34 deletions.
6 changes: 3 additions & 3 deletions mock/apiDemo/routeMenu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,21 +63,21 @@ const menu = [
},
{
path: 'multilevel',
component: 'LayoutPage',
component: 'Layout',
meta: {
title: '多级菜单',
},
children: [
{
path: '1',
component: 'LayoutPage',
component: 'Layout',
meta: {
title: '多级菜单1',
},
children: [
{
path: '1-1',
component: 'LayoutPage',
component: 'Layout',
meta: {
title: '多级菜单1-1',
alwaysShow: true,
Expand Down
2 changes: 1 addition & 1 deletion src/layout/components/header/components/tagBar/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ import contextmenu from './components/contextmenu.vue';
import { isExternal } from '@/utils/validate';
import { resolve } from 'path-browserify';
import $ from 'jquery';
const { themeConfig } = useSettingStore();
const { themeConfig } = storeToRefs(useSettingStore());
// 初始化tags
const tags = reactive([] as RouteLocationNormalized[]);
const resolvePath = (routePath: string, basePath = '') => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,17 @@
import { mitter, event } from '@/event';
import { useSettingStore, useGlobalStore, useRouteStore } from '@/store';
import { RouteLocationNormalized, RouteRecordRaw } from 'vue-router';
const { themeConfig } = useSettingStore();
const { themeConfig } = storeToRefs(useSettingStore());
const globalStore = useGlobalStore();
const setMenuCollapse = () => {
themeConfig.menuCollapse = !themeConfig.menuCollapse;
themeConfig.value.menuCollapse = !themeConfig.value.menuCollapse;
};
const breadcrumbList = ref([] as Pick<RouteRecordRaw, 'name' | 'path' | 'meta' | 'redirect'>[]);
const route = useRoute();
const { routes } = useRouteStore();
const { routes } = storeToRefs(useRouteStore());
const setBreadcrumbList = (route: RouteLocationNormalized) => {
const list = [] as Pick<RouteRecordRaw, 'name' | 'path' | 'meta' | 'redirect'>[];
let temp = { children: routes } as unknown as RouteRecordRaw;
let temp = { children: routes.value } as unknown as RouteRecordRaw;
route.meta.menuIndex!.forEach((item) => {
temp = temp.children![item];
if (temp.meta && temp.meta.title && temp.meta.breadcrumb !== false) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import { localeConfig } from '@/config';
import MessageBox from './components/messageBox.vue';
import { useSettingStore } from '@/store';
import User from './components/user.vue';
const { themeConfig } = useSettingStore();
const { themeConfig } = storeToRefs(useSettingStore());
</script>
<style lang="scss" scoped>
.right {
Expand Down
2 changes: 1 addition & 1 deletion src/layout/components/header/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import { useSettingStore } from '@/store';
import TopBar from './components/topBar/index.vue';
import TagBar from './components/tagBar/index.vue';
const { themeConfig } = useSettingStore();
const { themeConfig } = storeToRefs(useSettingStore());
</script>
<style lang="scss" scoped>
.layout-header {
Expand Down
4 changes: 3 additions & 1 deletion src/layout/components/menu/components/menuItem.vue
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
<template>
<template v-if="!item.meta?.hideMenu">
<template
v-if="onlyOneChild && (!onlyOneChild.children || onlyOneChild.noShowingChildren) && !item.meta?.alwaysShow"
v-if="
onlyOneChild && (!onlyOneChild.children?.length || onlyOneChild.noShowingChildren) && !item.meta?.alwaysShow
"
>
<component
:is="onlyOneChild.meta?.isLink ? 'a' : 'routerLink'"
Expand Down
8 changes: 4 additions & 4 deletions src/layout/components/menu/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
<script setup lang="ts" name="layoutMenu">
import { useSettingStore, useRouteStore, useGlobalStore } from '@/store';
import { mixColor, getColorLuma } from '@/utils/helper';
const { themeConfig } = useSettingStore();
const { themeConfig } = storeToRefs(useSettingStore());
const routeStore = useRouteStore();
const globalStore = useGlobalStore();
const route = useRoute();
Expand All @@ -38,10 +38,10 @@ watch(
{ immediate: true },
);
const menuBg1 = computed(() =>
mixColor(themeConfig.menuBg, getColorLuma(themeConfig.menuBg) < 100 ? '#ffffff' : '#303133', 0.1),
mixColor(themeConfig.value.menuBg, getColorLuma(themeConfig.value.menuBg) < 100 ? '#ffffff' : '#303133', 0.1),
);
const menuActiveColor = computed(() => (getColorLuma(themeConfig.menuBg) < 100 ? '#ffffff' : '#303133'));
const menuTextColor = computed(() => mixColor(themeConfig.menuBg, menuActiveColor.value, 0.8));
const menuActiveColor = computed(() => (getColorLuma(themeConfig.value.menuBg) < 100 ? '#ffffff' : '#303133'));
const menuTextColor = computed(() => mixColor(themeConfig.value.menuBg, menuActiveColor.value, 0.8));
</script>
<style lang="scss" scoped>
.layout-menu {
Expand Down
2 changes: 1 addition & 1 deletion src/layout/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ import LayoutHeader from './components/header/index.vue';
import LayoutMenu from './components/menu/index.vue';
import LayoutPage from './components/page.vue';
import { useSettingStore, useGlobalStore } from '@/store';
const { themeConfig } = useSettingStore();
const { themeConfig } = storeToRefs(useSettingStore());
const globalStore = useGlobalStore();
onMounted(() => {
nextTick(() => (globalStore.layoutLoaded = true));
Expand Down
23 changes: 12 additions & 11 deletions src/router/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,6 @@ import { isExternal } from '@/utils/validate';
import { resolve } from 'path-browserify';

export const constantRoutes: RouteRecordRaw[] = [
{
path: '/',
redirect: PageEnum.HOME,
meta: {
hideMenu: true,
title: '首页',
},
},
{
path: PageEnum.LOGIN,
component: async () => await import('@/views/login/index.vue'),
Expand Down Expand Up @@ -64,13 +56,14 @@ export const flatteningRoutes = (
basePath = '',
menuIndex: number[] = [],
newRoutes: RouteRecordRaw[] = [],
baseIndex = 0,
) => {
routes.forEach((route, index) => {
route.path = resolvePath(route.path, basePath);
if (!route.meta) {
route.meta = { title: '' };
}
route.meta.menuIndex = [...menuIndex, index];
route.meta.menuIndex = [...menuIndex, index + baseIndex];
newRoutes.push(Object.assign({ ...route }, { children: [] }));
if (route.children) {
flatteningRoutes(route.children, route.path, route.meta.menuIndex, newRoutes);
Expand All @@ -79,7 +72,7 @@ export const flatteningRoutes = (
return newRoutes;
};
//扁平化为2级路由
export const flatteningRoutes2 = (routes: RouteRecordRaw[], startIndex = 0) => {
export const flatteningRoutes2 = (routes: RouteRecordRaw[], startIndex = 0, ignoreFirst = false) => {
const newRoutes = [] as RouteRecordRaw[];
routes.forEach((route, index) => {
if (!route.meta) {
Expand All @@ -90,7 +83,15 @@ export const flatteningRoutes2 = (routes: RouteRecordRaw[], startIndex = 0) => {
Object.assign(
{ ...route },
{
children: route.children ? flatteningRoutes(route.children, route.path, [index + startIndex]) : [],
children: route.children
? flatteningRoutes(
route.children,
route.path,
ignoreFirst ? [] : [index + startIndex],
[],
ignoreFirst ? index + startIndex : 0,
)
: [],
},
),
);
Expand Down
4 changes: 2 additions & 2 deletions src/router/routes/example/6-multilevel.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { RouteRecordRaw } from 'vue-router';
import { LayoutPage } from '@/router/constant';
import { Layout } from '@/router/constant';
import { concatObjectValue } from '@/utils/helper';
export const routes: RouteRecordRaw[] = [
{
path: 'multilevel',
component: LayoutPage,
component: Layout,
meta: { title: '多级菜单' },
children: concatObjectValue<RouteRecordRaw>(
import.meta.glob('./multilevel/*.ts', { eager: true, import: 'routes' }),
Expand Down
6 changes: 3 additions & 3 deletions src/router/routes/example/multilevel/1.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import { RouteRecordRaw } from 'vue-router';
import { LayoutPage } from '@/router/constant';
import { Layout } from '@/router/constant';
export const routes: RouteRecordRaw[] = [
{
path: '1',
component: LayoutPage,
component: Layout,
meta: { title: '多级菜单1' },
children: [
{
path: '1-1',
component: LayoutPage,
component: Layout,
meta: { title: '多级菜单1-1', alwaysShow: true },
redirect: '/example/multilevel/1/1-1/1-1-1',
children: [
Expand Down
18 changes: 17 additions & 1 deletion src/store/modules/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import { router, constantRoutes, asyncRoutes, flatteningRoutes2 } from '@/router
import { RouteRecordRaw } from 'vue-router';
import { settingConfig } from '@/config';
import { menuApi } from '@/api/routeMenu';
import { PageEnum } from '@/dict/pageEnum';
import { Layout } from '@/router/constant';
export default defineStore('route', {
state: () => ({
addRoutes: [] as RouteRecordRaw[],
Expand All @@ -31,7 +33,21 @@ export default defineStore('route', {
},
//初始化路由
async initRoutes() {
flatteningRoutes2(await this.generateRoutes(), constantRoutes.length).forEach((route) => router.addRoute(route));
flatteningRoutes2(
[
{
path: '/',
redirect: PageEnum.HOME,
meta: {
title: '',
},
component: Layout,
children: await this.generateRoutes(),
},
],
constantRoutes.length,
true,
).forEach((route) => router.addRoute(route));
},
},
});
2 changes: 1 addition & 1 deletion src/views/login/components/header.vue
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<script setup lang="ts" name="Header">
import { localeConfig } from '@/config';
import { useSettingStore } from '@/store';
const { themeConfig } = useSettingStore();
const { themeConfig } = storeToRefs(useSettingStore());
</script>
<style lang="scss" scoped>
.header {
Expand Down
2 changes: 2 additions & 0 deletions types/auto-imports.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
export {}
declare global {
const EffectScope: typeof import('vue')['EffectScope']
const ElLoading: typeof import('element-plus/es')['ElLoading']
const ElMessageBox: typeof import('element-plus/es')['ElMessageBox']
const acceptHMRUpdate: typeof import('pinia')['acceptHMRUpdate']
const asyncComputed: typeof import('@vueuse/core')['asyncComputed']
const autoResetRef: typeof import('@vueuse/core')['autoResetRef']
Expand Down

0 comments on commit 9b716ac

Please sign in to comment.