Commit bdce84537aa58b9507744a3a14c8d598e88e95fc
1 parent
fb0c7763
perf(button): delete the button component useless code
Showing
6 changed files
with
95 additions
and
52 deletions
src/components/Button/index.vue
1 | 1 | <template> |
2 | 2 | <Button v-bind="getBindValue" :class="[getColor, $attrs.class]"> |
3 | - <!-- <template #[item]="data" v-for="item in Object.keys($slots)"> | |
4 | - <slot :name="item" v-bind="data" /> | |
5 | - </template> --> | |
6 | 3 | <template #default="data"> |
7 | - <Icon :icon="preIcon" class="mr-1" v-if="preIcon" /> | |
4 | + <Icon :icon="preIcon" :class="{ 'mr-1': !getIsCircleBtn }" v-if="preIcon" /> | |
8 | 5 | <slot v-bind="data" /> |
9 | - <Icon :icon="postIcon" class="ml-1" v-if="postIcon" /> | |
6 | + <Icon :icon="postIcon" :class="{ 'ml-1': !getIsCircleBtn }" v-if="postIcon" /> | |
10 | 7 | </template> |
11 | 8 | </Button> |
12 | 9 | </template> |
13 | 10 | <script lang="ts"> |
14 | 11 | import { PropType } from 'vue'; |
15 | 12 | |
16 | - import { defineComponent, computed, unref } from 'vue'; | |
13 | + import { defineComponent, computed } from 'vue'; | |
17 | 14 | import { Button } from 'ant-design-vue'; |
18 | 15 | // import { extendSlots } from '/@/utils/helper/tsxHelper'; |
19 | - import { useThrottle } from '/@/hooks/core/useThrottle'; | |
20 | - import { isFunction } from '/@/utils/is'; | |
16 | + // import { useThrottle } from '/@/hooks/core/useThrottle'; | |
17 | + // import { isFunction } from '/@/utils/is'; | |
21 | 18 | import Icon from '/@/components/Icon'; |
22 | 19 | export default defineComponent({ |
23 | 20 | name: 'AButton', |
... | ... | @@ -30,18 +27,18 @@ |
30 | 27 | default: 'default', |
31 | 28 | }, |
32 | 29 | // 节流防抖类型 throttle debounce |
33 | - throttle: { | |
34 | - type: String as PropType<'throttle' | 'debounce'>, | |
35 | - default: 'throttle', | |
36 | - }, | |
30 | + // throttle: { | |
31 | + // type: String as PropType<'throttle' | 'debounce'>, | |
32 | + // default: 'throttle', | |
33 | + // }, | |
37 | 34 | color: { |
38 | 35 | type: String as PropType<'error' | 'warning' | 'success' | ''>, |
39 | 36 | }, |
40 | - // 防抖节流时间 | |
41 | - throttleTime: { | |
42 | - type: Number as PropType<number>, | |
43 | - default: 0, | |
44 | - }, | |
37 | + // // 防抖节流时间 | |
38 | + // throttleTime: { | |
39 | + // type: Number as PropType<number>, | |
40 | + // default: 50, | |
41 | + // }, | |
45 | 42 | loading: { |
46 | 43 | type: Boolean as PropType<boolean>, |
47 | 44 | default: false, |
... | ... | @@ -58,30 +55,38 @@ |
58 | 55 | }, |
59 | 56 | }, |
60 | 57 | setup(props, { attrs }) { |
61 | - const getListeners = computed(() => { | |
62 | - const { throttle, throttleTime = 0 } = props; | |
63 | - // 是否开启节流防抖 | |
64 | - const throttleType = throttle!.toLowerCase(); | |
65 | - const isDebounce = throttleType === 'debounce'; | |
66 | - const openThrottle = ['throttle', 'debounce'].includes(throttleType) && throttleTime > 0; | |
58 | + const getIsCircleBtn = computed(() => { | |
59 | + return attrs.shape === 'circle'; | |
60 | + }); | |
61 | + // const getListeners = computed(() => { | |
62 | + // const { throttle, throttleTime = 0 } = props; | |
63 | + // // 是否开启节流防抖 | |
64 | + // const throttleType = throttle!.toLowerCase(); | |
65 | + // const isDebounce = throttleType === 'debounce'; | |
66 | + // const openThrottle = ['throttle', 'debounce'].includes(throttleType) && throttleTime > 0; | |
67 | + // if (!openThrottle) { | |
68 | + // return { | |
69 | + // ...attrs, | |
70 | + // }; | |
71 | + // } | |
67 | 72 | |
68 | - const on: { | |
69 | - onClick?: Fn; | |
70 | - } = {}; | |
73 | + // const on: { | |
74 | + // onClick?: Fn; | |
75 | + // } = {}; | |
71 | 76 | |
72 | - if (attrs.onClick && isFunction(attrs.onClick) && openThrottle) { | |
73 | - const [handler] = useThrottle(attrs.onClick as any, throttleTime!, { | |
74 | - debounce: isDebounce, | |
75 | - immediate: true, | |
76 | - }); | |
77 | - on.onClick = handler; | |
78 | - } | |
77 | + // if (attrs.onClick && isFunction(attrs.onClick) && openThrottle) { | |
78 | + // const [handler] = useThrottle(attrs.onClick as any, throttleTime!, { | |
79 | + // debounce: isDebounce, | |
80 | + // immediate: false, | |
81 | + // }); | |
82 | + // on.onClick = handler; | |
83 | + // } | |
79 | 84 | |
80 | - return { | |
81 | - ...attrs, | |
82 | - ...on, | |
83 | - }; | |
84 | - }); | |
85 | + // return { | |
86 | + // ...attrs, | |
87 | + // ...on, | |
88 | + // }; | |
89 | + // }); | |
85 | 90 | |
86 | 91 | const getColor = computed(() => { |
87 | 92 | const res: string[] = []; |
... | ... | @@ -92,9 +97,10 @@ |
92 | 97 | }); |
93 | 98 | |
94 | 99 | const getBindValue = computed((): any => { |
95 | - return { ...unref(getListeners), ...props }; | |
100 | + return { ...attrs, ...props }; | |
96 | 101 | }); |
97 | - return { getBindValue, getColor }; | |
102 | + | |
103 | + return { getBindValue, getColor, getIsCircleBtn }; | |
98 | 104 | }, |
99 | 105 | }); |
100 | 106 | </script> | ... | ... |
src/components/ClickOutSide/index.vue
src/components/Scrollbar/src/Bar.tsx
... | ... | @@ -17,7 +17,7 @@ export default defineComponent({ |
17 | 17 | setup(props) { |
18 | 18 | const thumbRef = ref<Nullable<HTMLDivElement>>(null); |
19 | 19 | const elRef = ref<Nullable<HTMLDivElement>>(null); |
20 | - const commonState = reactive<KeyString>({}); | |
20 | + const commonState = reactive<Indexable>({}); | |
21 | 21 | const getBarRef = computed(() => { |
22 | 22 | return BAR_MAP[props.vertical ? 'vertical' : 'horizontal']; |
23 | 23 | }); | ... | ... |
src/setup/directives/repeatClick.ts
0 → 100644
1 | +import { on, once } from '/@/utils/domUtils'; | |
2 | + | |
3 | +export default { | |
4 | + beforeMount(el: Element, binding: any) { | |
5 | + let interval: ReturnType<typeof setInterval> | null = null; | |
6 | + let startTime = 0; | |
7 | + const handler = () => binding.value && binding.value(); | |
8 | + const clear = () => { | |
9 | + if (Date.now() - startTime < 100) { | |
10 | + handler(); | |
11 | + } | |
12 | + interval && clearInterval(interval); | |
13 | + interval = null; | |
14 | + }; | |
15 | + | |
16 | + on(el, 'mousedown', (e) => { | |
17 | + if ((e as any).button !== 0) return; | |
18 | + startTime = Date.now(); | |
19 | + once(document as any, 'mouseup', clear); | |
20 | + interval && clearInterval(interval); | |
21 | + interval = setInterval(handler, 100); | |
22 | + }); | |
23 | + }, | |
24 | +}; | ... | ... |
src/types/global.d.ts
... | ... | @@ -23,15 +23,12 @@ declare type RefType<T> = T | null; |
23 | 23 | |
24 | 24 | declare type CustomizedHTMLElement<T> = HTMLElement & T; |
25 | 25 | |
26 | -declare type Indexable<T> = { | |
26 | +declare type Indexable<T = any> = { | |
27 | 27 | [key: string]: T; |
28 | 28 | }; |
29 | +declare type Hash<T> = Indexable<T>; | |
29 | 30 | |
30 | -declare type KeyString<T = any> = { | |
31 | - [key: string]: T; | |
32 | -}; | |
33 | - | |
34 | -type DeepPartial<T> = { | |
31 | +declare type DeepPartial<T> = { | |
35 | 32 | [P in keyof T]?: T[P] extends (infer U)[] |
36 | 33 | ? RecursivePartial<U>[] |
37 | 34 | : T[P] extends object |
... | ... | @@ -39,11 +36,11 @@ type DeepPartial<T> = { |
39 | 36 | : T[P]; |
40 | 37 | }; |
41 | 38 | |
42 | -type SelectOptions = { | |
39 | +declare type SelectOptions = { | |
43 | 40 | label: string; |
44 | 41 | value: any; |
45 | 42 | }[]; |
46 | 43 | |
47 | -type EmitType = (event: string, ...args: any[]) => void; | |
44 | +declare type EmitType = (event: string, ...args: any[]) => void; | |
48 | 45 | |
49 | -type TargetContext = '_self' | '_blank'; | |
46 | +declare type TargetContext = '_self' | '_blank'; | ... | ... |
src/utils/domUtils.ts
... | ... | @@ -15,9 +15,11 @@ export function getBoundingClientRect(element: Element): DOMRect | number { |
15 | 15 | } |
16 | 16 | return element.getBoundingClientRect(); |
17 | 17 | } |
18 | + | |
18 | 19 | const trim = function (string: string) { |
19 | 20 | return (string || '').replace(/^[\s\uFEFF]+|[\s\uFEFF]+$/g, ''); |
20 | 21 | }; |
22 | + | |
21 | 23 | /* istanbul ignore next */ |
22 | 24 | export function hasClass(el: Element, cls: string) { |
23 | 25 | if (!el || !cls) return false; |
... | ... | @@ -28,6 +30,7 @@ export function hasClass(el: Element, cls: string) { |
28 | 30 | return (' ' + el.className + ' ').indexOf(' ' + cls + ' ') > -1; |
29 | 31 | } |
30 | 32 | } |
33 | + | |
31 | 34 | /* istanbul ignore next */ |
32 | 35 | export function addClass(el: Element, cls: string) { |
33 | 36 | if (!el) return; |
... | ... | @@ -130,7 +133,7 @@ export function hackCss(attr: string, value: string) { |
130 | 133 | |
131 | 134 | /* istanbul ignore next */ |
132 | 135 | export const on = function ( |
133 | - element: HTMLElement | Document | Window, | |
136 | + element: Element | HTMLElement | Document | Window, | |
134 | 137 | event: string, |
135 | 138 | handler: EventListenerOrEventListenerObject |
136 | 139 | ): void { |
... | ... | @@ -141,7 +144,7 @@ export const on = function ( |
141 | 144 | |
142 | 145 | /* istanbul ignore next */ |
143 | 146 | export const off = function ( |
144 | - element: HTMLElement | Document | Window, | |
147 | + element: Element | HTMLElement | Document | Window, | |
145 | 148 | event: string, |
146 | 149 | handler: Fn |
147 | 150 | ): void { |
... | ... | @@ -149,3 +152,14 @@ export const off = function ( |
149 | 152 | element.removeEventListener(event, handler, false); |
150 | 153 | } |
151 | 154 | }; |
155 | + | |
156 | +/* istanbul ignore next */ | |
157 | +export const once = function (el: HTMLElement, event: string, fn: EventListener): void { | |
158 | + const listener = function (this: any, ...args: unknown[]) { | |
159 | + if (fn) { | |
160 | + fn.apply(this, args); | |
161 | + } | |
162 | + off(el, event, listener); | |
163 | + }; | |
164 | + on(el, event, listener); | |
165 | +}; | ... | ... |