mirror of
https://github.com/vbenjs/gf-vben-admin.git
synced 2025-01-24 04:10:20 +08:00
perf(button): delete the button component useless code
This commit is contained in:
parent
fb0c7763ed
commit
bdce84537a
@ -1,23 +1,20 @@
|
|||||||
<template>
|
<template>
|
||||||
<Button v-bind="getBindValue" :class="[getColor, $attrs.class]">
|
<Button v-bind="getBindValue" :class="[getColor, $attrs.class]">
|
||||||
<!-- <template #[item]="data" v-for="item in Object.keys($slots)">
|
|
||||||
<slot :name="item" v-bind="data" />
|
|
||||||
</template> -->
|
|
||||||
<template #default="data">
|
<template #default="data">
|
||||||
<Icon :icon="preIcon" class="mr-1" v-if="preIcon" />
|
<Icon :icon="preIcon" :class="{ 'mr-1': !getIsCircleBtn }" v-if="preIcon" />
|
||||||
<slot v-bind="data" />
|
<slot v-bind="data" />
|
||||||
<Icon :icon="postIcon" class="ml-1" v-if="postIcon" />
|
<Icon :icon="postIcon" :class="{ 'ml-1': !getIsCircleBtn }" v-if="postIcon" />
|
||||||
</template>
|
</template>
|
||||||
</Button>
|
</Button>
|
||||||
</template>
|
</template>
|
||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import { PropType } from 'vue';
|
import { PropType } from 'vue';
|
||||||
|
|
||||||
import { defineComponent, computed, unref } from 'vue';
|
import { defineComponent, computed } from 'vue';
|
||||||
import { Button } from 'ant-design-vue';
|
import { Button } from 'ant-design-vue';
|
||||||
// import { extendSlots } from '/@/utils/helper/tsxHelper';
|
// import { extendSlots } from '/@/utils/helper/tsxHelper';
|
||||||
import { useThrottle } from '/@/hooks/core/useThrottle';
|
// import { useThrottle } from '/@/hooks/core/useThrottle';
|
||||||
import { isFunction } from '/@/utils/is';
|
// import { isFunction } from '/@/utils/is';
|
||||||
import Icon from '/@/components/Icon';
|
import Icon from '/@/components/Icon';
|
||||||
export default defineComponent({
|
export default defineComponent({
|
||||||
name: 'AButton',
|
name: 'AButton',
|
||||||
@ -30,18 +27,18 @@
|
|||||||
default: 'default',
|
default: 'default',
|
||||||
},
|
},
|
||||||
// 节流防抖类型 throttle debounce
|
// 节流防抖类型 throttle debounce
|
||||||
throttle: {
|
// throttle: {
|
||||||
type: String as PropType<'throttle' | 'debounce'>,
|
// type: String as PropType<'throttle' | 'debounce'>,
|
||||||
default: 'throttle',
|
// default: 'throttle',
|
||||||
},
|
// },
|
||||||
color: {
|
color: {
|
||||||
type: String as PropType<'error' | 'warning' | 'success' | ''>,
|
type: String as PropType<'error' | 'warning' | 'success' | ''>,
|
||||||
},
|
},
|
||||||
// 防抖节流时间
|
// // 防抖节流时间
|
||||||
throttleTime: {
|
// throttleTime: {
|
||||||
type: Number as PropType<number>,
|
// type: Number as PropType<number>,
|
||||||
default: 0,
|
// default: 50,
|
||||||
},
|
// },
|
||||||
loading: {
|
loading: {
|
||||||
type: Boolean as PropType<boolean>,
|
type: Boolean as PropType<boolean>,
|
||||||
default: false,
|
default: false,
|
||||||
@ -58,30 +55,38 @@
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
setup(props, { attrs }) {
|
setup(props, { attrs }) {
|
||||||
const getListeners = computed(() => {
|
const getIsCircleBtn = computed(() => {
|
||||||
const { throttle, throttleTime = 0 } = props;
|
return attrs.shape === 'circle';
|
||||||
// 是否开启节流防抖
|
|
||||||
const throttleType = throttle!.toLowerCase();
|
|
||||||
const isDebounce = throttleType === 'debounce';
|
|
||||||
const openThrottle = ['throttle', 'debounce'].includes(throttleType) && throttleTime > 0;
|
|
||||||
|
|
||||||
const on: {
|
|
||||||
onClick?: Fn;
|
|
||||||
} = {};
|
|
||||||
|
|
||||||
if (attrs.onClick && isFunction(attrs.onClick) && openThrottle) {
|
|
||||||
const [handler] = useThrottle(attrs.onClick as any, throttleTime!, {
|
|
||||||
debounce: isDebounce,
|
|
||||||
immediate: true,
|
|
||||||
});
|
|
||||||
on.onClick = handler;
|
|
||||||
}
|
|
||||||
|
|
||||||
return {
|
|
||||||
...attrs,
|
|
||||||
...on,
|
|
||||||
};
|
|
||||||
});
|
});
|
||||||
|
// const getListeners = computed(() => {
|
||||||
|
// const { throttle, throttleTime = 0 } = props;
|
||||||
|
// // 是否开启节流防抖
|
||||||
|
// const throttleType = throttle!.toLowerCase();
|
||||||
|
// const isDebounce = throttleType === 'debounce';
|
||||||
|
// const openThrottle = ['throttle', 'debounce'].includes(throttleType) && throttleTime > 0;
|
||||||
|
// if (!openThrottle) {
|
||||||
|
// return {
|
||||||
|
// ...attrs,
|
||||||
|
// };
|
||||||
|
// }
|
||||||
|
|
||||||
|
// const on: {
|
||||||
|
// onClick?: Fn;
|
||||||
|
// } = {};
|
||||||
|
|
||||||
|
// if (attrs.onClick && isFunction(attrs.onClick) && openThrottle) {
|
||||||
|
// const [handler] = useThrottle(attrs.onClick as any, throttleTime!, {
|
||||||
|
// debounce: isDebounce,
|
||||||
|
// immediate: false,
|
||||||
|
// });
|
||||||
|
// on.onClick = handler;
|
||||||
|
// }
|
||||||
|
|
||||||
|
// return {
|
||||||
|
// ...attrs,
|
||||||
|
// ...on,
|
||||||
|
// };
|
||||||
|
// });
|
||||||
|
|
||||||
const getColor = computed(() => {
|
const getColor = computed(() => {
|
||||||
const res: string[] = [];
|
const res: string[] = [];
|
||||||
@ -92,9 +97,10 @@
|
|||||||
});
|
});
|
||||||
|
|
||||||
const getBindValue = computed((): any => {
|
const getBindValue = computed((): any => {
|
||||||
return { ...unref(getListeners), ...props };
|
return { ...attrs, ...props };
|
||||||
});
|
});
|
||||||
return { getBindValue, getColor };
|
|
||||||
|
return { getBindValue, getColor, getIsCircleBtn };
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
|
@ -12,9 +12,11 @@
|
|||||||
|
|
||||||
setup(_, { emit }) {
|
setup(_, { emit }) {
|
||||||
const wrapRef = ref<Nullable<HTMLDivElement | null>>(null);
|
const wrapRef = ref<Nullable<HTMLDivElement | null>>(null);
|
||||||
|
|
||||||
useClickOutside(wrapRef as Ref<HTMLDivElement>, () => {
|
useClickOutside(wrapRef as Ref<HTMLDivElement>, () => {
|
||||||
emit('clickOutside');
|
emit('clickOutside');
|
||||||
});
|
});
|
||||||
|
|
||||||
return { wrapRef };
|
return { wrapRef };
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
@ -17,7 +17,7 @@ export default defineComponent({
|
|||||||
setup(props) {
|
setup(props) {
|
||||||
const thumbRef = ref<Nullable<HTMLDivElement>>(null);
|
const thumbRef = ref<Nullable<HTMLDivElement>>(null);
|
||||||
const elRef = ref<Nullable<HTMLDivElement>>(null);
|
const elRef = ref<Nullable<HTMLDivElement>>(null);
|
||||||
const commonState = reactive<KeyString>({});
|
const commonState = reactive<Indexable>({});
|
||||||
const getBarRef = computed(() => {
|
const getBarRef = computed(() => {
|
||||||
return BAR_MAP[props.vertical ? 'vertical' : 'horizontal'];
|
return BAR_MAP[props.vertical ? 'vertical' : 'horizontal'];
|
||||||
});
|
});
|
||||||
|
24
src/setup/directives/repeatClick.ts
Normal file
24
src/setup/directives/repeatClick.ts
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
import { on, once } from '/@/utils/domUtils';
|
||||||
|
|
||||||
|
export default {
|
||||||
|
beforeMount(el: Element, binding: any) {
|
||||||
|
let interval: ReturnType<typeof setInterval> | null = null;
|
||||||
|
let startTime = 0;
|
||||||
|
const handler = () => binding.value && binding.value();
|
||||||
|
const clear = () => {
|
||||||
|
if (Date.now() - startTime < 100) {
|
||||||
|
handler();
|
||||||
|
}
|
||||||
|
interval && clearInterval(interval);
|
||||||
|
interval = null;
|
||||||
|
};
|
||||||
|
|
||||||
|
on(el, 'mousedown', (e) => {
|
||||||
|
if ((e as any).button !== 0) return;
|
||||||
|
startTime = Date.now();
|
||||||
|
once(document as any, 'mouseup', clear);
|
||||||
|
interval && clearInterval(interval);
|
||||||
|
interval = setInterval(handler, 100);
|
||||||
|
});
|
||||||
|
},
|
||||||
|
};
|
15
src/types/global.d.ts
vendored
15
src/types/global.d.ts
vendored
@ -23,15 +23,12 @@ declare type RefType<T> = T | null;
|
|||||||
|
|
||||||
declare type CustomizedHTMLElement<T> = HTMLElement & T;
|
declare type CustomizedHTMLElement<T> = HTMLElement & T;
|
||||||
|
|
||||||
declare type Indexable<T> = {
|
declare type Indexable<T = any> = {
|
||||||
[key: string]: T;
|
[key: string]: T;
|
||||||
};
|
};
|
||||||
|
declare type Hash<T> = Indexable<T>;
|
||||||
|
|
||||||
declare type KeyString<T = any> = {
|
declare type DeepPartial<T> = {
|
||||||
[key: string]: T;
|
|
||||||
};
|
|
||||||
|
|
||||||
type DeepPartial<T> = {
|
|
||||||
[P in keyof T]?: T[P] extends (infer U)[]
|
[P in keyof T]?: T[P] extends (infer U)[]
|
||||||
? RecursivePartial<U>[]
|
? RecursivePartial<U>[]
|
||||||
: T[P] extends object
|
: T[P] extends object
|
||||||
@ -39,11 +36,11 @@ type DeepPartial<T> = {
|
|||||||
: T[P];
|
: T[P];
|
||||||
};
|
};
|
||||||
|
|
||||||
type SelectOptions = {
|
declare type SelectOptions = {
|
||||||
label: string;
|
label: string;
|
||||||
value: any;
|
value: any;
|
||||||
}[];
|
}[];
|
||||||
|
|
||||||
type EmitType = (event: string, ...args: any[]) => void;
|
declare type EmitType = (event: string, ...args: any[]) => void;
|
||||||
|
|
||||||
type TargetContext = '_self' | '_blank';
|
declare type TargetContext = '_self' | '_blank';
|
||||||
|
@ -15,9 +15,11 @@ export function getBoundingClientRect(element: Element): DOMRect | number {
|
|||||||
}
|
}
|
||||||
return element.getBoundingClientRect();
|
return element.getBoundingClientRect();
|
||||||
}
|
}
|
||||||
|
|
||||||
const trim = function (string: string) {
|
const trim = function (string: string) {
|
||||||
return (string || '').replace(/^[\s\uFEFF]+|[\s\uFEFF]+$/g, '');
|
return (string || '').replace(/^[\s\uFEFF]+|[\s\uFEFF]+$/g, '');
|
||||||
};
|
};
|
||||||
|
|
||||||
/* istanbul ignore next */
|
/* istanbul ignore next */
|
||||||
export function hasClass(el: Element, cls: string) {
|
export function hasClass(el: Element, cls: string) {
|
||||||
if (!el || !cls) return false;
|
if (!el || !cls) return false;
|
||||||
@ -28,6 +30,7 @@ export function hasClass(el: Element, cls: string) {
|
|||||||
return (' ' + el.className + ' ').indexOf(' ' + cls + ' ') > -1;
|
return (' ' + el.className + ' ').indexOf(' ' + cls + ' ') > -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* istanbul ignore next */
|
/* istanbul ignore next */
|
||||||
export function addClass(el: Element, cls: string) {
|
export function addClass(el: Element, cls: string) {
|
||||||
if (!el) return;
|
if (!el) return;
|
||||||
@ -130,7 +133,7 @@ export function hackCss(attr: string, value: string) {
|
|||||||
|
|
||||||
/* istanbul ignore next */
|
/* istanbul ignore next */
|
||||||
export const on = function (
|
export const on = function (
|
||||||
element: HTMLElement | Document | Window,
|
element: Element | HTMLElement | Document | Window,
|
||||||
event: string,
|
event: string,
|
||||||
handler: EventListenerOrEventListenerObject
|
handler: EventListenerOrEventListenerObject
|
||||||
): void {
|
): void {
|
||||||
@ -141,7 +144,7 @@ export const on = function (
|
|||||||
|
|
||||||
/* istanbul ignore next */
|
/* istanbul ignore next */
|
||||||
export const off = function (
|
export const off = function (
|
||||||
element: HTMLElement | Document | Window,
|
element: Element | HTMLElement | Document | Window,
|
||||||
event: string,
|
event: string,
|
||||||
handler: Fn
|
handler: Fn
|
||||||
): void {
|
): void {
|
||||||
@ -149,3 +152,14 @@ export const off = function (
|
|||||||
element.removeEventListener(event, handler, false);
|
element.removeEventListener(event, handler, false);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/* istanbul ignore next */
|
||||||
|
export const once = function (el: HTMLElement, event: string, fn: EventListener): void {
|
||||||
|
const listener = function (this: any, ...args: unknown[]) {
|
||||||
|
if (fn) {
|
||||||
|
fn.apply(this, args);
|
||||||
|
}
|
||||||
|
off(el, event, listener);
|
||||||
|
};
|
||||||
|
on(el, event, listener);
|
||||||
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user