Files
simple-memo-wx/components/TitleBadge.vue
T

77 lines
1.4 KiB
Vue

<template>
<view class="title-badge" :style="{ background: badgeGradient }">
<text class="badge-icon">{{ icon }}</text>
<text class="badge-title">{{ title }}</text>
<text class="badge-level">Lv.{{ level }}</text>
</view>
</template>
<script>
import themeMixin from '../mixins/themeMixin.js'
import { THEME_CHANGE_EVENT } from '../utils/theme.js'
export default {
name: 'TitleBadge',
mixins: [themeMixin],
props: {
level: {
type: Number,
default: 1
},
title: {
type: String,
default: ''
},
icon: {
type: String,
default: ''
}
},
created() {
this.syncThemeConfig()
this.watchThemeChange()
},
beforeUnmount() {
if (this.themeChangeHandler) {
uni.$off(THEME_CHANGE_EVENT, this.themeChangeHandler)
}
},
computed: {
badgeGradient() {
const theme = this.themeConfig
return `linear-gradient(135deg, ${theme.primaryColor}, ${theme.secondaryColor})`
}
}
}
</script>
<style scoped>
.title-badge {
display: inline-flex;
align-items: center;
padding: 8rpx 24rpx;
border-radius: 12rpx;
box-shadow: 0 4rpx 16rpx rgba(0, 0, 0, 0.15);
gap: 12rpx;
}
.badge-icon {
font-size: 32rpx;
line-height: 1;
}
.badge-title {
font-size: 26rpx;
font-weight: 600;
color: #ffffff;
}
.badge-level {
font-size: 22rpx;
color: rgba(255, 255, 255, 0.9);
background: rgba(255, 255, 255, 0.25);
padding: 2rpx 10rpx;
border-radius: 20rpx;
}
</style>