Files
im/components/MyAvatar/index.vue
T

92 lines
1.8 KiB
Vue
Raw Normal View History

2025-11-07 09:56:20 +08:00
<template>
2025-12-27 07:08:30 +08:00
<u-avatar @longpress="longpress" @click="click" @onError="errorHandle" :src="cachesrc" :text="avatarText"
2026-01-12 18:07:21 +08:00
bg-color="#cdcdcd" :defaultUrl="getDefaultUrl" :shape="shape" :size="size" mode="aspectFill" font-size="14">
2025-11-27 07:48:42 +08:00
</u-avatar>
2025-11-07 09:56:20 +08:00
</template>
<script>
2025-12-08 18:10:51 +08:00
import defaultGroupIcon from "@/static/images/contact_my_group.png";
2025-12-27 07:08:30 +08:00
import defaultUserIcon from "@/static/images/user/avatar.png";
2025-12-08 18:10:51 +08:00
import defaultNotifyIcon from "@/static/images/default_notify_icon.png";
2025-11-27 07:48:42 +08:00
import util from "@/util";
2025-12-27 07:08:30 +08:00
import md5 from "md5";
2025-11-27 07:48:42 +08:00
export default {
name: "MyAvatar",
props: {
src: String,
shape: {
type: String,
default: "square",
},
size: {
type: String,
default: "40",
},
isGroup: {
type: Boolean,
default: false,
},
isNotify: {
type: Boolean,
default: false,
},
2025-11-07 09:56:20 +08:00
2025-11-27 07:48:42 +08:00
desc: String,
},
data() {
return {
avatarText: undefined,
2025-12-27 07:08:30 +08:00
cachesrc:"",
2025-11-27 07:48:42 +08:00
};
},
computed: {
2026-01-12 18:07:21 +08:00
getDefaultUrl() {
2025-12-27 07:08:30 +08:00
return this.isGroup ? defaultGroupIcon : defaultUserIcon;
2025-11-27 07:48:42 +08:00
},
},
2026-01-09 09:15:59 +08:00
watch:{
src(nv,ov){
this.init(nv);
},
desc() {
//this.redirectShow();
2025-12-27 07:08:30 +08:00
}
2026-01-09 09:15:59 +08:00
},
created() {
this.init(this.src);
2025-12-27 07:08:30 +08:00
},
2025-11-27 07:48:42 +08:00
methods: {
2026-01-09 09:15:59 +08:00
init(nv){
const _this = this;
if (nv) {
util.cacheFile(util.cdn(nv),'avatar').then(res=>{
_this.avatarText=""
_this.cachesrc = res;
//console.log(_this.cachesrc);
});
return ;
}
if (this.isGroup) {
_this.cachesrc = defaultGroupIcon;
return ;
}
if (this.isNotify) {
_this.cachesrc = defaultNotifyIcon;
return ;
}
2025-11-27 07:48:42 +08:00
this.avatarText = this.desc ? this.desc.slice(0, 1) : "未知";
},
2026-01-09 09:15:59 +08:00
errorHandle() {
this.avatarText = this.desc ? this.desc.slice(0, 1) : "未知";
2025-11-27 07:48:42 +08:00
},
click() {
this.$emit("click");
},
longpress() {
this.$emit("longpress");
},
2026-01-09 09:15:59 +08:00
}
2025-11-27 07:48:42 +08:00
};
2025-11-07 09:56:20 +08:00
</script>
2025-11-27 07:48:42 +08:00
<style></style>