Merge branch 'develop' of http://25.13.9.101:9000/K17_AITS/tra-app into develop

This commit is contained in:
杨航
2025-11-20 16:58:37 +08:00
3 changed files with 71 additions and 43 deletions
+1 -1
View File
@@ -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';
-37
View File
@@ -35,12 +35,6 @@
<!-- 显示当前选中的徽章 -->
<view class="dan" @click="common.navigateTo('/pages/pointsAndRank/rank')">
<view class="dan_img">
<!-- <image
class="img_100"
:src="`/static/images/me/${badgeList[currentIndex].png}`"
mode="heightFix"
alt="当前徽章"
></image> -->
<image-preview
class="img_100"
:src="statistics_data['currentRankAddr']"
@@ -197,37 +191,6 @@
user_info.imagePath = '';
}
});
const badgeList = [
{
name: '黑铁',
png: 'badge_1.png'
},
{
name: '青铜',
png: 'badge_2.png'
},
{
name: '白银',
png: 'badge_3.png'
},
{
name: '黄金',
png: 'badge_4.png'
},
{
name: '铂金',
png: 'badge_5.png'
},
{
name: '钻石',
png: 'badge_6.png'
},
{
name: '王者',
png: 'badge_7.png'
}
];
const currentIndex = ref(0);
const socketStore = useSocketStore();
const badgeNumRef = ref(null);
+70 -5
View File
@@ -20,9 +20,16 @@
</view>
</template>
</uv-cell>
<uv-cell title="性别" @click="sexPicker.open()" :isLink="true" :value="showGenderText"></uv-cell>
<uv-cell title="百禄形象" @click="gotoMascot()" :isLink="true" :border="false" :value="mascotName"></uv-cell>
<uv-cell title="性别" @click="sexPicker.open()" :isLink="true" :value="showGenderText"></uv-cell>
<uv-cell title="百禄形象" @click="gotoMascot()" :isLink="true" :value="mascotName"></uv-cell>
<uv-cell title="竞赛是否匿名" @click="isAnonyClick()" :isLink="true" :value="showIsAnonyText"></uv-cell>
<uv-cell
title="用户隐私协议"
@click="common.navigateTo('/pages/login/ysxy?page=1')"
:isLink="true"
:border="false"
></uv-cell>
</uv-cell-group>
</view>
<avatar-cropper
@@ -36,6 +43,7 @@
@confirm="avatarOnConfirm"
></avatar-cropper>
<uv-picker ref="sexPicker" :columns="[sexOptions]" keyName="label" @confirm="sexConfirm"></uv-picker>
<uv-picker ref="isAnonyPicker" :columns="[isAnonyOptions]" keyName="label" @confirm="anonyConfirm"></uv-picker>
</view>
</template>
@@ -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);
});
});
</script>
<style lang="scss" scoped>