topfans/frontend/components/ConfirmModal.vue
2026-05-17 19:03:34 +08:00

256 lines
4.9 KiB
Vue

<template>
<view v-show="visible" class="modal-overlay" :class="{ 'modal-visible': visible }" @tap="handleCancel">
<view class="modal-box" @tap.stop>
<!-- 标题 -->
<view v-if="title" class="modal-title">
<text>{{ title }}</text>
</view>
<view v-else class="modal-title">
<text class="modal-title-text">铸造确认</text>
</view>
<!-- 铸造费用信息 -->
<view v-if="costCrystal > 0 || currentBalance > 0" class="cost-info">
<view class="cost-row">
<text class="cost-label">本次消耗</text>
<text class="cost-value cost-crystal">{{ costCrystal }} 水晶</text>
</view>
<view class="cost-row">
<text class="cost-label">当前余额</text>
<text class="cost-value">{{ currentBalance }} 水晶</text>
</view>
<view class="cost-row">
<text class="cost-label">铸造后余额</text>
<text class="cost-value balance-after">{{ balanceAfter }} 水晶</text>
</view>
<view v-if="mintCount > 0" class="cost-row">
<text class="cost-label">铸造次数</text>
<text class="cost-value">第 {{ mintCount }} 次</text>
</view>
<view v-if="nextTierHint" class="next-tier-hint">
<text>{{ nextTierHint }}</text>
</view>
</view>
<!-- 内容 -->
<view v-else-if="content" class="modal-body">
<text class="modal-content">{{ content }}</text>
</view>
<!-- 按钮区 -->
<view class="modal-actions">
<view v-if="showCancel" class="btn btn-cancel" @tap="handleCancel">
<text>{{ cancelText }}</text>
</view>
<view class="btn btn-confirm" @tap="handleConfirm">
<text>{{ confirmText }}</text>
</view>
</view>
</view>
</view>
</template>
<script>
export default {
inheritAttrs: false,
};
</script>
<script setup>
const props = defineProps({
visible: {
type: Boolean,
default: false
},
title: {
type: String,
default: ''
},
content: {
type: String,
default: ''
},
confirmText: {
type: String,
default: '确认'
},
cancelText: {
type: String,
default: '取消'
},
showCancel: {
type: Boolean,
default: true
},
// 铸造费用信息
costCrystal: {
type: Number,
default: 0
},
currentBalance: {
type: Number,
default: 0
},
balanceAfter: {
type: Number,
default: 0
},
mintCount: {
type: Number,
default: 0
},
nextTierHint: {
type: String,
default: ''
}
})
const emit = defineEmits(['confirm', 'cancel'])
function handleConfirm() {
emit('confirm', { confirm: true })
}
function handleCancel() {
emit('cancel', { confirm: false })
}
</script>
<style scoped>
.modal-overlay {
position: fixed;
top: 0; left: 0; right: 0; bottom: 0;
background: rgba(0, 0, 0, 0.5);
z-index: 999;
display: flex;
align-items: center;
justify-content: center;
opacity: 0;
transition: opacity 0.25s ease;
pointer-events: none;
}
.modal-overlay.modal-visible {
opacity: 1;
pointer-events: auto;
}
.modal-box {
width: 560rpx;
/* background: #fff; */
background-image: url('/static/starbookcontent/beijing.png');
background-size: cover;
background-position: center bottom;
border-radius: 24rpx;
overflow: visible;
padding: 48rpx 40rpx 32rpx;
display: flex;
flex-direction: column;
align-items: center;
}
.modal-title {
font-size: 34rpx;
font-weight: bold;
color: #fff;
margin-bottom: 32rpx;
}
.cost-info {
width: 100%;
margin-bottom: 32rpx;
}
.cost-row {
display: flex;
justify-content: space-between;
align-items: center;
padding: 12rpx 0;
/* border-bottom: 1rpx solid rgba(0, 0, 0, 0.05); */
}
.cost-row:last-child {
border-bottom: none;
}
.cost-label {
font-size: 28rpx;
color: #fff;
text-shadow: 0 2px 8px rgba(0, 0, 0, 0.7);
}
.cost-value {
font-size: 28rpx;
color: #fff;
font-weight: 500;
text-shadow: 0 2px 8px rgba(0, 0, 0, 0.7);
}
.cost-crystal {
color: #fff;
font-weight: bold;
text-shadow: 0 2px 8px rgba(0, 0, 0, 0.7);
}
.balance-after {
color: #fff;
}
.next-tier-hint {
margin-top: 16rpx;
padding: 12rpx 16rpx;
background: rgba(255, 107, 157, 0.1);
border-radius: 12rpx;
text-align: center;
}
.next-tier-hint text {
font-size: 24rpx;
color: #FF6B9D;
}
.modal-body {
display: flex;
flex-direction: column;
align-items: center;
gap: 12rpx;
margin-bottom: 40rpx;
}
.modal-content {
font-size: 28rpx;
color: #555;
text-align: center;
white-space: pre-line;
}
.modal-actions {
width: 100%;
display: flex;
gap: 24rpx;
}
.btn {
flex: 1;
height: 80rpx;
border-radius: 40rpx;
display: flex;
align-items: center;
justify-content: center;
font-size: 30rpx;
}
.btn-cancel {
background: #f0f0f0;
color: #666;
}
.btn-confirm {
background: linear-gradient(to right, #F08399, #B94E73);
color: #fff;
}
</style>