Merge branch 'dev' into 'master'

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

See merge request jianweie/coreshoppro!60
This commit is contained in:
花城
2024-10-28 07:45:43 +00:00
2 changed files with 50 additions and 17 deletions

View File

@@ -41,6 +41,22 @@
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 {

View File

@@ -12,16 +12,24 @@
<view class="item-box">
<view class="lab">头像</view>
<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">
<image v-if="state.avatar" class="img" :src="state.avatar"></image>
<image v-else class="img" src="/static/images/member/upload.png"></image>
</view>
<!-- #endif -->
</view>
</view>
<view class="item-box center">
<view class="lab">昵称</view>
<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 class="item-box center">
@@ -99,38 +107,47 @@
});
onReady(() => {
datetimePicker.value.setFormatter(formatter)
datetimePicker?.value.setFormatter(formatter)
});
/** 获取头像*/
const getChooseavatar = (res : any) => {
handleUploadImages(res.detail.avatarUrl);
}
/** 上传 */
const handleUploadAvatar = () => {
uni.chooseImage({
count: 1,
async success(res : any) {
const img : Response<any> = await queryUploadImages(res.tempFilePaths[0]);
if (img.status) {
state.avatar = img?.data?.src;
const changeAvatar : Response<any> = await queryChangeAvatar({ id: img?.data?.src });
if (changeAvatar.status) {
handleShowToast('上传成功', 'success');
} else {
handleShowToast('上传失败');
}
} else {
handleShowToast('上传失败');
}
success(res : any) {
handleUploadImages(res.tempFilePaths[0]);
}
})
}
/** 请求上传头像 */
const handleUploadImages = async (url : string) => {
const img : Response<any> = await queryUploadImages(url);
if (img.status) {
state.avatar = img?.data?.src;
const changeAvatar : Response<any> = await queryChangeAvatar({ id: img?.data?.src });
if (changeAvatar.status) {
handleShowToast('上传成功', 'success');
} else {
handleShowToast('上传失败');
}
} else {
handleShowToast('上传失败');
}
}
/** 获取用户信息 */
const getUserInfo = async () => {
const userInfo : Response<UserInfoType> = await queryUserInfo();
state.userInfo = userInfo?.data;
if (userInfo?.data?.birthday) {
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');
}
if (userInfo?.data?.nickName) {