refactor(用户资料): 重构个人资料设置流程和头像处理
将自动跳转个人资料页的逻辑移除,改为在个人中心显示设置按钮 优化头像处理逻辑,移除默认头像并添加空值检查 调整用户信息展示样式,添加个人资料设置按钮 实现防连点机制保护敏感操作
This commit is contained in:
parent
a1e4a46656
commit
d212815281
|
|
@ -101,16 +101,6 @@ onLoad(async (query) => {
|
||||||
console.error('用户登录处理失败:', error);
|
console.error('用户登录处理失败:', error);
|
||||||
}
|
}
|
||||||
|
|
||||||
// 检查是否需要跳转到个人资料设置页面
|
|
||||||
// 条件:未绑定 ab98UserId 且 profileDone 不为真
|
|
||||||
if (wxUserDTO.value && !wxUserDTO.value.ab98UserId && wxUserDTO.value.profileDone !== true) {
|
|
||||||
console.log('用户需要完善资料,跳转到个人资料设置页面');
|
|
||||||
uni.navigateTo({
|
|
||||||
url: '/pages/profile/index'
|
|
||||||
});
|
|
||||||
return; // 跳转后不执行后续逻辑
|
|
||||||
}
|
|
||||||
|
|
||||||
// 获取店铺列表
|
// 获取店铺列表
|
||||||
if (showShopList.value) {
|
if (showShopList.value) {
|
||||||
try {
|
try {
|
||||||
|
|
|
||||||
|
|
@ -30,27 +30,50 @@ const name = computed(() => {
|
||||||
return userName.value || qyName.value || '未知用户'
|
return userName.value || qyName.value || '未知用户'
|
||||||
})
|
})
|
||||||
|
|
||||||
const userAvatar = computed(() => face_img.value ? toHttpsUrl(face_img.value) :
|
const userAvatar = computed(() => face_img.value ? toHttpsUrl(face_img.value) :
|
||||||
wxUserDTO.value?.avatar ? toHttpsUrl(wxUserDTO.value.avatar) : '/static/favicon.ico')
|
wxUserDTO.value?.avatar ? toHttpsUrl(wxUserDTO.value.avatar) : '/static/favicon.ico')
|
||||||
|
|
||||||
|
const showProfileSetupButton = computed(() => {
|
||||||
|
return wxUserDTO.value && !wxUserDTO.value.ab98UserId && wxUserDTO.value.profileDone !== true
|
||||||
|
})
|
||||||
|
|
||||||
// 动态码相关
|
// 动态码相关
|
||||||
const dynamicCodeActionSheet = ref<boolean>(false)
|
const dynamicCodeActionSheet = ref<boolean>(false)
|
||||||
const dynamicCodeData = ref<DynamicCodeResponse | null>(null)
|
const dynamicCodeData = ref<DynamicCodeResponse | null>(null)
|
||||||
const toast = useToast()
|
const toast = useToast()
|
||||||
|
|
||||||
// wx参数展示弹窗
|
// wx参数展示弹窗
|
||||||
const wxParamsActionSheet = ref<boolean>(false)
|
const wxParamsActionSheet = ref<boolean>(false);
|
||||||
|
// 连点计数器
|
||||||
const ab98BalanceInYuan = computed(() => {
|
const clickTimestamps = ref<number[]>([]);
|
||||||
if (ab98User.value && ab98User.value.ab98Balance !== undefined) {
|
|
||||||
return (ab98User.value.ab98Balance / 100).toFixed(2)
|
|
||||||
}
|
|
||||||
return '0.00'
|
|
||||||
})
|
|
||||||
|
|
||||||
// 展示wx参数
|
// 展示wx参数
|
||||||
const handleShowWxParams = () => {
|
const handleShowWxParams = () => {
|
||||||
wxParamsActionSheet.value = true
|
const now = Date.now();
|
||||||
|
const timestamps = clickTimestamps.value;
|
||||||
|
|
||||||
|
// 移除超过3秒的旧时间戳
|
||||||
|
const threeSecondsAgo = now - 3000;
|
||||||
|
const validTimestamps = timestamps.filter(timestamp => timestamp >= threeSecondsAgo);
|
||||||
|
|
||||||
|
// 检查最后一次点击的间隔
|
||||||
|
if (validTimestamps.length > 0) {
|
||||||
|
const lastTimestamp = validTimestamps[validTimestamps.length - 1];
|
||||||
|
const interval = now - lastTimestamp;
|
||||||
|
if (interval < 100) {
|
||||||
|
// 间隔小于100毫秒,
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 添加当前时间戳
|
||||||
|
validTimestamps.push(now);
|
||||||
|
clickTimestamps.value = validTimestamps;
|
||||||
|
|
||||||
|
// 检查是否达到5次点击
|
||||||
|
if (clickTimestamps.value.length >= 5) {
|
||||||
|
wxParamsActionSheet.value = true; // 触发弹窗
|
||||||
|
clickTimestamps.value = []; // 重置计数器
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 统一的页面跳转函数
|
// 统一的页面跳转函数
|
||||||
|
|
@ -78,7 +101,7 @@ const navigateToPage = (pagePath: string, options: { type?: 'navigateTo' | 'swit
|
||||||
}
|
}
|
||||||
|
|
||||||
onMounted(() => {
|
onMounted(() => {
|
||||||
wxStore.refreshBalance()
|
wxStore.refreshBalance();
|
||||||
});
|
});
|
||||||
|
|
||||||
onShow(async () => {
|
onShow(async () => {
|
||||||
|
|
@ -117,13 +140,23 @@ const handleGenerateDynamicCode = async () => {
|
||||||
<view class="avatar-wrapper">
|
<view class="avatar-wrapper">
|
||||||
<image
|
<image
|
||||||
class="avatar"
|
class="avatar"
|
||||||
:src="wxUserDTO?.ab98FaceImg || wxUserDTO?.avatar || '/static/favicon.ico'"
|
:src="toHttpsUrl(wxUserDTO?.ab98FaceImg || wxUserDTO?.avatar || '')"
|
||||||
mode="aspectFill"
|
mode="aspectFill"
|
||||||
@click="handleShowWxParams"
|
@click="handleShowWxParams"
|
||||||
/>
|
/>
|
||||||
</view>
|
</view>
|
||||||
<view class="user-details">
|
<view class="user-details">
|
||||||
<view class="user-name">{{ wxUserDTO?.ab98Name || wxUserDTO?.nickName }}</view>
|
<view class="user-name">{{ wxUserDTO?.ab98Name || wxUserDTO?.nickName }}</view>
|
||||||
|
<view v-if="showProfileSetupButton" class="profile-setup-button">
|
||||||
|
<wd-button
|
||||||
|
size="small"
|
||||||
|
type="primary"
|
||||||
|
plain
|
||||||
|
@click="navigateToPage('/pages/profile/index')"
|
||||||
|
>
|
||||||
|
设置个人资料
|
||||||
|
</wd-button>
|
||||||
|
</view>
|
||||||
</view>
|
</view>
|
||||||
</view>
|
</view>
|
||||||
|
|
||||||
|
|
@ -321,6 +354,17 @@ const handleGenerateDynamicCode = async () => {
|
||||||
font-weight: 600;
|
font-weight: 600;
|
||||||
color: #1a1a1a;
|
color: #1a1a1a;
|
||||||
letter-spacing: 0.5px;
|
letter-spacing: 0.5px;
|
||||||
|
margin-bottom: 8px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.profile-setup-button {
|
||||||
|
margin-top: 8px;
|
||||||
|
|
||||||
|
:deep(.wd-button) {
|
||||||
|
--wot-button-small-height: 28px;
|
||||||
|
--wot-button-small-padding: 0 12px;
|
||||||
|
--wot-button-small-font-size: 12px;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -29,7 +29,7 @@ const nickName = ref('')
|
||||||
|
|
||||||
// 初始化数据
|
// 初始化数据
|
||||||
onMounted(() => {
|
onMounted(() => {
|
||||||
// 优先使用微信用户信息,其次使用企业用户信息
|
/* // 优先使用微信用户信息,其次使用企业用户信息
|
||||||
if (wxUserDTO.value) {
|
if (wxUserDTO.value) {
|
||||||
avatarUrl.value = wxUserDTO.value.avatar || ''
|
avatarUrl.value = wxUserDTO.value.avatar || ''
|
||||||
nickName.value = wxUserDTO.value.nickName || ''
|
nickName.value = wxUserDTO.value.nickName || ''
|
||||||
|
|
@ -47,8 +47,8 @@ onMounted(() => {
|
||||||
|
|
||||||
// 默认头像
|
// 默认头像
|
||||||
if (!avatarUrl.value) {
|
if (!avatarUrl.value) {
|
||||||
avatarUrl.value = '/static/favicon.ico'
|
avatarUrl.value = ''
|
||||||
}
|
} */
|
||||||
})
|
})
|
||||||
|
|
||||||
// 图片上传相关
|
// 图片上传相关
|
||||||
|
|
@ -198,7 +198,12 @@ const handleSubmit = async () => {
|
||||||
}
|
}
|
||||||
|
|
||||||
// 获取要使用的头像路径
|
// 获取要使用的头像路径
|
||||||
const finalAvatarPath = tempAvatarPath.value || avatarUrl.value
|
const finalAvatarPath = tempAvatarPath.value || avatarUrl.value;
|
||||||
|
|
||||||
|
if (!finalAvatarPath) {
|
||||||
|
toast.show('请选择头像')
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
loading.value = true
|
loading.value = true
|
||||||
try {
|
try {
|
||||||
|
|
@ -391,6 +396,7 @@ const handleSubmit = async () => {
|
||||||
font-size: 16px;
|
font-size: 16px;
|
||||||
color: #1a1a1a;
|
color: #1a1a1a;
|
||||||
margin-bottom: 12px;
|
margin-bottom: 12px;
|
||||||
|
box-sizing: border-box;
|
||||||
|
|
||||||
&:focus {
|
&:focus {
|
||||||
border-color: #409EFF;
|
border-color: #409EFF;
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue