Lufaneng 11 months ago
parent 04bbcfcf02
commit 3565433ce9

@ -1,460 +1,472 @@
<template> <template>
<view class="container"> <view class="container">
<!-- 个人信息设置 --> <!-- 个人信息设置 -->
<view class="profile-section"> <view class="profile-section">
<!-- 头像 --> <!-- 头像 -->
<view class="profile-item" @click="changeAvatar"> <view class="profile-item" @click="changeAvatar">
<view class="item-label">头像</view> <view class="item-label">头像</view>
<view class="item-content"> <view class="item-content">
<image class="avatar" :src="userInfo.avatar" mode="aspectFill"></image> <image
<u-icon name="arrow-right" size="16" color="#ccc"></u-icon> class="avatar"
</view> :src="userInfo.avatar"
</view> mode="aspectFill"
></image>
<!-- 用户名 --> <uv-icon name="arrow-right" size="16" color="#ccc"></uv-icon>
<view class="profile-item" @click="editUsername"> </view>
<view class="item-label">用户名</view> </view>
<view class="item-content">
<text class="item-value">{{ userInfo.username }}</text> <!-- 用户名 -->
<u-icon name="arrow-right" size="16" color="#ccc"></u-icon> <view class="profile-item" @click="editUsername">
</view> <view class="item-label">用户名</view>
</view> <view class="item-content">
<text class="item-value">{{ userInfo.username }}</text>
<!-- 电话 --> <uv-icon name="arrow-right" size="16" color="#ccc"></uv-icon>
<view class="profile-item" @click="editPhone"> </view>
<view class="item-label">电话</view> </view>
<view class="item-content">
<text class="item-value">{{ userInfo.phone }}</text> <!-- 电话 -->
<u-icon name="arrow-right" size="16" color="#ccc"></u-icon> <view class="profile-item" @click="editPhone">
</view> <view class="item-label">电话</view>
</view> <view class="item-content">
<text class="item-value">{{ userInfo.phone }}</text>
<!-- 邮箱 --> <uv-icon name="arrow-right" size="16" color="#ccc"></uv-icon>
<view class="profile-item" @click="editEmail"> </view>
<view class="item-label">邮箱</view> </view>
<view class="item-content">
<text class="item-value">{{ userInfo.email }}</text> <!-- 邮箱 -->
<u-icon name="arrow-right" size="16" color="#ccc"></u-icon> <view class="profile-item" @click="editEmail">
</view> <view class="item-label">邮箱</view>
</view> <view class="item-content">
</view> <text class="item-value">{{ userInfo.email }}</text>
<uv-icon name="arrow-right" size="16" color="#ccc"></uv-icon>
<!-- 应用设置 --> </view>
<view class="app-section"> </view>
<!-- 缓存 --> </view>
<!-- <view class="profile-item" @click="clearCache">
<!-- 应用设置 -->
<view class="app-section">
<!-- 缓存 -->
<!-- <view class="profile-item" @click="clearCache">
<view class="item-label">缓存</view> <view class="item-label">缓存</view>
<view class="item-content"> <view class="item-content">
<text class="item-value">{{ cacheSize }}</text> <text class="item-value">{{ cacheSize }}</text>
<u-icon name="arrow-right" size="16" color="#ccc"></u-icon> <uv-icon name="arrow-right" size="16" color="#ccc"></uv-icon>
</view> </view>
</view> --> </view> -->
<!-- 用户协议 --> <!-- 用户协议 -->
<view class="profile-item" @click="viewUserAgreement"> <view class="profile-item" @click="viewUserAgreement">
<view class="item-label">用户协议</view> <view class="item-label">用户协议</view>
<view class="item-content"> <view class="item-content">
<u-icon name="arrow-right" size="16" color="#ccc"></u-icon> <uv-icon name="arrow-right" size="16" color="#ccc"></uv-icon>
</view> </view>
</view> </view>
<!-- 关于我们 --> <!-- 关于我们 -->
<view class="profile-item" @click="viewAbout"> <view class="profile-item" @click="viewAbout">
<view class="item-label">关于我们</view> <view class="item-label">关于我们</view>
<view class="item-content"> <view class="item-content">
<u-icon name="arrow-right" size="16" color="#ccc"></u-icon> <uv-icon name="arrow-right" size="16" color="#ccc"></uv-icon>
</view> </view>
</view> </view>
</view> </view>
<!-- 退出登录按钮 --> <!-- 退出登录按钮 -->
<view class="logout-section"> <view class="logout-section">
<u-button type="primary" size="large" @click="logout" :loading="logoutLoading"> <uv-button
退出登陆 type="primary"
</u-button> size="large"
</view> @click="logout"
:loading="logoutLoading"
<!-- 编辑弹窗 --> >
<u-popup :show="showEditModal" mode="center" @close="closeEditModal" :round="10"> 退出登陆
<view class="edit-modal"> </uv-button>
<view class="modal-title"> </view>
编辑{{
<!-- 编辑弹窗 -->
<uv-popup ref="editPopup" mode="center" @close="closeEditModal" :round="10">
<view class="edit-modal">
<view class="modal-title">
编辑{{
editType === "username" editType === "username"
? "用户名" ? "用户名"
: editType === "phone" : editType === "phone"
? "电话" ? "电话"
: "邮箱" : editType === 'email' ? "邮箱" : ''
}} }}
</view> </view>
<u-input v-model="editValue" :placeholder="getPlaceholder()" :type=" <uv-input
v-model="editValue"
:placeholder="getPlaceholder()"
:type="
editType === 'phone' editType === 'phone'
? 'number' ? 'number'
: editType === 'email' : editType === 'email'
? 'email' ? 'email'
: 'text' : 'text'
" border="bottom" clearable></u-input> "
<view class="modal-actions"> border="bottom"
<u-button type="default" @click="closeEditModal"></u-button> clearable
<u-button type="primary" @click="saveEdit"></u-button> ></uv-input>
</view> <view class="modal-actions">
</view> <uv-button type="default" @click="closeEditModal"></uv-button>
</u-popup> <uv-button type="primary" @click="saveEdit"></uv-button>
</view>
<!-- 头像选择弹窗 --> </view>
<u-action-sheet :show="showAvatarSheet" :actions="avatarActions" @close="showAvatarSheet = false" </uv-popup>
@select="onAvatarSelect"></u-action-sheet>
</view> <!-- 头像选择弹窗 -->
<uv-action-sheet
:show="showAvatarSheet"
:actions="avatarActions"
@close="showAvatarSheet = false"
@select="onAvatarSelect"
></uv-action-sheet>
</view>
</template> </template>
<script setup> <script setup>
import { import { ref, onMounted } from "vue";
ref, import { onShow } from "@dcloudio/uni-app";
onMounted import { useAuthStore, useUserStore } from "@/store";
} from "vue";
import { const authStore = useAuthStore();
onShow const userStore = useUserStore();
} from "@dcloudio/uni-app";
import { //
useAuthStore, const userInfo = ref({
useUserStore avatar: "/static/imgs/avatar.png",
} from "@/store"; username: "张三",
phone: "15825556676",
const authStore = useAuthStore() email: "235382903@qq.com",
const userStore = useUserStore() });
// const cacheSize = ref("36MB");
const userInfo = ref({ const logoutLoading = ref(false);
avatar: "/static/imgs/avatar.png", const showAvatarSheet = ref(false);
username: "张三", const editType = ref("");
phone: "15825556676", const editValue = ref("");
email: "235382903@qq.com", const editPopup = ref(null);
});
//
const cacheSize = ref("36MB"); const avatarActions = ref([
const logoutLoading = ref(false); {
const showEditModal = ref(false); name: "拍照",
const showAvatarSheet = ref(false); value: "camera",
const editType = ref(""); },
const editValue = ref(""); {
name: "从相册选择",
// value: "album",
const avatarActions = ref([{ },
name: "拍照", ]);
value: "camera",
}, //
{ const changeAvatar = () => {
name: "从相册选择", showAvatarSheet.value = true;
value: "album", };
},
]); //
const onAvatarSelect = (item) => {
// showAvatarSheet.value = false;
const changeAvatar = () => {
showAvatarSheet.value = true; uni.chooseImage({
}; count: 1,
sizeType: ["compressed"],
// sourceType: item.value === "camera" ? ["camera"] : ["album"],
const onAvatarSelect = (item) => { success: (res) => {
showAvatarSheet.value = false; const tempFilePath = res.tempFilePaths[0];
uni.chooseImage({ //
count: 1, // uploadAvatar(tempFilePath)
sizeType: ["compressed"],
sourceType: item.value === "camera" ? ["camera"] : ["album"], //
success: (res) => { userInfo.value.avatar = tempFilePath;
const tempFilePath = res.tempFilePaths[0];
uni.showToast({
// title: "头像更新成功",
// uploadAvatar(tempFilePath) icon: "success",
});
// },
userInfo.value.avatar = tempFilePath; fail: () => {
uni.showToast({
uni.showToast({ title: "选择图片失败",
title: "头像更新成功", icon: "none",
icon: "success", });
}); },
}, });
fail: () => { };
uni.showToast({
title: "选择图片失败", //
icon: "none", const editUsername = () => {
}); editType.value = "username";
}, editValue.value = userInfo.value.username;
}); editPopup.value.open();
}; };
// //
const editUsername = () => { const editPhone = () => {
editType.value = "username"; editType.value = "phone";
editValue.value = userInfo.value.username; editValue.value = userInfo.value.phone;
showEditModal.value = true; editPopup.value.open();
}; };
// //
const editPhone = () => { const editEmail = () => {
editType.value = "phone"; editType.value = "email";
editValue.value = userInfo.value.phone; editValue.value = userInfo.value.email;
showEditModal.value = true; editPopup.value.open();
}; };
// //
const editEmail = () => { const getPlaceholder = () => {
editType.value = "email"; switch (editType.value) {
editValue.value = userInfo.value.email; case "username":
showEditModal.value = true; return "请输入用户名";
}; case "phone":
return "请输入手机号";
// case "email":
const getPlaceholder = () => { return "请输入邮箱地址";
switch (editType.value) { default:
case "username": return "请输入";
return "请输入用户名"; }
case "phone": };
return "请输入手机号";
case "email": //
return "请输入邮箱地址"; const closeEditModal = () => {
default: editPopup.value.close();
return "请输入"; editType.value = "";
} editValue.value = "";
}; };
// //
const closeEditModal = () => { const saveEdit = async () => {
showEditModal.value = false; if (!editValue.value.trim()) {
editType.value = ""; uni.showToast({
editValue.value = ""; title: "请输入内容",
}; icon: "none",
});
// return;
const saveEdit = async () => { }
if (!editValue.value.trim()) {
uni.showToast({ //
title: "请输入内容", if (editType.value === "phone" && !/^1[3-9]\d{9}$/.test(editValue.value)) {
icon: "none", uni.showToast({
}); title: "请输入正确的手机号",
return; icon: "none",
} });
return;
// }
if (editType.value === "phone" && !/^1[3-9]\d{9}$/.test(editValue.value)) {
uni.showToast({ if (
title: "请输入正确的手机号", editType.value === "email" &&
icon: "none", !/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(editValue.value)
}); ) {
return; uni.showToast({
} title: "请输入正确的邮箱地址",
icon: "none",
if ( });
editType.value === "email" && return;
!/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(editValue.value) }
) {
uni.showToast({ try {
title: "请输入正确的邮箱地址", // API
icon: "none", // await RPC.post('/api/user/update', {
}); // [editType.value]: editValue.value
return; // })
}
//
try { userInfo.value[editType.value] = editValue.value;
// API
// await RPC.post('/api/user/update', { uni.showToast({
// [editType.value]: editValue.value title: "保存成功",
// }) icon: "success",
});
//
userInfo.value[editType.value] = editValue.value; closeEditModal();
} catch (error) {
uni.showToast({ console.error("保存失败:", error);
title: "保存成功", uni.showToast({
icon: "success", title: "保存失败,请重试",
}); icon: "none",
});
closeEditModal(); }
} catch (error) { };
console.error("保存失败:", error);
uni.showToast({ //
title: "保存失败,请重试", const clearCache = () => {
icon: "none", uni.showModal({
}); title: "清除缓存",
} content: "确定要清除应用缓存吗?",
}; success: (res) => {
if (res.confirm) {
// uni.showLoading({
const clearCache = () => { title: "清除中...",
uni.showModal({ });
title: "清除缓存",
content: "确定要清除应用缓存吗?", //
success: (res) => { setTimeout(() => {
if (res.confirm) { uni.hideLoading();
uni.showLoading({ cacheSize.value = "0MB";
title: "清除中...", uni.showToast({
}); title: "缓存清除成功",
icon: "success",
// });
setTimeout(() => { }, 1500);
uni.hideLoading(); }
cacheSize.value = "0MB"; },
uni.showToast({ });
title: "缓存清除成功", };
icon: "success",
}); //
}, 1500); const viewUserAgreement = () => {
} uni.navigateTo({
}, url: "/pagesA/user-agreement/user-agreement",
}); });
}; };
// //
const viewUserAgreement = () => { const viewAbout = () => {
uni.navigateTo({ // uni.navigateTo({
url: "/pagesA/user-agreement/user-agreement", // url: "/pagesA/about/about",
}); // });
}; };
// // 退
const viewAbout = () => { const logout = () => {
uni.navigateTo({ uni.showModal({
url: "/pagesA/about/about", title: "退出登录",
}); content: "确定要退出登录吗?",
}; success: (res) => {
if (res.confirm) {
// 退 logoutLoading.value = true;
const logout = () => {
uni.showModal({ // 退
title: "退出登录", setTimeout(() => {
content: "确定要退出登录吗?", authStore.signOut();
success: (res) => { logoutLoading.value = false;
if (res.confirm) {
logoutLoading.value = true; // token
// authStore.logout()
// 退
setTimeout(() => { uni.showToast({
authStore.signOut() title: "已退出登录",
logoutLoading.value = false; icon: "success",
});
// token
// authStore.logout() //
uni.reLaunch({
uni.showToast({ url: "/pages/login/login",
title: "已退出登录", });
icon: "success", }, 1000);
}); }
},
// });
uni.reLaunch({ };
url: "/pages/login/login",
}); //
}, 1000); const loadUserInfo = async () => {
} try {
}, // API
}); // const result = await RPC.get('/api/user/info')
}; // userInfo.value = result.data
} catch (error) {
// console.error("加载用户信息失败:", error);
const loadUserInfo = async () => { }
try { };
// API
// const result = await RPC.get('/api/user/info') //
// userInfo.value = result.data const calculateCacheSize = () => {
} catch (error) { //
console.error("加载用户信息失败:", error); // const size = await getCacheSize()
} // cacheSize.value = formatSize(size)
}; };
// onMounted(() => {
const calculateCacheSize = () => { loadUserInfo();
// calculateCacheSize();
// const size = await getCacheSize() });
// cacheSize.value = formatSize(size)
}; onShow(() => {
//
onMounted(() => { loadUserInfo();
loadUserInfo(); });
calculateCacheSize();
});
onShow(() => {
//
loadUserInfo();
});
</script> </script>
<style lang="scss" scoped> <style lang="scss" scoped>
.container { .container {
font-size: 14px; font-size: 14px;
min-height: 100vh; min-height: 100vh;
background-color: #f8f8f8; background-color: #f8f8f8;
padding: 16px; padding: 16px;
} }
.profile-section, .profile-section,
.app-section { .app-section {
background: white; background: white;
border-radius: 12px; border-radius: 12px;
margin-bottom: 16px; margin-bottom: 16px;
overflow: hidden; overflow: hidden;
.profile-item { .profile-item {
display: flex; display: flex;
align-items: center; align-items: center;
justify-content: space-between; justify-content: space-between;
padding: 16px; padding: 16px;
border-bottom: 1px solid #f0f0f0; border-bottom: 1px solid #f0f0f0;
&:last-child { &:last-child {
border-bottom: none; border-bottom: none;
} }
.item-label { .item-label {
font-size: 16px; font-size: 16px;
color: #333; color: #333;
font-weight: 500; font-weight: 500;
} }
.item-content { .item-content {
display: flex; display: flex;
align-items: center; align-items: center;
gap: 8px; gap: 8px;
.avatar { .avatar {
width: 40px; width: 40px;
height: 40px; height: 40px;
border-radius: 50%; border-radius: 50%;
} }
.item-value { .item-value {
font-size: 14px; font-size: 14px;
color: #666; color: #666;
} }
} }
} }
} }
.logout-section { .logout-section {
margin-top: 32px; margin-top: 32px;
} }
.edit-modal { .edit-modal {
width: 300px; width: 300px;
padding: 24px; padding: 24px;
.modal-title { .modal-title {
font-size: 18px; font-size: 18px;
font-weight: bold; font-weight: bold;
color: #333; color: #333;
text-align: center; text-align: center;
margin-bottom: 20px; margin-bottom: 20px;
} }
.modal-actions { .modal-actions {
display: flex; display: flex;
gap: 12px; gap: 12px;
margin-top: 20px; margin-top: 20px;
.u-button { .uv-button {
flex: 1; flex: 1;
} }
} }
} }
</style> </style>
Loading…
Cancel
Save