You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.
< script setup >
/**
* name:
* user: sa0ChunLuyu
* date: 2022-04-20 08:38:17
*/
import {
ref
} from 'vue'
const user _avatar = ref ( '' )
const onChooseAvatar = ( e ) => {
let avatar = e . detail . avatarUrl
if ( avatar . indexOf ( 'thirdwx.qlogo.cn' ) === - 1 ) {
wx . getFileSystemManager ( ) . readFile ( {
filePath : avatar ,
encoding : 'base64' ,
success : res => {
let base64 = 'data:image/png;base64,' + res . data ;
user _avatar . value = base64
}
} ) ;
} else {
uni . request ( {
url : avatar ,
method : 'GET' ,
responseType : 'arraybuffer' ,
success : res => {
let base64 = 'data:image/png;base64,' + uni . arrayBufferToBase64 ( res . data ) ;
user _avatar . value = base64
}
} ) ;
}
}
< / script >
< template >
< u -tr >
< u -td > 用户头像 < / u - t d >
< u -td >
< view class = "avatar_wrapper" >
< u -image v-if ="user_avatar" :showLoading="true" :src="user_avatar" width="140rpx" height="140rpx">
</u-image>
</view>
</u-td>
<u-td>
<button class="open_type_button_wrapper" open-type="chooseAvatar"
@chooseavatar="onChooseAvatar" > 获 取 头 像 < / button >
< / u -td >
< / u - t r >
< / template >
< style scoped >
. open _type _button _wrapper {
width : 140 rpx ;
height : 40 rpx ;
line - height : 40 rpx ;
font - size : 16 rpx ;
}
. avatar _wrapper {
width : 140 rpx ;
height : 140 rpx ;
position : relative ;
}
< / style >