Commit 5f2a927cd50a5efe4c9576528d944553c5243277
1 parent
03b6025d
perf: optimized page switching effect
Showing
12 changed files
with
47 additions
and
40 deletions
package.json
1 | { | 1 | { |
2 | "name": "vben-admin-2.0", | 2 | "name": "vben-admin-2.0", |
3 | - "version": "2.0.0-beta.4", | 3 | + "version": "2.0.0-beta.5", |
4 | "scripts": { | 4 | "scripts": { |
5 | "bootstrap": "yarn install", | 5 | "bootstrap": "yarn install", |
6 | "serve": "ts-node --project ./build/tsconfig.json ./build/script/preserve && cross-env NODE_ENV=development vite", | 6 | "serve": "ts-node --project ./build/tsconfig.json ./build/script/preserve && cross-env NODE_ENV=development vite", |
@@ -55,7 +55,6 @@ | @@ -55,7 +55,6 @@ | ||
55 | "@typescript-eslint/parser": "^4.4.0", | 55 | "@typescript-eslint/parser": "^4.4.0", |
56 | "@vue/compiler-sfc": "^3.0.0", | 56 | "@vue/compiler-sfc": "^3.0.0", |
57 | "autoprefixer": "^9.8.6", | 57 | "autoprefixer": "^9.8.6", |
58 | - "babel-plugin-import": "^1.13.0", | ||
59 | "commitizen": "^4.2.1", | 58 | "commitizen": "^4.2.1", |
60 | "conventional-changelog-cli": "^2.1.0", | 59 | "conventional-changelog-cli": "^2.1.0", |
61 | "conventional-changelog-custom-config": "^0.3.1", | 60 | "conventional-changelog-custom-config": "^0.3.1", |
src/components/Menu/src/BasicMenu.tsx
1 | import type { MenuState } from './types'; | 1 | import type { MenuState } from './types'; |
2 | import type { Menu as MenuType } from '/@/router/types'; | 2 | import type { Menu as MenuType } from '/@/router/types'; |
3 | 3 | ||
4 | -import { | ||
5 | - computed, | ||
6 | - defineComponent, | ||
7 | - unref, | ||
8 | - reactive, | ||
9 | - toRef, | ||
10 | - watch, | ||
11 | - onMounted, | ||
12 | - watchEffect, | ||
13 | - ref, | ||
14 | -} from 'vue'; | 4 | +import { computed, defineComponent, unref, reactive, toRef, watch, onMounted, ref } from 'vue'; |
15 | import { basicProps } from './props'; | 5 | import { basicProps } from './props'; |
16 | import { Menu } from 'ant-design-vue'; | 6 | import { Menu } from 'ant-design-vue'; |
17 | import { MenuModeEnum, MenuTypeEnum } from '/@/enums/menuEnum'; | 7 | import { MenuModeEnum, MenuTypeEnum } from '/@/enums/menuEnum'; |
@@ -106,11 +96,18 @@ export default defineComponent({ | @@ -106,11 +96,18 @@ export default defineComponent({ | ||
106 | getParentPath(); | 96 | getParentPath(); |
107 | } | 97 | } |
108 | ); | 98 | ); |
109 | - watchEffect(() => { | ||
110 | - if (props.items) { | ||
111 | - handleMenuChange(); | 99 | + |
100 | + watch( | ||
101 | + () => props.items, | ||
102 | + () => { | ||
103 | + if (props.items) { | ||
104 | + handleMenuChange(); | ||
105 | + } | ||
106 | + }, | ||
107 | + { | ||
108 | + immediate: true, | ||
112 | } | 109 | } |
113 | - }); | 110 | + ); |
114 | 111 | ||
115 | async function getParentPath() { | 112 | async function getParentPath() { |
116 | const { appendClass } = props; | 113 | const { appendClass } = props; |
src/layouts/default/LayoutSideBar.tsx
@@ -158,7 +158,6 @@ export default defineComponent({ | @@ -158,7 +158,6 @@ export default defineComponent({ | ||
158 | menuSetting: { theme, split: splitMenu }, | 158 | menuSetting: { theme, split: splitMenu }, |
159 | } = unref(getProjectConfigRef); | 159 | } = unref(getProjectConfigRef); |
160 | const { getCollapsedState, getMenuWidthState } = menuStore; | 160 | const { getCollapsedState, getMenuWidthState } = menuStore; |
161 | - | ||
162 | return ( | 161 | return ( |
163 | <Layout.Sider | 162 | <Layout.Sider |
164 | onCollapse={onCollapseChange} | 163 | onCollapse={onCollapseChange} |
src/layouts/default/index.less
1 | @import (reference) '../../design/index.less'; | 1 | @import (reference) '../../design/index.less'; |
2 | 2 | ||
3 | +.ant-menu-submenu .ant-menu-sub { | ||
4 | + transition: background 0.1s cubic-bezier(0.645, 0.045, 0.355, 1) 0s, | ||
5 | + padding 0.1s cubic-bezier(0.645, 0.045, 0.355, 1) 0s !important; | ||
6 | +} | ||
7 | + | ||
3 | .default-layout { | 8 | .default-layout { |
4 | &__content { | 9 | &__content { |
5 | position: relative; | 10 | position: relative; |
src/layouts/default/setting/SettingDrawer.tsx
@@ -262,7 +262,7 @@ export default defineComponent({ | @@ -262,7 +262,7 @@ export default defineComponent({ | ||
262 | size="small" | 262 | size="small" |
263 | min={0} | 263 | min={0} |
264 | onChange={(e) => { | 264 | onChange={(e) => { |
265 | - baseHandler('menuWidth', e); | 265 | + baseHandler('lockTime', e); |
266 | }} | 266 | }} |
267 | defaultValue={appStore.getProjectConfig.lockTime} | 267 | defaultValue={appStore.getProjectConfig.lockTime} |
268 | formatter={(value: string) => { | 268 | formatter={(value: string) => { |
@@ -448,7 +448,7 @@ export default defineComponent({ | @@ -448,7 +448,7 @@ export default defineComponent({ | ||
448 | }, | 448 | }, |
449 | }; | 449 | }; |
450 | } | 450 | } |
451 | - if (event === 'menuWidth') { | 451 | + if (event === 'lockTime') { |
452 | config = { | 452 | config = { |
453 | lockTime: value, | 453 | lockTime: value, |
454 | }; | 454 | }; |
src/layouts/iframe/useFrameKeepAlive.ts
@@ -32,9 +32,6 @@ export function useFrameKeepAlive() { | @@ -32,9 +32,6 @@ export function useFrameKeepAlive() { | ||
32 | const getFramePages = computed(() => { | 32 | const getFramePages = computed(() => { |
33 | const ret = | 33 | const ret = |
34 | getAllFramePages((toRaw(router.getRoutes()) as unknown) as AppRouteRecordRaw[]) || []; | 34 | getAllFramePages((toRaw(router.getRoutes()) as unknown) as AppRouteRecordRaw[]) || []; |
35 | - console.log('======================'); | ||
36 | - console.log(ret); | ||
37 | - console.log('======================'); | ||
38 | return ret; | 35 | return ret; |
39 | }); | 36 | }); |
40 | 37 |
src/layouts/page/index.tsx
@@ -40,6 +40,7 @@ export default defineComponent({ | @@ -40,6 +40,7 @@ export default defineComponent({ | ||
40 | <RouterView> | 40 | <RouterView> |
41 | {{ | 41 | {{ |
42 | default: ({ Component, route }: { Component: any; route: RouteLocation }) => { | 42 | default: ({ Component, route }: { Component: any; route: RouteLocation }) => { |
43 | + const name = route.meta.inTab ? ' ' : null; | ||
43 | const Content = openCache ? ( | 44 | const Content = openCache ? ( |
44 | <KeepAlive max={max} include={cacheTabs}> | 45 | <KeepAlive max={max} include={cacheTabs}> |
45 | <Component {...route.params} /> | 46 | <Component {...route.params} /> |
@@ -50,7 +51,7 @@ export default defineComponent({ | @@ -50,7 +51,7 @@ export default defineComponent({ | ||
50 | return openRouterTransition ? ( | 51 | return openRouterTransition ? ( |
51 | <Transition | 52 | <Transition |
52 | {...on} | 53 | {...on} |
53 | - name={route.meta.transitionName || routerTransition} | 54 | + name={name || route.meta.transitionName || routerTransition} |
54 | mode="out-in" | 55 | mode="out-in" |
55 | > | 56 | > |
56 | {() => Content} | 57 | {() => Content} |
src/router/guard/progressGuard.ts
@@ -2,17 +2,20 @@ import type { Router } from 'vue-router'; | @@ -2,17 +2,20 @@ import type { Router } from 'vue-router'; | ||
2 | 2 | ||
3 | import NProgress from 'nprogress'; | 3 | import NProgress from 'nprogress'; |
4 | import 'nprogress/nprogress.css'; | 4 | import 'nprogress/nprogress.css'; |
5 | +import { getIsOpenTab } from '/@/utils/helper/routeHelper'; | ||
5 | 6 | ||
6 | export function createProgressGuard(router: Router) { | 7 | export function createProgressGuard(router: Router) { |
7 | - NProgress.inc(0.1); | ||
8 | - NProgress.configure({ easing: 'ease', speed: 200, showSpinner: false }); | 8 | + // NProgress.inc(0.1); |
9 | + // NProgress.configure({ easing: 'ease', speed: 200, showSpinner: false }); | ||
9 | 10 | ||
10 | - router.beforeEach(async () => { | ||
11 | - NProgress.start(); | 11 | + router.beforeEach(async (to) => { |
12 | + const isOpen = getIsOpenTab(to.path); | ||
13 | + to.meta.inTab = isOpen; | ||
14 | + !isOpen && NProgress.start(); | ||
12 | return true; | 15 | return true; |
13 | }); | 16 | }); |
14 | - router.afterEach(async () => { | ||
15 | - NProgress.done(); | 17 | + router.afterEach(async (to) => { |
18 | + !to.meta.inTab && NProgress.done(); | ||
16 | return true; | 19 | return true; |
17 | }); | 20 | }); |
18 | } | 21 | } |
src/router/types.d.ts
@@ -29,6 +29,8 @@ export interface RouteMeta { | @@ -29,6 +29,8 @@ export interface RouteMeta { | ||
29 | 29 | ||
30 | // close loading | 30 | // close loading |
31 | afterCloseLoading?: boolean; | 31 | afterCloseLoading?: boolean; |
32 | + | ||
33 | + inTab?: boolean; | ||
32 | } | 34 | } |
33 | 35 | ||
34 | export interface AppRouteRecordRaw extends Omit<RouteRecordRaw, 'meta'> { | 36 | export interface AppRouteRecordRaw extends Omit<RouteRecordRaw, 'meta'> { |
src/useApp.tsx renamed to src/useApp.ts
src/utils/helper/routeHelper.ts
1 | import type { AppRouteModule, AppRouteRecordRaw } from '/@/router/types'; | 1 | import type { AppRouteModule, AppRouteRecordRaw } from '/@/router/types'; |
2 | import type { RouteRecordRaw } from 'vue-router'; | 2 | import type { RouteRecordRaw } from 'vue-router'; |
3 | 3 | ||
4 | +import { appStore } from '/@/store/modules/app'; | ||
5 | +import { tabStore } from '/@/store/modules/tab'; | ||
4 | import { createRouter, createWebHashHistory } from 'vue-router'; | 6 | import { createRouter, createWebHashHistory } from 'vue-router'; |
5 | import { toRaw } from 'vue'; | 7 | import { toRaw } from 'vue'; |
6 | import { PAGE_LAYOUT_COMPONENT } from '/@/router/constant'; | 8 | import { PAGE_LAYOUT_COMPONENT } from '/@/router/constant'; |
@@ -45,3 +47,13 @@ export function transformObjToRoute(routeList: AppRouteModule[]) { | @@ -45,3 +47,13 @@ export function transformObjToRoute(routeList: AppRouteModule[]) { | ||
45 | }); | 47 | }); |
46 | return routeList; | 48 | return routeList; |
47 | } | 49 | } |
50 | + | ||
51 | +export function getIsOpenTab(toPath: string) { | ||
52 | + const { openKeepAlive, multiTabsSetting: { show } = {} } = appStore.getProjectConfig; | ||
53 | + | ||
54 | + if (show && openKeepAlive) { | ||
55 | + const tabList = tabStore.getTabsState; | ||
56 | + return tabList.some((tab) => tab.path === toPath); | ||
57 | + } | ||
58 | + return false; | ||
59 | +} |
yarn.lock
@@ -95,7 +95,7 @@ | @@ -95,7 +95,7 @@ | ||
95 | dependencies: | 95 | dependencies: |
96 | "@babel/types" "^7.11.0" | 96 | "@babel/types" "^7.11.0" |
97 | 97 | ||
98 | -"@babel/helper-module-imports@^7.0.0", "@babel/helper-module-imports@^7.10.4": | 98 | +"@babel/helper-module-imports@^7.10.4": |
99 | version "7.10.4" | 99 | version "7.10.4" |
100 | resolved "https://registry.npmjs.org/@babel/helper-module-imports/-/helper-module-imports-7.10.4.tgz#4c5c54be04bd31670a7382797d75b9fa2e5b5620" | 100 | resolved "https://registry.npmjs.org/@babel/helper-module-imports/-/helper-module-imports-7.10.4.tgz#4c5c54be04bd31670a7382797d75b9fa2e5b5620" |
101 | integrity sha512-nEQJHqYavI217oD9+s5MUBzk6x1IlvoS9WTPfgG43CbMEeStE0v+r+TucWdx8KFGowPGvyOkDT9+7DHedIDnVw== | 101 | integrity sha512-nEQJHqYavI217oD9+s5MUBzk6x1IlvoS9WTPfgG43CbMEeStE0v+r+TucWdx8KFGowPGvyOkDT9+7DHedIDnVw== |
@@ -175,7 +175,7 @@ | @@ -175,7 +175,7 @@ | ||
175 | resolved "https://registry.npmjs.org/@babel/parser/-/parser-7.11.5.tgz#c7ff6303df71080ec7a4f5b8c003c58f1cf51037" | 175 | resolved "https://registry.npmjs.org/@babel/parser/-/parser-7.11.5.tgz#c7ff6303df71080ec7a4f5b8c003c58f1cf51037" |
176 | integrity sha512-X9rD8qqm695vgmeaQ4fvz/o3+Wk4ZzQvSHkDBgpYKxpD4qTAUm88ZKtHkVqIOsYFFbIQ6wQYhC6q7pjqVK0E0Q== | 176 | integrity sha512-X9rD8qqm695vgmeaQ4fvz/o3+Wk4ZzQvSHkDBgpYKxpD4qTAUm88ZKtHkVqIOsYFFbIQ6wQYhC6q7pjqVK0E0Q== |
177 | 177 | ||
178 | -"@babel/runtime@^7.0.0", "@babel/runtime@^7.10.4", "@babel/runtime@^7.10.5", "@babel/runtime@^7.11.2": | 178 | +"@babel/runtime@^7.10.4", "@babel/runtime@^7.10.5", "@babel/runtime@^7.11.2": |
179 | version "7.11.2" | 179 | version "7.11.2" |
180 | resolved "https://registry.npmjs.org/@babel/runtime/-/runtime-7.11.2.tgz#f549c13c754cc40b87644b9fa9f09a6a95fe0736" | 180 | resolved "https://registry.npmjs.org/@babel/runtime/-/runtime-7.11.2.tgz#f549c13c754cc40b87644b9fa9f09a6a95fe0736" |
181 | integrity sha512-TeWkU52so0mPtDcaCTxNBI/IHiz0pZgr8VEFqXFtZWpYD08ZB6FaSwVAS8MKRQAP3bYKiVjwysOJgMFY28o6Tw== | 181 | integrity sha512-TeWkU52so0mPtDcaCTxNBI/IHiz0pZgr8VEFqXFtZWpYD08ZB6FaSwVAS8MKRQAP3bYKiVjwysOJgMFY28o6Tw== |
@@ -1214,14 +1214,6 @@ babel-helper-vue-jsx-merge-props@^2.0.3: | @@ -1214,14 +1214,6 @@ babel-helper-vue-jsx-merge-props@^2.0.3: | ||
1214 | resolved "https://registry.npmjs.org/babel-helper-vue-jsx-merge-props/-/babel-helper-vue-jsx-merge-props-2.0.3.tgz#22aebd3b33902328e513293a8e4992b384f9f1b6" | 1214 | resolved "https://registry.npmjs.org/babel-helper-vue-jsx-merge-props/-/babel-helper-vue-jsx-merge-props-2.0.3.tgz#22aebd3b33902328e513293a8e4992b384f9f1b6" |
1215 | integrity sha512-gsLiKK7Qrb7zYJNgiXKpXblxbV5ffSwR0f5whkPAaBAR4fhi6bwRZxX9wBlIc5M/v8CCkXUbXZL4N/nSE97cqg== | 1215 | integrity sha512-gsLiKK7Qrb7zYJNgiXKpXblxbV5ffSwR0f5whkPAaBAR4fhi6bwRZxX9wBlIc5M/v8CCkXUbXZL4N/nSE97cqg== |
1216 | 1216 | ||
1217 | -babel-plugin-import@^1.13.0: | ||
1218 | - version "1.13.0" | ||
1219 | - resolved "https://registry.npmjs.org/babel-plugin-import/-/babel-plugin-import-1.13.0.tgz#c532fd533df9db53b47d4d4db3676090fc5c07a5" | ||
1220 | - integrity sha512-bHU8m0SrY89ub2hBBuYjbennOeH0YUYkVpH6jxKFk0uD8rhN+0jNHIPtXnac+Vn7N/hgkLGGDcIoYK7je3Hhew== | ||
1221 | - dependencies: | ||
1222 | - "@babel/helper-module-imports" "^7.0.0" | ||
1223 | - "@babel/runtime" "^7.0.0" | ||
1224 | - | ||
1225 | bail@^1.0.0: | 1217 | bail@^1.0.0: |
1226 | version "1.0.5" | 1218 | version "1.0.5" |
1227 | resolved "https://registry.npmjs.org/bail/-/bail-1.0.5.tgz#b6fa133404a392cbc1f8c4bf63f5953351e7a776" | 1219 | resolved "https://registry.npmjs.org/bail/-/bail-1.0.5.tgz#b6fa133404a392cbc1f8c4bf63f5953351e7a776" |