From 54765747d0ce69bcef570a87795d08e37fa89255 Mon Sep 17 00:00:00 2001 From: anlyyao Date: Mon, 23 Dec 2024 19:26:13 +0800 Subject: [PATCH] feat(Avatar): the size attr supports rpx units --- src/avatar/avatar.ts | 3 ++- src/avatar/avatar.wxml | 2 +- src/avatar/avatar.wxs | 14 ++++++++++---- 3 files changed, 13 insertions(+), 6 deletions(-) diff --git a/src/avatar/avatar.ts b/src/avatar/avatar.ts index 397af3a29..cdc7dee0c 100644 --- a/src/avatar/avatar.ts +++ b/src/avatar/avatar.ts @@ -1,7 +1,7 @@ import { SuperComponent, wxComponent, RelationsOptions } from '../common/src/index'; import config from '../common/config'; import avatarProps from './props'; -import { setIcon } from '../common/utils'; +import { setIcon, systemInfo } from '../common/utils'; const { prefix } = config; const name = `${prefix}-avatar`; @@ -27,6 +27,7 @@ export default class Avatar extends SuperComponent { classPrefix: name, isShow: true, zIndex: 0, + systemInfo, }; relations: RelationsOptions = { diff --git a/src/avatar/avatar.wxml b/src/avatar/avatar.wxml index 3f6e6791a..f76c227ab 100644 --- a/src/avatar/avatar.wxml +++ b/src/avatar/avatar.wxml @@ -22,7 +22,7 @@ > -1) { - return 'width:' + size + ';height:' + size + ';font-size:' + ((size.slice(0, pxIndex) / 8) * 3 + 2) + 'px;'; + getSize: function (size = 'medium', systemInfo) { + var res = getRegExp('^([0-9]+)(px|rpx)$').exec(size);; + + if (res && res.length >= 3) { + var px = res[1]; + if (res[2] === 'rpx') { + px = Math.floor((systemInfo.windowWidth * res[1]) / 750); + } + + return 'width:' + size + ';height:' + size + ';font-size:' + ((px / 8) * 3 + 2) + 'px'; } },