refactor(用户资料): 重构个人资料设置流程和头像处理
将自动跳转个人资料页的逻辑移除,改为在个人中心显示设置按钮 优化头像处理逻辑,移除默认头像并添加空值检查 调整用户信息展示样式,添加个人资料设置按钮 实现防连点机制保护敏感操作
This commit is contained in:
parent
a1e4a46656
commit
d212815281
|
|
@ -101,16 +101,6 @@ onLoad(async (query) => {
|
|||
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) {
|
||||
try {
|
||||
|
|
|
|||
|
|
@ -33,24 +33,47 @@ const name = computed(() => {
|
|||
const userAvatar = computed(() => face_img.value ? toHttpsUrl(face_img.value) :
|
||||
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 dynamicCodeData = ref<DynamicCodeResponse | null>(null)
|
||||
const toast = useToast()
|
||||
|
||||
// wx参数展示弹窗
|
||||
const wxParamsActionSheet = ref<boolean>(false)
|
||||
|
||||
const ab98BalanceInYuan = computed(() => {
|
||||
if (ab98User.value && ab98User.value.ab98Balance !== undefined) {
|
||||
return (ab98User.value.ab98Balance / 100).toFixed(2)
|
||||
}
|
||||
return '0.00'
|
||||
})
|
||||
|
||||
const wxParamsActionSheet = ref<boolean>(false);
|
||||
// 连点计数器
|
||||
const clickTimestamps = ref<number[]>([]);
|
||||
// 展示wx参数
|
||||
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(() => {
|
||||
wxStore.refreshBalance()
|
||||
wxStore.refreshBalance();
|
||||
});
|
||||
|
||||
onShow(async () => {
|
||||
|
|
@ -117,13 +140,23 @@ const handleGenerateDynamicCode = async () => {
|
|||
<view class="avatar-wrapper">
|
||||
<image
|
||||
class="avatar"
|
||||
:src="wxUserDTO?.ab98FaceImg || wxUserDTO?.avatar || '/static/favicon.ico'"
|
||||
:src="toHttpsUrl(wxUserDTO?.ab98FaceImg || wxUserDTO?.avatar || '')"
|
||||
mode="aspectFill"
|
||||
@click="handleShowWxParams"
|
||||
/>
|
||||
</view>
|
||||
<view class="user-details">
|
||||
<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>
|
||||
|
||||
|
|
@ -321,6 +354,17 @@ const handleGenerateDynamicCode = async () => {
|
|||
font-weight: 600;
|
||||
color: #1a1a1a;
|
||||
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(() => {
|
||||
// 优先使用微信用户信息,其次使用企业用户信息
|
||||
/* // 优先使用微信用户信息,其次使用企业用户信息
|
||||
if (wxUserDTO.value) {
|
||||
avatarUrl.value = wxUserDTO.value.avatar || ''
|
||||
nickName.value = wxUserDTO.value.nickName || ''
|
||||
|
|
@ -47,8 +47,8 @@ onMounted(() => {
|
|||
|
||||
// 默认头像
|
||||
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
|
||||
try {
|
||||
|
|
@ -391,6 +396,7 @@ const handleSubmit = async () => {
|
|||
font-size: 16px;
|
||||
color: #1a1a1a;
|
||||
margin-bottom: 12px;
|
||||
box-sizing: border-box;
|
||||
|
||||
&:focus {
|
||||
border-color: #409EFF;
|
||||
|
|
|
|||
Loading…
Reference in New Issue