104 lines
3.5 KiB
Plaintext
104 lines
3.5 KiB
Plaintext
/*
|
||
* Copyright (C) 2024 Huawei Device Co., Ltd.
|
||
* Licensed under the Apache License, Version 2.0 (the 'License');
|
||
* you may not use this file except in compliance with the License.
|
||
* You may obtain a copy of the License at
|
||
*
|
||
* http://www.apache.org/licenses/LICENSE-2.0
|
||
*
|
||
* Unless required by applicable law or agreed to in writing, software
|
||
* distributed under the License is distributed on an 'AS IS' BASIS,
|
||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||
* See the License for the specific language governing permissions and
|
||
* limitations under the License.
|
||
*/
|
||
import { ImageKnifeComponent, ImageKnifeOption } from '@ohos/libraryimageknife'
|
||
|
||
// const logger = new imUtils.logger.IMLogger('Avatar')
|
||
@ObservedV2
|
||
export class MyStorage {
|
||
static instance:MyStorage | undefined = undefined
|
||
static getInstance(){
|
||
if(MyStorage.instance == undefined) {
|
||
MyStorage.instance = new MyStorage()
|
||
}
|
||
return MyStorage.instance
|
||
}
|
||
@Trace WeLink_Mob_fontSize_multiple: number = 1
|
||
}
|
||
|
||
@ComponentV2
|
||
export struct UserAvatar {
|
||
// @Prop userInfo: string = ""
|
||
imgSize: number = 100
|
||
radius: number = 12
|
||
borderSize: number = 0
|
||
imgSizes: number = 1
|
||
@Local ImageKnifeOption: ImageKnifeOption = new ImageKnifeOption()
|
||
scalable: boolean = true;
|
||
@Local calcImgSize: number = 100
|
||
@Param userInfo: string = ""
|
||
@Monitor('userInfo')
|
||
userInfoUpdate() {
|
||
// if (uri === 'userInfo' && this.imageKnifeOption.account !== this.userInfo.contactId) return;
|
||
// // logger.info(`userInfoUpdate uri=${uri} oldAcc=${this.imageKnifeOption.loadSrc} nowAcc=${this.userInfo.externalHeadUrl}`)
|
||
// if (this.userInfo.externalHeadUrl === this.imageKnifeOption.loadSrc && this.userInfo.infoUpdateTime.getTime()
|
||
// .toString() === this.imageKnifeOption?.signature?.getKey()) return;
|
||
this.ImageKnifeOption = new ImageKnifeOption({
|
||
//TODO:写死loadSRC,场景:变更组件大小,所有图片不显示
|
||
loadSrc: this.userInfo,
|
||
placeholderSrc: $r('app.media.loading'),
|
||
errorholderSrc: $r('app.media.failed'),
|
||
border: { radius:20,width:5,color:$r('app.color.start_window_background') },
|
||
objectFit:ImageFit.Contain
|
||
// signature: new ObjectKey(this.userInfo.infoUpdateTime.getTime().toString())
|
||
})
|
||
}
|
||
@Local storage: MyStorage = MyStorage.getInstance()
|
||
@Monitor('storage.WeLink_Mob_fontSize_multiple')
|
||
updateImgSize() {
|
||
this.setImageSize()
|
||
}
|
||
aboutToAppear(): void {
|
||
this.userInfoUpdate()
|
||
this.setImageSize()
|
||
}
|
||
|
||
setImageSize() {
|
||
if (!this.scalable) {
|
||
this.calcImgSize = this.imgSize
|
||
} else if (this.storage.WeLink_Mob_fontSize_multiple < 0.9) {
|
||
this.calcImgSize = this.imgSize * 0.9
|
||
} else if (this.storage.WeLink_Mob_fontSize_multiple > 1.6) {
|
||
this.calcImgSize = this.imgSize * 1.6
|
||
} else {
|
||
this.calcImgSize = this.imgSize * this.storage.WeLink_Mob_fontSize_multiple
|
||
}
|
||
}
|
||
|
||
aboutToReuse(param: ESObject) {
|
||
this.userInfoUpdate()
|
||
}
|
||
|
||
build() {
|
||
Row() {
|
||
// Image(this.imageKnifeOption.loadSrc)
|
||
|
||
ImageKnifeComponent({ imageKnifeOption: this.ImageKnifeOption })
|
||
.borderRadius(this.radius)
|
||
.clip(true)
|
||
.width(this.calcImgSize)
|
||
.height(this.calcImgSize)
|
||
.backgroundColor(Color.Pink)
|
||
|
||
|
||
|
||
// Image(this.userInfo)
|
||
// Text((this.imageKnifeOption.loadSrc as string).split('/')[8])
|
||
// .position({ x: 0, y: 0 })
|
||
// .zIndex(9)
|
||
// .fontSize(12)
|
||
// .fontColor('#ff0000')
|
||
}
|
||
}
|
||
} |