干燥机配套车间生产管理系统/云平台服务端
baoshiwei
2023-05-24 beca65f4d01ca07c358102a35b949c2a4f277afe
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
<template>
    <Button v-bind="getBindValue" :class="getButtonClass" @click="onClick">
        <template v-if="preIcon" #icon>
            <Icon :icon="preIcon" :size="iconSize" />
        </template>
        <template #default="data">
            <slot v-bind="data || {}"></slot>
            <Icon :icon="postIcon" v-if="postIcon" :size="iconSize" />
        </template>
    </Button>
</template>
 
<script lang="ts">
    import { defineComponent } from 'vue'
    export default defineComponent({
        name: 'AButton',
        inheritAttrs: false,
    })
</script>
<script lang="ts" setup>
    import { computed, unref } from 'vue'
    import { Button } from 'ant-design-vue'
    import Icon from '/@/components/Icon/src/Icon.vue'
    import { buttonProps } from './props'
    import { useAttrs } from '/@/hooks/core/useAttrs'
    const props = defineProps(buttonProps)
    // get component class
    const attrs = useAttrs({ excludeDefaultKeys: false })
    const getButtonClass = computed(() => {
        const { color, disabled } = props
        return [
            {
                [`ant-btn-${color}`]: !!color,
                [`is-disabled`]: disabled,
            },
        ]
    })
 
    // get inherit binding value
    const getBindValue = computed(() => ({ ...unref(attrs), ...props }))
</script>