custom avatars

This commit is contained in:
m1k1o 2020-10-18 15:13:12 +02:00
parent 6e101b6ac0
commit aeb98e60cd
4 changed files with 47 additions and 10 deletions

View File

@ -1,7 +1,30 @@
<template>
<!--
<img :src="`https://ui-avatars.com/api/?name=${seed}&size=${size}`" />
-->
<div class="avatar" :style="{
width: size + 'px',
height: size + 'px',
lineHeight: size + 'px',
fontSize: (size/2) + 'px',
backgroundColor: Background(),
}">
{{ seed.substring(0, 2).toUpperCase() }}
</div>
</template>
<style lang="scss" scoped>
.avatar {
user-select: none;
text-align: center;
background: white;
color: black;
display: inline-block;
overflow: hidden;
border-radius: 50%;
}
</style>
<script lang="ts">
import { Vue, Component, Prop } from 'vue-property-decorator'
@ -11,5 +34,19 @@
export default class extends Vue {
@Prop(String) readonly seed: string | undefined;
@Prop(Number) readonly size: number | undefined;
Background() {
let a = 0, b = 0, c = 0;
for(let i = 0; i < this.seed.length; i++) {
a += this.seed.charCodeAt(i) * 3;
b += this.seed.charCodeAt(i) * 5;
c += this.seed.charCodeAt(i) * 7;
}
let x = Math.floor(128 + (a % 128));
let y = Math.floor(128 + (b % 128));
let z = Math.floor(128 + (c % 128));
return "rgb(" + x + "," + y + "," + z + ")";
}
}
</script>

View File

@ -4,7 +4,7 @@
<template v-for="(message, index) in history">
<li :key="index" class="message" v-if="message.type === 'text'">
<div class="author" @contextmenu.stop.prevent="onContext($event, { member: member(message.id) })">
<neko-avatar :seed="member(message.id).displayname" :size="40" />
<neko-avatar class="avatar" :seed="member(message.id).displayname" :size="40" />
</div>
<div class="content">
<div class="content-head">
@ -106,7 +106,7 @@
background: $style-primary;
margin: 0px 10px 10px 0px;
img {
.avatar {
width: 100%;
}
}

View File

@ -3,7 +3,7 @@
<template slot-scope="child" v-if="child.data">
<li class="header">
<div class="user">
<neko-avatar :seed="child.data.member.displayname" :size="25" />
<neko-avatar class="avatar" :seed="child.data.member.displayname" :size="25" />
<strong>{{ child.data.member.displayname }}</strong>
</div>
</li>
@ -80,7 +80,7 @@
align-content: center;
padding: 5px 0;
img {
.avatar {
width: 25px;
height: 25px;
border-radius: 50%;

View File

@ -4,7 +4,7 @@
<ul class="members-list">
<li v-if="member">
<div :class="[{ host: member.id === host }, 'self', 'member']">
<neko-avatar :seed="member.displayname" :size="50" />
<neko-avatar class="avatar" :seed="member.displayname" :size="50" />
</div>
</li>
<template v-for="(member, index) in members">
@ -17,7 +17,7 @@
:class="[{ host: member.id === host, admin: member.admin }, 'member']"
@contextmenu.stop.prevent="onContext($event, { member })"
>
<neko-avatar :seed="member.displayname" :size="50" />
<neko-avatar class="avatar" :seed="member.displayname" :size="50" />
</div>
</li>
</template>
@ -130,7 +130,7 @@
border-radius: 50%;
}
img {
.avatar {
border-radius: 50%;
overflow: hidden;
width: 100%;