修改用户上传
This commit is contained in:
@@ -4,7 +4,8 @@ import Taro from '@tarojs/taro';
|
||||
import './index.scss';
|
||||
import { UserInfo } from '@/components/UserInfo';
|
||||
import { UserService } from '@/services/userService';
|
||||
import {clear_login_state} from '@/services/loginService';
|
||||
import { clear_login_state } from '@/services/loginService';
|
||||
import { convert_db_gender_to_display } from '@/utils/genderUtils';
|
||||
import { EditModal } from '@/components';
|
||||
|
||||
const EditProfilePage: React.FC = () => {
|
||||
@@ -123,15 +124,15 @@ const EditProfilePage: React.FC = () => {
|
||||
// 调用更新用户信息接口,只传递修改的字段
|
||||
const update_data = { [editing_field]: value };
|
||||
await UserService.update_user_info(update_data);
|
||||
|
||||
|
||||
// 更新本地状态
|
||||
setFormData(prev => ({ ...prev, [editing_field]: value }));
|
||||
setUserInfo(prev => ({ ...prev, [editing_field]: value }));
|
||||
|
||||
|
||||
// 关闭弹窗
|
||||
setEditModalVisible(false);
|
||||
setEditingField('');
|
||||
|
||||
|
||||
// 显示成功提示
|
||||
Taro.showToast({
|
||||
title: '保存成功',
|
||||
@@ -157,11 +158,11 @@ const EditProfilePage: React.FC = () => {
|
||||
// 调用更新用户信息接口,只传递修改的字段
|
||||
const update_data = { [field]: value };
|
||||
await UserService.update_user_info(update_data);
|
||||
|
||||
|
||||
// 更新本地状态
|
||||
setFormData(prev => ({ ...prev, [field]: value }));
|
||||
setUserInfo(prev => ({ ...prev, [field]: value }));
|
||||
|
||||
|
||||
// 显示成功提示
|
||||
Taro.showToast({
|
||||
title: '保存成功',
|
||||
@@ -179,8 +180,9 @@ const EditProfilePage: React.FC = () => {
|
||||
// 处理性别选择
|
||||
const handle_gender_change = (e: any) => {
|
||||
const gender_value = e.detail.value;
|
||||
const gender_text = gender_value === 'male' ? '男' : '女';
|
||||
handle_field_edit('gender', gender_text);
|
||||
// 使用工具函数转换:页面选择器值(0/1) -> 数据库值('0'/'1')
|
||||
const gender_db_value = gender_value === 0 ? '0' : '1';
|
||||
handle_field_edit('gender', gender_db_value);
|
||||
};
|
||||
|
||||
// 处理生日选择
|
||||
@@ -189,19 +191,42 @@ const EditProfilePage: React.FC = () => {
|
||||
handle_field_edit('birthday', birthday_value);
|
||||
};
|
||||
|
||||
// 处理职业输入
|
||||
const handle_occupation_change = (e: any) => {
|
||||
// 处理职业输入 - 实时更新本地状态
|
||||
const handle_occupation_input = (e: any) => {
|
||||
const occupation_value = e.detail.value;
|
||||
setFormData(prev => ({ ...prev, occupation: occupation_value }));
|
||||
};
|
||||
|
||||
// 处理职业输入 - 失去焦点时保存到服务器
|
||||
const handle_occupation_blur = (e: any) => {
|
||||
const occupation_value = e.detail.value;
|
||||
handle_field_edit('occupation', occupation_value);
|
||||
};
|
||||
|
||||
// 处理地区输入 - 实时更新本地状态
|
||||
const handle_location_input = (e: any) => {
|
||||
const location_value = e.detail.value;
|
||||
setFormData(prev => ({ ...prev, location: location_value }));
|
||||
};
|
||||
|
||||
// 处理地区输入
|
||||
const handle_location_change = (e: any) => {
|
||||
// 处理地区输入 - 失去焦点时保存到服务器
|
||||
const handle_location_blur = (e: any) => {
|
||||
const location_value = e.detail.value;
|
||||
handle_field_edit('location', location_value);
|
||||
};
|
||||
|
||||
// 处理手机号输入 - 实时更新本地状态
|
||||
const handle_phone_input = (e: any) => {
|
||||
const phone_value = e.detail.value;
|
||||
setFormData(prev => ({ ...prev, phone: phone_value }));
|
||||
};
|
||||
|
||||
// 处理手机号输入 - 失去焦点时保存到服务器
|
||||
const handle_phone_blur = (e: any) => {
|
||||
const phone_value = e.detail.value;
|
||||
handle_field_edit('phone', phone_value);
|
||||
};
|
||||
|
||||
|
||||
// 处理退出登录
|
||||
const handle_logout = () => {
|
||||
@@ -212,7 +237,7 @@ const EditProfilePage: React.FC = () => {
|
||||
if (res.confirm) {
|
||||
// 清除用户数据
|
||||
clear_login_state();
|
||||
|
||||
|
||||
Taro.reLaunch({
|
||||
url: '/pages/login/index/index'
|
||||
});
|
||||
@@ -267,10 +292,10 @@ const EditProfilePage: React.FC = () => {
|
||||
|
||||
{/* 性别 */}
|
||||
<View className="form_group">
|
||||
<Picker
|
||||
mode="selector"
|
||||
range={['男', '女']}
|
||||
value={form_data.gender === '男' ? 0 : 1}
|
||||
<Picker
|
||||
mode="selector"
|
||||
range={['男', '女']}
|
||||
value={form_data.gender === '0' ? 0 : form_data.gender === '1' ? 1 : 0}
|
||||
onChange={handle_gender_change}
|
||||
>
|
||||
<View className="form_item">
|
||||
@@ -279,7 +304,9 @@ const EditProfilePage: React.FC = () => {
|
||||
<Text className="item_label">性别</Text>
|
||||
</View>
|
||||
<View className="item_right">
|
||||
<Text className="item_value">{form_data.gender || '请选择'}</Text>
|
||||
<Text className="item_value">
|
||||
{convert_db_gender_to_display(form_data.gender)}
|
||||
</Text>
|
||||
<Image className="arrow_icon" src={require('../../../static/list/icon-list-right-arrow.svg')} />
|
||||
</View>
|
||||
</View>
|
||||
@@ -289,8 +316,8 @@ const EditProfilePage: React.FC = () => {
|
||||
|
||||
{/* 生日 */}
|
||||
<View className="form_group">
|
||||
<Picker
|
||||
mode="date"
|
||||
<Picker
|
||||
mode="date"
|
||||
value={form_data.birthday}
|
||||
onChange={handle_birthday_change}
|
||||
>
|
||||
@@ -336,11 +363,12 @@ const EditProfilePage: React.FC = () => {
|
||||
<Text className="item_label">地区</Text>
|
||||
</View>
|
||||
<View className="item_right">
|
||||
<Input
|
||||
<Input
|
||||
className="item_input"
|
||||
value={form_data.location}
|
||||
placeholder="请输入地区"
|
||||
onBlur={(e) => handle_location_change(e)}
|
||||
onInput={handle_location_input}
|
||||
onBlur={handle_location_blur}
|
||||
/>
|
||||
</View>
|
||||
</View>
|
||||
@@ -366,11 +394,12 @@ const EditProfilePage: React.FC = () => {
|
||||
<Text className="item_label">职业</Text>
|
||||
</View>
|
||||
<View className="item_right">
|
||||
<Input
|
||||
<Input
|
||||
className="item_input"
|
||||
value={form_data.occupation}
|
||||
placeholder="请输入职业"
|
||||
onBlur={(e) => handle_occupation_change(e)}
|
||||
onInput={handle_occupation_input}
|
||||
onBlur={handle_occupation_blur}
|
||||
/>
|
||||
</View>
|
||||
</View>
|
||||
@@ -386,12 +415,13 @@ const EditProfilePage: React.FC = () => {
|
||||
<Text className="item_label">手机</Text>
|
||||
</View>
|
||||
<View className="item_right">
|
||||
<Input
|
||||
<Input
|
||||
className="item_input"
|
||||
value={form_data.phone}
|
||||
placeholder="请输入手机号"
|
||||
type="number"
|
||||
onBlur={(e) => handle_field_edit('phone', e.detail.value)}
|
||||
onInput={handle_phone_input}
|
||||
onBlur={handle_phone_blur}
|
||||
/>
|
||||
</View>
|
||||
</View>
|
||||
|
||||
Reference in New Issue
Block a user