2
0

fix: 个人信息修改出生日期

This commit is contained in:
caiyuchao
2025-02-19 16:33:18 +08:00
parent f59ea203ec
commit 24f4dc23cc

View File

@@ -11,7 +11,7 @@ import { useRouter } from 'vue-router';
interface UserProfile {
username: string;
fullname: string;
birthdate: string;
birthDate: string;
email: string;
phonenumber: string;
sex: string;
@@ -24,7 +24,7 @@ const loading = ref(false);
const formState = ref<UserProfile>({
username: '',
fullname: '',
birthdate: '',
birthDate: '',
email: '',
phonenumber: '',
sex: '0'
@@ -105,7 +105,7 @@ const rules = computed<{ [k: string]: RuleObject | RuleObject[] }>(() => {
{ validator: validateEmail, trigger: 'blur' }
],
phonenumber: [{ validator: validatePhone, trigger: 'blur' }],
birthdate: [
birthDate: [
{
validator: (_rule: RuleObject, value: string) => {
if (!value) return Promise.resolve();
@@ -144,7 +144,7 @@ onMounted(async () => {
formState.value = {
username: userInfo.userName ?? '',
fullname: userInfo.nickName ?? '',
birthdate: userInfo.birthDate ?? '', // 添加出生日期
birthDate: userInfo.birthDate ? dayjs(userInfo.birthDate, 'YYYY-MM-DD') : '',
email: userInfo.email ?? '',
phonenumber: userInfo.phonenumber ?? '',
sex: userInfo.sex ?? '0'
@@ -183,9 +183,9 @@ const handleSubmit = async () => {
if (formState.value.sex) {
updateData.sex = formState.value.sex;
}
if (formState.value.birthdate) {
updateData.birthDate = formState.value.birthdate;
updateData.age = dayjs().diff(dayjs(formState.value.birthdate), 'year');
if (formState.value.birthDate) {
updateData.birthDate = formState.value.birthDate;
updateData.age = dayjs().diff(formState.value.birthDate, 'year');
}
// 调用更新接口
@@ -199,7 +199,7 @@ const handleSubmit = async () => {
formState.value = {
username: userInfo.userName ?? '',
fullname: userInfo.nickName ?? '',
birthdate: userInfo.birthDate ?? '',
birthDate: userInfo.birthDate ? dayjs(userInfo.birthDate, 'YYYY-MM-DD') : '',
email: userInfo.email ?? '',
phonenumber: userInfo.phonenumber ?? '',
sex: userInfo.sex ?? '0'
@@ -253,9 +253,9 @@ const handleBack = () => {
/>
</a-form-item>
<a-form-item :label="t('page.login.register.birthDate')" name="birthdate">
<a-form-item :label="t('page.login.register.birthDate')" name="birthDate">
<a-date-picker
v-model:value="formState.birthdate"
v-model:value="formState.birthDate"
style="width: 100%"
:format="'YYYY-MM-DD'"
:placeholder="t('page.login.register.birthDatePlaceholder')"