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.

51 lines
1.1 KiB
Vue

This file contains ambiguous Unicode characters!

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
* usersa0ChunLuyu
* date2022-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: 140rpx;
height: 140rpx;
position: relative;
}
</style>