|
1
2
|
<template>
<Button v-bind="getBindValue" :class="[getColor, $attrs.class]">
|
vben
authored
|
3
|
<template #default="data">
|
vben
authored
|
4
|
<Icon :icon="preIcon" :class="{ 'mr-1': !getIsCircleBtn }" v-if="preIcon" />
|
vben
authored
|
5
|
<slot v-bind="data" />
|
vben
authored
|
6
|
<Icon :icon="postIcon" :class="{ 'ml-1': !getIsCircleBtn }" v-if="postIcon" />
|
|
7
8
9
10
11
12
|
</template>
</Button>
</template>
<script lang="ts">
import { PropType } from 'vue';
|
vben
authored
|
13
|
import { defineComponent, computed } from 'vue';
|
|
14
15
|
import { Button } from 'ant-design-vue';
// import { extendSlots } from '/@/utils/helper/tsxHelper';
|
vben
authored
|
16
17
|
// import { useThrottle } from '/@/hooks/core/useThrottle';
// import { isFunction } from '/@/utils/is';
|
vben
authored
|
18
|
import Icon from '/@/components/Icon';
|
|
19
20
21
|
export default defineComponent({
name: 'AButton',
inheritAttrs: false,
|
vben
authored
|
22
|
components: { Button, Icon },
|
|
23
24
25
26
27
28
29
|
props: {
// 按钮类型
type: {
type: String as PropType<'primary' | 'default' | 'danger' | 'dashed' | 'link'>,
default: 'default',
},
// 节流防抖类型 throttle debounce
|
vben
authored
|
30
31
32
33
|
// throttle: {
// type: String as PropType<'throttle' | 'debounce'>,
// default: 'throttle',
// },
|
|
34
|
color: {
|
vben
authored
|
35
|
type: String as PropType<'error' | 'warning' | 'success' | ''>,
|
|
36
|
},
|
vben
authored
|
37
38
39
40
41
|
// // 防抖节流时间
// throttleTime: {
// type: Number as PropType<number>,
// default: 50,
// },
|
|
42
43
44
45
46
47
48
49
|
loading: {
type: Boolean as PropType<boolean>,
default: false,
},
disabled: {
type: Boolean as PropType<boolean>,
default: false,
},
|
vben
authored
|
50
51
52
53
54
55
|
preIcon: {
type: String as PropType<string>,
},
postIcon: {
type: String as PropType<string>,
},
|
|
56
57
|
},
setup(props, { attrs }) {
|
vben
authored
|
58
59
60
61
62
63
64
65
66
67
68
69
70
71
|
const getIsCircleBtn = computed(() => {
return attrs.shape === 'circle';
});
// 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,
// };
// }
|
|
72
|
|
vben
authored
|
73
74
75
|
// const on: {
// onClick?: Fn;
// } = {};
|
|
76
|
|
vben
authored
|
77
78
79
80
81
82
83
|
// if (attrs.onClick && isFunction(attrs.onClick) && openThrottle) {
// const [handler] = useThrottle(attrs.onClick as any, throttleTime!, {
// debounce: isDebounce,
// immediate: false,
// });
// on.onClick = handler;
// }
|
|
84
|
|
vben
authored
|
85
86
87
88
89
|
// return {
// ...attrs,
// ...on,
// };
// });
|
|
90
91
92
93
94
95
96
97
98
99
|
const getColor = computed(() => {
const res: string[] = [];
const { color, disabled } = props;
color && res.push(`ant-btn-${color}`);
disabled && res.push('is-disabled');
return res;
});
const getBindValue = computed((): any => {
|
vben
authored
|
100
|
return { ...attrs, ...props };
|
|
101
|
});
|
vben
authored
|
102
103
|
return { getBindValue, getColor, getIsCircleBtn };
|
|
104
105
106
|
},
});
</script>
|