ny
昨天 282fbc6488f4e8ceb5fda759f963ee88fbf7b999
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
66
67
<script lang="ts" setup>
import { computed, unref } from 'vue';
 
import { useAttrs } from '@jnpf/hooks';
 
import { Button } from 'ant-design-vue';
 
import { buttonProps } from './props';
 
defineOptions({
  // @ts-ignore
  extends: Button,
  inheritAttrs: false,
  name: 'AButton',
});
 
const props: any = defineProps(buttonProps);
const attrs = useAttrs({ excludeDefaultKeys: false });
 
const getType = computed(() => {
  const { ghost, type } = props;
  if (!type) return 'default';
  if (['error', 'info', 'success', 'warning'].includes(type) && ghost) return 'default';
  return type;
});
const getButtonClass = computed(() => {
  const { color, disabled, ghost, type } = props;
  return [
    {
      [`ant-btn-${color}`]: !!color && type !== 'dashed' && !ghost,
      [`is-disabled`]: disabled,
    },
  ];
});
const getBindValue = computed(() => ({ ...unref(attrs), ...props, type: unref(getType) }));
</script>
<template>
  <Button v-bind="getBindValue" :class="getButtonClass" @click="onClick">
    <template v-if="$slots.icon || preIcon" #icon>
      <slot name="icon">
        <i :class="[preIcon]" class="button-preIcon"></i>
      </slot>
    </template>
    <template #default="data">
      <slot v-bind="data || {}"></slot>
      <i v-if="postIcon" :class="[postIcon]" class="button-postIcon"></i>
    </template>
  </Button>
</template>
<style lang="scss" scoped>
.ant-btn {
  .button-preIcon,
  .button-postIcon,
  i {
    font-size: 14px;
  }
 
  :deep(.button-preIcon + span),
  :deep(i + span) {
    margin-left: 5px;
  }
 
  .button-postIcon {
    margin-left: 5px;
  }
}
</style>