Skip to content

Commit

Permalink
perf: code optimization
Browse files Browse the repository at this point in the history
  • Loading branch information
anncwb committed Mar 28, 2021
1 parent 2f99892 commit 37f6660
Show file tree
Hide file tree
Showing 18 changed files with 136 additions and 219 deletions.
4 changes: 3 additions & 1 deletion build/config/themeConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import { generate } from '@ant-design/colors';

export const primaryColor = '#0960bd';

export const borderColorBase = '#d9d9d9';

export const themeMode = 'light';

export type ThemeMode = 'dark' | 'light';
Expand Down Expand Up @@ -97,7 +99,7 @@ export function generateModifyVars() {
'text-color-secondary': 'rgba(0, 0, 0, 0.45)', // Subtext color
'font-size-base': '14px', // Main font size
'box-shadow-base': '0 2px 8px rgba(0, 0, 0, 0.15)', // Floating shadow
'border-color-base': '#d9d9d9', // Border color,
'border-color-base': borderColorBase, // Border color,
'border-radius-base': '2px', // Component/float fillet
'link-color': primary, // Link color
};
Expand Down
12 changes: 6 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
"@iconify/iconify": "^2.0.0-rc.6",
"@vueuse/core": "^4.6.2",
"@zxcvbn-ts/core": "^0.3.0",
"ant-design-vue": "2.1.1",
"ant-design-vue": "^2.1.2",
"apexcharts": "^3.26.0",
"axios": "^0.21.1",
"crypto-js": "^4.0.0",
Expand All @@ -47,7 +47,7 @@
"qrcode": "^1.4.4",
"sortablejs": "^1.13.0",
"vditor": "^3.8.4",
"vue": "^3.0.9",
"vue": "3.0.7",
"vue-i18n": "^9.0.0",
"vue-router": "^4.0.5",
"vue-types": "^3.0.2",
Expand Down Expand Up @@ -75,7 +75,7 @@
"@vitejs/plugin-legacy": "^1.3.2",
"@vitejs/plugin-vue": "^1.2.0",
"@vitejs/plugin-vue-jsx": "^1.1.2",
"@vue/compiler-sfc": "^3.0.9",
"@vue/compiler-sfc": "3.0.7",
"autoprefixer": "^10.2.5",
"body-parser": "^1.19.0",
"commitizen": "^4.2.3",
Expand Down Expand Up @@ -112,11 +112,11 @@
"vite-plugin-imagemin": "^0.2.9",
"vite-plugin-mock": "^2.4.0",
"vite-plugin-purge-icons": "^0.7.0",
"vite-plugin-pwa": "^0.6.3",
"vite-plugin-style-import": "^0.9.0",
"vite-plugin-pwa": "^0.6.4",
"vite-plugin-style-import": "^0.9.1",
"vite-plugin-svg-icons": "^0.4.0",
"vite-plugin-theme": "^0.5.0",
"vite-plugin-windicss": "0.10.2",
"vite-plugin-windicss": "0.10.4",
"vue-eslint-parser": "^7.6.0"
},
"resolutions": {
Expand Down
24 changes: 18 additions & 6 deletions src/components/Basic/src/BasicTitle.vue
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
<template>
<span :class="[prefixCls, { 'show-span': span && $slots.default }]">
<span :class="getClass">
<slot></slot>
<BasicHelp :class="`${prefixCls}__help`" v-if="helpMessage" :text="helpMessage" />
</span>
</template>
<script lang="ts">
import type { PropType } from 'vue';
import { defineComponent } from 'vue';
import { defineComponent, computed } from 'vue';
import BasicHelp from './BasicHelp.vue';
import { useDesign } from '/@/hooks/web/useDesign';
Expand All @@ -23,10 +23,17 @@
default: '',
},
span: propTypes.bool,
normal: propTypes.bool.def(false),
},
setup() {
setup(props, { slots }) {
const { prefixCls } = useDesign('basic-title');
return { prefixCls };
const getClass = computed(() => [
prefixCls,
{ [`${prefixCls}-show-span`]: props.span && slots.default },
{ [`${prefixCls}-normal`]: props.normal },
]);
return { prefixCls, getClass };
},
});
</script>
Expand All @@ -38,13 +45,18 @@
display: flex;
padding-left: 7px;
font-size: 16px;
font-weight: 700;
font-weight: 500;
line-height: 24px;
color: @text-color-base;
cursor: pointer;
user-select: none;
&.show-span::before {
&-normal {
font-size: 14px;
font-weight: normal;
}
&-show-span::before {
position: absolute;
top: 4px;
left: 0;
Expand Down
1 change: 0 additions & 1 deletion src/components/ClickOutSide/src/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
</template>
<script lang="ts">
import { defineComponent, ref, onMounted } from 'vue';
import { onClickOutside } from '@vueuse/core';
export default defineComponent({
name: 'ClickOutSide',
Expand Down
14 changes: 1 addition & 13 deletions src/components/Container/src/LazyContainer.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<template>
<transition-group
:class="prefixCls"
class="h-full w-full"
v-bind="$attrs"
ref="elRef"
:name="transitionName"
Expand All @@ -25,7 +25,6 @@
import { useTimeoutFn } from '/@/hooks/core/useTimeout';
import { useIntersectionObserver } from '/@/hooks/event/useIntersectionObserver';
import { propTypes } from '/@/utils/propTypes';
import { useDesign } from '/@/hooks/web/useDesign';
interface State {
isInit: boolean;
Expand Down Expand Up @@ -72,8 +71,6 @@
intersectionObserverInstance: null,
});
const { prefixCls } = useDesign('lazy-container');
onMounted(() => {
immediateInit();
initIntersectionObserver();
Expand Down Expand Up @@ -133,17 +130,8 @@
}
return {
elRef,
prefixCls,
...toRefs(state),
};
},
});
</script>
<style lang="less">
@prefix-cls: ~'@{namespace}-lazy-container';
.@{prefix-cls} {
width: 100%;
height: 100%;
}
</style>
21 changes: 15 additions & 6 deletions src/components/Container/src/ScrollContainer.vue
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,21 @@
export default defineComponent({
name: 'ScrollContainer',
// inheritAttrs: false,
components: { Scrollbar },
setup() {
const scrollbarRef = ref<Nullable<ScrollbarType>>(null);
function scrollTo(to: number, duration = 500) {
const scrollbar = unref(scrollbarRef);
if (!scrollbar) return;
if (!scrollbar) {
return;
}
nextTick(() => {
const wrap = unref(scrollbar.wrap);
if (!wrap) return;
if (!wrap) {
return;
}
const { start } = useScrollTo({
el: wrap,
to,
Expand All @@ -35,17 +38,23 @@
function getScrollWrap() {
const scrollbar = unref(scrollbarRef);
if (!scrollbar) return null;
if (!scrollbar) {
return null;
}
return scrollbar.wrap;
}
function scrollBottom() {
const scrollbar = unref(scrollbarRef);
if (!scrollbar) return;
if (!scrollbar) {
return;
}
nextTick(() => {
const wrap = unref(scrollbar.wrap);
if (!wrap) return;
if (!wrap) {
return;
}
const scrollHeight = wrap.scrollHeight as number;
const { start } = useScrollTo({
el: wrap,
Expand Down
32 changes: 12 additions & 20 deletions src/components/Container/src/collapse/CollapseContainer.vue
Original file line number Diff line number Diff line change
@@ -1,29 +1,24 @@
<template>
<div :class="['p-2', prefixCls]">
<div :class="prefixCls">
<CollapseHeader
v-bind="getBindValues"
:prefixCls="prefixCls"
:show="show"
@expand="handleExpand"
:class="show ? 'mb-3' : ''"
>
<template #title>
<slot name="title"></slot>
</template>
</CollapseHeader>

<CollapseTransition :enable="canExpan">
<Skeleton v-if="loading" />
<div :class="`${prefixCls}__body`" v-else v-show="show">
<LazyContainer :timeout="lazyTime" v-if="lazy">
<div class="p-2">
<CollapseTransition :enable="canExpan">
<Skeleton v-if="loading" :active="active" />
<div :class="`${prefixCls}__body`" v-else v-show="show">
<slot></slot>
<template #skeleton>
<slot name="lazySkeleton"></slot>
</template>
</LazyContainer>
<slot v-else></slot>
</div>
</CollapseTransition>
</div>
</CollapseTransition>
</div>
</div>
</template>
<script lang="ts">
Expand All @@ -33,9 +28,8 @@
// component
import { Skeleton } from 'ant-design-vue';
import { CollapseTransition } from '/@/components/Transition/index';
import { CollapseTransition } from '/@/components/Transition';
import CollapseHeader from './CollapseHeader.vue';
import LazyContainer from '../LazyContainer.vue';
import { triggerWindowResize } from '/@/utils/event';
// hook
Expand All @@ -47,7 +41,6 @@
name: 'CollapseContainer',
components: {
Skeleton,
LazyContainer,
CollapseHeader,
CollapseTransition,
},
Expand All @@ -63,9 +56,8 @@
// Whether to trigger window.resize when expanding and contracting,
// Can adapt to tables and forms, when the form shrinks, the form triggers resize to adapt to the height
triggerWindowResize: propTypes.bool,
loading: propTypes.bool,
// Delayed loading
lazy: propTypes.bool,
loading: propTypes.bool.def(false),
active: propTypes.bool.def(true),
// Delayed loading time
lazyTime: propTypes.number.def(0),
},
Expand Down Expand Up @@ -109,9 +101,9 @@
&__header {
display: flex;
height: 32px;
// margin-bottom: 10px;
justify-content: space-between;
align-items: center;
border-bottom: 1px solid @border-color-light;
}
&__action {
Expand Down
4 changes: 2 additions & 2 deletions src/components/Container/src/collapse/CollapseHeader.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<template>
<div :class="[`${prefixCls}__header`, $attrs.class]">
<BasicTitle :helpMessage="helpMessage">
<div :class="[`${prefixCls}__header px-2 py-5`, $attrs.class]">
<BasicTitle :helpMessage="helpMessage" normal>
<template v-if="title">
{{ title }}
</template>
Expand Down
6 changes: 3 additions & 3 deletions src/components/Scrollbar/src/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -111,9 +111,9 @@
onBeforeUnmount(() => {
if (props.native) return;
if (!props.noresize) {
removeResizeListener(unref(resize), update);
removeResizeListener(unref(wrap), update);
removeEventListener('resize', update);
// removeResizeListener(unref(resize), update);
// removeResizeListener(unref(wrap), update);
// removeEventListener('resize', update);
}
});
Expand Down
8 changes: 4 additions & 4 deletions src/components/SimpleMenu/src/components/SubMenuItem.vue
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@
:class="`${prefixCls}-submenu-title-icon`"
/>
</div>
<MenuCollapseTransition>
<CollapseTransition>
<ul :class="prefixCls" v-show="opened">
<slot></slot>
</ul>
</MenuCollapseTransition>
</CollapseTransition>
</template>

<Popover
Expand Down Expand Up @@ -72,7 +72,7 @@
import { propTypes } from '/@/utils/propTypes';
import { useMenuItem } from './useMenu';
import { useSimpleRootMenuContext } from './useSimpleMenuContext';
import MenuCollapseTransition from './MenuCollapseTransition.vue';
import { CollapseTransition } from '/@/components/Transition';
import Icon from '/@/components/Icon';
import { Popover } from 'ant-design-vue';
import { isBoolean, isObject } from '/@/utils/is';
Expand All @@ -83,7 +83,7 @@
name: 'SubMenu',
components: {
Icon,
MenuCollapseTransition,
CollapseTransition,
Popover,
},
props: {
Expand Down
8 changes: 4 additions & 4 deletions src/components/SimpleMenu/src/components/menu.less
Original file line number Diff line number Diff line change
Expand Up @@ -101,10 +101,10 @@
list-style: none;
outline: none;

.collapse-transition {
transition: @transition-time height ease-in-out, @transition-time padding-top ease-in-out,
@transition-time padding-bottom ease-in-out;
}
// .collapse-transition {
// transition: @transition-time height ease-in-out, @transition-time padding-top ease-in-out,
// @transition-time padding-bottom ease-in-out;
// }

&-light {
background: #fff;
Expand Down
5 changes: 3 additions & 2 deletions src/components/Table/src/BasicTable.vue
Original file line number Diff line number Diff line change
Expand Up @@ -185,8 +185,10 @@
} = useTableForm(getProps, slots, fetch);
const getBindValues = computed(() => {
const dataSource = toRaw(unref(getDataSourceRef));
let propsData: Recordable = {
size: 'middle',
// ...(dataSource.length === 0 ? { getPopupContainer: () => document.body } : {}),
...attrs,
customRow,
expandIcon: expandIcon(),
Expand All @@ -199,7 +201,7 @@
rowKey: unref(getRowKey),
columns: toRaw(unref(getViewColumns)),
pagination: toRaw(unref(getPaginationInfo)),
dataSource: toRaw(unref(getDataSourceRef)),
dataSource,
footer: unref(getFooterProps),
...unref(getExpandOption),
};
Expand All @@ -208,7 +210,6 @@
}
propsData = omit(propsData, 'class');
return propsData;
});
Expand Down
Loading

0 comments on commit 37f6660

Please sign in to comment.