Commit c701cc92c31c2eef7e6b77b4c7497ced7e58b990
1 parent
83592ad0
perf: add xtextbutton
Showing
1 changed file
with
46 additions
and
0 deletions
yudao-ui-admin-vue3/src/components/XButton/src/XTextButton.vue
0 → 100644
| 1 | +<script setup lang="ts"> | ||
| 2 | +import { propTypes } from '@/utils/propTypes' | ||
| 3 | +import { computed, useAttrs, PropType } from 'vue' | ||
| 4 | + | ||
| 5 | +const props = defineProps({ | ||
| 6 | + modelValue: propTypes.bool.def(false), | ||
| 7 | + loading: propTypes.bool.def(false), | ||
| 8 | + preIcon: propTypes.string.def(''), | ||
| 9 | + postIcon: propTypes.string.def(''), | ||
| 10 | + title: propTypes.string.def(''), | ||
| 11 | + type: propTypes.oneOf(['', 'primary', 'success', 'warning', 'danger', 'info']).def('primary'), | ||
| 12 | + circle: propTypes.bool.def(false), | ||
| 13 | + round: propTypes.bool.def(false), | ||
| 14 | + plain: propTypes.bool.def(false), | ||
| 15 | + onClick: { type: Function as PropType<(...args) => any>, default: null } | ||
| 16 | +}) | ||
| 17 | +const getBindValue = computed(() => { | ||
| 18 | + const delArr: string[] = ['title', 'preIcon', 'postIcon', 'onClick'] | ||
| 19 | + const attrs = useAttrs() | ||
| 20 | + const obj = { ...attrs, ...props } | ||
| 21 | + for (const key in obj) { | ||
| 22 | + if (delArr.indexOf(key) !== -1) { | ||
| 23 | + delete obj[key] | ||
| 24 | + } | ||
| 25 | + } | ||
| 26 | + return obj | ||
| 27 | +}) | ||
| 28 | +</script> | ||
| 29 | + | ||
| 30 | +<template> | ||
| 31 | + <el-button link v-bind="getBindValue" @click="onClick"> | ||
| 32 | + <Icon :icon="preIcon" v-if="preIcon" class="mr-1px" /> | ||
| 33 | + {{ title ? title : '' }} | ||
| 34 | + <Icon :icon="postIcon" v-if="postIcon" class="mr-1px" /> | ||
| 35 | + </el-button> | ||
| 36 | +</template> | ||
| 37 | +<style lang="less" scoped> | ||
| 38 | +:deep(.el-button.is-text) { | ||
| 39 | + margin-left: 0; | ||
| 40 | + padding: 8px 4px; | ||
| 41 | +} | ||
| 42 | +:deep(.el-button.is-link) { | ||
| 43 | + margin-left: 0; | ||
| 44 | + padding: 8px 4px; | ||
| 45 | +} | ||
| 46 | +</style> |