提交 | 用户 | 时间
|
314507
|
1 |
<script lang="ts" setup> |
H |
2 |
import { PropType } from 'vue' |
|
3 |
import { propTypes } from '@/utils/propTypes' |
|
4 |
|
|
5 |
defineOptions({ name: 'XButton' }) |
|
6 |
|
|
7 |
const props = defineProps({ |
|
8 |
modelValue: propTypes.bool.def(false), |
|
9 |
loading: propTypes.bool.def(false), |
|
10 |
preIcon: propTypes.string.def(''), |
|
11 |
postIcon: propTypes.string.def(''), |
|
12 |
title: propTypes.string.def(''), |
|
13 |
type: propTypes.oneOf(['', 'primary', 'success', 'warning', 'danger', 'info']).def(''), |
|
14 |
link: propTypes.bool.def(false), |
|
15 |
circle: propTypes.bool.def(false), |
|
16 |
round: propTypes.bool.def(false), |
|
17 |
plain: propTypes.bool.def(false), |
|
18 |
onClick: { type: Function as PropType<(...args) => any>, default: null } |
|
19 |
}) |
|
20 |
const getBindValue = computed(() => { |
|
21 |
const delArr: string[] = ['title', 'preIcon', 'postIcon', 'onClick'] |
|
22 |
const attrs = useAttrs() |
|
23 |
const obj = { ...attrs, ...props } |
|
24 |
for (const key in obj) { |
|
25 |
if (delArr.indexOf(key) !== -1) { |
|
26 |
delete obj[key] |
|
27 |
} |
|
28 |
} |
|
29 |
return obj |
|
30 |
}) |
|
31 |
</script> |
|
32 |
|
|
33 |
<template> |
|
34 |
<el-button v-bind="getBindValue" @click="onClick"> |
|
35 |
<Icon v-if="preIcon" :icon="preIcon" class="mr-1px" /> |
|
36 |
{{ title ? title : '' }} |
|
37 |
<Icon v-if="postIcon" :icon="postIcon" class="mr-1px" /> |
|
38 |
</el-button> |
|
39 |
</template> |
|
40 |
<style lang="scss" scoped> |
|
41 |
:deep(.el-button.is-text) { |
|
42 |
padding: 8px 4px; |
|
43 |
margin-left: 0; |
|
44 |
} |
|
45 |
|
|
46 |
:deep(.el-button.is-link) { |
|
47 |
padding: 8px 4px; |
|
48 |
margin-left: 0; |
|
49 |
} |
|
50 |
</style> |