From 379cdb37539818482c0a737af46d3295cfc55077 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=94=B0=E5=B2=A9?= Date: Thu, 20 Nov 2025 16:52:40 +0800 Subject: [PATCH] =?UTF-8?q?=E5=BC=80=E5=8F=91=E8=AE=BE=E7=BD=AE=E9=A1=B5?= =?UTF-8?q?=E7=9A=84=E6=98=AF=E5=90=A6=E5=8C=BF=E5=90=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/pages/competition/matching.vue | 2 +- src/pages/me/index.vue | 37 --------------- src/pages/setting/index.vue | 75 ++++++++++++++++++++++++++++-- 3 files changed, 71 insertions(+), 43 deletions(-) diff --git a/src/pages/competition/matching.vue b/src/pages/competition/matching.vue index 94dbe151..1926a494 100644 --- a/src/pages/competition/matching.vue +++ b/src/pages/competition/matching.vue @@ -123,7 +123,7 @@ import { onLoad } from '@dcloudio/uni-app'; import { defaultAnonymousAvatar } from '@/enum'; import { pkAnonymousClose, pkAnonymousOpen, pkRankingList, pkRules, switchIcon, optionErrorIcon } from '@/common/imgSvg'; - import { queryTraUserAnonyByUserId, updateTraUserAnony } from '@/api/user'; + import { updateTraUserAnony } from '@/api/user'; import selectionInstitutions from '@/components/selection-institutions/index.vue'; diff --git a/src/pages/me/index.vue b/src/pages/me/index.vue index a7ae1614..bc43c74a 100644 --- a/src/pages/me/index.vue +++ b/src/pages/me/index.vue @@ -35,12 +35,6 @@ - + - - + + + + @@ -50,8 +58,10 @@ import { updateDfSysUserExtandInfoGender } from '@/api/user.js'; import { queryValidTraMascotInfo } from '@/api/mascot.js'; import { get_base_url } from '@/api/request.js'; + import { queryTraUserAnonyByUserId, updateTraUserAnony } from '@/api/user'; const index = ref(0); const sexPicker = ref(null); + const isAnonyPicker = ref(null); const userInfo = ref({ gender: '', imagePath: '', @@ -68,12 +78,16 @@ const mascotName = computed(() => userInfo.value.mascotInfo?.mascotName || ''); const sexOptions = GENDER; - // 去选择百禄 const gotoMascot = () => { common.navigateTo('/pages/mascot/mascot_select_list?from=setting'); }; + // 展开是否匿名的框 + const isAnonyClick = () => { + isAnonyPicker.value.setIndexs([isAnony.value === 'Y' ? 1 : 0], true); + isAnonyPicker.value.open(); + }; // 显示性别的计算属性 const showGenderText = computed(() => { @@ -84,7 +98,21 @@ return '未填写'; } }); - + const isAnonyOptions = [ + { + value: 'N', + label: '不匿名' + }, + { + value: 'Y', + label: '匿名' + } + ]; + // 显示是否匿名的计算属性 + const showIsAnonyText = computed(() => { + const item = isAnonyOptions.find((item) => item.value === isAnony.value); + return item?.label ?? ''; + }); // 修改性别 const sexConfirm = (e) => { userInfo.value.gender = e.value[0].value; @@ -100,11 +128,48 @@ common.hideLoading(); }); }; - + const isAnony = ref(''); // 状态:Y(匿名)/N(非匿名)/''(未初始化) + // 修改是否匿名 + const anonyConfirm = async (e) => { + // 2. 解构取值 + 边界校验(避免e.value[0]不存在导致报错) + const targetValue = e?.value?.[0]?.value; + if (typeof targetValue !== 'string' || targetValue === isAnony.value) { + return; // 值未变化/非法,直接返回 + } + + // 3. 缓存原始值(仅声明一次) + const originalValue = isAnony.value; + + try { + // 4. 先更新本地状态(提升用户体验)+ 显示加载 + isAnony.value = targetValue; + common.loading('修改中'); + + // 5. 发起请求(await简化异步逻辑,避免.then/.catch嵌套) + await updateTraUserAnony({ isAnony: targetValue }); + + // 6. 成功提示(延迟更合理,避免加载框消失过快) + setTimeout(() => common.msg('切换成功'), 400); + } catch (error) { + // 7. 失败回滚 + 错误日志 + 提示 + isAnony.value = originalValue; + console.error('匿名状态修改失败:', error); // 便于排查问题 + common.msg('切换失败,请重试'); + } finally { + // 8. 确保加载框始终关闭 + common.hideLoading(); + } + }; onShow((params) => { userInfo.value = getUserInfo(); console.log('userInfo.value,', userInfo.value); }); + onLoad(() => { + queryTraUserAnonyByUserId().then(({ body }) => { + isAnony.value = body.isAnony; + console.log('res', body); + }); + });