perf: tsx use useExpose

This commit is contained in:
vben
2020-12-08 22:53:29 +08:00
parent 29461a8568
commit 9bb751475d
14 changed files with 63 additions and 55 deletions

View File

@@ -11,7 +11,7 @@
<script lang="ts">
import { defineComponent, ref, unref, nextTick } from 'vue';
import { Scrollbar } from '/@/components/Scrollbar';
import { Scrollbar, ScrollbarType } from '/@/components/Scrollbar';
import { useScrollTo } from '/@/hooks/event/useScrollTo';
@@ -19,15 +19,17 @@
name: 'ScrollContainer',
components: { Scrollbar },
setup() {
const scrollbarRef = ref<RefInstanceType<any>>(null);
const scrollbarRef = ref<Nullable<ScrollbarType>>(null);
function scrollTo(to: number, duration = 500) {
const scrollbar = unref(scrollbarRef);
if (!scrollbar) return;
nextTick(() => {
const wrap = unref(scrollbar.wrap);
if (!wrap) return;
const { start } = useScrollTo({
el: unref(scrollbar.$.wrap),
el: wrap,
to,
duration,
});
@@ -38,7 +40,7 @@
function getScrollWrap() {
const scrollbar = unref(scrollbarRef);
if (!scrollbar) return null;
return scrollbar.$.wrap;
return scrollbar.wrap;
}
function scrollBottom() {
@@ -46,9 +48,11 @@
if (!scrollbar) return;
nextTick(() => {
const scrollHeight = scrollbar.$.wrap.scrollHeight as number;
const wrap = unref(scrollbar.wrap);
if (!wrap) return;
const scrollHeight = wrap.scrollHeight as number;
const { start } = useScrollTo({
el: unref(scrollbar.$.wrap),
el: wrap,
to: scrollHeight,
});
start();

View File

@@ -31,17 +31,7 @@
import type { Ref, WatchStopHandle } from 'vue';
import type { ValidateFields } from 'ant-design-vue/lib/form/interface';
import {
defineComponent,
reactive,
ref,
computed,
unref,
toRef,
onMounted,
watch,
toRefs,
} from 'vue';
import { defineComponent, reactive, ref, computed, unref, onMounted, watch, toRefs } from 'vue';
import { Form, Row } from 'ant-design-vue';
import FormItem from './FormItem';
import { basicProps } from './props';

View File

@@ -2,4 +2,10 @@
* copy from element-ui
*/
export { default as Scrollbar } from './src/Scrollbar';
import Scrollbar from './src/Scrollbar';
import { withInstall } from '../util';
withInstall(Scrollbar);
export { Scrollbar };
export type { ScrollbarType } from './src/types';

View File

@@ -15,8 +15,9 @@ import {
onBeforeUnmount,
} from 'vue';
import { getSlot } from '/@/utils/helper/tsxHelper';
import { tryTsxEmit } from '/@/utils/helper/vueHelper';
import './index.less';
import { useExpose } from '/@/hooks/core/useExpose';
import { ScrollbarType } from './types';
export default defineComponent({
name: 'Scrollbar',
@@ -65,10 +66,9 @@ export default defineComponent({
}
onMounted(() => {
tryTsxEmit<any>((instance) => {
instance.wrap = unref(wrapElRef);
useExpose<ScrollbarType>({
wrap: unref(wrapElRef),
});
const { native, noresize } = props;
const resizeEl = unref(resizeRef);
const warpEl = unref(wrapElRef);

View File

@@ -12,3 +12,7 @@ export interface BarMap {
vertical: BarMapItem;
horizontal: BarMapItem;
}
export interface ScrollbarType {
wrap: ElRef;
}

View File

@@ -69,6 +69,7 @@
import { basicProps } from './props';
import { ROW_KEY } from './const';
import './style/index.less';
import { useExpose } from '/@/hooks/core/useExpose';
export default defineComponent({
props: basicProps,
components: { Table, BasicForm },
@@ -309,6 +310,8 @@
wrapRef,
});
useExpose<TableActionType>(tableAction);
emit('register', tableAction);
return {
tableElRef,
@@ -322,7 +325,7 @@
getRowClassName,
wrapRef,
tableAction,
...tableAction,
redoHeight,
};
},
});

View File

@@ -11,10 +11,10 @@ import { useContextMenu, ContextMenuItem } from '/@/hooks/web/useContextMenu';
import { isFunction } from '/@/utils/is';
import { omit } from 'lodash-es';
import { extendSlots } from '/@/utils/helper/tsxHelper';
import { tryTsxEmit } from '/@/utils/helper/vueHelper';
import { basicProps } from './props';
import { useTree } from './useTree';
import { useExpose } from '/@/hooks/core/useExpose';
interface State {
expandedKeys: Keys;
@@ -182,20 +182,21 @@ export default defineComponent({
state.checkedKeys = props.checkedKeys;
});
tryTsxEmit<TreeActionType>((currentInstance) => {
currentInstance.setExpandedKeys = setExpandedKeys;
currentInstance.getExpandedKeys = getExpandedKeys;
currentInstance.setSelectedKeys = setSelectedKeys;
currentInstance.getSelectedKeys = getSelectedKeys;
currentInstance.setCheckedKeys = setCheckedKeys;
currentInstance.getCheckedKeys = getCheckedKeys;
currentInstance.insertNodeByKey = insertNodeByKey;
currentInstance.deleteNodeByKey = deleteNodeByKey;
currentInstance.updateNodeByKey = updateNodeByKey;
currentInstance.filterByLevel = (level: number) => {
useExpose<TreeActionType>({
setExpandedKeys,
getExpandedKeys,
setSelectedKeys,
getSelectedKeys,
setCheckedKeys,
getCheckedKeys,
insertNodeByKey,
deleteNodeByKey,
updateNodeByKey,
filterByLevel: (level: number) => {
state.expandedKeys = filterByLevel(level);
};
},
});
return () => {
return (
<Tree {...unref(getBindValues)} class={prefixCls}>

View File

@@ -5,8 +5,8 @@ import { basicProps } from './props';
import { getSlot } from '/@/utils/helper/tsxHelper';
import './DragVerify.less';
import { CheckOutlined, DoubleRightOutlined } from '@ant-design/icons-vue';
import { tryTsxEmit } from '/@/utils/helper/vueHelper';
import type { DragVerifyActionType } from './types';
import { useExpose } from '/@/hooks/core/useExpose';
export default defineComponent({
name: 'BaseDargVerify',
props: basicProps,
@@ -211,8 +211,8 @@ export default defineComponent({
contentEl.style.width = unref(getContentStyleRef).width;
}
tryTsxEmit<DragVerifyActionType>((instance) => {
instance.resume = resume;
useExpose<DragVerifyActionType>({
resume,
});
return () => {

View File

@@ -18,7 +18,7 @@ export default defineComponent({
props: rotateProps,
emits: ['success', 'change', 'update:value'],
setup(props, { emit, attrs }) {
const basicRef = ref<RefInstanceType<DragVerifyActionType>>(null);
const basicRef = ref<Nullable<DragVerifyActionType>>(null);
const state = reactive({
showTip: false,
isPassing: false,
@@ -113,7 +113,7 @@ export default defineComponent({
}
state.isPassing = false;
basicEl.$.resume();
basicEl.resume();
handleImgOnLoad();
}