Files
shoot-miniprograms/src/components/Avatar.vue

124 lines
2.3 KiB
Vue
Raw Normal View History

2025-05-27 12:38:39 +08:00
<script setup>
2025-07-07 19:01:14 +08:00
import { ref, onMounted, watch } from "vue";
import useStore from "@/store";
import { storeToRefs } from "pinia";
const store = useStore();
const { getLvlImage } = store;
const { config } = storeToRefs(store);
const props = defineProps({
2025-05-27 12:38:39 +08:00
src: {
type: String,
default: "",
},
2025-07-14 15:13:10 +08:00
rankLvl: {
2025-07-07 19:01:14 +08:00
type: Number,
default: undefined,
2025-07-07 01:12:49 +08:00
},
2025-05-27 12:38:39 +08:00
onClick: {
type: Function,
default: () => {},
},
rank: {
type: Number,
default: 0,
},
2025-05-28 15:00:31 +08:00
size: {
type: Number,
default: 45,
},
2025-06-08 12:52:49 +08:00
borderColor: {
2025-06-25 00:09:53 +08:00
type: String,
default: "",
2025-06-08 12:52:49 +08:00
},
2025-05-27 12:38:39 +08:00
});
2025-07-07 19:01:14 +08:00
const avatarFrame = ref("");
watch(
2025-07-14 15:13:10 +08:00
() => [config.value, props.rankLvl],
2025-07-07 19:01:14 +08:00
() => {
2025-07-14 15:13:10 +08:00
if (props.rankLvl !== undefined) {
avatarFrame.value = getLvlImage(props.rankLvl);
2025-07-07 19:01:14 +08:00
}
},
{
immediate: true,
}
);
2025-05-27 12:38:39 +08:00
</script>
<template>
<view class="avatar" @click="onClick">
<image
2025-07-07 19:01:14 +08:00
v-if="avatarFrame"
:src="avatarFrame"
2025-05-27 12:38:39 +08:00
mode="widthFix"
2025-06-08 12:52:49 +08:00
:style="{
width: Number(size) + 10 + 'px',
height: Number(size) + 10 + 'px',
}"
2025-05-27 12:38:39 +08:00
class="avatar-frame"
/>
<image
v-if="rank === 1"
src="../static/champ1.png"
mode="widthFix"
class="avatar-rank"
/>
<image
v-if="rank === 2"
src="../static/champ2.png"
mode="widthFix"
class="avatar-rank"
/>
<image
v-if="rank === 3"
src="../static/champ3.png"
mode="widthFix"
class="avatar-rank"
/>
<view v-if="rank > 3" class="rank-view">{{ rank }}</view>
2025-05-28 15:00:31 +08:00
<image
2025-07-11 00:47:34 +08:00
:src="src || '../static/user-icon.png'"
2025-05-28 15:00:31 +08:00
mode="widthFix"
2025-06-08 12:52:49 +08:00
:style="{
width: size + 'px',
height: size + 'px',
2025-06-17 21:34:41 +08:00
minHeight: size + 'px',
2025-06-25 00:09:53 +08:00
borderColor: borderColor || '#fff',
2025-06-08 12:52:49 +08:00
}"
class="avatar-image"
2025-05-28 15:00:31 +08:00
/>
2025-05-27 12:38:39 +08:00
</view>
</template>
<style scoped>
.avatar {
position: relative;
display: flex;
align-items: center;
justify-content: center;
}
.avatar-frame {
position: absolute;
}
.avatar-rank,
.rank-view {
position: absolute;
width: 20px;
height: 15px;
top: -6px;
right: -4px;
}
.rank-view {
background-color: #6d6d6d;
text-align: center;
line-height: 15px;
font-size: 12px;
border-top-left-radius: 50%;
border-bottom-right-radius: 50%;
}
2025-06-08 12:52:49 +08:00
.avatar-image {
2025-05-27 12:38:39 +08:00
border-radius: 50%;
border: 1px solid #fff;
}
</style>