Commit 5639f6e0 authored by 王炽's avatar 王炽

66666

parent e7541c01
......@@ -6,12 +6,14 @@
:iconSelected="$baseUrl + 'my/track/icon_stage_sel.png'"
@update:selectedIndex="(val) => (wheelSelectedIndex = val)" @change="handleWheelChange" />
</view>
<view class="bg-container" :data-log="{
<view class="bg-container"
v-if="cfgStatus.isRegister"
:data-log="{
xcxClick: '我的页面点击',
pageName: '我的页面',
buttonName: '个人信息修改',
}" @click="handleEditProfile">
<image class="bg-img" :src="babyInfo?.content?.backgroundImg || $baseUrl + 'my/default_bg.png'
}" @click="handleUploadBackground">
<image class="bg-img" :src="localBackgroundImg || babyInfo?.content?.backgroundImg || $baseUrl + 'my/default_bg.png'
" mode="widthFix" lazy-load="false" binderror="" bindload="" />
<image class="banner_cover" :src="$baseUrl + 'my/cover_white.png'" mode="aspectFill" />
</view>
......@@ -21,14 +23,16 @@
<!-- 用户信息区域 -->
<view class="user-info" :style="{ 'min-height': cfgStatus.showDetail ? '343rpx' : '168rpx' }">
<view class="user-header">
<view class="avatar-container" @click="handleEditProfile" :data-log="{
<view class="avatar-container">
<button class="avatar-wrapper" :data-log="{
xcxClick: '我的页面点击',
pageName: '我的页面',
buttonName: '个人信息修改',
}">
<image class="avatar" :src="babyInfo?.content?.babyAvatar ||
$baseUrl + 'common/default_avatar.png'
" mode="widthFix" />
}" open-type="chooseAvatar" @chooseavatar="onChooseAvatar">
<image class="avatar" :src="localAvatarUrl || babyInfo?.content?.babyAvatar ||
$baseUrl + 'common/default_avatar.png'
" mode="widthFix" />
</button>
</view>
<button v-if="!cfgStatus.isRegister" type="primary" class="avatar-container" @click="clickRegisterShield" />
<image class="avatar-modify" :src="$baseUrl + 'my/icon_modify.png'" mode="aspectFit" lazy-load="false" />
......@@ -310,6 +314,12 @@ const points = ref(0);
const babyId = ref(0);
// 本地头像 URL,用于临时显示上传后的头像
const localAvatarUrl = ref('');
// 本地背景图片 URL,用于临时显示上传后的背景图
const localBackgroundImg = ref('');
const handleTaskClick = async () => {
// 添加点击埋点
md.sensorComponentLogTake({
......@@ -546,11 +556,85 @@ const handleEditProfile = (e) => {
if (type === "edit") {
babyId.value = userStore.babyInfo?.allBabyBaseInfo.find(
(item) => item.selected
)?.id;
)?.id;
navigateTo(`/pages/person/person?type=${type}&id=${babyId.value}`);
} else {
navigateTo(`/pages/person/person?type=${type}`);
}
};
// 选择头像
const onChooseAvatar = async (e) => {
showLoading('上传中...');
md.sensorLog(e);
md.sensorComponentLogTake({
xcxComponentClick: "true",
pageName: "我的页面",
componentName: "资料编辑",
componentContent: "资料编辑"
})
try {
const fs = uni.getFileSystemManager();
const base64 =
"data:image/jpeg;base64," + fs.readFileSync(e.detail.avatarUrl, "base64");
const res = await uploadImage(base64);
if (res.success) {
// 立即更新本地显示的头像
localAvatarUrl.value = res.data.url;
// 获取当前选中的宝宝信息并更新到服务器
const selectedBaby = userStore.babyInfo?.allBabyBaseInfo?.find(
(item) => item.selected
);
if (selectedBaby) {
const updateData = {
id: selectedBaby.id,
babyAvatar: res.data.url,
};
const updateRes = await updateBabyInfo(updateData);
if (updateRes.success) {
// 刷新用户信息
await userStore.loadBabyInfo();
// 清空本地临时头像,使用更新后的 babyInfo
localAvatarUrl.value = '';
uni.showToast({
title: "头像更新成功",
icon: "success",
});
} else {
uni.showToast({
title: updateRes.message || "更新失败",
icon: "none",
});
}
} else {
uni.showToast({
title: "未找到宝宝信息",
icon: "none",
});
}
} else {
uni.showToast({
title: res.message,
icon: "none",
});
}
} catch (error) {
console.error("头像选择失败:", error);
uni.showToast({
title: "头像选择失败",
icon: "none",
});
} finally {
hideLoading();
}
};
const onRegisterConfirm = async () => {
......@@ -867,6 +951,103 @@ const handleOpenClick = () => {
cfgStatus.value.openBabyCardDesc = !cfgStatus.value.openBabyCardDesc;
};
// 上传背景图片
const handleUploadBackground = async (e) => {
// 检查登录状态
if (!cfgStatus.value.isRegister) {
return;
}
md.sensorLog(e);
md.sensorComponentLogTake({
xcxComponentClick: "true",
pageName: "我的页面",
componentName: "资料编辑",
componentContent: "资料编辑"
})
// 唤起图片选择器
uni.chooseImage({
count: 1,
sizeType: ["original", "compressed"],
sourceType: ["album", "camera"],
success: async (res) => {
showLoading('上传中...');
try {
const tempFilePath = res.tempFilePaths[0];
const fs = uni.getFileSystemManager();
const base64 =
"data:image/jpeg;base64," + fs.readFileSync(tempFilePath, "base64");
const uploadRes = await uploadImage(base64);
if (uploadRes.success) {
// 立即更新本地显示的背景图
localBackgroundImg.value = uploadRes.data.url;
// 获取当前选中的宝宝信息并更新到服务器
const selectedBaby = userStore.babyInfo?.allBabyBaseInfo?.find(
(item) => item.selected
);
if (selectedBaby) {
const updateData = {
id: selectedBaby.id,
backgroundImg: uploadRes.data.url,
};
const updateRes = await updateBabyInfo(updateData);
if (updateRes.success) {
// 刷新用户信息
await userStore.loadBabyInfo();
// 清空本地临时背景图,使用更新后的 babyInfo
localBackgroundImg.value = '';
uni.showToast({
title: "背景更新成功",
icon: "success",
});
} else {
uni.showToast({
title: updateRes.message || "更新失败",
icon: "none",
});
}
} else {
uni.showToast({
title: "未找到宝宝信息",
icon: "none",
});
}
} else {
uni.showToast({
title: uploadRes.message || "上传失败",
icon: "none",
});
}
} catch (error) {
console.error("背景图片上传失败:", error);
uni.showToast({
title: "背景图片上传失败",
icon: "none",
});
} finally {
hideLoading();
}
},
fail: (err) => {
console.error("选择图片失败:", err);
uni.showToast({
title: "选择图片失败",
icon: "none",
});
}
});
};
// 页面加载
onMounted(async () => {
md.sensorLogTake({
......@@ -1062,6 +1243,17 @@ defineExpose({});
top: 32rpx;
z-index: 1;
.avatar-wrapper {
display: flex;
align-items: center;
justify-content: center;
padding: 0;
border: none;
background: transparent;
width: 100%;
height: 100%;
}
.avatar {
width: 100%;
height: 100%;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment