From bfc6f0056ed91b5bfca3a039196deb79c0ddfa96 Mon Sep 17 00:00:00 2001 From: xsx <825657193@qq.com> Date: Wed, 16 Jul 2025 17:19:37 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A4=B4=E5=83=8F=E6=A0=B7=E5=BC=8F=E4=BC=98?= =?UTF-8?q?=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../components/head-image/head-image.vue | 8 +++++-- im-web/src/components/common/HeadImage.vue | 24 +++++++++++++------ 2 files changed, 23 insertions(+), 9 deletions(-) diff --git a/im-uniapp/components/head-image/head-image.vue b/im-uniapp/components/head-image/head-image.vue index 3e4210a..1f1251e 100644 --- a/im-uniapp/components/head-image/head-image.vue +++ b/im-uniapp/components/head-image/head-image.vue @@ -71,11 +71,15 @@ export default { avatarTextStyle() { return `width: ${this._size}rpx; height:${this._size}rpx; - background-color:${this.name ? this.textColor : '#fff'}; - font-size:${this._size * 0.5}rpx; + background: linear-gradient(145deg,#ffffff20 25%,#00000060),${this.textColor}; + font-size:${this._size * 0.45}rpx; + border-radius: ${this.radius}; ` }, textColor() { + if(!this.name){ + return '#fff'; + } let hash = 0; for (var i = 0; i < this.name.length; i++) { hash += this.name.charCodeAt(i); diff --git a/im-web/src/components/common/HeadImage.vue b/im-web/src/components/common/HeadImage.vue index ed0008f..40fa044 100644 --- a/im-web/src/components/common/HeadImage.vue +++ b/im-web/src/components/common/HeadImage.vue @@ -2,7 +2,7 @@
- {{ name?.substring(0, 2).toUpperCase() }}
+ {{ avaterText }}
@@ -66,6 +66,9 @@ export default { this.$eventBus.$emit("openUserInfo", user, pos); }) } + }, + isChinese(charCode) { + return charCode >= 0x4e00 && charCode <= 0x9fa5; } }, computed: { @@ -78,14 +81,21 @@ export default { avatarTextStyle() { let w = this.width ? this.width : this.size; let h = this.height ? this.height : this.size; - return ` - width: ${w}px;height:${h}px; - background-color: ${this.name ? this.textColor : '#fff'}; - font-size:${w * 0.35}px; - border-radius: ${this.radius}; - ` + return `width: ${w}px;height:${h}px; + background: linear-gradient(145deg,#ffffff20 25%,#00000060),${this.textColor}; + font-size:${w * 0.4}px; + border-radius: ${this.radius};` + }, + avaterText() { + if (!this.name) return ''; + if (this.isChinese(this.name.charCodeAt(0))) { + return this.name.charAt(0) + } else { + return this.name.charAt(0).toUpperCase() + this.name.charAt(1) + } }, textColor() { + if (!this.name) return 'fff'; let hash = 0; for (var i = 0; i < this.name.length; i++) { hash += this.name.charCodeAt(i);