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 >
< uni -section title = "用户头像" type = "line" >
< view class = "uni-ma-5 uni-pb-5 example_item_wrapper" >
< image v-if ="user_avatar" :src ="user_avatar" > < / image >
< button size = "mini" open -type = " chooseAvatar "
@chooseavatar ="onChooseAvatar" > 获 取 头 像 < / button >
< / view >
< / uni -section >
< / template >
< style scoped >
. avatar _wrapper {
width : 140 rpx ;
height : 140 rpx ;
position : relative ;
}
< / style >