uniapp【优化】: 个人信息头像昵称可以从小程序取

This commit is contained in:
15093570141
2024-10-28 15:45:25 +08:00
parent cc5210e88a
commit e105712390
2 changed files with 50 additions and 17 deletions

View File

@@ -41,6 +41,22 @@
height: 100%; height: 100%;
} }
} }
.avatar-botton {
background-color: none;
padding: 0;
line-height: inherit;
width: 150rpx;
height: 150rpx;
border-radius: 15rpx;
.img {
display: block;
width: 100%;
height: 100%;
}
&::after {
content: none;
}
}
} }
} }
.center { .center {

View File

@@ -12,16 +12,24 @@
<view class="item-box"> <view class="item-box">
<view class="lab">头像</view> <view class="lab">头像</view>
<view class="val"> <view class="val">
<!-- #ifdef MP-WEIXIN -->
<button class="avatar-botton" open-type="chooseAvatar" @chooseavatar="getChooseavatar">
<image v-if="state.avatar" class="img" :src="state.avatar"></image>
<image v-else class="img" src="/static/images/member/upload.png"></image>
</button>
<!-- #endif -->
<!-- #ifndef MP-WEIXIN -->
<view class="upload-box" @click="handleUploadAvatar"> <view class="upload-box" @click="handleUploadAvatar">
<image v-if="state.avatar" class="img" :src="state.avatar"></image> <image v-if="state.avatar" class="img" :src="state.avatar"></image>
<image v-else class="img" src="/static/images/member/upload.png"></image> <image v-else class="img" src="/static/images/member/upload.png"></image>
</view> </view>
<!-- #endif -->
</view> </view>
</view> </view>
<view class="item-box center"> <view class="item-box center">
<view class="lab">昵称</view> <view class="lab">昵称</view>
<view class="val"> <view class="val">
<uv-input placeholder="请输入昵称" border="none" v-model="state.nickname"></uv-input> <input type="nickname" placeholder="请输入昵称" border="none" v-model="state.nickname" ></input>
</view> </view>
</view> </view>
<view class="item-box center"> <view class="item-box center">
@@ -99,18 +107,29 @@
}); });
onReady(() => { onReady(() => {
datetimePicker.value.setFormatter(formatter) datetimePicker?.value.setFormatter(formatter)
}); });
/** 获取头像*/
const getChooseavatar = (res : any) => {
handleUploadImages(res.detail.avatarUrl);
}
/** 上传 */ /** 上传 */
const handleUploadAvatar = () => { const handleUploadAvatar = () => {
uni.chooseImage({ uni.chooseImage({
count: 1, count: 1,
async success(res : any) { success(res : any) {
const img : Response<any> = await queryUploadImages(res.tempFilePaths[0]); handleUploadImages(res.tempFilePaths[0]);
}
})
}
/** 请求上传头像 */
const handleUploadImages = async (url : string) => {
const img : Response<any> = await queryUploadImages(url);
if (img.status) { if (img.status) {
state.avatar = img?.data?.src; state.avatar = img?.data?.src;
const changeAvatar : Response<any> = await queryChangeAvatar({ id: img?.data?.src }); const changeAvatar : Response<any> = await queryChangeAvatar({ id: img?.data?.src });
if (changeAvatar.status) { if (changeAvatar.status) {
handleShowToast('上传成功', 'success'); handleShowToast('上传成功', 'success');
@@ -121,8 +140,6 @@
handleShowToast('上传失败'); handleShowToast('上传失败');
} }
} }
})
}
/** 获取用户信息 */ /** 获取用户信息 */
const getUserInfo = async () => { const getUserInfo = async () => {
@@ -130,7 +147,7 @@
state.userInfo = userInfo?.data; state.userInfo = userInfo?.data;
if (userInfo?.data?.birthday) { if (userInfo?.data?.birthday) {
state.percentage += 25; state.percentage += 25;
state.birthdayTemporary = new Date(userInfo?.data?.birthday).getTime(); state.birthdayTemporary = String(new Date(userInfo?.data?.birthday).getTime());
state.birthday = timeFormat(userInfo?.data?.birthday, 'yyyy-mm-dd'); state.birthday = timeFormat(userInfo?.data?.birthday, 'yyyy-mm-dd');
} }
if (userInfo?.data?.nickName) { if (userInfo?.data?.nickName) {