Skip to content

Commit

Permalink
fix(layout): transition component memory leak
Browse files Browse the repository at this point in the history
  • Loading branch information
buqiyuan committed Mar 7, 2024
1 parent 69ce11c commit 19eda95
Show file tree
Hide file tree
Showing 13 changed files with 68 additions and 58 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
"nprogress": "~1.0.0-1",
"pinia": "~2.1.7",
"qiniu-js": "^3.4.2",
"qs": "~6.11.2",
"qs": "~6.12.0",
"sortablejs": "~1.15.2",
"tinymce": "^6.8.3",
"vue": "~3.4.21",
Expand Down
4 changes: 3 additions & 1 deletion packages/vite-plugin-msw/src/browser/enableMocking.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@ export const enableMocking = async (handlers: HttpHandler[], options?: StartOpti
);
const worker = setupWorker(...handlers);

globalThis.__msw_worker = worker;
if (import.meta.env.DEV) {
globalThis.__msw_worker = worker;
}

const serviceWorkerRegistration = await worker.start({
onUnhandledRequest: 'bypass',
Expand Down
21 changes: 16 additions & 5 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion src/components/basic/icon/Icon.vue
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
const handleIconUpdated = (vnode: VNode) => {
const title = attrs.title;
if (vnode.el && title) {
globalThis.sss = vnode.el;
vnode.el.insertAdjacentHTML?.('afterbegin', `<title>${title}</title>`);
}
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

<script lang="tsx" setup>
import { computed, ref, h, type FunctionalComponent } from 'vue';
import { debounce, isFunction, isObject, isString } from 'lodash-es';
import { isFunction, isObject, isString } from 'lodash-es';
import { Popconfirm, Tooltip, type TooltipProps } from 'ant-design-vue';
import type { ActionItem } from '../types/tableAction';
import type { CustomRenderParams } from '../types/column';
Expand Down Expand Up @@ -89,7 +89,7 @@
const onClick = item.onClick;
if (isFunction(onClick) && !hasClickFnFlag(onClick)) {
item.onClick = debounce(async () => {
item.onClick = async () => {
const callbackRes = onClick(props.columnParams);
if (isPromise(callbackRes)) {
Expand All @@ -99,7 +99,7 @@
loadingMap.value.delete(key);
});
}
});
};
setClickFnFlag(item.onClick);
}
if (item.icon) {
Expand Down
12 changes: 6 additions & 6 deletions src/components/core/schema-form/src/hooks/useFormState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,19 @@ export type useFormStateParams = {
};

export const useFormState = ({ props, attrs }: useFormStateParams) => {
// TODO 将formSchema克隆一份,避免修改原有的formSchema
/** // TODO 将formSchema克隆一份,避免修改原有的formSchema */
const formPropsRef = ref<SchemaFormProps>(cloneDeep(props));
/** 表单项数据 */
const formModel = reactive({ ...props.initialValues });
// 表单默认数据
/** 表单默认数据 */
const defaultFormValues = reactive({ ...props.initialValues });
// 表单实例
/** 表单实例 */
const schemaFormRef = ref<FormInstance>();
// 缓存的表单值,用于恢复form-item v-if为true后的值
/** 缓存的表单值,用于恢复form-item v-if为true后的值 */
const cacheFormModel = { ...props.initialValues };
// 将所有的表单组件实例保存起来
/** 将所有的表单组件实例保存起来 */
const compRefMap = new Map<string, DefineComponent<any>>();
// 初始时的componentProps,用于updateSchema更新时不覆盖componentProps为函数时的值
/** 初始时的componentProps,用于updateSchema更新时不覆盖componentProps为函数时的值 */
const originComponentPropsFnMap = new Map<
string,
(opt: RenderCallbackParams) => ComponentProps
Expand Down
2 changes: 1 addition & 1 deletion src/layout/menu/menu.vue
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
});
const menus = computed(() => userStore.menus);
console.log('menus', menus.value);
// console.log('menus', menus.value);
/** 侧边栏布局 */
const isSideMenu = computed(() => layoutSettingStore.layoutSetting.layout === 'sidemenu');
const getRouteByName = (name: string) => router.getRoutes().find((n) => n.name === name);
Expand Down
26 changes: 13 additions & 13 deletions src/layout/tabs/tabs-view.vue
Original file line number Diff line number Diff line change
Expand Up @@ -23,20 +23,20 @@
<div class="tabs-view-content" :style="{ overflow }">
<router-view v-slot="{ Component }">
<template v-if="Component">
<Transition
:name="Object.is(route.meta?.transitionName, false) ? '' : 'fade-transform'"
mode="out-in"
appear
@before-leave="overflow = 'hidden'"
@after-leave="overflow = 'auto'"
>
<keep-alive :include="keepAliveComponents">
<Suspense>
<Suspense>
<Transition
name="fade-slide"
mode="out-in"
appear
@before-leave="overflow = 'hidden'"
@after-leave="overflow = 'auto'"
>
<keep-alive :include="keepAliveComponents">
<component :is="Component" :key="route.fullPath" />
<template #fallback> 正在加载... </template>
</Suspense>
</keep-alive>
</Transition>
</keep-alive>
</Transition>
<template #fallback> 正在加载... </template>
</Suspense>
</template>
</router-view>
</div>
Expand Down
2 changes: 1 addition & 1 deletion src/router/asyncModules/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,4 @@ export const asyncRoutes = Object.entries(modulesFiles).reduce((routes, [url, im
return routes;
}, {} as Recordable<ImportVueFileFnType>);

console.log('asyncRoutes', asyncRoutes);
// console.log('asyncRoutes', asyncRoutes);
2 changes: 1 addition & 1 deletion src/router/helper/routeHelper.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ export const generateDynamicRoutes = (menus: RouteRecordRaw[]) => {
rootRoute.children = [...filterRoutes];
// 4.重新添加拍平后的路由
router.addRoute(rootRoute);
console.log('routes', router.getRoutes());
// console.log('routes', router.getRoutes());

return routes;
};
Expand Down
36 changes: 18 additions & 18 deletions src/router/routes/modules/demos.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ const routes: Array<RouteRecordRaw> = [
meta: {
title: t('routes.demo.modal'),
icon: 'ant-design:desktop-outlined',
keepAlive: true,
keepAlive: false,
},
component: () => import('@/views/demos/custom-modal.vue'),
},
Expand All @@ -29,7 +29,7 @@ const routes: Array<RouteRecordRaw> = [
meta: {
title: t('routes.demo.button'),
icon: 'ant-design:desktop-outlined',
keepAlive: true,
keepAlive: false,
},
component: () => import('@/views/demos/button.vue'),
},
Expand All @@ -39,7 +39,7 @@ const routes: Array<RouteRecordRaw> = [
meta: {
title: t('routes.demo.form.demo'),
icon: 'ant-design:desktop-outlined',
keepAlive: true,
keepAlive: false,
},
redirect: { name: `${moduleName}-form-basic` },
children: [
Expand All @@ -49,7 +49,7 @@ const routes: Array<RouteRecordRaw> = [
meta: {
title: t('routes.demo.form.basic'),
icon: 'ant-design:desktop-outlined',
keepAlive: true,
keepAlive: false,
},
component: () => import('@/views/demos/form/basic-form/index.vue'),
},
Expand All @@ -59,7 +59,7 @@ const routes: Array<RouteRecordRaw> = [
meta: {
title: t('routes.demo.form.rule'),
icon: 'ant-design:desktop-outlined',
keepAlive: true,
keepAlive: false,
},
component: () => import('@/views/demos/form/rule-form/index.vue'),
},
Expand All @@ -69,7 +69,7 @@ const routes: Array<RouteRecordRaw> = [
meta: {
title: t('routes.demo.form.dynamic'),
icon: 'ant-design:desktop-outlined',
keepAlive: true,
keepAlive: false,
},
component: () => import('@/views/demos/form/dynamic-form/index.vue'),
},
Expand All @@ -79,7 +79,7 @@ const routes: Array<RouteRecordRaw> = [
meta: {
title: 'useForm',
icon: 'ant-design:desktop-outlined',
keepAlive: true,
keepAlive: false,
},
component: () => import('@/views/demos/form/use-form/index.vue'),
},
Expand All @@ -89,7 +89,7 @@ const routes: Array<RouteRecordRaw> = [
meta: {
title: t('routes.demo.form.customForm'),
icon: 'ant-design:desktop-outlined',
keepAlive: true,
keepAlive: false,
},
component: () => import('@/views/demos/form/custom-form/index.vue'),
},
Expand All @@ -99,7 +99,7 @@ const routes: Array<RouteRecordRaw> = [
meta: {
title: '自定义请求表单',
icon: 'ant-design:desktop-outlined',
keepAlive: true,
keepAlive: false,
},
component: () => import('@/views/demos/form/request-form/index.vue'),
},
Expand All @@ -111,7 +111,7 @@ const routes: Array<RouteRecordRaw> = [
meta: {
title: t('routes.demo.table.demo'),
icon: 'ant-design:desktop-outlined',
keepAlive: true,
keepAlive: false,
},
redirect: { name: `${moduleName}-table-wzry` },
children: [
Expand Down Expand Up @@ -151,7 +151,7 @@ const routes: Array<RouteRecordRaw> = [
meta: {
title: t('routes.demo.table.lol'),
icon: 'ant-design:desktop-outlined',
keepAlive: true,
keepAlive: false,
},
component: () => import('@/views/demos/tables/lol-table/index.vue'),
},
Expand All @@ -161,8 +161,8 @@ const routes: Array<RouteRecordRaw> = [
meta: {
title: '英雄详情',
icon: 'ant-design:desktop-outlined',
hideInMenu: true,
keepAlive: true,
hideInMenu: false,
keepAlive: false,
activeMenu: `${moduleName}-table-lol`,
},
component: () => import('@/views/demos/tables/lol-table/heroInfo.vue'),
Expand All @@ -176,8 +176,8 @@ const routes: Array<RouteRecordRaw> = [
meta: {
title: '嵌套路由',
icon: 'ant-design:desktop-outlined',
keepAlive: true,
hideChildrenInMenu: true,
keepAlive: false,
hideChildrenInMenu: false,
transitionName: false,
},
component: () => import('@/views/demos/nested-routes/index.vue'),
Expand All @@ -188,7 +188,7 @@ const routes: Array<RouteRecordRaw> = [
meta: {
title: '路由一',
icon: 'ant-design:desktop-outlined',
hideInMenu: true,
hideInMenu: false,
activeMenu: `${moduleName}-nested-routes`,
},
component: () => import('@/views/demos/nested-routes/route-one.vue'),
Expand All @@ -199,7 +199,7 @@ const routes: Array<RouteRecordRaw> = [
meta: {
title: '路由二',
icon: 'ant-design:desktop-outlined',
hideInMenu: true,
hideInMenu: false,
activeMenu: `${moduleName}-nested-routes`,
},
component: () => import('@/views/demos/nested-routes/route-two.vue'),
Expand All @@ -210,7 +210,7 @@ const routes: Array<RouteRecordRaw> = [
meta: {
title: '路由三',
icon: 'ant-design:desktop-outlined',
hideInMenu: true,
hideInMenu: false,
activeMenu: `${moduleName}-nested-routes`,
},
component: () => import('@/views/demos/nested-routes/route-three.vue'),
Expand Down
10 changes: 5 additions & 5 deletions src/styles/transition.less
Original file line number Diff line number Diff line change
Expand Up @@ -25,18 +25,18 @@
opacity: 0;
}

/* fade-transform */
.fade-transform-leave-active,
.fade-transform-enter-active {
/* fade-slide */
.fade-slide-leave-active,
.fade-slide-enter-active {
transition: all 0.5s;
}

.fade-transform-enter-from {
.fade-slide-enter-from {
transform: translateX(-30px);
opacity: 0;
}

.fade-transform-leave-to {
.fade-slide-leave-to {
transform: translateX(30px);
opacity: 0;
}
Expand Down
2 changes: 0 additions & 2 deletions src/views/demos/form/rule-form/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,6 @@
name: 'DemosFormRuleForm',
});
console.log('sss', import.meta.url);
/**
* @description 验证表单
*/
Expand Down

0 comments on commit 19eda95

Please sign in to comment.