youdas/pages/me/account-info.vue
2025-06-22 12:31:15 +08:00

279 lines
7.4 KiB
Vue
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<!-- 详情 -->
<template>
<page-container ref="pageContainer" title="我的信息" show-back :show-not-data="false" :refresh="onRefresh">
<view class="content">
<view class="form-container">
<view class="form-item" @click="onClickAvatar">
<view class="form-label">头像:</view>
<view class="form-input avatar-container">
<image class="avatar" :src="avatarUrl"></image>
<image class="arrow-icon" src="/static/app-plus/arrow-right.png" mode="aspectFill"
style="width: 24rpx;height: 24rpx;"></image>
</view>
</view>
<view class="form-item">
<view class="form-label">昵称:</view>
<view class="form-input">
<input type="text" v-model="nickname" placeholder="请输入您的昵称" />
</view>
</view>
<view class="form-item" @click="copyUid">
<view class="form-label">ID:</view>
<view class="form-input">
<text class="form-text">{{ uid }}</text>
<image class="copy-icon" src="/static/app-plus/copy.png" mode="aspectFill"
style="width: 24rpx;height: 24rpx;"></image>
</view>
</view>
<view class="form-item" @click="showGenderPicker">
<view class="form-label">性别:</view>
<view class="form-input">
<text class="form-text">{{ genderText || '请选择性别' }}</text>
<image class="arrow-icon" src="/static/ic_arrow.png" mode="aspectFill"
style="width: 24rpx;height: 24rpx;"></image>
</view>
</view>
<view class="form-item">
<view class="form-label">已绑定手机号:</view>
<view class="form-input">
<input disabled :value="phoneNumber" placeholder="暂未绑定手机号" />
</view>
</view>
</view>
<view class="submit-btn" @click="handleUpdateUserInfo">确认修改</view>
</view>
</page-container>
</template>
<script setup>
import { ref, onMounted } from 'vue'
import { updateUserInfo } from '@/common/server/user'
import { getAccountInfo } from '@/common/system/userInfo'
//# 必须要引入
import PageContainer from '@/components/youdas-container/page-container.vue'
// 用户信息
const pageContainer = ref(null)
const avatarUrl = ref("")
const nickname = ref("")
const uid = ref("")
const imageBase64 = ref("")
const showNotData = ref(false)
const gender = ref(3); // 0-未设置1-男2-女3-保密
const genderText = ref("保密"); // 性别文本,默认保密
const phoneNumber = ref(""); // 已绑定手机号
// 初始化用户信息
onMounted(async () => {
const userInfo = await getAccountInfo();
if (userInfo) {
avatarUrl.value = userInfo.userIcon || "";
nickname.value = userInfo.username || "";
uid.value = userInfo.uid || "";
gender.value = yds.getCache("user_gender") || 3; // 默认为保密
genderText.value = gender.value === 1 ? "男" : (gender.value === 2 ? "女" : "保密");
phoneNumber.value = userInfo.mobile || "";
}
console.log(userInfo);
});
// 选择头像
const onClickAvatar = () => {
uni.chooseImage({
count: 1,
sourceType: ["album"],
success: async (res) => {
avatarUrl.value = res.tempFilePaths[0];
imageBase64.value = await imageToBase64Plus(avatarUrl.value);
}
});
};
// 图片转Base64
const imageToBase64Plus = (filePath) => {
return new Promise((resolve, reject) => {
plus.io.resolveLocalFileSystemURL(filePath, entry => {
entry.file(file => {
const fileReader = new plus.io.FileReader();
fileReader.onloadend = function (e) {
const base64 = e.target.result;
resolve(base64);
};
fileReader.readAsDataURL(file);
}, reject);
}, reject);
});
};
// 更新用户信息
const handleUpdateUserInfo = async () => {
if (!nickname.value) {
uni.showToast({
title: "请输入昵称",
icon: "none",
});
return;
}
const result = await updateUserInfo(
nickname.value,
avatarUrl.value,
imageBase64.value,
gender.value
);
if (result) {
yds.showToast("修改成功");
yds.userInfo.clearAccountInfo();
yds.setCache("user_gender", gender.value);
// // 延迟返回
// setTimeout(() => {
// uni.navigateBack();
// }, 1000);
} else {
yds.showToast("修改失败");
}
};
// 复制ID到剪贴板
const copyUid = () => {
if (uid.value) {
uni.setClipboardData({
data: uid.value,
success: () => {
uni.showToast({
title: 'ID已复制',
icon: 'success'
});
}
});
}
};
// 显示性别选择器
const showGenderPicker = () => {
uni.showActionSheet({
itemList: ["男", "女", "保密"],
success: (res) => {
gender.value = res.tapIndex + 1; // 1-男2-女3-保密
genderText.value = ["男", "女", "保密"][res.tapIndex];
}
});
};
// 刷新方法
const onRefresh = async (paging) => {
await yds.sleep(500);
paging.complete();
};
</script>
<style lang="scss" scoped>
.content {
width: 100%;
box-sizing: border-box;
display: flex;
flex-direction: column;
background-color: #FFFFFF;
}
.form-container {
width: 690rpx;
margin: 0 auto;
}
.form-item {
display: flex;
padding: 30rpx 0;
position: relative;
align-items: center;
&::after {
content: "";
display: block;
position: absolute;
left: 0;
bottom: 0;
width: 100%;
height: 2rpx;
background: #F3F3F3;
}
.form-label {
width: 150rpx;
font-size: 24rpx;
color: #8A8A8A;
display: flex;
align-items: center;
}
.form-input {
flex: 1;
display: flex;
align-items: center;
input {
flex: 1;
text-align: right;
font-size: 24rpx;
color: #333333;
}
.copy-icon {
margin-left: 10rpx;
width: 24rpx;
height: 24rpx;
}
.arrow-icon {
margin-left: 10rpx;
width: 24rpx;
height: 24rpx;
}
.form-text {
flex: 1;
text-align: right;
font-size: 24rpx;
color: #333333;
}
}
}
.submit-btn {
width: 244rpx;
height: 72rpx;
background: #333333;
border-radius: 16rpx;
font-size: 24rpx;
color: #D8FD24;
margin: 200rpx auto 0;
display: flex;
align-items: center;
justify-content: center;
}
.avatar-container {
display: flex;
align-items: center;
justify-content: flex-end;
.avatar {
width: 80rpx;
height: 80rpx;
border-radius: 50%;
margin-right: 10rpx;
}
}
</style>