|
|
|
@ -19,30 +19,30 @@
|
|
|
|
<view class="profile-item" @click="editUsername">
|
|
|
|
<view class="profile-item" @click="editUsername">
|
|
|
|
<view class="item-label">用户名</view>
|
|
|
|
<view class="item-label">用户名</view>
|
|
|
|
<view class="item-content">
|
|
|
|
<view class="item-content">
|
|
|
|
<text class="item-value">{{ userInfo.username }}</text>
|
|
|
|
<text class="item-value">{{ userStore.userInfo.username }}</text>
|
|
|
|
<uv-icon name="arrow-right" size="16" color="#ccc"></uv-icon>
|
|
|
|
<uv-icon name="arrow-right" size="16" color="#ccc"></uv-icon>
|
|
|
|
</view>
|
|
|
|
</view>
|
|
|
|
</view>
|
|
|
|
</view>
|
|
|
|
|
|
|
|
|
|
|
|
<!-- 电话 -->
|
|
|
|
|
|
|
|
<!-- <view class="profile-item" @click="editPhone">
|
|
|
|
|
|
|
|
<view class="item-label">电话</view>
|
|
|
|
|
|
|
|
<view class="item-content">
|
|
|
|
|
|
|
|
<text class="item-value">{{ userInfo.phone }}</text>
|
|
|
|
|
|
|
|
<uv-icon name="arrow-right" size="16" color="#ccc"></uv-icon>
|
|
|
|
|
|
|
|
</view>
|
|
|
|
|
|
|
|
</view> -->
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<!-- 邮箱 -->
|
|
|
|
<!-- 邮箱 -->
|
|
|
|
<view class="profile-item" @click="editEmail">
|
|
|
|
<view class="profile-item" @click="editEmail">
|
|
|
|
<view class="item-label">邮箱</view>
|
|
|
|
<view class="item-label">邮箱</view>
|
|
|
|
<view class="item-content">
|
|
|
|
<view class="item-content">
|
|
|
|
<text class="item-value">{{ userInfo.email }}</text>
|
|
|
|
<text class="item-value">{{ userStore.userInfo.email }}</text>
|
|
|
|
<uv-icon name="arrow-right" size="16" color="#ccc"></uv-icon>
|
|
|
|
<uv-icon name="arrow-right" size="16" color="#ccc"></uv-icon>
|
|
|
|
</view>
|
|
|
|
</view>
|
|
|
|
</view>
|
|
|
|
</view>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<!-- 电话 -->
|
|
|
|
|
|
|
|
<view class="profile-item">
|
|
|
|
|
|
|
|
<view class="item-label">手机号</view>
|
|
|
|
|
|
|
|
<view class="item-content">
|
|
|
|
|
|
|
|
<text class="item-value">{{ userStore.userInfo.phone }}</text>
|
|
|
|
|
|
|
|
</view>
|
|
|
|
|
|
|
|
</view>
|
|
|
|
</view>
|
|
|
|
</view>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<!-- 应用设置 -->
|
|
|
|
<!-- 应用设置 -->
|
|
|
|
<view class="app-section">
|
|
|
|
<view class="app-section">
|
|
|
|
<!-- 缓存 -->
|
|
|
|
<!-- 缓存 -->
|
|
|
|
@ -152,6 +152,7 @@
|
|
|
|
import { ref, onMounted } from "vue";
|
|
|
|
import { ref, onMounted } from "vue";
|
|
|
|
import { onShow } from "@dcloudio/uni-app";
|
|
|
|
import { onShow } from "@dcloudio/uni-app";
|
|
|
|
import { useAuthStore, useUserStore } from "@/store";
|
|
|
|
import { useAuthStore, useUserStore } from "@/store";
|
|
|
|
|
|
|
|
import RPC from "@/utils/request";
|
|
|
|
|
|
|
|
|
|
|
|
const authStore = useAuthStore();
|
|
|
|
const authStore = useAuthStore();
|
|
|
|
const userStore = useUserStore();
|
|
|
|
const userStore = useUserStore();
|
|
|
|
@ -219,21 +220,21 @@ const selectAvatarSource = (source) => {
|
|
|
|
// 编辑用户名
|
|
|
|
// 编辑用户名
|
|
|
|
const editUsername = () => {
|
|
|
|
const editUsername = () => {
|
|
|
|
editType.value = "username";
|
|
|
|
editType.value = "username";
|
|
|
|
editValue.value = userInfo.value.username;
|
|
|
|
editValue.value = userStore.userInfo.username;
|
|
|
|
editPopup.value.open();
|
|
|
|
editPopup.value.open();
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
// 编辑电话
|
|
|
|
// 编辑电话
|
|
|
|
const editPhone = () => {
|
|
|
|
const editPhone = () => {
|
|
|
|
editType.value = "phone";
|
|
|
|
editType.value = "phone";
|
|
|
|
editValue.value = userInfo.value.phone;
|
|
|
|
editValue.value = userStore.userInfo.phone;
|
|
|
|
editPopup.value.open();
|
|
|
|
editPopup.value.open();
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
// 编辑邮箱
|
|
|
|
// 编辑邮箱
|
|
|
|
const editEmail = () => {
|
|
|
|
const editEmail = () => {
|
|
|
|
editType.value = "email";
|
|
|
|
editType.value = "email";
|
|
|
|
editValue.value = userInfo.value.email;
|
|
|
|
editValue.value = userStore.userInfo.email;
|
|
|
|
editPopup.value.open();
|
|
|
|
editPopup.value.open();
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
@ -267,49 +268,49 @@ const saveEdit = async () => {
|
|
|
|
});
|
|
|
|
});
|
|
|
|
return;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if(editType.value === 'username') {
|
|
|
|
// 验证格式
|
|
|
|
RPC.post('/user/update',{id:userStore.userInfo.id,username:editValue.value}).then(() => {
|
|
|
|
if (editType.value === "phone" && !/^1[3-9]\d{9}$/.test(editValue.value)) {
|
|
|
|
|
|
|
|
uni.showToast({
|
|
|
|
uni.showToast({
|
|
|
|
title: "请输入正确的手机号",
|
|
|
|
title: "保存成功",
|
|
|
|
icon: "none",
|
|
|
|
icon: "success",
|
|
|
|
});
|
|
|
|
});
|
|
|
|
return;
|
|
|
|
userStore.setUserInfo({...userStore.userInfo,username:editValue.value})
|
|
|
|
|
|
|
|
closeEditModal()
|
|
|
|
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if(editType.value === 'email') {
|
|
|
|
if (
|
|
|
|
RPC.post('/user/update',{id:userStore.userInfo.id,email:editValue.value}).then(() => {
|
|
|
|
editType.value === "email" &&
|
|
|
|
|
|
|
|
!/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(editValue.value)
|
|
|
|
|
|
|
|
) {
|
|
|
|
|
|
|
|
uni.showToast({
|
|
|
|
uni.showToast({
|
|
|
|
title: "请输入正确的邮箱地址",
|
|
|
|
title: "保存成功",
|
|
|
|
icon: "none",
|
|
|
|
icon: "success",
|
|
|
|
});
|
|
|
|
});
|
|
|
|
return;
|
|
|
|
userStore.setUserInfo({...userStore.userInfo,email:editValue.value})
|
|
|
|
|
|
|
|
closeEditModal()
|
|
|
|
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
// try {
|
|
|
|
// 调用更新用户信息API
|
|
|
|
// // 调用更新用户信息API
|
|
|
|
// await RPC.post('/api/user/update', {
|
|
|
|
// // await RPC.post('/api/user/update', {
|
|
|
|
// [editType.value]: editValue.value
|
|
|
|
// // [editType.value]: editValue.value
|
|
|
|
// })
|
|
|
|
// // })
|
|
|
|
|
|
|
|
|
|
|
|
// 更新本地数据
|
|
|
|
// // 更新本地数据
|
|
|
|
userInfo.value[editType.value] = editValue.value;
|
|
|
|
// userInfo.value[editType.value] = editValue.value;
|
|
|
|
|
|
|
|
|
|
|
|
uni.showToast({
|
|
|
|
// uni.showToast({
|
|
|
|
title: "保存成功",
|
|
|
|
// title: "保存成功",
|
|
|
|
icon: "success",
|
|
|
|
// icon: "success",
|
|
|
|
});
|
|
|
|
// });
|
|
|
|
|
|
|
|
|
|
|
|
closeEditModal();
|
|
|
|
// closeEditModal();
|
|
|
|
} catch (error) {
|
|
|
|
// } catch (error) {
|
|
|
|
console.error("保存失败:", error);
|
|
|
|
// console.error("保存失败:", error);
|
|
|
|
uni.showToast({
|
|
|
|
// uni.showToast({
|
|
|
|
title: "保存失败,请重试",
|
|
|
|
// title: "保存失败,请重试",
|
|
|
|
icon: "none",
|
|
|
|
// icon: "none",
|
|
|
|
});
|
|
|
|
// });
|
|
|
|
}
|
|
|
|
// }
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
// 清除缓存
|
|
|
|
// 清除缓存
|
|
|
|
|