201 lines
3.9 KiB
Vue
201 lines
3.9 KiB
Vue
<template>
|
|
<button
|
|
:class="['gradient-button', { 'gradient-button--disabled': disabled, 'gradient-button--loading': loading }]"
|
|
:disabled="disabled || loading"
|
|
@click="handleClick"
|
|
>
|
|
<span v-if="loading" class="gradient-button__loading">
|
|
<a-spin size="small" />
|
|
<span v-if="loadingText" class="gradient-button__loading-text">{{ loadingText }}</span>
|
|
</span>
|
|
<span v-else class="gradient-button__content">
|
|
<slot name="icon">
|
|
<span v-if="icon" class="gradient-button__icon">
|
|
<GmIcon :name="icon" :size="iconSize" />
|
|
</span>
|
|
</slot>
|
|
<span class="gradient-button__text">
|
|
<slot>{{ text }}</slot>
|
|
</span>
|
|
</span>
|
|
</button>
|
|
</template>
|
|
|
|
<script setup>
|
|
import { computed } from 'vue'
|
|
import GmIcon from '@/components/icons/Icon.vue'
|
|
|
|
const props = defineProps({
|
|
// 按钮文本
|
|
text: {
|
|
type: String,
|
|
default: ''
|
|
},
|
|
// 是否禁用
|
|
disabled: {
|
|
type: Boolean,
|
|
default: false
|
|
},
|
|
// 是否加载中
|
|
loading: {
|
|
type: Boolean,
|
|
default: false
|
|
},
|
|
// 加载中的文本
|
|
loadingText: {
|
|
type: String,
|
|
default: ''
|
|
},
|
|
// 图标名称
|
|
icon: {
|
|
type: String,
|
|
default: ''
|
|
},
|
|
// 图标大小
|
|
iconSize: {
|
|
type: Number,
|
|
default: 16
|
|
},
|
|
// 按钮大小
|
|
size: {
|
|
type: String,
|
|
default: 'large', // large, middle, small
|
|
validator: (value) => ['large', 'middle', 'small'].includes(value)
|
|
},
|
|
// 是否块级按钮
|
|
block: {
|
|
type: Boolean,
|
|
default: false
|
|
}
|
|
})
|
|
|
|
const emit = defineEmits(['click'])
|
|
|
|
const handleClick = (event) => {
|
|
if (!props.disabled && !props.loading) {
|
|
emit('click', event)
|
|
}
|
|
}
|
|
|
|
const buttonClass = computed(() => {
|
|
return [
|
|
`gradient-button--${props.size}`,
|
|
{
|
|
'gradient-button--block': props.block
|
|
}
|
|
]
|
|
})
|
|
</script>
|
|
|
|
<style scoped>
|
|
.gradient-button {
|
|
position: relative;
|
|
display: inline-flex;
|
|
align-items: center;
|
|
justify-content: center;
|
|
gap: var(--space-2);
|
|
padding: var(--space-2) var(--space-6);
|
|
border: none;
|
|
border-radius: var(--radius-lg);
|
|
font-size: var(--font-size-base);
|
|
font-weight: 500;
|
|
color: #ffffff;
|
|
cursor: pointer;
|
|
transition: all var(--duration-fast);
|
|
background: var(--color-gray-900);
|
|
user-select: none;
|
|
}
|
|
|
|
.gradient-button:hover {
|
|
background: var(--color-gray-800);
|
|
}
|
|
|
|
.gradient-button:active {
|
|
background: var(--color-gray-800);
|
|
transform: translateY(0);
|
|
box-shadow: var(--shadow-primary);
|
|
}
|
|
|
|
.gradient-button__content,
|
|
.gradient-button__loading {
|
|
position: relative;
|
|
z-index: 1;
|
|
display: inline-flex;
|
|
align-items: center;
|
|
justify-content: center;
|
|
gap: var(--space-1);
|
|
}
|
|
|
|
.gradient-button__icon {
|
|
display: inline-flex;
|
|
align-items: center;
|
|
}
|
|
|
|
.gradient-button__text {
|
|
line-height: 1;
|
|
}
|
|
|
|
.gradient-button__loading-text {
|
|
margin-left: var(--space-1);
|
|
}
|
|
|
|
/* 尺寸变体 */
|
|
.gradient-button--large {
|
|
padding: 10px 20px;
|
|
font-size: var(--font-size-sm);
|
|
min-height: 36px;
|
|
}
|
|
|
|
.gradient-button--middle {
|
|
padding: var(--space-2) var(--space-4);
|
|
font-size: var(--font-size-sm);
|
|
min-height: 32px;
|
|
}
|
|
|
|
.gradient-button--small {
|
|
padding: var(--space-1) var(--space-3);
|
|
font-size: var(--font-size-xs);
|
|
min-height: 24px;
|
|
}
|
|
|
|
/* 块级按钮 */
|
|
.gradient-button--block {
|
|
width: 100%;
|
|
display: flex;
|
|
}
|
|
|
|
/* 禁用状态 */
|
|
.gradient-button--disabled,
|
|
.gradient-button:disabled {
|
|
opacity: 0.4;
|
|
cursor: not-allowed;
|
|
background: var(--color-gray-700);
|
|
box-shadow: none;
|
|
}
|
|
|
|
.gradient-button--disabled:hover,
|
|
.gradient-button:disabled:hover {
|
|
background: var(--color-gray-700);
|
|
transform: none;
|
|
box-shadow: none;
|
|
}
|
|
|
|
/* 加载状态 */
|
|
.gradient-button--loading {
|
|
cursor: wait;
|
|
}
|
|
|
|
.gradient-button--loading:hover {
|
|
transform: none;
|
|
}
|
|
|
|
/* 响应式调整 */
|
|
@media (max-width: 768px) {
|
|
.gradient-button--large {
|
|
padding: var(--space-2) var(--space-4);
|
|
font-size: var(--font-size-sm);
|
|
min-height: 32px;
|
|
}
|
|
}
|
|
</style>
|