index.vue
1.73 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
<template>
<Button v-bind="getBindValue" :class="[getColor, $attrs.class]">
<template #default="data">
<Icon :icon="preIcon" :class="{ 'mr-1': !getIsCircleBtn }" v-if="preIcon" />
<slot v-bind="data" />
<Icon :icon="postIcon" :class="{ 'ml-1': !getIsCircleBtn }" v-if="postIcon" />
</template>
</Button>
</template>
<script lang="ts">
import { PropType } from 'vue';
import { defineComponent, computed } from 'vue';
import { Button } from 'ant-design-vue';
import Icon from '/@/components/Icon';
export default defineComponent({
name: 'AButton',
inheritAttrs: false,
components: { Button, Icon },
props: {
type: {
type: String as PropType<'primary' | 'default' | 'danger' | 'dashed' | 'link'>,
default: 'default',
},
color: {
type: String as PropType<'error' | 'warning' | 'success' | ''>,
},
loading: {
type: Boolean as PropType<boolean>,
default: false,
},
disabled: {
type: Boolean as PropType<boolean>,
default: false,
},
preIcon: {
type: String as PropType<string>,
},
postIcon: {
type: String as PropType<string>,
},
},
setup(props, { attrs }) {
const getIsCircleBtn = computed(() => {
return attrs.shape === 'circle';
});
const getColor = computed(() => {
const { color, disabled } = props;
return [
{
[`ant-btn-${color}`]: !!color,
[`is-disabled`]: disabled,
},
];
});
const getBindValue = computed((): any => {
return { ...attrs, ...props };
});
return { getBindValue, getColor, getIsCircleBtn };
},
});
</script>