feat: 修改注册页面
This commit is contained in:
parent
f1e51f7ff6
commit
9a6efea1c9
@ -51,10 +51,13 @@
|
||||
|
||||
<script setup>
|
||||
import { ref } from 'vue';
|
||||
import { useStore } from 'vuex';
|
||||
import Avatar from '../components/Avatar.vue';
|
||||
import { checkNicknameApi } from '@/utils/api.js';
|
||||
import { validateNickname } from '@/utils/validator.js';
|
||||
|
||||
const store = useStore();
|
||||
|
||||
// 响应式数据
|
||||
const nickname = ref('');
|
||||
const errorMessage = ref('');
|
||||
@ -127,16 +130,81 @@ const handleNext = async () => {
|
||||
// url: '/pages/welcome/welcome'
|
||||
// });
|
||||
|
||||
// 跳转到粉丝身份选择页面
|
||||
uni.navigateTo({
|
||||
url: '/pages/profile/selectRole'
|
||||
// // 跳转到粉丝身份选择页面
|
||||
// uni.navigateTo({
|
||||
// url: '/pages/profile/selectRole'
|
||||
// });
|
||||
|
||||
// 获取临时存储的注册信息
|
||||
const mobile = uni.getStorageSync('temp_register_mobile');
|
||||
const password = uni.getStorageSync('temp_register_password');
|
||||
const star_id = 87; // 默认身份
|
||||
|
||||
// 验证数据完整性
|
||||
if (!mobile || !password || !trimmedNickname || !star_id) {
|
||||
uni.showToast({
|
||||
title: '注册信息不完整,请重新注册',
|
||||
icon: 'none'
|
||||
});
|
||||
uni.removeStorageSync('temp_register_mobile');
|
||||
uni.removeStorageSync('temp_register_password');
|
||||
uni.removeStorageSync('temp_register_nickname');
|
||||
setTimeout(() => {
|
||||
uni.reLaunch({
|
||||
url: '/pages/register/register'
|
||||
});
|
||||
}, 1500);
|
||||
isChecking.value = false;
|
||||
return;
|
||||
}
|
||||
|
||||
// 显示加载提示
|
||||
uni.showLoading({
|
||||
title: '注册中...',
|
||||
mask: true
|
||||
});
|
||||
|
||||
// 调用注册 API
|
||||
await store.dispatch('user/register', {
|
||||
mobile,
|
||||
password,
|
||||
star_id,
|
||||
nickname: trimmedNickname
|
||||
});
|
||||
|
||||
uni.hideLoading();
|
||||
|
||||
// 清除临时数据
|
||||
uni.removeStorageSync('temp_register_mobile');
|
||||
uni.removeStorageSync('temp_register_password');
|
||||
uni.removeStorageSync('temp_register_nickname');
|
||||
|
||||
// 设置新用户标记
|
||||
uni.setStorageSync('is_new_user', true);
|
||||
|
||||
// 跳转到主页
|
||||
uni.reLaunch({
|
||||
url: '/pages/square/square'
|
||||
});
|
||||
|
||||
} catch (error) {
|
||||
errorMessage.value = error.message || '操作失败,请重试';
|
||||
uni.showToast({
|
||||
title: errorMessage.value,
|
||||
icon: 'none'
|
||||
});
|
||||
uni.hideLoading();
|
||||
|
||||
// 处理昵称已存在的情况(409错误)
|
||||
if (error.code === 409 || error.message.includes('昵称') || error.message.includes('已存在')) {
|
||||
uni.showModal({
|
||||
title: '昵称已存在',
|
||||
content: '该昵称已被使用,请返回修改昵称',
|
||||
showCancel: false,
|
||||
confirmText: '知道了'
|
||||
});
|
||||
} else {
|
||||
errorMessage.value = error.message || '注册失败,请重试';
|
||||
uni.showToast({
|
||||
title: errorMessage.value,
|
||||
icon: 'none'
|
||||
});
|
||||
}
|
||||
} finally {
|
||||
isChecking.value = false;
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user